LLVM: include/llvm/Analysis/InlineCost.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13#ifndef LLVM_ANALYSIS_INLINECOST_H

14#define LLVM_ANALYSIS_INLINECOST_H

15

21#include

22#include

23#include

24

25namespace llvm {

36

38

39

41

42

44

45

47

48

53

54

56

57

59

61 "function-inline-cost-multiplier";

62

64}

65

66

68public:

71

73

75

76private:

79};

80

81

82

83

84

85

86

87

88

89

90

91class InlineCost {

92 enum SentinelValues { AlwaysInlineCost = INT_MIN, NeverInlineCost = INT_MAX };

93

94

95 int Cost = 0;

96

97

98 int Threshold = 0;

99

100

101 int StaticBonusApplied = 0;

102

103

104 const char *Reason = nullptr;

105

106

107 std::optional CostBenefit;

108

109

110 InlineCost(int Cost, int Threshold, int StaticBonusApplied,

111 const char *Reason = nullptr,

112 std::optional CostBenefit = std::nullopt)

113 : Cost(Cost), Threshold(Threshold),

114 StaticBonusApplied(StaticBonusApplied), Reason(Reason),

117 "Reason must be provided for Never or Always");

118 }

119

120public:

121 static InlineCost get(int Cost, int Threshold, int StaticBonus = 0) {

122 assert(Cost > AlwaysInlineCost && "Cost crosses sentinel value");

123 assert(Cost < NeverInlineCost && "Cost crosses sentinel value");

124 return InlineCost(Cost, Threshold, StaticBonus);

125 }

128 std::optional CostBenefit = std::nullopt) {

129 return InlineCost(AlwaysInlineCost, 0, 0, Reason, CostBenefit);

130 }

133 std::optional CostBenefit = std::nullopt) {

134 return InlineCost(NeverInlineCost, 0, 0, Reason, CostBenefit);

135 }

136

137

138 explicit operator bool() const { return Cost < Threshold; }

139

140 bool isAlways() const { return Cost == AlwaysInlineCost; }

141 bool isNever() const { return Cost == NeverInlineCost; }

143

144

145

150

151

154 return Threshold;

155 }

156

157

160 return StaticBonusApplied;

161 }

162

163

164 std::optional getCostBenefit() const { return CostBenefit; }

165

166

169 "InlineCost reason must be set for Always or Never");

170 return Reason;

171 }

172

173

174

175

177};

178

179

180

181class InlineResult {

182 const char *Message = nullptr;

183 InlineResult(const char *Message = nullptr) : Message(Message) {}

184

185public:

186 static InlineResult success() { return {}; }

187 static InlineResult failure(const char *Reason) {

188 return InlineResult(Reason);

189 }

190 bool isSuccess() const { return Message == nullptr; }

193 "getFailureReason should only be called in failure cases");

194 return Message;

195 }

196};

197

198

199

200

201

202

203

204

205

206

208

210

211

213

214

216

217

219

220

222

223

225

226

227

229

230

232

233

235

236

238

239

241};

242

245

246

247

249

250

251

252

254

255

256

257

258

259

260

262

263

264

267

268

269

270

271

272

273

274

275

276

277

278

286 nullptr);

287

288

289

290

291

292

301 nullptr);

302

303

304

305

306

307

308

312

313

314

315

316

317

318

319

320

328

329

330

338

339

340

341

342

343

345

346

347

348

350 : PassInfoMixin {

352

353public:

357};

358}

359

360#endif

assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")

This file implements a class to represent arbitrary precision integral constant values and operations...

MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL

This header defines various interfaces for pass management in LLVM.

FunctionAnalysisManager FAM

Class for arbitrary precision integers.

A cache of @llvm.assume calls within a function.

BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...

Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...

const APInt & getBenefit() const

Definition InlineCost.h:74

CostBenefitPair(APInt Cost, APInt Benefit)

Definition InlineCost.h:69

const APInt & getCost() const

Definition InlineCost.h:72

A parsed version of the target data layout string in and methods for querying it.

A cache of ephemeral values within a function.

Represents the cost of inlining a function.

Definition InlineCost.h:91

std::optional< CostBenefitPair > getCostBenefit() const

Get the cost-benefit pair which was computed by cost-benefit analysis.

Definition InlineCost.h:164

int getThreshold() const

Get the threshold against which the cost was computed.

Definition InlineCost.h:152

const char * getReason() const

Get the reason of Always or Never.

Definition InlineCost.h:167

int getStaticBonusApplied() const

Get the amount of StaticBonus applied.

Definition InlineCost.h:158

int getCost() const

Get the inline cost estimate.

Definition InlineCost.h:146

static InlineCost getNever(const char *Reason, std::optional< CostBenefitPair > CostBenefit=std::nullopt)

Definition InlineCost.h:132

static InlineCost getAlways(const char *Reason, std::optional< CostBenefitPair > CostBenefit=std::nullopt)

Definition InlineCost.h:127

static InlineCost get(int Cost, int Threshold, int StaticBonus=0)

Definition InlineCost.h:121

bool isAlways() const

Definition InlineCost.h:140

int getCostDelta() const

Get the cost delta from the threshold for inlining.

Definition InlineCost.h:176

bool isVariable() const

Definition InlineCost.h:142

bool isNever() const

Definition InlineCost.h:141

InlineResult is basically true or false.

Definition InlineCost.h:181

static InlineResult success()

Definition InlineCost.h:186

static InlineResult failure(const char *Reason)

Definition InlineCost.h:187

bool isSuccess() const

Definition InlineCost.h:190

const char * getFailureReason() const

Definition InlineCost.h:191

A set of analyses that are preserved following a run of a transformation pass.

Analysis providing profile information.

StringRef - Represent a constant reference to a string, i.e.

Provides information about what library functions are available for the current target.

This pass provides access to the codegen interfaces that are needed for IR-level transformations.

An efficient, type-erasing, non-owning reference to a callable.

This class implements an extremely fast bulk output stream that can only output to a stream.

Definition InlineCost.h:37

const int ColdccPenalty

Definition InlineCost.h:52

const char FunctionInlineCostMultiplierAttributeName[]

Definition InlineCost.h:60

const int OptSizeThreshold

Use when optsize (-Os) is specified.

Definition InlineCost.h:40

const int OptMinSizeThreshold

Use when minsize (-Oz) is specified.

Definition InlineCost.h:43

const int LoopPenalty

Definition InlineCost.h:51

const uint64_t MaxSimplifiedDynamicAllocaToInline

Do not inline dynamic allocas that have been constant propagated to be static allocas above this amou...

Definition InlineCost.h:58

const int IndirectCallThreshold

Definition InlineCost.h:50

const int OptAggressiveThreshold

Use when -O3 is specified.

Definition InlineCost.h:46

const char MaxInlineStackSizeAttributeName[]

Definition InlineCost.h:63

const unsigned TotalAllocaSizeRecursiveCaller

Do not inline functions which allocate this many bytes on the stack when the caller is recursive.

Definition InlineCost.h:55

LLVM_ABI int getInstrCost()

This is an optimization pass for GlobalISel generic memory operations.

LLVM_ABI std::optional< int > getStringFnAttrAsInt(CallBase &CB, StringRef AttrKind)

LLVM_ABI InlineResult isInlineViable(Function &Callee)

Check if it is mechanically possible to inline the function Callee, based on the contents of the func...

LLVM_ABI std::optional< InlineCostFeatures > getInliningCostFeatures(CallBase &Call, TargetTransformInfo &CalleeTTI, function_ref< AssumptionCache &(Function &)> GetAssumptionCache, function_ref< BlockFrequencyInfo &(Function &)> GetBFI=nullptr, function_ref< const TargetLibraryInfo &(Function &)> GetTLI=nullptr, ProfileSummaryInfo *PSI=nullptr, OptimizationRemarkEmitter *ORE=nullptr)

Get the expanded cost features.

LLVM_ABI InlineCost getInlineCost(CallBase &Call, const InlineParams &Params, TargetTransformInfo &CalleeTTI, function_ref< AssumptionCache &(Function &)> GetAssumptionCache, function_ref< const TargetLibraryInfo &(Function &)> GetTLI, function_ref< BlockFrequencyInfo &(Function &)> GetBFI=nullptr, ProfileSummaryInfo *PSI=nullptr, OptimizationRemarkEmitter *ORE=nullptr, function_ref< EphemeralValuesCache &(Function &)> GetEphValuesCache=nullptr)

Get an InlineCost object representing the cost of inlining this callsite.

LLVM_ABI std::optional< InlineResult > getAttributeBasedInliningDecision(CallBase &Call, Function *Callee, TargetTransformInfo &CalleeTTI, function_ref< const TargetLibraryInfo &(Function &)> GetTLI)

Returns InlineResult::success() if the call site should be always inlined because of user directives,...

LLVM_ABI InlineParams getInlineParams()

Generate the parameters to tune the inline cost analysis based only on the commandline options.

LLVM_ABI int getCallsiteCost(const TargetTransformInfo &TTI, const CallBase &Call, const DataLayout &DL)

Return the cost associated with a callsite, including parameter passing and the call/return instructi...

OutputIt move(R &&Range, OutputIt Out)

Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.

LLVM_ABI std::optional< int > getInliningCostEstimate(CallBase &Call, TargetTransformInfo &CalleeTTI, function_ref< AssumptionCache &(Function &)> GetAssumptionCache, function_ref< BlockFrequencyInfo &(Function &)> GetBFI=nullptr, function_ref< const TargetLibraryInfo &(Function &)> GetTLI=nullptr, ProfileSummaryInfo *PSI=nullptr, OptimizationRemarkEmitter *ORE=nullptr)

Get the cost estimate ignoring thresholds.

AnalysisManager< Function > FunctionAnalysisManager

Convenience typedef for the Function analysis manager.

Implement std::hash so that hash_code can be used in STL containers.

raw_ostream & OS

Definition InlineCost.h:351

static bool isRequired()

Definition InlineCost.h:356

LLVM_ABI PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM)

InlineCostAnnotationPrinterPass(raw_ostream &OS)

Definition InlineCost.h:354

Thresholds to tune inline cost analysis.

Definition InlineCost.h:207

std::optional< int > OptMinSizeThreshold

Threshold to use when the caller is optimized for minsize.

Definition InlineCost.h:221

std::optional< int > OptSizeThreshold

Threshold to use when the caller is optimized for size.

Definition InlineCost.h:218

std::optional< int > ColdCallSiteThreshold

Threshold to use when the callsite is considered cold.

Definition InlineCost.h:231

std::optional< int > ColdThreshold

Threshold to use for cold callees.

Definition InlineCost.h:215

std::optional< int > HotCallSiteThreshold

Threshold to use when the callsite is considered hot.

Definition InlineCost.h:224

std::optional< bool > AllowRecursiveCall

Indicate whether we allow inlining for recursive call.

Definition InlineCost.h:240

int DefaultThreshold

The default threshold to start with for a callee.

Definition InlineCost.h:209

std::optional< bool > EnableDeferral

Indicate whether we should allow inline deferral.

Definition InlineCost.h:237

std::optional< int > HintThreshold

Threshold to use for callees with inline hint.

Definition InlineCost.h:212

std::optional< int > LocallyHotCallSiteThreshold

Threshold to use when the callsite is considered hot relative to function entry.

Definition InlineCost.h:228

std::optional< bool > ComputeFullInlineCost

Compute inline cost even when the cost has exceeded the threshold.

Definition InlineCost.h:234

A CRTP mix-in to automatically provide informational APIs needed for passes.