clang 23.0.0git
CIRGenFunction.h
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// Internal per-function state used for AST-to-ClangIR code gen
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef CLANG_LIB_CIR_CODEGEN_CIRGENFUNCTION_H
14#define CLANG_LIB_CIR_CODEGEN_CIRGENFUNCTION_H
15
16#include "CIRGenBuilder.h"
17#include "CIRGenCall.h"
18#include "CIRGenModule.h"
19#include "CIRGenTypeCache.h"
20#include "CIRGenValue.h"
21#include "EHScopeStack.h"
22
23#include "Address.h"
24
27#include "clang/AST/CharUnits.h"
29#include "clang/AST/Decl.h"
30#include "clang/AST/ExprCXX.h"
31#include "clang/AST/Stmt.h"
32#include "clang/AST/Type.h"
38#include "llvm/ADT/ScopedHashTable.h"
39#include "llvm/IR/Instructions.h"
40
41namespace {
42class ScalarExprEmitter;
43} // namespace
44
45namespace mlir {
46namespace acc {
47class LoopOp;
48} // namespace acc
49} // namespace mlir
50
51namespace clang::CIRGen {
52
53struct CGCoroData;
54
56public:
58
59private:
60 friend class ::ScalarExprEmitter;
61 /// The builder is a helper class to create IR inside a function. The
62 /// builder is stateful, in particular it keeps an "insertion point": this
63 /// is where the next operations will be introduced.
64 CIRGenBuilderTy &builder;
65
66public:
67 /// The GlobalDecl for the current function being compiled or the global
68 /// variable currently being initialized.
70
72
73 /// The compiler-generated variable that holds the return value.
74 std::optional<mlir::Value> fnRetAlloca;
75
76 // Holds coroutine data if the current function is a coroutine. We use a
77 // wrapper to manage its lifetime, so that we don't have to define CGCoroData
78 // in this header.
79 struct CGCoroInfo {
80 std::unique_ptr<CGCoroData> data;
81 CGCoroInfo();
83 };
85
86 bool isCoroutine() const { return curCoro.data != nullptr; }
87
88 /// The temporary alloca to hold the return value. This is
89 /// invalid iff the function has no return value.
91
92 /// Tracks function scope overall cleanup handling.
94
95 typedef void Destroyer(CIRGenFunction &cgf, Address addr, QualType ty);
96
97 /// A cleanup entry that will be promoted onto the EH scope stack at a later
98 /// point. Used by both the lifetime-extended cleanup stack (promoted when
99 /// the enclosing scope exits) and the deferred conditional cleanup stack
100 /// (promoted at the enclosing full-expression level).
101 ///
102 /// Currently only DestroyObject cleanups use this. When other cleanup types
103 /// are needed (e.g., CallLifetimeEnd), this struct can be extended with a
104 /// std::variant of cleanup data types.
112
114
116
117 /// A cleanup that was pushed to the EH stack but whose deactivation is
118 /// deferred until the enclosing CleanupDeactivationScope exits. Used to
119 /// protect partially-constructed aggregates (e.g. lambda captures) so that
120 /// already-initialized sub-objects are destroyed if a later initializer
121 /// throws, while avoiding double-destruction after full construction.
127
128 /// Scope that deactivates all enclosed deferred cleanups on exit.
129 /// Mirrors CodeGenFunction::CleanupDeactivationScope in classic codegen.
133 bool deactivated = false;
134
138
140 assert(!deactivated && "Deactivating already deactivated scope");
141 auto &stack = cgf.deferredDeactivationCleanupStack;
142 for (size_t i = stack.size(); i > oldDeactivateCleanupStackSize; i--) {
143 cgf.deactivateCleanupBlock(stack[i - 1].cleanup,
144 stack[i - 1].dominatingIP);
145 stack[i - 1].dominatingIP->erase();
146 }
147 stack.resize(oldDeactivateCleanupStackSize);
148 deactivated = true;
149 }
150
155 };
156
158
159 /// If a ParmVarDecl had the pass_object_size attribute, this will contain a
160 /// mapping from said ParmVarDecl to its implicit "object_size" parameter.
161 llvm::SmallDenseMap<const ParmVarDecl *, const ImplicitParamDecl *>
163
164 /// A mapping from NRVO variables to the flags used to indicate
165 /// when the NRVO has been applied to this variable.
166 llvm::DenseMap<const VarDecl *, mlir::Value> nrvoFlags;
167
168 llvm::DenseMap<const clang::ValueDecl *, clang::FieldDecl *>
171
172 /// CXXThisDecl - When generating code for a C++ member function,
173 /// this will hold the implicit 'this' declaration.
175 mlir::Value cxxabiThisValue = nullptr;
176 mlir::Value cxxThisValue = nullptr;
179
180 /// When generating code for a constructor or destructor, this will hold the
181 /// implicit argument (e.g. VTT).
184
185 /// The value of 'this' to sue when evaluating CXXDefaultInitExprs within this
186 /// expression.
188
189 /// The values of function arguments to use when evaluating
190 /// CXXInheritedCtorInitExprs within this context.
192
193 /// The current array initialization index when evaluating an
194 /// ArrayInitIndexExpr within an ArrayInitLoopExpr.
195 mlir::Value arrayInitIndex = nullptr;
196
197 // Holds the Decl for the current outermost non-closure context
198 const clang::Decl *curFuncDecl = nullptr;
199 /// This is the inner-most code context, which includes blocks.
200 const clang::Decl *curCodeDecl = nullptr;
203
204 /// The current function or global initializer that is generated code for.
205 /// This is usually a cir::FuncOp, but it can also be a cir::GlobalOp for
206 /// global initializers.
207 mlir::Operation *curFn = nullptr;
208
209 /// Save Parameter Decl for coroutine.
211
212 using DeclMapTy = llvm::DenseMap<const clang::Decl *, Address>;
213 /// This keeps track of the CIR allocas or globals for local C
214 /// declarations.
216
217 /// The type of the condition for the emitting switch statement.
219
220 clang::ASTContext &getContext() const { return cgm.getASTContext(); }
221
222 CIRGenBuilderTy &getBuilder() { return builder; }
223
225 const CIRGenModule &getCIRGenModule() const { return cgm; }
226
228 // We currently assume this isn't called for a global initializer.
229 auto fn = mlir::cast<cir::FuncOp>(curFn);
230 return &fn.getRegion().front();
231 }
232
233 /// Sanitizers enabled for this function.
235
237 public:
241
242 private:
243 void ConstructorHelper(clang::FPOptions FPFeatures);
244 CIRGenFunction &cgf;
245 clang::FPOptions oldFPFeatures;
246 llvm::fp::ExceptionBehavior oldExcept;
247 llvm::RoundingMode oldRounding;
248 };
250
251 /// The symbol table maps a variable name to a value in the current scope.
252 /// Entering a function creates a new scope, and the function arguments are
253 /// added to the mapping. When the processing of a function is terminated,
254 /// the scope is destroyed and the mappings created in this scope are
255 /// dropped.
256 using SymTableTy = llvm::ScopedHashTable<const clang::Decl *, mlir::Value>;
258
259 /// Whether a cir.stacksave operation has been added. Used to avoid
260 /// inserting cir.stacksave for multiple VLAs in the same scope.
261 bool didCallStackSave = false;
262
263 /// Whether or not a Microsoft-style asm block has been processed within
264 /// this fuction. These can potentially set the return value.
265 bool sawAsmBlock = false;
266
267 /// In C++, whether we are code generating a thunk. This controls whether we
268 /// should emit cleanups.
269 bool curFuncIsThunk = false;
270
271 mlir::Type convertTypeForMem(QualType t);
272
273 mlir::Type convertType(clang::QualType t);
274 mlir::Type convertType(const TypeDecl *t) {
275 return convertType(getContext().getTypeDeclType(t));
276 }
277
278 /// Get integer from a mlir::Value that is an int constant or a constant op.
279 static int64_t getSExtIntValueFromConstOp(mlir::Value val) {
280 auto constOp = val.getDefiningOp<cir::ConstantOp>();
281 assert(constOp && "getSExtIntValueFromConstOp call with non ConstantOp");
282 return constOp.getIntValue().getSExtValue();
283 }
284
285 /// Get zero-extended integer from a mlir::Value that is an int constant or a
286 /// constant op.
287 static int64_t getZExtIntValueFromConstOp(mlir::Value val) {
288 auto constOp = val.getDefiningOp<cir::ConstantOp>();
289 assert(constOp && "getZExtIntValueFromConstOp call with non ConstantOp");
290 return constOp.getIntValue().getZExtValue();
291 }
292
293 /// Return the cir::TypeEvaluationKind of QualType \c type.
295
299
303
305 bool suppressNewContext = false);
307
308 CIRGenTypes &getTypes() const { return cgm.getTypes(); }
309
310 const TargetInfo &getTarget() const { return cgm.getTarget(); }
311 mlir::MLIRContext &getMLIRContext() { return cgm.getMLIRContext(); }
312
314 return cgm.getTargetCIRGenInfo();
315 }
316
317 // ---------------------
318 // Opaque value handling
319 // ---------------------
320
321 /// Keeps track of the current set of opaque value expressions.
322 llvm::DenseMap<const OpaqueValueExpr *, LValue> opaqueLValues;
323 llvm::DenseMap<const OpaqueValueExpr *, RValue> opaqueRValues;
324
325 // This keeps track of the associated size for each VLA type.
326 // We track this by the size expression rather than the type itself because
327 // in certain situations, like a const qualifier applied to an VLA typedef,
328 // multiple VLA types can share the same size expression.
329 // FIXME: Maybe this could be a stack of maps that is pushed/popped as we
330 // enter/leave scopes.
331 llvm::DenseMap<const Expr *, mlir::Value> vlaSizeMap;
332
333public:
334 /// A non-RAII class containing all the information about a bound
335 /// opaque value. OpaqueValueMapping, below, is a RAII wrapper for
336 /// this which makes individual mappings very simple; using this
337 /// class directly is useful when you have a variable number of
338 /// opaque values or don't want the RAII functionality for some
339 /// reason.
340 class OpaqueValueMappingData {
341 const OpaqueValueExpr *opaqueValue;
342 bool boundLValue;
343
344 OpaqueValueMappingData(const OpaqueValueExpr *ov, bool boundLValue)
345 : opaqueValue(ov), boundLValue(boundLValue) {}
346
347 public:
348 OpaqueValueMappingData() : opaqueValue(nullptr) {}
349
350 static bool shouldBindAsLValue(const Expr *expr) {
351 // gl-values should be bound as l-values for obvious reasons.
352 // Records should be bound as l-values because IR generation
353 // always keeps them in memory. Expressions of function type
354 // act exactly like l-values but are formally required to be
355 // r-values in C.
356 return expr->isGLValue() || expr->getType()->isFunctionType() ||
358 }
359
361 bind(CIRGenFunction &cgf, const OpaqueValueExpr *ov, const Expr *e) {
362 if (shouldBindAsLValue(ov))
363 return bind(cgf, ov, cgf.emitLValue(e));
364 return bind(cgf, ov, cgf.emitAnyExpr(e));
365 }
366
368 bind(CIRGenFunction &cgf, const OpaqueValueExpr *ov, const LValue &lv) {
369 assert(shouldBindAsLValue(ov));
370 cgf.opaqueLValues.insert(std::make_pair(ov, lv));
371 return OpaqueValueMappingData(ov, true);
372 }
373
375 bind(CIRGenFunction &cgf, const OpaqueValueExpr *ov, const RValue &rv) {
376 assert(!shouldBindAsLValue(ov));
377 cgf.opaqueRValues.insert(std::make_pair(ov, rv));
378
379 OpaqueValueMappingData data(ov, false);
380
381 // Work around an extremely aggressive peephole optimization in
382 // EmitScalarConversion which assumes that all other uses of a
383 // value are extant.
385 return data;
386 }
387
388 bool isValid() const { return opaqueValue != nullptr; }
389 void clear() { opaqueValue = nullptr; }
390
392 assert(opaqueValue && "no data to unbind!");
393
394 if (boundLValue) {
395 cgf.opaqueLValues.erase(opaqueValue);
396 } else {
397 cgf.opaqueRValues.erase(opaqueValue);
399 }
400 }
401 };
402
403 /// An RAII object to set (and then clear) a mapping for an OpaqueValueExpr.
405 CIRGenFunction &cgf;
407
408 public:
412
413 /// Build the opaque value mapping for the given conditional
414 /// operator if it's the GNU ?: extension. This is a common
415 /// enough pattern that the convenience operator is really
416 /// helpful.
417 ///
420 : cgf(cgf) {
421 if (mlir::isa<ConditionalOperator>(op))
422 // Leave Data empty.
423 return;
424
426 mlir::cast<BinaryConditionalOperator>(op);
428 e->getCommon());
429 }
430
431 /// Build the opaque value mapping for an OpaqueValueExpr whose source
432 /// expression is set to the expression the OVE represents.
434 : cgf(cgf) {
435 if (ov) {
436 assert(ov->getSourceExpr() && "wrong form of OpaqueValueMapping used "
437 "for OVE with no source expression");
438 data = OpaqueValueMappingData::bind(cgf, ov, ov->getSourceExpr());
439 }
440 }
441
443 LValue lvalue)
444 : cgf(cgf),
445 data(OpaqueValueMappingData::bind(cgf, opaqueValue, lvalue)) {}
446
448 RValue rvalue)
449 : cgf(cgf),
450 data(OpaqueValueMappingData::bind(cgf, opaqueValue, rvalue)) {}
451
452 void pop() {
453 data.unbind(cgf);
454 data.clear();
455 }
456
458 if (data.isValid())
459 data.unbind(cgf);
460 }
461 };
462
463private:
464 /// Declare a variable in the current scope, return success if the variable
465 /// wasn't declared yet.
466 void declare(mlir::Value addrVal, const clang::Decl *var, clang::QualType ty,
467 mlir::Location loc, clang::CharUnits alignment,
468 bool isParam = false);
469
470public:
471 mlir::Value createDummyValue(mlir::Location loc, clang::QualType qt);
472
473 void emitNullInitialization(mlir::Location loc, Address destPtr, QualType ty);
474
475private:
476 // Track current variable initialization (if there's one)
477 const clang::VarDecl *currVarDecl = nullptr;
478 class VarDeclContext {
480 const clang::VarDecl *oldVal = nullptr;
481
482 public:
483 VarDeclContext(CIRGenFunction &p, const VarDecl *value) : p(p) {
484 if (p.currVarDecl)
485 oldVal = p.currVarDecl;
486 p.currVarDecl = value;
487 }
488
489 /// Can be used to restore the state early, before the dtor
490 /// is run.
491 void restore() { p.currVarDecl = oldVal; }
492 ~VarDeclContext() { restore(); }
493 };
494
495public:
496 /// Use to track source locations across nested visitor traversals.
497 /// Always use a `SourceLocRAIIObject` to change currSrcLoc.
498 std::optional<mlir::Location> currSrcLoc;
500 CIRGenFunction &cgf;
501 std::optional<mlir::Location> oldLoc;
502
503 public:
504 SourceLocRAIIObject(CIRGenFunction &cgf, mlir::Location value) : cgf(cgf) {
505 if (cgf.currSrcLoc)
506 oldLoc = cgf.currSrcLoc;
507 cgf.currSrcLoc = value;
508 }
509
510 /// Can be used to restore the state early, before the dtor
511 /// is run.
512 void restore() { cgf.currSrcLoc = oldLoc; }
514 };
515
517 llvm::ScopedHashTableScope<const clang::Decl *, mlir::Value>;
518
519 /// Hold counters for incrementally naming temporaries
520 unsigned counterRefTmp = 0;
521 unsigned counterAggTmp = 0;
522 std::string getCounterRefTmpAsString();
523 std::string getCounterAggTmpAsString();
524
525 /// Helpers to convert Clang's SourceLocation to a MLIR Location.
526 mlir::Location getLoc(clang::SourceLocation srcLoc);
527 mlir::Location getLoc(clang::SourceRange srcLoc);
528 mlir::Location getLoc(mlir::Location lhs, mlir::Location rhs);
529
530 const clang::LangOptions &getLangOpts() const { return cgm.getLangOpts(); }
531
532 /// True if an insertion point is defined. If not, this indicates that the
533 /// current code being emitted is unreachable.
534 /// FIXME(cir): we need to inspect this and perhaps use a cleaner mechanism
535 /// since we don't yet force null insertion point to designate behavior (like
536 /// LLVM's codegen does) and we probably shouldn't.
537 bool haveInsertPoint() const {
538 return builder.getInsertionBlock() != nullptr;
539 }
540
541 // Wrapper for function prototype sources. Wraps either a FunctionProtoType or
542 // an ObjCMethodDecl.
544 llvm::PointerUnion<const clang::FunctionProtoType *,
545 const clang::ObjCMethodDecl *>
547
550 };
551
553
556 RValue emitAtomicLoad(LValue lvalue, SourceLocation loc, cir::MemOrder order,
557 bool isVolatile = false,
559
560 /// An abstract representation of regular/ObjC call/message targets.
562 /// The function declaration of the callee.
563 [[maybe_unused]] const clang::Decl *calleeDecl;
564
565 public:
566 AbstractCallee() : calleeDecl(nullptr) {}
567 AbstractCallee(const clang::FunctionDecl *fd) : calleeDecl(fd) {}
568
569 bool hasFunctionDecl() const {
570 return llvm::isa_and_nonnull<clang::FunctionDecl>(calleeDecl);
571 }
572
573 const clang::Decl *getDecl() const { return calleeDecl; }
574
575 unsigned getNumParams() const {
576 if (const auto *fd = llvm::dyn_cast<clang::FunctionDecl>(calleeDecl))
577 return fd->getNumParams();
578 return llvm::cast<clang::ObjCMethodDecl>(calleeDecl)->param_size();
579 }
580
581 const clang::ParmVarDecl *getParamDecl(unsigned I) const {
582 if (const auto *fd = llvm::dyn_cast<clang::FunctionDecl>(calleeDecl))
583 return fd->getParamDecl(I);
584 return *(llvm::cast<clang::ObjCMethodDecl>(calleeDecl)->param_begin() +
585 I);
586 }
587 };
588
589 struct VlaSizePair {
590 mlir::Value numElts;
592
593 VlaSizePair(mlir::Value num, QualType ty) : numElts(num), type(ty) {}
594 };
595
596 /// Return the number of elements for a single dimension
597 /// for the given array type.
598 VlaSizePair getVLAElements1D(const VariableArrayType *vla);
599
600 /// Returns an MLIR::Value+QualType pair that corresponds to the size,
601 /// in non-variably-sized elements, of a variable length array type,
602 /// plus that largest non-variably-sized element type. Assumes that
603 /// the type has already been emitted with emitVariablyModifiedType.
604 VlaSizePair getVLASize(const VariableArrayType *type);
605 VlaSizePair getVLASize(QualType type);
606
608
609 mlir::Value getAsNaturalPointerTo(Address addr, QualType pointeeType) {
610 return getAsNaturalAddressOf(addr, pointeeType).getBasePointer();
611 }
612
613 void finishFunction(SourceLocation endLoc);
614
615 /// Determine whether the given initializer is trivial in the sense
616 /// that it requires no code to be generated.
617 bool isTrivialInitializer(const Expr *init);
618
619 /// If the specified expression does not fold to a constant, or if it does but
620 /// contains a label, return false. If it constant folds return true and set
621 /// the boolean result in Result.
622 bool constantFoldsToBool(const clang::Expr *cond, bool &resultBool,
623 bool allowLabels = false);
625 llvm::APSInt &resultInt,
626 bool allowLabels = false);
627
628 /// Return true if the statement contains a label in it. If
629 /// this statement is not executed normally, it not containing a label means
630 /// that we can just remove the code.
631 bool containsLabel(const clang::Stmt *s, bool ignoreCaseStmts = false);
632
633 Address emitExtVectorElementLValue(LValue lv, mlir::Location loc);
634
635 class ConstantEmission {
636 // Cannot use mlir::TypedAttr directly here because of bit availability.
637 llvm::PointerIntPair<mlir::Attribute, 1, bool> valueAndIsReference;
638 ConstantEmission(mlir::TypedAttr c, bool isReference)
639 : valueAndIsReference(c, isReference) {}
640
641 public:
643 static ConstantEmission forReference(mlir::TypedAttr c) {
644 return ConstantEmission(c, true);
645 }
646 static ConstantEmission forValue(mlir::TypedAttr c) {
647 return ConstantEmission(c, false);
648 }
649
650 explicit operator bool() const {
651 return valueAndIsReference.getOpaqueValue() != nullptr;
652 }
653
654 bool isReference() const { return valueAndIsReference.getInt(); }
656 assert(isReference());
657 cgf.cgm.errorNYI(refExpr->getSourceRange(),
658 "ConstantEmission::getReferenceLValue");
659 return {};
660 }
661
662 mlir::TypedAttr getValue() const {
663 assert(!isReference());
664 return mlir::cast<mlir::TypedAttr>(valueAndIsReference.getPointer());
665 }
666 };
667
668 ConstantEmission tryEmitAsConstant(const DeclRefExpr *refExpr);
669 ConstantEmission tryEmitAsConstant(const MemberExpr *me);
670
673 /// The address of the alloca for languages with explicit address space
674 /// (e.g. OpenCL) or alloca casted to generic pointer for address space
675 /// agnostic languages (e.g. C++). Invalid if the variable was emitted
676 /// as a global constant.
678
679 /// True if the variable is of aggregate type and has a constant
680 /// initializer.
682
683 /// True if the variable is a __block variable that is captured by an
684 /// escaping block.
685 bool isEscapingByRef = false;
686
687 /// True if the variable was emitted as an offload recipe, and thus doesn't
688 /// have the same sort of alloca initialization.
689 bool emittedAsOffload = false;
690
691 mlir::Value nrvoFlag{};
692
693 struct Invalid {};
695
698
700
701 bool wasEmittedAsGlobal() const { return !addr.isValid(); }
702
704
705 /// Returns the raw, allocated address, which is not necessarily
706 /// the address of the object itself. It is casted to default
707 /// address space for address space agnostic languages.
708 Address getAllocatedAddress() const { return addr; }
709
710 // Changes the stored address for the emission. This function should only
711 // be used in extreme cases, and isn't required to model normal AST
712 // initialization/variables.
714
715 /// Returns the address of the object within this declaration.
716 /// Note that this does not chase the forwarding pointer for
717 /// __block decls.
719 if (!isEscapingByRef)
720 return addr;
721
723 return Address::invalid();
724 }
725 };
726
727 /// IndirectBranch - The first time an indirect goto is seen we create a block
728 /// reserved for the indirect branch. Unlike before,the actual 'indirectbr'
729 /// is emitted at the end of the function, once all block destinations have
730 /// been resolved.
731 mlir::Block *indirectGotoBlock = nullptr;
732
735
736 /// Perform the usual unary conversions on the specified expression and
737 /// compare the result against zero, returning an Int1Ty value.
738 mlir::Value evaluateExprAsBool(const clang::Expr *e);
739
740 cir::GlobalOp addInitializerToStaticVarDecl(const VarDecl &d,
741 cir::GlobalOp gv,
742 cir::GetGlobalOp gvAddr);
743
744 /// Enter the cleanups necessary to complete the given phase of destruction
745 /// for a destructor. The end result should call destructors on members and
746 /// base classes in reverse order of their construction.
748
749 /// Determines whether an EH cleanup is required to destroy a type
750 /// with the given destruction kind.
751 /// TODO(cir): could be shared with Clang LLVM codegen
753 switch (kind) {
755 return false;
759 return getLangOpts().Exceptions;
761 return getLangOpts().Exceptions &&
762 cgm.getCodeGenOpts().ObjCAutoRefCountExceptions;
763 }
764 llvm_unreachable("bad destruction kind");
765 }
766
770
772
773 /// Set the address of a local variable.
775 assert(!localDeclMap.count(vd) && "Decl already exists in LocalDeclMap!");
776 localDeclMap.insert({vd, addr});
777
778 // Add to the symbol table if not there already.
779 if (symbolTable.count(vd))
780 return;
781 symbolTable.insert(vd, addr.getPointer());
782 }
783
784 // Replaces the address of the local variable, if it exists. Else does the
785 // same thing as setAddrOfLocalVar.
787 localDeclMap.insert_or_assign(vd, addr);
788 }
789
790 // A class to allow reverting changes to a var-decl's registration to the
791 // localDeclMap. This is used in cases where things are being inserted into
792 // the variable list but don't follow normal lookup/search rules, like in
793 // OpenACC recipe generation.
795 CIRGenFunction &cgf;
796 const VarDecl *vd;
797 bool shouldDelete = false;
798 Address oldAddr = Address::invalid();
799
800 public:
802 : cgf(cgf), vd(vd) {
803 auto mapItr = cgf.localDeclMap.find(vd);
804
805 if (mapItr != cgf.localDeclMap.end())
806 oldAddr = mapItr->second;
807 else
808 shouldDelete = true;
809 }
810
812 if (shouldDelete)
813 cgf.localDeclMap.erase(vd);
814 else
815 cgf.localDeclMap.insert_or_assign(vd, oldAddr);
816 }
817 };
818
820
823
824 static bool
826
833
836
840 const clang::CXXRecordDecl *nearestVBase,
841 clang::CharUnits offsetFromNearestVBase,
842 bool baseIsNonVirtualPrimaryBase,
843 const clang::CXXRecordDecl *vtableClass,
844 VisitedVirtualBasesSetTy &vbases, VPtrsVector &vptrs);
845 /// Return the Value of the vtable pointer member pointed to by thisAddr.
846 mlir::Value getVTablePtr(mlir::Location loc, Address thisAddr,
847 const clang::CXXRecordDecl *vtableClass);
848
849 /// Returns whether we should perform a type checked load when loading a
850 /// virtual function for virtual calls to members of RD. This is generally
851 /// true when both vcall CFI and whole-program-vtables are enabled.
853
854 /// Source location information about the default argument or member
855 /// initializer expression we're evaluating, if any.
859
860 /// A scope within which we are constructing the fields of an object which
861 /// might use a CXXDefaultInitExpr. This stashes away a 'this' value to use if
862 /// we need to evaluate the CXXDefaultInitExpr within the evaluation.
864 public:
866 : cgf(cgf), oldCXXDefaultInitExprThis(cgf.cxxDefaultInitExprThis) {
867 cgf.cxxDefaultInitExprThis = thisAddr;
868 }
870 cgf.cxxDefaultInitExprThis = oldCXXDefaultInitExprThis;
871 }
872
873 private:
874 CIRGenFunction &cgf;
875 Address oldCXXDefaultInitExprThis;
876 };
877
878 /// The scope of a CXXDefaultInitExpr. Within this scope, the value of 'this'
879 /// is overridden to be the object under construction.
881 public:
886 cgf.cxxThisValue = cgf.cxxDefaultInitExprThis.getPointer();
887 cgf.cxxThisAlignment = cgf.cxxDefaultInitExprThis.getAlignment();
888 }
890 cgf.cxxThisValue = oldCXXThisValue;
891 cgf.cxxThisAlignment = oldCXXThisAlignment;
892 }
893
894 public:
896 mlir::Value oldCXXThisValue;
899 };
900
905
906 /// The scope of an ArrayInitLoopExpr. Within this scope, the value of the
907 /// current loop index is overridden. In order to encourage re-use of existing
908 /// array initialization, this uses a flag to determine if it is a 'no-op' or
909 /// not.
911 public:
912 ArrayInitLoopExprScope(CIRGenFunction &cgf, bool setIdx, mlir::Value index)
913 : cgf(cgf),
914 oldArrayInitIndex(setIdx
915 ? std::optional<mlir::Value>(cgf.arrayInitIndex)
916 : std::nullopt) {
917 if (setIdx)
918 cgf.arrayInitIndex = index;
919 }
921 if (oldArrayInitIndex.has_value())
922 cgf.arrayInitIndex = *oldArrayInitIndex;
923 }
924
925 private:
926 CIRGenFunction &cgf;
927 std::optional<mlir::Value> oldArrayInitIndex;
928 };
929
930 /// Get the index of the current ArrayInitLoopExpr, if any.
931 mlir::Value getArrayInitIndex() { return arrayInitIndex; }
932
934 LValue makeNaturalAlignAddrLValue(mlir::Value val, QualType ty);
935
936 /// Construct an address with the natural alignment of T. If a pointer to T
937 /// is expected to be signed, the pointer passed to this function must have
938 /// been signed, and the returned Address will have the pointer authentication
939 /// information needed to authenticate the signed pointer.
941 CharUnits alignment,
942 bool forPointeeType = false,
943 LValueBaseInfo *baseInfo = nullptr) {
944 if (alignment.isZero())
945 alignment = cgm.getNaturalTypeAlignment(t, baseInfo);
946 return Address(ptr, convertTypeForMem(t), alignment);
947 }
948
950 Address value, const CXXRecordDecl *derived,
951 llvm::iterator_range<CastExpr::path_const_iterator> path,
952 bool nullCheckValue, SourceLocation loc);
953
955 mlir::Location loc, Address baseAddr, const CXXRecordDecl *derived,
956 llvm::iterator_range<CastExpr::path_const_iterator> path,
957 bool nullCheckValue);
958
959 /// Return the VTT parameter that should be passed to a base
960 /// constructor/destructor with virtual bases.
961 /// FIXME: VTTs are Itanium ABI-specific, so the definition should move
962 /// to ItaniumCXXABI.cpp together with all the references to VTT.
963 mlir::Value getVTTParameter(GlobalDecl gd, bool forVirtualBase,
964 bool delegating);
965
968 return makeAddrLValue(addr, ty, LValueBaseInfo(source));
969 }
970
972 return LValue::makeAddr(addr, ty, baseInfo);
973 }
974
975 void initializeVTablePointers(mlir::Location loc,
976 const clang::CXXRecordDecl *rd);
977 void initializeVTablePointer(mlir::Location loc, const VPtr &vptr);
978
980
981 /// Return the address of a local variable.
983 auto it = localDeclMap.find(vd);
984 assert(it != localDeclMap.end() &&
985 "Invalid argument to getAddrOfLocalVar(), no decl!");
986 return it->second;
987 }
988
990 mlir::Type fieldType, unsigned index);
991
992 /// Given an opaque value expression, return its LValue mapping if it exists,
993 /// otherwise create one.
995
996 /// Given an opaque value expression, return its RValue mapping if it exists,
997 /// otherwise create one.
999
1000 /// Load the value for 'this'. This function is only valid while generating
1001 /// code for an C++ member function.
1002 /// FIXME(cir): this should return a mlir::Value!
1003 mlir::Value loadCXXThis() {
1004 assert(cxxThisValue && "no 'this' value for this function");
1005 return cxxThisValue;
1006 }
1008
1009 /// Load the VTT parameter to base constructors/destructors have virtual
1010 /// bases. FIXME: Every place that calls LoadCXXVTT is something that needs to
1011 /// be abstracted properly.
1012 mlir::Value loadCXXVTT() {
1013 assert(cxxStructorImplicitParamValue && "no VTT value for this function");
1015 }
1016
1017 /// Convert the given pointer to a complete class to the given direct base.
1019 Address value,
1020 const CXXRecordDecl *derived,
1021 const CXXRecordDecl *base,
1022 bool baseIsVirtual);
1023
1024 /// Determine whether a return value slot may overlap some other object.
1026 // FIXME: Assuming no overlap here breaks guaranteed copy elision for base
1027 // class subobjects. These cases may need to be revisited depending on the
1028 // resolution of the relevant core issue.
1030 }
1031
1032 /// Determine whether a base class initialization may overlap some other
1033 /// object.
1035 const CXXRecordDecl *baseRD,
1036 bool isVirtual);
1037
1038 /// Return a CIR constant for an undefined value of \p cirTy.
1039 mlir::Value getUndefConstant(mlir::Location loc, mlir::Type cirTy);
1040
1041 /// Get an appropriate 'undef' rvalue for the given type.
1043
1044 cir::FuncOp generateCode(clang::GlobalDecl gd, cir::FuncOp fn,
1045 cir::FuncType funcType);
1046
1048 FunctionArgList &args);
1049
1050 /// Emit the function prologue: declare function arguments in the symbol
1051 /// table.
1052 void emitFunctionProlog(const FunctionArgList &args, mlir::Block *entryBB,
1053 const FunctionDecl *fd, SourceLocation bodyBeginLoc);
1054
1055 /// Emit code for the start of a function.
1056 /// \param loc The location to be associated with the function.
1057 /// \param startLoc The location of the function body.
1059 cir::FuncOp fn, cir::FuncType funcType,
1061 clang::SourceLocation startLoc);
1062
1063 /// returns true if aggregate type has a volatile member.
1065 if (const auto *rd = t->getAsRecordDecl())
1066 return rd->hasVolatileMember();
1067 return false;
1068 }
1069
1070 void addCatchHandlerAttr(const CXXCatchStmt *catchStmt,
1071 SmallVector<mlir::Attribute> &handlerAttrs);
1072
1073 /// The cleanup depth enclosing all the cleanups associated with the
1074 /// parameters.
1076
1078
1079 /// Takes the old cleanup stack size and emits the cleanup blocks
1080 /// that have been added.
1081 void popCleanupBlocks(EHScopeStack::stable_iterator oldCleanupStackDepth,
1082 ArrayRef<mlir::Value *> valuesToReload = {});
1083
1084 /// Pops cleanup blocks until the given savepoint is reached, then adds the
1085 /// cleanups from the given savepoint in the lifetime-extended cleanups stack.
1086 void popCleanupBlocks(EHScopeStack::stable_iterator oldCleanupStackDepth,
1087 size_t oldLifetimeExtendedSize,
1088 ArrayRef<mlir::Value *> valuesToReload = {});
1089 void popCleanupBlock(bool forDeactivation = false);
1090
1091 void terminateStructuredRegionBody(mlir::Region &r, mlir::Location loc);
1092
1093 /// Deactivates the given cleanup block. The block cannot be reactivated. Pops
1094 /// it if it's the top of the stack.
1095 ///
1096 /// \param DominatingIP - An instruction which is known to
1097 /// dominate the current IP (if set) and which lies along
1098 /// all paths of execution between the current IP and the
1099 /// the point at which the cleanup comes into scope.
1100 void deactivateCleanupBlock(EHScopeStack::stable_iterator cleanup,
1101 mlir::Operation *dominatingIP);
1102
1103 /// Create an active flag variable for use with conditional cleanups. The
1104 /// flag is initialized to false before the outermost conditional and set to
1105 /// true at the current insertion point (inside the conditional branch).
1106 Address createCleanupActiveFlag();
1107
1108 /// Set up the last cleanup that was pushed as a conditional
1109 /// full-expression cleanup.
1110 void initFullExprCleanup();
1111 void initFullExprCleanupWithFlag(Address activeFlag);
1112
1113 /// Promote a single pending cleanup entry onto the EH scope stack. If the
1114 /// entry has a valid activeFlag, the cleanup is configured as conditional.
1115 /// Defined in CIRGenDecl.cpp where the concrete cleanup types are visible.
1116 void pushPendingCleanupToEHStack(const PendingCleanupEntry &entry);
1117
1118 /// Push a cleanup to be run at the end of the current full-expression. Safe
1119 /// against the possibility that we're currently inside a
1120 /// conditionally-evaluated expression.
1121 template <class T, class... As>
1123 if (!isInConditionalBranch())
1124 return ehStack.pushCleanup<T>(kind, a...);
1125
1126 // Defer the cleanup until the FullExprCleanupScope exits. We can't push
1127 // to the EH stack now because the ternary's inner LexicalScope would pop
1128 // it prematurely.
1129 Address activeFlag = createCleanupActiveFlag();
1131 PendingCleanupEntry{kind, a..., activeFlag});
1132 }
1133
1134 /// Push a cleanup and record it for deferred deactivation. The cleanup will
1135 /// be deactivated when the enclosing CleanupDeactivationScope exits.
1136 template <class T, class... As>
1138 mlir::Location loc = builder.getUnknownLoc();
1139 mlir::Operation *dominatingIP = builder.getBool(false, loc).getOperation();
1140 ehStack.pushCleanup<T>(kind, a...);
1142 {ehStack.stable_begin(), dominatingIP});
1143 }
1144
1146 Address addr, QualType type);
1148 QualType type, Destroyer *destroyer,
1149 bool useEHCleanupForArray);
1150
1151 /// Queue a cleanup to be pushed after finishing the current full-expression.
1152 /// When the enclosing RunCleanupsScope exits, popCleanupBlocks promotes these
1153 /// entries onto the EH scope stack for the enclosing scope.
1155 Destroyer *destroyer) {
1156 lifetimeExtendedCleanupStack.push_back({kind, addr, type, destroyer});
1157 }
1158
1159 /// Enters a new scope for capturing cleanups, all of which
1160 /// will be executed once the scope is exited.
1161 class RunCleanupsScope {
1162 EHScopeStack::stable_iterator cleanupStackDepth, oldCleanupStackDepth;
1163 size_t lifetimeExtendedCleanupStackSize;
1164 CleanupDeactivationScope deactivateCleanups;
1165
1166 protected:
1169
1170 private:
1171 RunCleanupsScope(const RunCleanupsScope &) = delete;
1172 void operator=(const RunCleanupsScope &) = delete;
1173
1174 protected:
1176
1177 public:
1178 /// Enter a new cleanup scope.
1180 : deactivateCleanups(cgf), performCleanup(true), cgf(cgf) {
1181 cleanupStackDepth = cgf.ehStack.stable_begin();
1182 lifetimeExtendedCleanupStackSize =
1183 cgf.lifetimeExtendedCleanupStack.size();
1184 oldDidCallStackSave = cgf.didCallStackSave;
1185 cgf.didCallStackSave = false;
1186 oldCleanupStackDepth = cgf.currentCleanupStackDepth;
1187 cgf.currentCleanupStackDepth = cleanupStackDepth;
1188 }
1189
1190 /// Exit this cleanup scope, emitting any accumulated cleanups.
1192 if (performCleanup)
1193 forceCleanup();
1194 }
1195
1196 /// Force the emission of cleanups now, instead of waiting
1197 /// until this object is destroyed.
1198 void forceCleanup(ArrayRef<mlir::Value *> valuesToReload = {}) {
1199 assert(performCleanup && "Already forced cleanup");
1201
1202 // forceDeactivate() can pop cleanup scopes that were pushed with
1203 // deferred deactivation, which moves the insertion point out of the
1204 // cleanup body region. Any caller value defined inside such a body
1205 // would no longer dominate uses past the scope. The downstream
1206 // popCleanupBlocks() handles the spill for any cleanups it pops
1207 // itself, but it cannot help with cleanups that forceDeactivate has
1208 // already popped. Spill those values here, while the insertion point
1209 // is still inside the body, so we can reload them after all popping
1210 // is done. We only spill values whose defining op lives inside a
1211 // cir.cleanup.scope, since values defined outside any cleanup scope
1212 // (e.g. allocas in the entry block) already dominate the post-scope
1213 // insertion point.
1214 const bool hasPendingDeactivations =
1216 deactivateCleanups.oldDeactivateCleanupStackSize;
1217
1218 llvm::SmallVector<Address> tempAllocas;
1219 bool didSpillAny = false;
1220 if (hasPendingDeactivations) {
1221 tempAllocas.reserve(valuesToReload.size());
1222 for (mlir::Value *valPtr : valuesToReload) {
1223 mlir::Value val = *valPtr;
1224 if (!val || !val.getDefiningOp() ||
1225 !val.getDefiningOp()->getParentOfType<cir::CleanupScopeOp>()) {
1226 tempAllocas.push_back(Address::invalid());
1227 continue;
1228 }
1230 val.getType(), val.getLoc(), "tmp.exprcleanup");
1231 tempAllocas.push_back(temp);
1232 cgf.builder.createStore(val.getLoc(), val, temp);
1233 didSpillAny = true;
1234 }
1235 }
1236
1237 deactivateCleanups.forceDeactivate();
1238 // If we already spilled some of the caller's values, don't ask
1239 // popCleanupBlocks to spill them again. Values we did not pre-spill
1240 // are not inside any cir.cleanup.scope, so they cannot be invalidated
1241 // by either forceDeactivate's or popCleanupBlocks's pops (both only
1242 // pop cir.cleanup.scope ops); they already dominate the post-scope
1243 // insertion point on their own.
1244 if (didSpillAny) {
1245 cgf.popCleanupBlocks(cleanupStackDepth,
1246 lifetimeExtendedCleanupStackSize);
1247
1248 // Reload the spilled values now that all cleanup popping (and
1249 // promotion of any lifetime-extended cleanups onto the EH stack) is
1250 // done.
1251 for (auto [addr, valPtr] : llvm::zip(tempAllocas, valuesToReload)) {
1252 if (!addr.isValid())
1253 continue;
1254 *valPtr = cgf.builder.createLoad(valPtr->getLoc(), addr);
1255 }
1256 } else {
1257 cgf.popCleanupBlocks(cleanupStackDepth,
1258 lifetimeExtendedCleanupStackSize, valuesToReload);
1259 }
1260
1261 performCleanup = false;
1262 cgf.currentCleanupStackDepth = oldCleanupStackDepth;
1263 }
1264
1265 /// Force the emission of EH cleanups now, but defer promoting any
1266 /// lifetime-extended cleanup entries onto the EH scope stack. The caller
1267 /// must subsequently call forceLifetimeExtendedCleanups() to finalize the
1268 /// scope.
1270 assert(performCleanup && "Already forced cleanup");
1271 cgf.didCallStackSave = oldDidCallStackSave;
1272 deactivateCleanups.forceDeactivate();
1273 cgf.popCleanupBlocks(cleanupStackDepth);
1274 }
1275
1276 /// Promote any pending lifetime-extended cleanup entries onto the EH scope
1277 /// stack at the current insertion point and finalize this scope. This must
1278 /// be paired with a prior call to forceCleanupExceptLifetimeExtended().
1280 assert(performCleanup && "Already forced cleanup");
1281 assert(deactivateCleanups.deactivated &&
1282 "forceCleanupExceptLifetimeExtended() must be called first");
1283 cgf.popCleanupBlocks(cleanupStackDepth, lifetimeExtendedCleanupStackSize);
1284 performCleanup = false;
1285 cgf.currentCleanupStackDepth = oldCleanupStackDepth;
1286 }
1287
1288 /// Whether there are any pending cleanups that have been pushed since
1289 /// this scope was entered.
1290 bool hasPendingCleanups() const {
1291 return cgf.ehStack.stable_begin() != cleanupStackDepth;
1292 }
1293 };
1294
1295 // Cleanup stack depth of the RunCleanupsScope that was pushed most recently.
1297
1299 CIRGenFunction &cgf;
1300 RunCleanupsScope cleanups;
1301 cir::CleanupScopeOp scope;
1302 size_t deferredCleanupStackSize;
1303 bool exited = false;
1304
1305 public:
1306 FullExprCleanupScope(CIRGenFunction &cgf, const Expr *subExpr);
1307
1308 void exit(ArrayRef<mlir::Value *> valuesToReload = {});
1309
1311 if (!exited)
1312 exit();
1313 }
1314
1315 private:
1317 void operator=(const FullExprCleanupScope &) = delete;
1318 };
1319
1320public:
1321 /// Represents a scope, including function bodies, compound statements, and
1322 /// the substatements of if/while/do/for/switch/try statements. This class
1323 /// handles any automatic cleanup, along with the return value.
1324 struct LexicalScope : public RunCleanupsScope {
1325 private:
1326 // Points to the scope entry block. This is useful, for instance, for
1327 // helping to insert allocas before finalizing any recursive CodeGen from
1328 // switches.
1329 mlir::Block *entryBlock;
1330
1331 LexicalScope *parentScope = nullptr;
1332
1333 // Holds the actual value for ScopeKind::Try
1334 cir::TryOp tryOp = nullptr;
1335
1336 // On a coroutine body, the OnFallthrough sub stmt holds the handler
1337 // (CoreturnStmt) for control flow falling off the body. Keep track
1338 // of emitted co_return in this scope and allow OnFallthrough to be
1339 // skipeed.
1340 bool hasCoreturnStmt = false;
1341
1342 // Only Regular is used at the moment. Support for other kinds will be
1343 // added as the relevant statements/expressions are upstreamed.
1344 enum Kind {
1345 Regular, // cir.if, cir.scope, if_regions
1346 Ternary, // cir.ternary
1347 Switch, // cir.switch
1348 Try, // cir.try
1349 GlobalInit // cir.global initialization code
1350 };
1351 Kind scopeKind = Kind::Regular;
1352
1353 // The scope return value.
1354 mlir::Value retVal = nullptr;
1355
1356 mlir::Location beginLoc;
1357 mlir::Location endLoc;
1358
1359 public:
1360 unsigned depth = 0;
1361
1362 LexicalScope(CIRGenFunction &cgf, mlir::Location loc, mlir::Block *eb)
1363 : RunCleanupsScope(cgf), entryBlock(eb), parentScope(cgf.curLexScope),
1364 beginLoc(loc), endLoc(loc) {
1365
1366 assert(entryBlock && "LexicalScope requires an entry block");
1367 cgf.curLexScope = this;
1368 if (parentScope)
1369 ++depth;
1370
1371 if (const auto fusedLoc = mlir::dyn_cast<mlir::FusedLoc>(loc)) {
1372 assert(fusedLoc.getLocations().size() == 2 && "too many locations");
1373 beginLoc = fusedLoc.getLocations()[0];
1374 endLoc = fusedLoc.getLocations()[1];
1375 }
1376 }
1377
1378 void setRetVal(mlir::Value v) { retVal = v; }
1379
1380 void cleanup();
1381 void restore() { cgf.curLexScope = parentScope; }
1382
1385 cleanup();
1386 restore();
1387 }
1388
1389 // ---
1390 // Coroutine tracking
1391 // ---
1392 bool hasCoreturn() const { return hasCoreturnStmt; }
1393 void setCoreturn() { hasCoreturnStmt = true; }
1394
1395 // ---
1396 // Kind
1397 // ---
1398 bool isGlobalInit() { return scopeKind == Kind::GlobalInit; }
1399 bool isRegular() { return scopeKind == Kind::Regular; }
1400 bool isSwitch() { return scopeKind == Kind::Switch; }
1401 bool isTernary() { return scopeKind == Kind::Ternary; }
1402 bool isTry() { return scopeKind == Kind::Try; }
1403 cir::TryOp getClosestTryParent();
1404 void setAsGlobalInit() { scopeKind = Kind::GlobalInit; }
1405 void setAsSwitch() { scopeKind = Kind::Switch; }
1406 void setAsTernary() { scopeKind = Kind::Ternary; }
1407 void setAsTry(cir::TryOp op) {
1408 scopeKind = Kind::Try;
1409 tryOp = op;
1410 }
1411
1412 cir::TryOp getTry() {
1413 assert(isTry());
1414 return tryOp;
1415 }
1416
1417 // ---
1418 // Return handling.
1419 // ---
1420
1421 private:
1422 // On switches we need one return block per region, since cases don't
1423 // have their own scopes but are distinct regions nonetheless.
1424
1425 // TODO: This implementation should change once we have support for early
1426 // exits in MLIR structured control flow (llvm-project#161575)
1428 llvm::DenseMap<mlir::Block *, mlir::Location> retLocs;
1429 llvm::DenseMap<cir::CaseOp, unsigned> retBlockInCaseIndex;
1430 std::optional<unsigned> normalRetBlockIndex;
1431
1432 // There's usually only one ret block per scope, but this needs to be
1433 // get or create because of potential unreachable return statements, note
1434 // that for those, all source location maps to the first one found.
1435 mlir::Block *createRetBlock(CIRGenFunction &cgf, mlir::Location loc) {
1436 assert((isa_and_nonnull<cir::CaseOp>(
1437 cgf.builder.getBlock()->getParentOp()) ||
1438 retBlocks.size() == 0) &&
1439 "only switches can hold more than one ret block");
1440
1441 // Create the return block but don't hook it up just yet.
1442 mlir::OpBuilder::InsertionGuard guard(cgf.builder);
1443 auto *b = cgf.builder.createBlock(cgf.builder.getBlock()->getParent());
1444 retBlocks.push_back(b);
1445 updateRetLoc(b, loc);
1446 return b;
1447 }
1448
1449 cir::ReturnOp emitReturn(mlir::Location loc);
1450 void emitImplicitReturn();
1451
1452 public:
1454 mlir::Location getRetLoc(mlir::Block *b) { return retLocs.at(b); }
1455 void updateRetLoc(mlir::Block *b, mlir::Location loc) {
1456 retLocs.insert_or_assign(b, loc);
1457 }
1458
1459 mlir::Block *getOrCreateRetBlock(CIRGenFunction &cgf, mlir::Location loc) {
1460 // Check if we're inside a case region
1461 if (auto caseOp = mlir::dyn_cast_if_present<cir::CaseOp>(
1462 cgf.builder.getBlock()->getParentOp())) {
1463 auto iter = retBlockInCaseIndex.find(caseOp);
1464 if (iter != retBlockInCaseIndex.end()) {
1465 // Reuse existing return block
1466 mlir::Block *ret = retBlocks[iter->second];
1467 updateRetLoc(ret, loc);
1468 return ret;
1469 }
1470 // Create new return block
1471 mlir::Block *ret = createRetBlock(cgf, loc);
1472 retBlockInCaseIndex[caseOp] = retBlocks.size() - 1;
1473 return ret;
1474 }
1475
1476 if (normalRetBlockIndex) {
1477 mlir::Block *ret = retBlocks[*normalRetBlockIndex];
1478 updateRetLoc(ret, loc);
1479 return ret;
1480 }
1481
1482 mlir::Block *ret = createRetBlock(cgf, loc);
1483 normalRetBlockIndex = retBlocks.size() - 1;
1484 return ret;
1485 }
1486
1487 mlir::Block *getEntryBlock() { return entryBlock; }
1488 };
1489
1491
1493
1495 QualType type);
1496
1497 void pushDestroy(QualType::DestructionKind dtorKind, Address addr,
1498 QualType type);
1499
1501 Destroyer *destroyer);
1502
1504 QualType type, Destroyer *destroyer,
1505 bool useEHCleanupForArray);
1506
1508
1509 void pushIrregularPartialArrayCleanup(mlir::Value arrayBegin,
1510 Address arrayEndPointer,
1511 QualType elementType,
1512 CharUnits elementAlign,
1513 Destroyer *destroyer);
1514
1515 /// Start generating a thunk function.
1516 void startThunk(cir::FuncOp fn, GlobalDecl gd,
1517 const CIRGenFunctionInfo &fnInfo, bool isUnprototyped);
1518
1519 /// Finish generating a thunk function.
1520 void finishThunk();
1521
1522 /// Generate code for a thunk function.
1523 void generateThunk(cir::FuncOp fn, const CIRGenFunctionInfo &fnInfo,
1524 GlobalDecl gd, const ThunkInfo &thunk,
1525 bool isUnprototyped);
1526
1527 /// ----------------------
1528 /// CIR emit functions
1529 /// ----------------------
1530public:
1531 bool getAArch64SVEProcessedOperands(unsigned builtinID, const CallExpr *expr,
1533 clang::SVETypeFlags typeFlags);
1534 mlir::Value emitSVEPredicateCast(mlir::Value pred, unsigned minNumElts,
1535 mlir::Location loc);
1536 std::optional<mlir::Value>
1537 emitAArch64BuiltinExpr(unsigned builtinID, const CallExpr *expr,
1539 llvm::Triple::ArchType arch);
1540 std::optional<mlir::Value> emitAArch64SMEBuiltinExpr(unsigned builtinID,
1541 const CallExpr *expr);
1542 std::optional<mlir::Value> emitAArch64SVEBuiltinExpr(unsigned builtinID,
1543 const CallExpr *expr);
1544
1545 mlir::Value emitAlignmentAssumption(mlir::Value ptrValue, QualType ty,
1546 SourceLocation loc,
1547 SourceLocation assumptionLoc,
1548 int64_t alignment,
1549 mlir::Value offsetValue = nullptr);
1550
1551 mlir::Value emitAlignmentAssumption(mlir::Value ptrValue, const Expr *expr,
1552 SourceLocation assumptionLoc,
1553 int64_t alignment,
1554 mlir::Value offsetValue = nullptr);
1555
1556private:
1557 void emitAndUpdateRetAlloca(clang::QualType type, mlir::Location loc,
1558 clang::CharUnits alignment);
1559
1560 CIRGenCallee emitDirectCallee(const GlobalDecl &gd);
1561
1562public:
1564 llvm::StringRef fieldName,
1565 unsigned fieldIndex);
1566
1567 mlir::Value emitAlloca(llvm::StringRef name, mlir::Type ty,
1568 mlir::Location loc, clang::CharUnits alignment,
1569 bool insertIntoFnEntryBlock,
1570 mlir::Value arraySize = nullptr);
1571 mlir::Value emitAlloca(llvm::StringRef name, mlir::Type ty,
1572 mlir::Location loc, clang::CharUnits alignment,
1573 mlir::OpBuilder::InsertPoint ip,
1574 mlir::Value arraySize = nullptr);
1575
1576 void emitAggregateStore(mlir::Value value, Address dest);
1577
1578 void emitAggExpr(const clang::Expr *e, AggValueSlot slot);
1579
1581
1583
1584 /// Emit an aggregate copy.
1585 ///
1586 /// \param isVolatile \c true iff either the source or the destination is
1587 /// volatile.
1588 /// \param MayOverlap Whether the tail padding of the destination might be
1589 /// occupied by some other object. More efficient code can often be
1590 /// generated if not.
1591 void emitAggregateCopy(LValue dest, LValue src, QualType eltTy,
1592 AggValueSlot::Overlap_t mayOverlap,
1593 bool isVolatile = false);
1594
1595 /// Emit code to compute the specified expression which can have any type. The
1596 /// result is returned as an RValue struct. If this is an aggregate
1597 /// expression, the aggloc/agglocvolatile arguments indicate where the result
1598 /// should be returned.
1601 bool ignoreResult = false);
1602
1603 /// Emits the code necessary to evaluate an arbitrary expression into the
1604 /// given memory location.
1605 void emitAnyExprToMem(const Expr *e, Address location, Qualifiers quals,
1606 bool isInitializer);
1607
1608 /// Similarly to emitAnyExpr(), however, the result will always be accessible
1609 /// even if no aggregate location is provided.
1611
1612 void emitAnyExprToExn(const Expr *e, Address addr);
1613
1614 void emitArrayDestroy(mlir::Value begin, mlir::Value numElements,
1615 QualType elementType, CharUnits elementAlign,
1616 Destroyer *destroyer);
1617
1618 mlir::Value emitArrayLength(const clang::ArrayType *arrayType,
1619 QualType &baseType, Address &addr);
1622
1624
1626 LValueBaseInfo *baseInfo = nullptr);
1627
1628 std::pair<mlir::Value, mlir::Type>
1630 QualType inputType, std::string &constraintString,
1631 SourceLocation loc);
1632 std::pair<mlir::Value, mlir::Type>
1633 emitAsmInput(const TargetInfo::ConstraintInfo &info, const Expr *inputExpr,
1634 std::string &constraintString);
1635 mlir::LogicalResult emitAsmStmt(const clang::AsmStmt &s);
1636
1638 void emitAtomicInit(Expr *init, LValue dest);
1639 void emitAtomicStore(RValue rvalue, LValue dest, bool isInit);
1640 void emitAtomicStore(RValue rvalue, LValue dest, cir::MemOrder order,
1641 bool isVolatile, bool isInit);
1643 const Expr *memOrder, bool isStore, bool isLoad, bool isFence,
1644 llvm::function_ref<void(cir::MemOrder)> emitAtomicOp);
1645
1646 mlir::LogicalResult emitAttributedStmt(const AttributedStmt &s);
1647
1648 AutoVarEmission emitAutoVarAlloca(const clang::VarDecl &d,
1649 mlir::OpBuilder::InsertPoint ip = {});
1650
1652 AggValueSlot slot = AggValueSlot::ignored());
1654
1655 /// Emit code and set up symbol table for a variable declaration with auto,
1656 /// register, or no storage class specifier. These turn into simple stack
1657 /// objects, globals depending on target.
1658 void emitAutoVarDecl(const clang::VarDecl &d);
1659
1660 void emitAutoVarCleanups(const AutoVarEmission &emission);
1661 /// Emit the initializer for an allocated variable. If this call is not
1662 /// associated with the call to emitAutoVarAlloca (as the address of the
1663 /// emission is not directly an alloca), the allocatedSeparately parameter can
1664 /// be used to suppress the assertions. However, this should only be used in
1665 /// extreme cases, as it doesn't properly reflect the language/AST.
1666 void emitAutoVarInit(const AutoVarEmission &emission);
1667 void emitAutoVarTypeCleanup(const AutoVarEmission &emission,
1669
1670 void maybeEmitDeferredVarDeclInit(const VarDecl *vd);
1671
1672 void emitBaseInitializer(mlir::Location loc, const CXXRecordDecl *classDecl,
1673 CXXCtorInitializer *baseInit);
1674
1676
1677 mlir::LogicalResult emitBreakStmt(const clang::BreakStmt &s);
1678
1679 RValue emitBuiltinExpr(const clang::GlobalDecl &gd, unsigned builtinID,
1680 const clang::CallExpr *e, ReturnValueSlot returnValue);
1681
1682 /// Returns a Value corresponding to the size of the given expression by
1683 /// emitting a `cir.objsize` operation.
1684 ///
1685 /// \param e The expression whose object size to compute
1686 /// \param type Determines the semantics of the object size computation.
1687 /// The type parameter is a 2-bit value where:
1688 /// bit 0 (type & 1): 0 = whole object, 1 = closest subobject
1689 /// bit 1 (type & 2): 0 = maximum size, 2 = minimum size
1690 /// \param resType The result type for the size value
1691 /// \param emittedE Optional pre-emitted pointer value. If non-null, we'll
1692 /// call `cir.objsize` on this value rather than emitting e.
1693 /// \param isDynamic If true, allows runtime evaluation via dynamic mode
1694 mlir::Value emitBuiltinObjectSize(const clang::Expr *e, unsigned type,
1695 cir::IntType resType, mlir::Value emittedE,
1696 bool isDynamic);
1697
1698 mlir::Value evaluateOrEmitBuiltinObjectSize(const clang::Expr *e,
1699 unsigned type,
1700 cir::IntType resType,
1701 mlir::Value emittedE,
1702 bool isDynamic);
1703
1704 int64_t getAccessedFieldNo(unsigned idx, mlir::ArrayAttr elts);
1705
1707
1708 /// Emit a simple LLVM intrinsic that takes N scalar arguments and whose
1709 /// return type matches the type of the first argument. The intrinsic name is
1710 /// used verbatim; any overload mangling (e.g. `.f32`, `.p1`) must be baked
1711 /// into \p intrinName by the caller.
1712 template <unsigned N>
1713 [[maybe_unused]] RValue
1715 llvm::StringRef intrinName) {
1716 static_assert(N, "expect non-empty argument");
1717 mlir::Type cirTy = convertType(e->getArg(0)->getType());
1719 for (unsigned i = 0; i < N; ++i)
1720 args.push_back(emitScalarExpr(e->getArg(i)));
1721 const auto call = cir::LLVMIntrinsicCallOp::create(
1722 builder, getLoc(e->getExprLoc()), builder.getStringAttr(intrinName),
1723 cirTy, args);
1724 return RValue::get(call->getResult(0));
1725 }
1726
1727 RValue emitCall(const CIRGenFunctionInfo &funcInfo,
1729 const CallArgList &args, cir::CIRCallOpInterface *callOp,
1730 mlir::Location loc);
1733 const CallArgList &args,
1734 cir::CIRCallOpInterface *callOrTryCall = nullptr) {
1735 assert(currSrcLoc && "source location must have been set");
1736 return emitCall(funcInfo, callee, returnValue, args, callOrTryCall,
1737 *currSrcLoc);
1738 }
1739
1740 RValue emitCall(clang::QualType calleeTy, const CIRGenCallee &callee,
1742
1743 /// Emit the call and return for a thunk function.
1744 void emitCallAndReturnForThunk(cir::FuncOp callee, const ThunkInfo *thunk,
1745 bool isUnprototyped);
1746
1747 void emitCallArg(CallArgList &args, const clang::Expr *e,
1748 clang::QualType argType);
1749 void emitCallArgs(
1750 CallArgList &args, PrototypeWrapper prototype,
1751 llvm::iterator_range<clang::CallExpr::const_arg_iterator> argRange,
1752 AbstractCallee callee = AbstractCallee(), unsigned paramsToSkip = 0);
1756
1760
1761 template <typename T>
1762 mlir::LogicalResult emitCaseDefaultCascade(const T *stmt, mlir::Type condType,
1763 mlir::ArrayAttr value,
1764 cir::CaseOpKind kind,
1765 bool buildingTopLevelCase);
1766
1768
1769 mlir::LogicalResult emitCaseStmt(const clang::CaseStmt &s,
1770 mlir::Type condType,
1771 bool buildingTopLevelCase);
1772
1773 LValue emitCastLValue(const CastExpr *e);
1774
1775 /// Emits an argument for a call to a `__builtin_assume`. If the builtin
1776 /// sanitizer is enabled, a runtime check is also emitted.
1777 mlir::Value emitCheckedArgForAssume(const Expr *e);
1778
1779 /// Emit a conversion from the specified complex type to the specified
1780 /// destination type, where the destination type is an LLVM scalar type.
1781 mlir::Value emitComplexToScalarConversion(mlir::Value src, QualType srcTy,
1782 QualType dstTy, SourceLocation loc);
1783
1786
1788
1789 mlir::LogicalResult emitCoroutineBody(const CoroutineBodyStmt &s);
1790 cir::CallOp emitCoroEndBuiltinCall(mlir::Location loc, mlir::Value nullPtr);
1791 cir::CallOp emitCoroIDBuiltinCall(mlir::Location loc, mlir::Value nullPtr);
1792 cir::CallOp emitCoroAllocBuiltinCall(mlir::Location loc);
1793 cir::CallOp emitCoroBeginBuiltinCall(mlir::Location loc,
1794 mlir::Value coroframeAddr);
1795
1796 cir::CallOp emitCoroFreeBuiltin(const CallExpr *e);
1798
1799 void emitDestroy(Address addr, QualType type, Destroyer *destroyer);
1800
1802
1803 mlir::LogicalResult emitContinueStmt(const clang::ContinueStmt &s);
1804
1805 mlir::LogicalResult emitCoreturnStmt(const CoreturnStmt &s);
1806
1808 AggValueSlot dest);
1809
1812 Address arrayBegin, const CXXConstructExpr *e,
1813 bool newPointerIsChecked,
1814 bool zeroInitialize = false);
1816 mlir::Value numElements, Address arrayBase,
1817 const CXXConstructExpr *e,
1818 bool newPointerIsChecked, bool zeroInitialize,
1819 Address endOfInit);
1821 clang::CXXCtorType type, bool forVirtualBase,
1822 bool delegating, AggValueSlot thisAVS,
1823 const clang::CXXConstructExpr *e);
1824
1826 clang::CXXCtorType type, bool forVirtualBase,
1827 bool delegating, Address thisAddr,
1829
1831 bool forVirtualBase, Address thisAddr,
1832 bool inheritedFromVBase,
1833 const CXXInheritedCtorInitExpr *e);
1834
1836 SourceLocation loc, const CXXConstructorDecl *d, CXXCtorType ctorType,
1837 bool forVirtualBase, bool delegating, CallArgList &args);
1838
1839 void emitCXXDeleteExpr(const CXXDeleteExpr *e);
1840
1842 bool forVirtualBase, bool delegating,
1843 Address thisAddr, QualType thisTy);
1844
1846 mlir::Value thisVal, QualType thisTy,
1847 mlir::Value implicitParam,
1848 QualType implicitParamTy, const CallExpr *e);
1849
1850 mlir::LogicalResult emitCXXForRangeStmt(const CXXForRangeStmt &s,
1852
1855
1857 const Expr *e, Address base, mlir::Value memberPtr,
1858 const MemberPointerType *memberPtrType, LValueBaseInfo *baseInfo);
1859
1861 const clang::CXXMethodDecl *md, const CIRGenCallee &callee,
1862 ReturnValueSlot returnValue, mlir::Value thisPtr,
1863 mlir::Value implicitParam, clang::QualType implicitParamTy,
1864 const clang::CallExpr *ce, CallArgList *rtlArgs);
1865
1867 const clang::CallExpr *ce, const clang::CXXMethodDecl *md,
1868 ReturnValueSlot returnValue, bool hasQualifier,
1869 clang::NestedNameSpecifier qualifier, bool isArrow,
1870 const clang::Expr *base);
1871
1874
1875 mlir::Value emitCXXNewExpr(const CXXNewExpr *e);
1876
1877 void emitNewArrayInitializer(const CXXNewExpr *e, QualType elementType,
1878 mlir::Type elementTy, Address beginPtr,
1879 mlir::Value numElements,
1880 mlir::Value allocSizeWithoutCookie);
1881
1882 /// Create a check for a function parameter that may potentially be
1883 /// declared as non-null.
1884 void emitNonNullArgCheck(RValue rv, QualType argType, SourceLocation argLoc,
1885 AbstractCallee ac, unsigned paramNum);
1886
1888 const CXXMethodDecl *md,
1890
1893
1895
1897 const CallExpr *callExpr,
1899
1900 void emitCXXTemporary(const CXXTemporary *temporary, QualType tempType,
1901 Address ptr);
1902
1903 void emitCXXThrowExpr(const CXXThrowExpr *e);
1904
1906 virtual mlir::LogicalResult operator()(CIRGenFunction &cgf) = 0;
1907 virtual ~cxxTryBodyEmitter() = default;
1908 };
1909
1910 void emitBeginCatch(const CXXCatchStmt *catchStmt, mlir::Value ehToken);
1911
1912 mlir::LogicalResult emitCXXTryStmt(const clang::CXXTryStmt &s,
1913 cxxTryBodyEmitter &bodyCallback);
1914 mlir::LogicalResult emitCXXTryStmt(const clang::CXXTryStmt &s);
1915
1917 clang::CXXCtorType ctorType, FunctionArgList &args);
1918
1919 // It's important not to confuse this and emitDelegateCXXConstructorCall.
1920 // Delegating constructors are the C++11 feature. The constructor delegate
1921 // optimization is used to reduce duplication in the base and complete
1922 // constructors where they are substantially the same.
1924 const FunctionArgList &args);
1925
1926 void emitDeleteCall(const FunctionDecl *deleteFD, mlir::Value ptr,
1927 QualType deleteTy);
1928
1929 mlir::LogicalResult emitDoStmt(const clang::DoStmt &s);
1930
1931 mlir::Value emitCXXTypeidExpr(const CXXTypeidExpr *e);
1932 mlir::Value emitDynamicCast(Address thisAddr, const CXXDynamicCastExpr *dce);
1933
1934 /// Emit an expression as an initializer for an object (variable, field, etc.)
1935 /// at the given location. The expression is not necessarily the normal
1936 /// initializer for the object, and the address is not necessarily
1937 /// its normal location.
1938 ///
1939 /// \param init the initializing expression
1940 /// \param d the object to act as if we're initializing
1941 /// \param lvalue the lvalue to initialize
1942 /// \param capturedByInit true if \p d is a __block variable whose address is
1943 /// potentially changed by the initializer
1944 void emitExprAsInit(const clang::Expr *init, const clang::ValueDecl *d,
1945 LValue lvalue, bool capturedByInit = false);
1946
1947 mlir::LogicalResult emitFunctionBody(const clang::Stmt *body);
1948
1949 mlir::LogicalResult emitGotoStmt(const clang::GotoStmt &s);
1950
1951 mlir::LogicalResult emitIndirectGotoStmt(const IndirectGotoStmt &s);
1952
1954
1956 clang::Expr *init);
1957
1959
1960 mlir::Value emitPromotedComplexExpr(const Expr *e, QualType promotionType);
1961
1962 mlir::Value emitPromotedScalarExpr(const Expr *e, QualType promotionType);
1963
1964 mlir::Value emitPromotedValue(mlir::Value result, QualType promotionType);
1965
1966 void emitReturnOfRValue(mlir::Location loc, RValue rv, QualType ty);
1967
1968 mlir::Value emitRuntimeCall(mlir::Location loc, cir::FuncOp callee,
1970 mlir::NamedAttrList attrs = {});
1971
1972 void emitInvariantStart(CharUnits size, mlir::Value addr, mlir::Location loc);
1973
1974 /// Emit the computation of the specified expression of scalar type.
1975 mlir::Value emitScalarExpr(const clang::Expr *e,
1976 bool ignoreResultAssign = false);
1977
1978 mlir::Value emitScalarPrePostIncDec(const UnaryOperator *e, LValue lv);
1979
1980 /// Build a debug stoppoint if we are emitting debug info.
1981 void emitStopPoint(const Stmt *s);
1982
1983 // Build CIR for a statement. useCurrentScope should be true if no
1984 // new scopes need be created when finding a compound statement.
1985 mlir::LogicalResult emitStmt(const clang::Stmt *s, bool useCurrentScope,
1986 llvm::ArrayRef<const Attr *> attrs = {});
1987
1988 mlir::LogicalResult emitSimpleStmt(const clang::Stmt *s,
1989 bool useCurrentScope);
1990
1991 mlir::LogicalResult emitForStmt(const clang::ForStmt &s);
1992
1993 void emitForwardingCallToLambda(const CXXMethodDecl *lambdaCallOperator,
1994 CallArgList &callArgs);
1995
1996 RValue emitCoawaitExpr(const CoawaitExpr &e,
1997 AggValueSlot aggSlot = AggValueSlot::ignored(),
1998 bool ignoreResult = false);
1999
2000 RValue emitCoyieldExpr(const CoyieldExpr &e,
2001 AggValueSlot aggSlot = AggValueSlot::ignored(),
2002 bool ignoreResult = false);
2003 /// Emit the computation of the specified expression of complex type,
2004 /// returning the result.
2005 mlir::Value emitComplexExpr(const Expr *e);
2006
2007 void emitComplexExprIntoLValue(const Expr *e, LValue dest, bool isInit);
2008
2009 mlir::Value emitComplexPrePostIncDec(const UnaryOperator *e, LValue lv);
2010
2011 LValue emitComplexAssignmentLValue(const BinaryOperator *e);
2012 LValue emitComplexCompoundAssignmentLValue(const CompoundAssignOperator *e);
2013 LValue emitScalarCompoundAssignWithComplex(const CompoundAssignOperator *e,
2014 mlir::Value &result);
2015
2016 mlir::LogicalResult
2017 emitCompoundStmt(const clang::CompoundStmt &s, Address *lastValue = nullptr,
2018 AggValueSlot slot = AggValueSlot::ignored());
2019
2020 mlir::LogicalResult
2022 Address *lastValue = nullptr,
2023 AggValueSlot slot = AggValueSlot::ignored());
2024
2025 void emitDecl(const clang::Decl &d, bool evaluateConditionDecl = false);
2026 mlir::LogicalResult emitDeclStmt(const clang::DeclStmt &s);
2027 LValue emitDeclRefLValue(const clang::DeclRefExpr *e);
2028
2029 mlir::LogicalResult emitDefaultStmt(const clang::DefaultStmt &s,
2030 mlir::Type condType,
2031 bool buildingTopLevelCase);
2032
2034 clang::CXXCtorType ctorType,
2035 const FunctionArgList &args,
2037
2038 /// We are performing a delegate call; that is, the current function is
2039 /// delegating to another one. Produce a r-value suitable for passing the
2040 /// given parameter.
2041 void emitDelegateCallArg(CallArgList &args, const clang::VarDecl *param,
2043
2044 /// Emit an `if` on a boolean condition to the specified blocks.
2045 /// FIXME: Based on the condition, this might try to simplify the codegen of
2046 /// the conditional based on the branch.
2047 /// In the future, we may apply code generation simplifications here,
2048 /// similar to those used in classic LLVM codegen
2049 /// See `EmitBranchOnBoolExpr` for inspiration.
2050 mlir::LogicalResult emitIfOnBoolExpr(const clang::Expr *cond,
2051 const clang::Stmt *thenS,
2052 const clang::Stmt *elseS);
2053 cir::IfOp emitIfOnBoolExpr(const clang::Expr *cond,
2054 BuilderCallbackRef thenBuilder,
2055 mlir::Location thenLoc,
2056 BuilderCallbackRef elseBuilder,
2057 std::optional<mlir::Location> elseLoc = {});
2058
2059 mlir::Value emitOpOnBoolExpr(mlir::Location loc, const clang::Expr *cond);
2060
2061 LValue emitPointerToDataMemberBinaryExpr(const BinaryOperator *e);
2062
2063 mlir::LogicalResult emitLabel(const clang::LabelDecl &d);
2064 mlir::LogicalResult emitLabelStmt(const clang::LabelStmt &s);
2065
2066 void emitLambdaDelegatingInvokeBody(const CXXMethodDecl *md);
2067 void emitLambdaStaticInvokeBody(const CXXMethodDecl *md);
2068
2069 mlir::LogicalResult emitIfStmt(const clang::IfStmt &s);
2070
2071 /// Emit code to compute the specified expression,
2072 /// ignoring the result.
2073 void emitIgnoredExpr(const clang::Expr *e);
2074
2075 RValue emitLoadOfBitfieldLValue(LValue lv, SourceLocation loc);
2076
2077 /// Load a complex number from the specified l-value.
2078 mlir::Value emitLoadOfComplex(LValue src, SourceLocation loc);
2079
2080 RValue emitLoadOfExtVectorElementLValue(LValue lv);
2081
2082 /// Given an expression that represents a value lvalue, this method emits
2083 /// the address of the lvalue, then loads the result as an rvalue,
2084 /// returning the rvalue.
2085 RValue emitLoadOfLValue(LValue lv, SourceLocation loc);
2086
2087 Address emitLoadOfReference(LValue refLVal, mlir::Location loc,
2088 LValueBaseInfo *pointeeBaseInfo);
2089 LValue emitLoadOfReferenceLValue(Address refAddr, mlir::Location loc,
2090 QualType refTy, AlignmentSource source);
2091
2092 /// EmitLoadOfScalar - Load a scalar value from an address, taking
2093 /// care to appropriately convert from the memory representation to
2094 /// the LLVM value representation. The l-value must be a simple
2095 /// l-value.
2096 mlir::Value emitLoadOfScalar(LValue lvalue, SourceLocation loc);
2097 mlir::Value emitLoadOfScalar(Address addr, bool isVolatile, QualType ty,
2098 SourceLocation loc, LValueBaseInfo baseInfo);
2099
2100 /// Emit code to compute a designator that specifies the location
2101 /// of the expression.
2102 /// FIXME: document this function better.
2103 LValue emitLValue(const clang::Expr *e);
2104 LValue emitLValueForBitField(LValue base, const FieldDecl *field);
2105 LValue emitLValueForField(LValue base, const clang::FieldDecl *field);
2106
2107 LValue emitLValueForLambdaField(const FieldDecl *field);
2108 LValue emitLValueForLambdaField(const FieldDecl *field,
2109 mlir::Value thisValue);
2110
2111 /// Like emitLValueForField, excpet that if the Field is a reference, this
2112 /// will return the address of the reference and not the address of the value
2113 /// stored in the reference.
2114 LValue emitLValueForFieldInitialization(LValue base,
2115 const clang::FieldDecl *field,
2116 llvm::StringRef fieldName);
2117
2118 LValue emitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *e);
2119
2120 LValue emitMemberExpr(const MemberExpr *e);
2121
2122 /// Emit a musttail call for a thunk with a potentially different ABI.
2123 void emitMustTailThunk(GlobalDecl gd, mlir::Value adjustedThisPtr,
2124 cir::FuncOp callee);
2125
2126 /// Emit a call to an AMDGPU builtin function.
2127 std::optional<mlir::Value> emitAMDGPUBuiltinExpr(unsigned builtinID,
2128 const CallExpr *expr);
2129
2130 /// Emit a call to an NVPTX builtin function.
2131 std::optional<mlir::Value> emitNVPTXBuiltinExpr(unsigned builtinID,
2132 const CallExpr *expr);
2133
2134 /// Emit a device-side printf call for NVPTX targets.
2135 mlir::Value emitNVPTXDevicePrintfCallExpr(const CallExpr *expr);
2136
2137 LValue emitOpaqueValueLValue(const OpaqueValueExpr *e);
2138
2139 LValue emitConditionalOperatorLValue(const AbstractConditionalOperator *expr);
2140
2141 /// Given an expression with a pointer type, emit the value and compute our
2142 /// best estimate of the alignment of the pointee.
2143 ///
2144 /// One reasonable way to use this information is when there's a language
2145 /// guarantee that the pointer must be aligned to some stricter value, and
2146 /// we're simply trying to ensure that sufficiently obvious uses of under-
2147 /// aligned objects don't get miscompiled; for example, a placement new
2148 /// into the address of a local variable. In such a case, it's quite
2149 /// reasonable to just ignore the returned alignment when it isn't from an
2150 /// explicit source.
2151 Address emitPointerWithAlignment(const clang::Expr *expr,
2152 LValueBaseInfo *baseInfo = nullptr);
2153
2154 /// Emits a reference binding to the passed in expression.
2155 RValue emitReferenceBindingToExpr(const Expr *e);
2156
2157 mlir::LogicalResult emitReturnStmt(const clang::ReturnStmt &s);
2158
2159 RValue emitRotate(const CallExpr *e, bool isRotateLeft);
2160
2161 mlir::Value emitScalarConstant(const ConstantEmission &constant, Expr *e);
2162
2163 /// Emit a conversion from the specified type to the specified destination
2164 /// type, both of which are CIR scalar types.
2165 mlir::Value emitScalarConversion(mlir::Value src, clang::QualType srcType,
2166 clang::QualType dstType,
2167 clang::SourceLocation loc);
2168
2169 void emitScalarInit(const clang::Expr *init, mlir::Location loc,
2170 LValue lvalue, bool capturedByInit = false);
2171
2172 mlir::Value emitScalarOrConstFoldImmArg(unsigned iceArguments, unsigned idx,
2173 const Expr *argExpr);
2174
2175 void emitStaticVarDecl(const VarDecl &d, cir::GlobalLinkageKind linkage);
2176
2177 /// Emit a guarded initializer for a static local variable.
2178 void emitCXXGuardedInit(const VarDecl &varDecl, cir::GlobalOp globalOp,
2179 bool performInit);
2180
2181 void emitStoreOfComplex(mlir::Location loc, mlir::Value v, LValue dest,
2182 bool isInit);
2183
2184 void emitStoreOfScalar(mlir::Value value, Address addr, bool isVolatile,
2185 clang::QualType ty, LValueBaseInfo baseInfo,
2186 bool isInit = false, bool isNontemporal = false);
2187 void emitStoreOfScalar(mlir::Value value, LValue lvalue, bool isInit);
2188
2189 void emitStoreThroughExtVectorComponentLValue(RValue src, LValue dst);
2190
2191 /// Store the specified rvalue into the specified
2192 /// lvalue, where both are guaranteed to the have the same type, and that
2193 /// type is 'Ty'.
2194 void emitStoreThroughLValue(RValue src, LValue dst, bool isInit = false);
2195
2196 mlir::Value emitStoreThroughBitfieldLValue(RValue src, LValue dstresult);
2197
2198 LValue emitStringLiteralLValue(const StringLiteral *e,
2199 llvm::StringRef name = ".str");
2200
2201 mlir::LogicalResult emitSwitchBody(const clang::Stmt *s);
2202 mlir::LogicalResult emitSwitchCase(const clang::SwitchCase &s,
2203 bool buildingTopLevelCase);
2204 mlir::LogicalResult emitSwitchStmt(const clang::SwitchStmt &s);
2205
2206 std::optional<mlir::Value>
2207 emitTargetBuiltinExpr(unsigned builtinID, const clang::CallExpr *e,
2208 ReturnValueSlot &returnValue);
2209
2210 /// Given a value and its clang type, returns the value casted to its memory
2211 /// representation.
2212 /// Note: CIR defers most of the special casting to the final lowering passes
2213 /// to conserve the high level information.
2214 mlir::Value emitToMemory(mlir::Value value, clang::QualType ty);
2215
2216 /// EmitFromMemory - Change a scalar value from its memory
2217 /// representation to its value representation.
2218 mlir::Value emitFromMemory(mlir::Value value, clang::QualType ty);
2219
2220 /// Emit a trap instruction, which is used to abort the program in an abnormal
2221 /// way, usually for debugging purposes.
2222 /// \p createNewBlock indicates whether to create a new block for the IR
2223 /// builder. Since the `cir.trap` operation is a terminator, operations that
2224 /// follow a trap cannot be emitted after `cir.trap` in the same block. To
2225 /// ensure these operations get emitted successfully, you need to create a new
2226 /// dummy block and set the insertion point there before continuing from the
2227 /// trap operation.
2228 void emitTrap(mlir::Location loc, bool createNewBlock);
2229
2230 LValue emitUnaryOpLValue(const clang::UnaryOperator *e);
2231
2232 mlir::Value emitUnPromotedValue(mlir::Value result, QualType unPromotionType);
2233
2234 /// Emit a reached-unreachable diagnostic if \p loc is valid and runtime
2235 /// checking is enabled. Otherwise, just emit an unreachable instruction.
2236 /// \p createNewBlock indicates whether to create a new block for the IR
2237 /// builder. Since the `cir.unreachable` operation is a terminator, operations
2238 /// that follow an unreachable point cannot be emitted after `cir.unreachable`
2239 /// in the same block. To ensure these operations get emitted successfully,
2240 /// you need to create a dummy block and set the insertion point there before
2241 /// continuing from the unreachable point.
2242 void emitUnreachable(clang::SourceLocation loc, bool createNewBlock);
2243
2244 /// This method handles emission of any variable declaration
2245 /// inside a function, including static vars etc.
2246 void emitVarDecl(const clang::VarDecl &d);
2247
2248 void emitVariablyModifiedType(QualType ty);
2249
2250 mlir::LogicalResult emitWhileStmt(const clang::WhileStmt &s);
2251
2252 std::optional<mlir::Value> emitRISCVBuiltinExpr(unsigned builtinID,
2253 const CallExpr *expr);
2254
2255 std::optional<mlir::Value> emitX86BuiltinExpr(unsigned builtinID,
2256 const CallExpr *expr);
2257
2258 /// Given an assignment `*lhs = rhs`, emit a test that checks if \p rhs is
2259 /// nonnull, if 1\p LHS is marked _Nonnull.
2260 void emitNullabilityCheck(LValue lhs, mlir::Value rhs,
2261 clang::SourceLocation loc);
2262
2263 /// An object to manage conditionally-evaluated expressions.
2265 CIRGenFunction &cgf;
2266 mlir::OpBuilder::InsertPoint insertPt;
2267
2268 public:
2270 : cgf(cgf), insertPt(cgf.builder.saveInsertionPoint()) {}
2271 ConditionalEvaluation(CIRGenFunction &cgf, mlir::OpBuilder::InsertPoint ip)
2272 : cgf(cgf), insertPt(ip) {}
2273
2275 assert(cgf.outermostConditional != this);
2276 if (!cgf.outermostConditional)
2277 cgf.outermostConditional = this;
2278 }
2279
2281 assert(cgf.outermostConditional != nullptr);
2282 if (cgf.outermostConditional == this)
2283 cgf.outermostConditional = nullptr;
2284 }
2285
2286 /// Returns the insertion point which will be executed prior to each
2287 /// evaluation of the conditional code. In LLVM OG, this method
2288 /// is called getStartingBlock.
2289 mlir::OpBuilder::InsertPoint getInsertPoint() const { return insertPt; }
2290 };
2291
2293 std::optional<LValue> lhs{}, rhs{};
2294 mlir::Value result{};
2295 };
2296
2297 // Return true if we're currently emitting one branch or the other of a
2298 // conditional expression.
2299 bool isInConditionalBranch() const { return outermostConditional != nullptr; }
2300
2301 void setBeforeOutermostConditional(mlir::Value value, Address addr) {
2302 assert(isInConditionalBranch());
2303 {
2304 mlir::OpBuilder::InsertionGuard guard(builder);
2305 builder.restoreInsertionPoint(outermostConditional->getInsertPoint());
2306 builder.createStore(
2307 value.getLoc(), value, addr, /*isVolatile=*/false,
2308 mlir::IntegerAttr::get(
2309 mlir::IntegerType::get(value.getContext(), 64),
2310 (uint64_t)addr.getAlignment().getAsAlign().value()));
2311 }
2312 }
2313
2314 // Points to the outermost active conditional control. This is used so that
2315 // we know if a temporary should be destroyed conditionally.
2317
2318 /// An RAII object to record that we're evaluating a statement
2319 /// expression.
2321 CIRGenFunction &cgf;
2322
2323 /// We have to save the outermost conditional: cleanups in a
2324 /// statement expression aren't conditional just because the
2325 /// StmtExpr is.
2326 ConditionalEvaluation *savedOutermostConditional;
2327
2328 public:
2330 : cgf(cgf), savedOutermostConditional(cgf.outermostConditional) {
2331 cgf.outermostConditional = nullptr;
2332 }
2333
2335 cgf.outermostConditional = savedOutermostConditional;
2336 }
2337 };
2338
2339 template <typename FuncTy>
2340 ConditionalInfo emitConditionalBlocks(const AbstractConditionalOperator *e,
2341 const FuncTy &branchGenFunc);
2342
2343 mlir::Value emitTernaryOnBoolExpr(const clang::Expr *cond, mlir::Location loc,
2344 const clang::Stmt *thenS,
2345 const clang::Stmt *elseS);
2346
2347 /// Build a "reference" to a va_list; this is either the address or the value
2348 /// of the expression, depending on how va_list is defined.
2349 Address emitVAListRef(const Expr *e);
2350
2351 /// Emits the start of a CIR variable-argument operation (`cir.va_start`)
2352 ///
2353 /// \param vaList A reference to the \c va_list as emitted by either
2354 /// \c emitVAListRef or \c emitMSVAListRef.
2355 void emitVAStart(mlir::Value vaList);
2356
2357 /// Emits the end of a CIR variable-argument operation (`cir.va_start`)
2358 ///
2359 /// \param vaList A reference to the \c va_list as emitted by either
2360 /// \c emitVAListRef or \c emitMSVAListRef.
2361 void emitVAEnd(mlir::Value vaList);
2362
2363 /// Generate code to get an argument from the passed in pointer
2364 /// and update it accordingly.
2365 ///
2366 /// \param ve The \c VAArgExpr for which to generate code.
2367 ///
2368 /// \param vaListAddr Receives a reference to the \c va_list as emitted by
2369 /// either \c emitVAListRef or \c emitMSVAListRef.
2370 ///
2371 /// \returns SSA value with the argument.
2372 mlir::Value emitVAArg(VAArgExpr *ve);
2373
2374 /// ----------------------
2375 /// CIR build helpers
2376 /// -----------------
2377public:
2378 cir::AllocaOp createTempAlloca(mlir::Type ty, mlir::Location loc,
2379 const Twine &name = "tmp",
2380 mlir::Value arraySize = nullptr,
2381 bool insertIntoFnEntryBlock = false);
2382 cir::AllocaOp createTempAlloca(mlir::Type ty, mlir::Location loc,
2383 const Twine &name = "tmp",
2384 mlir::OpBuilder::InsertPoint ip = {},
2385 mlir::Value arraySize = nullptr);
2386 Address createTempAlloca(mlir::Type ty, CharUnits align, mlir::Location loc,
2387 const Twine &name = "tmp",
2388 mlir::Value arraySize = nullptr,
2389 Address *alloca = nullptr,
2390 mlir::OpBuilder::InsertPoint ip = {});
2391 Address createTempAlloca(mlir::Type ty,
2392 mlir::ptr::MemorySpaceAttrInterface destAddrSpace,
2393 CharUnits align, mlir::Location loc,
2394 const Twine &name = "tmp",
2395 mlir::Value arraySize = nullptr,
2396 Address *alloca = nullptr,
2397 mlir::OpBuilder::InsertPoint ip = {});
2398 Address createTempAllocaWithoutCast(mlir::Type ty, CharUnits align,
2399 mlir::Location loc,
2400 const Twine &name = "tmp",
2401 mlir::Value arraySize = nullptr,
2402 mlir::OpBuilder::InsertPoint ip = {});
2403 Address
2404 maybeCastStackAddressSpace(Address alloca,
2405 mlir::ptr::MemorySpaceAttrInterface destAddrSpace,
2406 mlir::Value arraySize);
2407 Address createDefaultAlignTempAlloca(mlir::Type ty, mlir::Location loc,
2408 const Twine &name);
2409
2410 /// Create a temporary memory object of the given type, with
2411 /// appropriate alignmen and cast it to the default address space. Returns
2412 /// the original alloca instruction by \p Alloca if it is not nullptr.
2413 Address createMemTemp(QualType t, mlir::Location loc,
2414 const Twine &name = "tmp", Address *alloca = nullptr,
2415 mlir::OpBuilder::InsertPoint ip = {});
2416 Address createMemTemp(QualType t, CharUnits align, mlir::Location loc,
2417 const Twine &name = "tmp", Address *alloca = nullptr,
2418 mlir::OpBuilder::InsertPoint ip = {});
2419 Address createMemTempWithoutCast(QualType t, mlir::Location loc,
2420 const Twine &name = "tmp");
2421
2422 mlir::Value performAddrSpaceCast(mlir::Value v, mlir::Type destTy) const {
2423 if (cir::GlobalOp globalOp = v.getDefiningOp<cir::GlobalOp>())
2424 cgm.errorNYI("Global op addrspace cast");
2425 return builder.createAddrSpaceCast(v, destTy);
2426 }
2427
2428 //===--------------------------------------------------------------------===//
2429 // OpenMP Emission
2430 //===--------------------------------------------------------------------===//
2431public:
2432 mlir::LogicalResult emitOMPScopeDirective(const OMPScopeDirective &s);
2433 mlir::LogicalResult emitOMPErrorDirective(const OMPErrorDirective &s);
2434 mlir::LogicalResult emitOMPParallelDirective(const OMPParallelDirective &s);
2435 mlir::LogicalResult emitOMPTaskwaitDirective(const OMPTaskwaitDirective &s);
2436 mlir::LogicalResult emitOMPTaskyieldDirective(const OMPTaskyieldDirective &s);
2437 mlir::LogicalResult emitOMPBarrierDirective(const OMPBarrierDirective &s);
2438 mlir::LogicalResult emitOMPMetaDirective(const OMPMetaDirective &s);
2439 mlir::LogicalResult emitOMPCanonicalLoop(const OMPCanonicalLoop &s);
2440 mlir::LogicalResult emitOMPSimdDirective(const OMPSimdDirective &s);
2441 mlir::LogicalResult emitOMPTileDirective(const OMPTileDirective &s);
2442 mlir::LogicalResult emitOMPUnrollDirective(const OMPUnrollDirective &s);
2443 mlir::LogicalResult emitOMPFuseDirective(const OMPFuseDirective &s);
2444 mlir::LogicalResult emitOMPForDirective(const OMPForDirective &s);
2445 mlir::LogicalResult emitOMPForSimdDirective(const OMPForSimdDirective &s);
2446 mlir::LogicalResult emitOMPSectionsDirective(const OMPSectionsDirective &s);
2447 mlir::LogicalResult emitOMPSectionDirective(const OMPSectionDirective &s);
2448 mlir::LogicalResult emitOMPSingleDirective(const OMPSingleDirective &s);
2449 mlir::LogicalResult emitOMPMasterDirective(const OMPMasterDirective &s);
2450 mlir::LogicalResult emitOMPCriticalDirective(const OMPCriticalDirective &s);
2451 mlir::LogicalResult
2452 emitOMPParallelForDirective(const OMPParallelForDirective &s);
2453 mlir::LogicalResult
2454 emitOMPParallelForSimdDirective(const OMPParallelForSimdDirective &s);
2455 mlir::LogicalResult
2456 emitOMPParallelMasterDirective(const OMPParallelMasterDirective &s);
2457 mlir::LogicalResult
2458 emitOMPParallelSectionsDirective(const OMPParallelSectionsDirective &s);
2459 mlir::LogicalResult emitOMPTaskDirective(const OMPTaskDirective &s);
2460 mlir::LogicalResult emitOMPTaskgroupDirective(const OMPTaskgroupDirective &s);
2461 mlir::LogicalResult emitOMPFlushDirective(const OMPFlushDirective &s);
2462 mlir::LogicalResult emitOMPDepobjDirective(const OMPDepobjDirective &s);
2463 mlir::LogicalResult emitOMPScanDirective(const OMPScanDirective &s);
2464 mlir::LogicalResult emitOMPOrderedDirective(const OMPOrderedDirective &s);
2465 mlir::LogicalResult emitOMPAtomicDirective(const OMPAtomicDirective &s);
2466 mlir::LogicalResult emitOMPTargetDirective(const OMPTargetDirective &s);
2467 mlir::LogicalResult emitOMPTeamsDirective(const OMPTeamsDirective &s);
2468 mlir::LogicalResult
2470 mlir::LogicalResult emitOMPCancelDirective(const OMPCancelDirective &s);
2471 mlir::LogicalResult
2473 mlir::LogicalResult
2475 mlir::LogicalResult
2477 mlir::LogicalResult
2479 mlir::LogicalResult
2481 mlir::LogicalResult emitOMPTaskLoopDirective(const OMPTaskLoopDirective &s);
2482 mlir::LogicalResult
2484 mlir::LogicalResult
2486 mlir::LogicalResult
2488 mlir::LogicalResult
2490 mlir::LogicalResult
2492 mlir::LogicalResult
2494 mlir::LogicalResult
2495 emitOMPParallelMaskedDirective(const OMPParallelMaskedDirective &s);
2496 mlir::LogicalResult emitOMPParallelMaskedTaskLoopDirective(
2500 mlir::LogicalResult emitOMPParallelMasterTaskLoopDirective(
2504 mlir::LogicalResult
2506 mlir::LogicalResult emitOMPDistributeParallelForDirective(
2510 mlir::LogicalResult
2514 mlir::LogicalResult emitOMPTargetParallelForSimdDirective(
2516 mlir::LogicalResult
2518 mlir::LogicalResult emitOMPTargetTeamsGenericLoopDirective(
2520 mlir::LogicalResult
2522 mlir::LogicalResult
2524 mlir::LogicalResult
2530 mlir::LogicalResult
2532 mlir::LogicalResult
2534 mlir::LogicalResult emitOMPTargetTeamsDistributeDirective(
2542 mlir::LogicalResult emitOMPInteropDirective(const OMPInteropDirective &s);
2543 mlir::LogicalResult emitOMPDispatchDirective(const OMPDispatchDirective &s);
2544 mlir::LogicalResult
2546 mlir::LogicalResult emitOMPReverseDirective(const OMPReverseDirective &s);
2547 mlir::LogicalResult emitOMPSplitDirective(const OMPSplitDirective &s);
2548 mlir::LogicalResult
2550 mlir::LogicalResult emitOMPAssumeDirective(const OMPAssumeDirective &s);
2551 mlir::LogicalResult emitOMPMaskedDirective(const OMPMaskedDirective &s);
2552 mlir::LogicalResult emitOMPStripeDirective(const OMPStripeDirective &s);
2553
2557 void emitOMPAllocateDecl(const OMPAllocateDecl &d);
2560 void emitOMPRequiresDecl(const OMPRequiresDecl &d);
2561
2562private:
2563 template <typename Op>
2564 void emitOpenMPClauses(Op &op, ArrayRef<const OMPClause *> clauses);
2565
2566 //===--------------------------------------------------------------------===//
2567 // OpenACC Emission
2568 //===--------------------------------------------------------------------===//
2569private:
2570 template <typename Op>
2571 Op emitOpenACCOp(mlir::Location start, OpenACCDirectiveKind dirKind,
2573 // Function to do the basic implementation of an operation with an Associated
2574 // Statement. Models AssociatedStmtConstruct.
2575 template <typename Op, typename TermOp>
2576 mlir::LogicalResult
2577 emitOpenACCOpAssociatedStmt(mlir::Location start, mlir::Location end,
2578 OpenACCDirectiveKind dirKind,
2580 const Stmt *associatedStmt);
2581
2582 template <typename Op, typename TermOp>
2583 mlir::LogicalResult emitOpenACCOpCombinedConstruct(
2584 mlir::Location start, mlir::Location end, OpenACCDirectiveKind dirKind,
2585 llvm::ArrayRef<const OpenACCClause *> clauses, const Stmt *loopStmt);
2586
2587 template <typename Op>
2588 void emitOpenACCClauses(Op &op, OpenACCDirectiveKind dirKind,
2590 // The second template argument doesn't need to be a template, since it should
2591 // always be an mlir::acc::LoopOp, but as this is a template anyway, we make
2592 // it a template argument as this way we can avoid including the OpenACC MLIR
2593 // headers here. We will count on linker failures/explicit instantiation to
2594 // ensure we don't mess this up, but it is only called from 1 place, and
2595 // instantiated 3x.
2596 template <typename ComputeOp, typename LoopOp>
2597 void emitOpenACCClauses(ComputeOp &op, LoopOp &loopOp,
2598 OpenACCDirectiveKind dirKind,
2600
2601 // The OpenACC LoopOp requires that we have auto, seq, or independent on all
2602 // LoopOp operations for the 'none' device type case. This function checks if
2603 // the LoopOp has one, else it updates it to have one.
2604 void updateLoopOpParallelism(mlir::acc::LoopOp &op, bool isOrphan,
2606
2607 // The OpenACC 'cache' construct actually applies to the 'loop' if present. So
2608 // keep track of the 'loop' so that we can add the cache vars to it correctly.
2609 mlir::acc::LoopOp *activeLoopOp = nullptr;
2610
2611 struct ActiveOpenACCLoopRAII {
2612 CIRGenFunction &cgf;
2613 mlir::acc::LoopOp *oldLoopOp;
2614
2615 ActiveOpenACCLoopRAII(CIRGenFunction &cgf, mlir::acc::LoopOp *newOp)
2616 : cgf(cgf), oldLoopOp(cgf.activeLoopOp) {
2617 cgf.activeLoopOp = newOp;
2618 }
2619 ~ActiveOpenACCLoopRAII() { cgf.activeLoopOp = oldLoopOp; }
2620 };
2621
2622 // Keep track of the last place we inserted a 'recipe' so that we can insert
2623 // the next one in lexical order.
2624 mlir::OpBuilder::InsertPoint lastRecipeLocation;
2625
2626public:
2627 // Helper type used to store the list of important information for a 'data'
2628 // clause variable, or a 'cache' variable reference.
2630 mlir::Location beginLoc;
2631 mlir::Value varValue;
2632 std::string name;
2633 // The type of the original variable reference: that is, after 'bounds' have
2634 // removed pointers/array types/etc. So in the case of int arr[5], and a
2635 // private(arr[1]), 'origType' is 'int', but 'baseType' is 'int[5]'.
2639 // The list of types that we found when going through the bounds, which we
2640 // can use to properly set the alloca section.
2642 };
2643
2644 // Gets the collection of info required to lower and OpenACC clause or cache
2645 // construct variable reference.
2647 // Helper function to emit the integer expressions as required by an OpenACC
2648 // clause/construct.
2649 mlir::Value emitOpenACCIntExpr(const Expr *intExpr);
2650 // Helper function to emit an integer constant as an mlir int type, used for
2651 // constants in OpenACC constructs/clauses.
2652 mlir::Value createOpenACCConstantInt(mlir::Location loc, unsigned width,
2653 int64_t value);
2654
2655 mlir::LogicalResult
2657 mlir::LogicalResult emitOpenACCLoopConstruct(const OpenACCLoopConstruct &s);
2658 mlir::LogicalResult
2660 mlir::LogicalResult emitOpenACCDataConstruct(const OpenACCDataConstruct &s);
2661 mlir::LogicalResult
2663 mlir::LogicalResult
2665 mlir::LogicalResult
2667 mlir::LogicalResult emitOpenACCWaitConstruct(const OpenACCWaitConstruct &s);
2668 mlir::LogicalResult emitOpenACCInitConstruct(const OpenACCInitConstruct &s);
2669 mlir::LogicalResult
2671 mlir::LogicalResult emitOpenACCSetConstruct(const OpenACCSetConstruct &s);
2672 mlir::LogicalResult
2674 mlir::LogicalResult
2676 mlir::LogicalResult emitOpenACCCacheConstruct(const OpenACCCacheConstruct &s);
2677
2680
2681 /// Create a temporary memory object for the given aggregate type.
2682 AggValueSlot createAggTemp(QualType ty, mlir::Location loc,
2683 const Twine &name = "tmp",
2684 Address *alloca = nullptr) {
2686 return AggValueSlot::forAddr(
2687 createMemTemp(ty, loc, name, alloca), ty.getQualifiers(),
2690 }
2691
2692private:
2693 QualType getVarArgType(const Expr *arg);
2694
2695 class InlinedInheritingConstructorScope {
2696 public:
2697 InlinedInheritingConstructorScope(CIRGenFunction &cgf, GlobalDecl gd)
2698 : cgf(cgf), oldCurGD(cgf.curGD), oldCurFuncDecl(cgf.curFuncDecl),
2699 oldCurCodeDecl(cgf.curCodeDecl),
2700 oldCxxabiThisDecl(cgf.cxxabiThisDecl),
2701 oldCxxThisValue(cgf.cxxThisValue),
2702 oldCxxabiThisAlignment(cgf.cxxabiThisAlignment),
2703 oldCxxThisAlignment(cgf.cxxThisAlignment),
2704 oldReturnValue(cgf.returnValue), oldFnRetTy(cgf.fnRetTy),
2705 oldCxxInheritedCtorInitExprArgs(
2706 std::move(cgf.cxxInheritedCtorInitExprArgs)) {
2707 cgf.curGD = gd;
2709 cgf.curCodeDecl = cgf.curFuncDecl;
2710 cgf.cxxabiThisDecl = nullptr;
2711 cgf.cxxabiThisValue = nullptr;
2712 cgf.cxxThisValue = nullptr;
2716 cgf.fnRetTy = QualType();
2717 cgf.cxxInheritedCtorInitExprArgs.clear();
2718 // FIXME: at one point when we want to call one of these, we'll need
2719 // CXXInheritedCtorInitExprArgs here too.
2720 }
2721 ~InlinedInheritingConstructorScope() {
2722 cgf.curGD = oldCurGD;
2723 cgf.curFuncDecl = oldCurFuncDecl;
2724 cgf.curCodeDecl = oldCurCodeDecl;
2725 cgf.cxxabiThisDecl = oldCxxabiThisDecl;
2726 cgf.cxxabiThisValue = oldCxxabiThisValue;
2727 cgf.cxxThisValue = oldCxxThisValue;
2728 cgf.cxxThisAlignment = oldCxxThisAlignment;
2729 cgf.cxxabiThisAlignment = oldCxxabiThisAlignment;
2730 cgf.returnValue = oldReturnValue;
2731 cgf.fnRetTy = oldFnRetTy;
2733 std::move(oldCxxInheritedCtorInitExprArgs);
2734 }
2735
2736 private:
2737 CIRGenFunction &cgf;
2738 GlobalDecl oldCurGD;
2739 const Decl *oldCurFuncDecl;
2740 const Decl *oldCurCodeDecl;
2741 ImplicitParamDecl *oldCxxabiThisDecl;
2742 mlir::Value oldCxxabiThisValue;
2743 mlir::Value oldCxxThisValue;
2744 clang::CharUnits oldCxxabiThisAlignment;
2745 clang::CharUnits oldCxxThisAlignment;
2746 Address oldReturnValue;
2747 QualType oldFnRetTy;
2748 CallArgList oldCxxInheritedCtorInitExprArgs;
2749 };
2750};
2751
2752} // namespace clang::CIRGen
2753
2754#endif
Defines the clang::ASTContext interface.
llvm::function_ref< void(mlir::OpBuilder &, mlir::Location)> BuilderCallbackRef
Definition CIRDialect.h:37
static void emitAtomicOp(CIRGenFunction &cgf, AtomicExpr *expr, Address dest, Address ptr, Address val1, Address val2, Expr *isWeakExpr, Expr *failureOrderExpr, int64_t size, cir::MemOrder order, cir::SyncScopeKind scope)
Defines the clang::Expr interface and subclasses for C++ expressions.
tooling::Replacements cleanup(const FormatStyle &Style, StringRef Code, ArrayRef< tooling::Range > Ranges, StringRef FileName="<stdin>")
Clean up any erroneous/redundant code in the given Ranges in Code.
*collection of selector each with an associated kind and an ordered *collection of selectors A selector has a kind
Defines an enumeration for C++ overloaded operators.
Enumerates target-specific builtins in their own namespaces within namespace clang.
C Language Family Type Representation.
This represents 'pragma omp cancel' directive.
This represents 'pragma omp cancellation point' directive.
This represents 'pragma omp dispatch' directive.
This represents 'pragma omp distribute' directive.
This represents 'pragma omp distribute parallel for' composite directive.
This represents 'pragma omp distribute parallel for simd' composite directive.
This represents 'pragma omp distribute simd' composite directive.
This represents 'pragma omp error' directive.
Represents the 'pragma omp fuse' loop transformation directive.
This represents 'pragma omp loop' directive.
Represents the 'pragma omp interchange' loop transformation directive.
This represents 'pragma omp interop' directive.
This represents 'pragma omp masked' directive.
This represents 'pragma omp masked taskloop' directive.
This represents 'pragma omp masked taskloop simd' directive.
This represents 'pragma omp master taskloop' directive.
This represents 'pragma omp master taskloop simd' directive.
This represents 'pragma omp metadirective' directive.
This represents 'pragma omp parallel loop' directive.
This represents 'pragma omp parallel masked taskloop' directive.
This represents 'pragma omp parallel masked taskloop simd' directive.
This represents 'pragma omp parallel master taskloop' directive.
This represents 'pragma omp parallel master taskloop simd' directive.
Represents the 'pragma omp reverse' loop transformation directive.
This represents 'pragma omp scan' directive.
Represents the 'pragma omp split' loop transformation directive.
This represents the 'pragma omp stripe' loop transformation directive.
This represents 'pragma omp target data' directive.
This represents 'pragma omp target' directive.
This represents 'pragma omp target enter data' directive.
This represents 'pragma omp target exit data' directive.
This represents 'pragma omp target parallel' directive.
This represents 'pragma omp target parallel for' directive.
This represents 'pragma omp target parallel for simd' directive.
This represents 'pragma omp target parallel loop' directive.
This represents 'pragma omp target simd' directive.
This represents 'pragma omp target teams' directive.
This represents 'pragma omp target teams distribute' combined directive.
This represents 'pragma omp target teams distribute parallel for' combined directive.
This represents 'pragma omp target teams distribute parallel for simd' combined directive.
This represents 'pragma omp target teams distribute simd' combined directive.
This represents 'pragma omp target teams loop' directive.
This represents 'pragma omp target update' directive.
This represents 'pragma omp taskloop' directive.
This represents 'pragma omp taskloop simd' directive.
This represents 'pragma omp teams' directive.
This represents 'pragma omp teams distribute' directive.
This represents 'pragma omp teams distribute parallel for' composite directive.
This represents 'pragma omp teams distribute parallel for simd' composite directive.
This represents 'pragma omp teams distribute simd' combined directive.
This represents 'pragma omp teams loop' directive.
This represents the 'pragma omp tile' loop transformation directive.
This represents the 'pragma omp unroll' loop transformation directive.
This class represents a 'loop' construct. The 'loop' construct applies to a 'for' loop (or range-for ...
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:223
AbstractConditionalOperator - An abstract base class for ConditionalOperator and BinaryConditionalOpe...
Definition Expr.h:4356
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
Definition Expr.h:2724
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Definition TypeBase.h:3786
AsmStmt is the base class for GCCAsmStmt and MSAsmStmt.
Definition Stmt.h:3287
AtomicExpr - Variadic atomic builtins: __atomic_exchange, __atomic_fetch_*, __atomic_load,...
Definition Expr.h:6928
Represents an attribute applied to a statement.
Definition Stmt.h:2213
BinaryConditionalOperator - The GNU extension to the conditional operator which allows the middle ope...
Definition Expr.h:4456
OpaqueValueExpr * getOpaqueValue() const
getOpaqueValue - Return the opaque value placeholder.
Definition Expr.h:4494
Expr * getCommon() const
getCommon - Return the common expression, written to the left of the condition.
Definition Expr.h:4491
A builtin binary operation expression such as "x + y" or "x <= y".
Definition Expr.h:4041
BreakStmt - This represents a break.
Definition Stmt.h:3145
mlir::Value getPointer() const
Definition Address.h:98
static Address invalid()
Definition Address.h:76
clang::CharUnits getAlignment() const
Definition Address.h:138
mlir::Value getBasePointer() const
Definition Address.h:103
An aggregate value slot.
static AggValueSlot forAddr(Address addr, clang::Qualifiers quals, IsDestructed_t isDestructed, IsAliased_t isAliased, Overlap_t mayOverlap, IsZeroed_t isZeroed=IsNotZeroed)
static AggValueSlot ignored()
Returns an aggregate value slot indicating that the aggregate value is being ignored.
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)
An abstract representation of regular/ObjC call/message targets.
AbstractCallee(const clang::FunctionDecl *fd)
const clang::ParmVarDecl * getParamDecl(unsigned I) const
ArrayInitLoopExprScope(CIRGenFunction &cgf, bool setIdx, mlir::Value index)
CIRGenFPOptionsRAII(CIRGenFunction &cgf, FPOptions FPFeatures)
CXXDefaultInitExprScope(CIRGenFunction &cgf, const CXXDefaultInitExpr *e)
An object to manage conditionally-evaluated expressions.
ConditionalEvaluation(CIRGenFunction &cgf, mlir::OpBuilder::InsertPoint ip)
mlir::OpBuilder::InsertPoint getInsertPoint() const
Returns the insertion point which will be executed prior to each evaluation of the conditional code.
static ConstantEmission forReference(mlir::TypedAttr c)
static ConstantEmission forValue(mlir::TypedAttr c)
LValue getReferenceLValue(CIRGenFunction &cgf, Expr *refExpr) const
DeclMapRevertingRAII(CIRGenFunction &cgf, const VarDecl *vd)
FieldConstructionScope(CIRGenFunction &cgf, Address thisAddr)
FullExprCleanupScope(CIRGenFunction &cgf, const Expr *subExpr)
void exit(ArrayRef< mlir::Value * > valuesToReload={})
A non-RAII class containing all the information about a bound opaque value.
static OpaqueValueMappingData bind(CIRGenFunction &cgf, const OpaqueValueExpr *ov, const LValue &lv)
static OpaqueValueMappingData bind(CIRGenFunction &cgf, const OpaqueValueExpr *ov, const RValue &rv)
static OpaqueValueMappingData bind(CIRGenFunction &cgf, const OpaqueValueExpr *ov, const Expr *e)
OpaqueValueMapping(CIRGenFunction &cgf, const OpaqueValueExpr *opaqueValue, RValue rvalue)
OpaqueValueMapping(CIRGenFunction &cgf, const OpaqueValueExpr *opaqueValue, LValue lvalue)
OpaqueValueMapping(CIRGenFunction &cgf, const AbstractConditionalOperator *op)
Build the opaque value mapping for the given conditional operator if it's the GNU ?
OpaqueValueMapping(CIRGenFunction &cgf, const OpaqueValueExpr *ov)
Build the opaque value mapping for an OpaqueValueExpr whose source expression is set to the expressio...
Enters a new scope for capturing cleanups, all of which will be executed once the scope is exited.
RunCleanupsScope(CIRGenFunction &cgf)
Enter a new cleanup scope.
void forceLifetimeExtendedCleanups()
Promote any pending lifetime-extended cleanup entries onto the EH scope stack at the current insertio...
void forceCleanup(ArrayRef< mlir::Value * > valuesToReload={})
Force the emission of cleanups now, instead of waiting until this object is destroyed.
void forceCleanupExceptLifetimeExtended()
Force the emission of EH cleanups now, but defer promoting any lifetime-extended cleanup entries onto...
bool hasPendingCleanups() const
Whether there are any pending cleanups that have been pushed since this scope was entered.
~RunCleanupsScope()
Exit this cleanup scope, emitting any accumulated cleanups.
void restore()
Can be used to restore the state early, before the dtor is run.
SourceLocRAIIObject(CIRGenFunction &cgf, mlir::Location value)
static bool isConstructorDelegationValid(const clang::CXXConstructorDecl *ctor)
Checks whether the given constructor is a valid subject for the complete-to-base constructor delegati...
cir::CallOp emitCoroEndBuiltinCall(mlir::Location loc, mlir::Value nullPtr)
static bool hasScalarEvaluationKind(clang::QualType type)
void emitFunctionProlog(const FunctionArgList &args, mlir::Block *entryBB, const FunctionDecl *fd, SourceLocation bodyBeginLoc)
Emit the function prologue: declare function arguments in the symbol table.
void emitOpenACCRoutine(const OpenACCRoutineDecl &d)
void emitLambdaDelegatingInvokeBody(const CXXMethodDecl *md)
mlir::Value emitComplexToScalarConversion(mlir::Value src, QualType srcTy, QualType dstTy, SourceLocation loc)
Emit a conversion from the specified complex type to the specified destination type,...
cir::CallOp emitCoroIDBuiltinCall(mlir::Location loc, mlir::Value nullPtr)
void emitCallArgs(CallArgList &args, PrototypeWrapper prototype, llvm::iterator_range< clang::CallExpr::const_arg_iterator > argRange, AbstractCallee callee=AbstractCallee(), unsigned paramsToSkip=0)
mlir::Type convertType(clang::QualType t)
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.
mlir::LogicalResult emitOMPTargetParallelForDirective(const OMPTargetParallelForDirective &s)
LValue emitCXXBindTemporaryLValue(const CXXBindTemporaryExpr *e)
mlir::LogicalResult emitOMPParallelMasterTaskLoopSimdDirective(const OMPParallelMasterTaskLoopSimdDirective &s)
void generateThunk(cir::FuncOp fn, const CIRGenFunctionInfo &fnInfo, GlobalDecl gd, const ThunkInfo &thunk, bool isUnprototyped)
Generate code for a thunk function.
mlir::LogicalResult emitOMPSimdDirective(const OMPSimdDirective &s)
mlir::Value emitCheckedArgForAssume(const Expr *e)
Emits an argument for a call to a __builtin_assume.
LValue emitOpaqueValueLValue(const OpaqueValueExpr *e)
mlir::LogicalResult emitDoStmt(const clang::DoStmt &s)
mlir::LogicalResult emitOMPCriticalDirective(const OMPCriticalDirective &s)
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...
clang::CurrentSourceLocExprScope::SourceLocExprScopeGuard SourceLocExprScopeGuard
RValue convertTempToRValue(Address addr, clang::QualType type, clang::SourceLocation loc)
Given the address of a temporary variable, produce an r-value of its type.
mlir::LogicalResult emitCoreturnStmt(const CoreturnStmt &s)
mlir::LogicalResult emitOpenACCDataConstruct(const OpenACCDataConstruct &s)
AutoVarEmission emitAutoVarAlloca(const clang::VarDecl &d, mlir::OpBuilder::InsertPoint ip={})
mlir::Value emitPromotedValue(mlir::Value result, QualType promotionType)
void emitAutoVarTypeCleanup(const AutoVarEmission &emission, clang::QualType::DestructionKind dtorKind)
Enter a destroy cleanup for the given local variable.
ImplicitParamDecl * cxxabiThisDecl
CXXThisDecl - When generating code for a C++ member function, this will hold the implicit 'this' decl...
EHScopeStack::stable_iterator prologueCleanupDepth
The cleanup depth enclosing all the cleanups associated with the parameters.
mlir::LogicalResult emitOpenACCCombinedConstruct(const OpenACCCombinedConstruct &s)
Address emitCXXMemberDataPointerAddress(const Expr *e, Address base, mlir::Value memberPtr, const MemberPointerType *memberPtrType, LValueBaseInfo *baseInfo)
bool curFuncIsThunk
In C++, whether we are code generating a thunk.
Address maybeCastStackAddressSpace(Address alloca, mlir::ptr::MemorySpaceAttrInterface destAddrSpace, mlir::Value arraySize)
mlir::LogicalResult emitOMPParallelMasterDirective(const OMPParallelMasterDirective &s)
mlir::LogicalResult emitOpenACCWaitConstruct(const OpenACCWaitConstruct &s)
cir::FuncOp generateCode(clang::GlobalDecl gd, cir::FuncOp fn, cir::FuncType funcType)
llvm::SmallVector< PendingCleanupEntry > lifetimeExtendedCleanupStack
mlir::LogicalResult emitOMPCancellationPointDirective(const OMPCancellationPointDirective &s)
mlir::LogicalResult emitOMPParallelMaskedTaskLoopDirective(const OMPParallelMaskedTaskLoopDirective &s)
CIRGenTypes & getTypes() const
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...
llvm::ScopedHashTable< const clang::Decl *, mlir::Value > SymTableTy
The symbol table maps a variable name to a value in the current scope.
void initFullExprCleanup()
Set up the last cleanup that was pushed as a conditional full-expression cleanup.
void emitInvariantStart(CharUnits size, mlir::Value addr, mlir::Location loc)
Definition CIRGenCXX.cpp:33
mlir::LogicalResult emitOMPReverseDirective(const OMPReverseDirective &s)
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
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,...
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...
void emitForwardingCallToLambda(const CXXMethodDecl *lambdaCallOperator, CallArgList &callArgs)
mlir::Block * getCurFunctionEntryBlock()
RValue emitCXXMemberCallExpr(const clang::CXXMemberCallExpr *e, ReturnValueSlot returnValue)
mlir::LogicalResult emitOpenACCUpdateConstruct(const OpenACCUpdateConstruct &s)
RValue emitCXXMemberPointerCallExpr(const CXXMemberCallExpr *ce, ReturnValueSlot returnValue)
LValue emitLValueForBitField(LValue base, const FieldDecl *field)
mlir::LogicalResult emitOMPTileDirective(const OMPTileDirective &s)
mlir::LogicalResult emitIfOnBoolExpr(const clang::Expr *cond, const clang::Stmt *thenS, const clang::Stmt *elseS)
Emit an if on a boolean condition to the specified blocks.
void emitOMPRequiresDecl(const OMPRequiresDecl &d)
VlaSizePair getVLASize(const VariableArrayType *type)
Returns an MLIR::Value+QualType pair that corresponds to the size, in non-variably-sized elements,...
LValue emitScalarCompoundAssignWithComplex(const CompoundAssignOperator *e, mlir::Value &result)
mlir::LogicalResult emitOMPTargetTeamsDirective(const OMPTargetTeamsDirective &s)
Address cxxDefaultInitExprThis
The value of 'this' to sue when evaluating CXXDefaultInitExprs within this expression.
RValue emitBuiltinWithOneOverloadedType(const CallExpr *e, llvm::StringRef intrinName)
Emit a simple LLVM intrinsic that takes N scalar arguments and whose return type matches the type of ...
void emitStaticVarDecl(const VarDecl &d, cir::GlobalLinkageKind linkage)
mlir::Value emitComplexExpr(const Expr *e)
Emit the computation of the specified expression of complex type, returning the result.
mlir::LogicalResult emitOMPTeamsDistributeParallelForDirective(const OMPTeamsDistributeParallelForDirective &s)
mlir::LogicalResult emitOMPBarrierDirective(const OMPBarrierDirective &s)
void setBeforeOutermostConditional(mlir::Value value, Address addr)
mlir::LogicalResult emitOMPTargetParallelDirective(const OMPTargetParallelDirective &s)
mlir::LogicalResult emitOpenACCCacheConstruct(const OpenACCCacheConstruct &s)
mlir::Value loadCXXThis()
Load the value for 'this'.
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...
RValue emitCallExpr(const clang::CallExpr *e, ReturnValueSlot returnValue=ReturnValueSlot())
void emitDeleteCall(const FunctionDecl *deleteFD, mlir::Value ptr, QualType deleteTy)
LValue emitMemberExpr(const MemberExpr *e)
const TargetInfo & getTarget() const
void replaceAddrOfLocalVar(const clang::VarDecl *vd, Address addr)
llvm::DenseMap< const clang::Decl *, Address > DeclMapTy
LValue emitConditionalOperatorLValue(const AbstractConditionalOperator *expr)
LValue emitLValue(const clang::Expr *e)
Emit code to compute a designator that specifies the location of the expression.
void addCatchHandlerAttr(const CXXCatchStmt *catchStmt, SmallVector< mlir::Attribute > &handlerAttrs)
Address makeNaturalAddressForPointer(mlir::Value ptr, QualType t, CharUnits alignment, bool forPointeeType=false, LValueBaseInfo *baseInfo=nullptr)
Construct an address with the natural alignment of T.
const clang::Decl * curFuncDecl
mlir::LogicalResult emitOMPTargetDirective(const OMPTargetDirective &s)
mlir::LogicalResult emitCXXForRangeStmt(const CXXForRangeStmt &s, llvm::ArrayRef< const Attr * > attrs)
LValue emitLValueForLambdaField(const FieldDecl *field)
RValue emitCall(const CIRGenFunctionInfo &funcInfo, const CIRGenCallee &callee, ReturnValueSlot returnValue, const CallArgList &args, cir::CIRCallOpInterface *callOrTryCall=nullptr)
mlir::Value evaluateExprAsBool(const clang::Expr *e)
Perform the usual unary conversions on the specified expression and compare the result against zero,...
bool isTrivialInitializer(const Expr *init)
Determine whether the given initializer is trivial in the sense that it requires no code to be genera...
void emitOpenACCDeclare(const OpenACCDeclareDecl &d)
void emitInlinedInheritingCXXConstructorCall(SourceLocation loc, const CXXConstructorDecl *d, CXXCtorType ctorType, bool forVirtualBase, bool delegating, CallArgList &args)
Address getAddrOfLocalVar(const clang::VarDecl *vd)
Return the address of a local variable.
void emitAnyExprToExn(const Expr *e, Address addr)
void emitAggregateCopy(LValue dest, LValue src, QualType eltTy, AggValueSlot::Overlap_t mayOverlap, bool isVolatile=false)
Emit an aggregate copy.
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,...
mlir::Value emitNVPTXDevicePrintfCallExpr(const CallExpr *expr)
Emit a device-side printf call for NVPTX targets.
void emitMustTailThunk(GlobalDecl gd, mlir::Value adjustedThisPtr, cir::FuncOp callee)
Emit a musttail call for a thunk with a potentially different ABI.
void pushIrregularPartialArrayCleanup(mlir::Value arrayBegin, Address arrayEndPointer, QualType elementType, CharUnits elementAlign, Destroyer *destroyer)
Push an EH cleanup to destroy already-constructed elements of the given array.
Address getAsNaturalAddressOf(Address addr, QualType pointeeTy)
void pushCleanupAndDeferDeactivation(CleanupKind kind, As... a)
Push a cleanup and record it for deferred deactivation.
LValue emitComplexCompoundAssignmentLValue(const CompoundAssignOperator *e)
mlir::LogicalResult emitOMPScopeDirective(const OMPScopeDirective &s)
void emitBeginCatch(const CXXCatchStmt *catchStmt, mlir::Value ehToken)
Begins a catch statement by initializing the catch variable and calling __cxa_begin_catch.
mlir::Value getVTTParameter(GlobalDecl gd, bool forVirtualBase, bool delegating)
Return the VTT parameter that should be passed to a base constructor/destructor with virtual bases.
mlir::Location getLoc(clang::SourceLocation srcLoc)
Helpers to convert Clang's SourceLocation to a MLIR Location.
mlir::LogicalResult emitOMPDepobjDirective(const OMPDepobjDirective &s)
void initializeVTablePointers(mlir::Location loc, const clang::CXXRecordDecl *rd)
mlir::Type convertType(const TypeDecl *t)
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,...
mlir::Value emitOpOnBoolExpr(mlir::Location loc, const clang::Expr *cond)
TODO(cir): see EmitBranchOnBoolExpr for extra ideas).
void emitStoreThroughExtVectorComponentLValue(RValue src, LValue dst)
void initializeVTablePointer(mlir::Location loc, const VPtr &vptr)
Address getAddressOfBaseClass(Address value, const CXXRecordDecl *derived, llvm::iterator_range< CastExpr::path_const_iterator > path, bool nullCheckValue, SourceLocation loc)
void emitOMPDeclareReduction(const OMPDeclareReductionDecl &d)
void emitAggregateStore(mlir::Value value, Address dest)
mlir::LogicalResult emitReturnStmt(const clang::ReturnStmt &s)
LValue emitLoadOfReferenceLValue(Address refAddr, mlir::Location loc, QualType refTy, AlignmentSource source)
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.
ConditionalEvaluation * outermostConditional
mlir::LogicalResult emitOpenACCInitConstruct(const OpenACCInitConstruct &s)
void emitAnyExprToMem(const Expr *e, Address location, Qualifiers quals, bool isInitializer)
Emits the code necessary to evaluate an arbitrary expression into the given memory location.
RValue emitCXXMemberOrOperatorCall(const clang::CXXMethodDecl *md, const CIRGenCallee &callee, ReturnValueSlot returnValue, mlir::Value thisPtr, mlir::Value implicitParam, clang::QualType implicitParamTy, const clang::CallExpr *ce, CallArgList *rtlArgs)
LValue getOrCreateOpaqueLValueMapping(const OpaqueValueExpr *e)
Given an opaque value expression, return its LValue mapping if it exists, otherwise create one.
mlir::LogicalResult emitOMPDistributeParallelForSimdDirective(const OMPDistributeParallelForSimdDirective &s)
void emitBaseInitializer(mlir::Location loc, const CXXRecordDecl *classDecl, CXXCtorInitializer *baseInit)
RValue emitAtomicExpr(AtomicExpr *e)
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.
void emitCXXGuardedInit(const VarDecl &varDecl, cir::GlobalOp globalOp, bool performInit)
Emit a guarded initializer for a static local variable.
mlir::LogicalResult emitOMPUnrollDirective(const OMPUnrollDirective &s)
cir::CallOp emitCoroFreeBuiltin(const CallExpr *e)
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)
mlir::LogicalResult emitOMPTaskDirective(const OMPTaskDirective &s)
mlir::LogicalResult emitOpenACCSetConstruct(const OpenACCSetConstruct &s)
mlir::Value performAddrSpaceCast(mlir::Value v, mlir::Type destTy) const
RValue emitReferenceBindingToExpr(const Expr *e)
Emits a reference binding to the passed in expression.
mlir::LogicalResult emitOMPTeamsGenericLoopDirective(const OMPTeamsGenericLoopDirective &s)
llvm::SmallVector< DeferredDeactivateCleanup > deferredDeactivationCleanupStack
VPtrsVector getVTablePointers(const clang::CXXRecordDecl *vtableClass)
const TargetCIRGenInfo & getTargetHooks() const
mlir::LogicalResult emitOMPCanonicalLoop(const OMPCanonicalLoop &s)
mlir::LogicalResult emitSwitchStmt(const clang::SwitchStmt &s)
RValue emitCoyieldExpr(const CoyieldExpr &e, AggValueSlot aggSlot=AggValueSlot::ignored(), bool ignoreResult=false)
mlir::Value evaluateOrEmitBuiltinObjectSize(const clang::Expr *e, unsigned type, cir::IntType resType, mlir::Value emittedE, bool isDynamic)
mlir::LogicalResult emitOMPTeamsDirective(const OMPTeamsDirective &s)
std::optional< mlir::Value > emitRISCVBuiltinExpr(unsigned builtinID, const CallExpr *expr)
void pushDestroyAndDeferDeactivation(QualType::DestructionKind dtorKind, Address addr, QualType type)
mlir::LogicalResult emitCaseStmt(const clang::CaseStmt &s, mlir::Type condType, bool buildingTopLevelCase)
LValue emitArraySubscriptExpr(const clang::ArraySubscriptExpr *e)
llvm::ScopedHashTableScope< const clang::Decl *, mlir::Value > SymTableScopeTy
OpenACCDataOperandInfo getOpenACCDataOperandInfo(const Expr *e)
mlir::LogicalResult emitOMPMaskedTaskLoopDirective(const OMPMaskedTaskLoopDirective &s)
CleanupKind getCleanupKind(QualType::DestructionKind kind)
clang::CharUnits cxxabiThisAlignment
mlir::Value emitBuiltinObjectSize(const clang::Expr *e, unsigned type, cir::IntType resType, mlir::Value emittedE, bool isDynamic)
Returns a Value corresponding to the size of the given expression by emitting a cir....
RValue emitCUDAKernelCallExpr(const CUDAKernelCallExpr *expr, ReturnValueSlot returnValue)
mlir::LogicalResult emitOMPFuseDirective(const OMPFuseDirective &s)
AggValueSlot::Overlap_t getOverlapForFieldInit(const FieldDecl *fd)
mlir::LogicalResult emitSimpleStmt(const clang::Stmt *s, bool useCurrentScope)
mlir::LogicalResult emitOMPSectionDirective(const OMPSectionDirective &s)
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.
mlir::LogicalResult emitAsmStmt(const clang::AsmStmt &s)
std::pair< mlir::Value, mlir::Type > emitAsmInputLValue(const TargetInfo::ConstraintInfo &info, LValue inputValue, QualType inputType, std::string &constraintString, SourceLocation loc)
Address emitExtVectorElementLValue(LValue lv, mlir::Location loc)
Generates lvalue for partial ext_vector access.
mlir::LogicalResult emitOMPParallelForSimdDirective(const OMPParallelForSimdDirective &s)
void emitOMPAllocateDecl(const OMPAllocateDecl &d)
mlir::LogicalResult emitOMPDistributeParallelForDirective(const OMPDistributeParallelForDirective &s)
mlir::Value emitScalarConversion(mlir::Value src, clang::QualType srcType, clang::QualType dstType, clang::SourceLocation loc)
Emit a conversion from the specified type to the specified destination type, both of which are CIR sc...
Address getAddressOfDerivedClass(mlir::Location loc, Address baseAddr, const CXXRecordDecl *derived, llvm::iterator_range< CastExpr::path_const_iterator > path, bool nullCheckValue)
std::optional< mlir::Value > emitTargetBuiltinExpr(unsigned builtinID, const clang::CallExpr *e, ReturnValueSlot &returnValue)
CallArgList cxxInheritedCtorInitExprArgs
The values of function arguments to use when evaluating CXXInheritedCtorInitExprs within this context...
mlir::Value emitPromotedComplexExpr(const Expr *e, QualType promotionType)
ImplicitParamDecl * cxxStructorImplicitParamDecl
When generating code for a constructor or destructor, this will hold the implicit argument (e....
mlir::LogicalResult emitOpenACCComputeConstruct(const OpenACCComputeConstruct &s)
void emitOMPDeclareMapper(const OMPDeclareMapperDecl &d)
mlir::LogicalResult emitOMPMasterTaskLoopSimdDirective(const OMPMasterTaskLoopSimdDirective &s)
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.
mlir::Value emitUnPromotedValue(mlir::Value result, QualType unPromotionType)
mlir::LogicalResult emitSwitchBody(const clang::Stmt *s)
void startThunk(cir::FuncOp fn, GlobalDecl gd, const CIRGenFunctionInfo &fnInfo, bool isUnprototyped)
Start generating a thunk function.
RValue emitAtomicLoad(LValue lvalue, SourceLocation loc, AggValueSlot slot=AggValueSlot::ignored())
mlir::LogicalResult emitForStmt(const clang::ForStmt &s)
AggValueSlot createAggTemp(QualType ty, mlir::Location loc, const Twine &name="tmp", Address *alloca=nullptr)
Create a temporary memory object for the given aggregate type.
llvm::SmallVector< PendingCleanupEntry > deferredConditionalCleanupStack
void emitNewArrayInitializer(const CXXNewExpr *e, QualType elementType, mlir::Type elementTy, Address beginPtr, mlir::Value numElements, mlir::Value allocSizeWithoutCookie)
mlir::LogicalResult emitOMPTaskwaitDirective(const OMPTaskwaitDirective &s)
mlir::LogicalResult emitOMPFlushDirective(const OMPFlushDirective &s)
mlir::LogicalResult emitOMPGenericLoopDirective(const OMPGenericLoopDirective &s)
mlir::LogicalResult emitOMPTargetUpdateDirective(const OMPTargetUpdateDirective &s)
std::optional< mlir::Value > fnRetAlloca
The compiler-generated variable that holds the return value.
void emitImplicitAssignmentOperatorBody(FunctionArgList &args)
clang::SanitizerSet sanOpts
Sanitizers enabled for this function.
static int64_t getZExtIntValueFromConstOp(mlir::Value val)
Get zero-extended integer from a mlir::Value that is an int constant or a constant op.
mlir::LogicalResult emitOMPOrderedDirective(const OMPOrderedDirective &s)
mlir::LogicalResult emitOMPTargetParallelForSimdDirective(const OMPTargetParallelForSimdDirective &s)
mlir::LogicalResult emitOMPInterchangeDirective(const OMPInterchangeDirective &s)
RValue emitLoadOfExtVectorElementLValue(LValue lv)
mlir::Value emitCXXTypeidExpr(const CXXTypeidExpr *e)
mlir::LogicalResult emitOMPDispatchDirective(const OMPDispatchDirective &s)
mlir::Type convertTypeForMem(QualType t)
mlir::LogicalResult emitCXXTryStmt(const clang::CXXTryStmt &s, cxxTryBodyEmitter &bodyCallback)
clang::QualType buildFunctionArgList(clang::GlobalDecl gd, FunctionArgList &args)
mlir::LogicalResult emitOMPParallelDirective(const OMPParallelDirective &s)
cir::CallOp emitCoroAllocBuiltinCall(mlir::Location loc)
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)
mlir::Value emitComplexPrePostIncDec(const UnaryOperator *e, LValue lv)
void emitUnreachable(clang::SourceLocation loc, bool createNewBlock)
Emit a reached-unreachable diagnostic if loc is valid and runtime checking is enabled.
mlir::Value createDummyValue(mlir::Location loc, clang::QualType qt)
mlir::LogicalResult emitAttributedStmt(const AttributedStmt &s)
void emitCXXConstructExpr(const clang::CXXConstructExpr *e, AggValueSlot dest)
mlir::Value emitLoadOfComplex(LValue src, SourceLocation loc)
Load a complex number from the specified l-value.
mlir::LogicalResult emitOMPForSimdDirective(const OMPForSimdDirective &s)
LValue emitAggExprToLValue(const Expr *e)
mlir::LogicalResult emitOMPTaskLoopDirective(const OMPTaskLoopDirective &s)
void emitStoreOfScalar(mlir::Value value, Address addr, bool isVolatile, clang::QualType ty, LValueBaseInfo baseInfo, bool isInit=false, bool isNontemporal=false)
void pushDestroy(QualType::DestructionKind dtorKind, Address addr, QualType type)
Push the standard destructor for the given type as at least a normal cleanup.
clang::CurrentSourceLocExprScope curSourceLocExprScope
Source location information about the default argument or member initializer expression we're evaluat...
mlir::Value loadCXXVTT()
Load the VTT parameter to base constructors/destructors have virtual bases.
void emitVarDecl(const clang::VarDecl &d)
This method handles emission of any variable declaration inside a function, including static vars etc...
LValue emitCompoundAssignmentLValue(const clang::CompoundAssignOperator *e)
mlir::Value emitSVEPredicateCast(mlir::Value pred, unsigned minNumElts, mlir::Location loc)
mlir::Value emitCXXNewExpr(const CXXNewExpr *e)
RValue getUndefRValue(clang::QualType ty)
Get an appropriate 'undef' rvalue for the given type.
bool getAArch64SVEProcessedOperands(unsigned builtinID, const CallExpr *expr, SmallVectorImpl< mlir::Value > &ops, clang::SVETypeFlags typeFlags)
Address returnValue
The temporary alloca to hold the return value.
LValue makeAddrLValue(Address addr, QualType ty, LValueBaseInfo baseInfo)
void emitCallAndReturnForThunk(cir::FuncOp callee, const ThunkInfo *thunk, bool isUnprototyped)
Emit the call and return for a thunk function.
static int64_t getSExtIntValueFromConstOp(mlir::Value val)
Get integer from a mlir::Value that is an int constant or a constant op.
mlir::Value getArrayInitIndex()
Get the index of the current ArrayInitLoopExpr, if any.
mlir::LogicalResult emitOMPTargetDataDirective(const OMPTargetDataDirective &s)
std::optional< mlir::Value > emitX86BuiltinExpr(unsigned builtinID, const CallExpr *expr)
mlir::LogicalResult emitLabel(const clang::LabelDecl &d)
void emitCXXConstructorCall(const clang::CXXConstructorDecl *d, clang::CXXCtorType type, bool forVirtualBase, bool delegating, AggValueSlot thisAVS, const clang::CXXConstructExpr *e)
mlir::LogicalResult emitOMPTargetParallelGenericLoopDirective(const OMPTargetParallelGenericLoopDirective &s)
static bool hasAggregateEvaluationKind(clang::QualType type)
mlir::Value getVTablePtr(mlir::Location loc, Address thisAddr, const clang::CXXRecordDecl *vtableClass)
Return the Value of the vtable pointer member pointed to by thisAddr.
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.
LValue emitPointerToDataMemberBinaryExpr(const BinaryOperator *e)
mlir::LogicalResult emitOMPParallelMaskedDirective(const OMPParallelMaskedDirective &s)
RValue emitAnyExprToTemp(const clang::Expr *e)
Similarly to emitAnyExpr(), however, the result will always be accessible even if no aggregate locati...
void finishFunction(SourceLocation endLoc)
mlir::LogicalResult emitOMPMaskedTaskLoopSimdDirective(const OMPMaskedTaskLoopSimdDirective &s)
mlir::LogicalResult emitOMPAtomicDirective(const OMPAtomicDirective &s)
mlir::LogicalResult emitOpenACCShutdownConstruct(const OpenACCShutdownConstruct &s)
mlir::LogicalResult emitFunctionBody(const clang::Stmt *body)
mlir::LogicalResult emitBreakStmt(const clang::BreakStmt &s)
void initFullExprCleanupWithFlag(Address activeFlag)
mlir::LogicalResult emitIndirectGotoStmt(const IndirectGotoStmt &s)
mlir::LogicalResult emitOMPTeamsDistributeParallelForSimdDirective(const OMPTeamsDistributeParallelForSimdDirective &s)
mlir::LogicalResult emitOMPTaskgroupDirective(const OMPTaskgroupDirective &s)
mlir::Value emitTernaryOnBoolExpr(const clang::Expr *cond, mlir::Location loc, const clang::Stmt *thenS, const clang::Stmt *elseS)
void emitStoreOfComplex(mlir::Location loc, mlir::Value v, LValue dest, bool isInit)
EmitStoreOfComplex - Store a complex number into the specified l-value.
llvm::SmallPtrSet< const clang::CXXRecordDecl *, 4 > VisitedVirtualBasesSetTy
mlir::LogicalResult emitOMPParallelMaskedTaskLoopSimdDirective(const OMPParallelMaskedTaskLoopSimdDirective &s)
mlir::LogicalResult emitOMPTeamsDistributeDirective(const OMPTeamsDistributeDirective &s)
void emitScalarInit(const clang::Expr *init, mlir::Location loc, LValue lvalue, bool capturedByInit=false)
LValue emitUnaryOpLValue(const clang::UnaryOperator *e)
void emitReturnOfRValue(mlir::Location loc, RValue rv, QualType ty)
Address createCleanupActiveFlag()
Create an active flag variable for use with conditional cleanups.
bool shouldEmitVTableTypeCheckedLoad(const CXXRecordDecl *rd)
Returns whether we should perform a type checked load when loading a virtual function for virtual cal...
bool hasVolatileMember(QualType t)
returns true if aggregate type has a volatile member.
RValue emitLoadOfBitfieldLValue(LValue lv, SourceLocation loc)
mlir::LogicalResult emitOMPInteropDirective(const OMPInteropDirective &s)
RValue emitCall(const CIRGenFunctionInfo &funcInfo, const CIRGenCallee &callee, ReturnValueSlot returnValue, const CallArgList &args, cir::CIRCallOpInterface *callOp, mlir::Location loc)
mlir::LogicalResult emitOMPErrorDirective(const OMPErrorDirective &s)
LValue emitComplexAssignmentLValue(const BinaryOperator *e)
mlir::LogicalResult emitOMPSingleDirective(const OMPSingleDirective &s)
void emitCallArg(CallArgList &args, const clang::Expr *e, clang::QualType argType)
clang::FieldDecl * lambdaThisCaptureField
void deactivateCleanupBlock(EHScopeStack::stable_iterator cleanup, mlir::Operation *dominatingIP)
Deactivates the given cleanup block.
mlir::LogicalResult emitContinueStmt(const clang::ContinueStmt &s)
const clang::Decl * curCodeDecl
This is the inner-most code context, which includes blocks.
mlir::LogicalResult emitOMPTaskyieldDirective(const OMPTaskyieldDirective &s)
void emitConstructorBody(FunctionArgList &args)
LValue emitLValueForFieldInitialization(LValue base, const clang::FieldDecl *field, llvm::StringRef fieldName)
Like emitLValueForField, excpet that if the Field is a reference, this will return the address of the...
mlir::Value getAsNaturalPointerTo(Address addr, QualType pointeeType)
mlir::LogicalResult emitOMPTargetTeamsDistributeSimdDirective(const OMPTargetTeamsDistributeSimdDirective &s)
LValue emitCallExprLValue(const clang::CallExpr *e)
mlir::LogicalResult emitOMPScanDirective(const OMPScanDirective &s)
bool haveInsertPoint() const
True if an insertion point is defined.
llvm::SmallVector< mlir::Type, 2 > condTypeStack
The type of the condition for the emitting switch statement.
mlir::LogicalResult emitOMPTargetEnterDataDirective(const OMPTargetEnterDataDirective &s)
void emitAutoVarInit(const AutoVarEmission &emission)
Emit the initializer for an allocated variable.
void emitInitializerForField(clang::FieldDecl *field, LValue lhs, clang::Expr *init)
void emitStopPoint(const Stmt *s)
Build a debug stoppoint if we are emitting debug info.
std::optional< mlir::Value > emitAMDGPUBuiltinExpr(unsigned builtinID, const CallExpr *expr)
Emit a call to an AMDGPU builtin function.
std::optional< mlir::Value > emitAArch64BuiltinExpr(unsigned builtinID, const CallExpr *expr, ReturnValueSlot returnValue, llvm::Triple::ArchType arch)
void emitCXXTemporary(const CXXTemporary *temporary, QualType tempType, Address ptr)
Emits all the code to cause the given temporary to be cleaned up.
LValue emitStringLiteralLValue(const StringLiteral *e, llvm::StringRef name=".str")
mlir::LogicalResult emitOMPMasterTaskLoopDirective(const OMPMasterTaskLoopDirective &s)
void emitAtomicExprWithMemOrder(const Expr *memOrder, bool isStore, bool isLoad, bool isFence, llvm::function_ref< void(cir::MemOrder)> emitAtomicOp)
void maybeEmitDeferredVarDeclInit(const VarDecl *vd)
mlir::Value getUndefConstant(mlir::Location loc, mlir::Type cirTy)
Return a CIR constant for an undefined value of cirTy.
llvm::SmallDenseMap< const ParmVarDecl *, const ImplicitParamDecl * > sizeArguments
If a ParmVarDecl had the pass_object_size attribute, this will contain a mapping from said ParmVarDec...
void emitVAEnd(mlir::Value vaList)
Emits the end of a CIR variable-argument operation (cir.va_start)
mlir::Value emitToMemory(mlir::Value value, clang::QualType ty)
Given a value and its clang type, returns the value casted to its memory representation.
mlir::LogicalResult emitOpenACCHostDataConstruct(const OpenACCHostDataConstruct &s)
std::optional< mlir::Value > emitAArch64SMEBuiltinExpr(unsigned builtinID, const CallExpr *expr)
LValue emitLValueForField(LValue base, const clang::FieldDecl *field)
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)
LValue emitPseudoObjectLValue(const PseudoObjectExpr *E)
mlir::LogicalResult emitIfStmt(const clang::IfStmt &s)
mlir::LogicalResult emitOMPForDirective(const OMPForDirective &s)
void emitAutoVarDecl(const clang::VarDecl &d)
Emit code and set up symbol table for a variable declaration with auto, register, or no storage class...
mlir::LogicalResult emitOMPMasterDirective(const OMPMasterDirective &s)
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.
mlir::Value emitPromotedScalarExpr(const Expr *e, QualType promotionType)
AggValueSlot::Overlap_t getOverlapForReturnValue()
Determine whether a return value slot may overlap some other object.
bool needsEHCleanup(QualType::DestructionKind kind)
Determines whether an EH cleanup is required to destroy a type with the given destruction kind.
mlir::LogicalResult emitSwitchCase(const clang::SwitchCase &s, bool buildingTopLevelCase)
Address emitLoadOfReference(LValue refLVal, mlir::Location loc, LValueBaseInfo *pointeeBaseInfo)
Address getAddressOfDirectBaseInCompleteClass(mlir::Location loc, Address value, const CXXRecordDecl *derived, const CXXRecordDecl *base, bool baseIsVirtual)
Convert the given pointer to a complete class to the given direct base.
bool shouldNullCheckClassCastValue(const CastExpr *ce)
mlir::LogicalResult emitOMPMetaDirective(const OMPMetaDirective &s)
mlir::LogicalResult emitOMPDistributeSimdDirective(const OMPDistributeSimdDirective &s)
CIRGenBuilderTy & getBuilder()
void emitVAStart(mlir::Value vaList)
Emits the start of a CIR variable-argument operation (cir.va_start)
bool didCallStackSave
Whether a cir.stacksave operation has been added.
void emitDecl(const clang::Decl &d, bool evaluateConditionDecl=false)
mlir::LogicalResult emitOMPParallelGenericLoopDirective(const OMPParallelGenericLoopDirective &s)
LValue emitBinaryOperatorLValue(const BinaryOperator *e)
mlir::Value emitOpenACCIntExpr(const Expr *intExpr)
mlir::LogicalResult emitOMPMaskedDirective(const OMPMaskedDirective &s)
Address getAddrOfBitFieldStorage(LValue base, const clang::FieldDecl *field, mlir::Type fieldType, unsigned index)
AggValueSlot::Overlap_t getOverlapForBaseInit(const CXXRecordDecl *rd, const CXXRecordDecl *baseRD, bool isVirtual)
Determine whether a base class initialization may overlap some other object.
void emitDestroy(Address addr, QualType type, Destroyer *destroyer)
Immediately perform the destruction of the given object.
void emitNonNullArgCheck(RValue rv, QualType argType, SourceLocation argLoc, AbstractCallee ac, unsigned paramNum)
Create a check for a function parameter that may potentially be declared as non-null.
void pushPendingCleanupToEHStack(const PendingCleanupEntry &entry)
Promote a single pending cleanup entry onto the EH scope stack.
mlir::LogicalResult emitOMPSplitDirective(const OMPSplitDirective &s)
const CIRGenModule & getCIRGenModule() const
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.
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...
unsigned counterRefTmp
Hold counters for incrementally naming temporaries.
mlir::MLIRContext & getMLIRContext()
mlir::LogicalResult emitOpenACCEnterDataConstruct(const OpenACCEnterDataConstruct &s)
Destroyer * getDestroyer(clang::QualType::DestructionKind kind)
mlir::Value emitRuntimeCall(mlir::Location loc, cir::FuncOp callee, llvm::ArrayRef< mlir::Value > args={}, mlir::NamedAttrList attrs={})
void Destroyer(CIRGenFunction &cgf, Address addr, QualType ty)
void emitDestructorBody(FunctionArgList &args)
Emits the body of the current destructor.
LValue emitInitListLValue(const InitListExpr *e)
mlir::Value arrayInitIndex
The current array initialization index when evaluating an ArrayInitIndexExpr within an ArrayInitLoopE...
void emitAtomicInit(Expr *init, LValue dest)
void popCleanupBlock(bool forDeactivation=false)
Pop a cleanup block from the stack.
LValue emitCastLValue(const CastExpr *e)
Casts are never lvalues unless that cast is to a reference type.
LValue emitCXXTypeidLValue(const CXXTypeidExpr *e)
mlir::LogicalResult emitOMPTargetExitDataDirective(const OMPTargetExitDataDirective &s)
mlir::Value emitLoadOfScalar(LValue lvalue, SourceLocation loc)
EmitLoadOfScalar - Load a scalar value from an address, taking care to appropriately convert from the...
mlir::Value emitScalarPrePostIncDec(const UnaryOperator *e, LValue lv)
bool containsLabel(const clang::Stmt *s, bool ignoreCaseStmts=false)
Return true if the statement contains a label in it.
DeclMapTy localDeclMap
This keeps track of the CIR allocas or globals for local C declarations.
mlir::Value createOpenACCConstantInt(mlir::Location loc, unsigned width, int64_t value)
RValue emitPseudoObjectRValue(const PseudoObjectExpr *e, AggValueSlot slot=AggValueSlot::ignored())
LValue emitDeclRefLValue(const clang::DeclRefExpr *e)
mlir::LogicalResult emitOMPTargetTeamsDistributeParallelForDirective(const OMPTargetTeamsDistributeParallelForDirective &s)
void emitComplexExprIntoLValue(const Expr *e, LValue dest, bool isInit)
void pushEHDestroyIfNeeded(QualType::DestructionKind dtorKind, Address addr, QualType type)
pushEHDestroyIfNeeded - Push the standard destructor for the given type as an EH-only cleanup.
void emitOMPThreadPrivateDecl(const OMPThreadPrivateDecl &d)
std::optional< mlir::Value > emitNVPTXBuiltinExpr(unsigned builtinID, const CallExpr *expr)
Emit a call to an NVPTX builtin function.
void emitOMPGroupPrivateDecl(const OMPGroupPrivateDecl &d)
llvm::DenseMap< const clang::ValueDecl *, clang::FieldDecl * > lambdaCaptureFields
mlir::LogicalResult emitOMPParallelForDirective(const OMPParallelForDirective &s)
RValue emitCoawaitExpr(const CoawaitExpr &e, AggValueSlot aggSlot=AggValueSlot::ignored(), bool ignoreResult=false)
ConstantEmission tryEmitAsConstant(const DeclRefExpr *refExpr)
Try to emit a reference to the given value without producing it as an l-value.
mlir::Value emitAlignmentAssumption(mlir::Value ptrValue, QualType ty, SourceLocation loc, SourceLocation assumptionLoc, int64_t alignment, mlir::Value offsetValue=nullptr)
mlir::LogicalResult emitCaseDefaultCascade(const T *stmt, mlir::Type condType, mlir::ArrayAttr value, cir::CaseOpKind kind, bool buildingTopLevelCase)
void emitCXXThrowExpr(const CXXThrowExpr *e)
mlir::LogicalResult emitOMPSectionsDirective(const OMPSectionsDirective &s)
LValue makeAddrLValue(Address addr, QualType ty, AlignmentSource source=AlignmentSource::Type)
int64_t getAccessedFieldNo(unsigned idx, mlir::ArrayAttr elts)
LValue emitPredefinedLValue(const PredefinedExpr *e)
mlir::LogicalResult emitOMPDistributeDirective(const OMPDistributeDirective &s)
RValue emitAnyExpr(const clang::Expr *e, AggValueSlot aggSlot=AggValueSlot::ignored(), bool ignoreResult=false)
Emit code to compute the specified expression which can have any type.
mlir::LogicalResult emitOMPTargetTeamsDistributeParallelForSimdDirective(const OMPTargetTeamsDistributeParallelForSimdDirective &s)
void emitCXXDestructorCall(const CXXDestructorDecl *dd, CXXDtorType type, bool forVirtualBase, bool delegating, Address thisAddr, QualType thisTy)
mlir::LogicalResult emitOMPTargetTeamsGenericLoopDirective(const OMPTargetTeamsGenericLoopDirective &s)
llvm::SmallVector< VPtr, 4 > VPtrsVector
void emitLambdaStaticInvokeBody(const CXXMethodDecl *md)
bool sawAsmBlock
Whether or not a Microsoft-style asm block has been processed within this fuction.
mlir::LogicalResult emitDeclStmt(const clang::DeclStmt &s)
mlir::LogicalResult emitOMPTeamsDistributeSimdDirective(const OMPTeamsDistributeSimdDirective &s)
llvm::DenseMap< const OpaqueValueExpr *, RValue > opaqueRValues
RValue emitNewOrDeleteBuiltinCall(const FunctionProtoType *type, const CallExpr *callExpr, OverloadedOperatorKind op)
mlir::LogicalResult emitDefaultStmt(const clang::DefaultStmt &s, mlir::Type condType, bool buildingTopLevelCase)
mlir::LogicalResult emitWhileStmt(const clang::WhileStmt &s)
mlir::LogicalResult emitLabelStmt(const clang::LabelStmt &s)
Address emitArrayToPointerDecay(const Expr *e, LValueBaseInfo *baseInfo=nullptr)
std::pair< mlir::Value, mlir::Type > emitAsmInput(const TargetInfo::ConstraintInfo &info, const Expr *inputExpr, std::string &constraintString)
EHScopeStack::stable_iterator currentCleanupStackDepth
void emitCXXAggrConstructorCall(const CXXConstructorDecl *ctor, const clang::ArrayType *arrayType, Address arrayBegin, const CXXConstructExpr *e, bool newPointerIsChecked, bool zeroInitialize=false)
Emit a loop to call a particular constructor for each of several members of an array.
void pushFullExprCleanup(CleanupKind kind, As... a)
Push a cleanup to be run at the end of the current full-expression.
void emitDelegateCallArg(CallArgList &args, const clang::VarDecl *param, clang::SourceLocation loc)
We are performing a delegate call; that is, the current function is delegating to another one.
mlir::LogicalResult emitOMPTaskLoopSimdDirective(const OMPTaskLoopSimdDirective &s)
void emitAtomicStore(RValue rvalue, LValue dest, bool isInit)
mlir::Value emitStoreThroughBitfieldLValue(RValue src, LValue dstresult)
llvm::DenseMap< const OpaqueValueExpr *, LValue > opaqueLValues
Keeps track of the current set of opaque value expressions.
const CIRGenFunctionInfo * curFnInfo
CIRGenFunction(CIRGenModule &cgm, CIRGenBuilderTy &builder, bool suppressNewContext=false)
std::optional< mlir::Location > currSrcLoc
Use to track source locations across nested visitor traversals.
void terminateStructuredRegionBody(mlir::Region &r, mlir::Location loc)
Address createMemTempWithoutCast(QualType t, mlir::Location loc, const Twine &name="tmp")
LValue emitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *e)
LValue emitExtVectorElementExpr(const ExtVectorElementExpr *e)
clang::ASTContext & getContext() const
RValue emitCXXMemberOrOperatorMemberCallExpr(const clang::CallExpr *ce, const clang::CXXMethodDecl *md, ReturnValueSlot returnValue, bool hasQualifier, clang::NestedNameSpecifier qualifier, bool isArrow, const clang::Expr *base)
void setAddrOfLocalVar(const clang::VarDecl *vd, Address addr)
Set the address of a local variable.
mlir::Value emitScalarConstant(const ConstantEmission &constant, Expr *e)
RValue emitBuiltinExpr(const clang::GlobalDecl &gd, unsigned builtinID, const clang::CallExpr *e, ReturnValueSlot returnValue)
void emitInheritedCXXConstructorCall(const CXXConstructorDecl *d, bool forVirtualBase, Address thisAddr, bool inheritedFromVBase, const CXXInheritedCtorInitExpr *e)
void emitCXXDeleteExpr(const CXXDeleteExpr *e)
mlir::LogicalResult emitCoroutineBody(const CoroutineBodyStmt &s)
void pushCleanupAfterFullExpr(CleanupKind kind, Address addr, QualType type, Destroyer *destroyer)
Queue a cleanup to be pushed after finishing the current full-expression.
RValue emitCXXOperatorMemberCallExpr(const CXXOperatorCallExpr *e, const CXXMethodDecl *md, ReturnValueSlot returnValue)
mlir::LogicalResult emitCompoundStmt(const clang::CompoundStmt &s, Address *lastValue=nullptr, AggValueSlot slot=AggValueSlot::ignored())
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...
mlir::LogicalResult emitGotoStmt(const clang::GotoStmt &s)
std::optional< mlir::Value > emitAArch64SVEBuiltinExpr(unsigned builtinID, const CallExpr *expr)
cir::CallOp emitCoroBeginBuiltinCall(mlir::Location loc, mlir::Value coroframeAddr)
void emitOMPCapturedExpr(const OMPCapturedExprDecl &d)
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 ...
mlir::LogicalResult emitOMPParallelMasterTaskLoopDirective(const OMPParallelMasterTaskLoopDirective &s)
bool isLValueSuitableForInlineAtomic(LValue lv)
An LValue is a candidate for having its loads and stores be made atomic if we are operating under /vo...
mlir::LogicalResult emitStmt(const clang::Stmt *s, bool useCurrentScope, llvm::ArrayRef< const Attr * > attrs={})
void pushLifetimeExtendedDestroy(CleanupKind kind, Address addr, QualType type, Destroyer *destroyer, bool useEHCleanupForArray)
RValue getOrCreateOpaqueRValueMapping(const OpaqueValueExpr *e)
Given an opaque value expression, return its RValue mapping if it exists, otherwise create one.
mlir::LogicalResult emitOMPCancelDirective(const OMPCancelDirective &s)
Address createTempAllocaWithoutCast(mlir::Type ty, CharUnits align, mlir::Location loc, const Twine &name="tmp", mlir::Value arraySize=nullptr, mlir::OpBuilder::InsertPoint ip={})
This creates a alloca and inserts it into the entry block of the current region.
mlir::Value emitFromMemory(mlir::Value value, clang::QualType ty)
EmitFromMemory - Change a scalar value from its memory representation to its value representation.
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 emitOMPStripeDirective(const OMPStripeDirective &s)
mlir::LogicalResult emitOMPTargetTeamsDistributeDirective(const OMPTargetTeamsDistributeDirective &s)
mlir::LogicalResult emitCompoundStmtWithoutScope(const clang::CompoundStmt &s, Address *lastValue=nullptr, AggValueSlot slot=AggValueSlot::ignored())
mlir::LogicalResult emitOMPParallelSectionsDirective(const OMPParallelSectionsDirective &s)
mlir::LogicalResult emitOpenACCExitDataConstruct(const OpenACCExitDataConstruct &s)
void emitIgnoredExpr(const clang::Expr *e)
Emit code to compute the specified expression, ignoring the result.
Address createMemTemp(QualType t, mlir::Location loc, const Twine &name="tmp", Address *alloca=nullptr, mlir::OpBuilder::InsertPoint ip={})
Create a temporary memory object of the given type, with appropriate alignmen and cast it to the defa...
void emitDelegatingCXXConstructorCall(const CXXConstructorDecl *ctor, const FunctionArgList &args)
mlir::Value emitDynamicCast(Address thisAddr, const CXXDynamicCastExpr *dce)
void emitAggExpr(const clang::Expr *e, AggValueSlot slot)
mlir::Value emitScalarOrConstFoldImmArg(unsigned iceArguments, unsigned idx, const Expr *argExpr)
ConditionalInfo emitConditionalBlocks(const AbstractConditionalOperator *e, const FuncTy &branchGenFunc)
Address createDefaultAlignTempAlloca(mlir::Type ty, mlir::Location loc, const Twine &name)
CreateDefaultAlignTempAlloca - This creates an alloca with the default alignment of the corresponding...
mlir::Value emitAlloca(llvm::StringRef name, mlir::Type ty, mlir::Location loc, clang::CharUnits alignment, mlir::OpBuilder::InsertPoint ip, mlir::Value arraySize=nullptr)
mlir::LogicalResult emitOpenACCAtomicConstruct(const OpenACCAtomicConstruct &s)
mlir::LogicalResult emitOMPTargetSimdDirective(const OMPTargetSimdDirective &s)
LValue emitCXXConstructLValue(const CXXConstructExpr *e)
void finishThunk()
Finish generating a thunk function.
mlir::LogicalResult emitOMPAssumeDirective(const OMPAssumeDirective &s)
mlir::Value emitVAArg(VAArgExpr *ve)
Generate code to get an argument from the passed in pointer and update it accordingly.
RValue emitCXXPseudoDestructorExpr(const CXXPseudoDestructorExpr *expr)
LValue emitCompoundLiteralLValue(const CompoundLiteralExpr *e)
void emitAutoVarCleanups(const AutoVarEmission &emission)
RValue emitRotate(const CallExpr *e, bool isRotateLeft)
mlir::LogicalResult emitOpenACCLoopConstruct(const OpenACCLoopConstruct &s)
CIRGenCallee emitCallee(const clang::Expr *e)
Address emitAddrOfFieldStorage(Address base, const FieldDecl *field, llvm::StringRef fieldName, unsigned fieldIndex)
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.
This class organizes the cross-module state that is used while lowering AST types to CIR types.
Definition CIRGenTypes.h:50
A saved depth on the scope stack.
A stack of scopes which respond to exceptions, including cleanups and catch blocks.
Type for representing both the decl and type of parameters to a function.
Definition CIRGenCall.h:193
static LValue makeAddr(Address address, clang::QualType t, LValueBaseInfo baseInfo)
This trivial value class is used to represent the result of an expression that is evaluated.
Definition CIRGenValue.h:33
static RValue get(mlir::Value v)
Definition CIRGenValue.h:83
Contains the address where the return value of a function can be stored, and whether the address is v...
Definition CIRGenCall.h:260
Represents a call to a CUDA kernel function.
Definition ExprCXX.h:238
Represents binding an expression to a temporary.
Definition ExprCXX.h:1497
CXXCatchStmt - This represents a C++ catch block.
Definition StmtCXX.h:28
Represents a call to a C++ constructor.
Definition ExprCXX.h:1552
Represents a C++ constructor within a class.
Definition DeclCXX.h:2633
Represents a C++ base or member initializer.
Definition DeclCXX.h:2398
A default argument (C++ [dcl.fct.default]).
Definition ExprCXX.h:1274
A use of a default initializer in a constructor or in aggregate initialization.
Definition ExprCXX.h:1381
Represents a delete expression for memory deallocation and destructor calls, e.g.
Definition ExprCXX.h:2630
Represents a C++ destructor within a class.
Definition DeclCXX.h:2895
A C++ dynamic_cast expression (C++ [expr.dynamic.cast]).
Definition ExprCXX.h:485
CXXForRangeStmt - This represents C++0x [stmt.ranged]'s ranged for statement, represented as 'for (ra...
Definition StmtCXX.h:135
Represents a call to an inherited base class constructor from an inheriting constructor.
Definition ExprCXX.h:1755
Represents a call to a member function that may be written either with member call syntax (e....
Definition ExprCXX.h:183
Represents a static or instance method of a struct/union/class.
Definition DeclCXX.h:2145
Represents a new-expression for memory allocation and constructor calls, e.g: "new CXXNewExpr(foo)".
Definition ExprCXX.h:2359
A call to an overloaded operator written using operator syntax.
Definition ExprCXX.h:85
Represents a C++ pseudo-destructor (C++ [expr.pseudo]).
Definition ExprCXX.h:2749
Represents a C++ struct/union/class.
Definition DeclCXX.h:258
Represents a C++ temporary.
Definition ExprCXX.h:1463
A C++ throw-expression (C++ [except.throw]).
Definition ExprCXX.h:1212
CXXTryStmt - A C++ try block, including all handlers.
Definition StmtCXX.h:69
A C++ typeid expression (C++ [expr.typeid]), which gets the type_info that corresponds to the supplie...
Definition ExprCXX.h:852
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition Expr.h:2946
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
Definition Expr.h:3150
CaseStmt - Represent a case statement.
Definition Stmt.h:1930
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
Definition Expr.h:3679
CharUnits - This is an opaque type for sizes expressed in character units.
Definition CharUnits.h:38
bool isZero() const
isZero - Test whether the quantity equals zero.
Definition CharUnits.h:122
llvm::Align getAsAlign() const
getAsAlign - Returns Quantity as a valid llvm::Align, Beware llvm::Align assumes power of two 8-bit b...
Definition CharUnits.h:189
CompoundAssignOperator - For compound assignments (e.g.
Definition Expr.h:4303
CompoundLiteralExpr - [C99 6.5.2.5].
Definition Expr.h:3608
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition Stmt.h:1750
ContinueStmt - This represents a continue.
Definition Stmt.h:3129
Represents a 'co_return' statement in the C++ Coroutines TS.
Definition StmtCXX.h:473
Represents the body of a coroutine.
Definition StmtCXX.h:320
SourceLocExprScopeGuard(const Expr *DefaultExpr, CurrentSourceLocExprScope &Current)
Represents the current source location and context used to determine the value of the source location...
A reference to a declared variable, function, enum, etc.
Definition Expr.h:1273
DeclStmt - Adaptor class for mixing declarations with statements and expressions.
Definition Stmt.h:1641
Decl - This represents one declaration (or definition), e.g.
Definition DeclBase.h:86
DoStmt - This represents a 'do/while' stmt.
Definition Stmt.h:2842
This represents one expression.
Definition Expr.h:112
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
Definition Expr.cpp:283
QualType getType() const
Definition Expr.h:144
ExtVectorElementExpr - This represents access to specific elements of a vector, and may occur on the ...
Definition Expr.h:6610
Represents a member of a struct/union/class.
Definition Decl.h:3182
ForStmt - This represents a 'for (init;cond;inc)' stmt.
Definition Stmt.h:2898
Represents a function declaration or definition.
Definition Decl.h:2018
Represents a prototype with parameter type info, e.g.
Definition TypeBase.h:5371
GlobalDecl - represents a global declaration.
Definition GlobalDecl.h:57
const Decl * getDecl() const
Definition GlobalDecl.h:106
GotoStmt - This represents a direct goto.
Definition Stmt.h:2979
IndirectGotoStmt - This represents an indirect goto.
Definition Stmt.h:3018
Describes an C or C++ initializer list.
Definition Expr.h:5302
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
Definition Expr.h:3367
A pointer to member type per C++ 8.3.3 - Pointers to members.
Definition TypeBase.h:3717
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
This represents 'pragma omp allocate ...' directive.
Definition DeclOpenMP.h:536
Pseudo declaration for capturing expressions.
Definition DeclOpenMP.h:445
This represents 'pragma omp declare mapper ...' directive.
Definition DeclOpenMP.h:349
This represents 'pragma omp declare reduction ...' directive.
Definition DeclOpenMP.h:239
This represents 'pragma omp groupprivate ...' directive.
Definition DeclOpenMP.h:173
This represents 'pragma omp requires...' directive.
Definition DeclOpenMP.h:479
This represents 'pragma omp threadprivate ...' directive.
Definition DeclOpenMP.h:110
ObjCMethodDecl - Represents an instance or class method declaration.
Definition DeclObjC.h:140
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.
Definition Expr.h:1181
Expr * getSourceExpr() const
The source expression of an opaque value expression is the expression which originally generated the ...
Definition Expr.h:1231
Represents a parameter to a function.
Definition Decl.h:1808
[C99 6.4.2.2] - A predefined identifier such as func.
Definition Expr.h:2008
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
Definition Expr.h:6804
A (possibly-)qualified type.
Definition TypeBase.h:937
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
Definition TypeBase.h:8487
The collection of all-type qualifiers we support.
Definition TypeBase.h:331
Flags to identify the types for overloaded SVE builtins.
Encodes a location in the source.
A trivial tuple used to represent a source range.
Stmt - This represents one statement.
Definition Stmt.h:86
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
Definition Stmt.cpp:343
Exposes information about the current target.
Definition TargetInfo.h:227
Represents a declaration of a type.
Definition Decl.h:3535
RecordDecl * getAsRecordDecl() const
Retrieves the RecordDecl this type refers to.
Definition Type.h:41
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Definition Expr.h:2247
Represents a call to the builtin function __builtin_va_arg.
Definition Expr.h:4960
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition Decl.h:712
Represents a variable declaration or definition.
Definition Decl.h:924
Represents a C array with a specified size that is not an integer-constant-expression.
Definition TypeBase.h:4030
AlignmentSource
The source of the alignment of an l-value; an expression of confidence in the alignment actually matc...
@ 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 ...
@ NormalCleanup
Denotes a cleanup that should run when a scope is exited using normal control flow (falling off the e...
const internal::VariadicDynCastAllOfMatcher< Decl, VarDecl > varDecl
Matches variable declarations.
const internal::VariadicDynCastAllOfMatcher< Stmt, CallExpr > callExpr
Matches call expressions.
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
const AstTypeMatcher< ArrayType > arrayType
const internal::VariadicAllOfMatcher< Stmt > stmt
Matches statements.
const internal::VariadicDynCastAllOfMatcher< Stmt, Expr > expr
Matches expressions.
@ Address
A pointer to a ValueDecl.
Definition Primitives.h:28
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.
CXXCtorType
C++ constructor types.
Definition ABI.h:24
OpenACCDirectiveKind
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
OpenACCComputeConstruct(OpenACCDirectiveKind K, SourceLocation Start, SourceLocation DirectiveLoc, SourceLocation End, ArrayRef< const OpenACCClause * > Clauses, Stmt *StructuredBlock)
CXXDtorType
C++ destructor types.
Definition ABI.h:34
U cast(CodeGen::Address addr)
Definition Address.h:327
#define true
Definition stdbool.h:25
static bool aggValueSlot()
static bool peepholeProtection()
static bool opAllocaEscapeByReference()
static bool generateDebugInfo()
AutoVarEmission(const clang::VarDecl &variable)
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.
bool emittedAsOffload
True if the variable was emitted as an offload recipe, and thus doesn't have the same sort of alloca ...
bool isConstantAggregate
True if the variable is of aggregate type and has a constant initializer.
Address getAllocatedAddress() const
Returns the raw, allocated address, which is not necessarily the address of the object itself.
Address getObjectAddress(CIRGenFunction &cgf) const
Returns the address of the object within this declaration.
std::unique_ptr< CGCoroData > data
CXXDefaultArgExprScope(CIRGenFunction &cfg, const CXXDefaultArgExpr *e)
Scope that deactivates all enclosed deferred cleanups on exit.
A cleanup that was pushed to the EH stack but whose deactivation is deferred until the enclosing Clea...
Represents a scope, including function bodies, compound statements, and the substatements of if/while...
llvm::ArrayRef< mlir::Block * > getRetBlocks()
mlir::Block * getOrCreateRetBlock(CIRGenFunction &cgf, mlir::Location loc)
LexicalScope(CIRGenFunction &cgf, mlir::Location loc, mlir::Block *eb)
void updateRetLoc(mlir::Block *b, mlir::Location loc)
mlir::Location getRetLoc(mlir::Block *b)
A cleanup entry that will be promoted onto the EH scope stack at a later point.
llvm::PointerUnion< const clang::FunctionProtoType *, const clang::ObjCMethodDecl * > p
PrototypeWrapper(const clang::ObjCMethodDecl *md)
PrototypeWrapper(const clang::FunctionProtoType *ft)
const clang::CXXRecordDecl * vtableClass
const clang::CXXRecordDecl * nearestVBase
VlaSizePair(mlir::Value num, QualType ty)
virtual mlir::LogicalResult operator()(CIRGenFunction &cgf)=0
The this pointer adjustment as well as an optional return adjustment for a thunk.
Definition Thunk.h:157