diff --git a/llvm/lib/CodeGen/LiveDebugValues.cpp b/llvm/lib/CodeGen/LiveDebugValues.cpp index 12451174643c..bca3361ad4cb 100644 --- a/llvm/lib/CodeGen/LiveDebugValues.cpp +++ b/llvm/lib/CodeGen/LiveDebugValues.cpp @@ -1,4 +1,4 @@ -//===------ LiveDebugValues.cpp - Tracking Debug Value MIs ----------------===//G +//===- LiveDebugValues.cpp - Tracking Debug Value MIs ---------------------===// // // The LLVM Compiler Infrastructure // @@ -18,20 +18,32 @@ /// //===----------------------------------------------------------------------===// +#include "llvm/ADT/DenseMap.h" #include "llvm/ADT/PostOrderIterator.h" #include "llvm/ADT/SmallPtrSet.h" +#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/SparseBitVector.h" #include "llvm/ADT/Statistic.h" #include "llvm/ADT/UniqueVector.h" #include "llvm/CodeGen/LexicalScopes.h" +#include "llvm/CodeGen/MachineBasicBlock.h" #include "llvm/CodeGen/MachineFrameInfo.h" #include "llvm/CodeGen/MachineFunction.h" #include "llvm/CodeGen/MachineFunctionPass.h" +#include "llvm/CodeGen/MachineInstr.h" #include "llvm/CodeGen/MachineInstrBuilder.h" #include "llvm/CodeGen/MachineMemOperand.h" #include "llvm/CodeGen/MachineModuleInfo.h" -#include "llvm/CodeGen/Passes.h" -#include "llvm/IR/DebugInfo.h" +#include "llvm/CodeGen/MachineOperand.h" +#include "llvm/CodeGen/PseudoSourceValue.h" +#include "llvm/IR/DebugInfoMetadata.h" +#include "llvm/IR/DebugLoc.h" +#include "llvm/IR/Function.h" +#include "llvm/IR/Module.h" +#include "llvm/MC/MCRegisterInfo.h" +#include "llvm/Pass.h" +#include "llvm/Support/Casting.h" +#include "llvm/Support/Compiler.h" #include "llvm/Support/Debug.h" #include "llvm/Support/raw_ostream.h" #include "llvm/Target/TargetFrameLowering.h" @@ -39,8 +51,13 @@ #include "llvm/Target/TargetLowering.h" #include "llvm/Target/TargetRegisterInfo.h" #include "llvm/Target/TargetSubtargetInfo.h" -#include +#include +#include +#include +#include #include +#include +#include using namespace llvm; @@ -48,8 +65,6 @@ using namespace llvm; STATISTIC(NumInserted, "Number of DBG_VALUE instructions inserted"); -namespace { - // \brief If @MI is a DBG_VALUE with debug value described by a defined // register, returns the number of this register. In the other case, returns 0. static unsigned isDbgValueDescribedByReg(const MachineInstr &MI) { @@ -60,8 +75,9 @@ static unsigned isDbgValueDescribedByReg(const MachineInstr &MI) { return MI.getOperand(0).isReg() ? MI.getOperand(0).getReg() : 0; } -class LiveDebugValues : public MachineFunctionPass { +namespace { +class LiveDebugValues : public MachineFunctionPass { private: const TargetRegisterInfo *TRI; const TargetInstrInfo *TII; @@ -88,15 +104,15 @@ private: }; /// Based on std::pair so it can be used as an index into a DenseMap. - typedef std::pair - DebugVariableBase; + using DebugVariableBase = + std::pair; /// A potentially inlined instance of a variable. struct DebugVariable : public DebugVariableBase { DebugVariable(const DILocalVariable *Var, const DILocation *InlinedAt) : DebugVariableBase(Var, InlinedAt) {} - const DILocalVariable *getVar() const { return this->first; }; - const DILocation *getInlinedAt() const { return this->second; }; + const DILocalVariable *getVar() const { return this->first; } + const DILocation *getInlinedAt() const { return this->second; } bool operator<(const DebugVariable &DV) const { if (getVar() == DV.getVar()) @@ -110,7 +126,7 @@ private: const DebugVariable Var; const MachineInstr &MI; ///< Only used for cloning a new DBG_VALUE. mutable UserValueScopes UVS; - enum { InvalidKind = 0, RegisterKind } Kind; + enum { InvalidKind = 0, RegisterKind } Kind = InvalidKind; /// The value location. Stored separately to avoid repeatedly /// extracting it from MI. @@ -121,7 +137,7 @@ private: VarLoc(const MachineInstr &MI, LexicalScopes &LS) : Var(MI.getDebugVariable(), MI.getDebugLoc()->getInlinedAt()), MI(MI), - UVS(MI.getDebugLoc(), LS), Kind(InvalidKind) { + UVS(MI.getDebugLoc(), LS) { static_assert((sizeof(Loc) == sizeof(uint64_t)), "hash does not cover all members of Loc"); assert(MI.isDebugValue() && "not a DBG_VALUE"); @@ -160,14 +176,14 @@ private: } }; - typedef UniqueVector VarLocMap; - typedef SparseBitVector<> VarLocSet; - typedef SmallDenseMap VarLocInMBB; + using VarLocMap = UniqueVector; + using VarLocSet = SparseBitVector<>; + using VarLocInMBB = SmallDenseMap; struct SpillDebugPair { MachineInstr *SpillInst; MachineInstr *DebugInst; }; - typedef SmallVector SpillMap; + using SpillMap = SmallVector; /// This holds the working set of currently open ranges. For fast /// access, this is done both as a set of VarLocIDs, and a map of @@ -263,14 +279,16 @@ public: bool runOnMachineFunction(MachineFunction &MF) override; }; -} // namespace +} // end anonymous namespace //===----------------------------------------------------------------------===// // Implementation //===----------------------------------------------------------------------===// char LiveDebugValues::ID = 0; + char &llvm::LiveDebugValuesID = LiveDebugValues::ID; + INITIALIZE_PASS(LiveDebugValues, DEBUG_TYPE, "Live DEBUG_VALUE analysis", false, false) @@ -586,7 +604,6 @@ bool LiveDebugValues::join(MachineBasicBlock &MBB, VarLocInMBB &OutLocs, /// Calculate the liveness information for the given machine function and /// extend ranges across basic blocks. bool LiveDebugValues::ExtendRanges(MachineFunction &MF) { - DEBUG(dbgs() << "\nDebug Range Extension\n"); bool Changed = false; diff --git a/llvm/lib/CodeGen/LiveDebugVariables.cpp b/llvm/lib/CodeGen/LiveDebugVariables.cpp index cb9340826f4d..6f09592a37ea 100644 --- a/llvm/lib/CodeGen/LiveDebugVariables.cpp +++ b/llvm/lib/CodeGen/LiveDebugVariables.cpp @@ -20,28 +20,44 @@ //===----------------------------------------------------------------------===// #include "LiveDebugVariables.h" +#include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/DenseMap.h" #include "llvm/ADT/IntervalMap.h" +#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallSet.h" +#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/Statistic.h" +#include "llvm/ADT/StringRef.h" #include "llvm/CodeGen/LexicalScopes.h" +#include "llvm/CodeGen/LiveInterval.h" #include "llvm/CodeGen/LiveIntervalAnalysis.h" +#include "llvm/CodeGen/MachineBasicBlock.h" #include "llvm/CodeGen/MachineDominators.h" #include "llvm/CodeGen/MachineFunction.h" +#include "llvm/CodeGen/MachineInstr.h" #include "llvm/CodeGen/MachineInstrBuilder.h" +#include "llvm/CodeGen/MachineOperand.h" #include "llvm/CodeGen/MachineRegisterInfo.h" -#include "llvm/CodeGen/Passes.h" +#include "llvm/CodeGen/SlotIndexes.h" #include "llvm/CodeGen/VirtRegMap.h" -#include "llvm/IR/Constants.h" -#include "llvm/IR/DebugInfo.h" +#include "llvm/IR/DebugInfoMetadata.h" +#include "llvm/IR/DebugLoc.h" +#include "llvm/IR/Function.h" #include "llvm/IR/Metadata.h" -#include "llvm/IR/Value.h" +#include "llvm/MC/MCRegisterInfo.h" +#include "llvm/Pass.h" +#include "llvm/Support/Casting.h" #include "llvm/Support/CommandLine.h" +#include "llvm/Support/Compiler.h" #include "llvm/Support/Debug.h" #include "llvm/Support/raw_ostream.h" #include "llvm/Target/TargetInstrInfo.h" -#include "llvm/Target/TargetMachine.h" +#include "llvm/Target/TargetOpcodes.h" #include "llvm/Target/TargetRegisterInfo.h" #include "llvm/Target/TargetSubtargetInfo.h" +#include +#include +#include #include #include @@ -54,6 +70,7 @@ EnableLDV("live-debug-variables", cl::init(true), cl::desc("Enable the live debug variables pass"), cl::Hidden); STATISTIC(NumInsertedDebugValues, "Number of DBG_VALUEs inserted"); + char LiveDebugVariables::ID = 0; INITIALIZE_PASS_BEGIN(LiveDebugVariables, DEBUG_TYPE, @@ -70,12 +87,16 @@ void LiveDebugVariables::getAnalysisUsage(AnalysisUsage &AU) const { MachineFunctionPass::getAnalysisUsage(AU); } -LiveDebugVariables::LiveDebugVariables() : MachineFunctionPass(ID), pImpl(nullptr) { +LiveDebugVariables::LiveDebugVariables() : MachineFunctionPass(ID) { initializeLiveDebugVariablesPass(*PassRegistry::getPassRegistry()); } /// LocMap - Map of where a user value is live, and its location. -typedef IntervalMap LocMap; +using LocMap = IntervalMap; + +namespace { + +class LDVImpl; /// UserValue - A user value is a part of a debug info user variable. /// @@ -86,8 +107,6 @@ typedef IntervalMap LocMap; /// user values are related if they refer to the same variable, or if they are /// held by the same virtual register. The equivalence class is the transitive /// closure of that relation. -namespace { -class LDVImpl; class UserValue { const MDNode *Variable; ///< The debug info variable we are part of. const MDNode *Expression; ///< Any complex address expression. @@ -95,7 +114,7 @@ class UserValue { DebugLoc dl; ///< The debug location for the variable. This is ///< used by dwarf writer to find lexical scope. UserValue *leader; ///< Equivalence class leader. - UserValue *next; ///< Next value in equivalence class, or null. + UserValue *next = nullptr; ///< Next value in equivalence class, or null. /// Numbered locations referenced by locmap. SmallVector locations; @@ -126,7 +145,7 @@ public: UserValue(const MDNode *var, const MDNode *expr, bool i, DebugLoc L, LocMap::Allocator &alloc) : Variable(var), Expression(expr), IsIndirect(i), dl(std::move(L)), - leader(this), next(nullptr), locInts(alloc) {} + leader(this), locInts(alloc) {} /// getLeader - Get the leader of this value's equivalence class. UserValue *getLeader() { @@ -227,10 +246,10 @@ public: /// @param Kills Points where the range of LocNo could be extended. /// @param NewDefs Append (Idx, LocNo) of inserted defs here. void addDefsFromCopies(LiveInterval *LI, unsigned LocNo, - const SmallVectorImpl &Kills, - SmallVectorImpl > &NewDefs, - MachineRegisterInfo &MRI, - LiveIntervals &LIS); + const SmallVectorImpl &Kills, + SmallVectorImpl> &NewDefs, + MachineRegisterInfo &MRI, + LiveIntervals &LIS); /// computeIntervals - Compute the live intervals of all locations after /// collecting all their def points. @@ -252,33 +271,33 @@ public: /// getDebugLoc - Return DebugLoc of this UserValue. DebugLoc getDebugLoc() { return dl;} + void print(raw_ostream &, const TargetRegisterInfo *); }; -} // namespace /// LDVImpl - Implementation of the LiveDebugVariables pass. -namespace { class LDVImpl { LiveDebugVariables &pass; LocMap::Allocator allocator; - MachineFunction *MF; + MachineFunction *MF = nullptr; LiveIntervals *LIS; const TargetRegisterInfo *TRI; /// Whether emitDebugValues is called. - bool EmitDone; + bool EmitDone = false; + /// Whether the machine function is modified during the pass. - bool ModifiedMF; + bool ModifiedMF = false; /// userValues - All allocated UserValue instances. SmallVector, 8> userValues; /// Map virtual register to eq class leader. - typedef DenseMap VRMap; + using VRMap = DenseMap; VRMap virtRegToEqClass; /// Map user variable to eq class leader. - typedef DenseMap UVMap; + using UVMap = DenseMap; UVMap userVarMap; /// getUserValue - Find or create a UserValue. @@ -305,8 +324,8 @@ class LDVImpl { void computeIntervals(); public: - LDVImpl(LiveDebugVariables *ps) - : pass(*ps), MF(nullptr), EmitDone(false), ModifiedMF(false) {} + LDVImpl(LiveDebugVariables *ps) : pass(*ps) {} + bool runOnMachineFunction(MachineFunction &mf); /// clear - Release all memory. @@ -333,7 +352,8 @@ public: void print(raw_ostream&); }; -} // namespace + +} // end anonymous namespace #ifndef NDEBUG static void printDebugLoc(const DebugLoc &DL, raw_ostream &CommentOS, @@ -446,7 +466,7 @@ UserValue *LDVImpl::getUserValue(const MDNode *Var, const MDNode *Expr, } userValues.push_back( - make_unique(Var, Expr, IsIndirect, DL, allocator)); + llvm::make_unique(Var, Expr, IsIndirect, DL, allocator)); UserValue *UV = userValues.back().get(); Leader = UserValue::merge(Leader, UV); return UV; @@ -564,9 +584,9 @@ void UserValue::extendDef(SlotIndex Idx, unsigned LocNo, LiveRange *LR, void UserValue::addDefsFromCopies(LiveInterval *LI, unsigned LocNo, - const SmallVectorImpl &Kills, - SmallVectorImpl > &NewDefs, - MachineRegisterInfo &MRI, LiveIntervals &LIS) { + const SmallVectorImpl &Kills, + SmallVectorImpl> &NewDefs, + MachineRegisterInfo &MRI, LiveIntervals &LIS) { if (Kills.empty()) return; // Don't track copies from physregs, there are too many uses. diff --git a/llvm/lib/CodeGen/LiveDebugVariables.h b/llvm/lib/CodeGen/LiveDebugVariables.h index 1d7e3d4371a2..aa35880b063a 100644 --- a/llvm/lib/CodeGen/LiveDebugVariables.h +++ b/llvm/lib/CodeGen/LiveDebugVariables.h @@ -1,4 +1,4 @@ -//===- LiveDebugVariables.h - Tracking debug info variables ----*- c++ -*--===// +//===- LiveDebugVariables.h - Tracking debug info variables -----*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -22,17 +22,16 @@ #define LLVM_LIB_CODEGEN_LIVEDEBUGVARIABLES_H #include "llvm/CodeGen/MachineFunctionPass.h" -#include "llvm/IR/DebugInfo.h" +#include "llvm/Support/Compiler.h" namespace llvm { template class ArrayRef; -class LiveInterval; class LiveIntervals; class VirtRegMap; class LLVM_LIBRARY_VISIBILITY LiveDebugVariables : public MachineFunctionPass { - void *pImpl; + void *pImpl = nullptr; public: static char ID; // Pass identification, replacement for typeid @@ -62,14 +61,12 @@ public: void dump() const; private: - bool runOnMachineFunction(MachineFunction &) override; void releaseMemory() override; void getAnalysisUsage(AnalysisUsage &) const override; bool doInitialization(Module &) override; - }; -} // namespace llvm +} // end namespace llvm -#endif +#endif // LLVM_LIB_CODEGEN_LIVEDEBUGVARIABLES_H diff --git a/llvm/lib/CodeGen/LiveInterval.cpp b/llvm/lib/CodeGen/LiveInterval.cpp index 9ef9f238fdce..ac19d7b01393 100644 --- a/llvm/lib/CodeGen/LiveInterval.cpp +++ b/llvm/lib/CodeGen/LiveInterval.cpp @@ -1,4 +1,4 @@ -//===-- LiveInterval.cpp - Live Interval Representation -------------------===// +//===- LiveInterval.cpp - Live Interval Representation --------------------===// // // The LLVM Compiler Infrastructure // @@ -19,20 +19,34 @@ //===----------------------------------------------------------------------===// #include "llvm/CodeGen/LiveInterval.h" - #include "LiveRangeUtils.h" #include "RegisterCoalescer.h" +#include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/STLExtras.h" -#include "llvm/ADT/SmallSet.h" +#include "llvm/ADT/SmallPtrSet.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/iterator_range.h" #include "llvm/CodeGen/LiveIntervalAnalysis.h" +#include "llvm/CodeGen/MachineBasicBlock.h" +#include "llvm/CodeGen/MachineInstr.h" +#include "llvm/CodeGen/MachineOperand.h" #include "llvm/CodeGen/MachineRegisterInfo.h" +#include "llvm/CodeGen/SlotIndexes.h" +#include "llvm/MC/LaneBitmask.h" +#include "llvm/Support/Compiler.h" #include "llvm/Support/Debug.h" #include "llvm/Support/raw_ostream.h" #include "llvm/Target/TargetRegisterInfo.h" #include +#include +#include +#include +#include + using namespace llvm; namespace { + //===----------------------------------------------------------------------===// // Implementation of various methods necessary for calculation of live ranges. // The implementation of the methods abstracts from the concrete type of the @@ -56,8 +70,8 @@ protected: CalcLiveRangeUtilBase(LiveRange *LR) : LR(LR) {} public: - typedef LiveRange::Segment Segment; - typedef IteratorT iterator; + using Segment = LiveRange::Segment; + using iterator = IteratorT; /// A counterpart of LiveRange::createDeadDef: Make sure the range has a /// value defined at @p Def. @@ -265,8 +279,9 @@ private: //===----------------------------------------------------------------------===// class CalcLiveRangeUtilVector; -typedef CalcLiveRangeUtilBase CalcLiveRangeUtilVectorBase; +using CalcLiveRangeUtilVectorBase = + CalcLiveRangeUtilBase; class CalcLiveRangeUtilVector : public CalcLiveRangeUtilVectorBase { public: @@ -292,9 +307,9 @@ private: //===----------------------------------------------------------------------===// class CalcLiveRangeUtilSet; -typedef CalcLiveRangeUtilBase CalcLiveRangeUtilSetBase; +using CalcLiveRangeUtilSetBase = + CalcLiveRangeUtilBase; class CalcLiveRangeUtilSet : public CalcLiveRangeUtilSetBase { public: @@ -327,7 +342,8 @@ private: return I; } }; -} // namespace + +} // end anonymous namespace //===----------------------------------------------------------------------===// // LiveRange methods @@ -444,7 +460,7 @@ bool LiveRange::overlaps(const LiveRange &Other, const CoalescerPair &CP, if (J == JE) return false; - for (;;) { + while (true) { // J has just been advanced to satisfy: assert(J->end >= I->start); // Check for an overlap. @@ -865,7 +881,6 @@ void LiveInterval::clearSubRanges() { void LiveInterval::refineSubRanges(BumpPtrAllocator &Allocator, LaneBitmask LaneMask, std::function Apply) { - LaneBitmask ToApply = LaneMask; for (SubRange &SR : subranges()) { LaneBitmask SRMask = SR.LaneMask; @@ -925,8 +940,8 @@ void LiveInterval::computeSubRangeUndefs(SmallVectorImpl &Undefs, } } -raw_ostream& llvm::operator<<(raw_ostream& os, const LiveRange::Segment &S) { - return os << '[' << S.start << ',' << S.end << ':' << S.valno->id << ')'; +raw_ostream& llvm::operator<<(raw_ostream& OS, const LiveRange::Segment &S) { + return OS << '[' << S.start << ',' << S.end << ':' << S.valno->id << ')'; } #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) @@ -1033,7 +1048,6 @@ void LiveInterval::verify(const MachineRegisterInfo *MRI) const { } #endif - //===----------------------------------------------------------------------===// // LiveRangeUpdater class //===----------------------------------------------------------------------===// diff --git a/llvm/lib/CodeGen/LiveRangeCalc.cpp b/llvm/lib/CodeGen/LiveRangeCalc.cpp index 8c43c9f3f884..befce3593b15 100644 --- a/llvm/lib/CodeGen/LiveRangeCalc.cpp +++ b/llvm/lib/CodeGen/LiveRangeCalc.cpp @@ -1,4 +1,4 @@ -//===---- LiveRangeCalc.cpp - Calculate live ranges -----------------------===// +//===- LiveRangeCalc.cpp - Calculate live ranges --------------------------===// // // The LLVM Compiler Infrastructure // @@ -12,9 +12,27 @@ //===----------------------------------------------------------------------===// #include "LiveRangeCalc.h" +#include "llvm/ADT/BitVector.h" +#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SetVector.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/CodeGen/LiveInterval.h" +#include "llvm/CodeGen/MachineBasicBlock.h" #include "llvm/CodeGen/MachineDominators.h" +#include "llvm/CodeGen/MachineFunction.h" +#include "llvm/CodeGen/MachineInstr.h" +#include "llvm/CodeGen/MachineOperand.h" #include "llvm/CodeGen/MachineRegisterInfo.h" +#include "llvm/CodeGen/SlotIndexes.h" +#include "llvm/MC/LaneBitmask.h" +#include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/raw_ostream.h" +#include "llvm/Target/TargetRegisterInfo.h" +#include +#include +#include +#include +#include using namespace llvm; @@ -44,7 +62,6 @@ void LiveRangeCalc::reset(const MachineFunction *mf, LiveIn.clear(); } - static void createDeadDef(SlotIndexes &Indexes, VNInfo::Allocator &Alloc, LiveRange &LR, const MachineOperand &MO) { const MachineInstr &MI = *MO.getParent(); @@ -136,7 +153,6 @@ void LiveRangeCalc::createDeadDefs(LiveRange &LR, unsigned Reg) { createDeadDef(*Indexes, *Alloc, LR, MO); } - void LiveRangeCalc::extendToUses(LiveRange &LR, unsigned Reg, LaneBitmask Mask, LiveInterval *LI) { SmallVector Undefs; @@ -197,7 +213,6 @@ void LiveRangeCalc::extendToUses(LiveRange &LR, unsigned Reg, LaneBitmask Mask, } } - void LiveRangeCalc::updateFromLiveIns() { LiveRangeUpdater Updater; for (const LiveInBlock &I : LiveIn) { @@ -248,7 +263,6 @@ void LiveRangeCalc::extend(LiveRange &LR, SlotIndex Use, unsigned PhysReg, calculateValues(); } - // This function is called by a client after using the low-level API to add // live-out and live-in blocks. The unique value optimization is not // available, SplitEditor::transferValues handles that case directly anyway. @@ -259,7 +273,6 @@ void LiveRangeCalc::calculateValues() { updateFromLiveIns(); } - bool LiveRangeCalc::isDefOnEntry(LiveRange &LR, ArrayRef Undefs, MachineBasicBlock &MBB, BitVector &DefOnEntry, BitVector &UndefOnEntry) { @@ -410,7 +423,7 @@ bool LiveRangeCalc::findReachingDefs(LiveRange &LR, MachineBasicBlock &UseMBB, LiveIn.clear(); FoundUndef |= (TheVNI == nullptr || TheVNI == &UndefVNI); - if (Undefs.size() > 0 && FoundUndef) + if (!Undefs.empty() && FoundUndef) UniqueVNI = false; // Both updateSSA() and LiveRangeUpdater benefit from ordered blocks, but @@ -454,7 +467,7 @@ bool LiveRangeCalc::findReachingDefs(LiveRange &LR, MachineBasicBlock &UseMBB, LiveIn.reserve(WorkList.size()); for (unsigned BN : WorkList) { MachineBasicBlock *MBB = MF->getBlockNumbered(BN); - if (Undefs.size() > 0 && + if (!Undefs.empty() && !isDefOnEntry(LR, Undefs, *MBB, DefOnEntry, UndefOnEntry)) continue; addLiveInBlock(LR, DomTree->getNode(MBB)); @@ -465,7 +478,6 @@ bool LiveRangeCalc::findReachingDefs(LiveRange &LR, MachineBasicBlock &UseMBB, return false; } - // This is essentially the same iterative algorithm that SSAUpdater uses, // except we already have a dominator tree, so we don't have to recompute it. void LiveRangeCalc::updateSSA() { diff --git a/llvm/lib/CodeGen/LiveRangeCalc.h b/llvm/lib/CodeGen/LiveRangeCalc.h index d41b782d9bdf..c4914f23f56d 100644 --- a/llvm/lib/CodeGen/LiveRangeCalc.h +++ b/llvm/lib/CodeGen/LiveRangeCalc.h @@ -1,4 +1,4 @@ -//===---- LiveRangeCalc.h - Calculate live ranges ---------------*- C++ -*-===// +//===- LiveRangeCalc.h - Calculate live ranges ------------------*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -26,28 +26,35 @@ #include "llvm/ADT/BitVector.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/IndexedMap.h" +#include "llvm/ADT/SmallVector.h" #include "llvm/CodeGen/LiveInterval.h" +#include "llvm/CodeGen/MachineBasicBlock.h" +#include "llvm/CodeGen/SlotIndexes.h" +#include "llvm/MC/LaneBitmask.h" +#include namespace llvm { -/// Forward declarations for MachineDominators.h: -class MachineDominatorTree; template class DomTreeNodeBase; -typedef DomTreeNodeBase MachineDomTreeNode; +class MachineDominatorTree; +class MachineFunction; +class MachineRegisterInfo; + +using MachineDomTreeNode = DomTreeNodeBase; class LiveRangeCalc { - const MachineFunction *MF; - const MachineRegisterInfo *MRI; - SlotIndexes *Indexes; - MachineDominatorTree *DomTree; - VNInfo::Allocator *Alloc; + const MachineFunction *MF = nullptr; + const MachineRegisterInfo *MRI = nullptr; + SlotIndexes *Indexes = nullptr; + MachineDominatorTree *DomTree = nullptr; + VNInfo::Allocator *Alloc = nullptr; /// LiveOutPair - A value and the block that defined it. The domtree node is /// redundant, it can be computed as: MDT[Indexes.getMBBFromIndex(VNI->def)]. - typedef std::pair LiveOutPair; + using LiveOutPair = std::pair; /// LiveOutMap - Map basic blocks to the value leaving the block. - typedef IndexedMap LiveOutMap; + using LiveOutMap = IndexedMap; /// Bit vector of active entries in LiveOut, also used as a visited set by /// findReachingDefs. One entry per basic block, indexed by block number. @@ -66,7 +73,7 @@ class LiveRangeCalc { /// registers do not overlap), but the defined/undefined information must /// be kept separate for each individual range. /// By convention, EntryInfoMap[&LR] = { Defined, Undefined }. - typedef DenseMap> EntryInfoMap; + using EntryInfoMap = DenseMap>; EntryInfoMap EntryInfos; /// Map each basic block where a live range is live out to the live-out value @@ -105,10 +112,10 @@ class LiveRangeCalc { SlotIndex Kill; // Live-in value filled in by updateSSA once it is known. - VNInfo *Value; + VNInfo *Value = nullptr; LiveInBlock(LiveRange &LR, MachineDomTreeNode *node, SlotIndex kill) - : LR(LR), DomNode(node), Kill(kill), Value(nullptr) {} + : LR(LR), DomNode(node), Kill(kill) {} }; /// LiveIn - Work list of blocks where the live-in value has yet to be @@ -171,8 +178,7 @@ class LiveRangeCalc { void resetLiveOutMap(); public: - LiveRangeCalc() : MF(nullptr), MRI(nullptr), Indexes(nullptr), - DomTree(nullptr), Alloc(nullptr) {} + LiveRangeCalc() = default; //===--------------------------------------------------------------------===// // High-level interface. @@ -186,10 +192,8 @@ public: /// that may overlap a previously computed live range, and before the first /// live range in a function. If live ranges are not known to be /// non-overlapping, call reset before each. - void reset(const MachineFunction *MF, - SlotIndexes*, - MachineDominatorTree*, - VNInfo::Allocator*); + void reset(const MachineFunction *mf, SlotIndexes *SI, + MachineDominatorTree *MDT, VNInfo::Allocator *VNIA); //===--------------------------------------------------------------------===// // Mid-level interface. @@ -282,4 +286,4 @@ public: } // end namespace llvm -#endif +#endif // LLVM_LIB_CODEGEN_LIVERANGECALC_H diff --git a/llvm/lib/CodeGen/LiveRangeShrink.cpp b/llvm/lib/CodeGen/LiveRangeShrink.cpp index 552f4b5393fe..29867cd57bae 100644 --- a/llvm/lib/CodeGen/LiveRangeShrink.cpp +++ b/llvm/lib/CodeGen/LiveRangeShrink.cpp @@ -1,4 +1,4 @@ -//===-- LiveRangeShrink.cpp - Move instructions to shrink live range ------===// +//===- LiveRangeShrink.cpp - Move instructions to shrink live range -------===// // // The LLVM Compiler Infrastructure // @@ -14,20 +14,32 @@ /// uses, all of which are the only use of the def. /// ///===---------------------------------------------------------------------===// + +#include "llvm/ADT/DenseMap.h" #include "llvm/ADT/Statistic.h" +#include "llvm/ADT/iterator_range.h" +#include "llvm/CodeGen/MachineBasicBlock.h" +#include "llvm/CodeGen/MachineFunction.h" #include "llvm/CodeGen/MachineFunctionPass.h" #include "llvm/CodeGen/MachineRegisterInfo.h" -#include "llvm/CodeGen/Passes.h" +#include "llvm/CodeGen/MachineInstr.h" +#include "llvm/CodeGen/MachineOperand.h" +#include "llvm/Pass.h" #include "llvm/Support/Debug.h" +#include "llvm/Support/raw_ostream.h" +#include "llvm/Target/TargetRegisterInfo.h" +#include +#include + +using namespace llvm; #define DEBUG_TYPE "lrshrink" STATISTIC(NumInstrsHoistedToShrinkLiveRange, "Number of insructions hoisted to shrink live range."); -using namespace llvm; - namespace { + class LiveRangeShrink : public MachineFunctionPass { public: static char ID; @@ -45,23 +57,26 @@ public: bool runOnMachineFunction(MachineFunction &MF) override; }; -} // End anonymous namespace. + +} // end anonymous namespace char LiveRangeShrink::ID = 0; + char &llvm::LiveRangeShrinkID = LiveRangeShrink::ID; INITIALIZE_PASS(LiveRangeShrink, "lrshrink", "Live Range Shrink Pass", false, false) -namespace { -typedef DenseMap InstOrderMap; + +using InstOrderMap = DenseMap; /// Returns \p New if it's dominated by \p Old, otherwise return \p Old. /// \p M maintains a map from instruction to its dominating order that satisfies /// M[A] > M[B] guarantees that A is dominated by B. /// If \p New is not in \p M, return \p Old. Otherwise if \p Old is null, return /// \p New. -MachineInstr *FindDominatedInstruction(MachineInstr &New, MachineInstr *Old, - const InstOrderMap &M) { +static MachineInstr *FindDominatedInstruction(MachineInstr &New, + MachineInstr *Old, + const InstOrderMap &M) { auto NewIter = M.find(&New); if (NewIter == M.end()) return Old; @@ -82,13 +97,13 @@ MachineInstr *FindDominatedInstruction(MachineInstr &New, MachineInstr *Old, /// Builds Instruction to its dominating order number map \p M by traversing /// from instruction \p Start. -void BuildInstOrderMap(MachineBasicBlock::iterator Start, InstOrderMap &M) { +static void BuildInstOrderMap(MachineBasicBlock::iterator Start, + InstOrderMap &M) { M.clear(); unsigned i = 0; for (MachineInstr &I : make_range(Start, Start->getParent()->end())) M[&I] = i++; } -} // end anonymous namespace bool LiveRangeShrink::runOnMachineFunction(MachineFunction &MF) { if (skipFunction(*MF.getFunction())) diff --git a/llvm/lib/CodeGen/MachineBlockFrequencyInfo.cpp b/llvm/lib/CodeGen/MachineBlockFrequencyInfo.cpp index 4d1ec11df46c..104180ad4d2d 100644 --- a/llvm/lib/CodeGen/MachineBlockFrequencyInfo.cpp +++ b/llvm/lib/CodeGen/MachineBlockFrequencyInfo.cpp @@ -12,23 +12,23 @@ //===----------------------------------------------------------------------===// #include "llvm/CodeGen/MachineBlockFrequencyInfo.h" +#include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/None.h" +#include "llvm/ADT/iterator.h" #include "llvm/Analysis/BlockFrequencyInfoImpl.h" +#include "llvm/CodeGen/MachineBasicBlock.h" #include "llvm/CodeGen/MachineBranchProbabilityInfo.h" #include "llvm/CodeGen/MachineFunction.h" #include "llvm/CodeGen/MachineLoopInfo.h" -#include "llvm/CodeGen/Passes.h" -#include "llvm/InitializePasses.h" +#include "llvm/Pass.h" #include "llvm/Support/CommandLine.h" -#include "llvm/Support/Debug.h" -#include "llvm/Support/Format.h" #include "llvm/Support/GraphWriter.h" -#include "llvm/Support/raw_ostream.h" +#include using namespace llvm; #define DEBUG_TYPE "machine-block-freq" - static cl::opt ViewMachineBlockFreqPropagationDAG( "view-machine-block-freq-propagation-dags", cl::Hidden, cl::desc("Pop up a window to show a dag displaying how machine block " @@ -42,6 +42,7 @@ static cl::opt ViewMachineBlockFreqPropagationDAG( "integer fractional block frequency representation."), clEnumValN(GVDT_Count, "count", "display a graph using the real " "profile count if available."))); + // Similar option above, but used to control BFI display only after MBP pass cl::opt ViewBlockLayoutWithBFI( "view-block-layout-with-bfi", cl::Hidden, @@ -62,6 +63,7 @@ cl::opt ViewBlockLayoutWithBFI( // Command line option to specify the name of the function for CFG dump // Defined in Analysis/BlockFrequencyInfo.cpp: -view-bfi-func-name= extern cl::opt ViewBlockFreqFuncName; + // Command line option to specify hot frequency threshold. // Defined in Analysis/BlockFrequencyInfo.cpp: -view-hot-freq-perc= extern cl::opt ViewHotFreqPercent; @@ -76,9 +78,9 @@ static GVDAGType getGVDT() { namespace llvm { template <> struct GraphTraits { - typedef const MachineBasicBlock *NodeRef; - typedef MachineBasicBlock::const_succ_iterator ChildIteratorType; - typedef pointer_iterator nodes_iterator; + using NodeRef = const MachineBasicBlock *; + using ChildIteratorType = MachineBasicBlock::const_succ_iterator; + using nodes_iterator = pointer_iterator; static NodeRef getEntryNode(const MachineBlockFrequencyInfo *G) { return &G->getFunction()->front(); @@ -99,21 +101,21 @@ template <> struct GraphTraits { } }; -typedef BFIDOTGraphTraitsBase - MBFIDOTGraphTraitsBase; +using MBFIDOTGraphTraitsBase = + BFIDOTGraphTraitsBase; + template <> struct DOTGraphTraits : public MBFIDOTGraphTraitsBase { - explicit DOTGraphTraits(bool isSimple = false) - : MBFIDOTGraphTraitsBase(isSimple), CurFunc(nullptr), LayoutOrderMap() {} - - const MachineFunction *CurFunc; + const MachineFunction *CurFunc = nullptr; DenseMap LayoutOrderMap; + explicit DOTGraphTraits(bool isSimple = false) + : MBFIDOTGraphTraitsBase(isSimple) {} + std::string getNodeLabel(const MachineBasicBlock *Node, const MachineBlockFrequencyInfo *Graph) { - int layout_order = -1; // Attach additional ordering information if 'isSimple' is false. if (!isSimple()) { @@ -163,7 +165,7 @@ MachineBlockFrequencyInfo::MachineBlockFrequencyInfo() initializeMachineBlockFrequencyInfoPass(*PassRegistry::getPassRegistry()); } -MachineBlockFrequencyInfo::~MachineBlockFrequencyInfo() {} +MachineBlockFrequencyInfo::~MachineBlockFrequencyInfo() = default; void MachineBlockFrequencyInfo::getAnalysisUsage(AnalysisUsage &AU) const { AU.addRequired(); diff --git a/llvm/lib/CodeGen/MachineBlockPlacement.cpp b/llvm/lib/CodeGen/MachineBlockPlacement.cpp index c30f306a169c..f135cf715936 100644 --- a/llvm/lib/CodeGen/MachineBlockPlacement.cpp +++ b/llvm/lib/CodeGen/MachineBlockPlacement.cpp @@ -1,4 +1,4 @@ -//===-- MachineBlockPlacement.cpp - Basic Block Code Layout optimization --===// +//===- MachineBlockPlacement.cpp - Basic Block Code Layout optimization ---===// // // The LLVM Compiler Infrastructure // @@ -26,7 +26,10 @@ //===----------------------------------------------------------------------===// #include "BranchFolding.h" +#include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/SetVector.h" #include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/Statistic.h" @@ -39,19 +42,33 @@ #include "llvm/CodeGen/MachineLoopInfo.h" #include "llvm/CodeGen/MachineModuleInfo.h" #include "llvm/CodeGen/MachinePostDominators.h" -#include "llvm/CodeGen/Passes.h" #include "llvm/CodeGen/TailDuplicator.h" #include "llvm/CodeGen/TargetPassConfig.h" +#include "llvm/IR/DebugLoc.h" +#include "llvm/IR/Function.h" +#include "llvm/Pass.h" #include "llvm/Support/Allocator.h" +#include "llvm/Support/BlockFrequency.h" +#include "llvm/Support/BranchProbability.h" +#include "llvm/Support/CodeGen.h" #include "llvm/Support/CommandLine.h" +#include "llvm/Support/Compiler.h" #include "llvm/Support/Debug.h" #include "llvm/Support/raw_ostream.h" #include "llvm/Target/TargetInstrInfo.h" #include "llvm/Target/TargetLowering.h" +#include "llvm/Target/TargetMachine.h" #include "llvm/Target/TargetSubtargetInfo.h" #include -#include +#include +#include +#include +#include +#include +#include #include +#include + using namespace llvm; #define DEBUG_TYPE "block-placement" @@ -101,6 +118,7 @@ static cl::opt cl::desc("Model the cost of loop rotation more " "precisely by using profile data."), cl::init(false), cl::Hidden); + static cl::opt ForcePreciseRotationCost("force-precise-rotation-cost", cl::desc("Force the use of precise cost " @@ -177,12 +195,12 @@ extern cl::opt ViewBlockLayoutWithBFI; extern cl::opt ViewBlockFreqFuncName; namespace { -class BlockChain; -/// \brief Type for our function-wide basic block -> block chain mapping. -typedef DenseMap BlockToChainMapType; -} -namespace { +class BlockChain; + +/// \brief Type for our function-wide basic block -> block chain mapping. +using BlockToChainMapType = DenseMap; + /// \brief A chain of blocks which will be laid out contiguously. /// /// This is the datastructure representing a chain of consecutive blocks that @@ -216,14 +234,14 @@ public: /// function. It also registers itself as the chain that block participates /// in with the BlockToChain mapping. BlockChain(BlockToChainMapType &BlockToChain, MachineBasicBlock *BB) - : Blocks(1, BB), BlockToChain(BlockToChain), UnscheduledPredecessors(0) { + : Blocks(1, BB), BlockToChain(BlockToChain) { assert(BB && "Cannot create a chain with a null basic block"); BlockToChain[BB] = this; } /// \brief Iterator over blocks within the chain. - typedef SmallVectorImpl::iterator iterator; - typedef SmallVectorImpl::const_iterator const_iterator; + using iterator = SmallVectorImpl::iterator; + using const_iterator = SmallVectorImpl::const_iterator; /// \brief Beginning of blocks within the chain. iterator begin() { return Blocks.begin(); } @@ -291,14 +309,12 @@ public: /// /// Note: This field is reinitialized multiple times - once for each loop, /// and then once for the function as a whole. - unsigned UnscheduledPredecessors; + unsigned UnscheduledPredecessors = 0; }; -} -namespace { class MachineBlockPlacement : public MachineFunctionPass { - /// \brief A typedef for a block filter set. - typedef SmallSetVector BlockFilterSet; + /// \brief A type for a block filter set. + using BlockFilterSet = SmallSetVector; /// Pair struct containing basic block and taildup profitiability struct BlockAndTailDupResult { @@ -433,6 +449,7 @@ class MachineBlockPlacement : public MachineFunctionPass { void fillWorkLists(const MachineBasicBlock *MBB, SmallPtrSetImpl &UpdatedPreds, const BlockFilterSet *BlockFilter); + void buildChain(const MachineBasicBlock *BB, BlockChain &Chain, BlockFilterSet *BlockFilter = nullptr); MachineBasicBlock *findBestLoopTop( @@ -459,31 +476,37 @@ class MachineBlockPlacement : public MachineFunctionPass { const MachineBasicBlock *BB, const MachineBasicBlock *Succ, BranchProbability AdjustedSumProb, const BlockChain &Chain, const BlockFilterSet *BlockFilter); + /// Check for a trellis layout. bool isTrellis(const MachineBasicBlock *BB, const SmallVectorImpl &ViableSuccs, const BlockChain &Chain, const BlockFilterSet *BlockFilter); + /// Get the best successor given a trellis layout. BlockAndTailDupResult getBestTrellisSuccessor( const MachineBasicBlock *BB, const SmallVectorImpl &ViableSuccs, BranchProbability AdjustedSumProb, const BlockChain &Chain, const BlockFilterSet *BlockFilter); + /// Get the best pair of non-conflicting edges. static std::pair getBestNonConflictingEdges( const MachineBasicBlock *BB, MutableArrayRef> Edges); + /// Returns true if a block can tail duplicate into all unplaced /// predecessors. Filters based on loop. bool canTailDuplicateUnplacedPreds( const MachineBasicBlock *BB, MachineBasicBlock *Succ, const BlockChain &Chain, const BlockFilterSet *BlockFilter); + /// Find chains of triangles to tail-duplicate where a global analysis works, /// but a local analysis would not find them. void precomputeTriangleChains(); public: static char ID; // Pass identification, replacement for typeid + MachineBlockPlacement() : MachineFunctionPass(ID) { initializeMachineBlockPlacementPass(*PassRegistry::getPassRegistry()); } @@ -500,10 +523,13 @@ public: MachineFunctionPass::getAnalysisUsage(AU); } }; -} + +} // end anonymous namespace char MachineBlockPlacement::ID = 0; + char &llvm::MachineBlockPlacementID = MachineBlockPlacement::ID; + INITIALIZE_PASS_BEGIN(MachineBlockPlacement, DEBUG_TYPE, "Branch Probability Basic Block Placement", false, false) INITIALIZE_PASS_DEPENDENCY(MachineBranchProbabilityInfo) @@ -1099,6 +1125,7 @@ bool MachineBlockPlacement::canTailDuplicateUnplacedPreds( void MachineBlockPlacement::precomputeTriangleChains() { struct TriangleChain { std::vector Edges; + TriangleChain(MachineBasicBlock *src, MachineBasicBlock *dst) : Edges({src, dst}) {} @@ -1539,10 +1566,10 @@ MachineBasicBlock *MachineBlockPlacement::selectBestCandidateBlock( // worklist of already placed entries. // FIXME: If this shows up on profiles, it could be folded (at the cost of // some code complexity) into the loop below. - WorkList.erase(remove_if(WorkList, - [&](MachineBasicBlock *BB) { - return BlockToChain.lookup(BB) == &Chain; - }), + WorkList.erase(llvm::remove_if(WorkList, + [&](MachineBasicBlock *BB) { + return BlockToChain.lookup(BB) == &Chain; + }), WorkList.end()); if (WorkList.empty()) @@ -1664,7 +1691,7 @@ void MachineBlockPlacement::buildChain( const MachineBasicBlock *LoopHeaderBB = HeadBB; markChainSuccessors(Chain, LoopHeaderBB, BlockFilter); MachineBasicBlock *BB = *std::prev(Chain.end()); - for (;;) { + while (true) { assert(BB && "null block found at end of chain in loop."); assert(BlockToChain[BB] == &Chain && "BlockToChainMap mis-match in loop."); assert(*std::prev(Chain.end()) == BB && "BB Not found at end of chain."); @@ -1950,7 +1977,7 @@ void MachineBlockPlacement::rotateLoop(BlockChain &LoopChain, } } - BlockChain::iterator ExitIt = find(LoopChain, ExitingBB); + BlockChain::iterator ExitIt = llvm::find(LoopChain, ExitingBB); if (ExitIt == LoopChain.end()) return; @@ -2004,7 +2031,7 @@ void MachineBlockPlacement::rotateLoopWithProfile( BlockChain &LoopChain, const MachineLoop &L, const BlockFilterSet &LoopBlockSet) { auto HeaderBB = L.getHeader(); - auto HeaderIter = find(LoopChain, HeaderBB); + auto HeaderIter = llvm::find(LoopChain, HeaderBB); auto RotationPos = LoopChain.end(); BlockFrequency SmallestRotationCost = BlockFrequency::getMaxFrequency(); @@ -2277,7 +2304,7 @@ void MachineBlockPlacement::buildCFGChains() { new (ChainAllocator.Allocate()) BlockChain(BlockToChain, BB); // Also, merge any blocks which we cannot reason about and must preserve // the exact fallthrough behavior for. - for (;;) { + while (true) { Cond.clear(); MachineBasicBlock *TBB = nullptr, *FBB = nullptr; // For AnalyzeBranch. if (!TII->analyzeBranch(*BB, TBB, FBB, Cond) || !FI->canFallThrough()) @@ -2318,7 +2345,7 @@ void MachineBlockPlacement::buildCFGChains() { buildChain(&F->front(), FunctionChain); #ifndef NDEBUG - typedef SmallPtrSet FunctionBlockSetType; + using FunctionBlockSetType = SmallPtrSet; #endif DEBUG({ // Crash at the end so we get all of the debugging output first. @@ -2550,8 +2577,8 @@ bool MachineBlockPlacement::repeatedlyTailDuplicateBlock( // duplicated from here on are already scheduled. // Note that DuplicatedToLPred always implies Removed. while (DuplicatedToLPred) { - assert (Removed && "Block must have been removed to be duplicated into its " - "layout predecessor."); + assert(Removed && "Block must have been removed to be duplicated into its " + "layout predecessor."); MachineBasicBlock *DupBB, *DupPred; // The removal callback causes Chain.end() to be updated when a block is // removed. On the first pass through the loop, the chain end should be the @@ -2634,8 +2661,10 @@ bool MachineBlockPlacement::maybeTailDuplicateBlock( if (RemBB->isEHPad()) RemoveList = EHPadWorkList; RemoveList.erase( - remove_if(RemoveList, - [RemBB](MachineBasicBlock *BB) {return BB == RemBB;}), + llvm::remove_if(RemoveList, + [RemBB](MachineBasicBlock *BB) { + return BB == RemBB; + }), RemoveList.end()); } @@ -2653,7 +2682,7 @@ bool MachineBlockPlacement::maybeTailDuplicateBlock( << getBlockName(RemBB) << "\n"); }; auto RemovalCallbackRef = - llvm::function_ref(RemovalCallback); + function_ref(RemovalCallback); SmallVector DuplicatedPreds; bool IsSimple = TailDup.isSimpleBB(BB); @@ -2795,6 +2824,7 @@ bool MachineBlockPlacement::runOnMachineFunction(MachineFunction &MF) { } namespace { + /// \brief A pass to compute block placement statistics. /// /// A separate pass to compute interesting statistics for evaluating block @@ -2810,6 +2840,7 @@ class MachineBlockPlacementStats : public MachineFunctionPass { public: static char ID; // Pass identification, replacement for typeid + MachineBlockPlacementStats() : MachineFunctionPass(ID) { initializeMachineBlockPlacementStatsPass(*PassRegistry::getPassRegistry()); } @@ -2823,10 +2854,13 @@ public: MachineFunctionPass::getAnalysisUsage(AU); } }; -} + +} // end anonymous namespace char MachineBlockPlacementStats::ID = 0; + char &llvm::MachineBlockPlacementStatsID = MachineBlockPlacementStats::ID; + INITIALIZE_PASS_BEGIN(MachineBlockPlacementStats, "block-placement-stats", "Basic Block Placement Stats", false, false) INITIALIZE_PASS_DEPENDENCY(MachineBranchProbabilityInfo) diff --git a/llvm/lib/CodeGen/MachineCSE.cpp b/llvm/lib/CodeGen/MachineCSE.cpp index 582ff139f886..f0f63715d2f7 100644 --- a/llvm/lib/CodeGen/MachineCSE.cpp +++ b/llvm/lib/CodeGen/MachineCSE.cpp @@ -1,4 +1,4 @@ -//===-- MachineCSE.cpp - Machine Common Subexpression Elimination Pass ----===// +//===- MachineCSE.cpp - Machine Common Subexpression Elimination Pass -----===// // // The LLVM Compiler Infrastructure // @@ -15,18 +15,35 @@ #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/ScopedHashTable.h" +#include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/SmallSet.h" +#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/Statistic.h" #include "llvm/Analysis/AliasAnalysis.h" +#include "llvm/CodeGen/MachineBasicBlock.h" #include "llvm/CodeGen/MachineDominators.h" +#include "llvm/CodeGen/MachineFunction.h" +#include "llvm/CodeGen/MachineFunctionPass.h" #include "llvm/CodeGen/MachineInstr.h" +#include "llvm/CodeGen/MachineOperand.h" #include "llvm/CodeGen/MachineRegisterInfo.h" #include "llvm/CodeGen/Passes.h" +#include "llvm/MC/MCInstrDesc.h" +#include "llvm/MC/MCRegisterInfo.h" +#include "llvm/Pass.h" +#include "llvm/Support/Allocator.h" #include "llvm/Support/Debug.h" #include "llvm/Support/RecyclingAllocator.h" #include "llvm/Support/raw_ostream.h" #include "llvm/Target/TargetInstrInfo.h" +#include "llvm/Target/TargetOpcodes.h" +#include "llvm/Target/TargetRegisterInfo.h" #include "llvm/Target/TargetSubtargetInfo.h" +#include +#include +#include +#include + using namespace llvm; #define DEBUG_TYPE "machine-cse" @@ -40,15 +57,18 @@ STATISTIC(NumCrossBBCSEs, STATISTIC(NumCommutes, "Number of copies coalesced after commuting"); namespace { + class MachineCSE : public MachineFunctionPass { const TargetInstrInfo *TII; const TargetRegisterInfo *TRI; AliasAnalysis *AA; MachineDominatorTree *DT; MachineRegisterInfo *MRI; + public: static char ID; // Pass identification - MachineCSE() : MachineFunctionPass(ID), LookAheadLimit(0), CurrVN(0) { + + MachineCSE() : MachineFunctionPass(ID) { initializeMachineCSEPass(*PassRegistry::getPassRegistry()); } @@ -69,16 +89,18 @@ namespace { } private: - unsigned LookAheadLimit; - typedef RecyclingAllocator > AllocatorTy; - typedef ScopedHashTable ScopedHTType; - typedef ScopedHTType::ScopeTy ScopeType; - DenseMap ScopeMap; + using AllocatorTy = RecyclingAllocator>; + using ScopedHTType = + ScopedHashTable; + using ScopeType = ScopedHTType::ScopeTy; + + unsigned LookAheadLimit = 0; + DenseMap ScopeMap; ScopedHTType VNT; - SmallVector Exps; - unsigned CurrVN; + SmallVector Exps; + unsigned CurrVN = 0; bool PerformTrivialCopyPropagation(MachineInstr *MI, MachineBasicBlock *MBB); @@ -104,10 +126,13 @@ namespace { DenseMap &OpenChildren); bool PerformCSE(MachineDomTreeNode *Node); }; + } // end anonymous namespace char MachineCSE::ID = 0; + char &llvm::MachineCSEID = MachineCSE::ID; + INITIALIZE_PASS_BEGIN(MachineCSE, DEBUG_TYPE, "Machine Common Subexpression Elimination", false, false) INITIALIZE_PASS_DEPENDENCY(MachineDominatorTree)