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());


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());
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to