LLVM: lib/Transforms/IPO/AlwaysInliner.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

26

27using namespace llvm;

28

29#define DEBUG_TYPE "inline"

30

31namespace {

32

33bool AlwaysInlineImpl(

41

43 if (F.isPresplitCoroutine())

44 continue;

45

47 continue;

48

50

51 for (User *U : F.users())

53 if (CB->getCalledFunction() == &F &&

54 CB->hasFnAttr(Attribute::AlwaysInline) &&

55 !CB->getAttributes().hasFnAttr(Attribute::NoInline))

57

59 Function *Caller = CB->getCaller();

61 DebugLoc DLoc = CB->getDebugLoc();

63

66 &GetAAR(F), InsertLifetime);

68 ORE.emit([&]() {

70 << "'" << ore::NV("Callee", &F) << "' is not inlined into '"

71 << ore::NV("Caller", Caller)

73 });

74 continue;

75 }

76

78 ORE, DLoc, Block, F, *Caller,

80 false, DEBUG_TYPE);

81

85 }

86

87 F.removeDeadConstantUsers();

88 if (F.hasFnAttribute(Attribute::AlwaysInline) && F.isDefTriviallyDead()) {

89

90

91 if (F.hasComdat()) {

93 } else {

95 FAM->clear(F, F.getName());

96 M.getFunctionList().erase(F);

98 }

99 }

100 }

101

102 if (!InlinedComdatFunctions.empty()) {

103

104

106

107 for (Function *F : InlinedComdatFunctions) {

109 FAM->clear(*F, F->getName());

110 M.getFunctionList().erase(F);

112 }

113 }

114

116}

117

118struct AlwaysInlinerLegacyPass : public ModulePass {

119 bool InsertLifetime;

120

121 AlwaysInlinerLegacyPass()

122 : AlwaysInlinerLegacyPass( true) {}

123

124 AlwaysInlinerLegacyPass(bool InsertLifetime)

125 : ModulePass(ID), InsertLifetime(InsertLifetime) {

127 }

128

129

130 bool runOnModule(Module &M) override {

131

132 auto &PSI = getAnalysis().getPSI();

134 return getAnalysis(F).getAAResults();

135 };

137 return getAnalysis().getAssumptionCache(F);

138 };

139

140 return AlwaysInlineImpl(M, InsertLifetime, PSI, nullptr,

141 GetAssumptionCache, GetAAR);

142 }

143

144 static char ID;

145

146 void getAnalysisUsage(AnalysisUsage &AU) const override {

150 }

151};

152

153}

154

155char AlwaysInlinerLegacyPass::ID = 0;

157 "Inliner for always_inline functions", false, false)

162 "Inliner for always_inline functions", false, false)

163

165 return new AlwaysInlinerLegacyPass(InsertLifetime);

166}

167

174 };

177 };

179

180 bool Changed = AlwaysInlineImpl(M, InsertLifetime, PSI, &FAM,

181 GetAssumptionCache, GetAAR);

184

186

188 return PA;

189}

Provides passes to inlining "always_inline" functions.

Module.h This file contains the declarations for the Module class.

FunctionAnalysisManager FAM

ModuleAnalysisManager MAM

#define INITIALIZE_PASS_DEPENDENCY(depName)

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

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

This file implements a set that has insertion order iteration characteristics.

A manager for alias analyses.

A wrapper pass to provide the legacy pass manager access to a suitably prepared AAResults object.

This templated class represents "all analyses that operate over " (e....

LLVM_ABI PreservedAnalyses run(Module &M, ModuleAnalysisManager &)

Definition AlwaysInliner.cpp:168

Represent the analysis usage information of a pass.

AnalysisUsage & addRequired()

A function analysis which provides an AssumptionCache.

An immutable pass that tracks lazily created AssumptionCache objects.

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

LLVM Basic Block Representation.

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

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

This class captures the data input to the InlineFunction call, and records the auxiliary results prod...

InlineResult is basically true or false.

const char * getFailureReason() const

ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...

A Module instance is used to store all the information related to an LLVM module.

static LLVM_ABI PassRegistry * getPassRegistry()

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

Pass interface - Implemented by all 'passes'.

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

static PreservedAnalyses none()

Convenience factory function for the empty preserved set.

static PreservedAnalyses all()

Construct a special preserved set that preserves all passes.

PreservedAnalyses & preserveSet()

Mark an analysis set as preserved.

An analysis pass based on the new PM to deliver ProfileSummaryInfo.

An analysis pass based on legacy pass manager to deliver ProfileSummaryInfo.

Analysis providing profile information.

void clear()

Completely clear the SetVector.

bool insert(const value_type &X)

Insert a new element into the SetVector.

A SetVector that performs no allocations if smaller than a certain size.

void push_back(const T &Elt)

This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.

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

unsigned ID

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

DiagnosticInfoOptimizationBase::Argument NV

This is an optimization pass for GlobalISel generic memory operations.

LLVM_ABI InlineResult InlineFunction(CallBase &CB, InlineFunctionInfo &IFI, bool MergeAttributes=false, AAResults *CalleeAAR=nullptr, bool InsertLifetime=true, Function *ForwardVarArgsTo=nullptr, OptimizationRemarkEmitter *ORE=nullptr)

This function inlines the called function into the basic block of the caller.

decltype(auto) dyn_cast(const From &Val)

dyn_cast - Return the argument parameter cast to the specified type.

iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)

Make a range that does early increment to allow mutation of the underlying range without disrupting i...

InnerAnalysisManagerProxy< FunctionAnalysisManager, Module > FunctionAnalysisManagerModuleProxy

Provide the FunctionAnalysisManager to Module proxy.

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 void emitInlinedIntoBasedOnCost(OptimizationRemarkEmitter &ORE, DebugLoc DLoc, const BasicBlock *Block, const Function &Callee, const Function &Caller, const InlineCost &IC, bool ForProfileContext=false, const char *PassName=nullptr)

Emit ORE message based in cost (default heuristic).

LLVM_ABI Pass * createAlwaysInlinerLegacyPass(bool InsertLifetime=true)

Create a legacy pass manager instance of a pass to inline and remove functions marked as "always_inli...

Definition AlwaysInliner.cpp:164

LLVM_ABI void filterDeadComdatFunctions(SmallVectorImpl< Function * > &DeadComdatFunctions)

Filter out potentially dead comdat functions where other entries keep the entire comdat group alive.

LLVM_ABI void initializeAlwaysInlinerLegacyPassPass(PassRegistry &)

AnalysisManager< Function > FunctionAnalysisManager

Convenience typedef for the Function analysis manager.

AnalysisManager< Module > ModuleAnalysisManager

Convenience typedef for the Module analysis manager.