clang: lib/CodeGen/CGCall.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14#ifndef LLVM_CLANG_LIB_CODEGEN_CGCALL_H

15#define LLVM_CLANG_LIB_CODEGEN_CGCALL_H

16

24#include "llvm/ADT/STLForwardCompat.h"

25#include "llvm/IR/Value.h"

26

27namespace llvm {

28class Type;

30}

31

37

39

40

42

44

46

47public:

50 : CalleeProtoTy(calleeProtoTy), CalleeDecl(calleeDecl) {}

52 : CalleeProtoTy(calleeProtoTy) {}

54 : CalleeProtoTy(nullptr), CalleeDecl(calleeDecl) {}

55

57 return CalleeProtoTy;

58 }

60};

61

62

63class CGCallee {

64 enum class SpecialKind : uintptr_t {

65 Invalid,

66 Builtin,

67 PseudoDestructor,

68 Virtual,

69

70 Last = Virtual

71 };

72

73 struct OrdinaryInfoStorage {

76 };

77 struct BuiltinInfoStorage {

79 unsigned ID;

80 };

81 struct PseudoDestructorInfoStorage {

83 };

84 struct VirtualInfoStorage {

88 llvm::FunctionType *FTy;

89 };

90

91 SpecialKind KindOrFunctionPointer;

92 union {

97 };

98

99 explicit CGCallee(SpecialKind kind) : KindOrFunctionPointer(kind) {}

100

102 : KindOrFunctionPointer(SpecialKind::Builtin) {

105 }

106

107public:

108 CGCallee() : KindOrFunctionPointer(SpecialKind::Invalid) {}

109

110

111

113

115 : KindOrFunctionPointer(

116 SpecialKind(reinterpret_cast<uintptr_t>(functionPtr))) {

118 OrdinaryInfo.PointerAuthInfo = pointerAuthInfo;

119 assert(functionPtr && "configuring callee without function pointer");

120 assert(functionPtr->getType()->isPointerTy());

121 }

122

125 CGCallee result(SpecialKind::Builtin);

128 return result;

129 }

130

132 CGCallee result(SpecialKind::PseudoDestructor);

134 return result;

135 }

136

137 static CGCallee forDirect(llvm::Constant *functionPtr,

139 return CGCallee(abstractInfo, functionPtr);

140 }

141

142 static CGCallee forDirect(llvm::FunctionCallee functionPtr,

144 return CGCallee(abstractInfo, functionPtr.getCallee());

145 }

146

148 llvm::FunctionType *FTy) {

149 CGCallee result(SpecialKind::Virtual);

154 return result;

155 }

156

158 return KindOrFunctionPointer == SpecialKind::Builtin;

159 }

168

170 return KindOrFunctionPointer == SpecialKind::PseudoDestructor;

171 }

176

192 return reinterpret_cast<llvm::Value *>(uintptr_t(KindOrFunctionPointer));

193 }

196 KindOrFunctionPointer =

197 SpecialKind(reinterpret_cast<uintptr_t>(functionPtr));

198 }

203

205 return KindOrFunctionPointer == SpecialKind::Virtual;

206 }

223

224

225

227};

228

230private:

231 union {

233 LValue LV;

234 };

235 bool HasLV;

236

237

238

239 mutable bool IsUsed;

240

241public:

249

250

251

253

255 assert(HasLV && !IsUsed);

256 return LV;

257 }

259 assert(!HasLV && !IsUsed);

260 return RV;

261 }

263 assert(!HasLV);

264 RV = _RV;

265 }

266

267 bool isAggregate() const { return HasLV || RV.isAggregate(); }

268

270};

271

272

273

275public:

277

279

280

282

283

285

286

288

289

290

292 };

293

301

303

307

308

309

310

312 llvm::append_range(*this, other);

313 llvm::append_range(Writebacks, other.Writebacks);

314 llvm::append_range(CleanupsToDeactivate, other.CleanupsToDeactivate);

315 assert(!(StackBase && other.StackBase) && "can't merge stackbases");

316 if (!StackBase)

317 StackBase = other.StackBase;

318 }

319

321 const Expr *writebackExpr = nullptr) {

322 Writeback writeback = {srcLV, temporary, toUse, writebackExpr};

323 Writebacks.push_back(writeback);

324 }

325

327

328 typedef llvm::iterator_range<SmallVectorImpl::const_iterator>

330

334

336 llvm::Instruction *IsActiveIP) {

338 ArgCleanup.Cleanup = Cleanup;

340 CleanupsToDeactivate.push_back(ArgCleanup);

341 }

342

344 return CleanupsToDeactivate;

345 }

346

348 llvm::Instruction *getStackBase() const { return StackBase; }

350

351

352

354

355

357 std::reverse(Writebacks.begin(), Writebacks.end());

358 }

359

360private:

362

363

364

365

367

368

369 llvm::CallInst *StackBase = nullptr;

370};

371

372

373

374

376

377

378

381

382

383 LLVM_PREFERRED_TYPE(bool)

384 unsigned IsVolatile : 1;

385 LLVM_PREFERRED_TYPE(bool)

386 unsigned IsUnused : 1;

387 LLVM_PREFERRED_TYPE(bool)

388 unsigned IsExternallyDestructed : 1;

389

390public:

394 bool IsExternallyDestructed = false)

395 : Addr(Addr), IsVolatile(IsVolatile), IsUnused(IsUnused),

396 IsExternallyDestructed(IsExternallyDestructed) {}

397

398 bool isNull() const { return !Addr.isValid(); }

401 bool isUnused() const { return IsUnused; }

404};

405

406

407

408

409

410

411

412

413

414

415

416

417

418

419

420

421

422

427 bool WillInternalize);

428

435

437 return static_cast<FnInfoOpts>(llvm::to_underlying(A) |

438 llvm::to_underlying(B));

439}

440

442 return static_cast<FnInfoOpts>(llvm::to_underlying(A) &

443 llvm::to_underlying(B));

444}

445

447 A = A | B;

448 return A;

449}

450

452 A = A & B;

453 return A;

454}

455

461

462}

463}

464

465#endif

Forward declaration of all AST node types.

C Language Family Type Representation.

Represents a C++ pseudo-destructor (C++ [expr.pseudo]).

CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).

CodeGenOptions - Track various options which control how the code is optimized and passed to the back...

Like RawAddress, an abstract representation of an aligned address, but the pointer contained in this ...

Abstract information about a function or function prototype.

Definition CGCall.h:41

const GlobalDecl getCalleeDecl() const

Definition CGCall.h:59

CGCalleeInfo(const FunctionProtoType *calleeProtoTy)

Definition CGCall.h:51

CGCalleeInfo(const FunctionProtoType *calleeProtoTy, GlobalDecl calleeDecl)

Definition CGCall.h:49

const FunctionProtoType * getCalleeFunctionProtoType() const

Definition CGCall.h:56

CGCalleeInfo()

Definition CGCall.h:48

CGCalleeInfo(GlobalDecl calleeDecl)

Definition CGCall.h:53

All available information about a concrete callee.

Definition CGCall.h:63

CGCalleeInfo getAbstractInfo() const

Definition CGCall.h:180

CGCallee prepareConcreteCallee(CodeGenFunction &CGF) const

If this is a delayed callee computation of some sort, prepare a concrete callee.

VirtualInfoStorage VirtualInfo

Definition CGCall.h:96

CGCallee()

Definition CGCall.h:108

void setPointerAuthInfo(CGPointerAuthInfo PointerAuth)

Definition CGCall.h:199

bool isVirtual() const

Definition CGCall.h:204

const CXXPseudoDestructorExpr * getPseudoDestructorExpr() const

Definition CGCall.h:172

bool isOrdinary() const

Definition CGCall.h:177

Address getThisAddress() const

Definition CGCall.h:215

const CallExpr * getVirtualCallExpr() const

Definition CGCall.h:207

CGCallee(const CGCalleeInfo &abstractInfo, llvm::Value *functionPtr, const CGPointerAuthInfo &pointerAuthInfo=CGPointerAuthInfo())

Construct a callee.

Definition CGCall.h:112

BuiltinInfoStorage BuiltinInfo

Definition CGCall.h:94

bool isPseudoDestructor() const

Definition CGCall.h:169

llvm::Value * getFunctionPointer() const

Definition CGCall.h:190

PseudoDestructorInfoStorage PseudoDestructorInfo

Definition CGCall.h:95

static CGCallee forBuiltin(unsigned builtinID, const FunctionDecl *builtinDecl)

Definition CGCall.h:123

unsigned getBuiltinID() const

Definition CGCall.h:164

static CGCallee forVirtual(const CallExpr *CE, GlobalDecl MD, Address Addr, llvm::FunctionType *FTy)

Definition CGCall.h:147

void setFunctionPointer(llvm::Value *functionPtr)

Definition CGCall.h:194

static CGCallee forDirect(llvm::FunctionCallee functionPtr, const CGCalleeInfo &abstractInfo=CGCalleeInfo())

Definition CGCall.h:142

static CGCallee forDirect(llvm::Constant *functionPtr, const CGCalleeInfo &abstractInfo=CGCalleeInfo())

Definition CGCall.h:137

bool isBuiltin() const

Definition CGCall.h:157

llvm::FunctionType * getVirtualFunctionType() const

Definition CGCall.h:219

OrdinaryInfoStorage OrdinaryInfo

Definition CGCall.h:93

const FunctionDecl * getBuiltinDecl() const

Definition CGCall.h:160

const CGPointerAuthInfo & getPointerAuthInfo() const

Definition CGCall.h:186

static CGCallee forPseudoDestructor(const CXXPseudoDestructorExpr *E)

Definition CGCall.h:131

GlobalDecl getVirtualMethodDecl() const

Definition CGCall.h:211

void addWriteback(LValue srcLV, Address temporary, llvm::Value *toUse, const Expr *writebackExpr=nullptr)

Definition CGCall.h:320

llvm::Instruction * getStackBase() const

Definition CGCall.h:348

void addUncopiedAggregate(LValue LV, QualType type)

Definition CGCall.h:304

llvm::iterator_range< SmallVectorImpl< Writeback >::const_iterator > writeback_const_range

Definition CGCall.h:329

void addArgCleanupDeactivation(EHScopeStack::stable_iterator Cleanup, llvm::Instruction *IsActiveIP)

Definition CGCall.h:335

ArrayRef< CallArgCleanup > getCleanupsToDeactivate() const

Definition CGCall.h:343

bool hasWritebacks() const

Definition CGCall.h:326

void add(RValue rvalue, QualType type)

Definition CGCall.h:302

bool isUsingInAlloca() const

Returns if we're using an inalloca struct to pass arguments in memory.

Definition CGCall.h:353

void allocateArgumentMemory(CodeGenFunction &CGF)

void reverseWritebacks()

Definition CGCall.h:356

void freeArgumentMemory(CodeGenFunction &CGF) const

writeback_const_range writebacks() const

Definition CGCall.h:331

void addFrom(const CallArgList &other)

Add all the arguments from another CallArgList to this one.

Definition CGCall.h:311

CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...

A saved depth on the scope stack.

FunctionArgList - Type for representing both the decl and type of parameters to a function.

Definition CGCall.h:375

LValue - This represents an lvalue references.

RValue - This trivial value class is used to represent the result of an expression that is evaluated.

bool isNull() const

Definition CGCall.h:398

Address getValue() const

Definition CGCall.h:400

bool isExternallyDestructed() const

Definition CGCall.h:402

ReturnValueSlot()

Definition CGCall.h:391

bool isVolatile() const

Definition CGCall.h:399

ReturnValueSlot(Address Addr, bool IsVolatile, bool IsUnused=false, bool IsExternallyDestructed=false)

Definition CGCall.h:393

Address getAddress() const

Definition CGCall.h:403

bool isUnused() const

Definition CGCall.h:401

Decl - This represents one declaration (or definition), e.g.

This represents one expression.

Represents a function declaration or definition.

Represents a prototype with parameter type info, e.g.

GlobalDecl - represents a global declaration.

Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...

A (possibly-)qualified type.

Options for controlling the target.

Represents a variable declaration or definition.

@ Decl

The l-value was an access to a declared entity or something equivalently strong, like the address of ...

FnInfoOpts & operator&=(FnInfoOpts &A, FnInfoOpts B)

Definition CGCall.h:451

FnInfoOpts operator&(FnInfoOpts A, FnInfoOpts B)

Definition CGCall.h:441

FnInfoOpts

Definition CGCall.h:429

@ IsInstanceMethod

Definition CGCall.h:431

@ IsChainCall

Definition CGCall.h:432

@ IsDelegateCall

Definition CGCall.h:433

FnInfoOpts & operator|=(FnInfoOpts &A, FnInfoOpts B)

Definition CGCall.h:446

void mergeDefaultFunctionDefinitionAttributes(llvm::Function &F, const CodeGenOptions &CodeGenOpts, const LangOptions &LangOpts, const TargetOptions &TargetOpts, bool WillInternalize)

Adds attributes to F according to our CodeGenOpts and LangOpts, as though we had emitted it ourselves...

BlockFlags operator|(BlockLiteralFlags l, BlockLiteralFlags r)

const internal::VariadicAllOfMatcher< Type > type

Matches Types in the clang AST.

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

nullptr

This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...

Diagnostic wrappers for TextAPI types for error reporting.

__UINTPTR_TYPE__ uintptr_t

An unsigned integer type with the property that any valid pointer to void can be converted to this ty...

llvm::Instruction * IsActiveIP

The "is active" insertion point.

Definition CGCall.h:299

EHScopeStack::stable_iterator Cleanup

Definition CGCall.h:295

llvm::Value * ToUse

A value to "use" after the writeback, or null.

Definition CGCall.h:287

LValue Source

The original argument.

Definition CGCall.h:281

Address Temporary

The temporary alloca.

Definition CGCall.h:284

const Expr * WritebackExpr

An Expression (optional) that performs the writeback with any required casting.

Definition CGCall.h:291

LValue getKnownLValue() const

Definition CGCall.h:254

RValue getKnownRValue() const

Definition CGCall.h:258

QualType getType() const

Definition CGCall.h:248

bool isAggregate() const

Definition CGCall.h:267

CallArg(LValue lv, QualType ty)

Definition CGCall.h:245

void setRValue(RValue _RV)

Definition CGCall.h:262

QualType Ty

Definition CGCall.h:242

LValue LV

Definition CGCall.h:233

void copyInto(CodeGenFunction &CGF, Address A) const

RValue RV

Definition CGCall.h:232

CallArg(RValue rv, QualType ty)

Definition CGCall.h:243

bool hasLValue() const

Definition CGCall.h:247

RValue getRValue(CodeGenFunction &CGF) const

~DisableDebugLocationUpdates()

CodeGenFunction & CGF

Definition CGCall.h:457

DisableDebugLocationUpdates(CodeGenFunction &CGF)