PTX: Print .ptr kernel attributes if PTX version >= 2.2
authorJustin Holewinski <justin.holewinski@gmail.com>
Sun, 9 Oct 2011 15:42:02 +0000 (15:42 +0000)
committerJustin Holewinski <justin.holewinski@gmail.com>
Sun, 9 Oct 2011 15:42:02 +0000 (15:42 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@141508 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/PTX/PTXAsmPrinter.cpp
lib/Target/PTX/PTXISelLowering.cpp
lib/Target/PTX/PTXISelLowering.h
lib/Target/PTX/PTXSubtarget.h

index 590a51b7b4d1355b6a50c5e1dadbc739a2bbde3a..733744bbd08bf4bcb4e22f0806b9a2fc402fa22c 100644 (file)
@@ -20,7 +20,9 @@
 #include "PTXParamManager.h"
 #include "PTXRegisterInfo.h"
 #include "PTXTargetMachine.h"
+#include "llvm/Argument.h"
 #include "llvm/DerivedTypes.h"
+#include "llvm/Function.h"
 #include "llvm/Module.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringExtras.h"
@@ -445,9 +447,11 @@ void PTXAsmPrinter::EmitFunctionEntryLabel() {
 
   decl += " (";
 
+  const Function *F = MF->getFunction();
+
   // Print parameters
   if (isKernel || ST.useParamSpaceForDeviceArgs()) {
-    for (PTXParamManager::param_iterator i = PM.arg_begin(), e = PM.arg_end(),
+    /*for (PTXParamManager::param_iterator i = PM.arg_begin(), e = PM.arg_end(),
          b = i; i != e; ++i) {
       if (i != b) {
         decl += ", ";
@@ -457,6 +461,38 @@ void PTXAsmPrinter::EmitFunctionEntryLabel() {
       decl += utostr(PM.getParamSize(*i));
       decl += " ";
       decl += PM.getParamName(*i);
+    }*/
+    int Counter = 1;
+    for (Function::const_arg_iterator i = F->arg_begin(), e = F->arg_end(),
+         b = i; i != e; ++i) {
+      if (i != b)
+        decl += ", ";
+      const Type *ArgType = (*i).getType();
+      decl += ".param .b";
+      if (ArgType->isPointerTy()) {
+        if (ST.is64Bit())
+          decl += "64";
+        else
+          decl += "32";
+      } else {
+        decl += utostr(ArgType->getPrimitiveSizeInBits());
+      }
+      if (ArgType->isPointerTy() && ST.emitPtrAttribute()) {
+        const PointerType *PtrType = dyn_cast<const PointerType>(ArgType);
+        decl += " .ptr";
+        switch (PtrType->getAddressSpace()) {
+        default:
+          llvm_unreachable("Unknown address space in argument");
+        case PTXStateSpace::Global:
+          decl += " .global";
+          break;
+        case PTXStateSpace::Shared:
+          decl += " .shared";
+          break;
+        }
+      }
+      decl += " __param_";
+      decl += utostr(Counter++);
     }
   } else {
     for (PTXMachineFunctionInfo::reg_iterator
index f2234906d9d1b05c21b010f30f9ab85fe1e3290b..3307d91a618803749a7e0a69dcced775d1e2aee3 100644 (file)
@@ -414,3 +414,9 @@ PTXTargetLowering::LowerCall(SDValue Chain, SDValue Callee,
 
   return Chain;
 }
+
+unsigned PTXTargetLowering::getNumRegisters(LLVMContext &Context, EVT VT) {
+  // All arguments consist of one "register," regardless of the type.
+  return 1;
+}
+
index f88349f865c54385db68f777fe771ab8f6098f31..4d2566540af20ffe12e90457c99d1ba47df0f570 100644 (file)
@@ -75,6 +75,8 @@ class PTXTargetLowering : public TargetLowering {
 
     virtual EVT getSetCCResultType(EVT VT) const;
 
+    virtual unsigned getNumRegisters(LLVMContext &Context, EVT VT);
+
   private:
     SDValue LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const;
 }; // class PTXTargetLowering
index 0404200992000d83e6c1eeda014cf05b400b246f..b946d7c11cefd3a8acb211b6d798bd90caf56239 100644 (file)
@@ -119,6 +119,10 @@ class StringRef;
                (PTXTarget >= PTX_COMPUTE_2_0 && PTXTarget < PTX_LAST_COMPUTE);
       }
 
+      bool emitPtrAttribute() const {
+        return PTXVersion >= PTX_VERSION_2_2;
+      }
+
       void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
   }; // class PTXSubtarget
 } // namespace llvm