LLVM: lib/CodeGen/MachineFunctionSplitter.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

42#include

43

44using namespace llvm;

45

46

47

48

49

50

51

52

55 cl::desc("Percentile profile summary cutoff used to "

56 "determine cold blocks. Unused if set to zero."),

58

60 "mfs-count-threshold",

62 "Minimum number of times a block must be executed to be retained."),

64

66 "mfs-split-ehcode",

67 cl::desc("Splits all EH code and it's descendants by default."),

69

70namespace {

71

73public:

74 static char ID;

77 }

78

79 StringRef getPassName() const override {

80 return "Machine Function Splitter Transformation";

81 }

82

83 void getAnalysisUsage(AnalysisUsage &AU) const override;

84

85 bool runOnMachineFunction(MachineFunction &F) override;

86};

87}

88

89

90

91

95 for (auto Block : EHBlocks) {

97 }

98}

99

102 return X.getSectionID().Type < Y.getSectionID().Type;

103 };

106}

107

112

113

115

116

118 return true;

121

123

125 return false;

126 }

127

129}

130

131bool MachineFunctionSplitter::runOnMachineFunction(MachineFunction &MF) {

133 return false;

134

135

137 return false;

138

139

140

143 return false;

144

147 return false;

148

149

150

151 auto BBSectionsProfile =

152 getAnalysisIfAvailable();

153 if (BBSectionsProfile != nullptr &&

154 BBSectionsProfile->getBBSPR().isFunctionHot(MF.getName()))

155 return false;

156

157

158

159

160

163

164 MachineBlockFrequencyInfo *MBFI = nullptr;

165 ProfileSummaryInfo *PSI = nullptr;

166 if (UseProfileData) {

167 MBFI = &getAnalysis().getMBFI();

168 PSI = &getAnalysis().getPSI();

169

170

171

172

174

178 return true;

179 }

180 }

181

183 for (auto &MBB : MF) {

185 continue;

186

189 else if (UseProfileData && isColdBlock(MBB, MBFI, PSI) &&

192 }

193

194

197

198 else {

199

200 bool HasHotLandingPads = false;

201 for (const MachineBasicBlock *LP : LandingPads) {

203 HasHotLandingPads = true;

204 }

205 if (!HasHotLandingPads) {

206 for (MachineBasicBlock *LP : LandingPads)

208 }

209 }

210

212 return true;

213}

214

215void MachineFunctionSplitter::getAnalysisUsage(AnalysisUsage &AU) const {

216 AU.addRequired();

217 AU.addRequired();

218 AU.addRequired();

220}

221

222char MachineFunctionSplitter::ID = 0;

224 "Split machine functions using profile information", false,

225 false)

226

228 return new MachineFunctionSplitter();

229}

const TargetInstrInfo & TII

static bool isColdBlock(const MachineBasicBlock &MBB, const MachineBlockFrequencyInfo *MBFI, ProfileSummaryInfo *PSI)

Definition MachineFunctionSplitter.cpp:108

static void finishAdjustingBasicBlocksAndLandingPads(MachineFunction &MF)

Definition MachineFunctionSplitter.cpp:100

static cl::opt< unsigned > ColdCountThreshold("mfs-count-threshold", cl::desc("Minimum number of times a block must be executed to be retained."), cl::init(1), cl::Hidden)

static void setDescendantEHBlocksCold(MachineFunction &MF)

setDescendantEHBlocksCold - This splits all EH pads and blocks reachable only by EH pad as cold.

Definition MachineFunctionSplitter.cpp:92

static cl::opt< unsigned > PercentileCutoff("mfs-psi-cutoff", cl::desc("Percentile profile summary cutoff used to " "determine cold blocks. Unused if set to zero."), cl::init(999950), cl::Hidden)

static cl::opt< bool > SplitAllEHCode("mfs-split-ehcode", cl::desc("Splits all EH code and it's descendants by default."), cl::init(false), cl::Hidden)

#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)

This file defines the SmallVector class.

static TableGen::Emitter::Opt Y("gen-skeleton-entry", EmitSkeleton, "Generate example skeleton entry")

static TableGen::Emitter::OptClass< SkeletonEmitter > X("gen-skeleton-class", "Generate example skeleton class")

AnalysisUsage & addUsedIfAvailable()

Add the specified Pass class to the set of analyses used by this pass.

AnalysisUsage & addRequired()

Implements a dense probed hash-table based set.

bool hasProfileData(bool IncludeSynthetic=false) const

Return true if the function is annotated with profile data.

bool isEHPad() const

Returns true if the block is a landing pad.

LLVM_ABI bool isEntryBlock() const

Returns true if this is the entry block of the function.

void setSectionID(MBBSectionID V)

Sets the section ID for this basic block.

MachineBlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate machine basic b...

LLVM_ABI std::optional< uint64_t > getBlockProfileCount(const MachineBasicBlock *MBB) const

MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...

void setBBSectionsType(BasicBlockSection V)

const TargetSubtargetInfo & getSubtarget() const

getSubtarget - Return the subtarget for which this machine code is being compiled.

StringRef getName() const

getName - Return the name of the corresponding LLVM function.

Function & getFunction()

Return the LLVM function that this machine code represents.

void RenumberBlocks(MachineBasicBlock *MBBFrom=nullptr)

RenumberBlocks - This discards all of the MachineBasicBlock numbers and recomputes them.

const TargetMachine & getTarget() const

getTarget - Return the target machine this machine code is compiled with

static LLVM_ABI PassRegistry * getPassRegistry()

getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...

Analysis providing profile information.

bool hasCSInstrumentationProfile() const

Returns true if module M has context sensitive instrumentation profile.

bool hasInstrumentationProfile() const

Returns true if module M has instrumentation profile.

bool hasSampleProfile() const

Returns true if module M has sample profile.

LLVM_ABI bool isColdCountNthPercentile(int PercentileCutoff, uint64_t C) const

Returns true if count C is considered cold with regard to a given cold percentile cutoff value.

bool isFunctionHotInCallGraph(const FuncT *F, BFIT &BFI) const

Returns true if F contains hot code.

void push_back(const T &Elt)

virtual bool isMBBSafeToSplitToCold(const MachineBasicBlock &MBB) const

Return true if the MachineBasicBlock can safely be split to the cold section.

virtual bool isFunctionSafeToSplit(const MachineFunction &MF) const

Return true if the function is a viable candidate for machine function splitting.

llvm::BasicBlockSection getBBSectionsType() const

If basic blocks should be emitted into their own section, corresponding to -fbasic-block-sections.

virtual const TargetInstrInfo * getInstrInfo() const

unsigned ID

LLVM IR allows to use arbitrary numbers as calling convention identifiers.

initializer< Ty > init(const Ty &Val)

This is an optimization pass for GlobalISel generic memory operations.

LLVM_ABI MachineFunctionPass * createMachineFunctionSplitterPass()

createMachineFunctionSplitterPass - This pass splits machine functions using profile information.

LLVM_ABI void initializeMachineFunctionSplitterPass(PassRegistry &)

FunctionAddr VTableAddr Count

static void computeEHOnlyBlocks(FunctionT &F, DenseSet< BlockT * > &EHBlocks)

Compute a list of blocks that are only reachable via EH paths.

class LLVM_GSL_OWNER SmallVector

Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...

void avoidZeroOffsetLandingPad(MachineFunction &MF)

void sortBasicBlocksAndUpdateBranches(MachineFunction &MF, MachineBasicBlockComparator MBBCmp)

LLVM_ABI static const MBBSectionID ColdSectionID