summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustin Holewinski <justin.holewinski@gmail.com>2011-04-22 11:10:38 +0000
committerJustin Holewinski <justin.holewinski@gmail.com>2011-04-22 11:10:38 +0000
commitbd4a3c03ff84b4d1d4f14a3c8a011a937f52ad58 (patch)
tree05d671cdba2fee174d03ad009caafeeb4e0783b2
parent9392165a1734cdc89fc58f30dd880a10c176127f (diff)
downloadbcm5719-llvm-bd4a3c03ff84b4d1d4f14a3c8a011a937f52ad58.tar.gz
bcm5719-llvm-bd4a3c03ff84b4d1d4f14a3c8a011a937f52ad58.zip
PTX: Add default PTX calling conventions
llvm-svn: 129987
-rw-r--r--clang/lib/CodeGen/TargetInfo.cpp72
-rw-r--r--clang/test/CodeGen/ptx-cc.c9
2 files changed, 81 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/TargetInfo.cpp b/clang/lib/CodeGen/TargetInfo.cpp
index fd43dca5e15..0b244e8ba1e 100644
--- a/clang/lib/CodeGen/TargetInfo.cpp
+++ b/clang/lib/CodeGen/TargetInfo.cpp
@@ -2540,6 +2540,74 @@ llvm::Value *ARMABIInfo::EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
}
//===----------------------------------------------------------------------===//
+// 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));
diff --git a/clang/test/CodeGen/ptx-cc.c b/clang/test/CodeGen/ptx-cc.c
new file mode 100644
index 00000000000..6374cc71bbb
--- /dev/null
+++ b/clang/test/CodeGen/ptx-cc.c
@@ -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];
+}
OpenPOWER on IntegriCloud