]> granicus.if.org Git - clang/commitdiff
[RISCV] Support 'f' Inline Assembly Constraint
authorSam Elliott <selliott@lowrisc.org>
Wed, 31 Jul 2019 09:45:55 +0000 (09:45 +0000)
committerSam Elliott <selliott@lowrisc.org>
Wed, 31 Jul 2019 09:45:55 +0000 (09:45 +0000)
Summary:
This adds the 'f' inline assembly constraint, as supported by GCC. An
'f'-constrained operand is passed in a floating point register. Exactly
which kind of floating-point register (32-bit or 64-bit) is decided
based on the operand type and the available standard extensions (-f and
-d, respectively).

This patch adds support in both the clang frontend, and LLVM itself.

Reviewers: asb, lewis-revill

Reviewed By: asb

Subscribers: hiraditya, rbar, johnrusso, simoncook, apazos, sabuasal, niosHD, kito-cheng, shiva0217, jrtc27, MaskRay, zzheng, edward-jones, rogfer01, MartinMosbeck, brucehoult, the_o, rkruppe, PkmX, jocewei, psnobl, benna, Jim, s.egerton, cfe-commits, llvm-commits

Tags: #clang, #llvm

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@367403 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Basic/Targets/RISCV.cpp
test/CodeGen/riscv-inline-asm.c

index 788ae6939399a6da6d28e265b2b689b9d0124377..a634ba69f3cd3b342a6550b08993b5efc751d6cd 100644 (file)
@@ -71,6 +71,10 @@ bool RISCVTargetInfo::validateAsmConstraint(
     // A 5-bit unsigned immediate for CSR access instructions.
     Info.setRequiresImmediate(0, 31);
     return true;
+  case 'f':
+    // A floating-point register.
+    Info.setAllowsRegister();
+    return true;
   }
 }
 
index 2d23b7e35e2b0c48586710c843e57f07a5c01673..f79527337bdfb4520f2c7cead3f621b7260a1912 100644 (file)
@@ -26,3 +26,15 @@ void test_K() {
 // CHECK: call void asm sideeffect "", "K"(i32 0)
   asm volatile ("" :: "K"(0));
 }
+
+float f;
+double d;
+void test_f() {
+// CHECK-LABEL: define void @test_f()
+// CHECK: [[FLT_ARG:%[a-zA-Z_0-9]+]] = load float, float* @f
+// CHECK: call void asm sideeffect "", "f"(float [[FLT_ARG]])
+  asm volatile ("" :: "f"(f));
+// CHECK: [[FLT_ARG:%[a-zA-Z_0-9]+]] = load double, double* @d
+// CHECK: call void asm sideeffect "", "f"(double [[FLT_ARG]])
+  asm volatile ("" :: "f"(d));
+}