clang 22.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"
37#include "llvm/ADT/ScopedHashTable.h"
38
39namespace {
40class ScalarExprEmitter;
41} // namespace
42
43namespace mlir {
44namespace acc {
45class LoopOp;
46} // namespace acc
47} // namespace mlir
48
49namespace clang::CIRGen {
50
51struct CGCoroData;
52
54public:
56
57private:
58 friend class ::ScalarExprEmitter;
59 /// The builder is a helper class to create IR inside a function. The
60 /// builder is stateful, in particular it keeps an "insertion point": this
61 /// is where the next operations will be introduced.
62 CIRGenBuilderTy &builder;
63
64 /// A jump destination is an abstract label, branching to which may
65 /// require a jump out through normal cleanups.
66 struct JumpDest {
67 JumpDest() = default;
68 JumpDest(mlir::Block *block, EHScopeStack::stable_iterator depth = {},
69 unsigned index = 0)
70 : block(block) {}
71
72 bool isValid() const { return block != nullptr; }
73 mlir::Block *getBlock() const { return block; }
74 EHScopeStack::stable_iterator getScopeDepth() const { return scopeDepth; }
75 unsigned getDestIndex() const { return index; }
76
77 // This should be used cautiously.
78 void setScopeDepth(EHScopeStack::stable_iterator depth) {
79 scopeDepth = depth;
80 }
81
82 private:
83 mlir::Block *block = nullptr;
85 unsigned index;
86 };
87
88public:
89 /// The GlobalDecl for the current function being compiled or the global
90 /// variable currently being initialized.
92
93 /// Unified return block.
94 /// In CIR this is a function because each scope might have
95 /// its associated return block.
96 JumpDest returnBlock(mlir::Block *retBlock) {
97 return getJumpDestInCurrentScope(retBlock);
98 }
99
101
102 /// The compiler-generated variable that holds the return value.
103 std::optional<mlir::Value> fnRetAlloca;
104
105 // Holds coroutine data if the current function is a coroutine. We use a
106 // wrapper to manage its lifetime, so that we don't have to define CGCoroData
107 // in this header.
108 struct CGCoroInfo {
109 std::unique_ptr<CGCoroData> data;
110 CGCoroInfo();
111 ~CGCoroInfo();
112 };
114
115 bool isCoroutine() const { return curCoro.data != nullptr; }
116
117 /// The temporary alloca to hold the return value. This is
118 /// invalid iff the function has no return value.
120
121 /// Tracks function scope overall cleanup handling.
123
125
126 /// A mapping from NRVO variables to the flags used to indicate
127 /// when the NRVO has been applied to this variable.
128 llvm::DenseMap<const VarDecl *, mlir::Value> nrvoFlags;
129
130 llvm::DenseMap<const clang::ValueDecl *, clang::FieldDecl *>
133
134 /// CXXThisDecl - When generating code for a C++ member function,
135 /// this will hold the implicit 'this' declaration.
137 mlir::Value cxxabiThisValue = nullptr;
138 mlir::Value cxxThisValue = nullptr;
140
141 /// When generating code for a constructor or destructor, this will hold the
142 /// implicit argument (e.g. VTT).
145
146 /// The value of 'this' to sue when evaluating CXXDefaultInitExprs within this
147 /// expression.
149
150 // Holds the Decl for the current outermost non-closure context
151 const clang::Decl *curFuncDecl = nullptr;
152 /// This is the inner-most code context, which includes blocks.
153 const clang::Decl *curCodeDecl = nullptr;
154
155 /// The current function or global initializer that is generated code for.
156 /// This is usually a cir::FuncOp, but it can also be a cir::GlobalOp for
157 /// global initializers.
158 mlir::Operation *curFn = nullptr;
159
160 /// Save Parameter Decl for coroutine.
162
163 using DeclMapTy = llvm::DenseMap<const clang::Decl *, Address>;
164 /// This keeps track of the CIR allocas or globals for local C
165 /// declarations.
167
168 /// The type of the condition for the emitting switch statement.
170
171 clang::ASTContext &getContext() const { return cgm.getASTContext(); }
172
173 CIRGenBuilderTy &getBuilder() { return builder; }
174
176 const CIRGenModule &getCIRGenModule() const { return cgm; }
177
179 // We currently assume this isn't called for a global initializer.
180 auto fn = mlir::cast<cir::FuncOp>(curFn);
181 return &fn.getRegion().front();
182 }
183
184 /// Sanitizers enabled for this function.
186
187 /// The symbol table maps a variable name to a value in the current scope.
188 /// Entering a function creates a new scope, and the function arguments are
189 /// added to the mapping. When the processing of a function is terminated,
190 /// the scope is destroyed and the mappings created in this scope are
191 /// dropped.
192 using SymTableTy = llvm::ScopedHashTable<const clang::Decl *, mlir::Value>;
194
195 /// Whether a cir.stacksave operation has been added. Used to avoid
196 /// inserting cir.stacksave for multiple VLAs in the same scope.
197 bool didCallStackSave = false;
198
199 /// Whether or not a Microsoft-style asm block has been processed within
200 /// this fuction. These can potentially set the return value.
201 bool sawAsmBlock = false;
202
203 mlir::Type convertTypeForMem(QualType t);
204
205 mlir::Type convertType(clang::QualType t);
206 mlir::Type convertType(const TypeDecl *t) {
207 return convertType(getContext().getTypeDeclType(t));
208 }
209
210 /// Get integer from a mlir::Value that is an int constant or a constant op.
211 static int64_t getSExtIntValueFromConstOp(mlir::Value val) {
212 auto constOp = val.getDefiningOp<cir::ConstantOp>();
213 assert(constOp && "getIntValueFromConstOp call with non ConstantOp");
214 return constOp.getIntValue().getSExtValue();
215 }
216
217 /// Get zero-extended integer from a mlir::Value that is an int constant or a
218 /// constant op.
219 static int64_t getZExtIntValueFromConstOp(mlir::Value val) {
220 auto constOp = val.getDefiningOp<cir::ConstantOp>();
221 assert(constOp &&
222 "getZeroExtendedIntValueFromConstOp call with non ConstantOp");
223 return constOp.getIntValue().getZExtValue();
224 }
225
226 /// Return the cir::TypeEvaluationKind of QualType \c type.
228
232
236
238 bool suppressNewContext = false);
240
241 CIRGenTypes &getTypes() const { return cgm.getTypes(); }
242
243 const TargetInfo &getTarget() const { return cgm.getTarget(); }
244 mlir::MLIRContext &getMLIRContext() { return cgm.getMLIRContext(); }
245
247 return cgm.getTargetCIRGenInfo();
248 }
249
250 // ---------------------
251 // Opaque value handling
252 // ---------------------
253
254 /// Keeps track of the current set of opaque value expressions.
255 llvm::DenseMap<const OpaqueValueExpr *, LValue> opaqueLValues;
256 llvm::DenseMap<const OpaqueValueExpr *, RValue> opaqueRValues;
257
258 // This keeps track of the associated size for each VLA type.
259 // We track this by the size expression rather than the type itself because
260 // in certain situations, like a const qualifier applied to an VLA typedef,
261 // multiple VLA types can share the same size expression.
262 // FIXME: Maybe this could be a stack of maps that is pushed/popped as we
263 // enter/leave scopes.
264 llvm::DenseMap<const Expr *, mlir::Value> vlaSizeMap;
265
266public:
267 /// A non-RAII class containing all the information about a bound
268 /// opaque value. OpaqueValueMapping, below, is a RAII wrapper for
269 /// this which makes individual mappings very simple; using this
270 /// class directly is useful when you have a variable number of
271 /// opaque values or don't want the RAII functionality for some
272 /// reason.
273 class OpaqueValueMappingData {
274 const OpaqueValueExpr *opaqueValue;
275 bool boundLValue;
276
277 OpaqueValueMappingData(const OpaqueValueExpr *ov, bool boundLValue)
278 : opaqueValue(ov), boundLValue(boundLValue) {}
279
280 public:
281 OpaqueValueMappingData() : opaqueValue(nullptr) {}
282
283 static bool shouldBindAsLValue(const Expr *expr) {
284 // gl-values should be bound as l-values for obvious reasons.
285 // Records should be bound as l-values because IR generation
286 // always keeps them in memory. Expressions of function type
287 // act exactly like l-values but are formally required to be
288 // r-values in C.
289 return expr->isGLValue() || expr->getType()->isFunctionType() ||
291 }
292
294 bind(CIRGenFunction &cgf, const OpaqueValueExpr *ov, const Expr *e) {
295 if (shouldBindAsLValue(ov))
296 return bind(cgf, ov, cgf.emitLValue(e));
297 return bind(cgf, ov, cgf.emitAnyExpr(e));
298 }
299
301 bind(CIRGenFunction &cgf, const OpaqueValueExpr *ov, const LValue &lv) {
302 assert(shouldBindAsLValue(ov));
303 cgf.opaqueLValues.insert(std::make_pair(ov, lv));
304 return OpaqueValueMappingData(ov, true);
305 }
306
308 bind(CIRGenFunction &cgf, const OpaqueValueExpr *ov, const RValue &rv) {
309 assert(!shouldBindAsLValue(ov));
310 cgf.opaqueRValues.insert(std::make_pair(ov, rv));
311
312 OpaqueValueMappingData data(ov, false);
313
314 // Work around an extremely aggressive peephole optimization in
315 // EmitScalarConversion which assumes that all other uses of a
316 // value are extant.
318 return data;
319 }
320
321 bool isValid() const { return opaqueValue != nullptr; }
322 void clear() { opaqueValue = nullptr; }
323
325 assert(opaqueValue && "no data to unbind!");
326
327 if (boundLValue) {
328 cgf.opaqueLValues.erase(opaqueValue);
329 } else {
330 cgf.opaqueRValues.erase(opaqueValue);
332 }
333 }
334 };
335
336 /// An RAII object to set (and then clear) a mapping for an OpaqueValueExpr.
338 CIRGenFunction &cgf;
340
341 public:
345
346 /// Build the opaque value mapping for the given conditional
347 /// operator if it's the GNU ?: extension. This is a common
348 /// enough pattern that the convenience operator is really
349 /// helpful.
350 ///
353 : cgf(cgf) {
354 if (mlir::isa<ConditionalOperator>(op))
355 // Leave Data empty.
356 return;
357
359 mlir::cast<BinaryConditionalOperator>(op);
361 e->getCommon());
362 }
363
364 /// Build the opaque value mapping for an OpaqueValueExpr whose source
365 /// expression is set to the expression the OVE represents.
367 : cgf(cgf) {
368 if (ov) {
369 assert(ov->getSourceExpr() && "wrong form of OpaqueValueMapping used "
370 "for OVE with no source expression");
371 data = OpaqueValueMappingData::bind(cgf, ov, ov->getSourceExpr());
372 }
373 }
374
376 LValue lvalue)
377 : cgf(cgf),
378 data(OpaqueValueMappingData::bind(cgf, opaqueValue, lvalue)) {}
379
381 RValue rvalue)
382 : cgf(cgf),
383 data(OpaqueValueMappingData::bind(cgf, opaqueValue, rvalue)) {}
384
385 void pop() {
386 data.unbind(cgf);
387 data.clear();
388 }
389
391 if (data.isValid())
392 data.unbind(cgf);
393 }
394 };
395
396private:
397 /// Declare a variable in the current scope, return success if the variable
398 /// wasn't declared yet.
399 void declare(mlir::Value addrVal, const clang::Decl *var, clang::QualType ty,
400 mlir::Location loc, clang::CharUnits alignment,
401 bool isParam = false);
402
403public:
404 mlir::Value createDummyValue(mlir::Location loc, clang::QualType qt);
405
406 void emitNullInitialization(mlir::Location loc, Address destPtr, QualType ty);
407
408private:
409 // Track current variable initialization (if there's one)
410 const clang::VarDecl *currVarDecl = nullptr;
411 class VarDeclContext {
413 const clang::VarDecl *oldVal = nullptr;
414
415 public:
416 VarDeclContext(CIRGenFunction &p, const VarDecl *value) : p(p) {
417 if (p.currVarDecl)
418 oldVal = p.currVarDecl;
419 p.currVarDecl = value;
420 }
421
422 /// Can be used to restore the state early, before the dtor
423 /// is run.
424 void restore() { p.currVarDecl = oldVal; }
425 ~VarDeclContext() { restore(); }
426 };
427
428public:
429 /// Use to track source locations across nested visitor traversals.
430 /// Always use a `SourceLocRAIIObject` to change currSrcLoc.
431 std::optional<mlir::Location> currSrcLoc;
433 CIRGenFunction &cgf;
434 std::optional<mlir::Location> oldLoc;
435
436 public:
437 SourceLocRAIIObject(CIRGenFunction &cgf, mlir::Location value) : cgf(cgf) {
438 if (cgf.currSrcLoc)
439 oldLoc = cgf.currSrcLoc;
440 cgf.currSrcLoc = value;
441 }
442
443 /// Can be used to restore the state early, before the dtor
444 /// is run.
445 void restore() { cgf.currSrcLoc = oldLoc; }
447 };
448
450 llvm::ScopedHashTableScope<const clang::Decl *, mlir::Value>;
451
452 /// Hold counters for incrementally naming temporaries
453 unsigned counterRefTmp = 0;
454 unsigned counterAggTmp = 0;
455 std::string getCounterRefTmpAsString();
456 std::string getCounterAggTmpAsString();
457
458 /// Helpers to convert Clang's SourceLocation to a MLIR Location.
459 mlir::Location getLoc(clang::SourceLocation srcLoc);
460 mlir::Location getLoc(clang::SourceRange srcLoc);
461 mlir::Location getLoc(mlir::Location lhs, mlir::Location rhs);
462
463 const clang::LangOptions &getLangOpts() const { return cgm.getLangOpts(); }
464
465 /// True if an insertion point is defined. If not, this indicates that the
466 /// current code being emitted is unreachable.
467 /// FIXME(cir): we need to inspect this and perhaps use a cleaner mechanism
468 /// since we don't yet force null insertion point to designate behavior (like
469 /// LLVM's codegen does) and we probably shouldn't.
470 bool haveInsertPoint() const {
471 return builder.getInsertionBlock() != nullptr;
472 }
473
474 // Wrapper for function prototype sources. Wraps either a FunctionProtoType or
475 // an ObjCMethodDecl.
477 llvm::PointerUnion<const clang::FunctionProtoType *,
478 const clang::ObjCMethodDecl *>
480
483 };
484
486
487 /// An abstract representation of regular/ObjC call/message targets.
489 /// The function declaration of the callee.
490 [[maybe_unused]] const clang::Decl *calleeDecl;
491
492 public:
493 AbstractCallee() : calleeDecl(nullptr) {}
494 AbstractCallee(const clang::FunctionDecl *fd) : calleeDecl(fd) {}
495
496 bool hasFunctionDecl() const {
497 return llvm::isa_and_nonnull<clang::FunctionDecl>(calleeDecl);
498 }
499
500 unsigned getNumParams() const {
501 if (const auto *fd = llvm::dyn_cast<clang::FunctionDecl>(calleeDecl))
502 return fd->getNumParams();
503 return llvm::cast<clang::ObjCMethodDecl>(calleeDecl)->param_size();
504 }
505
506 const clang::ParmVarDecl *getParamDecl(unsigned I) const {
507 if (const auto *fd = llvm::dyn_cast<clang::FunctionDecl>(calleeDecl))
508 return fd->getParamDecl(I);
509 return *(llvm::cast<clang::ObjCMethodDecl>(calleeDecl)->param_begin() +
510 I);
511 }
512 };
513
514 struct VlaSizePair {
515 mlir::Value numElts;
517
518 VlaSizePair(mlir::Value num, QualType ty) : numElts(num), type(ty) {}
519 };
520
521 /// Return the number of elements for a single dimension
522 /// for the given array type.
523 VlaSizePair getVLAElements1D(const VariableArrayType *vla);
524
525 /// Returns an MLIR::Value+QualType pair that corresponds to the size,
526 /// in non-variably-sized elements, of a variable length array type,
527 /// plus that largest non-variably-sized element type. Assumes that
528 /// the type has already been emitted with emitVariablyModifiedType.
529 VlaSizePair getVLASize(const VariableArrayType *type);
530 VlaSizePair getVLASize(QualType type);
531
533
534 mlir::Value getAsNaturalPointerTo(Address addr, QualType pointeeType) {
535 return getAsNaturalAddressOf(addr, pointeeType).getBasePointer();
536 }
537
538 void finishFunction(SourceLocation endLoc);
539
540 /// Determine whether the given initializer is trivial in the sense
541 /// that it requires no code to be generated.
542 bool isTrivialInitializer(const Expr *init);
543
544 /// If the specified expression does not fold to a constant, or if it does but
545 /// contains a label, return false. If it constant folds return true and set
546 /// the boolean result in Result.
547 bool constantFoldsToBool(const clang::Expr *cond, bool &resultBool,
548 bool allowLabels = false);
550 llvm::APSInt &resultInt,
551 bool allowLabels = false);
552
553 /// Return true if the statement contains a label in it. If
554 /// this statement is not executed normally, it not containing a label means
555 /// that we can just remove the code.
556 bool containsLabel(const clang::Stmt *s, bool ignoreCaseStmts = false);
557
558 Address emitExtVectorElementLValue(LValue lv, mlir::Location loc);
559
560 class ConstantEmission {
561 // Cannot use mlir::TypedAttr directly here because of bit availability.
562 llvm::PointerIntPair<mlir::Attribute, 1, bool> valueAndIsReference;
563 ConstantEmission(mlir::TypedAttr c, bool isReference)
564 : valueAndIsReference(c, isReference) {}
565
566 public:
568 static ConstantEmission forReference(mlir::TypedAttr c) {
569 return ConstantEmission(c, true);
570 }
571 static ConstantEmission forValue(mlir::TypedAttr c) {
572 return ConstantEmission(c, false);
573 }
574
575 explicit operator bool() const {
576 return valueAndIsReference.getOpaqueValue() != nullptr;
577 }
578
579 bool isReference() const { return valueAndIsReference.getInt(); }
581 assert(isReference());
582 cgf.cgm.errorNYI(refExpr->getSourceRange(),
583 "ConstantEmission::getReferenceLValue");
584 return {};
585 }
586
587 mlir::TypedAttr getValue() const {
588 assert(!isReference());
589 return mlir::cast<mlir::TypedAttr>(valueAndIsReference.getPointer());
590 }
591 };
592
593 ConstantEmission tryEmitAsConstant(const DeclRefExpr *refExpr);
594 ConstantEmission tryEmitAsConstant(const MemberExpr *me);
595
598 /// The address of the alloca for languages with explicit address space
599 /// (e.g. OpenCL) or alloca casted to generic pointer for address space
600 /// agnostic languages (e.g. C++). Invalid if the variable was emitted
601 /// as a global constant.
603
604 /// True if the variable is of aggregate type and has a constant
605 /// initializer.
607
608 /// True if the variable is a __block variable that is captured by an
609 /// escaping block.
610 bool isEscapingByRef = false;
611
612 /// True if the variable was emitted as an offload recipe, and thus doesn't
613 /// have the same sort of alloca initialization.
614 bool emittedAsOffload = false;
615
616 mlir::Value nrvoFlag{};
617
618 struct Invalid {};
620
623
625
626 bool wasEmittedAsGlobal() const { return !addr.isValid(); }
627
629
630 /// Returns the raw, allocated address, which is not necessarily
631 /// the address of the object itself. It is casted to default
632 /// address space for address space agnostic languages.
633 Address getAllocatedAddress() const { return addr; }
634
635 // Changes the stored address for the emission. This function should only
636 // be used in extreme cases, and isn't required to model normal AST
637 // initialization/variables.
639
640 /// Returns the address of the object within this declaration.
641 /// Note that this does not chase the forwarding pointer for
642 /// __block decls.
644 if (!isEscapingByRef)
645 return addr;
646
648 return Address::invalid();
649 }
650 };
651
652 /// The given basic block lies in the current EH scope, but may be a
653 /// target of a potentially scope-crossing jump; get a stable handle
654 /// to which we can perform this jump later.
655 /// CIRGen: this mostly tracks state for figuring out the proper scope
656 /// information, no actual branches are emitted.
657 JumpDest getJumpDestInCurrentScope(mlir::Block *target) {
658 return JumpDest(target, ehStack.getInnermostNormalCleanup(),
660 }
661 /// IndirectBranch - The first time an indirect goto is seen we create a block
662 /// reserved for the indirect branch. Unlike before,the actual 'indirectbr'
663 /// is emitted at the end of the function, once all block destinations have
664 /// been resolved.
665 mlir::Block *indirectGotoBlock = nullptr;
666
669
670 /// Perform the usual unary conversions on the specified expression and
671 /// compare the result against zero, returning an Int1Ty value.
672 mlir::Value evaluateExprAsBool(const clang::Expr *e);
673
674 cir::GlobalOp addInitializerToStaticVarDecl(const VarDecl &d,
675 cir::GlobalOp gv,
676 cir::GetGlobalOp gvAddr);
677
678 /// Enter the cleanups necessary to complete the given phase of destruction
679 /// for a destructor. The end result should call destructors on members and
680 /// base classes in reverse order of their construction.
682
683 /// Determines whether an EH cleanup is required to destroy a type
684 /// with the given destruction kind.
685 /// TODO(cir): could be shared with Clang LLVM codegen
687 switch (kind) {
689 return false;
693 return getLangOpts().Exceptions;
695 return getLangOpts().Exceptions &&
696 cgm.getCodeGenOpts().ObjCAutoRefCountExceptions;
697 }
698 llvm_unreachable("bad destruction kind");
699 }
700
704
705 void pushStackRestore(CleanupKind kind, Address spMem);
706
707 /// Set the address of a local variable.
709 assert(!localDeclMap.count(vd) && "Decl already exists in LocalDeclMap!");
710 localDeclMap.insert({vd, addr});
711
712 // Add to the symbol table if not there already.
713 if (symbolTable.count(vd))
714 return;
715 symbolTable.insert(vd, addr.getPointer());
716 }
717
718 // Replaces the address of the local variable, if it exists. Else does the
719 // same thing as setAddrOfLocalVar.
721 localDeclMap.insert_or_assign(vd, addr);
722 }
723
724 // A class to allow reverting changes to a var-decl's registration to the
725 // localDeclMap. This is used in cases where things are being inserted into
726 // the variable list but don't follow normal lookup/search rules, like in
727 // OpenACC recipe generation.
729 CIRGenFunction &cgf;
730 const VarDecl *vd;
731 bool shouldDelete = false;
732 Address oldAddr = Address::invalid();
733
734 public:
736 : cgf(cgf), vd(vd) {
737 auto mapItr = cgf.localDeclMap.find(vd);
738
739 if (mapItr != cgf.localDeclMap.end())
740 oldAddr = mapItr->second;
741 else
742 shouldDelete = true;
743 }
744
746 if (shouldDelete)
747 cgf.localDeclMap.erase(vd);
748 else
749 cgf.localDeclMap.insert_or_assign(vd, oldAddr);
750 }
751 };
752
754
757
758 static bool
760
767
770
774 const clang::CXXRecordDecl *nearestVBase,
775 clang::CharUnits offsetFromNearestVBase,
776 bool baseIsNonVirtualPrimaryBase,
777 const clang::CXXRecordDecl *vtableClass,
778 VisitedVirtualBasesSetTy &vbases, VPtrsVector &vptrs);
779 /// Return the Value of the vtable pointer member pointed to by thisAddr.
780 mlir::Value getVTablePtr(mlir::Location loc, Address thisAddr,
781 const clang::CXXRecordDecl *vtableClass);
782
783 /// Returns whether we should perform a type checked load when loading a
784 /// virtual function for virtual calls to members of RD. This is generally
785 /// true when both vcall CFI and whole-program-vtables are enabled.
787
788 /// Source location information about the default argument or member
789 /// initializer expression we're evaluating, if any.
793
794 /// A scope within which we are constructing the fields of an object which
795 /// might use a CXXDefaultInitExpr. This stashes away a 'this' value to use if
796 /// we need to evaluate the CXXDefaultInitExpr within the evaluation.
798 public:
800 : cgf(cgf), oldCXXDefaultInitExprThis(cgf.cxxDefaultInitExprThis) {
801 cgf.cxxDefaultInitExprThis = thisAddr;
802 }
804 cgf.cxxDefaultInitExprThis = oldCXXDefaultInitExprThis;
805 }
806
807 private:
808 CIRGenFunction &cgf;
809 Address oldCXXDefaultInitExprThis;
810 };
811
812 /// The scope of a CXXDefaultInitExpr. Within this scope, the value of 'this'
813 /// is overridden to be the object under construction.
815 public:
820 cgf.cxxThisValue = cgf.cxxDefaultInitExprThis.getPointer();
821 cgf.cxxThisAlignment = cgf.cxxDefaultInitExprThis.getAlignment();
822 }
824 cgf.cxxThisValue = oldCXXThisValue;
825 cgf.cxxThisAlignment = oldCXXThisAlignment;
826 }
827
828 public:
830 mlir::Value oldCXXThisValue;
833 };
834
839
841 LValue makeNaturalAlignAddrLValue(mlir::Value val, QualType ty);
842
843 /// Construct an address with the natural alignment of T. If a pointer to T
844 /// is expected to be signed, the pointer passed to this function must have
845 /// been signed, and the returned Address will have the pointer authentication
846 /// information needed to authenticate the signed pointer.
848 CharUnits alignment,
849 bool forPointeeType = false,
850 LValueBaseInfo *baseInfo = nullptr) {
851 if (alignment.isZero())
852 alignment = cgm.getNaturalTypeAlignment(t, baseInfo);
853 return Address(ptr, convertTypeForMem(t), alignment);
854 }
855
857 Address value, const CXXRecordDecl *derived,
858 llvm::iterator_range<CastExpr::path_const_iterator> path,
859 bool nullCheckValue, SourceLocation loc);
860
862 mlir::Location loc, Address baseAddr, const CXXRecordDecl *derived,
863 llvm::iterator_range<CastExpr::path_const_iterator> path,
864 bool nullCheckValue);
865
866 /// Return the VTT parameter that should be passed to a base
867 /// constructor/destructor with virtual bases.
868 /// FIXME: VTTs are Itanium ABI-specific, so the definition should move
869 /// to ItaniumCXXABI.cpp together with all the references to VTT.
870 mlir::Value getVTTParameter(GlobalDecl gd, bool forVirtualBase,
871 bool delegating);
872
875 return makeAddrLValue(addr, ty, LValueBaseInfo(source));
876 }
877
879 return LValue::makeAddr(addr, ty, baseInfo);
880 }
881
882 void initializeVTablePointers(mlir::Location loc,
883 const clang::CXXRecordDecl *rd);
884 void initializeVTablePointer(mlir::Location loc, const VPtr &vptr);
885
887
888 /// Return the address of a local variable.
890 auto it = localDeclMap.find(vd);
891 assert(it != localDeclMap.end() &&
892 "Invalid argument to getAddrOfLocalVar(), no decl!");
893 return it->second;
894 }
895
897 mlir::Type fieldType, unsigned index);
898
899 /// Given an opaque value expression, return its LValue mapping if it exists,
900 /// otherwise create one.
902
903 /// Given an opaque value expression, return its RValue mapping if it exists,
904 /// otherwise create one.
906
907 /// Load the value for 'this'. This function is only valid while generating
908 /// code for an C++ member function.
909 /// FIXME(cir): this should return a mlir::Value!
910 mlir::Value loadCXXThis() {
911 assert(cxxThisValue && "no 'this' value for this function");
912 return cxxThisValue;
913 }
915
916 /// Load the VTT parameter to base constructors/destructors have virtual
917 /// bases. FIXME: Every place that calls LoadCXXVTT is something that needs to
918 /// be abstracted properly.
919 mlir::Value loadCXXVTT() {
920 assert(cxxStructorImplicitParamValue && "no VTT value for this function");
922 }
923
924 /// Convert the given pointer to a complete class to the given direct base.
926 Address value,
927 const CXXRecordDecl *derived,
928 const CXXRecordDecl *base,
929 bool baseIsVirtual);
930
931 /// Determine whether a return value slot may overlap some other object.
933 // FIXME: Assuming no overlap here breaks guaranteed copy elision for base
934 // class subobjects. These cases may need to be revisited depending on the
935 // resolution of the relevant core issue.
937 }
938
939 /// Determine whether a base class initialization may overlap some other
940 /// object.
942 const CXXRecordDecl *baseRD,
943 bool isVirtual);
944
945 /// Get an appropriate 'undef' rvalue for the given type.
946 /// TODO: What's the equivalent for MLIR? Currently we're only using this for
947 /// void types so it just returns RValue::get(nullptr) but it'll need
948 /// addressed later.
950
951 cir::FuncOp generateCode(clang::GlobalDecl gd, cir::FuncOp fn,
952 cir::FuncType funcType);
953
955 FunctionArgList &args);
956
957 /// Emit the function prologue: declare function arguments in the symbol
958 /// table.
959 void emitFunctionProlog(const FunctionArgList &args, mlir::Block *entryBB,
960 const FunctionDecl *fd, SourceLocation bodyBeginLoc);
961
962 /// Emit code for the start of a function.
963 /// \param loc The location to be associated with the function.
964 /// \param startLoc The location of the function body.
966 cir::FuncOp fn, cir::FuncType funcType,
968 clang::SourceLocation startLoc);
969
970 /// returns true if aggregate type has a volatile member.
972 if (const auto *rd = t->getAsRecordDecl())
973 return rd->hasVolatileMember();
974 return false;
975 }
976
978 cir::TryOp tryOp);
979
980 /// The cleanup depth enclosing all the cleanups associated with the
981 /// parameters.
983
985 void populateCatchHandlersIfRequired(cir::TryOp tryOp);
986
987 /// Takes the old cleanup stack size and emits the cleanup blocks
988 /// that have been added.
989 void popCleanupBlocks(EHScopeStack::stable_iterator oldCleanupStackDepth);
990 void popCleanupBlock();
991
992 /// Push a cleanup to be run at the end of the current full-expression. Safe
993 /// against the possibility that we're currently inside a
994 /// conditionally-evaluated expression.
995 template <class T, class... As>
996 void pushFullExprCleanup(CleanupKind kind, As... a) {
997 // If we're not in a conditional branch, or if none of the
998 // arguments requires saving, then use the unconditional cleanup.
1000 return ehStack.pushCleanup<T>(kind, a...);
1001
1002 cgm.errorNYI("pushFullExprCleanup in conditional branch");
1003 }
1004
1005 /// Enters a new scope for capturing cleanups, all of which
1006 /// will be executed once the scope is exited.
1007 class RunCleanupsScope {
1008 EHScopeStack::stable_iterator cleanupStackDepth, oldCleanupStackDepth;
1009
1010 protected:
1013
1014 private:
1015 RunCleanupsScope(const RunCleanupsScope &) = delete;
1016 void operator=(const RunCleanupsScope &) = delete;
1017
1018 protected:
1020
1021 public:
1022 /// Enter a new cleanup scope.
1024 : performCleanup(true), cgf(cgf) {
1025 cleanupStackDepth = cgf.ehStack.stable_begin();
1026 oldDidCallStackSave = cgf.didCallStackSave;
1027 cgf.didCallStackSave = false;
1028 oldCleanupStackDepth = cgf.currentCleanupStackDepth;
1029 cgf.currentCleanupStackDepth = cleanupStackDepth;
1030 }
1031
1032 /// Exit this cleanup scope, emitting any accumulated cleanups.
1034 if (performCleanup)
1035 forceCleanup();
1036 }
1037
1038 /// Force the emission of cleanups now, instead of waiting
1039 /// until this object is destroyed.
1041 assert(performCleanup && "Already forced cleanup");
1042 {
1043 mlir::OpBuilder::InsertionGuard guard(cgf.getBuilder());
1044 cgf.didCallStackSave = oldDidCallStackSave;
1045 cgf.popCleanupBlocks(cleanupStackDepth);
1046 performCleanup = false;
1047 cgf.currentCleanupStackDepth = oldCleanupStackDepth;
1048 }
1049 }
1050 };
1051
1052 // Cleanup stack depth of the RunCleanupsScope that was pushed most recently.
1054
1055public:
1056 /// Represents a scope, including function bodies, compound statements, and
1057 /// the substatements of if/while/do/for/switch/try statements. This class
1058 /// handles any automatic cleanup, along with the return value.
1059 struct LexicalScope : public RunCleanupsScope {
1060 private:
1061 // Block containing cleanup code for things initialized in this
1062 // lexical context (scope).
1063 mlir::Block *cleanupBlock = nullptr;
1064
1065 // Points to the scope entry block. This is useful, for instance, for
1066 // helping to insert allocas before finalizing any recursive CodeGen from
1067 // switches.
1068 mlir::Block *entryBlock;
1069
1070 LexicalScope *parentScope = nullptr;
1071
1072 // Holds the actual value for ScopeKind::Try
1073 cir::TryOp tryOp = nullptr;
1074
1075 // Only Regular is used at the moment. Support for other kinds will be
1076 // added as the relevant statements/expressions are upstreamed.
1077 enum Kind {
1078 Regular, // cir.if, cir.scope, if_regions
1079 Ternary, // cir.ternary
1080 Switch, // cir.switch
1081 Try, // cir.try
1082 GlobalInit // cir.global initialization code
1083 };
1084 Kind scopeKind = Kind::Regular;
1085
1086 // The scope return value.
1087 mlir::Value retVal = nullptr;
1088
1089 mlir::Location beginLoc;
1090 mlir::Location endLoc;
1091
1092 public:
1093 unsigned depth = 0;
1094
1095 LexicalScope(CIRGenFunction &cgf, mlir::Location loc, mlir::Block *eb)
1096 : RunCleanupsScope(cgf), entryBlock(eb), parentScope(cgf.curLexScope),
1097 beginLoc(loc), endLoc(loc) {
1098
1099 assert(entryBlock && "LexicalScope requires an entry block");
1100 cgf.curLexScope = this;
1101 if (parentScope)
1102 ++depth;
1103
1104 if (const auto fusedLoc = mlir::dyn_cast<mlir::FusedLoc>(loc)) {
1105 assert(fusedLoc.getLocations().size() == 2 && "too many locations");
1106 beginLoc = fusedLoc.getLocations()[0];
1107 endLoc = fusedLoc.getLocations()[1];
1108 }
1109 }
1110
1111 void setRetVal(mlir::Value v) { retVal = v; }
1112
1113 void cleanup();
1114 void restore() { cgf.curLexScope = parentScope; }
1115
1118 cleanup();
1119 restore();
1120 }
1121
1122 // ---
1123 // Kind
1124 // ---
1125 bool isGlobalInit() { return scopeKind == Kind::GlobalInit; }
1126 bool isRegular() { return scopeKind == Kind::Regular; }
1127 bool isSwitch() { return scopeKind == Kind::Switch; }
1128 bool isTernary() { return scopeKind == Kind::Ternary; }
1129 bool isTry() { return scopeKind == Kind::Try; }
1130 cir::TryOp getClosestTryParent();
1131 void setAsGlobalInit() { scopeKind = Kind::GlobalInit; }
1132 void setAsSwitch() { scopeKind = Kind::Switch; }
1133 void setAsTernary() { scopeKind = Kind::Ternary; }
1134 void setAsTry(cir::TryOp op) {
1135 scopeKind = Kind::Try;
1136 tryOp = op;
1137 }
1138
1139 // Lazy create cleanup block or return what's available.
1140 mlir::Block *getOrCreateCleanupBlock(mlir::OpBuilder &builder) {
1141 if (cleanupBlock)
1142 return cleanupBlock;
1143 cleanupBlock = createCleanupBlock(builder);
1144 return cleanupBlock;
1145 }
1146
1147 cir::TryOp getTry() {
1148 assert(isTry());
1149 return tryOp;
1150 }
1151
1152 mlir::Block *getCleanupBlock(mlir::OpBuilder &builder) {
1153 return cleanupBlock;
1154 }
1155
1156 mlir::Block *createCleanupBlock(mlir::OpBuilder &builder) {
1157 // Create the cleanup block but dont hook it up around just yet.
1158 mlir::OpBuilder::InsertionGuard guard(builder);
1159 mlir::Region *r = builder.getBlock() ? builder.getBlock()->getParent()
1160 : &cgf.curFn->getRegion(0);
1161 cleanupBlock = builder.createBlock(r);
1162 return cleanupBlock;
1163 }
1164
1165 // ---
1166 // Return handling.
1167 // ---
1168
1169 private:
1170 // On switches we need one return block per region, since cases don't
1171 // have their own scopes but are distinct regions nonetheless.
1172
1173 // TODO: This implementation should change once we have support for early
1174 // exits in MLIR structured control flow (llvm-project#161575)
1176 llvm::DenseMap<mlir::Block *, mlir::Location> retLocs;
1177 llvm::DenseMap<cir::CaseOp, unsigned> retBlockInCaseIndex;
1178 std::optional<unsigned> normalRetBlockIndex;
1179
1180 // There's usually only one ret block per scope, but this needs to be
1181 // get or create because of potential unreachable return statements, note
1182 // that for those, all source location maps to the first one found.
1183 mlir::Block *createRetBlock(CIRGenFunction &cgf, mlir::Location loc) {
1184 assert((isa_and_nonnull<cir::CaseOp>(
1185 cgf.builder.getBlock()->getParentOp()) ||
1186 retBlocks.size() == 0) &&
1187 "only switches can hold more than one ret block");
1188
1189 // Create the return block but don't hook it up just yet.
1190 mlir::OpBuilder::InsertionGuard guard(cgf.builder);
1191 auto *b = cgf.builder.createBlock(cgf.builder.getBlock()->getParent());
1192 retBlocks.push_back(b);
1193 updateRetLoc(b, loc);
1194 return b;
1195 }
1196
1197 cir::ReturnOp emitReturn(mlir::Location loc);
1198 void emitImplicitReturn();
1199
1200 public:
1202 mlir::Location getRetLoc(mlir::Block *b) { return retLocs.at(b); }
1203 void updateRetLoc(mlir::Block *b, mlir::Location loc) {
1204 retLocs.insert_or_assign(b, loc);
1205 }
1206
1207 mlir::Block *getOrCreateRetBlock(CIRGenFunction &cgf, mlir::Location loc) {
1208 // Check if we're inside a case region
1209 if (auto caseOp = mlir::dyn_cast_if_present<cir::CaseOp>(
1210 cgf.builder.getBlock()->getParentOp())) {
1211 auto iter = retBlockInCaseIndex.find(caseOp);
1212 if (iter != retBlockInCaseIndex.end()) {
1213 // Reuse existing return block
1214 mlir::Block *ret = retBlocks[iter->second];
1215 updateRetLoc(ret, loc);
1216 return ret;
1217 }
1218 // Create new return block
1219 mlir::Block *ret = createRetBlock(cgf, loc);
1220 retBlockInCaseIndex[caseOp] = retBlocks.size() - 1;
1221 return ret;
1222 }
1223
1224 if (normalRetBlockIndex) {
1225 mlir::Block *ret = retBlocks[*normalRetBlockIndex];
1226 updateRetLoc(ret, loc);
1227 return ret;
1228 }
1229
1230 mlir::Block *ret = createRetBlock(cgf, loc);
1231 normalRetBlockIndex = retBlocks.size() - 1;
1232 return ret;
1233 }
1234
1235 mlir::Block *getEntryBlock() { return entryBlock; }
1236 };
1237
1239
1240 typedef void Destroyer(CIRGenFunction &cgf, Address addr, QualType ty);
1241
1243
1244 void pushDestroy(QualType::DestructionKind dtorKind, Address addr,
1245 QualType type);
1246
1247 void pushDestroy(CleanupKind kind, Address addr, QualType type,
1248 Destroyer *destroyer);
1249
1251
1252 /// ----------------------
1253 /// CIR emit functions
1254 /// ----------------------
1255public:
1256 std::optional<mlir::Value>
1257 emitAArch64BuiltinExpr(unsigned builtinID, const CallExpr *expr,
1259 llvm::Triple::ArchType arch);
1260 std::optional<mlir::Value> emitAArch64SMEBuiltinExpr(unsigned builtinID,
1261 const CallExpr *expr);
1262 std::optional<mlir::Value> emitAArch64SVEBuiltinExpr(unsigned builtinID,
1263 const CallExpr *expr);
1264
1265 mlir::Value emitAlignmentAssumption(mlir::Value ptrValue, QualType ty,
1266 SourceLocation loc,
1267 SourceLocation assumptionLoc,
1268 int64_t alignment,
1269 mlir::Value offsetValue = nullptr);
1270
1271 mlir::Value emitAlignmentAssumption(mlir::Value ptrValue, const Expr *expr,
1272 SourceLocation assumptionLoc,
1273 int64_t alignment,
1274 mlir::Value offsetValue = nullptr);
1275
1276private:
1277 void emitAndUpdateRetAlloca(clang::QualType type, mlir::Location loc,
1278 clang::CharUnits alignment);
1279
1280 CIRGenCallee emitDirectCallee(const GlobalDecl &gd);
1281
1282public:
1284 llvm::StringRef fieldName,
1285 unsigned fieldIndex);
1286
1287 mlir::Value emitAlloca(llvm::StringRef name, mlir::Type ty,
1288 mlir::Location loc, clang::CharUnits alignment,
1289 bool insertIntoFnEntryBlock,
1290 mlir::Value arraySize = nullptr);
1291 mlir::Value emitAlloca(llvm::StringRef name, mlir::Type ty,
1292 mlir::Location loc, clang::CharUnits alignment,
1293 mlir::OpBuilder::InsertPoint ip,
1294 mlir::Value arraySize = nullptr);
1295
1296 void emitAggregateStore(mlir::Value value, Address dest);
1297
1298 void emitAggExpr(const clang::Expr *e, AggValueSlot slot);
1299
1301
1302 /// Emit an aggregate copy.
1303 ///
1304 /// \param isVolatile \c true iff either the source or the destination is
1305 /// volatile.
1306 /// \param MayOverlap Whether the tail padding of the destination might be
1307 /// occupied by some other object. More efficient code can often be
1308 /// generated if not.
1309 void emitAggregateCopy(LValue dest, LValue src, QualType eltTy,
1310 AggValueSlot::Overlap_t mayOverlap,
1311 bool isVolatile = false);
1312
1313 /// Emit code to compute the specified expression which can have any type. The
1314 /// result is returned as an RValue struct. If this is an aggregate
1315 /// expression, the aggloc/agglocvolatile arguments indicate where the result
1316 /// should be returned.
1319 bool ignoreResult = false);
1320
1321 /// Emits the code necessary to evaluate an arbitrary expression into the
1322 /// given memory location.
1323 void emitAnyExprToMem(const Expr *e, Address location, Qualifiers quals,
1324 bool isInitializer);
1325
1326 /// Similarly to emitAnyExpr(), however, the result will always be accessible
1327 /// even if no aggregate location is provided.
1329
1330 void emitAnyExprToExn(const Expr *e, Address addr);
1331
1332 void emitArrayDestroy(mlir::Value begin, mlir::Value numElements,
1333 QualType elementType, CharUnits elementAlign,
1334 Destroyer *destroyer);
1335
1336 mlir::Value emitArrayLength(const clang::ArrayType *arrayType,
1337 QualType &baseType, Address &addr);
1339
1341
1343 LValueBaseInfo *baseInfo = nullptr);
1344
1345 mlir::LogicalResult emitAsmStmt(const clang::AsmStmt &s);
1346
1348 void emitAtomicInit(Expr *init, LValue dest);
1349 void emitAtomicStore(RValue rvalue, LValue dest, bool isInit);
1350 void emitAtomicStore(RValue rvalue, LValue dest, cir::MemOrder order,
1351 bool isVolatile, bool isInit);
1352
1354 mlir::OpBuilder::InsertPoint ip = {});
1355
1356 /// Emit code and set up symbol table for a variable declaration with auto,
1357 /// register, or no storage class specifier. These turn into simple stack
1358 /// objects, globals depending on target.
1359 void emitAutoVarDecl(const clang::VarDecl &d);
1360
1361 void emitAutoVarCleanups(const AutoVarEmission &emission);
1362 /// Emit the initializer for an allocated variable. If this call is not
1363 /// associated with the call to emitAutoVarAlloca (as the address of the
1364 /// emission is not directly an alloca), the allocatedSeparately parameter can
1365 /// be used to suppress the assertions. However, this should only be used in
1366 /// extreme cases, as it doesn't properly reflect the language/AST.
1367 void emitAutoVarInit(const AutoVarEmission &emission);
1368 void emitAutoVarTypeCleanup(const AutoVarEmission &emission,
1370
1371 void maybeEmitDeferredVarDeclInit(const VarDecl *vd);
1372
1373 void emitBaseInitializer(mlir::Location loc, const CXXRecordDecl *classDecl,
1374 CXXCtorInitializer *baseInit);
1375
1377
1378 cir::BrOp emitBranchThroughCleanup(mlir::Location loc, JumpDest dest);
1379
1380 mlir::LogicalResult emitBreakStmt(const clang::BreakStmt &s);
1381
1382 RValue emitBuiltinExpr(const clang::GlobalDecl &gd, unsigned builtinID,
1384
1385 /// Returns a Value corresponding to the size of the given expression by
1386 /// emitting a `cir.objsize` operation.
1387 ///
1388 /// \param e The expression whose object size to compute
1389 /// \param type Determines the semantics of the object size computation.
1390 /// The type parameter is a 2-bit value where:
1391 /// bit 0 (type & 1): 0 = whole object, 1 = closest subobject
1392 /// bit 1 (type & 2): 0 = maximum size, 2 = minimum size
1393 /// \param resType The result type for the size value
1394 /// \param emittedE Optional pre-emitted pointer value. If non-null, we'll
1395 /// call `cir.objsize` on this value rather than emitting e.
1396 /// \param isDynamic If true, allows runtime evaluation via dynamic mode
1397 mlir::Value emitBuiltinObjectSize(const clang::Expr *e, unsigned type,
1398 cir::IntType resType, mlir::Value emittedE,
1399 bool isDynamic);
1400
1401 mlir::Value evaluateOrEmitBuiltinObjectSize(const clang::Expr *e,
1402 unsigned type,
1403 cir::IntType resType,
1404 mlir::Value emittedE,
1405 bool isDynamic);
1406
1407 int64_t getAccessedFieldNo(unsigned idx, mlir::ArrayAttr elts);
1408
1410
1411 RValue emitCall(const CIRGenFunctionInfo &funcInfo,
1413 const CallArgList &args, cir::CIRCallOpInterface *callOp,
1414 mlir::Location loc);
1417 const CallArgList &args,
1418 cir::CIRCallOpInterface *callOrTryCall = nullptr) {
1419 assert(currSrcLoc && "source location must have been set");
1420 return emitCall(funcInfo, callee, returnValue, args, callOrTryCall,
1421 *currSrcLoc);
1422 }
1423
1424 RValue emitCall(clang::QualType calleeTy, const CIRGenCallee &callee,
1426 void emitCallArg(CallArgList &args, const clang::Expr *e,
1427 clang::QualType argType);
1428 void emitCallArgs(
1429 CallArgList &args, PrototypeWrapper prototype,
1430 llvm::iterator_range<clang::CallExpr::const_arg_iterator> argRange,
1431 AbstractCallee callee = AbstractCallee(), unsigned paramsToSkip = 0);
1436
1437 template <typename T>
1438 mlir::LogicalResult emitCaseDefaultCascade(const T *stmt, mlir::Type condType,
1439 mlir::ArrayAttr value,
1440 cir::CaseOpKind kind,
1441 bool buildingTopLevelCase);
1442
1443 mlir::LogicalResult emitCaseStmt(const clang::CaseStmt &s,
1444 mlir::Type condType,
1445 bool buildingTopLevelCase);
1446
1447 LValue emitCastLValue(const CastExpr *e);
1448
1449 /// Emits an argument for a call to a `__builtin_assume`. If the builtin
1450 /// sanitizer is enabled, a runtime check is also emitted.
1451 mlir::Value emitCheckedArgForAssume(const Expr *e);
1452
1453 /// Emit a conversion from the specified complex type to the specified
1454 /// destination type, where the destination type is an LLVM scalar type.
1455 mlir::Value emitComplexToScalarConversion(mlir::Value src, QualType srcTy,
1456 QualType dstTy, SourceLocation loc);
1457
1460
1462
1463 mlir::LogicalResult emitCoroutineBody(const CoroutineBodyStmt &s);
1464 cir::CallOp emitCoroEndBuiltinCall(mlir::Location loc, mlir::Value nullPtr);
1465 cir::CallOp emitCoroIDBuiltinCall(mlir::Location loc, mlir::Value nullPtr);
1466 cir::CallOp emitCoroAllocBuiltinCall(mlir::Location loc);
1467 cir::CallOp emitCoroBeginBuiltinCall(mlir::Location loc,
1468 mlir::Value coroframeAddr);
1470
1471 void emitDestroy(Address addr, QualType type, Destroyer *destroyer);
1472
1474
1475 mlir::LogicalResult emitContinueStmt(const clang::ContinueStmt &s);
1476
1478 AggValueSlot dest);
1479
1482 Address arrayBegin, const CXXConstructExpr *e,
1483 bool newPointerIsChecked,
1484 bool zeroInitialize = false);
1486 mlir::Value numElements, Address arrayBase,
1487 const CXXConstructExpr *e,
1488 bool newPointerIsChecked,
1489 bool zeroInitialize);
1491 clang::CXXCtorType type, bool forVirtualBase,
1492 bool delegating, AggValueSlot thisAVS,
1493 const clang::CXXConstructExpr *e);
1494
1496 clang::CXXCtorType type, bool forVirtualBase,
1497 bool delegating, Address thisAddr,
1499
1500 void emitCXXDeleteExpr(const CXXDeleteExpr *e);
1501
1503 bool forVirtualBase, bool delegating,
1504 Address thisAddr, QualType thisTy);
1505
1507 mlir::Value thisVal, QualType thisTy,
1508 mlir::Value implicitParam,
1509 QualType implicitParamTy, const CallExpr *e);
1510
1511 mlir::LogicalResult emitCXXForRangeStmt(const CXXForRangeStmt &s,
1513
1516
1518 const Expr *e, Address base, mlir::Value memberPtr,
1519 const MemberPointerType *memberPtrType, LValueBaseInfo *baseInfo);
1520
1522 const clang::CXXMethodDecl *md, const CIRGenCallee &callee,
1523 ReturnValueSlot returnValue, mlir::Value thisPtr,
1524 mlir::Value implicitParam, clang::QualType implicitParamTy,
1525 const clang::CallExpr *ce, CallArgList *rtlArgs);
1526
1528 const clang::CallExpr *ce, const clang::CXXMethodDecl *md,
1529 ReturnValueSlot returnValue, bool hasQualifier,
1530 clang::NestedNameSpecifier qualifier, bool isArrow,
1531 const clang::Expr *base);
1532
1533 mlir::Value emitCXXNewExpr(const CXXNewExpr *e);
1534
1535 void emitNewArrayInitializer(const CXXNewExpr *e, QualType elementType,
1536 mlir::Type elementTy, Address beginPtr,
1537 mlir::Value numElements,
1538 mlir::Value allocSizeWithoutCookie);
1539
1541 const CXXMethodDecl *md,
1543
1545
1547 const CallExpr *callExpr,
1549
1550 void emitCXXTemporary(const CXXTemporary *temporary, QualType tempType,
1551 Address ptr);
1552
1553 void emitCXXThrowExpr(const CXXThrowExpr *e);
1554
1555 mlir::LogicalResult emitCXXTryStmt(const clang::CXXTryStmt &s);
1556
1557 mlir::LogicalResult emitCXXTryStmtUnderScope(const clang::CXXTryStmt &s);
1558
1559 void enterCXXTryStmt(const CXXTryStmt &s, cir::TryOp tryOp,
1560 bool isFnTryBlock = false);
1561
1562 void exitCXXTryStmt(const CXXTryStmt &s, bool isFnTryBlock = false);
1563
1565 clang::CXXCtorType ctorType, FunctionArgList &args);
1566
1567 // It's important not to confuse this and emitDelegateCXXConstructorCall.
1568 // Delegating constructors are the C++11 feature. The constructor delegate
1569 // optimization is used to reduce duplication in the base and complete
1570 // constructors where they are substantially the same.
1572 const FunctionArgList &args);
1573
1574 void emitDeleteCall(const FunctionDecl *deleteFD, mlir::Value ptr,
1575 QualType deleteTy);
1576
1577 mlir::LogicalResult emitDoStmt(const clang::DoStmt &s);
1578
1579 mlir::Value emitDynamicCast(Address thisAddr, const CXXDynamicCastExpr *dce);
1580
1581 /// Emit an expression as an initializer for an object (variable, field, etc.)
1582 /// at the given location. The expression is not necessarily the normal
1583 /// initializer for the object, and the address is not necessarily
1584 /// its normal location.
1585 ///
1586 /// \param init the initializing expression
1587 /// \param d the object to act as if we're initializing
1588 /// \param lvalue the lvalue to initialize
1589 /// \param capturedByInit true if \p d is a __block variable whose address is
1590 /// potentially changed by the initializer
1591 void emitExprAsInit(const clang::Expr *init, const clang::ValueDecl *d,
1592 LValue lvalue, bool capturedByInit = false);
1593
1594 mlir::LogicalResult emitFunctionBody(const clang::Stmt *body);
1595
1596 mlir::LogicalResult emitGotoStmt(const clang::GotoStmt &s);
1597
1598 mlir::LogicalResult emitIndirectGotoStmt(const IndirectGotoStmt &s);
1599
1601
1603 clang::Expr *init);
1604
1606
1607 mlir::Value emitPromotedComplexExpr(const Expr *e, QualType promotionType);
1608
1609 mlir::Value emitPromotedScalarExpr(const Expr *e, QualType promotionType);
1610
1611 mlir::Value emitPromotedValue(mlir::Value result, QualType promotionType);
1612
1613 void emitReturnOfRValue(mlir::Location loc, RValue rv, QualType ty);
1614
1615 mlir::Value emitRuntimeCall(mlir::Location loc, cir::FuncOp callee,
1616 llvm::ArrayRef<mlir::Value> args = {});
1617
1618 /// Emit the computation of the specified expression of scalar type.
1619 mlir::Value emitScalarExpr(const clang::Expr *e,
1620 bool ignoreResultAssign = false);
1621
1622 mlir::Value emitScalarPrePostIncDec(const UnaryOperator *e, LValue lv,
1623 cir::UnaryOpKind kind, bool isPre);
1624
1625 /// Build a debug stoppoint if we are emitting debug info.
1626 void emitStopPoint(const Stmt *s);
1627
1628 // Build CIR for a statement. useCurrentScope should be true if no
1629 // new scopes need be created when finding a compound statement.
1630 mlir::LogicalResult emitStmt(const clang::Stmt *s, bool useCurrentScope,
1631 llvm::ArrayRef<const Attr *> attrs = {});
1632
1633 mlir::LogicalResult emitSimpleStmt(const clang::Stmt *s,
1634 bool useCurrentScope);
1635
1636 mlir::LogicalResult emitForStmt(const clang::ForStmt &s);
1637
1638 void emitForwardingCallToLambda(const CXXMethodDecl *lambdaCallOperator,
1639 CallArgList &callArgs);
1640
1641 RValue emitCoawaitExpr(const CoawaitExpr &e,
1642 AggValueSlot aggSlot = AggValueSlot::ignored(),
1643 bool ignoreResult = false);
1644 /// Emit the computation of the specified expression of complex type,
1645 /// returning the result.
1646 mlir::Value emitComplexExpr(const Expr *e);
1647
1648 void emitComplexExprIntoLValue(const Expr *e, LValue dest, bool isInit);
1649
1650 mlir::Value emitComplexPrePostIncDec(const UnaryOperator *e, LValue lv,
1651 cir::UnaryOpKind op, bool isPre);
1652
1656 mlir::Value &result);
1657
1658 mlir::LogicalResult
1659 emitCompoundStmt(const clang::CompoundStmt &s, Address *lastValue = nullptr,
1660 AggValueSlot slot = AggValueSlot::ignored());
1661
1662 mlir::LogicalResult
1664 Address *lastValue = nullptr,
1665 AggValueSlot slot = AggValueSlot::ignored());
1666
1667 void emitDecl(const clang::Decl &d, bool evaluateConditionDecl = false);
1668 mlir::LogicalResult emitDeclStmt(const clang::DeclStmt &s);
1669 LValue emitDeclRefLValue(const clang::DeclRefExpr *e);
1670
1671 mlir::LogicalResult emitDefaultStmt(const clang::DefaultStmt &s,
1672 mlir::Type condType,
1673 bool buildingTopLevelCase);
1674
1676 clang::CXXCtorType ctorType,
1677 const FunctionArgList &args,
1679
1680 /// We are performing a delegate call; that is, the current function is
1681 /// delegating to another one. Produce a r-value suitable for passing the
1682 /// given parameter.
1683 void emitDelegateCallArg(CallArgList &args, const clang::VarDecl *param,
1685
1686 /// Emit an `if` on a boolean condition to the specified blocks.
1687 /// FIXME: Based on the condition, this might try to simplify the codegen of
1688 /// the conditional based on the branch.
1689 /// In the future, we may apply code generation simplifications here,
1690 /// similar to those used in classic LLVM codegen
1691 /// See `EmitBranchOnBoolExpr` for inspiration.
1692 mlir::LogicalResult emitIfOnBoolExpr(const clang::Expr *cond,
1693 const clang::Stmt *thenS,
1694 const clang::Stmt *elseS);
1695 cir::IfOp emitIfOnBoolExpr(const clang::Expr *cond,
1696 BuilderCallbackRef thenBuilder,
1697 mlir::Location thenLoc,
1698 BuilderCallbackRef elseBuilder,
1699 std::optional<mlir::Location> elseLoc = {});
1700
1701 mlir::Value emitOpOnBoolExpr(mlir::Location loc, const clang::Expr *cond);
1702
1703 LValue emitPointerToDataMemberBinaryExpr(const BinaryOperator *e);
1704
1705 mlir::LogicalResult emitLabel(const clang::LabelDecl &d);
1706 mlir::LogicalResult emitLabelStmt(const clang::LabelStmt &s);
1707
1708 void emitLambdaDelegatingInvokeBody(const CXXMethodDecl *md);
1709 void emitLambdaStaticInvokeBody(const CXXMethodDecl *md);
1710
1711 void populateCatchHandlers(cir::TryOp tryOp);
1712
1713 mlir::LogicalResult emitIfStmt(const clang::IfStmt &s);
1714
1715 /// Emit code to compute the specified expression,
1716 /// ignoring the result.
1717 void emitIgnoredExpr(const clang::Expr *e);
1718
1719 RValue emitLoadOfBitfieldLValue(LValue lv, SourceLocation loc);
1720
1721 /// Load a complex number from the specified l-value.
1722 mlir::Value emitLoadOfComplex(LValue src, SourceLocation loc);
1723
1724 RValue emitLoadOfExtVectorElementLValue(LValue lv);
1725
1726 /// Given an expression that represents a value lvalue, this method emits
1727 /// the address of the lvalue, then loads the result as an rvalue,
1728 /// returning the rvalue.
1729 RValue emitLoadOfLValue(LValue lv, SourceLocation loc);
1730
1731 Address emitLoadOfReference(LValue refLVal, mlir::Location loc,
1732 LValueBaseInfo *pointeeBaseInfo);
1733 LValue emitLoadOfReferenceLValue(Address refAddr, mlir::Location loc,
1734 QualType refTy, AlignmentSource source);
1735
1736 /// EmitLoadOfScalar - Load a scalar value from an address, taking
1737 /// care to appropriately convert from the memory representation to
1738 /// the LLVM value representation. The l-value must be a simple
1739 /// l-value.
1740 mlir::Value emitLoadOfScalar(LValue lvalue, SourceLocation loc);
1741 mlir::Value emitLoadOfScalar(Address addr, bool isVolatile, QualType ty,
1742 SourceLocation loc, LValueBaseInfo baseInfo);
1743
1744 /// Emit code to compute a designator that specifies the location
1745 /// of the expression.
1746 /// FIXME: document this function better.
1747 LValue emitLValue(const clang::Expr *e);
1748 LValue emitLValueForBitField(LValue base, const FieldDecl *field);
1749 LValue emitLValueForField(LValue base, const clang::FieldDecl *field);
1750
1751 LValue emitLValueForLambdaField(const FieldDecl *field);
1752 LValue emitLValueForLambdaField(const FieldDecl *field,
1753 mlir::Value thisValue);
1754
1755 /// Like emitLValueForField, excpet that if the Field is a reference, this
1756 /// will return the address of the reference and not the address of the value
1757 /// stored in the reference.
1758 LValue emitLValueForFieldInitialization(LValue base,
1759 const clang::FieldDecl *field,
1760 llvm::StringRef fieldName);
1761
1762 LValue emitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *e);
1763
1764 LValue emitMemberExpr(const MemberExpr *e);
1765
1766 LValue emitOpaqueValueLValue(const OpaqueValueExpr *e);
1767
1768 LValue emitConditionalOperatorLValue(const AbstractConditionalOperator *expr);
1769
1770 /// Given an expression with a pointer type, emit the value and compute our
1771 /// best estimate of the alignment of the pointee.
1772 ///
1773 /// One reasonable way to use this information is when there's a language
1774 /// guarantee that the pointer must be aligned to some stricter value, and
1775 /// we're simply trying to ensure that sufficiently obvious uses of under-
1776 /// aligned objects don't get miscompiled; for example, a placement new
1777 /// into the address of a local variable. In such a case, it's quite
1778 /// reasonable to just ignore the returned alignment when it isn't from an
1779 /// explicit source.
1781 LValueBaseInfo *baseInfo = nullptr);
1782
1783 /// Emits a reference binding to the passed in expression.
1784 RValue emitReferenceBindingToExpr(const Expr *e);
1785
1786 mlir::LogicalResult emitReturnStmt(const clang::ReturnStmt &s);
1787
1788 RValue emitRotate(const CallExpr *e, bool isRotateLeft);
1789
1790 mlir::Value emitScalarConstant(const ConstantEmission &constant, Expr *e);
1791
1792 /// Emit a conversion from the specified type to the specified destination
1793 /// type, both of which are CIR scalar types.
1794 mlir::Value emitScalarConversion(mlir::Value src, clang::QualType srcType,
1795 clang::QualType dstType,
1797
1798 void emitScalarInit(const clang::Expr *init, mlir::Location loc,
1799 LValue lvalue, bool capturedByInit = false);
1800
1801 mlir::Value emitScalarOrConstFoldImmArg(unsigned iceArguments, unsigned idx,
1802 const Expr *argExpr);
1803
1804 void emitStaticVarDecl(const VarDecl &d, cir::GlobalLinkageKind linkage);
1805
1806 void emitStoreOfComplex(mlir::Location loc, mlir::Value v, LValue dest,
1807 bool isInit);
1808
1809 void emitStoreOfScalar(mlir::Value value, Address addr, bool isVolatile,
1810 clang::QualType ty, LValueBaseInfo baseInfo,
1811 bool isInit = false, bool isNontemporal = false);
1812 void emitStoreOfScalar(mlir::Value value, LValue lvalue, bool isInit);
1813
1814 /// Store the specified rvalue into the specified
1815 /// lvalue, where both are guaranteed to the have the same type, and that type
1816 /// is 'Ty'.
1817 void emitStoreThroughLValue(RValue src, LValue dst, bool isInit = false);
1818
1819 mlir::Value emitStoreThroughBitfieldLValue(RValue src, LValue dstresult);
1820
1821 LValue emitStringLiteralLValue(const StringLiteral *e,
1822 llvm::StringRef name = ".str");
1823
1824 mlir::LogicalResult emitSwitchBody(const clang::Stmt *s);
1825 mlir::LogicalResult emitSwitchCase(const clang::SwitchCase &s,
1826 bool buildingTopLevelCase);
1827 mlir::LogicalResult emitSwitchStmt(const clang::SwitchStmt &s);
1828
1829 std::optional<mlir::Value>
1830 emitTargetBuiltinExpr(unsigned builtinID, const clang::CallExpr *e,
1831 ReturnValueSlot &returnValue);
1832
1833 /// Given a value and its clang type, returns the value casted to its memory
1834 /// representation.
1835 /// Note: CIR defers most of the special casting to the final lowering passes
1836 /// to conserve the high level information.
1837 mlir::Value emitToMemory(mlir::Value value, clang::QualType ty);
1838
1839 /// Emit a trap instruction, which is used to abort the program in an abnormal
1840 /// way, usually for debugging purposes.
1841 /// \p createNewBlock indicates whether to create a new block for the IR
1842 /// builder. Since the `cir.trap` operation is a terminator, operations that
1843 /// follow a trap cannot be emitted after `cir.trap` in the same block. To
1844 /// ensure these operations get emitted successfully, you need to create a new
1845 /// dummy block and set the insertion point there before continuing from the
1846 /// trap operation.
1847 void emitTrap(mlir::Location loc, bool createNewBlock);
1848
1849 LValue emitUnaryOpLValue(const clang::UnaryOperator *e);
1850
1851 mlir::Value emitUnPromotedValue(mlir::Value result, QualType unPromotionType);
1852
1853 /// Emit a reached-unreachable diagnostic if \p loc is valid and runtime
1854 /// checking is enabled. Otherwise, just emit an unreachable instruction.
1855 /// \p createNewBlock indicates whether to create a new block for the IR
1856 /// builder. Since the `cir.unreachable` operation is a terminator, operations
1857 /// that follow an unreachable point cannot be emitted after `cir.unreachable`
1858 /// in the same block. To ensure these operations get emitted successfully,
1859 /// you need to create a dummy block and set the insertion point there before
1860 /// continuing from the unreachable point.
1861 void emitUnreachable(clang::SourceLocation loc, bool createNewBlock);
1862
1863 /// This method handles emission of any variable declaration
1864 /// inside a function, including static vars etc.
1865 void emitVarDecl(const clang::VarDecl &d);
1866
1867 void emitVariablyModifiedType(QualType ty);
1868
1869 mlir::LogicalResult emitWhileStmt(const clang::WhileStmt &s);
1870
1871 std::optional<mlir::Value> emitX86BuiltinExpr(unsigned builtinID,
1872 const CallExpr *expr);
1873
1874 /// Given an assignment `*lhs = rhs`, emit a test that checks if \p rhs is
1875 /// nonnull, if 1\p LHS is marked _Nonnull.
1876 void emitNullabilityCheck(LValue lhs, mlir::Value rhs,
1878
1879 /// An object to manage conditionally-evaluated expressions.
1881 CIRGenFunction &cgf;
1882 mlir::OpBuilder::InsertPoint insertPt;
1883
1884 public:
1886 : cgf(cgf), insertPt(cgf.builder.saveInsertionPoint()) {}
1887 ConditionalEvaluation(CIRGenFunction &cgf, mlir::OpBuilder::InsertPoint ip)
1888 : cgf(cgf), insertPt(ip) {}
1889
1891 assert(cgf.outermostConditional != this);
1892 if (!cgf.outermostConditional)
1893 cgf.outermostConditional = this;
1894 }
1895
1897 assert(cgf.outermostConditional != nullptr);
1898 if (cgf.outermostConditional == this)
1899 cgf.outermostConditional = nullptr;
1900 }
1901
1902 /// Returns the insertion point which will be executed prior to each
1903 /// evaluation of the conditional code. In LLVM OG, this method
1904 /// is called getStartingBlock.
1905 mlir::OpBuilder::InsertPoint getInsertPoint() const { return insertPt; }
1906 };
1907
1909 std::optional<LValue> lhs{}, rhs{};
1910 mlir::Value result{};
1911 };
1912
1913 // Return true if we're currently emitting one branch or the other of a
1914 // conditional expression.
1915 bool isInConditionalBranch() const { return outermostConditional != nullptr; }
1916
1917 void setBeforeOutermostConditional(mlir::Value value, Address addr) {
1918 assert(isInConditionalBranch());
1919 {
1920 mlir::OpBuilder::InsertionGuard guard(builder);
1921 builder.restoreInsertionPoint(outermostConditional->getInsertPoint());
1922 builder.createStore(
1923 value.getLoc(), value, addr, /*isVolatile=*/false,
1924 mlir::IntegerAttr::get(
1925 mlir::IntegerType::get(value.getContext(), 64),
1926 (uint64_t)addr.getAlignment().getAsAlign().value()));
1927 }
1928 }
1929
1930 // Points to the outermost active conditional control. This is used so that
1931 // we know if a temporary should be destroyed conditionally.
1933
1934 /// An RAII object to record that we're evaluating a statement
1935 /// expression.
1937 CIRGenFunction &cgf;
1938
1939 /// We have to save the outermost conditional: cleanups in a
1940 /// statement expression aren't conditional just because the
1941 /// StmtExpr is.
1942 ConditionalEvaluation *savedOutermostConditional;
1943
1944 public:
1946 : cgf(cgf), savedOutermostConditional(cgf.outermostConditional) {
1947 cgf.outermostConditional = nullptr;
1948 }
1949
1951 cgf.outermostConditional = savedOutermostConditional;
1952 }
1953 };
1954
1955 template <typename FuncTy>
1956 ConditionalInfo emitConditionalBlocks(const AbstractConditionalOperator *e,
1957 const FuncTy &branchGenFunc);
1958
1959 mlir::Value emitTernaryOnBoolExpr(const clang::Expr *cond, mlir::Location loc,
1960 const clang::Stmt *thenS,
1961 const clang::Stmt *elseS);
1962
1963 /// Build a "reference" to a va_list; this is either the address or the value
1964 /// of the expression, depending on how va_list is defined.
1965 Address emitVAListRef(const Expr *e);
1966
1967 /// Emits the start of a CIR variable-argument operation (`cir.va_start`)
1968 ///
1969 /// \param vaList A reference to the \c va_list as emitted by either
1970 /// \c emitVAListRef or \c emitMSVAListRef.
1971 ///
1972 /// \param count The number of arguments in \c vaList
1973 void emitVAStart(mlir::Value vaList, mlir::Value count);
1974
1975 /// Emits the end of a CIR variable-argument operation (`cir.va_start`)
1976 ///
1977 /// \param vaList A reference to the \c va_list as emitted by either
1978 /// \c emitVAListRef or \c emitMSVAListRef.
1979 void emitVAEnd(mlir::Value vaList);
1980
1981 /// Generate code to get an argument from the passed in pointer
1982 /// and update it accordingly.
1983 ///
1984 /// \param ve The \c VAArgExpr for which to generate code.
1985 ///
1986 /// \param vaListAddr Receives a reference to the \c va_list as emitted by
1987 /// either \c emitVAListRef or \c emitMSVAListRef.
1988 ///
1989 /// \returns SSA value with the argument.
1990 mlir::Value emitVAArg(VAArgExpr *ve);
1991
1992 /// ----------------------
1993 /// CIR build helpers
1994 /// -----------------
1995public:
1996 cir::AllocaOp createTempAlloca(mlir::Type ty, mlir::Location loc,
1997 const Twine &name = "tmp",
1998 mlir::Value arraySize = nullptr,
1999 bool insertIntoFnEntryBlock = false);
2000 cir::AllocaOp createTempAlloca(mlir::Type ty, mlir::Location loc,
2001 const Twine &name = "tmp",
2002 mlir::OpBuilder::InsertPoint ip = {},
2003 mlir::Value arraySize = nullptr);
2004 Address createTempAlloca(mlir::Type ty, CharUnits align, mlir::Location loc,
2005 const Twine &name = "tmp",
2006 mlir::Value arraySize = nullptr,
2007 Address *alloca = nullptr,
2008 mlir::OpBuilder::InsertPoint ip = {});
2009 Address createTempAllocaWithoutCast(mlir::Type ty, CharUnits align,
2010 mlir::Location loc,
2011 const Twine &name = "tmp",
2012 mlir::Value arraySize = nullptr,
2013 mlir::OpBuilder::InsertPoint ip = {});
2014
2015 /// Create a temporary memory object of the given type, with
2016 /// appropriate alignmen and cast it to the default address space. Returns
2017 /// the original alloca instruction by \p Alloca if it is not nullptr.
2018 Address createMemTemp(QualType t, mlir::Location loc,
2019 const Twine &name = "tmp", Address *alloca = nullptr,
2020 mlir::OpBuilder::InsertPoint ip = {});
2021 Address createMemTemp(QualType t, CharUnits align, mlir::Location loc,
2022 const Twine &name = "tmp", Address *alloca = nullptr,
2023 mlir::OpBuilder::InsertPoint ip = {});
2024
2025 //===--------------------------------------------------------------------===//
2026 // OpenACC Emission
2027 //===--------------------------------------------------------------------===//
2028private:
2029 template <typename Op>
2030 Op emitOpenACCOp(mlir::Location start, OpenACCDirectiveKind dirKind,
2031 llvm::ArrayRef<const OpenACCClause *> clauses);
2032 // Function to do the basic implementation of an operation with an Associated
2033 // Statement. Models AssociatedStmtConstruct.
2034 template <typename Op, typename TermOp>
2035 mlir::LogicalResult
2036 emitOpenACCOpAssociatedStmt(mlir::Location start, mlir::Location end,
2037 OpenACCDirectiveKind dirKind,
2038 llvm::ArrayRef<const OpenACCClause *> clauses,
2039 const Stmt *associatedStmt);
2040
2041 template <typename Op, typename TermOp>
2042 mlir::LogicalResult emitOpenACCOpCombinedConstruct(
2043 mlir::Location start, mlir::Location end, OpenACCDirectiveKind dirKind,
2044 llvm::ArrayRef<const OpenACCClause *> clauses, const Stmt *loopStmt);
2045
2046 template <typename Op>
2047 void emitOpenACCClauses(Op &op, OpenACCDirectiveKind dirKind,
2048 ArrayRef<const OpenACCClause *> clauses);
2049 // The second template argument doesn't need to be a template, since it should
2050 // always be an mlir::acc::LoopOp, but as this is a template anyway, we make
2051 // it a template argument as this way we can avoid including the OpenACC MLIR
2052 // headers here. We will count on linker failures/explicit instantiation to
2053 // ensure we don't mess this up, but it is only called from 1 place, and
2054 // instantiated 3x.
2055 template <typename ComputeOp, typename LoopOp>
2056 void emitOpenACCClauses(ComputeOp &op, LoopOp &loopOp,
2057 OpenACCDirectiveKind dirKind,
2058 ArrayRef<const OpenACCClause *> clauses);
2059
2060 // The OpenACC LoopOp requires that we have auto, seq, or independent on all
2061 // LoopOp operations for the 'none' device type case. This function checks if
2062 // the LoopOp has one, else it updates it to have one.
2063 void updateLoopOpParallelism(mlir::acc::LoopOp &op, bool isOrphan,
2065
2066 // The OpenACC 'cache' construct actually applies to the 'loop' if present. So
2067 // keep track of the 'loop' so that we can add the cache vars to it correctly.
2068 mlir::acc::LoopOp *activeLoopOp = nullptr;
2069
2070 struct ActiveOpenACCLoopRAII {
2071 CIRGenFunction &cgf;
2072 mlir::acc::LoopOp *oldLoopOp;
2073
2074 ActiveOpenACCLoopRAII(CIRGenFunction &cgf, mlir::acc::LoopOp *newOp)
2075 : cgf(cgf), oldLoopOp(cgf.activeLoopOp) {
2076 cgf.activeLoopOp = newOp;
2077 }
2078 ~ActiveOpenACCLoopRAII() { cgf.activeLoopOp = oldLoopOp; }
2079 };
2080
2081 // Keep track of the last place we inserted a 'recipe' so that we can insert
2082 // the next one in lexical order.
2083 mlir::OpBuilder::InsertPoint lastRecipeLocation;
2084
2085public:
2086 // Helper type used to store the list of important information for a 'data'
2087 // clause variable, or a 'cache' variable reference.
2089 mlir::Location beginLoc;
2090 mlir::Value varValue;
2091 std::string name;
2092 // The type of the original variable reference: that is, after 'bounds' have
2093 // removed pointers/array types/etc. So in the case of int arr[5], and a
2094 // private(arr[1]), 'origType' is 'int', but 'baseType' is 'int[5]'.
2098 // The list of types that we found when going through the bounds, which we
2099 // can use to properly set the alloca section.
2101 };
2102
2103 // Gets the collection of info required to lower and OpenACC clause or cache
2104 // construct variable reference.
2106 // Helper function to emit the integer expressions as required by an OpenACC
2107 // clause/construct.
2108 mlir::Value emitOpenACCIntExpr(const Expr *intExpr);
2109 // Helper function to emit an integer constant as an mlir int type, used for
2110 // constants in OpenACC constructs/clauses.
2111 mlir::Value createOpenACCConstantInt(mlir::Location loc, unsigned width,
2112 int64_t value);
2113
2114 mlir::LogicalResult
2116 mlir::LogicalResult emitOpenACCLoopConstruct(const OpenACCLoopConstruct &s);
2117 mlir::LogicalResult
2119 mlir::LogicalResult emitOpenACCDataConstruct(const OpenACCDataConstruct &s);
2120 mlir::LogicalResult
2122 mlir::LogicalResult
2124 mlir::LogicalResult
2126 mlir::LogicalResult emitOpenACCWaitConstruct(const OpenACCWaitConstruct &s);
2127 mlir::LogicalResult emitOpenACCInitConstruct(const OpenACCInitConstruct &s);
2128 mlir::LogicalResult
2130 mlir::LogicalResult emitOpenACCSetConstruct(const OpenACCSetConstruct &s);
2131 mlir::LogicalResult
2133 mlir::LogicalResult
2135 mlir::LogicalResult emitOpenACCCacheConstruct(const OpenACCCacheConstruct &s);
2136
2139
2140 /// Create a temporary memory object for the given aggregate type.
2141 AggValueSlot createAggTemp(QualType ty, mlir::Location loc,
2142 const Twine &name = "tmp",
2143 Address *alloca = nullptr) {
2145 return AggValueSlot::forAddr(
2146 createMemTemp(ty, loc, name, alloca), ty.getQualifiers(),
2149 }
2150
2151private:
2152 QualType getVarArgType(const Expr *arg);
2153};
2154
2155} // namespace clang::CIRGen
2156
2157#endif
Defines the clang::ASTContext interface.
llvm::function_ref< void(mlir::OpBuilder &, mlir::Location)> BuilderCallbackRef
Definition CIRDialect.h:37
Defines the clang::Expr interface and subclasses for C++ expressions.
Defines an enumeration for C++ overloaded operators.
C Language Family Type Representation.
__device__ __2f16 b
__device__ __2f16 float __ockl_bool s
__device__ __2f16 float c
Represents a member of a struct/union/class.
Definition Decl.h:3160
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:220
AbstractConditionalOperator - An abstract base class for ConditionalOperator and BinaryConditionalOpe...
Definition Expr.h:4287
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
Definition Expr.h:2721
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Definition TypeBase.h:3722
AsmStmt is the base class for GCCAsmStmt and MSAsmStmt.
Definition Stmt.h:3267
AtomicExpr - Variadic atomic builtins: __atomic_exchange, __atomic_fetch_*, __atomic_load,...
Definition Expr.h:6814
BinaryConditionalOperator - The GNU extension to the conditional operator which allows the middle ope...
Definition Expr.h:4387
OpaqueValueExpr * getOpaqueValue() const
getOpaqueValue - Return the opaque value placeholder.
Definition Expr.h:4425
Expr * getCommon() const
getCommon - Return the common expression, written to the left of the condition.
Definition Expr.h:4422
A builtin binary operation expression such as "x + y" or "x <= y".
Definition Expr.h:3972
BreakStmt - This represents a break.
Definition Stmt.h:3125
mlir::Value getPointer() const
Definition Address.h:90
static Address invalid()
Definition Address.h:69
clang::CharUnits getAlignment() const
Definition Address.h:130
mlir::Value getBasePointer() const
Definition Address.h:95
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.
AbstractCallee(const clang::FunctionDecl *fd)
const clang::ParmVarDecl * getParamDecl(unsigned I) const
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)
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...
RunCleanupsScope(CIRGenFunction &cgf)
Enter a new cleanup scope.
void forceCleanup()
Force the emission of cleanups now, instead of waiting until this object is destroyed.
~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...
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::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)
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 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)
mlir::LogicalResult emitOpenACCWaitConstruct(const OpenACCWaitConstruct &s)
cir::FuncOp generateCode(clang::GlobalDecl gd, cir::FuncOp fn, cir::FuncType funcType)
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 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()
void enterCXXTryStmt(const CXXTryStmt &s, cir::TryOp tryOp, bool isFnTryBlock=false)
RValue emitCXXMemberCallExpr(const clang::CXXMemberCallExpr *e, ReturnValueSlot returnValue)
mlir::LogicalResult emitOpenACCUpdateConstruct(const OpenACCUpdateConstruct &s)
LValue emitLValueForBitField(LValue base, const FieldDecl *field)
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.
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)
void populateEHCatchRegions(EHScopeStack::stable_iterator scope, cir::TryOp tryOp)
Address cxxDefaultInitExprThis
The value of 'this' to sue when evaluating CXXDefaultInitExprs within this expression.
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.
void exitCXXTryStmt(const CXXTryStmt &s, bool isFnTryBlock=false)
void setBeforeOutermostConditional(mlir::Value value, Address addr)
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.
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 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)
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,...
Address getAsNaturalAddressOf(Address addr, QualType pointeeTy)
JumpDest returnBlock(mlir::Block *retBlock)
Unified return block.
LValue emitComplexCompoundAssignmentLValue(const CompoundAssignOperator *e)
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.
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 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 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.
mlir::Value emitScalarPrePostIncDec(const UnaryOperator *e, LValue lv, cir::UnaryOpKind kind, bool isPre)
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.
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.
mlir::LogicalResult emitCXXTryStmtUnderScope(const clang::CXXTryStmt &s)
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 emitOpenACCSetConstruct(const OpenACCSetConstruct &s)
RValue emitReferenceBindingToExpr(const Expr *e)
Emits a reference binding to the passed in expression.
void emitVAStart(mlir::Value vaList, mlir::Value count)
Emits the start of a CIR variable-argument operation (cir.va_start)
VPtrsVector getVTablePointers(const clang::CXXRecordDecl *vtableClass)
const TargetCIRGenInfo & getTargetHooks() const
mlir::LogicalResult emitSwitchStmt(const clang::SwitchStmt &s)
mlir::Value evaluateOrEmitBuiltinObjectSize(const clang::Expr *e, unsigned type, cir::IntType resType, mlir::Value emittedE, bool isDynamic)
JumpDest getJumpDestInCurrentScope(mlir::Block *target)
The given basic block lies in the current EH scope, but may be a target of a potentially scope-crossi...
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)
CleanupKind getCleanupKind(QualType::DestructionKind kind)
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....
AggValueSlot::Overlap_t getOverlapForFieldInit(const FieldDecl *fd)
mlir::LogicalResult emitSimpleStmt(const clang::Stmt *s, bool useCurrentScope)
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)
Definition CIRGenAsm.cpp:86
Address emitExtVectorElementLValue(LValue lv, mlir::Location loc)
Generates lvalue for partial ext_vector access.
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)
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)
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)
cir::CallOp emitCoroEndBuiltinCall(mlir::Location loc, mlir::Value nullPtr)
mlir::LogicalResult emitSwitchBody(const clang::Stmt *s)
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.
void populateCatchHandlersIfRequired(cir::TryOp tryOp)
void emitNewArrayInitializer(const CXXNewExpr *e, QualType elementType, mlir::Type elementTy, Address beginPtr, mlir::Value numElements, mlir::Value allocSizeWithoutCookie)
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.
RValue emitLoadOfExtVectorElementLValue(LValue lv)
mlir::Type convertTypeForMem(QualType t)
clang::QualType buildFunctionArgList(clang::GlobalDecl gd, FunctionArgList &args)
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)
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)
void emitCXXConstructExpr(const clang::CXXConstructExpr *e, AggValueSlot dest)
mlir::Value emitLoadOfComplex(LValue src, SourceLocation loc)
Load a complex number from the specified l-value.
LValue emitAggExprToLValue(const Expr *e)
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 emitCXXNewExpr(const CXXNewExpr *e)
RValue getUndefRValue(clang::QualType ty)
Get an appropriate 'undef' rvalue for the given type.
Address returnValue
The temporary alloca to hold the return value.
LValue makeAddrLValue(Address addr, QualType ty, LValueBaseInfo baseInfo)
static int64_t getSExtIntValueFromConstOp(mlir::Value val)
Get integer from a mlir::Value that is an int constant or a constant op.
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)
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)
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 emitOpenACCShutdownConstruct(const OpenACCShutdownConstruct &s)
mlir::LogicalResult emitFunctionBody(const clang::Stmt *body)
mlir::LogicalResult emitBreakStmt(const clang::BreakStmt &s)
mlir::Value emitComplexPrePostIncDec(const UnaryOperator *e, LValue lv, cir::UnaryOpKind op, bool isPre)
mlir::LogicalResult emitIndirectGotoStmt(const IndirectGotoStmt &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
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)
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)
RValue emitCall(const CIRGenFunctionInfo &funcInfo, const CIRGenCallee &callee, ReturnValueSlot returnValue, const CallArgList &args, cir::CIRCallOpInterface *callOp, mlir::Location loc)
LValue emitComplexAssignmentLValue(const BinaryOperator *e)
void emitCallArg(CallArgList &args, const clang::Expr *e, clang::QualType argType)
clang::FieldDecl * lambdaThisCaptureField
mlir::LogicalResult emitContinueStmt(const clang::ContinueStmt &s)
const clang::Decl * curCodeDecl
This is the inner-most code context, which includes blocks.
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)
LValue emitCallExprLValue(const clang::CallExpr *e)
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.
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 > 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")
void maybeEmitDeferredVarDeclInit(const VarDecl *vd)
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)
mlir::LogicalResult emitIfStmt(const clang::IfStmt &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::Value emitPromotedScalarExpr(const Expr *e, QualType promotionType)
AggValueSlot::Overlap_t getOverlapForReturnValue()
Determine whether a return value slot may overlap some other object.
cir::BrOp emitBranchThroughCleanup(mlir::Location loc, JumpDest dest)
Build a unconditional branch to the lexical scope cleanup block or with the labeled blocked if alread...
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)
CIRGenBuilderTy & getBuilder()
bool didCallStackSave
Whether a cir.stacksave operation has been added.
void emitDecl(const clang::Decl &d, bool evaluateConditionDecl=false)
LValue emitBinaryOperatorLValue(const BinaryOperator *e)
mlir::Value emitOpenACCIntExpr(const Expr *intExpr)
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.
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)
void Destroyer(CIRGenFunction &cgf, Address addr, QualType ty)
void emitDestructorBody(FunctionArgList &args)
Emits the body of the current destructor.
void emitAtomicInit(Expr *init, LValue dest)
LValue emitCastLValue(const CastExpr *e)
Casts are never lvalues unless that cast is to a reference type.
mlir::Value emitLoadOfScalar(LValue lvalue, SourceLocation loc)
EmitLoadOfScalar - Load a scalar value from an address, taking care to appropriately convert from the...
mlir::LogicalResult emitCXXTryStmt(const clang::CXXTryStmt &s)
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)
LValue emitDeclRefLValue(const clang::DeclRefExpr *e)
void emitComplexExprIntoLValue(const Expr *e, LValue dest, bool isInit)
mlir::Value emitRuntimeCall(mlir::Location loc, cir::FuncOp callee, llvm::ArrayRef< mlir::Value > args={})
llvm::DenseMap< const clang::ValueDecl *, clang::FieldDecl * > lambdaCaptureFields
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)
LValue makeAddrLValue(Address addr, QualType ty, AlignmentSource source=AlignmentSource::Type)
int64_t getAccessedFieldNo(unsigned idx, mlir::ArrayAttr elts)
LValue emitPredefinedLValue(const PredefinedExpr *e)
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.
void emitCXXDestructorCall(const CXXDestructorDecl *dd, CXXDtorType type, bool forVirtualBase, bool delegating, Address thisAddr, QualType thisTy)
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)
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)
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.
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.
CIRGenFunction(CIRGenModule &cgm, CIRGenBuilderTy &builder, bool suppressNewContext=false)
void populateCatchHandlers(cir::TryOp tryOp)
std::optional< mlir::Location > currSrcLoc
Use to track source locations across nested visitor traversals.
LValue emitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *e)
LValue emitExtVectorElementExpr(const ExtVectorElementExpr *e)
clang::ASTContext & getContext() const
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 emitCXXDeleteExpr(const CXXDeleteExpr *e)
mlir::LogicalResult emitCoroutineBody(const CoroutineBodyStmt &s)
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 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 ...
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 popCleanupBlocks(EHScopeStack::stable_iterator oldCleanupStackDepth)
Takes the old cleanup stack size and emits the cleanup blocks that have been added.
RValue getOrCreateOpaqueRValueMapping(const OpaqueValueExpr *e)
Given an opaque value expression, return its RValue mapping if it exists, otherwise create one.
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.
Address emitVAListRef(const Expr *e)
Build a "reference" to a va_list; this is either the address or the value of the expression,...
mlir::LogicalResult emitCompoundStmtWithoutScope(const clang::CompoundStmt &s, Address *lastValue=nullptr, AggValueSlot slot=AggValueSlot::ignored())
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)
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)
void popCleanupBlock()
Pops a cleanup block.
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)
Get the address of a zero-sized field within a record.
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:48
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:191
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
Contains the address where the return value of a function can be stored, and whether the address is v...
Definition CIRGenCall.h:254
Represents a call to a C++ constructor.
Definition ExprCXX.h:1548
Represents a C++ constructor within a class.
Definition DeclCXX.h:2604
Represents a C++ base or member initializer.
Definition DeclCXX.h:2369
A default argument (C++ [dcl.fct.default]).
Definition ExprCXX.h:1270
A use of a default initializer in a constructor or in aggregate initialization.
Definition ExprCXX.h:1377
Represents a delete expression for memory deallocation and destructor calls, e.g.
Definition ExprCXX.h:2626
Represents a C++ destructor within a class.
Definition DeclCXX.h:2869
A C++ dynamic_cast expression (C++ [expr.dynamic.cast]).
Definition ExprCXX.h:481
CXXForRangeStmt - This represents C++0x [stmt.ranged]'s ranged for statement, represented as 'for (ra...
Definition StmtCXX.h:135
Represents a call to a member function that may be written either with member call syntax (e....
Definition ExprCXX.h:179
Represents a static or instance method of a struct/union/class.
Definition DeclCXX.h:2129
Represents a new-expression for memory allocation and constructor calls, e.g: "new CXXNewExpr(foo)".
Definition ExprCXX.h:2355
A call to an overloaded operator written using operator syntax.
Definition ExprCXX.h:84
Represents a C++ pseudo-destructor (C++ [expr.pseudo]).
Definition ExprCXX.h:2745
Represents a C++ struct/union/class.
Definition DeclCXX.h:258
Represents a C++ temporary.
Definition ExprCXX.h:1459
A C++ throw-expression (C++ [except.throw]).
Definition ExprCXX.h:1208
CXXTryStmt - A C++ try block, including all handlers.
Definition StmtCXX.h:69
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition Expr.h:2877
CaseStmt - Represent a case statement.
Definition Stmt.h:1910
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
Definition Expr.h:3610
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
Represents a 'co_await' expression.
Definition ExprCXX.h:5369
CompoundAssignOperator - For compound assignments (e.g.
Definition Expr.h:4234
CompoundLiteralExpr - [C99 6.5.2.5].
Definition Expr.h:3539
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition Stmt.h:1730
ContinueStmt - This represents a continue.
Definition Stmt.h:3109
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:1270
DeclStmt - Adaptor class for mixing declarations with statements and expressions.
Definition Stmt.h:1621
Decl - This represents one declaration (or definition), e.g.
Definition DeclBase.h:86
DoStmt - This represents a 'do/while' stmt.
Definition Stmt.h:2822
This represents one expression.
Definition Expr.h:112
ExtVectorElementExpr - This represents access to specific elements of a vector, and may occur on the ...
Definition Expr.h:6498
Represents a member of a struct/union/class.
Definition Decl.h:3160
ForStmt - This represents a 'for (init;cond;inc)' stmt.
Definition Stmt.h:2878
Represents a function declaration or definition.
Definition Decl.h:2000
Represents a prototype with parameter type info, e.g.
Definition TypeBase.h:5254
GlobalDecl - represents a global declaration.
Definition GlobalDecl.h:57
GotoStmt - This represents a direct goto.
Definition Stmt.h:2959
IfStmt - This represents an if/then/else.
Definition Stmt.h:2249
IndirectGotoStmt - This represents an indirect goto.
Definition Stmt.h:2998
Represents the declaration of a label.
Definition Decl.h:524
LabelStmt - Represents a label, which has a substatement.
Definition Stmt.h:2136
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:3298
A pointer to member type per C++ 8.3.3 - Pointers to members.
Definition TypeBase.h:3653
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
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:1178
Expr * getSourceExpr() const
The source expression of an opaque value expression is the expression which originally generated the ...
Definition Expr.h:1228
Represents a parameter to a function.
Definition Decl.h:1790
[C99 6.4.2.2] - A predefined identifier such as func.
Definition Expr.h:2005
A (possibly-)qualified type.
Definition TypeBase.h:937
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
Definition TypeBase.h:8318
The collection of all-type qualifiers we support.
Definition TypeBase.h:331
ReturnStmt - This represents a return, optionally of an expression: return; return 4;.
Definition Stmt.h:3150
Encodes a location in the source.
A trivial tuple used to represent a source range.
Stmt - This represents one statement.
Definition Stmt.h:85
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
Definition Stmt.cpp:338
SwitchStmt - This represents a 'switch' stmt.
Definition Stmt.h:2499
Exposes information about the current target.
Definition TargetInfo.h:226
Represents a declaration of a type.
Definition Decl.h:3513
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:2244
Represents a call to the builtin function __builtin_va_arg.
Definition Expr.h:4891
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:926
Represents a C array with a specified size that is not an integer-constant-expression.
Definition TypeBase.h:3966
WhileStmt - This represents a 'while' stmt.
Definition Stmt.h:2687
#define bool
Definition gpuintrin.h:32
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.
@ NormalCleanup
Denotes a cleanup that should run when a scope is exited using normal control flow (falling off the e...
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.
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)
const FunctionProtoType * T
CXXDtorType
C++ destructor types.
Definition ABI.h:34
#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)
Represents a scope, including function bodies, compound statements, and the substatements of if/while...
llvm::ArrayRef< mlir::Block * > getRetBlocks()
mlir::Block * createCleanupBlock(mlir::OpBuilder &builder)
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::Block * getCleanupBlock(mlir::OpBuilder &builder)
mlir::Block * getOrCreateCleanupBlock(mlir::OpBuilder &builder)
mlir::Location getRetLoc(mlir::Block *b)
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)