LLVM: include/llvm/CodeGen/IndirectThunks.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16#ifndef LLVM_CODEGEN_INDIRECTTHUNKS_H

17#define LLVM_CODEGEN_INDIRECTTHUNKS_H

18

24

25namespace llvm {

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60template <typename Derived, typename InsertedThunksTy = bool>

62 Derived &getDerived() { return *static_cast<Derived *>(this); }

63

64

65

66

67

68 InsertedThunksTy InsertedThunks;

69

70protected:

71

72

73

74

75

76

79

80protected:

81

82

83

84

85

86

88

89

91

92

94

95

97 InsertedThunksTy ExistingThunks);

98

99

100

101

102

103

104

105

106

108

109public:

111 InsertedThunks = InsertedThunksTy{};

112 getDerived().doInitialization(M);

113 }

114

116};

117

118template <typename Derived, typename InsertedThunksTy>

122 assert(Name.starts_with(getDerived().getThunkPrefix()) &&

123 "Created a thunk with an unexpected prefix!");

124

134 F->setComdat(M.getOrInsertComdat(Name));

135 }

136

137

138

140 B.addAttribute(llvm::Attribute::NoUnwind);

141 B.addAttribute(llvm::Attribute::Naked);

142 if (TargetAttrs != "")

143 B.addAttribute("target-features", TargetAttrs);

144 F->addFnAttrs(B);

145

146

149

151

152

153

155

156

157

158

159

160

162}

163

164template <typename Derived, typename InsertedThunksTy>

167

169

170 if (!getDerived().mayUseThunk(MF))

171 return false;

172

173

174

175

176

177 InsertedThunks |= getDerived().insertThunks(MMI, MF, InsertedThunks);

178 return true;

179 }

180

181

182 getDerived().populateThunk(MF);

183 return true;

184}

185

186

187

188template <typename... Inserters>

190protected:

191 std::tuple<Inserters...> TIs;

192

194

195public:

197 initTIs(M, TIs);

198 return false;

199 }

200

202 auto &MMI = getAnalysis().getMMI();

203 return runTIs(MMI, MF, TIs);

204 }

205

206private:

207 template <typename... ThunkInserterT>

208 static void initTIs(Module &M,

209 std::tuple<ThunkInserterT...> &ThunkInserters) {

210 (..., std::get(ThunkInserters).init(M));

211 }

212

213 template <typename... ThunkInserterT>

214 static bool runTIs(MachineModuleInfo &MMI, MachineFunction &MF,

215 std::tuple<ThunkInserterT...> &ThunkInserters) {

216 return (0 | ... | std::get(ThunkInserters).run(MMI, MF));

217 }

218};

219

220}

221

222#endif

static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")

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

assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())

LLVM Basic Block Representation.

static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)

Creates a new BasicBlock.

static FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)

This static method is the primary way of constructing a FunctionType.

static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)

@ HiddenVisibility

The GV is hidden.

@ InternalLinkage

Rename collisions when linking (static functions).

@ LinkOnceODRLinkage

Same, but only replaced by something equivalent.

ReturnInst * CreateRetVoid()

Create a 'ret void' instruction.

This provides a uniform API for creating instructions and inserting them into a basic block: either a...

This is an important class for using LLVM in a threaded context.

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

MachineFunctionProperties & set(Property P)

StringRef getName() const

getName - Return the name of the corresponding LLVM function.

const MachineFunctionProperties & getProperties() const

Get the function properties.

This class contains meta information specific to a module.

const Module * getModule() const

MachineFunction & getOrCreateMachineFunction(Function &F)

Returns the MachineFunction constructed for the IR function F.

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

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

bool starts_with(StringRef Prefix) const

Check if this string starts with the given Prefix.

Basic implementation of MachineFunctionPass wrapping one or more ThunkInserters passed as type parame...

bool doInitialization(Module &M) override

doInitialization - Virtual method overridden by subclasses to do any necessary initialization before ...

bool runOnMachineFunction(MachineFunction &MF) override

runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...

std::tuple< Inserters... > TIs

ThunkInserterPass(char &ID)

This class assists in inserting MI thunk functions into the module and rewriting the existing machine...

bool mayUseThunk(const MachineFunction &MF)

Checks if MF may use thunks (true - maybe, false - definitely not).

void createThunkFunction(MachineModuleInfo &MMI, StringRef Name, bool Comdat=true, StringRef TargetAttrs="")

Create an empty thunk function.

InsertedThunksTy insertThunks(MachineModuleInfo &MMI, MachineFunction &MF, InsertedThunksTy ExistingThunks)

Rewrites the function if necessary, returns the set of thunks added.

bool run(MachineModuleInfo &MMI, MachineFunction &MF)

void doInitialization(Module &M)

Initializes thunk inserter.

const char * getThunkPrefix()

Returns common prefix for thunk function's names.

void populateThunk(MachineFunction &MF)

Populate the thunk function with instructions.

The instances of the Type class are immutable: once they are created, they are never changed.

static Type * getVoidTy(LLVMContext &C)

This is an optimization pass for GlobalISel generic memory operations.