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:
107 case CK_UserDefinedConversion:
108 case CK_ConstructorConversion:
111 "Implicit cast types must be compatible");
116 std::string(
"AggExprEmitter: VisitCastExpr: ") +
121 void VisitStmt(
Stmt *
s) {
123 std::string(
"AggExprEmitter::VisitStmt: ") +
124 s->getStmtClassName());
131 "AggExprEmitter: VisitGenericSelectionExpr");
144 "AggExprEmitter: VisitUnaryExtension");
148 "AggExprEmitter: VisitSubstNonTypeTemplateParmExpr");
164 "AggExprEmitter: VisitCompoundLiteralExpr");
168 "AggExprEmitter: VisitArraySubscriptExpr");
172 "AggExprEmitter: VisitPredefinedExpr");
176 "AggExprEmitter: VisitBinaryOperator");
178 void VisitPointerToDataMemberBinaryOperator(
const BinaryOperator *e) {
180 "AggExprEmitter: VisitPointerToDataMemberBinaryOperator");
193 "AggExprEmitter: VisitCXXRewrittenBinaryOperator");
197 "AggExprEmitter: VisitObjCMessageExpr");
201 "AggExprEmitter: VisitObjCIVarRefExpr");
206 "AggExprEmitter: VisitDesignatedInitUpdateExpr");
210 "AggExprEmitter: VisitAbstractConditionalOperator");
217 "AggExprEmitter: VisitCXXParenListInitExpr");
220 llvm::Value *outerBegin =
nullptr) {
222 "AggExprEmitter: VisitArrayInitLoopExpr");
226 "AggExprEmitter: VisitImplicitValueInitExpr");
233 "AggExprEmitter: VisitCXXDefaultArgExpr");
237 "AggExprEmitter: VisitCXXDefaultInitExpr");
241 "AggExprEmitter: VisitCXXInheritedCtorInitExpr");
248 "AggExprEmitter: VisitCXXStdInitializerListExpr");
253 "AggExprEmitter: VisitExprWithCleanups");
257 "AggExprEmitter: VisitCXXScalarValueInitExpr");
264 "AggExprEmitter: VisitMaterializeTemporaryExpr");
268 "AggExprEmitter: VisitOpaqueValueExpr");
273 "AggExprEmitter: VisitPseudoObjectExpr");
294 if (isa<ImplicitValueInitExpr>(e))
297 if (
auto *ile = dyn_cast<InitListExpr>(e)) {
298 if (ile->getNumInits())
303 if (
const auto *cons = dyn_cast_or_null<CXXConstructExpr>(e))
304 return cons->getConstructor()->isDefaultConstructor() &&
305 cons->getConstructor()->isTrivial();
312void AggExprEmitter::emitAggLoadOfLValue(
const Expr *e) {
318 emitFinalDestCopy(e->
getType(), lv);
321void AggExprEmitter::emitArrayInit(
Address destPtr, cir::ArrayType arrayTy,
327 const uint64_t numInitElements = args.size();
333 cgf.
cgm.
errorNYI(loc,
"initialized array requires destruction");
339 const mlir::Type cirElementType = cgf.
convertType(elementType);
340 const cir::PointerType cirElementPtrType =
343 auto begin = cir::CastOp::create(builder, loc, cirElementPtrType,
344 cir::CastKind::array_to_ptrdecay,
357 mlir::Value element = begin;
364 for (uint64_t i = 0; i != numInitElements; ++i) {
371 const Address address =
Address(element, cirElementType, elementAlign);
373 emitInitializationToLValue(args[i], elementLV);
376 const uint64_t numArrayElements = arrayTy.getSize();
384 if (numInitElements != numArrayElements &&
385 !(dest.
isZeroed() && hasTrivialFiller &&
388 if (numInitElements) {
390 element = cir::PtrStrideOp::create(builder, loc, cirElementPtrType,
402 cir::ConstantOp numArrayElementsConst = builder.
getConstInt(
403 loc, mlir::cast<cir::IntType>(cgf.
PtrDiffTy), numArrayElements);
404 mlir::Value end = cir::PtrStrideOp::create(builder, loc, cirElementPtrType,
405 begin, numArrayElementsConst);
410 [&](mlir::OpBuilder &
b, mlir::Location loc) {
411 cir::LoadOp currentElement = builder.
createLoad(loc, tmpAddr);
413 cir::CmpOp cmp = cir::CmpOp::create(
414 builder, loc, boolTy, cir::CmpOpKind::ne, currentElement, end);
418 [&](mlir::OpBuilder &
b, mlir::Location loc) {
419 cir::LoadOp currentElement = builder.
createLoad(loc, tmpAddr);
425 Address(currentElement, cirElementType, elementAlign),
428 emitInitializationToLValue(arrayFiller, elementLV);
430 emitNullInitializationToLValue(loc, elementLV);
434 cgf.
cgm.
errorNYI(loc,
"update destructed array element for EH");
440 loc, mlir::cast<cir::IntType>(cgf.
PtrDiffTy), 1);
441 auto nextElement = cir::PtrStrideOp::create(
442 builder, loc, cirElementPtrType, currentElement, one);
459 cgf.
cgm.
errorNYI(
"emitFinalDestCopy: non-ignored dest is NYI");
462void AggExprEmitter::emitInitializationToLValue(
Expr *e,
LValue lv) {
465 if (isa<ImplicitValueInitExpr, CXXScalarValueInitExpr>(e)) {
469 return emitNullInitializationToLValue(loc, lv);
472 if (isa<NoInitExpr>(e))
475 if (
type->isReferenceType())
476 cgf.
cgm.
errorNYI(
"emitInitializationToLValue ReferenceType");
480 cgf.
cgm.
errorNYI(
"emitInitializationToLValue TEK_Complex");
503void AggExprEmitter::emitNullInitializationToLValue(mlir::Location loc,
520 cgf.
cgm.
errorNYI(
"emitStoreThroughBitfieldLValue");
530void AggExprEmitter::VisitCallExpr(
const CallExpr *e) {
540void AggExprEmitter::withReturnValueSlot(
545 bool requiresDestruction =
547 if (requiresDestruction)
550 "withReturnValueSlot: return value requiring destruction is NYI");
568void AggExprEmitter::VisitInitListExpr(
InitListExpr *e) {
570 llvm_unreachable(
"GNU array range designator extension");
575 visitCXXParenListOrInitListExpr(
579void AggExprEmitter::visitCXXParenListOrInitListExpr(
587 cir::ArrayType arrayTy =
594 "visitCXXParenListOrInitListExpr variable array type");
600 "visitCXXParenListOrInitListExpr array type");
610 unsigned numInitElements = args.size();
617 unsigned curInitIndex = 0;
620 if (
auto *cxxrd = dyn_cast<CXXRecordDecl>(record)) {
621 assert(numInitElements >= cxxrd->getNumBases() &&
622 "missing initializer for base class");
623 if (cxxrd->getNumBases() > 0) {
625 "visitCXXParenListOrInitListExpr base class init");
632 if (record->isUnion()) {
634 "visitCXXParenListOrInitListExpr union type");
640 for (
const FieldDecl *field : record->fields()) {
642 if (field->getType()->isIncompleteArrayType())
646 if (field->isUnnamedBitField())
652 if (curInitIndex == numInitElements && dest.
isZeroed() &&
660 if (curInitIndex < numInitElements) {
663 cgf, cgf.
getLoc(record->getSourceRange())};
664 emitInitializationToLValue(args[curInitIndex++], lv);
673 if (field->getType().isDestructedType()) {
675 "visitCXXParenListOrInitListExpr destructor");
699 getContext().getASTRecordLayout(baseRD).getSize() <=
708 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.
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