[Mlir-commits] [mlir] 758ddba - [MLIR] Use Datalayout defaults when importing LLVM
William S. Moses
llvmlistbot at llvm.org
Wed Mar 2 10:00:56 PST 2022
Author: William S. Moses
Date: 2022-03-02T13:00:53-05:00
New Revision: 758ddba38113b2ab48cd6e45d7617463969bf813
URL: https://github.com/llvm/llvm-project/commit/758ddba38113b2ab48cd6e45d7617463969bf813
DIFF: https://github.com/llvm/llvm-project/commit/758ddba38113b2ab48cd6e45d7617463969bf813.diff
LOG: [MLIR] Use Datalayout defaults when importing LLVM
LLVM defines several default datalayouts for integer and floating point types that are not being considered when importing into MLIR. This patch remedies this.
Reviewed By: ftynse
Differential Revision: https://reviews.llvm.org/D120832
Added:
Modified:
mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp
mlir/test/Target/LLVMIR/data-layout.ll
Removed:
################################################################################
diff --git a/mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp b/mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp
index 83b6a88695f57..c0cf8322d15d2 100644
--- a/mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp
+++ b/mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp
@@ -22,6 +22,7 @@
#include "mlir/Target/LLVMIR/TypeFromLLVM.h"
#include "mlir/Translation.h"
+#include "llvm/ADT/StringSet.h"
#include "llvm/ADT/TypeSwitch.h"
#include "llvm/IR/Attributes.h"
#include "llvm/IR/Constants.h"
@@ -93,8 +94,23 @@ DataLayoutSpecInterface
mlir::translateDataLayout(const llvm::DataLayout &dataLayout,
MLIRContext *context) {
assert(context && "expected MLIR context");
- StringRef layout = dataLayout.getStringRepresentation();
+ std::string layoutstr = dataLayout.getStringRepresentation();
+
+ // Remaining unhandled default layout defaults
+ // e (little endian if not set)
+ // p[n]:64:64:64 (non zero address spaces have 64-bit properties)
+ std::string append =
+ "p:64:64:64-S0-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f16:16:16-f64:"
+ "64:64-f128:128:128-v64:64:64-v128:128:128-a:0:64";
+ if (layoutstr.empty())
+ layoutstr = append;
+ else
+ layoutstr = layoutstr + "-" + append;
+
+ StringRef layout(layoutstr);
+
SmallVector<DataLayoutEntryInterface> entries;
+ StringSet<> seen;
while (!layout.empty()) {
// Split at '-'.
std::pair<StringRef, StringRef> split = layout.split('-');
@@ -104,6 +120,9 @@ mlir::translateDataLayout(const llvm::DataLayout &dataLayout,
// Split at ':'.
StringRef kind, spec;
std::tie(kind, spec) = current.split(':');
+ if (seen.contains(kind))
+ continue;
+ seen.insert(kind);
char symbol = kind.front();
StringRef parameter = kind.substr(1);
diff --git a/mlir/test/Target/LLVMIR/data-layout.ll b/mlir/test/Target/LLVMIR/data-layout.ll
index 4e832e7150545..9bcd689e2ea3d 100644
--- a/mlir/test/Target/LLVMIR/data-layout.ll
+++ b/mlir/test/Target/LLVMIR/data-layout.ll
@@ -5,6 +5,7 @@
; CHECK: #dlti.dl_entry<"dlti.endianness", "little">
; CHECK: #dlti.dl_entry<i64, dense<64> : vector<2xi32>>
; CHECK: #dlti.dl_entry<f80, dense<128> : vector<2xi32>>
+; CHECK: #dlti.dl_entry<i8, dense<8> : vector<2xi32>>
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
declare void @foo()
More information about the Mlir-commits
mailing list