[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 06:11:27 PDT 2017


fhahn created this revision.
Herald added subscribers: kristof.beyls, javed.absar, aemerson.

This patch adds support for the target("arm") and target("thumb")
attributes, which can be used to force the compiler to generated ARM or
Thumb code for a function.

In LLVM, ARM or Thumb code generation can be controlled by the
thumb-mode target feature. But GCC already uses target("arm") and
target("thumb"), so we have to substitute "arm" with -thumb-mode and
"thumb" with +thumb-mode.


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,13 @@
+// RUN: %clang_cc1 -triple thumb-apple-darwin -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple arm-apple-darwin -emit-llvm -o - %s | FileCheck %s
+
+__attribute__((target("arm"))) void test_target_arm() {
+  // CHECK: define void @test_target_arm() [[ARM_ATTRS:#[0-9]+]]
+}
+
+__attribute__((target("thumb"))) void test_target_thumb() {
+  // CHECK: define void @test_target_thumb() [[THUMB_ATTRS:#[0-9]+]]
+}
+
+// CHECK: attributes [[ARM_ATTRS]] = { {{.*}} "target-features"="{{.*}}-thumb-mode{{.*}}"
+// CHECK: attributes [[THUMB_ATTRS]] = { {{.*}} "target-features"="{{.*}}+thumb-mode{{.*}}"
Index: include/clang/Basic/Attr.td
===================================================================
--- include/clang/Basic/Attr.td
+++ include/clang/Basic/Attr.td
@@ -1769,10 +1769,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 GNU target names for arm and thumb to thumb-mode target
+        // feature.
+        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.100854.patch
Type: text/x-patch
Size: 1820 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170531/5c2308cd/attachment.bin>


More information about the cfe-commits mailing list