10#include "TargetInfo.h"
11#include "llvm/IR/IntrinsicsNVPTX.h"
22class NVPTXTargetCodeGenInfo;
24class NVPTXABIInfo :
public ABIInfo {
25 NVPTXTargetCodeGenInfo &CGInfo;
28 NVPTXABIInfo(
CodeGenTypes &CGT, NVPTXTargetCodeGenInfo &Info)
57 return llvm::Type::getInt64Ty(
getABIInfo().getVMContext());
63 return llvm::Type::getInt64Ty(
getABIInfo().getVMContext());
67 LValue Src)
const override {
68 emitBuiltinSurfTexDeviceCopy(CGF, Dst, Src);
73 LValue Src)
const override {
74 emitBuiltinSurfTexDeviceCopy(CGF, Dst, Src);
80 static void addNVVMMetadata(llvm::GlobalValue *GV, StringRef Name,
86 llvm::Value *Handle =
nullptr;
90 if (
auto *ASC = llvm::dyn_cast_or_null<llvm::AddrSpaceCastOperator>(
C))
91 C = llvm::cast<llvm::Constant>(ASC->getPointerOperand());
92 if (
auto *GV = llvm::dyn_cast_or_null<llvm::GlobalVariable>(
C)) {
98 {GV},
"texsurf_handle");
106bool NVPTXABIInfo::isUnsupportedType(
QualType T)
const {
115 return EIT->getNumBits() >
121 return isUnsupportedType(AT->getElementType());
128 if (
const CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(RD))
130 if (isUnsupportedType(I.getType()))
134 if (isUnsupportedType(I->getType()))
141 unsigned MaxSize)
const {
144 const uint64_t Alignment = getContext().getTypeAlign(Ty);
145 const unsigned Div = std::min<unsigned>(MaxSize, Alignment);
146 llvm::Type *IntType = llvm::Type::getIntNTy(getVMContext(), Div);
155 if (getContext().getLangOpts().OpenMP &&
156 getContext().getLangOpts().OpenMPIsTargetDevice &&
157 isUnsupportedType(RetTy))
158 return coerceToIntArrayWithLimit(RetTy, 64);
166 RetTy = EnumTy->getDecl()->getIntegerType();
175 Ty = EnumTy->getDecl()->getIntegerType();
181 if (getContext().getLangOpts().CUDAIsDevice) {
184 CGInfo.getCUDADeviceBuiltinSurfaceDeviceType());
187 CGInfo.getCUDADeviceBuiltinTextureDeviceType());
189 return getNaturalAlignIndirect(Ty,
true);
193 if ((EIT->getNumBits() > 128) ||
194 (!getContext().getTargetInfo().hasInt128Type() &&
195 EIT->getNumBits() > 64))
196 return getNaturalAlignIndirect(Ty,
true);
207 for (
auto &&[ArgumentsCount, I] : llvm::enumerate(FI.
arguments()))
222 getContext().getTypeInfoInChars(Ty),
227void NVPTXTargetCodeGenInfo::setTargetAttributes(
229 if (GV->isDeclaration())
231 const VarDecl *VD = dyn_cast_or_null<VarDecl>(
D);
235 addNVVMMetadata(GV,
"surface", 1);
237 addNVVMMetadata(GV,
"texture", 1);
245 llvm::Function *F = cast<llvm::Function>(GV);
251 if (FD->
hasAttr<OpenCLKernelAttr>()) {
254 addNVVMMetadata(F,
"kernel", 1);
256 F->addFnAttr(llvm::Attribute::NoInline);
265 if (FD->
hasAttr<CUDAGlobalAttr>()) {
267 addNVVMMetadata(F,
"kernel", 1);
269 if (CUDALaunchBoundsAttr *
Attr = FD->
getAttr<CUDALaunchBoundsAttr>())
274 if (FD->
hasAttr<NVPTXKernelAttr>()) {
275 addNVVMMetadata(F,
"kernel", 1);
279void NVPTXTargetCodeGenInfo::addNVVMMetadata(llvm::GlobalValue *GV,
280 StringRef Name,
int Operand) {
281 llvm::Module *M = GV->getParent();
285 llvm::NamedMDNode *MD = M->getOrInsertNamedMetadata(
"nvvm.annotations");
287 llvm::Metadata *MDVals[] = {
288 llvm::ConstantAsMetadata::get(GV), llvm::MDString::get(Ctx, Name),
289 llvm::ConstantAsMetadata::get(
290 llvm::ConstantInt::get(llvm::Type::getInt32Ty(Ctx), Operand))};
292 MD->addOperand(llvm::MDNode::get(Ctx, MDVals));
295bool NVPTXTargetCodeGenInfo::shouldEmitStaticExternCAliases()
const {
301 llvm::PointerType *PT,
304 if (PT->getAddressSpace() != Ctx.getTargetAddressSpace(LangAS::opencl_local))
305 return llvm::ConstantPointerNull::get(PT);
307 auto NPT = llvm::PointerType::get(
308 PT->getContext(), Ctx.getTargetAddressSpace(LangAS::opencl_generic));
309 return llvm::ConstantExpr::getAddrSpaceCast(
310 llvm::ConstantPointerNull::get(NPT), PT);
315 const CUDALaunchBoundsAttr *
Attr,
316 int32_t *MaxThreadsVal,
317 int32_t *MinBlocksVal,
318 int32_t *MaxClusterRankVal) {
320 llvm::APSInt MaxThreads(32);
321 MaxThreads =
Attr->getMaxThreads()->EvaluateKnownConstInt(
getContext());
322 if (MaxThreads > 0) {
324 *MaxThreadsVal = MaxThreads.getExtValue();
327 NVPTXTargetCodeGenInfo::addNVVMMetadata(F,
"maxntidx",
328 MaxThreads.getExtValue());
335 if (
Attr->getMinBlocks()) {
336 llvm::APSInt MinBlocks(32);
337 MinBlocks =
Attr->getMinBlocks()->EvaluateKnownConstInt(
getContext());
340 *MinBlocksVal = MinBlocks.getExtValue();
343 NVPTXTargetCodeGenInfo::addNVVMMetadata(F,
"minctasm",
344 MinBlocks.getExtValue());
348 if (
Attr->getMaxBlocks()) {
349 llvm::APSInt MaxBlocks(32);
350 MaxBlocks =
Attr->getMaxBlocks()->EvaluateKnownConstInt(
getContext());
352 if (MaxClusterRankVal)
353 *MaxClusterRankVal = MaxBlocks.getExtValue();
356 NVPTXTargetCodeGenInfo::addNVVMMetadata(F,
"maxclusterrank",
357 MaxBlocks.getExtValue());
363std::unique_ptr<TargetCodeGenInfo>
365 return std::make_unique<NVPTXTargetCodeGenInfo>(CGM.
getTypes());
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
uint64_t getTypeSize(QualType T) const
Return the size of the specified (complete) type T, in bits.
const TargetInfo & getTargetInfo() const
Attr - This represents one attribute.
A fixed int type of a specified bitwidth.
Represents a base class of a C++ class.
Represents a C++ struct/union/class.
static CharUnits fromQuantity(QuantityType Quantity)
fromQuantity - Construct a CharUnits quantity from a raw integer type.
ABIArgInfo - Helper class to encapsulate information about how a specific C type should be passed to ...
static ABIArgInfo getIgnore()
static ABIArgInfo getDirect(llvm::Type *T=nullptr, unsigned Offset=0, llvm::Type *Padding=nullptr, bool CanBeFlattened=true, unsigned Align=0)
static ABIArgInfo getExtend(QualType Ty, llvm::Type *T=nullptr)
ABIInfo - Target specific hooks for defining how a type should be passed or returned from functions.
virtual RValue EmitVAArg(CodeGen::CodeGenFunction &CGF, CodeGen::Address VAListAddr, QualType Ty, AggValueSlot Slot) const =0
EmitVAArg - Emit the target dependent code to load a value of.
virtual void computeInfo(CodeGen::CGFunctionInfo &FI) const =0
Like RawAddress, an abstract representation of an aligned address, but the pointer contained in this ...
llvm::Value * emitRawPointer(CodeGenFunction &CGF) const
Return the pointer contained in this class after authenticating it and adding offset to it if necessa...
CGFunctionInfo - Class to encapsulate the information about a function definition.
ABIArgInfo & getReturnInfo()
unsigned getCallingConvention() const
getCallingConvention - Return the user specified calling convention, which has been translated into a...
CanQualType getReturnType() const
MutableArrayRef< ArgInfo > arguments()
void setEffectiveCallingConvention(unsigned Value)
unsigned getNumRequiredArgs() const
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
llvm::Value * EmitLoadOfScalar(Address Addr, bool Volatile, QualType Ty, SourceLocation Loc, AlignmentSource Source=AlignmentSource::Type, bool isNontemporal=false)
EmitLoadOfScalar - Load a scalar value from an address, taking care to appropriately convert from the...
llvm::CallInst * EmitRuntimeCall(llvm::FunctionCallee callee, const Twine &name="")
void EmitStoreOfScalar(llvm::Value *Value, Address Addr, bool Volatile, QualType Ty, AlignmentSource Source=AlignmentSource::Type, bool isInit=false, bool isNontemporal=false)
EmitStoreOfScalar - Store a scalar value to an address, taking care to appropriately convert from the...
This class organizes the cross-function state that is used while generating LLVM code.
void handleCUDALaunchBoundsAttr(llvm::Function *F, const CUDALaunchBoundsAttr *A, int32_t *MaxThreadsVal=nullptr, int32_t *MinBlocksVal=nullptr, int32_t *MaxClusterRankVal=nullptr)
Emit the IR encoding to attach the CUDA launch bounds attribute to F.
const LangOptions & getLangOpts() const
CodeGenTypes & getTypes()
ASTContext & getContext() const
llvm::Function * getIntrinsic(unsigned IID, ArrayRef< llvm::Type * > Tys=std::nullopt)
This class organizes the cross-module state that is used while lowering AST types to LLVM types.
LValue - This represents an lvalue references.
Address getAddress() const
RValue - This trivial value class is used to represent the result of an expression that is evaluated.
TargetCodeGenInfo - This class organizes various target-specific codegeneration issues,...
virtual bool emitCUDADeviceBuiltinSurfaceDeviceCopy(CodeGenFunction &CGF, LValue Dst, LValue Src) const
Emit the device-side copy of the builtin surface type.
virtual bool emitCUDADeviceBuiltinTextureDeviceCopy(CodeGenFunction &CGF, LValue Dst, LValue Src) const
Emit the device-side copy of the builtin texture type.
virtual llvm::Type * getCUDADeviceBuiltinSurfaceDeviceType() const
Return the device-side type for the CUDA device builtin surface type.
const T & getABIInfo() const
virtual void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV, CodeGen::CodeGenModule &M) const
setTargetAttributes - Provides a convenient hook to handle extra target-specific attributes for the g...
virtual llvm::Type * getCUDADeviceBuiltinTextureDeviceType() const
Return the device-side type for the CUDA device builtin texture type.
virtual llvm::Constant * getNullPointer(const CodeGen::CodeGenModule &CGM, llvm::PointerType *T, QualType QT) const
Get target specific null pointer.
virtual bool shouldEmitStaticExternCAliases() const
Decl - This represents one declaration (or definition), e.g.
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums.
Represents a member of a struct/union/class.
Represents a function declaration or definition.
A (possibly-)qualified type.
Represents a struct/union/class.
field_range fields() const
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Encodes a location in the source.
virtual bool hasInt128Type() const
Determine whether the __int128 type is supported on this target.
virtual bool hasFloat16Type() const
Determine whether the _Float16 type is supported on this target.
virtual bool hasFloat128Type() const
Determine whether the __float128 type is supported on this target.
bool isFloat16Type() const
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
bool isScalarType() const
bool isFloat128Type() const
bool isCUDADeviceBuiltinSurfaceType() const
Check if the type is the CUDA device builtin surface type.
bool isCUDADeviceBuiltinTextureType() const
Check if the type is the CUDA device builtin texture type.
const ArrayType * getAsArrayTypeUnsafe() const
A variant of getAs<> for array types which silently discards qualifiers from the outermost type.
bool isRealFloatingType() const
Floating point categories.
const T * getAs() const
Member-template getAs<specific type>'.
Represents a variable declaration or definition.
ABIArgInfo classifyArgumentType(CodeGenModule &CGM, CanQualType type)
Classify the rules for how to pass a particular type.
bool classifyReturnType(const CGCXXABI &CXXABI, CGFunctionInfo &FI, const ABIInfo &Info)
std::unique_ptr< TargetCodeGenInfo > createNVPTXTargetCodeGenInfo(CodeGenModule &CGM)
RValue emitVoidPtrVAArg(CodeGenFunction &CGF, Address VAListAddr, QualType ValueTy, bool IsIndirect, TypeInfoChars ValueInfo, CharUnits SlotSizeAndAlign, bool AllowHigherAlign, AggValueSlot Slot, bool ForceRightAdjust=false)
Emit va_arg for a platform using the common void* representation, where arguments are simply emitted ...
bool isAggregateTypeForABI(QualType T)
bool Div(InterpState &S, CodePtr OpPC)
1) Pops the RHS from the stack.
The JSON file list parser is used to communicate input to InstallAPI.
const FunctionProtoType * T