[llvm-commits] [PATCH][Target/PTX] Add address_size directive to PTX backend

陳韋任 chenwj at iis.sinica.edu.tw
Fri Jun 17 23:56:18 PDT 2011


> Perhaps my understanding of the .address_size directive is incomplete, but as far as I know it is just used as a flag for ptxas to make sure all PTX modules in a program assume the same pointer size.  That said, what is the purpose of allowing LLVM to generate 32-bit PTX code but assume 64-bit addresses, and vice versa?  Why not tie the directive directly to the existing 32/64-bit flag instead of allowing user intervention?

  I'll wait for Che-Liang and Dan's comment.
 
> Also, .address_size is only supported on PTX 2.3+.  Please amend the patch to emit this directive only if the target PTX version is >= 2.3.

  Fixed.

Regards,
chenwj

-- 
Wei-Ren Chen (陳韋任)
Computer Systems Lab, Institute of Information Science,
Academia Sinica, Taiwan (R.O.C.)
Tel:886-2-2788-3799 #1667
-------------- next part --------------
Index: test/CodeGen/PTX/options.ll
===================================================================
--- test/CodeGen/PTX/options.ll	(revision 133338)
+++ test/CodeGen/PTX/options.ll	(working copy)
@@ -5,6 +5,8 @@
 ; RUN: llc < %s -march=ptx32 -mattr=sm10 | grep ".target sm_10"
 ; RUN: llc < %s -march=ptx32 -mattr=sm13 | grep ".target sm_13"
 ; RUN: llc < %s -march=ptx32 -mattr=sm20 | grep ".target sm_20"
+; RUN: llc < %s -march=ptx32 -mattr=ptx23,32 | grep ".address_size 32"
+; RUN: llc < %s -march=ptx32 -mattr=ptx23,64 | grep ".address_size 64"
 
 define ptx_device void @t1() {
 	ret void
Index: lib/Target/PTX/PTX.td
===================================================================
--- lib/Target/PTX/PTX.td	(revision 133338)
+++ lib/Target/PTX/PTX.td	(working copy)
@@ -56,6 +56,13 @@
                                    "Enable Shader Model 2.0 compliance",
                                    [FeatureSM13]>;
 
+//===- PTX Address Size ---------------------------------------------------===//
+
+def FeatureAddrSize32 : SubtargetFeature<"32", "PTXAddrSize", "PTX_AddrSize_32",
+                                         "32-bit address size used throughout PTX module">;
+def FeatureAddrSize64 : SubtargetFeature<"64", "PTXAddrSize", "PTX_AddrSize_64",
+                                         "64-bit address size used throughout PTX module">;
+
 //===----------------------------------------------------------------------===//
 // PTX supported processors.
 //===----------------------------------------------------------------------===//
Index: lib/Target/PTX/PTXSubtarget.h
===================================================================
--- lib/Target/PTX/PTXSubtarget.h	(revision 133338)
+++ lib/Target/PTX/PTXSubtarget.h	(working copy)
@@ -41,12 +41,23 @@
         PTX_VERSION_2_3   /*< PTX Version 2.3 */
       };
 
+      /**
+       * Enumeration of address size used throughout PTX module
+       */
+      enum PTXAddrSizeEnum {
+        PTX_AddrSize_32,  /*< PTX Address Size 32 bit */
+        PTX_AddrSize_64   /*< PTX Address Size 64 bit */
+      };
+
       /// Shader Model supported on the target GPU.
       PTXShaderModelEnum PTXShaderModel;
 
       /// PTX Language Version.
       PTXVersionEnum PTXVersion;
 
+      /// Address size used throughout PTX module
+      PTXAddrSizeEnum PTXAddrSize;
+
       // The native .f64 type is supported on the hardware.
       bool SupportsDouble;
 
@@ -64,6 +75,8 @@
 
       std::string getPTXVersionString() const;
 
+      std::string getPTXAddrSizeString() const;
+
       bool supportsDouble() const { return SupportsDouble; }
 
       bool is64Bit() const { return Is64Bit; }
Index: lib/Target/PTX/PTXAsmPrinter.cpp
===================================================================
--- lib/Target/PTX/PTXAsmPrinter.cpp	(revision 133338)
+++ lib/Target/PTX/PTXAsmPrinter.cpp	(working copy)
@@ -162,6 +162,9 @@
   OutStreamer.EmitRawText(Twine("\t.target " + ST.getTargetString() +
                                 (ST.supportsDouble() ? ""
                                                      : ", map_f64_to_f32")));
+  if (ST.supportsPTX23())
+    OutStreamer.EmitRawText(Twine("\t.address_size " + ST.getPTXAddrSizeString()));
+
   OutStreamer.AddBlankLine();
 
   // declare global variables
Index: lib/Target/PTX/PTXSubtarget.cpp
===================================================================
--- lib/Target/PTX/PTXSubtarget.cpp	(revision 133338)
+++ lib/Target/PTX/PTXSubtarget.cpp	(working copy)
@@ -22,7 +22,8 @@
     PTXVersion(PTX_VERSION_2_0),
     SupportsDouble(false),
     SupportsFMA(true),
-    Is64Bit(is64Bit) {	
+    Is64Bit(is64Bit) {
+  PTXAddrSize = is64Bit? PTX_AddrSize_64 : PTX_AddrSize_32;
   std::string TARGET = "generic";
   ParseSubtargetFeatures(FS, TARGET);
 }
@@ -46,4 +47,12 @@
   }
 }
 
+std::string PTXSubtarget::getPTXAddrSizeString() const {
+  switch(PTXAddrSize) {
+    default: llvm_unreachable("Unknown address size");
+    case PTX_AddrSize_32: return "32";
+    case PTX_AddrSize_64: return "64";
+  }
+}
+
 #include "PTXGenSubtarget.inc"


More information about the llvm-commits mailing list