[cfe-commits] r129987 - in /cfe/trunk: lib/CodeGen/TargetInfo.cpp test/CodeGen/ptx-cc.c

Argyrios Kyrtzidis kyrtzidis at apple.com
Fri Apr 22 10:49:01 PDT 2011


Could you please change test/CodeGen/ptx-cc.c to test llvm IR so the test is self-contained for clang ?
This fails if one does not compile the PTX backend on the llvm side. If you want to test the PTX backend I think a test in the LLVM test suite is more appropriate.

-Argiris

On Apr 22, 2011, at 4:10 AM, Justin Holewinski wrote:

> Author: jholewinski
> Date: Fri Apr 22 06:10:38 2011
> New Revision: 129987
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=129987&view=rev
> Log:
> PTX: Add default PTX calling conventions
> 
> Added:
>    cfe/trunk/test/CodeGen/ptx-cc.c
> Modified:
>    cfe/trunk/lib/CodeGen/TargetInfo.cpp
> 
> Modified: cfe/trunk/lib/CodeGen/TargetInfo.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/TargetInfo.cpp?rev=129987&r1=129986&r2=129987&view=diff
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/TargetInfo.cpp (original)
> +++ cfe/trunk/lib/CodeGen/TargetInfo.cpp Fri Apr 22 06:10:38 2011
> @@ -2540,6 +2540,74 @@
> }
> 
> //===----------------------------------------------------------------------===//
> +// 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 @@
>   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));
> 
> 
> Added: cfe/trunk/test/CodeGen/ptx-cc.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/ptx-cc.c?rev=129987&view=auto
> ==============================================================================
> --- cfe/trunk/test/CodeGen/ptx-cc.c (added)
> +++ cfe/trunk/test/CodeGen/ptx-cc.c Fri Apr 22 06:10:38 2011
> @@ -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];
> +}
> 
> 
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits




More information about the cfe-commits mailing list