r274409 - Add TargetInfo for 32-bit and 64-bit RenderScript

Pirama Arumuga Nainar via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 1 17:05:42 PDT 2016


Author: pirama
Date: Fri Jul  1 19:05:42 2016
New Revision: 274409

URL: http://llvm.org/viewvc/llvm-project?rev=274409&view=rev
Log:
Add TargetInfo for 32-bit and 64-bit RenderScript

Summary:
The TargetInfo for 'renderscript32' and 'renderscript64' ArchTypes are
subclasses of ARMleTargetInfo and AArch64leTargetInfo respectively.

RenderScript32TargetInfo modifies the ARM ABI to set LongWidth and
LongAlign to be 64-bits.  Other than this modification, the underlying
TargetInfo base classes is initialized as if they have "armv7" and
"aarch64" architecture type respectively.

Reviewers: rsmith, echristo

Subscribers: aemerson, tberghammer, cfe-commits, danalbert, mehdi_amini, srhines

Differential Revision: http://reviews.llvm.org/D21334

Added:
    cfe/trunk/test/CodeGen/renderscript.c
Modified:
    cfe/trunk/lib/Basic/Targets.cpp

Modified: cfe/trunk/lib/Basic/Targets.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=274409&r1=274408&r2=274409&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/Targets.cpp (original)
+++ cfe/trunk/lib/Basic/Targets.cpp Fri Jul  1 19:05:42 2016
@@ -8071,6 +8071,42 @@ public:
     return true;
   }
 };
+
+// 32-bit RenderScript is armv7 with width and align of 'long' set to 8-bytes
+class RenderScript32TargetInfo : public ARMleTargetInfo {
+public:
+  RenderScript32TargetInfo(const llvm::Triple &Triple,
+                           const TargetOptions &Opts)
+      : ARMleTargetInfo(llvm::Triple("armv7", Triple.getVendorName(),
+                                     Triple.getOSName(),
+                                     Triple.getEnvironmentName()),
+                        Opts) {
+    LongWidth = LongAlign = 64;
+  }
+  void getTargetDefines(const LangOptions &Opts,
+                        MacroBuilder &Builder) const override {
+    Builder.defineMacro("__RENDERSCRIPT__");
+    ARMleTargetInfo::getTargetDefines(Opts, Builder);
+  }
+};
+
+// 64-bit RenderScript is aarch64
+class RenderScript64TargetInfo : public AArch64leTargetInfo {
+public:
+  RenderScript64TargetInfo(const llvm::Triple &Triple,
+                           const TargetOptions &Opts)
+      : AArch64leTargetInfo(llvm::Triple("aarch64", Triple.getVendorName(),
+                                         Triple.getOSName(),
+                                         Triple.getEnvironmentName()),
+                            Opts) {}
+
+  void getTargetDefines(const LangOptions &Opts,
+                        MacroBuilder &Builder) const override {
+    Builder.defineMacro("__RENDERSCRIPT__");
+    AArch64leTargetInfo::getTargetDefines(Opts, Builder);
+  }
+};
+
 } // end anonymous namespace
 
 //===----------------------------------------------------------------------===//
@@ -8499,6 +8535,11 @@ static TargetInfo *AllocateTarget(const
     if (!(Triple == llvm::Triple("wasm64-unknown-unknown")))
       return nullptr;
     return new WebAssemblyOSTargetInfo<WebAssembly64TargetInfo>(Triple, Opts);
+
+  case llvm::Triple::renderscript32:
+    return new LinuxTargetInfo<RenderScript32TargetInfo>(Triple, Opts);
+  case llvm::Triple::renderscript64:
+    return new LinuxTargetInfo<RenderScript64TargetInfo>(Triple, Opts);
   }
 }
 

Added: cfe/trunk/test/CodeGen/renderscript.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/renderscript.c?rev=274409&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/renderscript.c (added)
+++ cfe/trunk/test/CodeGen/renderscript.c Fri Jul  1 19:05:42 2016
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 %s -triple=renderscript32-none-linux-gnueabi -emit-llvm -o - -Werror | FileCheck %s -check-prefix=CHECK-RS32
+// RUN: %clang_cc1 %s -triple=renderscript64-none-linux-android -emit-llvm -o - -Werror | FileCheck %s -check-prefix=CHECK-RS64
+// RUN: %clang_cc1 %s -triple=armv7-none-linux-gnueabi -emit-llvm -o - -Werror | FileCheck %s -check-prefix=CHECK-ARM
+
+// Ensure that the bitcode has the correct triple
+// CHECK-RS32: target triple = "armv7-none-linux-gnueabi"
+// CHECK-RS64: target triple = "aarch64-none-linux-android"
+// CHECK-ARM: target triple = "armv7-none-linux-gnueabi"
+
+// Ensure that long data type has 8-byte size and alignment in RenderScript
+#ifdef __RENDERSCRIPT__
+#define LONG_WIDTH_AND_ALIGN 8
+#else
+#define LONG_WIDTH_AND_ALIGN 4
+#endif
+
+_Static_assert(sizeof(long) == LONG_WIDTH_AND_ALIGN, "sizeof long is wrong");
+_Static_assert(_Alignof(long) == LONG_WIDTH_AND_ALIGN, "sizeof long is wrong");
+
+// CHECK-RS32: i64 @test_long(i64 %v)
+// CHECK-RS64: i64 @test_long(i64 %v)
+// CHECK-ARM: i32 @test_long(i32 %v)
+long test_long(long v) {
+  return v + 1;
+}




More information about the cfe-commits mailing list