clang: lib/AST/ByteCode/Function.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15#ifndef LLVM_CLANG_AST_INTERP_FUNCTION_H

16#define LLVM_CLANG_AST_INTERP_FUNCTION_H

17

23#include "llvm/ADT/PointerUnion.h"

24#include "llvm/Support/raw_ostream.h"

25

27namespace interp {

28class Program;

29class ByteCodeEmitter;

32

33

34

35

37public:

38

40

42

44 };

45

47

49

50 llvm::iterator_rangeLocalVectorTy::const\_iterator locals() const {

51 return llvm::make_range(Descriptors.begin(), Descriptors.end());

52 }

53

54private:

55

57};

58

60 llvm::PointerUnion<const FunctionDecl *, const BlockExpr *>;

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

82public:

84

85

87

88 unsigned getArgSize() const { return ArgSize; }

89

90

92

94

95

97 return dyn_cast<const FunctionDecl *>(Source);

98 }

100 return dyn_cast<const BlockExpr *>(Source);

101 }

102

103

104

106 if (!Source || getDecl())

107 return "<>";

108

110 }

111

112

114

115

116 bool hasRVO() const { return HasRVO; }

117

119

120

121 llvm::iterator_range<llvm::SmallVector<Scope, 2>::const_iterator>

123 return llvm::make_range(Scopes.begin(), Scopes.end());

124 }

125

126

129 llvm::iterator_range<arg_reverse_iterator> args_reverse() const {

130 return llvm::reverse(ParamTypes);

131 }

132

133

135 const Scope &getScope(unsigned Idx) const { return Scopes[Idx]; }

136

137

139

140

142

143

145

146

148 return isa_and_nonnull(

149 dyn_cast<const FunctionDecl *>(Source));

150 }

151

153 return isa_and_nonnull(

154 dyn_cast<const FunctionDecl *>(Source));

155 }

156

157

159 if (const auto *MD = dyn_cast_if_present(

160 dyn_cast<const FunctionDecl *>(Source)))

162 return nullptr;

163 }

164

165

166

168 if (const auto *MD = dyn_cast_if_present(

169 dyn_cast<const FunctionDecl *>(Source)))

170 return MD->isLambdaStaticInvoker();

171 return false;

172 }

173

174

175

177 if (const auto *MD = dyn_cast_if_present(

178 dyn_cast<const FunctionDecl *>(Source)))

180 return false;

181 }

182

183

185

187

188

189 bool hasBody() const { return HasBody; }

190

191

193

195

197

199

201

202 unsigned getNumParams() const { return ParamTypes.size(); }

203

204

205

209 }

212 }

213

215 if (const auto *MD = dyn_cast_if_present(

217 return MD->isExplicitObjectMemberFunction();

218 return false;

219 }

220

222 return ParamOffsets[ParamIndex];

223 }

224

226 return ParamTypes[ParamIndex];

227 }

228

229private:

230

233 llvm::DenseMap<unsigned, ParamDescriptor> &&Params,

235 bool HasRVO, unsigned BuiltinID);

236

237

238 void setCode(unsigned NewFrameSize, std::vectorstd::byte &&NewCode,

240 bool NewHasBody) {

241 FrameSize = NewFrameSize;

242 Code = std::move(NewCode);

243 SrcMap = std::move(NewSrcMap);

244 Scopes = std::move(NewScopes);

245 IsValid = true;

246 HasBody = NewHasBody;

247 }

248

249 void setIsFullyCompiled(bool FC) { IsFullyCompiled = FC; }

250 void setDefined(bool D) { Defined = D; }

251

252private:

255

256

258

260

261 unsigned FrameSize = 0;

262

263 unsigned ArgSize;

264

265 std::vectorstd::byte Code;

266

268

270

272

273 llvm::DenseMap<unsigned, ParamDescriptor> Params;

274

276

277 bool IsValid = false;

278

279

280 bool IsFullyCompiled = false;

281

282

283 bool HasThisPointer = false;

284

285

286

287 bool HasRVO = false;

288

289 bool HasBody = false;

290 bool Defined = false;

291 bool Variadic = false;

292 unsigned BuiltinID = 0;

293

294public:

295

296 void dump() const;

297 void dump(llvm::raw_ostream &OS) const;

298};

299

300}

301}

302

303#endif

This file provides some common utility functions for processing Lambda related AST Constructs.

BlockExpr - Adaptor class for mixing a BlockDecl with expressions.

Represents a C++ struct/union/class.

DeclContext * getParent()

getParent - Returns the containing DeclContext.

Represents a function declaration or definition.

std::string getQualifiedNameAsString() const

An emitter which links the program to bytecode for later use.

Pointer into the code segment.

Scope & getScope(unsigned Idx)

Returns a specific scope.

CodePtr getCodeBegin() const

Returns a pointer to the start of the code.

bool isDestructor() const

Checks if the function is a destructor.

CodePtr getCodeEnd() const

Returns a pointer to the end of the code.

const std::string getName() const

Returns the name of the function decl this code was generated for.

unsigned getNumParams() const

bool isDefined() const

Checks if the function is defined.

bool hasNonNullAttr() const

PrimType getParamType(unsigned ParamIndex) const

std::pair< PrimType, Descriptor * > ParamDescriptor

const CXXRecordDecl * getParentDecl() const

Returns the parent record decl, if any.

unsigned getFrameSize() const

Returns the size of the function's local stack.

bool isLambdaCallOperator() const

Returns whether this function is the call operator of a lambda record decl.

const BlockExpr * getExpr() const

bool isFullyCompiled() const

Checks if the function is fully done compiling.

bool isConstructor() const

Checks if the function is a constructor.

unsigned getParamOffset(unsigned ParamIndex) const

const FunctionDecl * getDecl() const

Returns the original FunctionDecl.

bool hasBody() const

Checks if the function already has a body attached.

bool isUnevaluatedBuiltin() const

bool hasThisPointer() const

bool isVirtual() const

Checks if the function is virtual.

unsigned getBuiltinID() const

void dump() const

Dumps the disassembled bytecode to llvm::errs().

llvm::iterator_range< arg_reverse_iterator > args_reverse() const

bool isConstexpr() const

Checks if the function is valid to call in constexpr.

const Scope & getScope(unsigned Idx) const

bool isThisPointerExplicit() const

unsigned getNumWrittenParams() const

Returns the number of parameter this function takes when it's called, i.e excluding the instance poin...

unsigned getWrittenArgSize() const

unsigned getArgSize() const

Returns the size of the argument stack.

bool isLambdaStaticInvoker() const

Returns whether this function is a lambda static invoker, which we generate custom byte code for.

SmallVectorImpl< PrimType >::const_reverse_iterator arg_reverse_iterator

Range over argument types.

SourceInfo getSource(CodePtr PC) const

Returns the source information at a given PC.

ParamDescriptor getParamDescriptor(unsigned Offset) const

Returns a parameter descriptor.

llvm::iterator_range< llvm::SmallVector< Scope, 2 >::const_iterator > scopes() const

Range over the scope blocks.

bool hasRVO() const

Checks if the first argument is a RVO pointer.

The program contains and links the bytecode for all functions.

llvm::SmallVector< Local, 8 > LocalVectorTy

llvm::iterator_range< LocalVectorTy::const_iterator > locals() const

Scope(LocalVectorTy &&Descriptors)

Describes the statement/declaration an opcode was generated from.

std::vector< std::pair< unsigned, SourceInfo > > SourceMap

llvm::PointerUnion< const FunctionDecl *, const BlockExpr * > FunctionDeclTy

constexpr size_t align(size_t Size)

Aligns a size to the pointer alignment.

PrimType

Enumeration of the primitive types of the VM.

size_t primSize(PrimType Type)

Returns the size of a primitive type in bytes.

The JSON file list parser is used to communicate input to InstallAPI.

bool isLambdaCallOperator(const CXXMethodDecl *MD)

Describes a memory block created by an allocation site.

Information about a local's storage.

unsigned Offset

Offset of the local in frame.

Descriptor * Desc

Descriptor of the local.