[3/6] Set the triple to correct default value if SPIR and SPIR64

Submitted by junyan.he@inbox.com on June 23, 2017, 10:18 a.m.

Details

Message ID 1498213109-10042-3-git-send-email-junyan.he@inbox.com
State New
Headers show
Series "Series without cover letter" ( rev: 1 ) in Beignet

Not browsing as part of any series.

Commit Message

junyan.he@inbox.com June 23, 2017, 10:18 a.m.
From: Junyan He <junyan.he@intel.com>

Signed-off-by: Junyan He <junyan.he@intel.com>
---
 backend/src/backend/compiler_api.cpp | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

Patch hide | download patch | download mbox

diff --git a/backend/src/backend/compiler_api.cpp b/backend/src/backend/compiler_api.cpp
index e812414..6f8c332 100644
--- a/backend/src/backend/compiler_api.cpp
+++ b/backend/src/backend/compiler_api.cpp
@@ -743,8 +743,27 @@  GenLinkProgram(uint32_t deviceID, int binary_num, const char **binaries, size_t
   if (target_module == NULL)
     return false;
 
+  llvm::Triple target_triple(target_module->getTargetTriple());
+  if (target_triple.getArchName() == "spir" &&
+      target_triple.getVendorName() == "unknown" && target_triple.getOSName() == "unknown") {
+    target_module->setTargetTriple("spir");
+  } else if (target_triple.getArchName() == "spir64" &&
+             target_triple.getVendorName() == "unknown" && target_triple.getOSName() == "unknown") {
+    target_module->setTargetTriple("spir64");
+  }
+
   for (int i = 1; i < binary_num; i++) {
     llvm::Module *mod = loadProgramFromLLVMIRBinary(deviceID, binaries[i], binSizes[i]);
+
+    llvm::Triple triple(mod->getTargetTriple());
+    if (triple.getArchName() == "spir" &&
+        triple.getVendorName() == "unknown" && triple.getOSName() == "unknown") {
+      mod->setTargetTriple("spir");
+    } else if (triple.getArchName() == "spir64" &&
+               triple.getVendorName() == "unknown" && triple.getOSName() == "unknown") {
+      mod->setTargetTriple("spir64");
+    }
+
     bool link_ret =
 #if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 39
       LLVMLinkModules2(wrap(target_module), wrap(mod));