PTX: Add default PTX calling conventions
llvm-svn: 129987
This commit is contained in:
parent
9392165a17
commit
bd4a3c03ff
|
@ -2539,6 +2539,74 @@ llvm::Value *ARMABIInfo::EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
|
|||
return AddrTyped;
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// PTX ABI Implementation
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
namespace {
|
||||
|
||||
class PTXABIInfo : public ABIInfo {
|
||||
public:
|
||||
PTXABIInfo(CodeGenTypes &CGT) : ABIInfo(CGT) {}
|
||||
|
||||
ABIArgInfo classifyReturnType(QualType RetTy) const;
|
||||
ABIArgInfo classifyArgumentType(QualType Ty) const;
|
||||
|
||||
virtual void computeInfo(CGFunctionInfo &FI) const;
|
||||
virtual llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
|
||||
CodeGenFunction &CFG) const;
|
||||
};
|
||||
|
||||
class PTXTargetCodeGenInfo : public TargetCodeGenInfo {
|
||||
public:
|
||||
PTXTargetCodeGenInfo(CodeGenTypes &CGT)
|
||||
: TargetCodeGenInfo(new PTXABIInfo(CGT)) {}
|
||||
};
|
||||
|
||||
ABIArgInfo PTXABIInfo::classifyReturnType(QualType RetTy) const {
|
||||
if (RetTy->isVoidType())
|
||||
return ABIArgInfo::getIgnore();
|
||||
if (isAggregateTypeForABI(RetTy))
|
||||
return ABIArgInfo::getIndirect(0);
|
||||
return ABIArgInfo::getDirect();
|
||||
}
|
||||
|
||||
ABIArgInfo PTXABIInfo::classifyArgumentType(QualType Ty) const {
|
||||
if (isAggregateTypeForABI(Ty))
|
||||
return ABIArgInfo::getIndirect(0);
|
||||
|
||||
return ABIArgInfo::getDirect();
|
||||
}
|
||||
|
||||
void PTXABIInfo::computeInfo(CGFunctionInfo &FI) const {
|
||||
FI.getReturnInfo() = classifyReturnType(FI.getReturnType());
|
||||
for (CGFunctionInfo::arg_iterator it = FI.arg_begin(), ie = FI.arg_end();
|
||||
it != ie; ++it)
|
||||
it->info = classifyArgumentType(it->type);
|
||||
|
||||
// Always honor user-specified calling convention.
|
||||
if (FI.getCallingConvention() != llvm::CallingConv::C)
|
||||
return;
|
||||
|
||||
// Calling convention as default by an ABI.
|
||||
llvm::CallingConv::ID DefaultCC;
|
||||
llvm::StringRef Env = getContext().Target.getTriple().getEnvironmentName();
|
||||
if (Env == "device")
|
||||
DefaultCC = llvm::CallingConv::PTX_Device;
|
||||
else
|
||||
DefaultCC = llvm::CallingConv::PTX_Kernel;
|
||||
|
||||
FI.setEffectiveCallingConvention(DefaultCC);
|
||||
}
|
||||
|
||||
llvm::Value *PTXABIInfo::EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
|
||||
CodeGenFunction &CFG) const {
|
||||
llvm_unreachable("PTX does not support varargs");
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// SystemZ ABI Implementation
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
@ -2853,6 +2921,10 @@ const TargetCodeGenInfo &CodeGenModule::getTargetCodeGenInfo() {
|
|||
case llvm::Triple::ppc:
|
||||
return *(TheTargetCodeGenInfo = new PPC32TargetCodeGenInfo(Types));
|
||||
|
||||
case llvm::Triple::ptx32:
|
||||
case llvm::Triple::ptx64:
|
||||
return *(TheTargetCodeGenInfo = new PTXTargetCodeGenInfo(Types));
|
||||
|
||||
case llvm::Triple::systemz:
|
||||
return *(TheTargetCodeGenInfo = new SystemZTargetCodeGenInfo(Types));
|
||||
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
// RUN: %clang_cc1 -triple ptx32-unknown-unknown -O3 -S -o %t %s
|
||||
// RUN: %clang_cc1 -triple ptx64-unknown-unknown -O3 -S -o %t %s
|
||||
|
||||
// Just make sure Clang uses the proper calling convention for the PTX back-end.
|
||||
// If something is wrong, the back-end will fail.
|
||||
void foo(float* a,
|
||||
float* b) {
|
||||
a[0] = b[0];
|
||||
}
|
Loading…
Reference in New Issue