clang: lib/CIR/CodeGen/CIRGenCXX.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

16

19#include "llvm/Support/SaveAndRestore.h"

20

21using namespace clang;

23

25 cir::GlobalOp globalOp) {

26 assert((varDecl->hasGlobalStorage() ||

27 (varDecl->hasLocalStorage() &&

29 "VarDecl must have global or local (in the case of OpenCL) storage!");

30 assert(varDecl->getType()->isReferenceType() &&

31 "Should not call emitDeclInit on a reference!");

32

34

35

36 mlir::OpBuilder::InsertionGuard guard(builder);

37 mlir::Block *block = builder.createBlock(&globalOp.getCtorRegion());

39 builder.getInsertionBlock()};

41 builder.setInsertionPointToStart(block);

42

45

48

54 break;

57 break;

64 break;

65 }

66

67

68 builder.setInsertionPointToEnd(block);

69 cir::YieldOp::create(builder, globalOp.getLoc());

70}

71

73 cir::GlobalOp addr) {

74

75

76

77

78

79

81

82

83

84 switch (dtorKind) {

86 return;

87

89 break;

90

94

95 assert(!vd->getTLSKind() && "should have rejected this");

96 return;

97 }

98

99

101

102

103 mlir::OpBuilder::InsertionGuard guard(builder);

104 mlir::Block *block = builder.createBlock(&addr.getDtorRegion());

106 builder.getInsertionBlock()};

108 builder.setInsertionPointToStart(block);

109

112

113

114

115

116

118 bool canRegisterDestructor =

119 record && (!cgm.getCXXABI().hasThisReturn(

122

123

124

125

126 cir::FuncOp fnOp;

127 if (record && (canRegisterDestructor || cgm.getCodeGenOpts().CXAAtExit)) {

133

134

135

139 mlir::FlatSymbolRefAttr::get(fnOp.getSymNameAttr()),

140 mlir::ValueRange{cgm.getAddrOfGlobalVar(vd)});

141 assert(fnOp && "expected cir.func");

142

143

145 } else {

146

147

148

149

150

151

152

153

158 }

159

160 builder.setInsertionPointToEnd(block);

161 if (block->empty()) {

162 block->erase();

163

164 builder.clearInsertionPoint();

165 } else {

166 cir::YieldOp::create(builder, addr.getLoc());

167 }

168}

169

178 curCGF = &cgf;

179 {

180 mlir::OpBuilder::InsertionGuard guard(builder);

182 }

183 curCGF = nullptr;

184

185 setNonAliasAttributes(gd, fn);

187 fn);

188 return fn;

189}

190

191

192

193

194

195

196

197

199 cir::GlobalOp addr,

200 bool performInit) {

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

220

221

222

225 curCGF->curFn = addr;

226

229

231

234

237

238 if (performInit)

240

242 errorNYI(varDecl->getSourceRange(), "global with constant storage");

243 else

245 return;

246 }

247

248 errorNYI(varDecl->getSourceRange(), "global with reference type");

249}

static void emitDeclDestroy(CIRGenFunction &cgf, const VarDecl *vd, cir::GlobalOp addr)

Definition CIRGenCXX.cpp:72

static void emitDeclInit(CIRGenFunction &cgf, const VarDecl *varDecl, cir::GlobalOp globalOp)

Definition CIRGenCXX.cpp:24

cir::CallOp createCallOp(mlir::Location loc, mlir::SymbolRefAttr callee, mlir::Type returnType, mlir::ValueRange operands, llvm::ArrayRef< mlir::NamedAttribute > attrs={})

mlir::Value createGetGlobal(mlir::Location loc, cir::GlobalOp global, bool threadLocal=false)

const LangOptions & getLangOpts() const

CharUnits getDeclAlign(const Decl *D, bool ForAlignof=false) const

Return a conservative estimate of the alignment of the specified decl D.

static AggValueSlot forLValue(const LValue &LV, IsDestructed_t isDestructed, IsAliased_t isAliased, Overlap_t mayOverlap, IsZeroed_t isZeroed=IsNotZeroed)

virtual void registerGlobalDtor(const VarDecl *vd, cir::FuncOp dtor, mlir::Value addr)=0

Emit code to force the execution of a destructor during global teardown.

virtual bool canCallMismatchedFunctionType() const

Returns true if the target allows calling a function through a pointer with a different signature tha...

static cir::TypeEvaluationKind getEvaluationKind(clang::QualType type)

Return the cir::TypeEvaluationKind of QualType type.

cir::FuncOp generateCode(clang::GlobalDecl gd, cir::FuncOp fn, cir::FuncType funcType)

mlir::Location getLoc(clang::SourceLocation srcLoc)

Helpers to convert Clang's SourceLocation to a MLIR Location.

mlir::Type convertTypeForMem(QualType t)

void emitScalarInit(const clang::Expr *init, mlir::Location loc, LValue lvalue, bool capturedByInit=false)

CIRGenBuilderTy & getBuilder()

void emitDestroy(Address addr, QualType type, Destroyer *destroyer)

Immediately perform the destruction of the given object.

Destroyer * getDestroyer(clang::QualType::DestructionKind kind)

void emitComplexExprIntoLValue(const Expr *e, LValue dest, bool isInit)

LValue makeAddrLValue(Address addr, QualType ty, AlignmentSource source=AlignmentSource::Type)

clang::ASTContext & getContext() const

void emitAggExpr(const clang::Expr *e, AggValueSlot slot)

This class organizes the cross-function state that is used while generating CIR code.

void emitCXXGlobalVarDeclInit(const VarDecl *varDecl, cir::GlobalOp addr, bool performInit)

Emit the function that initializes the specified global.

Definition CIRGenCXX.cpp:198

DiagnosticBuilder errorNYI(SourceLocation, llvm::StringRef)

Helpers to emit "not yet implemented" error diagnostics.

clang::ASTContext & getASTContext() const

cir::FuncOp getAddrOfCXXStructor(clang::GlobalDecl gd, const CIRGenFunctionInfo *fnInfo=nullptr, cir::FuncType fnType=nullptr, bool dontDefer=false, ForDefinition_t isForDefinition=NotForDefinition)

std::pair< cir::FuncType, cir::FuncOp > getAddrAndTypeOfCXXStructor(clang::GlobalDecl gd, const CIRGenFunctionInfo *fnInfo=nullptr, cir::FuncType fnType=nullptr, bool dontDefer=false, ForDefinition_t isForDefinition=NotForDefinition)

mlir::Value getAddrOfGlobalVar(const VarDecl *d, mlir::Type ty={}, ForDefinition_t isForDefinition=NotForDefinition)

Return the mlir::Value for the address of the given global variable.

const clang::CodeGenOptions & getCodeGenOpts() const

cir::FuncOp codegenCXXStructor(clang::GlobalDecl gd)

Definition CIRGenCXX.cpp:170

mlir::Location getLoc(clang::SourceLocation cLoc)

Helpers to convert the presumed location of Clang's SourceLocation to an MLIR Location.

CIRGenCXXABI & getCXXABI() const

void setCIRFunctionAttributesForDefinition(const clang::FunctionDecl *fd, cir::FuncOp f)

Set extra attributes (inline, etc.) for a function.

void setFunctionLinkage(GlobalDecl gd, cir::FuncOp f)

const CIRGenFunctionInfo & arrangeCXXStructorDeclaration(clang::GlobalDecl gd)

cir::FuncType getFunctionType(const CIRGenFunctionInfo &info)

Get the CIR function type for.

Represents a C++ destructor within a class.

Represents a C++ struct/union/class.

bool hasTrivialDestructor() const

Determine whether this class has a trivial destructor (C++ [class.dtor]p3)

CXXDestructorDecl * getDestructor() const

Returns the destructor decl for this class.

CharUnits - This is an opaque type for sizes expressed in character units.

This represents one expression.

GlobalDecl - represents a global declaration.

const Decl * getDecl() const

A (possibly-)qualified type.

@ DK_objc_strong_lifetime

bool isReferenceType() const

Represents a variable declaration or definition.

TLSKind getTLSKind() const

SourceRange getSourceRange() const override LLVM_READONLY

Source range that this declaration covers.

QualType::DestructionKind needsDestruction(const ASTContext &Ctx) const

Would the destruction of this variable have any effect, and if so, what kind?

const internal::VariadicDynCastAllOfMatcher< Decl, VarDecl > varDecl

Matches variable declarations.

const internal::VariadicAllOfMatcher< Type > type

Matches Types in the clang AST.

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

@ Dtor_Complete

Complete object dtor.

static bool addressSpace()

static bool aggValueSlotGC()

static bool astVarDeclInterface()

Represents a scope, including function bodies, compound statements, and the substatements of if/while...