summaryrefslogtreecommitdiffstats
path: root/mlir/examples
diff options
context:
space:
mode:
Diffstat (limited to 'mlir/examples')
-rw-r--r--mlir/examples/Linalg/Linalg1/lib/ConvertToLLVMDialect.cpp46
-rw-r--r--mlir/examples/Linalg/Linalg3/lib/ConvertToLLVMDialect.cpp15
-rw-r--r--mlir/examples/toy/Ch5/mlir/LateLowering.cpp10
3 files changed, 14 insertions, 57 deletions
diff --git a/mlir/examples/Linalg/Linalg1/lib/ConvertToLLVMDialect.cpp b/mlir/examples/Linalg/Linalg1/lib/ConvertToLLVMDialect.cpp
index 0b640298e02..0b8d6bd9913 100644
--- a/mlir/examples/Linalg/Linalg1/lib/ConvertToLLVMDialect.cpp
+++ b/mlir/examples/Linalg/Linalg1/lib/ConvertToLLVMDialect.cpp
@@ -26,6 +26,7 @@
#include "mlir/IR/StandardTypes.h"
#include "mlir/IR/Types.h"
#include "mlir/LLVMIR/LLVMDialect.h"
+#include "mlir/LLVMIR/LLVMLowering.h"
#include "mlir/LLVMIR/Transforms.h"
#include "mlir/Pass/PassManager.h"
#include "mlir/Support/LogicalResult.h"
@@ -392,7 +393,9 @@ public:
: DialectOpConversion("some_consumer", 1, context) {}
void rewrite(Operation *op, ArrayRef<Value *> operands,
- PatternRewriter &rewriter) const override {}
+ PatternRewriter &rewriter) const override {
+ rewriter.replaceOp(op, llvm::None);
+ }
};
void linalg::getDescriptorConverters(mlir::OwningRewritePatternList &patterns,
@@ -403,7 +406,7 @@ void linalg::getDescriptorConverters(mlir::OwningRewritePatternList &patterns,
namespace {
// The conversion class from Linalg to LLVMIR.
-class Lowering : public DialectConversion {
+class Lowering : public LLVMLowering {
public:
explicit Lowering(std::function<void(mlir::OwningRewritePatternList &patterns,
mlir::MLIRContext *context)>
@@ -412,37 +415,13 @@ public:
protected:
// Initialize the list of converters.
- void initConverters(OwningRewritePatternList &patterns,
- MLIRContext *context) override {
- setup(patterns, context);
+ void initAdditionalConverters(OwningRewritePatternList &patterns) override {
+ setup(patterns, llvmDialect->getContext());
}
// This gets called for block and region arguments, and attributes.
- Type convertType(Type t) override { return linalg::convertLinalgType(t); }
-
- // This gets called for function signatures. Convert function arguments and
- // results to the LLVM types, but keep the outer function type as built-in
- // MLIR function type. This does not support multi-result functions because
- // LLVM does not.
- FunctionType convertFunctionSignatureType(
- FunctionType t, ArrayRef<NamedAttributeList> argAttrs,
- SmallVectorImpl<NamedAttributeList> &convertedArgAttrs) override {
- convertedArgAttrs.reserve(argAttrs.size());
- convertedArgAttrs.insert(convertedArgAttrs.end(), argAttrs.begin(),
- argAttrs.end());
-
- SmallVector<Type, 4> argTypes;
- argTypes.reserve(t.getNumInputs());
- for (auto ty : t.getInputs())
- argTypes.push_back(linalg::convertLinalgType(ty));
-
- SmallVector<Type, 1> resultTypes;
- resultTypes.reserve(t.getNumResults());
- for (auto ty : t.getResults())
- resultTypes.push_back(linalg::convertLinalgType(ty));
- assert(t.getNumResults() <= 1 && "NYI: multi-result functions");
-
- return FunctionType::get(argTypes, resultTypes, t.getContext());
+ Type convertAdditionalType(Type t) override {
+ return linalg::convertLinalgType(t);
}
private:
@@ -472,13 +451,6 @@ void linalg::convertToLLVM(mlir::Module &module) {
auto r = Lowering(getDescriptorConverters).convert(&module);
(void)r;
assert(succeeded(r) && "conversion failed");
-
- // Convert the remaining standard MLIR operations to the LLVM IR dialect using
- // the default converter.
- auto converter = createStdToLLVMConverter();
- r = converter->convert(&module);
- (void)r;
- assert(succeeded(r) && "second conversion failed");
}
namespace {
diff --git a/mlir/examples/Linalg/Linalg3/lib/ConvertToLLVMDialect.cpp b/mlir/examples/Linalg/Linalg3/lib/ConvertToLLVMDialect.cpp
index 8d945f3274c..b475ed2d2a1 100644
--- a/mlir/examples/Linalg/Linalg3/lib/ConvertToLLVMDialect.cpp
+++ b/mlir/examples/Linalg/Linalg3/lib/ConvertToLLVMDialect.cpp
@@ -58,13 +58,6 @@ public:
: DialectOpConversion(Op::getOperationName(), 1, context) {}
using Base = LoadStoreOpConversion<Op>;
- // Match the Op specified as template argument.
- PatternMatchResult match(Operation *op) const override {
- if (isa<Op>(op))
- return matchSuccess();
- return matchFailure();
- }
-
// Compute the pointer to an element of the buffer underlying the view given
// current view indices. Use the base offset and strides stored in the view
// descriptor to emit IR iteratively computing the actual offset, followed by
@@ -128,6 +121,7 @@ class StoreOpConversion : public LoadStoreOpConversion<linalg::StoreOp> {
ArrayRef<Value *> indices = operands.drop_front(2);
Value *ptr = obtainDataPtr(op, viewDescriptor, indices, rewriter);
intrinsics::store(data, ptr);
+ rewriter.replaceOp(op, llvm::None);
}
};
@@ -154,11 +148,4 @@ void linalg::convertLinalg3ToLLVM(Module &module) {
auto r = lowering->convert(&module);
(void)r;
assert(succeeded(r) && "conversion failed");
-
- // Convert the remaining standard MLIR operations to the LLVM IR dialect using
- // the default converter.
- auto converter = createStdToLLVMConverter();
- r = converter->convert(&module);
- (void)r;
- assert(succeeded(r) && "second conversion failed");
}
diff --git a/mlir/examples/toy/Ch5/mlir/LateLowering.cpp b/mlir/examples/toy/Ch5/mlir/LateLowering.cpp
index 4cb34d1181a..00b3a74f018 100644
--- a/mlir/examples/toy/Ch5/mlir/LateLowering.cpp
+++ b/mlir/examples/toy/Ch5/mlir/LateLowering.cpp
@@ -175,6 +175,7 @@ public:
});
// clang-format on
}
+ rewriter.replaceOp(op, llvm::None);
}
private:
@@ -308,14 +309,11 @@ public:
void rewrite(Operation *op, ArrayRef<Value *> operands,
PatternRewriter &rewriter) const override {
- auto retOp = cast<toy::ReturnOp>(op);
- using namespace edsc;
- auto loc = retOp.getLoc();
// Argument is optional, handle both cases.
- if (retOp.getNumOperands())
- rewriter.create<ReturnOp>(loc, operands[0]);
+ if (op->getNumOperands())
+ rewriter.replaceOpWithNewOp<ReturnOp>(op, operands[0]);
else
- rewriter.create<ReturnOp>(loc);
+ rewriter.replaceOpWithNewOp<ReturnOp>(op);
}
};
OpenPOWER on IntegriCloud