27class AggExprEmitter :
public StmtVisitor<AggExprEmitter> {
38 void withReturnValueSlot(
const Expr *e,
51 : cgf(cgf), dest(dest) {}
56 void emitAggLoadOfLValue(
const Expr *e);
58 void emitArrayInit(
Address destPtr, cir::ArrayType arrayTy,
QualType arrayQTy,
65 void emitInitializationToLValue(
Expr *e,
LValue lv);
67 void emitNullInitializationToLValue(mlir::Location loc,
LValue lv);
71 void VisitCallExpr(
const CallExpr *e);
72 void VisitStmtExpr(
const StmtExpr *e) {
79 void VisitDeclRefExpr(
DeclRefExpr *e) { emitAggLoadOfLValue(e); }
103 case CK_LValueToRValue:
108 "AggExprEmitter: volatile lvalue-to-rvalue cast");
111 case CK_UserDefinedConversion:
112 case CK_ConstructorConversion:
115 "Implicit cast types must be compatible");
120 std::string(
"AggExprEmitter: VisitCastExpr: ") +
125 void VisitStmt(
Stmt *
s) {
127 std::string(
"AggExprEmitter::VisitStmt: ") +
128 s->getStmtClassName());
135 "AggExprEmitter: VisitGenericSelectionExpr");
148 "AggExprEmitter: VisitUnaryExtension");
152 "AggExprEmitter: VisitSubstNonTypeTemplateParmExpr");
168 "AggExprEmitter: VisitCompoundLiteralExpr");
172 "AggExprEmitter: VisitArraySubscriptExpr");
176 "AggExprEmitter: VisitPredefinedExpr");
180 "AggExprEmitter: VisitBinaryOperator");
182 void VisitPointerToDataMemberBinaryOperator(
const BinaryOperator *e) {
184 "AggExprEmitter: VisitPointerToDataMemberBinaryOperator");
197 "AggExprEmitter: VisitCXXRewrittenBinaryOperator");
201 "AggExprEmitter: VisitObjCMessageExpr");
205 "AggExprEmitter: VisitObjCIVarRefExpr");
210 "AggExprEmitter: VisitDesignatedInitUpdateExpr");
214 "AggExprEmitter: VisitAbstractConditionalOperator");
221 "AggExprEmitter: VisitCXXParenListInitExpr");
224 llvm::Value *outerBegin =
nullptr) {
226 "AggExprEmitter: VisitArrayInitLoopExpr");
230 "AggExprEmitter: VisitImplicitValueInitExpr");
237 "AggExprEmitter: VisitCXXDefaultArgExpr");
241 "AggExprEmitter: VisitCXXDefaultInitExpr");
245 "AggExprEmitter: VisitCXXInheritedCtorInitExpr");
252 "AggExprEmitter: VisitCXXStdInitializerListExpr");
257 "AggExprEmitter: VisitExprWithCleanups");
261 "AggExprEmitter: VisitCXXScalarValueInitExpr");
268 "AggExprEmitter: VisitMaterializeTemporaryExpr");
272 "AggExprEmitter: VisitOpaqueValueExpr");
277 "AggExprEmitter: VisitPseudoObjectExpr");
298 if (isa<ImplicitValueInitExpr>(e))
301 if (
auto *ile = dyn_cast<InitListExpr>(e)) {
302 if (ile->getNumInits())
307 if (
const auto *cons = dyn_cast_or_null<CXXConstructExpr>(e))
308 return cons->getConstructor()->isDefaultConstructor() &&
309 cons->getConstructor()->isTrivial();
316void AggExprEmitter::emitAggLoadOfLValue(
const Expr *e) {
322 emitFinalDestCopy(e->
getType(), lv);
325void AggExprEmitter::emitArrayInit(
Address destPtr, cir::ArrayType arrayTy,
331 const uint64_t numInitElements = args.size();
337 cgf.
cgm.
errorNYI(loc,
"initialized array requires destruction");
343 const mlir::Type cirElementType = cgf.
convertType(elementType);
344 const cir::PointerType cirElementPtrType =
347 auto begin = cir::CastOp::create(builder, loc, cirElementPtrType,
348 cir::CastKind::array_to_ptrdecay,
361 mlir::Value element = begin;
368 for (uint64_t i = 0; i != numInitElements; ++i) {
375 const Address address =
Address(element, cirElementType, elementAlign);
377 emitInitializationToLValue(args[i], elementLV);
380 const uint64_t numArrayElements = arrayTy.getSize();
388 if (numInitElements != numArrayElements &&
389 !(dest.
isZeroed() && hasTrivialFiller &&
392 if (numInitElements) {
394 element = cir::PtrStrideOp::create(builder, loc, cirElementPtrType,
406 cir::ConstantOp numArrayElementsConst = builder.
getConstInt(
407 loc, mlir::cast<cir::IntType>(cgf.
PtrDiffTy), numArrayElements);
408 mlir::Value end = cir::PtrStrideOp::create(builder, loc, cirElementPtrType,
409 begin, numArrayElementsConst);
414 [&](mlir::OpBuilder &
b, mlir::Location loc) {
415 cir::LoadOp currentElement = builder.
createLoad(loc, tmpAddr);
417 cir::CmpOp cmp = cir::CmpOp::create(
418 builder, loc, boolTy, cir::CmpOpKind::ne, currentElement, end);
422 [&](mlir::OpBuilder &
b, mlir::Location loc) {
423 cir::LoadOp currentElement = builder.
createLoad(loc, tmpAddr);
429 Address(currentElement, cirElementType, elementAlign),
432 emitInitializationToLValue(arrayFiller, elementLV);
434 emitNullInitializationToLValue(loc, elementLV);
438 cgf.
cgm.
errorNYI(loc,
"update destructed array element for EH");
444 loc, mlir::cast<cir::IntType>(cgf.
PtrDiffTy), 1);
445 auto nextElement = cir::PtrStrideOp::create(
446 builder, loc, cirElementPtrType, currentElement, one);
463 cgf.
cgm.
errorNYI(
"emitFinalDestCopy: non-ignored dest is NYI");
466void AggExprEmitter::emitInitializationToLValue(
Expr *e,
LValue lv) {
469 if (isa<ImplicitValueInitExpr, CXXScalarValueInitExpr>(e)) {
473 return emitNullInitializationToLValue(loc, lv);
476 if (isa<NoInitExpr>(e))
479 if (
type->isReferenceType())
480 cgf.
cgm.
errorNYI(
"emitInitializationToLValue ReferenceType");
484 cgf.
cgm.
errorNYI(
"emitInitializationToLValue TEK_Complex");
507void AggExprEmitter::emitNullInitializationToLValue(mlir::Location loc,
524 cgf.
cgm.
errorNYI(
"emitStoreThroughBitfieldLValue");
534void AggExprEmitter::VisitCallExpr(
const CallExpr *e) {
544void AggExprEmitter::withReturnValueSlot(
549 bool requiresDestruction =
551 if (requiresDestruction)
554 "withReturnValueSlot: return value requiring destruction is NYI");
572void AggExprEmitter::VisitInitListExpr(
InitListExpr *e) {
574 llvm_unreachable(
"GNU array range designator extension");
579 visitCXXParenListOrInitListExpr(
583void AggExprEmitter::visitCXXParenListOrInitListExpr(
591 cir::ArrayType arrayTy =
598 "visitCXXParenListOrInitListExpr variable array type");
604 "visitCXXParenListOrInitListExpr array type");
614 unsigned numInitElements = args.size();
621 unsigned curInitIndex = 0;
624 if (
auto *cxxrd = dyn_cast<CXXRecordDecl>(record)) {
625 assert(numInitElements >= cxxrd->getNumBases() &&
626 "missing initializer for base class");
627 if (cxxrd->getNumBases() > 0) {
629 "visitCXXParenListOrInitListExpr base class init");
636 if (record->isUnion()) {
638 "visitCXXParenListOrInitListExpr union type");
644 for (
const FieldDecl *field : record->fields()) {
646 if (field->getType()->isIncompleteArrayType())
650 if (field->isUnnamedBitField())
656 if (curInitIndex == numInitElements && dest.
isZeroed() &&
664 if (curInitIndex < numInitElements) {
667 cgf, cgf.
getLoc(record->getSourceRange())};
668 emitInitializationToLValue(args[curInitIndex++], lv);
677 if (field->getType().isDestructedType()) {
679 "visitCXXParenListOrInitListExpr destructor");
703 getContext().getASTRecordLayout(baseRD).getSize() <=
712 AggExprEmitter(*
this, slot).Visit(
const_cast<Expr *
>(e));
static bool isTrivialFiller(Expr *e)
__device__ __2f16 float __ockl_bool s
cir::ConditionOp createCondition(mlir::Value condition)
Create a loop condition.
cir::PtrStrideOp createPtrStride(mlir::Location loc, mlir::Value base, mlir::Value stride)
cir::PointerType getPointerTo(mlir::Type ty)
cir::DoWhileOp createDoWhile(mlir::Location loc, llvm::function_ref< void(mlir::OpBuilder &, mlir::Location)> condBuilder, llvm::function_ref< void(mlir::OpBuilder &, mlir::Location)> bodyBuilder)
Create a do-while operation.
cir::ConstantOp getConstantInt(mlir::Location loc, mlir::Type ty, int64_t value)
cir::YieldOp createYield(mlir::Location loc, mlir::ValueRange value={})
Create a yield operation.
const ASTRecordLayout & getASTRecordLayout(const RecordDecl *D) const
Get or compute information about the layout of the specified record (struct/union/class) D,...
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
bool hasSameUnqualifiedType(QualType T1, QualType T2) const
Determine whether the given types are equivalent after cvr-qualifiers have been removed.
const ArrayType * getAsArrayType(QualType T) const
Type Query functions.
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
ASTRecordLayout - This class contains layout information for one RecordDecl, which is a struct/union/...
CharUnits getBaseClassOffset(const CXXRecordDecl *Base) const
getBaseClassOffset - Get the offset, in chars, for the given base class.
CharUnits getNonVirtualSize() const
getNonVirtualSize - Get the non-virtual size (in chars) of an object, which is the size of the object...
AbstractConditionalOperator - An abstract base class for ConditionalOperator and BinaryConditionalOpe...
Represents a loop initializing the elements of an array.
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
QualType getElementType() const
AtomicExpr - Variadic atomic builtins: __atomic_exchange, __atomic_fetch_*, __atomic_load,...
A builtin binary operation expression such as "x + y" or "x <= y".
mlir::Value getPointer() const
mlir::Type getElementType() const
clang::CharUnits getAlignment() const
IsZeroed_t isZeroed() const
static AggValueSlot forLValue(const LValue &LV, IsDestructed_t isDestructed, IsAliased_t isAliased, Overlap_t mayOverlap, IsZeroed_t isZeroed=IsNotZeroed)
Address getAddress() const
cir::ConstantOp getConstInt(mlir::Location loc, llvm::APSInt intVal)
cir::LoadOp createLoad(mlir::Location loc, Address addr, bool isVolatile=false)
An RAII object to record that we're evaluating a statement expression.
static bool hasScalarEvaluationKind(clang::QualType type)
mlir::Type convertType(clang::QualType t)
static cir::TypeEvaluationKind getEvaluationKind(clang::QualType type)
Return the cir::TypeEvaluationKind of QualType type.
CIRGenTypes & getTypes() 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,...
RValue emitCallExpr(const clang::CallExpr *e, ReturnValueSlot returnValue=ReturnValueSlot())
LValue emitLValue(const clang::Expr *e)
Emit code to compute a designator that specifies the location of the expression.
void emitStoreOfScalar(mlir::Value value, Address addr, bool isVolatile, clang::QualType ty, bool isInit=false, bool isNontemporal=false)
mlir::Location getLoc(clang::SourceLocation srcLoc)
Helpers to convert Clang's SourceLocation to a MLIR Location.
void emitNullInitialization(mlir::Location loc, Address destPtr, QualType ty)
void emitCXXConstructExpr(const clang::CXXConstructExpr *e, AggValueSlot dest)
LValue emitAggExprToLValue(const Expr *e)
static bool hasAggregateEvaluationKind(clang::QualType type)
void emitScalarInit(const clang::Expr *init, mlir::Location loc, LValue lvalue, bool capturedByInit=false)
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 emitScalarExpr(const clang::Expr *e)
Emit the computation of the specified expression of scalar type.
CIRGenBuilderTy & getBuilder()
AggValueSlot::Overlap_t getOverlapForBaseInit(const CXXRecordDecl *rd, const CXXRecordDecl *baseRD, bool isVirtual)
Determine whether a base class initialization may overlap some other object.
LValue makeAddrLValue(Address addr, QualType ty, AlignmentSource source=AlignmentSource::Type)
std::optional< mlir::Location > currSrcLoc
Use to track source locations across nested visitor traversals.
clang::ASTContext & getContext() const
mlir::LogicalResult emitCompoundStmt(const clang::CompoundStmt &s, Address *lastValue=nullptr, AggValueSlot slot=AggValueSlot::ignored())
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 ...
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 emitAggExpr(const clang::Expr *e, AggValueSlot slot)
DiagnosticBuilder errorNYI(SourceLocation, llvm::StringRef)
Helpers to emit "not yet implemented" error diagnostics.
const clang::LangOptions & getLangOpts() const
mlir::Value emitNullConstant(QualType t, mlir::Location loc)
Return the result of value-initializing the given type, i.e.
bool isZeroInitializable(clang::QualType ty)
Return whether a type can be zero-initialized (in the C++ sense) with an LLVM zeroinitializer.
Address getAddress() const
clang::QualType getType() const
This trivial value class is used to represent the result of an expression that is evaluated.
static RValue get(mlir::Value v)
Contains the address where the return value of a function can be stored, and whether the address is v...
Represents binding an expression to a temporary.
const Expr * getSubExpr() const
Represents a call to a C++ constructor.
A default argument (C++ [dcl.fct.default]).
A use of a default initializer in a constructor or in aggregate initialization.
Represents an explicit C++ type conversion that uses "functional" notation (C++ [expr....
Represents a call to an inherited base class constructor from an inheriting constructor.
Represents a list-initialization with parenthesis.
SourceRange getSourceRange() const LLVM_READONLY
Represents a C++ struct/union/class.
A rewritten comparison expression that was originally written using operator syntax.
SourceRange getSourceRange() const LLVM_READONLY
An expression "T()" which creates an rvalue of a non-class type T.
Implicit construction of a std::initializer_list<T> object from an array temporary within list-initia...
SourceRange getSourceRange() const LLVM_READONLY
Retrieve the source range of the expression.
A C++ throw-expression (C++ [except.throw]).
A C++ typeid expression (C++ [expr.typeid]), which gets the type_info that corresponds to the supplie...
SourceRange getSourceRange() const LLVM_READONLY
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
QualType getCallReturnType(const ASTContext &Ctx) const
getCallReturnType - Get the return type of the call expr.
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
CastKind getCastKind() const
static const char * getCastKindName(CastKind CK)
CharUnits - This is an opaque type for sizes expressed in character units.
CharUnits alignmentOfArrayElement(CharUnits elementSize) const
Given that this is the alignment of the first element of an array, return the minimum alignment of an...
ChooseExpr - GNU builtin-in function __builtin_choose_expr.
Represents a 'co_await' expression.
CompoundLiteralExpr - [C99 6.5.2.5].
ConstantExpr - An expression that occurs in a constant context and optionally the result of evaluatin...
Represents a 'co_yield' expression.
A reference to a declared variable, function, enum, etc.
Represents an expression – generally a full-expression – that introduces cleanups to be run at the en...
This represents one expression.
Represents a member of a struct/union/class.
Represents a C11 generic selection.
Represents an implicitly-generated value initialization of an object of a given type.
Describes an C or C++ initializer list.
bool isTransparent() const
Is this a transparent initializer list (that is, an InitListExpr that is purely syntactic,...
FieldDecl * getInitializedFieldInUnion()
If this initializes a union, specifies which field in the union to initialize.
bool hadArrayRangeDesignator() const
Expr * getArrayFiller()
If this initializer list initializes an array with more elements than there are initializers in the l...
const Expr * getInit(unsigned Init) const
ArrayRef< Expr * > inits()
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
Represents a prvalue temporary that is written into memory so that a reference can bind to it.
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
Represents a place-holder for an object not to be initialized by anything.
ObjCIvarRefExpr - A reference to an ObjC instance variable.
An expression that sends a message to the given Objective-C object or class.
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.
ParenExpr - This represents a parenthesized expression, e.g.
[C99 6.4.2.2] - A predefined identifier such as func.
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
A (possibly-)qualified type.
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
DestructionKind isDestructedType() const
Returns a nonzero value if objects of this type require non-trivial work to clean up after.
StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
CompoundStmt * getSubStmt()
RetTy Visit(PTR(Stmt) S, ParamTys... P)
StmtVisitor - This class implements a simple visitor for Stmt subclasses.
Stmt - This represents one statement.
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
StringLiteral - This represents a string literal expression, e.g.
Represents a reference to a non-type template parameter that has been substituted with a template arg...
bool isConstantArrayType() const
bool isReferenceType() const
bool isVariableArrayType() const
RecordDecl * castAsRecordDecl() const
bool isRecordType() const
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Represents a call to the builtin function __builtin_va_arg.
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
The JSON file list parser is used to communicate input to InstallAPI.
static bool emitLifetimeMarkers()
static bool aggValueSlotDestructedFlag()
static bool aggValueSlotGC()
static bool aggValueSlotAlias()
static bool opLoadStoreAtomic()
static bool aggValueSlotVolatile()
static bool constEmitterAggILE()
static bool requiresCleanups()
clang::CharUnits getPointerAlign() const