24struct MemberCallInfo {
35 assert(ce ==
nullptr || isa<CXXMemberCallExpr>(ce) ||
36 isa<CXXOperatorCallExpr>(ce));
38 "Trying to emit a member or operator call expr on a static method!");
53 unsigned prefixSize = args.size() - 1;
63 unsigned argsToSkip = isa<CXXOperatorCallExpr>(ce) ? 1 : 0;
68 fpt->getNumParams() == 0 &&
69 "No CallExpr specified for function with non-zero number of arguments");
73 return {required, prefixSize};
80 assert(isa<CXXMemberCallExpr>(ce) || isa<CXXOperatorCallExpr>(ce));
83 bool canUseVirtualCall = md->
isVirtual() && !hasQualifier;
99 if (
auto *oce = dyn_cast<CXXOperatorCallExpr>(ce)) {
100 if (oce->isAssignmentOp()) {
101 rtlArgs = &rtlArgStorage;
118 if (isa<CXXConstructorDecl>(md)) {
120 "emitCXXMemberOrOperatorMemberCallExpr: constructor call");
125 isa<CXXDestructorDecl>(md))
130 devirtualizedMethod ? devirtualizedMethod : md;
132 if (isa<CXXDestructorDecl>(calleeDecl)) {
134 "emitCXXMemberOrOperatorMemberCallExpr: destructor call");
151 bool useVirtualCall = canUseVirtualCall && !devirtualizedMethod;
153 if (isa<CXXDestructorDecl>(calleeDecl)) {
155 "emitCXXMemberOrOperatorMemberCallExpr: destructor call");
160 if (useVirtualCall) {
166 "emitCXXMemberOrOperatorMemberCallExpr: AppleKext");
177 *
this, calleeDecl, thisPtr.
getAddress(), useVirtualCall);
182 calleeDecl, callee, returnValue, thisPtr.
getPointer(),
191 "Trying to emit a member call expr on a static method!");
193 e, md, returnValue,
false, std::nullopt,
199 ReturnValueSlot returnValue, mlir::Value thisPtr, mlir::Value implicitParam,
204 *
this, md, thisPtr, implicitParam, implicitParamTy, ce, args, rtlArgs);
206 args, fpt, callInfo.reqArgs, callInfo.prefixSize);
207 assert((ce ||
currSrcLoc) &&
"expected source location");
210 return emitCall(fnInfo, callee, returnValue, args,
nullptr, loc);
214 unsigned minElements,
215 mlir::Value &numElements,
216 mlir::Value &sizeWithoutCookie) {
224 return sizeWithoutCookie;
242 "storeAnyExprIntoOneUnit: complex");
254 llvm_unreachable(
"bad evaluation kind");
258 QualType elementType, mlir::Type elementTy,
259 Address newPtr, mlir::Value numElements,
260 mlir::Value allocSizeWithoutCookie) {
278 "Pointer/Object mixup");
284 implicitParamTy, ce, args,
nullptr);
285 assert((ce || dtor.
getDecl()) &&
"expected source location provider");
299 cir::CIRCallOpInterface callOrTryCall;
324 unsigned minElements = 0;
329 mlir::Value numElements =
nullptr;
330 mlir::Value allocSizeWithoutCookie =
nullptr;
332 *
this, e, minElements, numElements, allocSizeWithoutCookie);
340 "emitCXXNewExpr: reserved global placement operator");
344 unsigned paramsToSkip = 0;
351 if (allocSize != allocSizeWithoutCookie) {
353 allocAlign = std::max(allocAlign, cookieAlign);
378 unsigned allocatorAlign = llvm::bit_floor(std::min<uint64_t>(
380 allocationAlign = std::max(
381 allocationAlign,
getContext().toCharUnitsFromBits(allocatorAlign));
384 mlir::Value allocPtr = rv.
getValue();
386 allocPtr, mlir::cast<cir::PointerType>(allocPtr.getType()).getPointee(),
406 if (allocSize != allocSizeWithoutCookie)
411 allocation, elementTy);
424 allocSizeWithoutCookie);
static void emitNewInitializer(CIRGenFunction &cgf, const CXXNewExpr *e, QualType elementType, mlir::Type elementTy, Address newPtr, mlir::Value numElements, mlir::Value allocSizeWithoutCookie)
static mlir::Value emitCXXNewAllocSize(CIRGenFunction &cgf, const CXXNewExpr *e, unsigned minElements, mlir::Value &numElements, mlir::Value &sizeWithoutCookie)
static void storeAnyExprIntoOneUnit(CIRGenFunction &cgf, const Expr *init, QualType allocType, Address newPtr, AggValueSlot::Overlap_t mayOverlap)
static MemberCallInfo commonBuildCXXMemberOrOperatorCall(CIRGenFunction &cgf, const CXXMethodDecl *md, mlir::Value thisPtr, mlir::Value implicitParam, QualType implicitParamTy, const CallExpr *ce, CallArgList &args, CallArgList *rtlArgs)
static RValue emitNewDeleteCall(CIRGenFunction &cgf, const FunctionDecl *calleeDecl, const FunctionProtoType *calleeType, const CallArgList &args)
Emit a call to an operator new or operator delete function, as implicitly created by new-expressions ...
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Defines the clang::Expr interface and subclasses for C++ expressions.
cir::ConstantOp getConstant(mlir::Location loc, mlir::TypedAttr attr)
CharUnits getTypeAlignInChars(QualType T) const
Return the ABI-specified alignment of a (complete) type T, in characters.
QualType getBaseElementType(const ArrayType *VAT) const
Return the innermost element type of an array type.
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
QualType getSizeType() const
Return the unique type for "size_t" (C99 7.17), defined in <stddef.h>.
const TargetInfo & getTargetInfo() const
mlir::Value getPointer() const
static AggValueSlot forAddr(Address addr, clang::Qualifiers quals, IsDestructed_t isDestructed, IsAliased_t isAliased, Overlap_t mayOverlap, IsZeroed_t isZeroed=IsNotZeroed)
Address createElementBitCast(mlir::Location loc, Address addr, mlir::Type destType)
Cast the element type of the given address to a different type, preserving information like the align...
virtual Address adjustThisArgumentForVirtualFunctionCall(CIRGenFunction &cgf, clang::GlobalDecl gd, Address thisPtr, bool virtualCall)
Perform ABI-specific "this" argument adjustment required prior to a call of a virtual function.
virtual const clang::CXXRecordDecl * getThisArgumentTypeForMethod(const clang::CXXMethodDecl *md)
Get the type of the implicit "this" parameter used by a method.
static CIRGenCallee forDirect(mlir::Operation *funcPtr, const CIRGenCalleeInfo &abstractInfo=CIRGenCalleeInfo())
static CIRGenCallee forVirtual(const clang::CallExpr *ce, clang::GlobalDecl md, Address addr, cir::FuncType fTy)
An abstract representation of regular/ObjC call/message targets.
void emitCallArgs(CallArgList &args, PrototypeWrapper prototype, llvm::iterator_range< clang::CallExpr::const_arg_iterator > argRange, AbstractCallee callee=AbstractCallee(), unsigned paramsToSkip=0)
static cir::TypeEvaluationKind getEvaluationKind(clang::QualType type)
Return the cir::TypeEvaluationKind of QualType type.
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...
const clang::LangOptions & getLangOpts() const
LValue emitLValue(const clang::Expr *e)
Emit code to compute a designator that specifies the location of the expression.
mlir::Location getLoc(clang::SourceLocation srcLoc)
Helpers to convert Clang's SourceLocation to a MLIR 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)
mlir::Type convertTypeForMem(QualType t)
mlir::Value emitCXXNewExpr(const CXXNewExpr *e)
void emitScalarInit(const clang::Expr *init, mlir::Location loc, LValue lvalue, bool capturedByInit=false)
RValue emitCall(const CIRGenFunctionInfo &funcInfo, const CIRGenCallee &callee, ReturnValueSlot returnValue, const CallArgList &args, cir::CIRCallOpInterface *callOp, mlir::Location loc)
CIRGenBuilderTy & getBuilder()
LValue makeAddrLValue(Address addr, QualType ty, AlignmentSource source=AlignmentSource::Type)
void emitCXXDestructorCall(const CXXDestructorDecl *dd, CXXDtorType type, bool forVirtualBase, bool delegating, Address thisAddr, QualType thisTy)
std::optional< mlir::Location > currSrcLoc
Use to track source locations across nested visitor traversals.
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)
RValue emitCXXOperatorMemberCallExpr(const CXXOperatorCallExpr *e, const CXXMethodDecl *md, ReturnValueSlot returnValue)
void emitAggExpr(const clang::Expr *e, AggValueSlot slot)
DiagnosticBuilder errorNYI(SourceLocation, llvm::StringRef)
Helpers to emit "not yet implemented" error diagnostics.
clang::ASTContext & getASTContext() const
cir::FuncOp getAddrOfFunction(clang::GlobalDecl gd, mlir::Type funcType=nullptr, bool forVTable=false, bool dontDefer=false, ForDefinition_t isForDefinition=NotForDefinition)
Return the address of the given function.
const clang::CodeGenOptions & getCodeGenOpts() const
CIRGenCXXABI & getCXXABI() const
const CIRGenFunctionInfo & arrangeCXXMethodDeclaration(const clang::CXXMethodDecl *md)
C++ methods have some special rules and also have implicit parameters.
const CIRGenFunctionInfo & arrangeCXXStructorDeclaration(clang::GlobalDecl gd)
const CIRGenFunctionInfo & arrangeFreeFunctionCall(const CallArgList &args, const FunctionType *fnType)
cir::FuncType getFunctionType(const CIRGenFunctionInfo &info)
Get the CIR function type for.
clang::CanQualType deriveThisType(const clang::CXXRecordDecl *rd, const clang::CXXMethodDecl *md)
Derives the 'this' type for CIRGen purposes, i.e.
const CIRGenFunctionInfo & arrangeCXXMethodCall(const CallArgList &args, const clang::FunctionProtoType *type, RequiredArgs required, unsigned numPrefixArgs)
Arrange a call to a C++ method, passing the given arguments.
void addFrom(const CallArgList &other)
Add all the arguments from another CallArgList to this one.
void add(RValue rvalue, clang::QualType type)
Address getAddress() const
mlir::Value getPointer() const
void setAddress(Address address)
This trivial value class is used to represent the result of an expression that is evaluated.
static RValue get(mlir::Value v)
mlir::Value getValue() const
Return the value of this scalar value.
A class for recording the number of arguments that a function signature requires.
static RequiredArgs getFromProtoWithExtraSlots(const clang::FunctionProtoType *prototype, unsigned additional)
Compute the arguments required by the given formal prototype, given that there may be some additional...
Contains the address where the return value of a function can be stored, and whether the address is v...
Represents a static or instance method of a struct/union/class.
const CXXRecordDecl * getParent() const
Return the parent of this method declaration, which is the class in which this method is defined.
Represents a new-expression for memory allocation and constructor calls, e.g: "new CXXNewExpr(foo)".
llvm::iterator_range< arg_iterator > placement_arguments()
QualType getAllocatedType() const
bool hasInitializer() const
Whether this new-expression has any initializer at all.
bool shouldNullCheckAllocation() const
True if the allocation result needs to be null-checked.
bool passAlignment() const
Indicates whether the required alignment should be implicitly passed to the allocation function.
FunctionDecl * getOperatorDelete() const
SourceRange getSourceRange() const
FunctionDecl * getOperatorNew() const
Expr * getInitializer()
The initializer of this new-expression.
A call to an overloaded operator written using operator syntax.
Represents a C++ struct/union/class.
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
FunctionDecl * getDirectCallee()
If the callee is a FunctionDecl, return it. Otherwise return null.
CharUnits - This is an opaque type for sizes expressed in character units.
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
virtual SourceRange getSourceRange() const LLVM_READONLY
Source range that this declaration covers.
This represents one expression.
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
Represents a function declaration or definition.
bool isTrivial() const
Whether this function is "trivial" in some specialized C++ senses.
bool isReplaceableGlobalAllocationFunction(UnsignedOrNone *AlignmentParam=nullptr, bool *IsNothrow=nullptr) const
Determines whether this function is one of the replaceable global allocation functions: void *operato...
bool isReservedGlobalPlacementOperator() const
Determines whether this operator new or delete is one of the reserved global placement operators: voi...
bool isDefaulted() const
Whether this function is defaulted.
Represents a prototype with parameter type info, e.g.
GlobalDecl - represents a global declaration.
const Decl * getDecl() const
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
A (possibly-)qualified type.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
bool isPODType(const ASTContext &Context) const
Determine whether this is a Plain Old Data (POD) type (C++ 3.9p10).
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
Exposes information about the current target.
unsigned getNewAlign() const
Return the largest alignment for which a suitably-sized allocation with '::operator new(size_t)' is g...
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
const T * castAs() const
Member-template castAs<specific type>.
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 addressSpace()
static bool aggValueSlotGC()
static bool devirtualizeMemberFunction()
static bool emitTypeCheck()
static bool opCallMustTail()
static bool exprNewNullCheck()
static bool attributeBuiltin()
static bool generateDebugInfo()
clang::CharUnits getSizeAlign() const