[PATCH] D33721: [ARM] Add support for target("arm") and target("thumb").

Florian Hahn via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed May 31 09:41:10 PDT 2017


fhahn updated this revision to Diff 100880.
fhahn added a comment.

reworded comment and improved test case to ensure only a single thumb-mode attribute is added.


https://reviews.llvm.org/D33721

Files:
  include/clang/Basic/Attr.td
  test/CodeGen/arm-target-attr.c


Index: test/CodeGen/arm-target-attr.c
===================================================================
--- /dev/null
+++ test/CodeGen/arm-target-attr.c
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -triple thumb-apple-darwin -emit-llvm -o - %s | FileCheck --check-prefix CHECKPOS %s
+// RUN: %clang_cc1 -triple thumb-apple-darwin -emit-llvm -o - %s | FileCheck --check-prefix CHECKNEG %s
+// RUN: %clang_cc1 -triple arm-apple-darwin -emit-llvm -o - %s | FileCheck --check-prefix CHECKPOS %s
+// RUN: %clang_cc1 -triple arm-apple-darwin -emit-llvm -o - %s | FileCheck --check-prefix CHECKNEG %s
+
+__attribute__((target("arm"))) void test_target_arm() {
+  // CHECKPOS: define void @test_target_arm() [[ARM_ATTRS:#[0-9]+]]
+  // CHECKNEG: define void @test_target_arm() [[ARM_ATTRS:#[0-9]+]]
+}
+
+__attribute__((target("thumb"))) void test_target_thumb() {
+  // CHECKPOS: define void @test_target_thumb() [[THUMB_ATTRS:#[0-9]+]]
+  // CHECKNEG: define void @test_target_thumb() [[THUMB_ATTRS:#[0-9]+]]
+}
+
+// CHECKPOS: attributes [[ARM_ATTRS]] = { {{.*}} "target-features"="{{.*}}-thumb-mode{{.*}}"
+// CHECKPOS: attributes [[THUMB_ATTRS]] = { {{.*}} "target-features"="{{.*}}+thumb-mode{{.*}}"
+// CHECKNEG-NOT: attributes [[ARM_ATTRS]] = { {{.*}} "target-features"="{{.*}}+thumb-mode{{.*}}"
+// CHECKNEG-NOT: attributes [[THUMB_ATTRS]] = { {{.*}} "target-features"="{{.*}}-thumb-mode{{.*}}"
Index: include/clang/Basic/Attr.td
===================================================================
--- include/clang/Basic/Attr.td
+++ include/clang/Basic/Attr.td
@@ -1784,10 +1784,16 @@
         // overall feature validity for the function with the rest of the
         // attributes on the function.
         if (Feature.startswith("fpmath=") || Feature.startswith("tune="))
-	  continue;
-
+          continue;
+
+        // Convert arm and thumb GNU target attributes to [-|+]thumb-mode
+        // target features respectively.
+        if (Feature.compare("arm") == 0)
+          Ret.first.push_back("-thumb-mode");
+        else if (Feature.compare("thumb") == 0)
+          Ret.first.push_back("+thumb-mode");
         // While we're here iterating check for a different target cpu.
-        if (Feature.startswith("arch="))
+        else if (Feature.startswith("arch="))
           Ret.second = Feature.split("=").second.trim();
         else if (Feature.startswith("no-"))
           Ret.first.push_back("-" + Feature.split("-").second.str());


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D33721.100880.patch
Type: text/x-patch
Size: 2448 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170531/74fa3377/attachment.bin>


More information about the cfe-commits mailing list