[llvm] r311703 - [CodeGen] Fix some Clang-tidy modernize-use-using and Include What You Use warnings; other minor fixes (NFC).
Eugene Zelenko via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 24 14:21:40 PDT 2017
Author: eugenezelenko
Date: Thu Aug 24 14:21:39 2017
New Revision: 311703
URL: http://llvm.org/viewvc/llvm-project?rev=311703&view=rev
Log:
[CodeGen] Fix some Clang-tidy modernize-use-using and Include What You Use warnings; other minor fixes (NFC).
Modified:
llvm/trunk/lib/CodeGen/LiveDebugValues.cpp
llvm/trunk/lib/CodeGen/LiveDebugVariables.cpp
llvm/trunk/lib/CodeGen/LiveDebugVariables.h
llvm/trunk/lib/CodeGen/LiveInterval.cpp
llvm/trunk/lib/CodeGen/LiveRangeCalc.cpp
llvm/trunk/lib/CodeGen/LiveRangeCalc.h
llvm/trunk/lib/CodeGen/LiveRangeShrink.cpp
llvm/trunk/lib/CodeGen/MachineBlockFrequencyInfo.cpp
llvm/trunk/lib/CodeGen/MachineBlockPlacement.cpp
llvm/trunk/lib/CodeGen/MachineCSE.cpp
Modified: llvm/trunk/lib/CodeGen/LiveDebugValues.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/LiveDebugValues.cpp?rev=311703&r1=311702&r2=311703&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/LiveDebugValues.cpp (original)
+++ llvm/trunk/lib/CodeGen/LiveDebugValues.cpp Thu Aug 24 14:21:39 2017
@@ -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 <list>
+#include <algorithm>
+#include <cassert>
+#include <cstdint>
+#include <functional>
#include <queue>
+#include <utility>
+#include <vector>
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
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<const DILocalVariable *, const DILocation *>
- DebugVariableBase;
+ using DebugVariableBase =
+ std::pair<const DILocalVariable *, const DILocation *>;
/// 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<VarLoc> VarLocMap;
- typedef SparseBitVector<> VarLocSet;
- typedef SmallDenseMap<const MachineBasicBlock *, VarLocSet> VarLocInMBB;
+ using VarLocMap = UniqueVector<VarLoc>;
+ using VarLocSet = SparseBitVector<>;
+ using VarLocInMBB = SmallDenseMap<const MachineBasicBlock *, VarLocSet>;
struct SpillDebugPair {
MachineInstr *SpillInst;
MachineInstr *DebugInst;
};
- typedef SmallVector<SpillDebugPair, 4> SpillMap;
+ using SpillMap = SmallVector<SpillDebugPair, 4>;
/// 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(MachineBasicB
/// 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;
Modified: llvm/trunk/lib/CodeGen/LiveDebugVariables.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/LiveDebugVariables.cpp?rev=311703&r1=311702&r2=311703&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/LiveDebugVariables.cpp (original)
+++ llvm/trunk/lib/CodeGen/LiveDebugVariables.cpp Thu Aug 24 14:21:39 2017
@@ -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 <algorithm>
+#include <cassert>
+#include <iterator>
#include <memory>
#include <utility>
@@ -54,6 +70,7 @@ EnableLDV("live-debug-variables", cl::in
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::getAnalysisUsag
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<SlotIndex, unsigned, 4> LocMap;
+using LocMap = IntervalMap<SlotIndex, unsigned, 4>;
+
+namespace {
+
+class LDVImpl;
/// UserValue - A user value is a part of a debug info user variable.
///
@@ -86,8 +107,6 @@ typedef IntervalMap<SlotIndex, unsigned,
/// 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<MachineOperand, 4> 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<SlotIndex> &Kills,
- SmallVectorImpl<std::pair<SlotIndex, unsigned> > &NewDefs,
- MachineRegisterInfo &MRI,
- LiveIntervals &LIS);
+ const SmallVectorImpl<SlotIndex> &Kills,
+ SmallVectorImpl<std::pair<SlotIndex, unsigned>> &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<std::unique_ptr<UserValue>, 8> userValues;
/// Map virtual register to eq class leader.
- typedef DenseMap<unsigned, UserValue*> VRMap;
+ using VRMap = DenseMap<unsigned, UserValue *>;
VRMap virtRegToEqClass;
/// Map user variable to eq class leader.
- typedef DenseMap<const MDNode *, UserValue*> UVMap;
+ using UVMap = DenseMap<const MDNode *, UserValue *>;
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 M
}
userValues.push_back(
- make_unique<UserValue>(Var, Expr, IsIndirect, DL, allocator));
+ llvm::make_unique<UserValue>(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,
void
UserValue::addDefsFromCopies(LiveInterval *LI, unsigned LocNo,
- const SmallVectorImpl<SlotIndex> &Kills,
- SmallVectorImpl<std::pair<SlotIndex, unsigned> > &NewDefs,
- MachineRegisterInfo &MRI, LiveIntervals &LIS) {
+ const SmallVectorImpl<SlotIndex> &Kills,
+ SmallVectorImpl<std::pair<SlotIndex, unsigned>> &NewDefs,
+ MachineRegisterInfo &MRI, LiveIntervals &LIS) {
if (Kills.empty())
return;
// Don't track copies from physregs, there are too many uses.
Modified: llvm/trunk/lib/CodeGen/LiveDebugVariables.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/LiveDebugVariables.h?rev=311703&r1=311702&r2=311703&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/LiveDebugVariables.h (original)
+++ llvm/trunk/lib/CodeGen/LiveDebugVariables.h Thu Aug 24 14:21:39 2017
@@ -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 <typename T> 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
Modified: llvm/trunk/lib/CodeGen/LiveInterval.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/LiveInterval.cpp?rev=311703&r1=311702&r2=311703&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/LiveInterval.cpp (original)
+++ llvm/trunk/lib/CodeGen/LiveInterval.cpp Thu Aug 24 14:21:39 2017
@@ -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 <algorithm>
+#include <cassert>
+#include <cstddef>
+#include <iterator>
+#include <utility>
+
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<CalcLiveRangeUtilVector, LiveRange::iterator,
- LiveRange::Segments> CalcLiveRangeUtilVectorBase;
+using CalcLiveRangeUtilVectorBase =
+ CalcLiveRangeUtilBase<CalcLiveRangeUtilVector, LiveRange::iterator,
+ LiveRange::Segments>;
class CalcLiveRangeUtilVector : public CalcLiveRangeUtilVectorBase {
public:
@@ -292,9 +307,9 @@ private:
//===----------------------------------------------------------------------===//
class CalcLiveRangeUtilSet;
-typedef CalcLiveRangeUtilBase<CalcLiveRangeUtilSet,
- LiveRange::SegmentSet::iterator,
- LiveRange::SegmentSet> CalcLiveRangeUtilSetBase;
+using CalcLiveRangeUtilSetBase =
+ CalcLiveRangeUtilBase<CalcLiveRangeUtilSet, LiveRange::SegmentSet::iterator,
+ LiveRange::SegmentSet>;
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
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<void(LiveInterval::SubRange&)> Apply) {
-
LaneBitmask ToApply = LaneMask;
for (SubRange &SR : subranges()) {
LaneBitmask SRMask = SR.LaneMask;
@@ -925,8 +940,8 @@ void LiveInterval::computeSubRangeUndefs
}
}
-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 MachineR
}
#endif
-
//===----------------------------------------------------------------------===//
// LiveRangeUpdater class
//===----------------------------------------------------------------------===//
Modified: llvm/trunk/lib/CodeGen/LiveRangeCalc.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/LiveRangeCalc.cpp?rev=311703&r1=311702&r2=311703&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/LiveRangeCalc.cpp (original)
+++ llvm/trunk/lib/CodeGen/LiveRangeCalc.cpp Thu Aug 24 14:21:39 2017
@@ -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 <algorithm>
+#include <cassert>
+#include <iterator>
+#include <tuple>
+#include <utility>
using namespace llvm;
@@ -44,7 +62,6 @@ void LiveRangeCalc::reset(const MachineF
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(LiveR
createDeadDef(*Indexes, *Alloc, LR, MO);
}
-
void LiveRangeCalc::extendToUses(LiveRange &LR, unsigned Reg, LaneBitmask Mask,
LiveInterval *LI) {
SmallVector<SlotIndex, 4> Undefs;
@@ -197,7 +213,6 @@ void LiveRangeCalc::extendToUses(LiveRan
}
}
-
void LiveRangeCalc::updateFromLiveIns() {
LiveRangeUpdater Updater;
for (const LiveInBlock &I : LiveIn) {
@@ -248,7 +263,6 @@ void LiveRangeCalc::extend(LiveRange &LR
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<SlotIndex> Undefs,
MachineBasicBlock &MBB, BitVector &DefOnEntry,
BitVector &UndefOnEntry) {
@@ -410,7 +423,7 @@ bool LiveRangeCalc::findReachingDefs(Liv
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(Liv
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(Liv
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() {
Modified: llvm/trunk/lib/CodeGen/LiveRangeCalc.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/LiveRangeCalc.h?rev=311703&r1=311702&r2=311703&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/LiveRangeCalc.h (original)
+++ llvm/trunk/lib/CodeGen/LiveRangeCalc.h Thu Aug 24 14:21:39 2017
@@ -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 <utility>
namespace llvm {
-/// Forward declarations for MachineDominators.h:
-class MachineDominatorTree;
template <class NodeT> class DomTreeNodeBase;
-typedef DomTreeNodeBase<MachineBasicBlock> MachineDomTreeNode;
+class MachineDominatorTree;
+class MachineFunction;
+class MachineRegisterInfo;
+
+using MachineDomTreeNode = DomTreeNodeBase<MachineBasicBlock>;
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<VNInfo*, MachineDomTreeNode*> LiveOutPair;
+ using LiveOutPair = std::pair<VNInfo *, MachineDomTreeNode *>;
/// LiveOutMap - Map basic blocks to the value leaving the block.
- typedef IndexedMap<LiveOutPair, MBB2NumberFunctor> LiveOutMap;
+ using LiveOutMap = IndexedMap<LiveOutPair, MBB2NumberFunctor>;
/// 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<LiveRange*,std::pair<BitVector,BitVector>> EntryInfoMap;
+ using EntryInfoMap = DenseMap<LiveRange *, std::pair<BitVector, BitVector>>;
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
Modified: llvm/trunk/lib/CodeGen/LiveRangeShrink.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/LiveRangeShrink.cpp?rev=311703&r1=311702&r2=311703&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/LiveRangeShrink.cpp (original)
+++ llvm/trunk/lib/CodeGen/LiveRangeShrink.cpp Thu Aug 24 14:21:39 2017
@@ -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 <iterator>
+#include <utility>
+
+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<MachineInstr *, unsigned> InstOrderMap;
+
+using InstOrderMap = DenseMap<MachineInstr *, unsigned>;
/// 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(M
/// 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()))
Modified: llvm/trunk/lib/CodeGen/MachineBlockFrequencyInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineBlockFrequencyInfo.cpp?rev=311703&r1=311702&r2=311703&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MachineBlockFrequencyInfo.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachineBlockFrequencyInfo.cpp Thu Aug 24 14:21:39 2017
@@ -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 <string>
using namespace llvm;
#define DEBUG_TYPE "machine-block-freq"
-
static cl::opt<GVDAGType> 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<GVDAGType> ViewMachineBlo
"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<GVDAGType> ViewBlockLayoutWithBFI(
"view-block-layout-with-bfi", cl::Hidden,
@@ -62,6 +63,7 @@ cl::opt<GVDAGType> ViewBlockLayoutWithBF
// 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<std::string> ViewBlockFreqFuncName;
+
// Command line option to specify hot frequency threshold.
// Defined in Analysis/BlockFrequencyInfo.cpp: -view-hot-freq-perc=
extern cl::opt<unsigned> ViewHotFreqPercent;
@@ -76,9 +78,9 @@ static GVDAGType getGVDT() {
namespace llvm {
template <> struct GraphTraits<MachineBlockFrequencyInfo *> {
- typedef const MachineBasicBlock *NodeRef;
- typedef MachineBasicBlock::const_succ_iterator ChildIteratorType;
- typedef pointer_iterator<MachineFunction::const_iterator> nodes_iterator;
+ using NodeRef = const MachineBasicBlock *;
+ using ChildIteratorType = MachineBasicBlock::const_succ_iterator;
+ using nodes_iterator = pointer_iterator<MachineFunction::const_iterator>;
static NodeRef getEntryNode(const MachineBlockFrequencyInfo *G) {
return &G->getFunction()->front();
@@ -99,21 +101,21 @@ template <> struct GraphTraits<MachineBl
}
};
-typedef BFIDOTGraphTraitsBase<MachineBlockFrequencyInfo,
- MachineBranchProbabilityInfo>
- MBFIDOTGraphTraitsBase;
+using MBFIDOTGraphTraitsBase =
+ BFIDOTGraphTraitsBase<MachineBlockFrequencyInfo,
+ MachineBranchProbabilityInfo>;
+
template <>
struct DOTGraphTraits<MachineBlockFrequencyInfo *>
: public MBFIDOTGraphTraitsBase {
- explicit DOTGraphTraits(bool isSimple = false)
- : MBFIDOTGraphTraitsBase(isSimple), CurFunc(nullptr), LayoutOrderMap() {}
-
- const MachineFunction *CurFunc;
+ const MachineFunction *CurFunc = nullptr;
DenseMap<const MachineBasicBlock *, int> 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::MachineBlockF
initializeMachineBlockFrequencyInfoPass(*PassRegistry::getPassRegistry());
}
-MachineBlockFrequencyInfo::~MachineBlockFrequencyInfo() {}
+MachineBlockFrequencyInfo::~MachineBlockFrequencyInfo() = default;
void MachineBlockFrequencyInfo::getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequired<MachineBranchProbabilityInfo>();
Modified: llvm/trunk/lib/CodeGen/MachineBlockPlacement.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineBlockPlacement.cpp?rev=311703&r1=311702&r2=311703&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MachineBlockPlacement.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachineBlockPlacement.cpp Thu Aug 24 14:21:39 2017
@@ -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 <algorithm>
-#include <functional>
+#include <cassert>
+#include <cstdint>
+#include <iterator>
+#include <memory>
+#include <string>
+#include <tuple>
#include <utility>
+#include <vector>
+
using namespace llvm;
#define DEBUG_TYPE "block-placement"
@@ -101,6 +118,7 @@ static cl::opt<bool>
cl::desc("Model the cost of loop rotation more "
"precisely by using profile data."),
cl::init(false), cl::Hidden);
+
static cl::opt<bool>
ForcePreciseRotationCost("force-precise-rotation-cost",
cl::desc("Force the use of precise cost "
@@ -177,12 +195,12 @@ extern cl::opt<GVDAGType> ViewBlockLayou
extern cl::opt<std::string> ViewBlockFreqFuncName;
namespace {
+
class BlockChain;
+
/// \brief Type for our function-wide basic block -> block chain mapping.
-typedef DenseMap<const MachineBasicBlock *, BlockChain *> BlockToChainMapType;
-}
+using BlockToChainMapType = DenseMap<const MachineBasicBlock *, BlockChain *>;
-namespace {
/// \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<MachineBasicBlock *>::iterator iterator;
- typedef SmallVectorImpl<MachineBasicBlock *>::const_iterator const_iterator;
+ using iterator = SmallVectorImpl<MachineBasicBlock *>::iterator;
+ using const_iterator = SmallVectorImpl<MachineBasicBlock *>::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<const MachineBasicBlock *, 16> BlockFilterSet;
+ /// \brief A type for a block filter set.
+ using BlockFilterSet = SmallSetVector<const MachineBasicBlock *, 16>;
/// Pair struct containing basic block and taildup profitiability
struct BlockAndTailDupResult {
@@ -433,6 +449,7 @@ class MachineBlockPlacement : public Mac
void fillWorkLists(const MachineBasicBlock *MBB,
SmallPtrSetImpl<BlockChain *> &UpdatedPreds,
const BlockFilterSet *BlockFilter);
+
void buildChain(const MachineBasicBlock *BB, BlockChain &Chain,
BlockFilterSet *BlockFilter = nullptr);
MachineBasicBlock *findBestLoopTop(
@@ -459,31 +476,37 @@ class MachineBlockPlacement : public Mac
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<MachineBasicBlock *> &ViableSuccs,
const BlockChain &Chain, const BlockFilterSet *BlockFilter);
+
/// Get the best successor given a trellis layout.
BlockAndTailDupResult getBestTrellisSuccessor(
const MachineBasicBlock *BB,
const SmallVectorImpl<MachineBasicBlock *> &ViableSuccs,
BranchProbability AdjustedSumProb, const BlockChain &Chain,
const BlockFilterSet *BlockFilter);
+
/// Get the best pair of non-conflicting edges.
static std::pair<WeightedEdge, WeightedEdge> getBestNonConflictingEdges(
const MachineBasicBlock *BB,
MutableArrayRef<SmallVector<WeightedEdge, 8>> 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::canTailDupli
void MachineBlockPlacement::precomputeTriangleChains() {
struct TriangleChain {
std::vector<MachineBasicBlock *> Edges;
+
TriangleChain(MachineBasicBlock *src, MachineBasicBlock *dst)
: Edges({src, dst}) {}
@@ -1539,10 +1566,10 @@ MachineBasicBlock *MachineBlockPlacement
// 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(B
}
}
- BlockChain::iterator ExitIt = find(LoopChain, ExitingBB);
+ BlockChain::iterator ExitIt = llvm::find(LoopChain, ExitingBB);
if (ExitIt == LoopChain.end())
return;
@@ -2004,7 +2031,7 @@ void MachineBlockPlacement::rotateLoopWi
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::buildCFGChai
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::buildCFGChai
buildChain(&F->front(), FunctionChain);
#ifndef NDEBUG
- typedef SmallPtrSet<MachineBasicBlock *, 16> FunctionBlockSetType;
+ using FunctionBlockSetType = SmallPtrSet<MachineBasicBlock *, 16>;
#endif
DEBUG({
// Crash at the end so we get all of the debugging output first.
@@ -2550,8 +2577,8 @@ bool MachineBlockPlacement::repeatedlyTa
// 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::maybeTailDup
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::maybeTailDup
<< getBlockName(RemBB) << "\n");
};
auto RemovalCallbackRef =
- llvm::function_ref<void(MachineBasicBlock*)>(RemovalCallback);
+ function_ref<void(MachineBasicBlock*)>(RemovalCallback);
SmallVector<MachineBasicBlock *, 8> DuplicatedPreds;
bool IsSimple = TailDup.isSimpleBB(BB);
@@ -2795,6 +2824,7 @@ bool MachineBlockPlacement::runOnMachine
}
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 : publi
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)
Modified: llvm/trunk/lib/CodeGen/MachineCSE.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineCSE.cpp?rev=311703&r1=311702&r2=311703&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MachineCSE.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachineCSE.cpp Thu Aug 24 14:21:39 2017
@@ -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 <cassert>
+#include <iterator>
+#include <utility>
+#include <vector>
+
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<BumpPtrAllocator,
- ScopedHashTableVal<MachineInstr*, unsigned> > AllocatorTy;
- typedef ScopedHashTable<MachineInstr*, unsigned,
- MachineInstrExpressionTrait, AllocatorTy> ScopedHTType;
- typedef ScopedHTType::ScopeTy ScopeType;
- DenseMap<MachineBasicBlock*, ScopeType*> ScopeMap;
+ using AllocatorTy = RecyclingAllocator<BumpPtrAllocator,
+ ScopedHashTableVal<MachineInstr *, unsigned>>;
+ using ScopedHTType =
+ ScopedHashTable<MachineInstr *, unsigned, MachineInstrExpressionTrait,
+ AllocatorTy>;
+ using ScopeType = ScopedHTType::ScopeTy;
+
+ unsigned LookAheadLimit = 0;
+ DenseMap<MachineBasicBlock *, ScopeType *> ScopeMap;
ScopedHTType VNT;
- SmallVector<MachineInstr*, 64> Exps;
- unsigned CurrVN;
+ SmallVector<MachineInstr *, 64> Exps;
+ unsigned CurrVN = 0;
bool PerformTrivialCopyPropagation(MachineInstr *MI,
MachineBasicBlock *MBB);
@@ -104,10 +126,13 @@ namespace {
DenseMap<MachineDomTreeNode*, unsigned> &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)
More information about the llvm-commits
mailing list