Commit 7e571364 by Jim Stichnoth

Subzero: Clean up a few areas.

1. Use a reverse_range() adaptor for range-based reverse iteration through containers. 2. Remove the emitting of the commented llvm-mc command line. 3. Remove a few TODOs. 4. For commented-out declarations within a class T like this: // T(const T&) = delete; // T &operator=(const T &) = delete; Replace them with this: T(const T&) = default; T &operator=(const T &) = default; And try to keep them private where possible. 5. Make LivenessNode and TimerTreeNode into internal classes. BUG= none R=jvoung@chromium.org Review URL: https://codereview.chromium.org/830303003
parent 5a122d70
......@@ -269,8 +269,7 @@ void Cfg::liveness(LivenessMode Mode) {
llvm::BitVector NeedToProcess(Nodes.size(), true);
while (NeedToProcess.any()) {
// Iterate in reverse topological order to speed up convergence.
for (auto I = Nodes.rbegin(), E = Nodes.rend(); I != E; ++I) {
CfgNode *Node = *I;
for (CfgNode *Node : reverse_range(Nodes)) {
if (NeedToProcess[Node->getIndex()]) {
NeedToProcess[Node->getIndex()] = false;
bool Changed = Node->liveness(getLiveness());
......@@ -442,16 +441,6 @@ void Cfg::emit() {
dump("After recomputing liveness for -decorate-asm");
}
Ostream &Str = Ctx->getStrEmit();
if (!Ctx->testAndSetHasEmittedFirstMethod()) {
// Print a helpful command for assembling the output.
// TODO: have the Target emit the header
// TODO: need a per-file emit in addition to per-CFG
Str << "# $LLVM_BIN_PATH/llvm-mc"
<< " -arch=x86"
<< " -filetype=obj"
<< " -o=MyObj.o"
<< "\n\n";
}
IceString MangledName = getContext()->mangleName(getFunctionName());
emitTextHeader(MangledName);
for (CfgNode *Node : Nodes)
......
......@@ -104,10 +104,6 @@ void CfgNode::placePhiLoads() {
// Note that this transformation takes the Phi dest variables out of
// SSA form, as there may be assignments to the dest variable in
// multiple blocks.
//
// TODO: Defer this pass until after register allocation, then split
// critical edges, add the assignments, and lower them. This should
// reduce the amount of shuffling at the end of each block.
void CfgNode::placePhiStores() {
// Find the insertion point.
InstList::iterator InsertionPoint = Insts.end();
......@@ -250,14 +246,13 @@ CfgNode *CfgNode::splitIncomingEdge(CfgNode *Pred, SizeT EdgeIndex) {
}
}
assert(Found);
// Repoint a suitable branch instruction's target.
// Repoint a suitable branch instruction's target and return.
Found = false;
for (auto I = Pred->getInsts().rbegin(), E = Pred->getInsts().rend();
!Found && I != E; ++I) {
if (!I->isDeleted()) {
Found = I->repointEdge(this, NewNode);
}
for (Inst &I : reverse_range(Pred->getInsts())) {
if (!I.isDeleted() && I.repointEdge(this, NewNode))
return NewNode;
}
// This should be unreachable, so the assert will fail.
assert(Found);
return NewNode;
}
......@@ -533,11 +528,10 @@ void CfgNode::livenessLightweight() {
SizeT NumVars = Func->getNumVariables();
LivenessBV Live(NumVars);
// Process regular instructions in reverse order.
// TODO(stichnot): Use llvm::make_range with LLVM 3.5.
for (auto I = Insts.rbegin(), E = Insts.rend(); I != E; ++I) {
if (I->isDeleted())
for (Inst &I : reverse_range(Insts)) {
if (I.isDeleted())
continue;
I->livenessLightweight(Func, Live);
I.livenessLightweight(Func, Live);
}
for (Inst &I : Phis) {
if (I.isDeleted())
......@@ -579,10 +573,10 @@ bool CfgNode::liveness(Liveness *Liveness) {
Liveness->getLiveOut(this) = Live;
// Process regular instructions in reverse order.
for (auto I = Insts.rbegin(), E = Insts.rend(); I != E; ++I) {
if (I->isDeleted())
for (Inst &I : reverse_range(Insts)) {
if (I.isDeleted())
continue;
I->liveness(I->getNumber(), Live, Liveness, LiveBegin, LiveEnd);
I.liveness(I.getNumber(), Live, Liveness, LiveBegin, LiveEnd);
}
// Process phis in forward order so that we can override the
// instruction number to be that of the earliest phi instruction in
......
......@@ -29,6 +29,7 @@
#include "llvm/ADT/BitVector.h"
#include "llvm/ADT/ilist.h"
#include "llvm/ADT/ilist_node.h"
#include "llvm/ADT/iterator_range.h"
#include "llvm/ADT/SmallBitVector.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/STLExtras.h"
......@@ -157,6 +158,17 @@ typedef uint32_t VerboseMask;
typedef llvm::raw_ostream Ostream;
typedef llvm::raw_fd_ostream Fdstream;
// Reverse range adaptors written in terms of llvm::make_range().
template <typename T>
llvm::iterator_range<typename T::const_reverse_iterator>
reverse_range(const T &Container) {
return llvm::make_range(Container.rbegin(), Container.rend());
}
template <typename T>
llvm::iterator_range<typename T::reverse_iterator> reverse_range(T &Container) {
return llvm::make_range(Container.rbegin(), Container.rend());
}
} // end of namespace Ice
#endif // SUBZERO_SRC_ICEDEFS_H
......@@ -130,8 +130,7 @@ GlobalContext::GlobalContext(Ostream *OsDump, Ostream *OsEmit,
IceString TestPrefix, const ClFlags &Flags)
: StrDump(OsDump), StrEmit(OsEmit), VMask(Mask),
ConstPool(new ConstantPool()), Arch(Arch), Opt(Opt),
TestPrefix(TestPrefix), Flags(Flags), HasEmittedFirstMethod(false),
RNG(""), ObjectWriter() {
TestPrefix(TestPrefix), Flags(Flags), RNG(""), ObjectWriter() {
// Pre-register built-in stack names.
if (ALLOW_DUMP) {
newTimerStackID("Total across all functions");
......
......@@ -33,7 +33,7 @@ class FuncSigType;
// This class collects rudimentary statistics during translation.
class CodeStats {
CodeStats(const CodeStats &) = delete;
// CodeStats &operator=(const CodeStats &) = delete;
CodeStats &operator=(const CodeStats &) = default;
public:
CodeStats()
......@@ -90,15 +90,6 @@ public:
IceString getTestPrefix() const { return TestPrefix; }
IceString mangleName(const IceString &Name) const;
// The purpose of HasEmitted is to add a header comment at the
// beginning of assembly code emission, doing it once per file
// rather than once per function.
bool testAndSetHasEmittedFirstMethod() {
bool HasEmitted = HasEmittedFirstMethod;
HasEmittedFirstMethod = true;
return HasEmitted;
}
// Manage Constants.
// getConstant*() functions are not const because they might add
// something to the constant pool.
......@@ -214,7 +205,6 @@ private:
const OptLevel Opt;
const IceString TestPrefix;
const ClFlags &Flags;
bool HasEmittedFirstMethod;
RandomNumberGenerator RNG;
std::unique_ptr<ELFObjectWriter> ObjectWriter;
CodeStats StatsFunction;
......
......@@ -25,40 +25,38 @@
namespace Ice {
class LivenessNode {
// TODO: Disable these constructors when Liveness::Nodes is no
// longer an STL container.
// LivenessNode(const LivenessNode &) = delete;
// LivenessNode &operator=(const LivenessNode &) = delete;
public:
LivenessNode() : NumLocals(0), NumNonDeadPhis(0) {}
// NumLocals is the number of Variables local to this block.
SizeT NumLocals;
// NumNonDeadPhis tracks the number of Phi instructions that
// Inst::liveness() identified as tentatively live. If
// NumNonDeadPhis changes from the last liveness pass, then liveness
// has not yet converged.
SizeT NumNonDeadPhis;
// LiveToVarMap maps a liveness bitvector index to a Variable. This
// is generally just for printing/dumping. The index should be less
// than NumLocals + Liveness::NumGlobals.
std::vector<Variable *> LiveToVarMap;
// LiveIn and LiveOut track the in- and out-liveness of the global
// variables. The size of each vector is
// LivenessNode::NumGlobals.
LivenessBV LiveIn, LiveOut;
// LiveBegin and LiveEnd track the instruction numbers of the start
// and end of each variable's live range within this block. The
// index/key of each element is less than NumLocals +
// Liveness::NumGlobals.
LiveBeginEndMap LiveBegin, LiveEnd;
};
class Liveness {
Liveness(const Liveness &) = delete;
Liveness &operator=(const Liveness &) = delete;
class LivenessNode {
LivenessNode &operator=(const LivenessNode &) = delete;
public:
LivenessNode() : NumLocals(0), NumNonDeadPhis(0) {}
LivenessNode(const LivenessNode &) = default;
// NumLocals is the number of Variables local to this block.
SizeT NumLocals;
// NumNonDeadPhis tracks the number of Phi instructions that
// Inst::liveness() identified as tentatively live. If
// NumNonDeadPhis changes from the last liveness pass, then liveness
// has not yet converged.
SizeT NumNonDeadPhis;
// LiveToVarMap maps a liveness bitvector index to a Variable. This
// is generally just for printing/dumping. The index should be less
// than NumLocals + Liveness::NumGlobals.
std::vector<Variable *> LiveToVarMap;
// LiveIn and LiveOut track the in- and out-liveness of the global
// variables. The size of each vector is
// LivenessNode::NumGlobals.
LivenessBV LiveIn, LiveOut;
// LiveBegin and LiveEnd track the instruction numbers of the start
// and end of each variable's live range within this block. The
// index/key of each element is less than NumLocals +
// Liveness::NumGlobals.
LiveBeginEndMap LiveBegin, LiveEnd;
};
public:
Liveness(Cfg *Func, LivenessMode Mode)
: Func(Func), Mode(Mode), NumGlobals(0) {}
......
......@@ -282,12 +282,12 @@ private:
// special value that represents infinite weight, and an addWeight()
// method that ensures that W+infinity=infinity.
class RegWeight {
// RegWeight(const RegWeight &) = delete;
// RegWeight &operator=(const RegWeight &) = delete;
public:
RegWeight() : Weight(0) {}
RegWeight(uint32_t Weight) : Weight(Weight) {}
RegWeight(const RegWeight &) = default;
RegWeight &operator=(const RegWeight &) = default;
const static uint32_t Inf = ~0; // Force regalloc to give a register
const static uint32_t Zero = 0; // Force regalloc NOT to give a register
void addWeight(uint32_t Delta) {
......@@ -526,7 +526,6 @@ typedef std::vector<const Inst *, CfgLocalAllocator<const Inst *> > InstDefList;
// VariableTracking tracks the metadata for a single variable. It is
// only meant to be used internally by VariablesMetadata.
class VariableTracking {
// VariableTracking(const VariableTracking &) = delete;
VariableTracking &operator=(const VariableTracking &) = delete;
public:
......@@ -545,6 +544,7 @@ public:
VariableTracking()
: MultiDef(MDS_Unknown), MultiBlock(MBS_Unknown), SingleUseNode(nullptr),
SingleDefNode(nullptr), FirstOrSingleDefinition(nullptr) {}
VariableTracking(const VariableTracking &) = default;
MultiDefState getMultiDef() const { return MultiDef; }
MultiBlockState getMultiBlock() const { return MultiBlock; }
const Inst *getFirstDefinition() const;
......
......@@ -494,9 +494,7 @@ void LinearScan::scan(const llvm::SmallBitVector &RegMaskFull,
// complexity.
llvm::SmallBitVector PrecoloredUnhandledMask(RegMask.size());
// Note: PrecoloredUnhandledMask is only used for dumping.
for (auto I = UnhandledPrecolored.rbegin(), E = UnhandledPrecolored.rend();
I != E; ++I) {
Variable *Item = *I;
for (Variable *Item : reverse_range(UnhandledPrecolored)) {
assert(Item->hasReg());
if (Cur->rangeEndsBefore(Item))
break;
......@@ -731,8 +729,8 @@ void LinearScan::dump(Cfg *Func) const {
Str << "\n";
}
Str << "++++++ Unhandled:\n";
for (auto I = Unhandled.rbegin(), E = Unhandled.rend(); I != E; ++I) {
dumpLiveRange(*I, Func);
for (const Variable *Item : reverse_range(Unhandled)) {
dumpLiveRange(Item, Func);
Str << "\n";
}
Str << "++++++ Active:\n";
......
......@@ -13,7 +13,6 @@
//
//===----------------------------------------------------------------------===//
#include "llvm/ADT/DenseMap.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/MathExtras.h"
......@@ -927,7 +926,6 @@ void TargetX8632::addProlog(CfgNode *Node) {
void TargetX8632::addEpilog(CfgNode *Node) {
InstList &Insts = Node->getInsts();
InstList::reverse_iterator RI, E;
// TODO(stichnot): Use llvm::make_range with LLVM 3.5.
for (RI = Insts.rbegin(), E = Insts.rend(); RI != E; ++RI) {
if (llvm::isa<InstX8632Ret>(*RI))
break;
......@@ -4242,9 +4240,9 @@ void TargetX8632::lowerPhiAssignments(CfgNode *Node,
// register set, and the lowered instruction numbers may be out of
// order, but that can be worked around by renumbering the block
// afterwards if necessary.
for (auto I = Assignments.rbegin(), E = Assignments.rend(); I != E; ++I) {
for (const Inst &I : reverse_range(Assignments)) {
Context.rewind();
auto Assign = llvm::dyn_cast<InstAssign>(&*I);
auto Assign = llvm::dyn_cast<InstAssign>(&I);
Variable *Dest = Assign->getDest();
Operand *Src = Assign->getSrc(0);
Variable *SrcVar = llvm::dyn_cast<Variable>(Src);
......
......@@ -141,12 +141,11 @@ typedef std::multimap<double, IceString> DumpMapType;
void dumpHelper(Ostream &Str, const DumpMapType &Map, double TotalTime) {
if (!ALLOW_DUMP)
return;
// TODO(stichnot): Use llvm::make_range with LLVM 3.5.
for (auto I = Map.rbegin(), E = Map.rend(); I != E; ++I) {
for (auto &I : reverse_range(Map)) {
char buf[80];
snprintf(buf, llvm::array_lengthof(buf), " %10.6f (%4.1f%%): ", I->first,
I->first * 100 / TotalTime);
Str << buf << I->second << "\n";
snprintf(buf, llvm::array_lengthof(buf), " %10.6f (%4.1f%%): ", I.first,
I.first * 100 / TotalTime);
Str << buf << I.second << "\n";
}
}
......
......@@ -19,33 +19,30 @@
namespace Ice {
class TimerTreeNode;
// Timer tree index type
typedef std::vector<TimerTreeNode>::size_type TTindex;
class TimerStack {
TimerStack &operator=(const TimerStack &) = delete;
// TimerTreeNode represents an interior or leaf node in the call tree.
// It contains a list of children, a pointer to its parent, and the
// timer ID for the node. It also holds the cumulative time spent at
// this node and below. The children are always at a higher index in
// the TimerTreeNode::Nodes array, and the parent is always at a lower
// index.
class TimerTreeNode {
// TimerTreeNode(const TimerTreeNode &) = delete;
TimerTreeNode &operator=(const TimerTreeNode &) = delete;
// Timer tree index type
typedef std::vector<class TimerTreeNode>::size_type TTindex;
public:
TimerTreeNode() : Parent(0), Interior(0), Time(0), UpdateCount(0) {}
std::vector<TTindex> Children; // indexed by TimerIdT
TTindex Parent;
TimerIdT Interior;
double Time;
size_t UpdateCount;
};
// TimerTreeNode represents an interior or leaf node in the call tree.
// It contains a list of children, a pointer to its parent, and the
// timer ID for the node. It also holds the cumulative time spent at
// this node and below. The children are always at a higher index in
// the TimerTreeNode::Nodes array, and the parent is always at a lower
// index.
class TimerTreeNode {
TimerTreeNode &operator=(const TimerTreeNode &) = delete;
class TimerStack {
// TimerStack(const TimerStack &) = delete;
TimerStack &operator=(const TimerStack &) = delete;
public:
TimerTreeNode() : Parent(0), Interior(0), Time(0), UpdateCount(0) {}
TimerTreeNode(const TimerTreeNode &) = default;
std::vector<TTindex> Children; // indexed by TimerIdT
TTindex Parent;
TimerIdT Interior;
double Time;
size_t UpdateCount;
};
public:
enum TimerTag {
......@@ -55,6 +52,7 @@ public:
TT__num
};
TimerStack(const IceString &Name);
TimerStack(const TimerStack &) = default;
TimerIdT getTimerID(const IceString &Name);
void setName(const IceString &NewName) { Name = NewName; }
void push(TimerIdT ID);
......
......@@ -112,10 +112,7 @@ inline StreamType &operator<<(StreamType &Str, const Type &Ty) {
}
/// Models a type signature for a function.
/// TODO(kschimpf): Consider using arena memory allocation for
/// the contents of type signatures.
class FuncSigType {
// FuncSigType(const FuncSigType &Ty) = delete;
FuncSigType &operator=(const FuncSigType &Ty) = delete;
public:
typedef std::vector<Type> ArgListType;
......@@ -123,6 +120,7 @@ public:
// Creates a function signature type with the given return type.
// Parameter types should be added using calls to appendArgType.
FuncSigType() : ReturnType(IceType_void) {}
FuncSigType(const FuncSigType &Ty) = default;
void appendArgType(Type ArgType) { ArgList.push_back(ArgType); }
......
......@@ -49,13 +49,13 @@ static cl::opt<bool> AllowErrorRecovery(
// Use methods setAsSimpleType and setAsFuncSigType to define
// the extended type.
class ExtendedType {
// ExtendedType(const ExtendedType &Ty) = delete;
ExtendedType &operator=(const ExtendedType &Ty) = delete;
public:
/// Discriminator for LLVM-style RTTI.
enum TypeKind { Undefined, Simple, FuncSig };
ExtendedType() : Kind(Undefined) {}
ExtendedType(const ExtendedType &Ty) = default;
virtual ~ExtendedType() {}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment