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)
37 bool isUnsupportedType(
QualType T)
const;
53 return llvm::Type::getInt64Ty(
getABIInfo().getVMContext());
59 return llvm::Type::getInt64Ty(
getABIInfo().getVMContext());
63 LValue Src)
const override {
64 emitBuiltinSurfTexDeviceCopy(CGF, Dst, Src);
69 LValue Src)
const override {
70 emitBuiltinSurfTexDeviceCopy(CGF, Dst, Src);
76 static void addNVVMMetadata(llvm::GlobalValue *GV, StringRef Name,
82 llvm::Value *Handle =
nullptr;
86 if (
auto *ASC = llvm::dyn_cast_or_null<llvm::AddrSpaceCastOperator>(
C))
87 C = llvm::cast<llvm::Constant>(ASC->getPointerOperand());
88 if (
auto *GV = llvm::dyn_cast_or_null<llvm::GlobalVariable>(
C)) {
94 {GV},
"texsurf_handle");
102bool NVPTXABIInfo::isUnsupportedType(
QualType T)
const {
111 return EIT->getNumBits() >
117 return isUnsupportedType(AT->getElementType());
124 if (
const CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(RD))
126 if (isUnsupportedType(I.getType()))
130 if (isUnsupportedType(I->getType()))
137 unsigned MaxSize)
const {
140 const uint64_t Alignment = getContext().getTypeAlign(Ty);
141 const unsigned Div = std::min<unsigned>(MaxSize, Alignment);
142 llvm::Type *IntType = llvm::Type::getIntNTy(getVMContext(), Div);
151 if (getContext().getLangOpts().OpenMP &&
152 getContext().getLangOpts().OpenMPIsTargetDevice &&
153 isUnsupportedType(RetTy))
154 return coerceToIntArrayWithLimit(RetTy, 64);
162 RetTy = EnumTy->getDecl()->getIntegerType();
171 Ty = EnumTy->getDecl()->getIntegerType();
177 if (getContext().getLangOpts().CUDAIsDevice) {
180 CGInfo.getCUDADeviceBuiltinSurfaceDeviceType());
183 CGInfo.getCUDADeviceBuiltinTextureDeviceType());
185 return getNaturalAlignIndirect(Ty,
true);
189 if ((EIT->getNumBits() > 128) ||
190 (!getContext().getTargetInfo().hasInt128Type() &&
191 EIT->getNumBits() > 64))
192 return getNaturalAlignIndirect(Ty,
true);
214 llvm_unreachable(
"NVPTX does not support varargs");
217void NVPTXTargetCodeGenInfo::setTargetAttributes(
219 if (GV->isDeclaration())
221 const VarDecl *VD = dyn_cast_or_null<VarDecl>(D);
225 addNVVMMetadata(GV,
"surface", 1);
227 addNVVMMetadata(GV,
"texture", 1);
232 const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D);
235 llvm::Function *F = cast<llvm::Function>(GV);
241 if (FD->
hasAttr<OpenCLKernelAttr>()) {
244 addNVVMMetadata(F,
"kernel", 1);
246 F->addFnAttr(llvm::Attribute::NoInline);
255 if (FD->
hasAttr<CUDAGlobalAttr>()) {
257 addNVVMMetadata(F,
"kernel", 1);
259 if (CUDALaunchBoundsAttr *
Attr = FD->
getAttr<CUDALaunchBoundsAttr>())
264 if (FD->
hasAttr<NVPTXKernelAttr>()) {
265 addNVVMMetadata(F,
"kernel", 1);
269void NVPTXTargetCodeGenInfo::addNVVMMetadata(llvm::GlobalValue *GV,
270 StringRef Name,
int Operand) {
271 llvm::Module *M = GV->getParent();
275 llvm::NamedMDNode *MD = M->getOrInsertNamedMetadata(
"nvvm.annotations");
277 llvm::Metadata *MDVals[] = {
278 llvm::ConstantAsMetadata::get(GV), llvm::MDString::get(Ctx, Name),
279 llvm::ConstantAsMetadata::get(
280 llvm::ConstantInt::get(llvm::Type::getInt32Ty(Ctx), Operand))};
282 MD->addOperand(llvm::MDNode::get(Ctx, MDVals));
285bool NVPTXTargetCodeGenInfo::shouldEmitStaticExternCAliases()
const {
291 const CUDALaunchBoundsAttr *
Attr,
292 int32_t *MaxThreadsVal,
293 int32_t *MinBlocksVal,
294 int32_t *MaxClusterRankVal) {
296 llvm::APSInt MaxThreads(32);
297 MaxThreads =
Attr->getMaxThreads()->EvaluateKnownConstInt(
getContext());
298 if (MaxThreads > 0) {
300 *MaxThreadsVal = MaxThreads.getExtValue();
303 NVPTXTargetCodeGenInfo::addNVVMMetadata(F,
"maxntidx",
304 MaxThreads.getExtValue());
311 if (
Attr->getMinBlocks()) {
312 llvm::APSInt MinBlocks(32);
313 MinBlocks =
Attr->getMinBlocks()->EvaluateKnownConstInt(
getContext());
316 *MinBlocksVal = MinBlocks.getExtValue();
319 NVPTXTargetCodeGenInfo::addNVVMMetadata(F,
"minctasm",
320 MinBlocks.getExtValue());
324 if (
Attr->getMaxBlocks()) {
325 llvm::APSInt MaxBlocks(32);
326 MaxBlocks =
Attr->getMaxBlocks()->EvaluateKnownConstInt(
getContext());
328 if (MaxClusterRankVal)
329 *MaxClusterRankVal = MaxBlocks.getExtValue();
332 NVPTXTargetCodeGenInfo::addNVVMMetadata(F,
"maxclusterrank",
333 MaxBlocks.getExtValue());
339std::unique_ptr<TargetCodeGenInfo>
341 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
llvm::Value * getPointer() const
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 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.