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);
218 llvm_unreachable(
"NVPTX does not support varargs");
221void NVPTXTargetCodeGenInfo::setTargetAttributes(
223 if (GV->isDeclaration())
225 const VarDecl *VD = dyn_cast_or_null<VarDecl>(D);
229 addNVVMMetadata(GV,
"surface", 1);
231 addNVVMMetadata(GV,
"texture", 1);
236 const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D);
239 llvm::Function *F = cast<llvm::Function>(GV);
245 if (FD->
hasAttr<OpenCLKernelAttr>()) {
248 addNVVMMetadata(F,
"kernel", 1);
250 F->addFnAttr(llvm::Attribute::NoInline);
259 if (FD->
hasAttr<CUDAGlobalAttr>()) {
261 addNVVMMetadata(F,
"kernel", 1);
263 if (CUDALaunchBoundsAttr *
Attr = FD->
getAttr<CUDALaunchBoundsAttr>())
268 if (FD->
hasAttr<NVPTXKernelAttr>()) {
269 addNVVMMetadata(F,
"kernel", 1);
273void NVPTXTargetCodeGenInfo::addNVVMMetadata(llvm::GlobalValue *GV,
274 StringRef Name,
int Operand) {
275 llvm::Module *M = GV->getParent();
279 llvm::NamedMDNode *MD = M->getOrInsertNamedMetadata(
"nvvm.annotations");
281 llvm::Metadata *MDVals[] = {
282 llvm::ConstantAsMetadata::get(GV), llvm::MDString::get(Ctx, Name),
283 llvm::ConstantAsMetadata::get(
284 llvm::ConstantInt::get(llvm::Type::getInt32Ty(Ctx), Operand))};
286 MD->addOperand(llvm::MDNode::get(Ctx, MDVals));
289bool NVPTXTargetCodeGenInfo::shouldEmitStaticExternCAliases()
const {
295 llvm::PointerType *PT,
298 if (PT->getAddressSpace() != Ctx.getTargetAddressSpace(LangAS::opencl_local))
299 return llvm::ConstantPointerNull::get(PT);
301 auto NPT = llvm::PointerType::get(
302 PT->getContext(), Ctx.getTargetAddressSpace(LangAS::opencl_generic));
303 return llvm::ConstantExpr::getAddrSpaceCast(
304 llvm::ConstantPointerNull::get(NPT), PT);
309 const CUDALaunchBoundsAttr *
Attr,
310 int32_t *MaxThreadsVal,
311 int32_t *MinBlocksVal,
312 int32_t *MaxClusterRankVal) {
314 llvm::APSInt MaxThreads(32);
315 MaxThreads =
Attr->getMaxThreads()->EvaluateKnownConstInt(
getContext());
316 if (MaxThreads > 0) {
318 *MaxThreadsVal = MaxThreads.getExtValue();
321 NVPTXTargetCodeGenInfo::addNVVMMetadata(F,
"maxntidx",
322 MaxThreads.getExtValue());
329 if (
Attr->getMinBlocks()) {
330 llvm::APSInt MinBlocks(32);
331 MinBlocks =
Attr->getMinBlocks()->EvaluateKnownConstInt(
getContext());
334 *MinBlocksVal = MinBlocks.getExtValue();
337 NVPTXTargetCodeGenInfo::addNVVMMetadata(F,
"minctasm",
338 MinBlocks.getExtValue());
342 if (
Attr->getMaxBlocks()) {
343 llvm::APSInt MaxBlocks(32);
344 MaxBlocks =
Attr->getMaxBlocks()->EvaluateKnownConstInt(
getContext());
346 if (MaxClusterRankVal)
347 *MaxClusterRankVal = MaxBlocks.getExtValue();
350 NVPTXTargetCodeGenInfo::addNVVMMetadata(F,
"maxclusterrank",
351 MaxBlocks.getExtValue());
357std::unique_ptr<TargetCodeGenInfo>
359 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.
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 CodeGen::Address EmitVAArg(CodeGen::CodeGenFunction &CGF, CodeGen::Address VAListAddr, QualType Ty) 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)
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(CodeGenFunction &CGF) const
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)
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