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

1

2

3

4

5

6

7

8

9

10

11

12

15#include "mlir/IR/Location.h"

22

23using namespace clang;

25

28 mlir::OpBuilder::InsertPoint ip) {

31 cgm.errorNYI(d.getSourceRange(), "emitAutoVarAlloca: address space");

32

34 bool nrvo =

36

41 "emitAutoVarDecl: decl escaping by reference");

42

44

45

48

50

53

54

55

56

57

58

59

60

65 getContext().getBaseElementType(ty)->isObjCObjectPointerType()) &&

67

68

69

70

71

72

73

74

75 bool needsDtor =

79 (cgm.getCodeGenOpts().MergeAllConstants && !nrvo &&

82 cgm.errorNYI(d.getSourceRange(), "emitAutoVarAlloca: type constant");

83 }

84

86 }

87

88

89

90

91

92 if (nrvo) {

93

94

95

97

99 if (const auto *cxxrd = dyn_cast(rd);

100 (cxxrd && !cxxrd->hasTrivialDestructor()) ||

101 rd->isNonTrivialToPrimitiveDestroy()) {

102

103

104

105

106 cir::ConstantOp falseNVRO = builder.getFalse(loc);

109 nullptr);

110 assert(builder.getInsertionBlock());

111 builder.createStore(loc, falseNVRO, nrvoFlag);

112

113

116 }

117 }

118 } else {

119

121

123 nullptr, nullptr, ip);

125 alignment);

126 }

127 } else {

128

131

134 cgm.getDataLayout().getAlignment(defaultTy, false));

136

137 mlir::Value v = builder.createStackSave(loc, defaultTy);

139 builder.createStore(loc, v, stack);

140

142

143

144

146 }

147

150

151

152 address =

154 nullptr, builder.saveInsertionPoint());

155

156

157

158

160 }

161

162 emission.addr = address;

164

165 return emission;

166}

167

168

169

171 if (!init)

172 return true;

173

174 if (const CXXConstructExpr *construct = dyn_cast(init))

176 if (constructor->isTrivial() && constructor->isDefaultConstructor() &&

177 !construct->requiresZeroInitialization())

178 return true;

179

180 return false;

181}

182

184 Address addr, bool isVolatile,

186 mlir::TypedAttr constant) {

187 mlir::Type ty = constant.getType();

190 if (!constantSize)

191 return;

198

199

200

201

202

203

204

207

208

209

210

211

212 auto allocaOp = addr.getDefiningOpcir::AllocaOp();

213 if (allocaOp)

214 allocaOp.setInitAttr(mlir::UnitAttr::get(&cgm.getMLIRContext()));

215

216

217

218 mlir::Location loc = builder.getUnknownLoc();

222}

223

226 assert(emission.variable && "emission was not valid!");

227

228

230 return;

231

233

235

236

238

239

240

241

242 if (!init && type.isNonTrivialToPrimitiveDefaultInitialize() ==

245 "emitAutoVarInit: non-trivial to default initialize");

246 return;

247 }

248

250

251

252

253

255

256

260 : (d.getAttr()

263

264 auto initializeWhatIsTechnicallyUninitialized = [&](Address addr) {

265 if (trivialAutoVarInit ==

267 return;

268

269 cgm.errorNYI(d.getSourceRange(), "emitAutoVarInit: trivial initialization");

270 };

271

273 initializeWhatIsTechnicallyUninitialized(addr);

274 return;

275 }

276

277 mlir::Attribute constant;

280

281

282

283

284

286 if (constant && !mlir::isacir::ZeroAttr(constant) &&

287 (trivialAutoVarInit !=

289 cgm.errorNYI(d.getSourceRange(), "emitAutoVarInit: constant aggregate");

290 return;

291 }

292 }

293

294

295

296

297

299 initializeWhatIsTechnicallyUninitialized(addr);

302

304

305

307 assert(val && "Should have an address");

308 auto allocaOp = val.getDefiningOpcir::AllocaOp();

309 assert(allocaOp && "Address should come straight out of the alloca");

310

311 if (!allocaOp.use_empty())

312 allocaOp.setInitAttr(mlir::UnitAttr::get(&getMLIRContext()));

313 }

314

315 return;

316 }

317

318

319 auto typedConstant = mlir::dyn_castmlir::TypedAttr(constant);

320 assert(typedConstant && "expected typed attribute");

322

324 assert(init && "expected initializer");

326

328 RValue::get(builder.getConstant(initLoc, typedConstant)), lv);

329 }

330

332 typedConstant);

333}

334

338

339

342

344

345

346 if (d.hasAttr())

347 cgm.errorNYI(d.getSourceRange(), "emitAutoVarCleanups: CleanupAttr");

348}

349

350

351

352

358

360

361

363 return;

364

366

368

369

370 cgm.errorNYI(d.getSourceRange(), "emitVarDecl static sampler type");

371 return;

372 }

373

374 cir::GlobalLinkageKind linkage =

375 cgm.getCIRLinkageVarDefinition(&d, false);

376

377

378

379

380

382 }

383

385 cgm.errorNYI(d.getSourceRange(), "emitVarDecl openCL address space");

386

388

389 CIRGenFunction::VarDeclContext varDeclCtx{*this, &d};

391}

392

396

397

399 std::string contextName;

401 if (auto *cd = dyn_cast(dc))

403 if (const auto *fd = dyn_cast(dc))

409 else

411

413 return contextName;

414}

415

416

417

418cir::GlobalOp

420 cir::GlobalLinkageKind linkage) {

421

422

423

424

426 return existingGV;

427

430

431

432 if (d.hasAttr())

434

436

439

440 if (d.hasAttr() || d.hasAttr())

442 "getOrCreateStaticVarDecl: LoaderUninitializedAttr");

444

445 mlir::Attribute init = builder.getZeroInitAttr(convertType(ty));

446

447 cir::GlobalOp gv = builder.createVersionedGlobal(

449

451 gv.setInitialValueAttr(init);

452 gv.setAlignment(getASTContext().getDeclAlign(&d).getAsAlign().value());

453

455 gv.setComdat(true);

456

459

461

462

463

464

465

466

467

468

469

470

471

472

474

475

476

479

480 if (!dc)

482 }

483

489 else if (const auto *fd = dyn_cast(dc))

491 else {

492

493

495 }

497

499 }

500

501 return gv;

502}

503

504

505

506

508 const VarDecl &d, cir::GlobalOp gv, cir::GetGlobalOp gvAddr) {

510 mlir::TypedAttr init =

512

513

514

515 if (!init) {

516 cgm.errorNYI(d.getSourceRange(), "static var without initializer");

517 return gv;

518 }

519

520

521

522

524

525

526

527

528

529 if (gv.getSymType() != init.getType()) {

530 gv.setSymType(init.getType());

531

532

533

534

535

536

538 gvAddr.getAddr().setType(builder.getPointerTo(init.getType()));

539 }

540

541 bool needsDtor =

543

545 getContext(), true, !needsDtor));

546 gv.setInitialValueAttr(init);

547

549

550 if (needsDtor) {

551

552

553

555 }

556

557 return gv;

558}

559

561 cir::GlobalLinkageKind linkage) {

562

563

564

565 cir::GlobalOp globalOp = cgm.getOrCreateStaticVarDecl(d, linkage);

566

567

568 mlir::Value addr = builder.createGetGlobal(globalOp);

569 auto getAddrOp = addr.getDefiningOpcir::GetGlobalOp();

570 assert(getAddrOp && "expected cir::GetGlobalOp");

571

573

574

575

578

579

580

581

584 "emitStaticVarDecl: variably modified type");

585 }

586

587

588 mlir::Type expectedType = addr.getType();

589

590 cir::GlobalOp var = globalOp;

591

593

594

597

598 var.setAlignment(alignment.getAsAlign().value());

599

600

601

604

605 if (cgm.getCodeGenOpts().KeepPersistentStorageVariables)

606 cgm.errorNYI(d.getSourceRange(), "static var keep persistent storage");

607

608

609

610

611

612

613

614 mlir::Value castedAddr =

615 builder.createBitcast(getAddrOp.getAddr(), expectedType);

617 cgm.setStaticLocalDeclAddress(&d, var);

618

621}

622

624 LValue lvalue, bool capturedByInit) {

626

629 if (capturedByInit) {

630 cgm.errorNYI(init->getSourceRange(), "emitScalarInit: captured by init");

631 return;

632 }

635}

636

638 LValue lvalue, bool capturedByInit) {

640 if (capturedByInit) {

641 cgm.errorNYI(init->getSourceRange(), "emitExprAsInit: captured by init");

642 return;

643 }

644

646

647 if (type->isReferenceType()) {

649 if (capturedByInit)

650 cgm.errorNYI(init->getSourceRange(), "emitExprAsInit: captured by init");

652 return;

653 }

657 return;

660 if (capturedByInit)

662 "emitExprAsInit: complex type captured by init");

665 true);

666 return;

667 }

669

675 return;

676 }

677 llvm_unreachable("bad evaluation kind");

678}

679

682 case Decl::BuiltinTemplate:

683 case Decl::TranslationUnit:

684 case Decl::ExternCContext:

685 case Decl::Namespace:

686 case Decl::UnresolvedUsingTypename:

687 case Decl::ClassTemplateSpecialization:

688 case Decl::ClassTemplatePartialSpecialization:

689 case Decl::VarTemplateSpecialization:

690 case Decl::VarTemplatePartialSpecialization:

691 case Decl::TemplateTypeParm:

692 case Decl::UnresolvedUsingValue:

693 case Decl::NonTypeTemplateParm:

694 case Decl::CXXDeductionGuide:

695 case Decl::CXXMethod:

696 case Decl::CXXConstructor:

697 case Decl::CXXDestructor:

698 case Decl::CXXConversion:

699 case Decl::Field:

700 case Decl::MSProperty:

701 case Decl::IndirectField:

702 case Decl::ObjCIvar:

703 case Decl::ObjCAtDefsField:

704 case Decl::ParmVar:

705 case Decl::ImplicitParam:

706 case Decl::ClassTemplate:

707 case Decl::VarTemplate:

708 case Decl::FunctionTemplate:

709 case Decl::TypeAliasTemplate:

710 case Decl::TemplateTemplateParm:

711 case Decl::ObjCMethod:

712 case Decl::ObjCCategory:

713 case Decl::ObjCProtocol:

714 case Decl::ObjCInterface:

715 case Decl::ObjCCategoryImpl:

716 case Decl::ObjCImplementation:

717 case Decl::ObjCProperty:

718 case Decl::ObjCCompatibleAlias:

719 case Decl::PragmaComment:

720 case Decl::PragmaDetectMismatch:

721 case Decl::AccessSpec:

722 case Decl::LinkageSpec:

723 case Decl::Export:

724 case Decl::ObjCPropertyImpl:

725 case Decl::FileScopeAsm:

726 case Decl::Friend:

727 case Decl::FriendTemplate:

728 case Decl::Block:

729 case Decl::OutlinedFunction:

730 case Decl::Captured:

731 case Decl::UsingShadow:

732 case Decl::ConstructorUsingShadow:

733 case Decl::ObjCTypeParam:

734 case Decl::Binding:

735 case Decl::UnresolvedUsingIfExists:

736 case Decl::HLSLBuffer:

737 case Decl::HLSLRootSignature:

738 llvm_unreachable("Declaration should not be in declstmts!");

739

740 case Decl::Function:

741 case Decl::EnumConstant:

742 case Decl::StaticAssert:

743 case Decl::Label:

744 case Decl::Import:

745 case Decl::MSGuid:

746 case Decl::TemplateParamObject:

747 case Decl::OMPThreadPrivate:

748 case Decl::OMPGroupPrivate:

749 case Decl::OMPAllocate:

750 case Decl::OMPCapturedExpr:

751 case Decl::OMPRequires:

752 case Decl::Empty:

753 case Decl::Concept:

754 case Decl::LifetimeExtendedTemporary:

755 case Decl::RequiresExprBody:

756 case Decl::UnnamedGlobalConstant:

757

758 return;

759

760 case Decl::Enum:

761 case Decl::Record:

762 case Decl::CXXRecord:

763 case Decl::NamespaceAlias:

764 case Decl::Using:

765 case Decl::UsingEnum:

766 case Decl::UsingDirective:

768 return;

769 case Decl::Var:

770 case Decl::Decomposition: {

773 "Should not see file-scope variables inside a function!");

775 if (evaluateConditionDecl)

777 return;

778 }

779 case Decl::OpenACCDeclare:

781 return;

782 case Decl::OpenACCRoutine:

784 return;

785 case Decl::Typedef:

786 case Decl::TypeAlias: {

790 cgm.errorNYI(d.getSourceRange(), "emitDecl: variably modified type");

791 return;

792 }

793 case Decl::ImplicitConceptSpecialization:

794 case Decl::TopLevelStmt:

795 case Decl::UsingPack:

796 case Decl::OMPDeclareMapper:

797 case Decl::OMPDeclareReduction:

799 std::string("emitDecl: unhandled decl type: ") +

801 }

802}

803

806 if (sanOpts.has(SanitizerKind::NullabilityAssign))

807 return;

808

810}

811

812namespace {

816 : addr(addr), type(type), destroyer(destroyer) {

818 }

819

823

827 }

828};

829

831 DestroyNRVOVariable(Address addr, QualType type, mlir::Value nrvoFlag)

832 : nrvoFlag(nrvoFlag), addr(addr), ty(type) {}

833

834 mlir::Value nrvoFlag;

835 Address addr;

836 QualType ty;

837

838 void emit(CIRGenFunction &cgf, Flags flags) override {

839

840 bool nrvo = flags.isForNormalCleanup() && nrvoFlag;

841

842 CIRGenBuilderTy &builder = cgf.getBuilder();

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

844 if (nrvo) {

845

846 mlir::Location loc = addr.getPointer().getLoc();

847 mlir::Value didNRVO = builder.createFlagLoad(loc, nrvoFlag);

848 mlir::Value notNRVO = builder.createNot(didNRVO);

849 cir::IfOp::create(builder, loc, notNRVO, false,

850 [&](mlir::OpBuilder &b, mlir::Location) {

851 static_cast<Derived *>(this)->emitDestructorCall(cgf);

853 });

854 } else {

855 static_cast<Derived *>(this)->emitDestructorCall(cgf);

856 }

857 }

858

859 virtual ~DestroyNRVOVariable() = default;

860};

861

862struct DestroyNRVOVariableCXX final

863 : DestroyNRVOVariable {

864 DestroyNRVOVariableCXX(Address addr, QualType type,

865 const CXXDestructorDecl *dtor, mlir::Value nrvoFlag)

866 : DestroyNRVOVariable(addr, type, nrvoFlag),

867 dtor(dtor) {}

868

869 const CXXDestructorDecl *dtor;

870

871 void emitDestructorCall(CIRGenFunction &cgf) {

873 false,

874 false, addr, ty);

875 }

876};

877

879 Address stack;

880 CallStackRestore(Address stack) : stack(stack) {}

881 void emit(CIRGenFunction &cgf, Flags flags) override {

882 mlir::Location loc = stack.getPointer().getLoc();

885 }

886};

887}

888

889

890

893 assert(dtorKind && "cannot push destructor for trivial type");

894

897}

898

903

904

905

906

907

908

909

910

912 mlir::Value numElements,

917

918

919

921 cir::PointerType ptrToElmType = builder.getPointerTo(cirElementType);

922

923 uint64_t size = 0;

924

925

926 if (auto constantCount = numElements.getDefiningOpcir::ConstantOp()) {

927 if (auto constIntAttr = constantCount.getValueAttrcir::IntAttr())

928 size = constIntAttr.getUInt();

929 } else {

930 cgm.errorNYI(begin.getDefiningOp()->getLoc(),

931 "dynamic-length array expression");

932 }

933

934 auto arrayTy = cir::ArrayType::get(cirElementType, size);

935 mlir::Value arrayOp = builder.createPtrBitcast(begin, arrayTy);

936

937

938 cir::ArrayDtor::create(

940 [&](mlir::OpBuilder &b, mlir::Location loc) {

941 auto arg = b.getInsertionBlock()->addArgument(ptrToElmType, loc);

942 Address curAddr = Address(arg, cirElementType, elementAlign);

944

945

946 destroyer(*this, curAddr, elementType);

947

948 cir::YieldOp::create(builder, loc);

949 });

950}

951

952

953

954

955

956

957

958

963 return destroyer(*this, addr, type);

964

966

969

970 auto constantCount = length.getDefiningOpcir::ConstantOp();

971 if (!constantCount) {

973 cgm.errorNYI("emitDestroy: variable length array");

974 return;

975 }

976

977 auto constIntAttr = mlir::dyn_castcir::IntAttr(constantCount.getValue());

978

979 if (constIntAttr && constIntAttr.getUInt() == 0)

980 return;

981

982 mlir::Value begin = addr.getPointer();

985

986

987 if (constantCount.use_empty())

988 constantCount.erase();

989}

990

993 switch (kind) {

995 llvm_unreachable("no destroyer for trivial dtor");

1001 cgm.errorNYI("getDestroyer: other destruction kind");

1002 return nullptr;

1003 }

1004 llvm_unreachable("Unknown DestructionKind");

1005}

1006

1008 ehStack.pushCleanup(kind, spMem);

1009}

1010

1011

1016

1017

1018

1020

1023

1026

1027 switch (dtorKind) {

1029 llvm_unreachable("no cleanup for trivially-destructible variable");

1030

1032

1033

1035 assert(type->isArrayType());

1037 ehStack.pushCleanup(cleanupKind, addr, type, dtor,

1039 return;

1040 }

1041

1042 break;

1043

1047 cgm.errorNYI(var->getSourceRange(),

1048 "emitAutoVarTypeCleanup: other dtor kind");

1049 return;

1050 }

1051

1052

1053 if (!destroyer)

1055

1057 ehStack.pushCleanup(cleanupKind, addr, type, destroyer);

1058}

1059

1061 if (auto *dd = dyn_cast_if_present(vd)) {

1062 for (auto *b : dd->flat_bindings())

1063 if (auto *hd = b->getHoldingVar())

1065 }

1066}

static void emit(Program &P, llvm::SmallVectorImpl< std::byte > &Code, const T &Val, bool &Success)

Helper to write bytecode and bail out if 32-bit offsets become invalid.

static void emitStoresForConstant(CIRGenModule &cgm, const VarDecl &d, Address addr, bool isVolatile, CIRGenBuilderTy &builder, mlir::TypedAttr constant)

Definition CIRGenDecl.cpp:183

static std::string getStaticDeclName(CIRGenModule &cgm, const VarDecl &d)

Definition CIRGenDecl.cpp:393

This file defines OpenACC nodes for declarative directives.

Defines the clang::Expr interface and subclasses for C++ expressions.

cir::ConstantOp getConstant(mlir::Location loc, mlir::TypedAttr attr)

mlir::Value createNot(mlir::Value value)

cir::YieldOp createYield(mlir::Location loc, mlir::ValueRange value={})

Create a yield operation.

cir::LoadOp createFlagLoad(mlir::Location loc, mlir::Value addr)

Emit a load from an boolean flag variable.

llvm::TypeSize getTypeAllocSize(mlir::Type ty) const

Returns the offset in bytes between successive objects of the specified type, including alignment pad...

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.

const ArrayType * getAsArrayType(QualType T) const

Type Query functions.

Represents an array type, per C99 6.7.5.2 - Array Declarators.

mlir::Value getPointer() const

mlir::Type getElementType() const

Address withElementType(CIRGenBuilderTy &builder, mlir::Type ElemTy) const

Return address with different element type, a bitcast pointer, and the same alignment.

clang::CharUnits getAlignment() const

mlir::Operation * getDefiningOp() const

Get the operation which defines this address.

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

cir::StackRestoreOp createStackRestore(mlir::Location loc, mlir::Value v)

cir::StoreOp createStore(mlir::Location loc, mlir::Value val, Address dst, bool isVolatile=false, mlir::IntegerAttr align={}, cir::SyncScopeKindAttr scope={}, cir::MemOrderAttr order={})

cir::LoadOp createLoad(mlir::Location loc, Address addr, bool isVolatile=false)

void emitOpenACCRoutine(const OpenACCRoutineDecl &d)

cir::GlobalOp addInitializerToStaticVarDecl(const VarDecl &d, cir::GlobalOp gv, cir::GetGlobalOp gvAddr)

Add the initializer for 'd' to the global variable that has already been created for it.

Definition CIRGenDecl.cpp:507

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

Return the cir::TypeEvaluationKind of QualType type.

AutoVarEmission emitAutoVarAlloca(const clang::VarDecl &d, mlir::OpBuilder::InsertPoint ip={})

Definition CIRGenDecl.cpp:27

void emitAutoVarTypeCleanup(const AutoVarEmission &emission, clang::QualType::DestructionKind dtorKind)

Enter a destroy cleanup for the given local variable.

Definition CIRGenDecl.cpp:1012

void emitVariablyModifiedType(QualType ty)

const clang::LangOptions & getLangOpts() const

cir::AllocaOp createTempAlloca(mlir::Type ty, mlir::Location loc, const Twine &name="tmp", mlir::Value arraySize=nullptr, bool insertIntoFnEntryBlock=false)

This creates an alloca and inserts it into the entry block if ArraySize is nullptr,...

VlaSizePair getVLASize(const VariableArrayType *type)

Returns an MLIR::Value+QualType pair that corresponds to the size, in non-variably-sized elements,...

void emitStaticVarDecl(const VarDecl &d, cir::GlobalLinkageKind linkage)

Definition CIRGenDecl.cpp:560

mlir::Value emitComplexExpr(const Expr *e)

Emit the computation of the specified expression of complex type, returning the result.

bool isTrivialInitializer(const Expr *init)

Determine whether the given initializer is trivial in the sense that it requires no code to be genera...

Definition CIRGenDecl.cpp:170

void emitOpenACCDeclare(const OpenACCDeclareDecl &d)

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

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

void emitExprAsInit(const clang::Expr *init, const clang::ValueDecl *d, LValue lvalue, bool capturedByInit=false)

Emit an expression as an initializer for an object (variable, field, etc.) at the given location.

Definition CIRGenDecl.cpp:637

mlir::Value emitArrayLength(const clang::ArrayType *arrayType, QualType &baseType, Address &addr)

Computes the length of an array in elements, as well as the base element type and a properly-typed fi...

RValue emitReferenceBindingToExpr(const Expr *e)

Emits a reference binding to the passed in expression.

CleanupKind getCleanupKind(QualType::DestructionKind kind)

EHScopeStack ehStack

Tracks function scope overall cleanup handling.

clang::SanitizerSet sanOpts

Sanitizers enabled for this function.

mlir::Type convertTypeForMem(QualType t)

void pushDestroy(QualType::DestructionKind dtorKind, Address addr, QualType type)

Push the standard destructor for the given type as at least a normal cleanup.

Definition CIRGenDecl.cpp:891

void emitVarDecl(const clang::VarDecl &d)

This method handles emission of any variable declaration inside a function, including static vars etc...

Definition CIRGenDecl.cpp:359

static Destroyer destroyCXXObject

Address returnValue

The temporary alloca to hold the return value.

void emitArrayDestroy(mlir::Value begin, mlir::Value numElements, QualType elementType, CharUnits elementAlign, Destroyer *destroyer)

Destroys all the elements of the given array, beginning from last to first.

Definition CIRGenDecl.cpp:911

void emitStoreOfComplex(mlir::Location loc, mlir::Value v, LValue dest, bool isInit)

EmitStoreOfComplex - Store a complex number into the specified l-value.

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

Definition CIRGenDecl.cpp:623

void emitAutoVarInit(const AutoVarEmission &emission)

Emit the initializer for an allocated variable.

Definition CIRGenDecl.cpp:224

void maybeEmitDeferredVarDeclInit(const VarDecl *vd)

Definition CIRGenDecl.cpp:1060

mlir::Value emitScalarExpr(const clang::Expr *e, bool ignoreResultAssign=false)

Emit the computation of the specified expression of scalar type.

void pushStackRestore(CleanupKind kind, Address spMem)

Definition CIRGenDecl.cpp:1007

void emitAutoVarDecl(const clang::VarDecl &d)

Emit code and set up symbol table for a variable declaration with auto, register, or no storage class...

Definition CIRGenDecl.cpp:353

CIRGenBuilderTy & getBuilder()

bool didCallStackSave

Whether a cir.stacksave operation has been added.

void emitDecl(const clang::Decl &d, bool evaluateConditionDecl=false)

Definition CIRGenDecl.cpp:680

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

Immediately perform the destruction of the given object.

Definition CIRGenDecl.cpp:959

llvm::DenseMap< const VarDecl *, mlir::Value > nrvoFlags

A mapping from NRVO variables to the flags used to indicate when the NRVO has been applied to this va...

mlir::MLIRContext & getMLIRContext()

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

Definition CIRGenDecl.cpp:992

void Destroyer(CIRGenFunction &cgf, Address addr, QualType ty)

DeclMapTy localDeclMap

This keeps track of the CIR allocas or globals for local C declarations.

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

void emitCXXDestructorCall(const CXXDestructorDecl *dd, CXXDtorType type, bool forVirtualBase, bool delegating, Address thisAddr, QualType thisTy)

void pushFullExprCleanup(CleanupKind kind, As... a)

Push a cleanup to be run at the end of the current full-expression.

std::optional< mlir::Location > currSrcLoc

Use to track source locations across nested visitor traversals.

clang::ASTContext & getContext() const

void setAddrOfLocalVar(const clang::VarDecl *vd, Address addr)

Set the address of a local variable.

void emitNullabilityCheck(LValue lhs, mlir::Value rhs, clang::SourceLocation loc)

Given an assignment *lhs = rhs, emit a test that checks if rhs is nonnull, if 1LHS is marked _Nonnull...

Definition CIRGenDecl.cpp:804

void emitStoreThroughLValue(RValue src, LValue dst, bool isInit=false)

Store the specified rvalue into the specified lvalue, where both are guaranteed to the have the same ...

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

void emitAutoVarCleanups(const AutoVarEmission &emission)

Definition CIRGenDecl.cpp:335

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

llvm::StringRef getMangledName(clang::GlobalDecl gd)

cir::GlobalOp getOrCreateStaticVarDecl(const VarDecl &d, cir::GlobalLinkageKind linkage)

Definition CIRGenDecl.cpp:419

DiagnosticBuilder errorNYI(SourceLocation, llvm::StringRef)

Helpers to emit "not yet implemented" error diagnostics.

clang::ASTContext & getASTContext() const

mlir::Type convertType(clang::QualType type)

void setGVProperties(mlir::Operation *op, const NamedDecl *d) const

Set visibility, dllimport/dllexport and dso_local.

static mlir::SymbolTable::Visibility getMLIRVisibilityFromCIRLinkage(cir::GlobalLinkageKind GLK)

const clang::LangOptions & getLangOpts() const

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

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

mlir::ModuleOp getModule() const

bool supportsCOMDAT() const

mlir::MLIRContext & getMLIRContext()

cir::GlobalOp getStaticLocalDeclAddress(const VarDecl *d)

mlir::Type convertTypeForMem(clang::QualType, bool forBitField=false)

Convert type T into an mlir::Type.

void finalize(cir::GlobalOp gv)

mlir::Attribute tryEmitForInitializer(const VarDecl &d)

Try to emit the initializer of the given declaration as an abstract constant.

mlir::Attribute tryEmitAbstractForInitializer(const VarDecl &d)

Try to emit the initializer of the given declaration as an abstract constant.

Information for lazily generating a cleanup.

Address getAddress() const

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

static RValue get(mlir::Value v)

Represents a call to a C++ constructor.

Represents a C++ constructor within a class.

Represents a C++ destructor within a class.

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

llvm::Align getAsAlign() const

getAsAlign - Returns Quantity as a valid llvm::Align, Beware llvm::Align assumes power of two 8-bit b...

static CharUnits One()

One - Construct a CharUnits quantity of one.

CharUnits alignmentOfArrayElement(CharUnits elementSize) const

Given that this is the alignment of the first element of an array, return the minimum alignment of an...

static CharUnits fromQuantity(QuantityType Quantity)

fromQuantity - Construct a CharUnits quantity from a raw integer type.

DeclContext - This is used only as base class of specific decl types that can act as declaration cont...

Decl * getNonClosureContext()

Find the innermost non-closure ancestor of this declaration, walking up through blocks,...

SourceLocation getLocation() const

const char * getDeclKindName() const

DeclContext * getDeclContext()

virtual SourceRange getSourceRange() const LLVM_READONLY

Source range that this declaration covers.

This represents one expression.

bool isConstantInitializer(ASTContext &Ctx, bool ForRef, const Expr **Culprit=nullptr) const

isConstantInitializer - Returns true if this expression can be emitted to IR as a constant,...

SourceLocation getExprLoc() const LLVM_READONLY

getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...

GlobalDecl - represents a global declaration.

const Decl * getDecl() const

StringRef getName() const

Get the name of identifier for this declaration as a StringRef.

std::string getNameAsString() const

Get a human-readable name for the declaration, even if it is one of the special kinds of names (C++ c...

bool isExternallyVisible() const

A (possibly-)qualified type.

@ DK_objc_strong_lifetime

@ PDIK_Struct

The type is a struct containing a field whose type is not PCK_Trivial.

LangAS getAddressSpace() const

Return the address space of this type.

bool isConstantStorage(const ASTContext &Ctx, bool ExcludeCtor, bool ExcludeDtor)

bool isPODType(const ASTContext &Context) const

Determine whether this is a Plain Old Data (POD) type (C++ 3.9p10).

Represents a struct/union/class.

Encodes a location in the source.

SourceRange getSourceRange() const LLVM_READONLY

SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...

RecordDecl * getAsRecordDecl() const

Retrieves the RecordDecl this type refers to.

bool isConstantSizeType() const

Return true if this is not a variable sized type, according to the rules of C99 6....

bool isVariablyModifiedType() const

Whether this type is a variably-modified type (C99 6.7.5).

bool isVectorType() const

bool isRecordType() const

Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...

Represents a variable declaration or definition.

bool isConstexpr() const

Whether this variable is (C++11) constexpr.

TLSKind getTLSKind() const

SourceRange getSourceRange() const override LLVM_READONLY

Source range that this declaration covers.

bool mightBeUsableInConstantExpressions(const ASTContext &C) const

Determine whether this variable's value might be usable in a constant expression, according to the re...

bool isNRVOVariable() const

Determine whether this local variable can be used with the named return value optimization (NRVO).

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

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

const Expr * getInit() const

bool hasExternalStorage() const

Returns true if a variable has extern or private_extern storage.

bool hasLocalStorage() const

Returns true if a variable with function scope is a non-static local variable.

bool isLocalVarDecl() const

Returns true for local variable declarations other than parameters.

StorageDuration getStorageDuration() const

Get the storage duration of this variable, per C++ [basic.stc].

bool isEscapingByref() const

Indicates the capture is a __block variable that is captured by a block that can potentially escape (...

@ Decl

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

@ NormalCleanup

Denotes a cleanup that should run when a scope is exited using normal control flow (falling off the e...

const internal::VariadicAllOfMatcher< Type > type

Matches Types in the clang AST.

const AstTypeMatcher< ArrayType > arrayType

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

bool isa(CodeGen::Address addr)

@ SD_Automatic

Automatic storage duration (most local variables).

@ Dtor_Complete

Complete object dtor.

U cast(CodeGen::Address addr)

float __ovld __cnfn length(float)

Return the length of vector p, i.e., sqrt(p.x2 + p.y 2 + ...)

static bool objCLifetime()

static bool addAutoInitAnnotation()

static bool addressSpace()

static bool emitNullabilityCheck()

static bool useEHCleanupForArray()

static bool vectorConstants()

static bool aggValueSlotMayOverlap()

static bool shouldSplitConstantStore()

static bool shouldUseMemSetToInitialize()

static bool dtorCleanups()

static bool shouldUseBZeroPlusStoresToInitialize()

static bool shouldCreateMemCpyFromGlobal()

static bool dataLayoutTypeAllocSize()

static bool opAllocaCaptureByInit()

static bool opAllocaPreciseLifetime()

static bool cudaSupport()

static bool generateDebugInfo()

bool wasEmittedAsGlobal() const

bool isEscapingByRef

True if the variable is a __block variable that is captured by an escaping block.

Address addr

The address of the alloca for languages with explicit address space (e.g.

const clang::VarDecl * variable

bool isConstantAggregate

True if the variable is of aggregate type and has a constant initializer.

bool wasEmittedAsOffloadClause() const

Address getObjectAddress(CIRGenFunction &cgf) const

Returns the address of the object within this declaration.

cir::PointerType allocaInt8PtrTy

void* in alloca address space