[clang] 3c6c2ec - [AMDGPU] Added 'A' constraint for inline assembler

2020-05-25 Thread Dmitry Preobrazhensky via cfe-commits

Author: Dmitry Preobrazhensky
Date: 2020-05-25T17:47:06+03:00
New Revision: 3c6c2ecd6efa393e7a8422d88e5d4ada0970e47e

URL: 
https://github.com/llvm/llvm-project/commit/3c6c2ecd6efa393e7a8422d88e5d4ada0970e47e
DIFF: 
https://github.com/llvm/llvm-project/commit/3c6c2ecd6efa393e7a8422d88e5d4ada0970e47e.diff

LOG: [AMDGPU] Added 'A' constraint for inline assembler

Summary: 'A' constraint requires an immediate int or fp constant that can be 
inlined in an instruction encoding.
This is the second part of the change. The llvm part has been committed as 
b087b91c9170.
See https://reviews.llvm.org/D78494

Reviewers: arsenm, rampitec

Differential Revision: https://reviews.llvm.org/D79493

Added: 


Modified: 
clang/lib/Basic/Targets/AMDGPU.h
clang/test/Sema/inline-asm-validate-amdgpu.cl

Removed: 




diff  --git a/clang/lib/Basic/Targets/AMDGPU.h 
b/clang/lib/Basic/Targets/AMDGPU.h
index d0e88e223e95..6c9060aa3f7b 100644
--- a/clang/lib/Basic/Targets/AMDGPU.h
+++ b/clang/lib/Basic/Targets/AMDGPU.h
@@ -131,6 +131,11 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : 
public TargetInfo {
 });
 
 StringRef S(Name);
+if (S == "A") {
+  Info.setRequiresImmediate();
+  return true;
+}
+
 bool HasLeftParen = false;
 if (S.front() == '{') {
   HasLeftParen = true;

diff  --git a/clang/test/Sema/inline-asm-validate-amdgpu.cl 
b/clang/test/Sema/inline-asm-validate-amdgpu.cl
index 51009ecb3f1e..3d6488227ef2 100644
--- a/clang/test/Sema/inline-asm-validate-amdgpu.cl
+++ b/clang/test/Sema/inline-asm-validate-amdgpu.cl
@@ -17,6 +17,10 @@ kernel void test () {
 
   // vgpr constraints
   __asm__ ("v_mov_b32 %0, %1" : "=v" (vgpr) : "v" (imm) : );
+
+  // 'A' constraint
+  __asm__ ("s_mov_b32 %0, %1" : "=s" (sgpr) : "A" (imm) : );
+
 }
 
 __kernel void



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 53422e8 - [AMDGPU] Added support of new inline assembler constraints

2020-07-03 Thread Dmitry Preobrazhensky via cfe-commits

Author: Dmitry Preobrazhensky
Date: 2020-07-03T18:01:12+03:00
New Revision: 53422e8b4f65a6736896311b10ad8a22fbc9e372

URL: 
https://github.com/llvm/llvm-project/commit/53422e8b4f65a6736896311b10ad8a22fbc9e372
DIFF: 
https://github.com/llvm/llvm-project/commit/53422e8b4f65a6736896311b10ad8a22fbc9e372.diff

LOG: [AMDGPU] Added support of new inline assembler constraints

Added support for constraints 'I', 'J', 'L', 'B', 'C', 'Kf', 'DA', 'DB'.

See 
https://gcc.gnu.org/onlinedocs/gcc/Machine-Constraints.html#Machine-Constraints.

Reviewers: arsenm, rampitec

Differential Revision: https://reviews.llvm.org/D81657

Added: 


Modified: 
clang/lib/Basic/Targets/AMDGPU.h
clang/test/CodeGenOpenCL/inline-asm-amdgcn.cl
clang/test/Sema/inline-asm-validate-amdgpu.cl

Removed: 




diff  --git a/clang/lib/Basic/Targets/AMDGPU.h 
b/clang/lib/Basic/Targets/AMDGPU.h
index 387b91abb537..d0394492cad6 100644
--- a/clang/lib/Basic/Targets/AMDGPU.h
+++ b/clang/lib/Basic/Targets/AMDGPU.h
@@ -130,8 +130,26 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : 
public TargetInfo {
 "exec_hi", "tma_lo", "tma_hi", "tba_lo", "tba_hi",
 });
 
+switch (*Name) {
+case 'I':
+  Info.setRequiresImmediate(-16, 64);
+  return true;
+case 'J':
+  Info.setRequiresImmediate(-32768, 32767);
+  return true;
+case 'A':
+case 'B':
+case 'C':
+  Info.setRequiresImmediate();
+  return true;
+default:
+  break;
+}
+
 StringRef S(Name);
-if (S == "A") {
+
+if (S == "DA" || S == "DB") {
+  Name++;
   Info.setRequiresImmediate();
   return true;
 }
@@ -203,6 +221,12 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : 
public TargetInfo {
   // the constraint.  In practice, it won't be changed unless the
   // constraint is longer than one character.
   std::string convertConstraint(const char *&Constraint) const override {
+
+StringRef S(Constraint);
+if (S == "DA" || S == "DB") {
+  return std::string("^") + std::string(Constraint++, 2);
+}
+
 const char *Begin = Constraint;
 TargetInfo::ConstraintInfo Info("", "");
 if (validateAsmConstraint(Constraint, Info))

diff  --git a/clang/test/CodeGenOpenCL/inline-asm-amdgcn.cl 
b/clang/test/CodeGenOpenCL/inline-asm-amdgcn.cl
index 37090772f664..259c12384f2c 100644
--- a/clang/test/CodeGenOpenCL/inline-asm-amdgcn.cl
+++ b/clang/test/CodeGenOpenCL/inline-asm-amdgcn.cl
@@ -33,3 +33,17 @@ kernel void test_agpr() {
  : "={a1}"(reg_a)
  : "{a1}"(reg_b));
 }
+
+kernel void test_constraint_DA() {
+  const long x = 0x20001;
+  int res;
+  // CHECK: call i32 asm sideeffect "v_mov_b32 $0, $1 & 0x", 
"=v,^DA"(i64 8589934593)
+  __asm volatile("v_mov_b32 %0, %1 & 0x" : "=v"(res) : "DA"(x));
+}
+
+kernel void test_constraint_DB() {
+  const long x = 0x20001;
+  int res;
+  // CHECK: call i32 asm sideeffect "v_mov_b32 $0, $1 & 0x", 
"=v,^DB"(i64 8589934593)
+  __asm volatile("v_mov_b32 %0, %1 & 0x" : "=v"(res) : "DB"(x));
+}

diff  --git a/clang/test/Sema/inline-asm-validate-amdgpu.cl 
b/clang/test/Sema/inline-asm-validate-amdgpu.cl
index 3d6488227ef2..418952c0e727 100644
--- a/clang/test/Sema/inline-asm-validate-amdgpu.cl
+++ b/clang/test/Sema/inline-asm-validate-amdgpu.cl
@@ -18,9 +18,35 @@ kernel void test () {
   // vgpr constraints
   __asm__ ("v_mov_b32 %0, %1" : "=v" (vgpr) : "v" (imm) : );
 
-  // 'A' constraint
+  // 'I' constraint (an immediate integer in the range -16 to 64)
+  __asm__ ("s_mov_b32 %0, %1" : "=s" (sgpr) : "I" (imm) : );
+  __asm__ ("s_mov_b32 %0, %1" : "=s" (sgpr) : "I" (-16) : );
+  __asm__ ("s_mov_b32 %0, %1" : "=s" (sgpr) : "I" (64) : );
+  __asm__ ("s_mov_b32 %0, %1" : "=s" (sgpr) : "I" (-17) : ); // expected-error 
{{value '-17' out of range for constraint 'I'}}
+  __asm__ ("s_mov_b32 %0, %1" : "=s" (sgpr) : "I" (65) : ); // expected-error 
{{value '65' out of range for constraint 'I'}}
+
+  // 'J' constraint (an immediate 16-bit signed integer)
+  __asm__ ("s_mov_b32 %0, %1" : "=s" (sgpr) : "J" (imm) : );
+  __asm__ ("s_mov_b32 %0, %1" : "=s" (sgpr) : "J" (-32768) : );
+  __asm__ ("s_mov_b32 %0, %1" : "=s" (sgpr) : "J" (32767) : );
+  __asm__ ("s_mov_b32 %0, %1" : "=s" (sgpr) : "J" (-32769) : ); // 
expected-error {{value '-32769' out of range for constraint 'J'}}
+  __asm__ ("s_mov_b32 %0, %1" : "=s" (sgpr) : "J" (32768) : ); // 
expected-error {{value '32768' out of range for constraint 'J'}}
+
+  // 'A' constraint (an immediate constant that can be inlined)
   __asm__ ("s_mov_b32 %0, %1" : "=s" (sgpr) : "A" (imm) : );
 
+  // 'B' constraint (an immediate 32-bit signed integer)
+  __asm__ ("s_mov_b32 %0, %1" : "=s" (sgpr) : "B" (imm) : );
+
+  // 'C' constraint (an immediate 32-bit unsigned integer or 'A' constraint)
+  __asm__ ("s_mov_b32 %0, %1" : "=s" (sgpr) : "C" (imm) : );
+
+  // 'DA' constrain