r184578 - [NVPTX] Add NVPTX register constraints

Justin Holewinski jholewinski at nvidia.com
Fri Jun 21 11:51:24 PDT 2013


Author: jholewinski
Date: Fri Jun 21 13:51:24 2013
New Revision: 184578

URL: http://llvm.org/viewvc/llvm-project?rev=184578&view=rev
Log:
[NVPTX] Add NVPTX register constraints

Added:
    cfe/trunk/test/CodeGen/nvptx-inlineasm-ptx.c
Modified:
    cfe/trunk/lib/Basic/Targets.cpp

Modified: cfe/trunk/lib/Basic/Targets.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=184578&r1=184577&r2=184578&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/Targets.cpp (original)
+++ cfe/trunk/lib/Basic/Targets.cpp Fri Jun 21 13:51:24 2013
@@ -1290,9 +1290,18 @@ namespace {
       NumAliases = 0;
     }
     virtual bool validateAsmConstraint(const char *&Name,
-                                       TargetInfo::ConstraintInfo &info) const {
-      // FIXME: implement
-      return true;
+                                       TargetInfo::ConstraintInfo &Info) const {
+      switch (*Name) {
+      default: return false;
+      case 'c':
+      case 'h':
+      case 'r':
+      case 'l':
+      case 'f':
+      case 'd':
+        Info.setAllowsRegister();
+        return true;
+      }
     }
     virtual const char *getClobbers() const {
       // FIXME: Is this really right?

Added: cfe/trunk/test/CodeGen/nvptx-inlineasm-ptx.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/nvptx-inlineasm-ptx.c?rev=184578&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/nvptx-inlineasm-ptx.c (added)
+++ cfe/trunk/test/CodeGen/nvptx-inlineasm-ptx.c Fri Jun 21 13:51:24 2013
@@ -0,0 +1,40 @@
+// RUN: %clang_cc1 -triple nvptx-unknown-unknown -O3 -S -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple nvptx64-unknown-unknown -O3 -S -o - %s | FileCheck %s
+
+void constraints() {
+  char           c;
+  unsigned char  uc;
+  short          s;
+  unsigned short us;
+  int            i;
+  unsigned int   ui;
+  long           l;
+  unsigned long  ul;
+  float          f;
+  double         d;
+
+  // CHECK: mov.b8 %rc{{[0-9]+}}, %rc{{[0-9]+}}
+  asm volatile ("mov.b8 %0, %1;" : "=c"(c) : "c"(c));
+  // CHECK: mov.b8 %rc{{[0-9]+}}, %rc{{[0-9]+}}
+  asm volatile ("mov.b8 %0, %1;" : "=c"(uc) : "c"(uc));
+
+  // CHECK: mov.b16 %rs{{[0-9]+}}, %rs{{[0-9]+}}
+  asm volatile ("mov.b16 %0, %1;" : "=h"(s) : "h"(s));
+  // CHECK: mov.b16 %rs{{[0-9]+}}, %rs{{[0-9]+}}
+  asm volatile ("mov.b16 %0, %1;" : "=h"(us) : "h"(us));
+
+  // CHECK: mov.b32 %r{{[0-9]+}}, %r{{[0-9]+}}
+  asm volatile ("mov.b32 %0, %1;" : "=r"(i) : "r"(i));
+  // CHECK: mov.b32 %r{{[0-9]+}}, %r{{[0-9]+}}
+  asm volatile ("mov.b32 %0, %1;" : "=r"(ui) : "r"(ui));
+
+  // CHECK: mov.b64 %rl{{[0-9]+}}, %rl{{[0-9]+}}
+  asm volatile ("mov.b64 %0, %1;" : "=l"(l) : "l"(l));
+  // CHECK: mov.b64 %rl{{[0-9]+}}, %rl{{[0-9]+}}
+  asm volatile ("mov.b64 %0, %1;" : "=l"(ul) : "l"(ul));
+
+  // CHECK: mov.b32 %f{{[0-9]+}}, %f{{[0-9]+}}
+  asm volatile ("mov.b32 %0, %1;" : "=f"(f) : "f"(f));
+  // CHECK: mov.b64 %fl{{[0-9]+}}, %fl{{[0-9]+}}
+  asm volatile ("mov.b64 %0, %1;" : "=d"(d) : "d"(d));
+}





More information about the cfe-commits mailing list