[Mlir-commits] [mlir] d85821d - [MLIR] Added llvm.freeze
Alex Zinenko
llvmlistbot at llvm.org
Mon Mar 2 01:24:11 PST 2020
Author: Sagar Jain
Date: 2020-03-02T10:24:01+01:00
New Revision: d85821dfa623b43b95dda1af3b80e11902d3994f
URL: https://github.com/llvm/llvm-project/commit/d85821dfa623b43b95dda1af3b80e11902d3994f
DIFF: https://github.com/llvm/llvm-project/commit/d85821dfa623b43b95dda1af3b80e11902d3994f.diff
LOG: [MLIR] Added llvm.freeze
This patch adds llvm.freeze & processes undef constants from LLVM IR.
Syntax:
LLVM IR
`<result> = freeze ty <val>`
MLIR LLVM Dialect:
`llvm.freeze val attr-dict : type`
Example:
LLVM IR: `%3 = freeze i32 5`
MLIR: `%6 = llvm.freeze %5 : !llvm.i32`
Differential Revision: https://reviews.llvm.org/D75329
Added:
Modified:
mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp
mlir/test/Dialect/LLVMIR/roundtrip.mlir
mlir/test/Target/import.ll
mlir/test/Target/llvmir.mlir
Removed:
################################################################################
diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
index 601bfbf68926..66d5f9d3c82c 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
@@ -451,6 +451,11 @@ def LLVM_SelectOp
}]>];
let assemblyFormat = "operands attr-dict `:` type($condition) `,` type($res)";
}
+def LLVM_FreezeOp : LLVM_OneResultOp<"freeze", [SameOperandsAndResultType]>,
+ Arguments<(ins LLVM_Type:$val)> {
+ let assemblyFormat = "$val attr-dict `:` type($val)";
+ string llvmBuilder = "builder.CreateFreeze($val);";
+}
// Terminators.
def LLVM_BrOp : LLVM_TerminatorOp<"br", []> {
diff --git a/mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp b/mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp
index b5cfcd6786d1..5441385acb03 100644
--- a/mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp
+++ b/mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp
@@ -426,6 +426,12 @@ Value Importer::processConstant(llvm::Constant *c) {
i->deleteValue();
return instMap[c] = instMap[i];
}
+ if (auto *ue = dyn_cast<llvm::UndefValue>(c)) {
+ LLVMType type = processType(ue->getType());
+ if (!type)
+ return nullptr;
+ return instMap[c] = bEntry.create<UndefOp>(UnknownLoc::get(context), type);
+ }
emitError(unknownLoc) << "unhandled constant: " << diag(*c);
return nullptr;
}
@@ -493,7 +499,7 @@ static const DenseMap<unsigned, StringRef> opcMap = {
// ICmp is handled specially.
// FIXME: fcmp
// PHI is handled specially.
- INST(Call, Call),
+ INST(Freeze, Freeze), INST(Call, Call),
// FIXME: select
// FIXME: vaarg
// FIXME: extractelement
@@ -591,6 +597,7 @@ LogicalResult Importer::processInstruction(llvm::Instruction *inst) {
case llvm::Instruction::PtrToInt:
case llvm::Instruction::IntToPtr:
case llvm::Instruction::AddrSpaceCast:
+ case llvm::Instruction::Freeze:
case llvm::Instruction::BitCast: {
OperationState state(loc, opcMap.lookup(inst->getOpcode()));
SmallVector<Value, 4> ops;
diff --git a/mlir/test/Dialect/LLVMIR/roundtrip.mlir b/mlir/test/Dialect/LLVMIR/roundtrip.mlir
index 53a2bb1f2658..8a8de4cf6f21 100644
--- a/mlir/test/Dialect/LLVMIR/roundtrip.mlir
+++ b/mlir/test/Dialect/LLVMIR/roundtrip.mlir
@@ -282,3 +282,14 @@ llvm.func @invokeLandingpad() -> !llvm.i32 {
^bb4:
llvm.return %0 : !llvm.i32
}
+
+// CHECK-LABEL: @useFreezeOp
+func @useFreezeOp(%arg0: !llvm.i32) {
+ // CHECK: = llvm.freeze %[[ARG0:.*]] : !llvm.i32
+ %0 = llvm.freeze %arg0 : !llvm.i32
+ // CHECK: %[[x:.*]] = llvm.mlir.undef : !llvm.i8
+ %1 = llvm.mlir.undef : !llvm.i8
+ // CHECK: = llvm.freeze %[[x]] : !llvm.i8
+ %2 = llvm.freeze %1 : !llvm.i8
+ return
+}
\ No newline at end of file
diff --git a/mlir/test/Target/import.ll b/mlir/test/Target/import.ll
index 9c1f13aed680..5e38b6b2fe7d 100644
--- a/mlir/test/Target/import.ll
+++ b/mlir/test/Target/import.ll
@@ -297,3 +297,14 @@ define i32 @invokeLandingpad() personality i8* bitcast (i32 (...)* @__gxx_person
; CHECK: llvm.return %{{[0-9]+}} : !llvm.i32
ret i32 0
}
+
+;CHECK-LABEL: @useFreezeOp
+define i32 @useFreezeOp(i32 %x) {
+ ;CHECK: %{{[0-9]+}} = llvm.freeze %{{[0-9a-z]+}} : !llvm.i32
+ %1 = freeze i32 %x
+ %2 = add i8 10, 10
+ ;CHECK: %{{[0-9]+}} = llvm.freeze %{{[0-9]+}} : !llvm.i8
+ %3 = freeze i8 %2
+ %poison = add nsw i1 0, undef
+ ret i32 0
+}
\ No newline at end of file
diff --git a/mlir/test/Target/llvmir.mlir b/mlir/test/Target/llvmir.mlir
index 1049c9c6ffed..9e0e8c247e20 100644
--- a/mlir/test/Target/llvmir.mlir
+++ b/mlir/test/Target/llvmir.mlir
@@ -1171,3 +1171,13 @@ llvm.func @invokeLandingpad() -> !llvm.i32 {
^bb3: // pred: ^bb1
%8 = llvm.invoke @bar(%6) to ^bb2 unwind ^bb1 : (!llvm<"i8*">) -> !llvm<"i8*">
}
+
+// CHECK-LABEL: @callFreezeOp
+llvm.func @callFreezeOp(%x : !llvm.i32) {
+ // CHECK: freeze i32 %{{[0-9]+}}
+ %0 = llvm.freeze %x : !llvm.i32
+ %1 = llvm.mlir.undef : !llvm.i32
+ // CHECK: freeze i32 undef
+ %2 = llvm.freeze %1 : !llvm.i32
+ llvm.return
+}
\ No newline at end of file
More information about the Mlir-commits
mailing list