18#include "mlir/IR/Location.h"
23#include "llvm/IR/FPEnv.h"
30 bool suppressNewContext)
41 switch (
type->getTypeClass()) {
42#define TYPE(name, parent)
43#define ABSTRACT_TYPE(name, parent)
44#define NON_CANONICAL_TYPE(name, parent) case Type::name:
45#define DEPENDENT_TYPE(name, parent) case Type::name:
46#define NON_CANONICAL_UNLESS_DEPENDENT_TYPE(name, parent) case Type::name:
47#include "clang/AST/TypeNodes.inc"
48 llvm_unreachable(
"non-canonical or dependent type in IR-generation");
51 case Type::DeducedTemplateSpecialization:
52 llvm_unreachable(
"undeduced type in IR-generation");
57 case Type::BlockPointer:
58 case Type::LValueReference:
59 case Type::RValueReference:
60 case Type::MemberPointer:
63 case Type::ConstantMatrix:
64 case Type::FunctionProto:
65 case Type::FunctionNoProto:
67 case Type::ObjCObjectPointer:
70 case Type::OverflowBehavior:
71 case Type::HLSLAttributedResource:
72 case Type::HLSLInlineSpirv:
80 case Type::ConstantArray:
81 case Type::IncompleteArray:
82 case Type::VariableArray:
84 case Type::ObjCObject:
85 case Type::ObjCInterface:
86 case Type::ArrayParameter:
94 llvm_unreachable(
"unknown type kind!");
99 return cgm.getTypes().convertTypeForMem(t);
103 return cgm.getTypes().convertType(t);
113 return mlir::FileLineColLoc::get(builder.getStringAttr(filename),
119 assert(
currSrcLoc &&
"expected to inherit some source location");
123 return builder.getUnknownLoc();
133 mlir::Attribute metadata;
139 assert(
currSrcLoc &&
"expected to inherit some source location");
143 return builder.getUnknownLoc();
148 mlir::Attribute metadata;
175 ignoreCaseStmts =
true;
178 return std::any_of(
s->child_begin(),
s->child_end(),
179 [=](
const Stmt *subStmt) {
180 return containsLabel(subStmt, ignoreCaseStmts);
189 llvm::APSInt resultInt;
193 resultBool = resultInt.getBoolValue();
201 llvm::APSInt &resultInt,
209 llvm::APSInt intValue = result.
Val.
getInt();
213 resultInt = intValue;
217void CIRGenFunction::emitAndUpdateRetAlloca(
QualType type, mlir::Location loc,
219 if (!
type->isVoidType()) {
227void CIRGenFunction::declare(mlir::Value addrVal,
const Decl *var, QualType ty,
228 mlir::Location loc, CharUnits alignment,
231 assert(!
symbolTable.count(var) &&
"not supposed to be available just yet");
233 auto allocaOp = addrVal.getDefiningOp<cir::AllocaOp>();
234 assert(allocaOp &&
"expected cir::AllocaOp");
238 if (ty->isReferenceType() || ty.isConstQualified())
248 auto applyCleanup = [&]() {
263 for (mlir::Block *retBlock : localScope->
getRetBlocks()) {
264 mlir::OpBuilder::InsertionGuard guard(builder);
265 builder.setInsertionPointToEnd(retBlock);
266 retBlocks.push_back(retBlock);
267 mlir::Location retLoc = localScope->
getRetLoc(retBlock);
271 auto insertCleanupAndLeave = [&](mlir::Block *insPt) {
272 mlir::OpBuilder::InsertionGuard guard(builder);
273 builder.setInsertionPointToEnd(insPt);
282 mlir::Block *currentBlock = builder.getBlock();
287 cir::BrOp::create(builder, insPt->back().getLoc(), cleanupBlock);
288 if (!cleanupBlock->mightHaveTerminator()) {
289 mlir::OpBuilder::InsertionGuard guard(builder);
290 builder.setInsertionPointToEnd(cleanupBlock);
291 cir::YieldOp::create(builder, localScope->endLoc);
295 if (localScope->
depth == 0) {
300 mlir::Location retLoc = localScope->
getRetLoc(retBlock);
301 if (retBlock->getUses().empty()) {
306 for (mlir::BlockOperand &blockUse : retBlock->getUses()) {
307 cir::BrOp brOp = mlir::cast<cir::BrOp>(blockUse.getOwner());
308 brOp.setSuccessor(cleanupBlock);
312 cir::BrOp::create(builder, retLoc, retBlock);
316 emitImplicitReturn();
323 if (!localScope->
isTernary() && !currentBlock->mightHaveTerminator()) {
324 !retVal ? cir::YieldOp::create(builder, localScope->endLoc)
325 : cir::YieldOp::create(builder, localScope->endLoc, retVal);
335 insertCleanupAndLeave(cleanupBlock);
340 mlir::Block *curBlock = builder.getBlock();
343 if (curBlock->mightHaveTerminator() && curBlock->getTerminator())
347 bool entryBlock = builder.getInsertionBlock()->isEntryBlock();
348 if (!entryBlock && curBlock->empty()) {
350 for (mlir::Block *retBlock : retBlocks) {
351 if (retBlock->getUses().empty())
359 cir::BrOp::create(builder, curBlock->back().getLoc(), cleanupBlock);
364 insertCleanupAndLeave(curBlock);
367cir::ReturnOp CIRGenFunction::LexicalScope::emitReturn(mlir::Location loc) {
370 auto fn = dyn_cast<cir::FuncOp>(cgf.curFn);
371 assert(fn &&
"emitReturn from non-function");
374 if (fn.getCoroutine())
375 cgf.emitCoroEndBuiltinCall(loc,
376 builder.getNullPtr(builder.getVoidPtrTy(), loc));
377 if (!fn.getFunctionType().hasVoidReturn()) {
379 auto value = cir::LoadOp::create(
380 builder, loc, fn.getFunctionType().getReturnType(), *cgf.fnRetAlloca);
381 return cir::ReturnOp::create(builder, loc,
384 return cir::ReturnOp::create(builder, loc);
394 return classDecl->hasTrivialDestructor();
401 mlir::Operation *op = &block->back();
402 auto cleanupScopeOp = mlir::dyn_cast<cir::CleanupScopeOp>(op);
410 for (mlir::Block &bodyBlock : cleanupScopeOp.getBodyRegion()) {
411 if (bodyBlock.mightHaveTerminator()) {
412 if (mlir::isa<cir::YieldOp>(bodyBlock.getTerminator()))
414 assert(!mlir::isa<cir::BreakOp>(bodyBlock.getTerminator()) &&
415 !mlir::isa<cir::ContinueOp>(bodyBlock.getTerminator()) &&
416 !mlir::isa<cir::ResumeOp>(bodyBlock.getTerminator()));
422void CIRGenFunction::LexicalScope::emitImplicitReturn() {
423 CIRGenBuilderTy &builder = cgf.getBuilder();
424 LexicalScope *localScope = cgf.curLexScope;
433 if (cgf.getLangOpts().CPlusPlus && !fd->hasImplicitReturnZero() &&
434 !cgf.sawAsmBlock && !fd->getReturnType()->isVoidType() &&
435 builder.getInsertionBlock() &&
437 bool shouldEmitUnreachable =
438 cgf.cgm.getCodeGenOpts().StrictReturn ||
441 if (shouldEmitUnreachable) {
443 if (cgf.cgm.getCodeGenOpts().OptimizationLevel == 0)
444 cir::TrapOp::create(builder, localScope->endLoc);
446 cir::UnreachableOp::create(builder, localScope->endLoc);
447 builder.clearInsertionPoint();
452 (void)emitReturn(localScope->endLoc);
460 scope = scope->parentScope;
473 if (value.getType() == ty)
476 assert((mlir::isa<cir::IntType>(ty) || cir::isAnyFloatingPointType(ty)) &&
477 "unexpected promotion type");
479 if (mlir::isa<cir::IntType>(ty))
480 return cgf.
getBuilder().CIRBaseBuilderTy::createIntCast(value, ty);
486 mlir::Block *entryBB,
490 if (fd && fd->
hasAttr<NakedAttr>()) {
491 cgm.errorNYI(bodyBeginLoc,
"naked function decl");
495 for (
const auto nameValue : llvm::zip(args, entryBB->getArguments())) {
496 const VarDecl *paramVar = std::get<0>(nameValue);
497 mlir::Value paramVal = std::get<1>(nameValue);
500 paramVal.setLoc(paramLoc);
502 mlir::Value addrVal =
507 declare(addrVal, paramVar, paramVar->
getType(), paramLoc, alignment,
520 mlir::Location fnBodyBegin =
getLoc(bodyBeginLoc);
521 builder.CIRBaseBuilderTy::createStore(fnBodyBegin, paramVal, addrVal);
523 assert(builder.getInsertionBlock() &&
"Should be valid");
527 cir::FuncOp fn, cir::FuncType funcType,
531 "CIRGenFunction can only be used for one function at a time");
539 const auto *fd = dyn_cast_or_null<FunctionDecl>(d);
544 mlir::Block *entryBB = &fn.getBlocks().front();
545 builder.setInsertionPointToStart(entryBB);
551 if (
Stmt *body = fd->getBody())
552 bodyBeginLoc = body->getBeginLoc();
554 bodyBeginLoc = fd->getLocation();
566 if (
Stmt *body = fd->getBody())
567 bodyEndLoc = body->getEndLoc();
569 bodyEndLoc = fd->getLocation();
571 emitAndUpdateRetAlloca(returnType,
getLoc(bodyEndLoc),
572 getContext().getTypeAlignInChars(returnType));
575 if (isa_and_nonnull<CXXMethodDecl>(d) &&
577 cgm.getCXXABI().emitInstanceFunctionProlog(loc, *
this);
580 if (md->getParent()->isLambda() && md->getOverloadedOperator() == OO_Call) {
582 auto fn = dyn_cast<cir::FuncOp>(
curFn);
583 assert(fn &&
"lambda in non-function region");
609 for (
auto *fd : md->getParent()->fields()) {
610 if (fd->hasCapturedVLAType())
611 cgm.errorNYI(loc,
"lambda captured VLA type");
626 for (cir::BlockAddressOp &blockAddress :
cgm.unresolvedBlockAddressToLabel) {
627 cir::LabelOp labelOp =
628 cgm.lookupBlockAddressInfo(blockAddress.getBlockAddrInfo());
629 assert(labelOp &&
"expected cir.labelOp to already be emitted");
630 cgm.updateResolvedBlockAddress(blockAddress, labelOp);
632 cgm.unresolvedBlockAddressToLabel.clear();
640 mlir::OpBuilder::InsertionGuard guard(builder);
642 for (
auto &[blockAdd, labelOp] :
cgm.blockAddressToLabel) {
643 succesors.push_back(labelOp->getBlock());
644 rangeOperands.push_back(labelOp->getBlock()->getArguments());
646 cir::IndirectBrOp::create(builder, builder.getUnknownLoc(),
648 rangeOperands, succesors);
649 cgm.blockAddressToLabel.clear();
664 indrBr.setPoison(
true);
684 if (
const CompoundStmt *block = dyn_cast<CompoundStmt>(body))
695 for (mlir::Block &block : func.getBlocks()) {
696 if (block.empty() && block.getUses().empty())
697 blocksToDelete.push_back(&block);
699 for (mlir::Block *block : blocksToDelete)
704 cir::FuncType funcType) {
708 if (funcDecl->isInlineBuiltinDeclaration()) {
712 std::string fdInlineName = (
cgm.getMangledName(funcDecl) +
".inline").str();
714 mlir::cast_or_null<cir::FuncOp>(
cgm.getGlobalValue(fdInlineName));
716 mlir::OpBuilder::InsertionGuard guard(builder);
717 builder.setInsertionPoint(fn);
718 clone = cir::FuncOp::create(builder, fn.getLoc(), fdInlineName,
719 fn.getFunctionType());
720 clone.setLinkage(cir::GlobalLinkageKind::InternalLinkage);
721 clone.setSymVisibility(
"private");
722 clone.setInlineKind(cir::InlineKind::AlwaysInline);
724 fn.setLinkage(cir::GlobalLinkageKind::ExternalLinkage);
725 fn.setSymVisibility(
"private");
733 if (LLVM_UNLIKELY(pd->isInlineBuiltinDeclaration())) {
734 std::string inlineName = funcDecl->getName().str() +
".inline";
735 if (
auto inlineFn = mlir::cast_or_null<cir::FuncOp>(
736 cgm.getGlobalValue(inlineName))) {
741 .replaceAllSymbolUses(fn.getSymNameAttr(),
cgm.getModule())
743 llvm_unreachable(
"Failed to replace inline builtin symbol uses");
752 Stmt *body = funcDecl->getBody();
757 : builder.getUnknownLoc()};
760 return clangLoc.isValid() ?
getLoc(clangLoc) : builder.getUnknownLoc();
762 const mlir::Location fusedLoc = mlir::FusedLoc::get(
764 {validMLIRLoc(bodyRange.
getBegin()), validMLIRLoc(bodyRange.
getEnd())});
765 mlir::Block *entryBB = fn.addEntryBlock();
779 if (body && isa_and_nonnull<CoroutineBodyStmt>(body))
780 llvm::append_range(
fnArgs, funcDecl->parameters());
787 funcDecl->hasAttr<CUDAGlobalAttr>()) {
788 cgm.getCUDARuntime().emitDeviceStub(*
this, fn, args);
808 llvm_unreachable(
"no definition for normal function");
811 if (mlir::failed(fn.verifyBody()))
826 assert((
cgm.getTarget().getCXXABI().hasConstructorVariants() ||
828 "can only generate complete ctor for this ABI");
833 cgm.getTarget().getCXXABI().hasConstructorVariants()) {
839 Stmt *body = ctor->getBody(definition);
840 assert(definition == ctor &&
"emitting wrong constructor body");
842 if (isa_and_nonnull<CXXTryStmt>(body)) {
843 cgm.errorNYI(ctor->getSourceRange(),
"emitConstructorBody: try body");
858 if (mlir::failed(
emitStmt(body,
true))) {
859 cgm.errorNYI(ctor->getSourceRange(),
860 "emitConstructorBody: emit body statement failed.");
906 const bool isTryBody = isa_and_nonnull<CXXTryStmt>(body);
922 llvm_unreachable(
"not expecting a unified dtor");
924 llvm_unreachable(
"not expecting a COMDAT");
927 llvm_unreachable(
"already handled deleting case");
930 assert((body ||
getTarget().getCXXABI().isMicrosoft()) &&
931 "can't emit a dtor without a body for non-Microsoft ABIs");
959 assert(dtor->
isImplicit() &&
"bodyless dtor not implicit");
985 CharUnits align =
cgm.getNaturalTypeAlignment(ty, &baseInfo);
992 CharUnits alignment =
cgm.getNaturalTypeAlignment(ty, &baseInfo);
1000static llvm::fp::ExceptionBehavior
1004 return llvm::fp::ebIgnore;
1006 return llvm::fp::ebMayTrap;
1008 return llvm::fp::ebStrict;
1010 llvm_unreachable(
"expected explicitly initialized exception behavior");
1012 llvm_unreachable(
"unsupported FP exception behavior");
1018 QualType retTy = fd->getReturnType();
1020 const auto *md = dyn_cast<CXXMethodDecl>(fd);
1021 if (md && md->isInstance()) {
1022 if (
cgm.getCXXABI().hasThisReturn(gd))
1023 cgm.errorNYI(fd->getSourceRange(),
"this return");
1024 else if (
cgm.getCXXABI().hasMostDerivedReturn(gd))
1025 cgm.errorNYI(fd->getSourceRange(),
"most derived return");
1026 cgm.getCXXABI().buildThisParam(*
this, args);
1029 if (
const auto *cd = dyn_cast<CXXConstructorDecl>(fd))
1030 if (cd->getInheritedConstructor())
1031 cgm.errorNYI(fd->getSourceRange(),
1032 "buildFunctionArgList: inherited constructor");
1034 for (
auto *param : fd->parameters())
1035 args.push_back(param);
1038 cgm.getCXXABI().addImplicitStructorParams(*
this, retTy, args);
1051 std::string(
"l-value not implemented for '") +
1054 case Expr::ConditionalOperatorClass:
1056 case Expr::BinaryConditionalOperatorClass:
1058 case Expr::ArraySubscriptExprClass:
1060 case Expr::ExtVectorElementExprClass:
1062 case Expr::UnaryOperatorClass:
1064 case Expr::StringLiteralClass:
1066 case Expr::MemberExprClass:
1068 case Expr::CompoundLiteralExprClass:
1070 case Expr::PredefinedExprClass:
1072 case Expr::BinaryOperatorClass:
1074 case Expr::CompoundAssignOperatorClass: {
1078 "CompoundAssignOperator with AtomicType");
1086 case Expr::CallExprClass:
1087 case Expr::CXXMemberCallExprClass:
1088 case Expr::CXXOperatorCallExprClass:
1089 case Expr::UserDefinedLiteralClass:
1091 case Expr::ExprWithCleanupsClass: {
1098 case Expr::CXXDefaultArgExprClass: {
1103 case Expr::CXXTypeidExprClass:
1105 case Expr::ParenExprClass:
1107 case Expr::GenericSelectionExprClass:
1109 case Expr::DeclRefExprClass:
1111 case Expr::ImplicitCastExprClass:
1112 case Expr::CStyleCastExprClass:
1113 case Expr::CXXStaticCastExprClass:
1114 case Expr::CXXDynamicCastExprClass:
1115 case Expr::CXXReinterpretCastExprClass:
1116 case Expr::CXXConstCastExprClass:
1120 case Expr::MaterializeTemporaryExprClass:
1122 case Expr::OpaqueValueExprClass:
1124 case Expr::ChooseExprClass:
1126 case Expr::SubstNonTypeTemplateParmExprClass:
1133 llvm::raw_svector_ostream
out(buffer);
1135 return std::string(
out.str());
1155 cgm.errorNYI(loc,
"Cast the dest ptr to the appropriate i8 pointer type");
1164 "emitNullInitialization for zero size VariableArrayType");
1174 if (!
cgm.getTypes().isZeroInitializable(ty)) {
1175 cgm.errorNYI(loc,
"type is not zero initializable");
1182 const mlir::Value zeroValue = builder.getNullValue(
convertType(ty), loc);
1183 builder.createStore(loc, zeroValue, destPtr);
1195 ConstructorHelper(fpFeatures);
1198void CIRGenFunction::CIRGenFPOptionsRAII::ConstructorHelper(
1200 oldFPFeatures = cgf.curFPFeatures;
1201 cgf.curFPFeatures = fpFeatures;
1203 oldExcept = cgf.builder.getDefaultConstrainedExcept();
1204 oldRounding = cgf.builder.getDefaultConstrainedRounding();
1206 if (oldFPFeatures == fpFeatures)
1212 [[maybe_unused]] llvm::RoundingMode newRoundingBehavior =
1215 [[maybe_unused]] llvm::fp::ExceptionBehavior newExceptionBehavior =
1223 assert((cgf.curFuncDecl ==
nullptr || cgf.builder.getIsFPConstrained() ||
1226 (newExceptionBehavior == llvm::fp::ebIgnore &&
1227 newRoundingBehavior == llvm::RoundingMode::NearestTiesToEven)) &&
1228 "FPConstrained should be enabled on entire function");
1235 cgf.curFPFeatures = oldFPFeatures;
1236 cgf.builder.setDefaultConstrainedExcept(oldExcept);
1237 cgf.builder.setDefaultConstrainedRounding(oldRounding);
1244 if (ce->
getCastKind() == CK_UncheckedDerivedToBase)
1254 if (ice->isGLValue())
1276 uint64_t countFromCLAs = 1;
1279 auto cirArrayType = mlir::dyn_cast<cir::ArrayType>(addr.
getElementType());
1281 while (cirArrayType) {
1283 countFromCLAs *= cirArrayType.getSize();
1287 mlir::dyn_cast<cir::ArrayType>(cirArrayType.getElementType());
1291 "CIR and Clang types are out-of-sync");
1298 cgm.errorNYI(*
currSrcLoc,
"length for non-array underlying types");
1310 mlir::OpBuilder::InsertionGuard guard(builder);
1312 builder.createBlock(builder.getBlock()->getParent(), {}, {voidPtrTy},
1313 {builder.getUnknownLoc()});
1318 SourceLocation assumptionLoc, int64_t alignment, mlir::Value offsetValue) {
1320 return cir::AssumeAlignedOp::create(builder,
getLoc(assumptionLoc), ptrValue,
1321 alignment, offsetValue);
1326 int64_t alignment, mlir::Value offsetValue) {
1335 cgm.getASTContext().getAsVariableArrayType(
type);
1336 assert(vla &&
"type was not a variable array type!");
1343 mlir::Value numElements;
1347 elementType =
type->getElementType();
1349 assert(vlaSize &&
"no size for VLA!");
1350 assert(vlaSize.getType() ==
sizeTy);
1353 numElements = vlaSize;
1359 builder.createMul(numElements.getLoc(), numElements, vlaSize,
1362 }
while ((
type =
getContext().getAsVariableArrayType(elementType)));
1364 assert(numElements &&
"Undefined elements number");
1365 return {numElements, elementType};
1371 assert(vlaSize &&
"no size for VLA!");
1372 assert(vlaSize.getType() ==
sizeTy);
1379 assert(
type->isVariablyModifiedType() &&
1380 "Must pass variably modified type to EmitVLASizes!");
1385 assert(
type->isVariablyModifiedType());
1387 const Type *ty =
type.getTypePtr();
1389 case Type::CountAttributed:
1390 case Type::PackIndexing:
1391 case Type::ArrayParameter:
1392 case Type::HLSLAttributedResource:
1393 case Type::HLSLInlineSpirv:
1394 case Type::PredefinedSugar:
1395 cgm.errorNYI(
"CIRGenFunction::emitVariablyModifiedType");
1398#define TYPE(Class, Base)
1399#define ABSTRACT_TYPE(Class, Base)
1400#define NON_CANONICAL_TYPE(Class, Base)
1401#define DEPENDENT_TYPE(Class, Base) case Type::Class:
1402#define NON_CANONICAL_UNLESS_DEPENDENT_TYPE(Class, Base)
1403#include "clang/AST/TypeNodes.inc"
1405 "dependent type must be resolved before the CIR codegen");
1411 case Type::ExtVector:
1412 case Type::ConstantMatrix:
1416 case Type::TemplateSpecialization:
1417 case Type::ObjCTypeParam:
1418 case Type::ObjCObject:
1419 case Type::ObjCInterface:
1420 case Type::ObjCObjectPointer:
1422 case Type::OverflowBehavior:
1423 llvm_unreachable(
"type class is never variably-modified!");
1425 case Type::Adjusted:
1437 case Type::BlockPointer:
1441 case Type::LValueReference:
1442 case Type::RValueReference:
1446 case Type::MemberPointer:
1450 case Type::ConstantArray:
1451 case Type::IncompleteArray:
1456 case Type::VariableArray: {
1473 entry = builder.createIntCast(size,
sizeTy);
1480 case Type::FunctionProto:
1481 case Type::FunctionNoProto:
1487 case Type::UnaryTransform:
1488 case Type::Attributed:
1489 case Type::BTFTagAttributed:
1490 case Type::SubstTemplateTypeParm:
1491 case Type::MacroQualified:
1497 case Type::Decltype:
1499 case Type::DeducedTemplateSpecialization:
1503 case Type::TypeOfExpr:
1516 }
while (
type->isVariablyModifiedType());
1520 if (
getContext().getBuiltinVaListType()->isArrayType())
Defines the clang::Expr interface and subclasses for C++ expressions.
*collection of selector each with an associated kind and an ordered *collection of selectors A selector has a kind
__device__ __2f16 float __ockl_bool s
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
SourceManager & getSourceManager()
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.
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
Represents an array type, per C99 6.7.5.2 - Array Declarators.
QualType getElementType() const
mlir::Type getElementType() const
mlir::Value createFloatingCast(mlir::Value v, mlir::Type destType)
CIRGenFPOptionsRAII(CIRGenFunction &cgf, FPOptions FPFeatures)
Enters a new scope for capturing cleanups, all of which will be executed once the scope is exited.
void forceCleanup(ArrayRef< mlir::Value * > valuesToReload={})
Force the emission of cleanups now, instead of waiting until this object is destroyed.
static bool isConstructorDelegationValid(const clang::CXXConstructorDecl *ctor)
Checks whether the given constructor is a valid subject for the complete-to-base constructor delegati...
void emitFunctionProlog(const FunctionArgList &args, mlir::Block *entryBB, const FunctionDecl *fd, SourceLocation bodyBeginLoc)
Emit the function prologue: declare function arguments in the symbol table.
mlir::Type convertType(clang::QualType t)
LValue emitOpaqueValueLValue(const OpaqueValueExpr *e)
static cir::TypeEvaluationKind getEvaluationKind(clang::QualType type)
Return the cir::TypeEvaluationKind of QualType type.
clang::GlobalDecl curGD
The GlobalDecl for the current function being compiled or the global variable currently being initial...
EHScopeStack::stable_iterator prologueCleanupDepth
The cleanup depth enclosing all the cleanups associated with the parameters.
cir::FuncOp generateCode(clang::GlobalDecl gd, cir::FuncOp fn, cir::FuncType funcType)
Address emitPointerWithAlignment(const clang::Expr *expr, LValueBaseInfo *baseInfo=nullptr)
Given an expression with a pointer type, emit the value and compute our best estimate of the alignmen...
void emitVariablyModifiedType(QualType ty)
RValue emitLoadOfLValue(LValue lv, SourceLocation loc)
Given an expression that represents a value lvalue, this method emits the address of the lvalue,...
const clang::LangOptions & getLangOpts() const
mlir::Value cxxStructorImplicitParamValue
void emitTrap(mlir::Location loc, bool createNewBlock)
Emit a trap instruction, which is used to abort the program in an abnormal way, usually for debugging...
VlaSizePair getVLASize(const VariableArrayType *type)
Returns an MLIR::Value+QualType pair that corresponds to the size, in non-variably-sized elements,...
LValue makeNaturalAlignPointeeAddrLValue(mlir::Value v, clang::QualType t)
Given a value of type T* that may not be to a complete object, construct an l-vlaue withi the natural...
LValue emitMemberExpr(const MemberExpr *e)
const TargetInfo & getTarget() const
LValue emitConditionalOperatorLValue(const AbstractConditionalOperator *expr)
LValue emitLValue(const clang::Expr *e)
Emit code to compute a designator that specifies the location of the expression.
const clang::Decl * curFuncDecl
Address loadCXXThisAddress()
LValue emitLValueForLambdaField(const FieldDecl *field)
std::string getCounterRefTmpAsString()
LValue makeNaturalAlignAddrLValue(mlir::Value val, QualType ty)
llvm::DenseMap< const Expr *, mlir::Value > vlaSizeMap
bool constantFoldsToSimpleInteger(const clang::Expr *cond, llvm::APSInt &resultInt, bool allowLabels=false)
If the specified expression does not fold to a constant, or if it does fold but contains a label,...
LValue emitComplexCompoundAssignmentLValue(const CompoundAssignOperator *e)
mlir::Location getLoc(clang::SourceLocation srcLoc)
Helpers to convert Clang's SourceLocation to a MLIR Location.
bool constantFoldsToBool(const clang::Expr *cond, bool &resultBool, bool allowLabels=false)
If the specified expression does not fold to a constant, or if it does but contains a label,...
void emitDelegateCXXConstructorCall(const clang::CXXConstructorDecl *ctor, clang::CXXCtorType ctorType, const FunctionArgList &args, clang::SourceLocation loc)
VlaSizePair getVLAElements1D(const VariableArrayType *vla)
Return the number of elements for a single dimension for the given array type.
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...
void emitNullInitialization(mlir::Location loc, Address destPtr, QualType ty)
LValue emitArraySubscriptExpr(const clang::ArraySubscriptExpr *e)
llvm::ScopedHashTableScope< const clang::Decl *, mlir::Value > SymTableScopeTy
mlir::Block * indirectGotoBlock
IndirectBranch - The first time an indirect goto is seen we create a block reserved for the indirect ...
mlir::Operation * curFn
The current function or global initializer that is generated code for.
EHScopeStack ehStack
Tracks function scope overall cleanup handling.
void enterDtorCleanups(const CXXDestructorDecl *dtor, CXXDtorType type)
Enter the cleanups necessary to complete the given phase of destruction for a destructor.
llvm::SmallVector< const ParmVarDecl * > fnArgs
Save Parameter Decl for coroutine.
std::optional< mlir::Value > fnRetAlloca
The compiler-generated variable that holds the return value.
void emitImplicitAssignmentOperatorBody(FunctionArgList &args)
mlir::Type convertTypeForMem(QualType t)
clang::QualType buildFunctionArgList(clang::GlobalDecl gd, FunctionArgList &args)
void emitCtorPrologue(const clang::CXXConstructorDecl *ctor, clang::CXXCtorType ctorType, FunctionArgList &args)
This routine generates necessary code to initialize base classes and non-static data members belongin...
mlir::Value emitAlloca(llvm::StringRef name, mlir::Type ty, mlir::Location loc, clang::CharUnits alignment, bool insertIntoFnEntryBlock, mlir::Value arraySize=nullptr)
LValue emitCompoundAssignmentLValue(const clang::CompoundAssignOperator *e)
Address returnValue
The temporary alloca to hold the return value.
void finishFunction(SourceLocation endLoc)
mlir::LogicalResult emitFunctionBody(const clang::Stmt *body)
std::string getCounterAggTmpAsString()
LValue emitUnaryOpLValue(const clang::UnaryOperator *e)
clang::FieldDecl * lambdaThisCaptureField
const clang::Decl * curCodeDecl
This is the inner-most code context, which includes blocks.
void emitConstructorBody(FunctionArgList &args)
LValue emitCallExprLValue(const clang::CallExpr *e)
bool haveInsertPoint() const
True if an insertion point is defined.
void finishIndirectBranch()
LValue emitStringLiteralLValue(const StringLiteral *e, llvm::StringRef name=".str")
void resolveBlockAddresses()
mlir::Value emitScalarExpr(const clang::Expr *e, bool ignoreResultAssign=false)
Emit the computation of the specified expression of scalar type.
void popCleanupBlocks(EHScopeStack::stable_iterator oldCleanupStackDepth, ArrayRef< mlir::Value * > valuesToReload={})
Takes the old cleanup stack size and emits the cleanup blocks that have been added.
bool shouldNullCheckClassCastValue(const CastExpr *ce)
CIRGenBuilderTy & getBuilder()
bool didCallStackSave
Whether a cir.stacksave operation has been added.
LValue emitBinaryOperatorLValue(const BinaryOperator *e)
void startFunction(clang::GlobalDecl gd, clang::QualType returnType, cir::FuncOp fn, cir::FuncType funcType, FunctionArgList args, clang::SourceLocation loc, clang::SourceLocation startLoc)
Emit code for the start of a function.
CIRGenModule & getCIRGenModule()
unsigned counterRefTmp
Hold counters for incrementally naming temporaries.
mlir::MLIRContext & getMLIRContext()
void emitDestructorBody(FunctionArgList &args)
Emits the body of the current destructor.
LValue emitCastLValue(const CastExpr *e)
Casts are never lvalues unless that cast is to a reference type.
LValue emitCXXTypeidLValue(const CXXTypeidExpr *e)
bool containsLabel(const clang::Stmt *s, bool ignoreCaseStmts=false)
Return true if the statement contains a label in it.
LValue emitDeclRefLValue(const clang::DeclRefExpr *e)
llvm::DenseMap< const clang::ValueDecl *, clang::FieldDecl * > lambdaCaptureFields
mlir::Value emitAlignmentAssumption(mlir::Value ptrValue, QualType ty, SourceLocation loc, SourceLocation assumptionLoc, int64_t alignment, mlir::Value offsetValue=nullptr)
LValue makeAddrLValue(Address addr, QualType ty, AlignmentSource source=AlignmentSource::Type)
LValue emitPredefinedLValue(const PredefinedExpr *e)
void emitCXXDestructorCall(const CXXDestructorDecl *dd, CXXDtorType type, bool forVirtualBase, bool delegating, Address thisAddr, QualType thisTy)
void emitLambdaStaticInvokeBody(const CXXMethodDecl *md)
void instantiateIndirectGotoBlock()
CIRGenFunction(CIRGenModule &cgm, CIRGenBuilderTy &builder, bool suppressNewContext=false)
std::optional< mlir::Location > currSrcLoc
Use to track source locations across nested visitor traversals.
LValue emitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *e)
LValue emitExtVectorElementExpr(const ExtVectorElementExpr *e)
clang::ASTContext & getContext() const
void setAddrOfLocalVar(const clang::VarDecl *vd, Address addr)
Set the address of a local variable.
mlir::Value cxxabiThisValue
mlir::LogicalResult emitStmt(const clang::Stmt *s, bool useCurrentScope, llvm::ArrayRef< const Attr * > attrs={})
Address emitVAListRef(const Expr *e)
Build a "reference" to a va_list; this is either the address or the value of the expression,...
mlir::LogicalResult emitCompoundStmtWithoutScope(const clang::CompoundStmt &s, Address *lastValue=nullptr, AggValueSlot slot=AggValueSlot::ignored())
void emitIgnoredExpr(const clang::Expr *e)
Emit code to compute the specified expression, ignoring the result.
LValue emitCompoundLiteralLValue(const CompoundLiteralExpr *e)
This class organizes the cross-function state that is used while generating CIR code.
DiagnosticBuilder errorNYI(SourceLocation, llvm::StringRef)
Helpers to emit "not yet implemented" error diagnostics.
Type for representing both the decl and type of parameters to a function.
Address getAddress() const
mlir::Value getPointer() const
mlir::Value getValue() const
Return the value of this scalar value.
Represents a C++ destructor within a class.
const CXXRecordDecl * getParent() const
Return the parent of this method declaration, which is the class in which this method is defined.
QualType getFunctionObjectParameterType() const
bool isAbstract() const
Determine whether this class has a pure virtual function.
bool isEmpty() const
Determine whether this is an empty class in the sense of (C++11 [meta.unary.prop]).
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
CastKind getCastKind() const
CharUnits - This is an opaque type for sizes expressed in character units.
bool isZero() const
isZero - Test whether the quantity equals zero.
CompoundStmt - This represents a group of statements like { stmt stmt }.
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
Decl * getNonClosureContext()
Find the innermost non-closure ancestor of this declaration, walking up through blocks,...
SourceLocation getLocation() const
This represents one expression.
bool EvaluateAsInt(EvalResult &Result, const ASTContext &Ctx, SideEffectsKind AllowSideEffects=SE_NoSideEffects, bool InConstantContext=false) const
EvaluateAsInt - Return true if this is a constant which we can fold and convert to an integer,...
FPOptions getFPFeaturesInEffect(const LangOptions &LO) const
Returns the set of floating point options that apply to this expression.
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point.
LangOptions::FPExceptionModeKind getExceptionMode() const
RoundingMode getRoundingMode() const
Represents a function declaration or definition.
Stmt * getBody(const FunctionDecl *&Definition) const
Retrieve the body (definition) of the function.
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
bool hasBody(const FunctionDecl *&Definition) const
Returns true if the function has a body.
FunctionDecl * getPreviousDecl()
Return the previous declaration of this declaration or NULL if this is the first declaration.
GlobalDecl - represents a global declaration.
const Decl * getDecl() const
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
FPExceptionModeKind
Possible floating point exception behavior.
@ FPE_Default
Used internally to represent initial unspecified value.
@ FPE_Strict
Strictly preserve the floating-point exception semantics.
@ FPE_MayTrap
Transformations do not cause new exceptions but may hide some.
@ FPE_Ignore
Assume that floating-point exceptions are masked.
Represents an unpacked "presumed" location which can be presented to the user.
unsigned getColumn() const
Return the presumed column number of this location.
const char * getFilename() const
Return the presumed filename of this location.
unsigned getLine() const
Return the presumed line number of this location.
A (possibly-)qualified type.
bool isTriviallyCopyableType(const ASTContext &Context) const
Return true if this is a trivially copyable type (C++0x [basic.types]p9)
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
This class handles loading and caching of source files into memory.
PresumedLoc getPresumedLoc(SourceLocation Loc, bool UseLineDirectives=true) const
Returns the "presumed" location of a SourceLocation specifies.
A trivial tuple used to represent a source range.
SourceLocation getEnd() const
SourceLocation getBegin() const
Stmt - This represents one statement.
StmtClass getStmtClass() const
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
const char * getStmtClassName() const
SourceLocation getBeginLoc() const LLVM_READONLY
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
bool isAnyComplexType() const
TypeClass getTypeClass() const
const T * getAs() const
Member-template getAs<specific type>'.
Represents a variable declaration or definition.
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Represents a C array with a specified size that is not an integer-constant-expression.
Expr * getSizeExpr() const
@ Type
The l-value was considered opaque, so the alignment was determined from a type.
@ Decl
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
static bool previousOpIsNonYieldingCleanup(mlir::Block *block)
static std::string getVersionedTmpName(llvm::StringRef name, unsigned cnt)
static bool mayDropFunctionReturn(const ASTContext &astContext, QualType returnType)
static mlir::Value emitArgumentDemotion(CIRGenFunction &cgf, const VarDecl *var, mlir::Value value)
An argument came in as a promoted argument; demote it back to its declared type.
static void eraseEmptyAndUnusedBlocks(cir::FuncOp func)
static llvm::fp::ExceptionBehavior toConstrainedExceptMd(LangOptions::FPExceptionModeKind kind)
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
const AstTypeMatcher< ArrayType > arrayType
const internal::VariadicDynCastAllOfMatcher< Stmt, Expr > expr
Matches expressions.
CXXCtorType
C++ constructor types.
@ Ctor_Base
Base object ctor.
@ Ctor_Complete
Complete object ctor.
bool isa(CodeGen::Address addr)
CXXDtorType
C++ destructor types.
@ Dtor_VectorDeleting
Vector deleting dtor.
@ Dtor_Comdat
The COMDAT used for dtors.
@ Dtor_Unified
GCC-style unified dtor.
@ Dtor_Base
Base object dtor.
@ Dtor_Complete
Complete object dtor.
@ Dtor_Deleting
Deleting dtor.
U cast(CodeGen::Address addr)
static bool fastMathFuncAttributes()
static bool vtableInitialization()
static bool constructABIArgDirectExtend()
static bool runCleanupsScope()
static bool emitTypeCheck()
static bool fastMathGuard()
static bool fastMathFlags()
static bool generateDebugInfo()
static bool cleanupWithPreservedValues()
static bool incrementProfileCounter()
Represents a scope, including function bodies, compound statements, and the substatements of if/while...
llvm::ArrayRef< mlir::Block * > getRetBlocks()
LexicalScope(CIRGenFunction &cgf, mlir::Location loc, mlir::Block *eb)
mlir::Block * getCleanupBlock(mlir::OpBuilder &builder)
cir::TryOp getClosestTryParent()
mlir::Location getRetLoc(mlir::Block *b)
EvalResult is a struct with detailed info about an evaluated expression.
APValue Val
Val - This is the value the expression can be folded to.