[PATCH] D80130: [mlir][SystemZ] Fix incompatible datalayout in SystemZ

Haruki Imai via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon May 18 09:07:36 PDT 2020


imaihal created this revision.
Herald added subscribers: llvm-commits, jurahul, Kayjukh, frgossen, grosul1, Joonsoo, stephenneuendorffer, liufengdb, lucyrfox, mgester, arpith-jacob, nicolasvasilache, antiagainst, shauheen, jpienaar, rriddle, mehdi_amini.
Herald added a project: LLVM.
imaihal added a comment.

Without this patch, following tests fail in SystemZ(z14)

  MLIR :: mlir-cpu-runner/linalg_integration_test.mlir
  MLIR :: mlir-cpu-runner/sgemm_naive_codegen.mlir
  MLIR :: mlir-cpu-runner/simple.mlir
  MLIR :: mlir-cpu-runner/unranked_memref.mlir
  MLIR :: mlir-cpu-runner/utils.mlir

Error message is as follows.

  Failure value returned from cantFail wrapped call
  Added modules have incompatible data layouts: E-m:e-i1:8:16-i8:8:16-i64:64-f128:64-a:8:16-n32:64 (module) vs E-m:e-i1:8:16-i8:8:16-i64:6\
  4-f128:64-v128:64-a:8:16-n32:64 (jit)


MLIR tests in "mlir/test/mlir-cpu-runner" fails in SystemZ (z14) because
of incompatible datalayout error. This patch fixes it by setting host
CPU name in createTargetMachine()


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D80130

Files:
  mlir/lib/ExecutionEngine/ExecutionEngine.cpp


Index: mlir/lib/ExecutionEngine/ExecutionEngine.cpp
===================================================================
--- mlir/lib/ExecutionEngine/ExecutionEngine.cpp
+++ mlir/lib/ExecutionEngine/ExecutionEngine.cpp
@@ -27,6 +27,7 @@
 #include "llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h"
 #include "llvm/ExecutionEngine/SectionMemoryManager.h"
 #include "llvm/IR/IRBuilder.h"
+#include "llvm/MC/SubtargetFeature.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/Host.h"
@@ -119,8 +120,16 @@
     errs() << "NO target: " << errorMessage << "\n";
     return true;
   }
-  std::unique_ptr<llvm::TargetMachine> machine(
-      target->createTargetMachine(targetTriple, "generic", "", {}, {}));
+  std::string CPU = std::string(llvm::sys::getHostCPUName());
+  llvm::SubtargetFeatures Features;
+  llvm::StringMap<bool> HostFeatures;
+
+  if (llvm::sys::getHostCPUFeatures(HostFeatures))
+    for (auto &F : HostFeatures)
+      Features.AddFeature(F.first(), F.second);
+
+  std::unique_ptr<llvm::TargetMachine> machine(target->createTargetMachine(
+      targetTriple, CPU, Features.getString(), {}, {}));
   llvmModule->setDataLayout(machine->createDataLayout());
   llvmModule->setTargetTriple(targetTriple);
   return false;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D80130.264640.patch
Type: text/x-patch
Size: 1281 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200518/8e219636/attachment.bin>


More information about the llvm-commits mailing list