]> granicus.if.org Git - clang/commitdiff
Add SPIR32/SPIR64 targets to Clang
authorGuy Benyei <guy.benyei@intel.com>
Tue, 11 Dec 2012 21:38:14 +0000 (21:38 +0000)
committerGuy Benyei <guy.benyei@intel.com>
Tue, 11 Dec 2012 21:38:14 +0000 (21:38 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@169917 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Basic/Targets.cpp
test/CodeGenOpenCL/spir32_target.cl [new file with mode: 0644]
test/CodeGenOpenCL/spir64_target.cl [new file with mode: 0644]

index 6d883c8a4b372263b3a20b6af4c044b9507a0ca7..3fbbf101d9a9387085bf2ec0ebf849d2fe4b0d7f 100644 (file)
@@ -4423,6 +4423,89 @@ void PNaClTargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases,
 }
 } // end anonymous namespace.
 
+namespace {
+  static const unsigned SPIRAddrSpaceMap[] = {
+    1,    // opencl_global
+    3,    // opencl_local
+    2,    // opencl_constant
+    0,    // cuda_device
+    0,    // cuda_constant
+    0     // cuda_shared
+  };
+  class SPIRTargetInfo : public TargetInfo {
+    static const char * const GCCRegNames[];
+    static const Builtin::Info BuiltinInfo[];
+    std::vector<llvm::StringRef> AvailableFeatures;
+  public:
+    SPIRTargetInfo(const std::string& triple) : TargetInfo(triple) {
+      assert(getTriple().getOS() == llvm::Triple::UnknownOS &&
+        "SPIR target must use unknown OS");
+      assert(getTriple().getEnvironment() == llvm::Triple::UnknownEnvironment &&
+        "SPIR target must use unknown environment type");
+      BigEndian = false;
+      TLSSupported = false;
+      LongWidth = LongAlign = 64;
+      AddrSpaceMap = &SPIRAddrSpaceMap;
+      // Define available target features
+      // These must be defined in sorted order!
+      NoAsmVariants = true;
+    }
+    virtual void getTargetDefines(const LangOptions &Opts,
+                                  MacroBuilder &Builder) const {
+      DefineStd(Builder, "SPIR", Opts);
+    }
+    virtual bool hasFeature(StringRef Feature) const {
+      return Feature == "spir";
+    }
+    
+    virtual void getTargetBuiltins(const Builtin::Info *&Records,
+                                   unsigned &NumRecords) const {}
+    virtual const char *getClobbers() const {
+      return "";
+    }
+    virtual void getGCCRegNames(const char * const *&Names,
+                                unsigned &NumNames) const {}
+    virtual bool validateAsmConstraint(const char *&Name,
+                                       TargetInfo::ConstraintInfo &info) const {
+      return true;
+    }
+    virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
+                                  unsigned &NumAliases) const {}
+    virtual BuiltinVaListKind getBuiltinVaListKind() const {
+      return TargetInfo::VoidPtrBuiltinVaList;
+    }
+  };
+
+
+  class SPIR32TargetInfo : public SPIRTargetInfo {
+  public:
+    SPIR32TargetInfo(const std::string& triple) : SPIRTargetInfo(triple) {
+      PointerWidth = PointerAlign = 32;
+      SizeType     = TargetInfo::UnsignedInt;
+      PtrDiffType = IntPtrType = TargetInfo::SignedInt;
+      DescriptionString
+        = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-"
+          "f32:32:32-f64:64:64-v16:16:16-v24:32:32-v32:32:32-v48:64:64-"
+          "v64:64:64-v96:128:128-v128:128:128-v192:256:256-v256:256:256-"
+          "v512:512:512-v1024:1024:1024";
+  }
+  };
+
+  class SPIR64TargetInfo : public SPIRTargetInfo {
+  public:
+    SPIR64TargetInfo(const std::string& triple) : SPIRTargetInfo(triple) {
+      PointerWidth = PointerAlign = 64;
+      SizeType     = TargetInfo::UnsignedLong;
+      PtrDiffType = IntPtrType = TargetInfo::SignedLong;
+      DescriptionString
+        = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-"
+          "f32:32:32-f64:64:64-v16:16:16-v24:32:32-v32:32:32-v48:64:64-"
+          "v64:64:64-v96:128:128-v128:128:128-v192:256:256-v256:256:256-"
+          "v512:512:512-v1024:1024:1024";
+  }
+  };
+}
+
 
 //===----------------------------------------------------------------------===//
 // Driver code
@@ -4669,6 +4752,21 @@ static TargetInfo *AllocateTarget(const std::string &T) {
     default:
       return new X86_64TargetInfo(T);
     }
+
+    case llvm::Triple::spir: {
+      llvm::Triple Triple(T);
+      if (Triple.getOS() != llvm::Triple::UnknownOS ||
+        Triple.getEnvironment() != llvm::Triple::UnknownEnvironment)
+        return NULL;
+      return new SPIR32TargetInfo(T);
+    }
+    case llvm::Triple::spir64: {
+      llvm::Triple Triple(T);
+      if (Triple.getOS() != llvm::Triple::UnknownOS ||
+        Triple.getEnvironment() != llvm::Triple::UnknownEnvironment)
+        return NULL;
+      return new SPIR64TargetInfo(T);
+    }
   }
 }
 
diff --git a/test/CodeGenOpenCL/spir32_target.cl b/test/CodeGenOpenCL/spir32_target.cl
new file mode 100644 (file)
index 0000000..42bffbd
--- /dev/null
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 %s -triple "spir-unknown-unknown" -emit-llvm -o - | FileCheck %s\r
+\r
+// CHECK: target triple = "spir-unknown-unknown"\r
+\r
+typedef struct {\r
+  char c;\r
+  void *v;\r
+  void *v2;\r
+} my_st;\r
+\r
+kernel void foo(global long *arg) {\r
+  int res1[sizeof(my_st)  == 12 ? 1 : -1];
+  int res2[sizeof(void *) ==  4 ? 1 : -1];
+  int res3[sizeof(arg)    ==  4 ? 1 : -1];
+\r
+  my_st *tmp = 0;\r
+\r
+  arg[0] = (long)(&tmp->v);\r
+//CHECK: store i64 4, i64 addrspace(1)*\r
+  arg[1] = (long)(&tmp->v2);\r
+//CHECK: store i64 8, i64 addrspace(1)*\r
+}\r
diff --git a/test/CodeGenOpenCL/spir64_target.cl b/test/CodeGenOpenCL/spir64_target.cl
new file mode 100644 (file)
index 0000000..93ee86c
--- /dev/null
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 %s -triple "spir64-unknown-unknown" -emit-llvm -o - | FileCheck %s\r
+\r
+// CHECK: target triple = "spir64-unknown-unknown"\r
+\r
+typedef struct {\r
+  char c;\r
+  void *v;\r
+  void *v2;\r
+} my_st;\r
+\r
+kernel void foo(global long *arg) {\r
+  int res1[sizeof(my_st)  == 24 ? 1 : -1];
+  int res2[sizeof(void *) ==  8 ? 1 : -1];
+  int res3[sizeof(arg)    ==  8 ? 1 : -1];
+\r
+  my_st *tmp = 0;\r
+  arg[3] = (long)(&tmp->v);\r
+//CHECK: store i64 8, i64 addrspace(1)*\r
+  arg[4] = (long)(&tmp->v2);\r
+//CHECK: store i64 16, i64 addrspace(1)*\r
+}\r