Remove useless null checks from the passes
This commit is contained in:
parent
4b03316d81
commit
895ff27a51
|
@ -496,6 +496,8 @@ Source code -> IR X -> IR Y -> IR Z -> ... -> Target Code
|
||||||
|
|
||||||
* Episode 11 - Lowering SLIR
|
* Episode 11 - Lowering SLIR
|
||||||
** Overview
|
** Overview
|
||||||
|
- What is a Pass?
|
||||||
|
- Pass Manager
|
||||||
** Dialect lowering
|
** Dialect lowering
|
||||||
*** Why?
|
*** Why?
|
||||||
*** Transforming a dialect to another dialect or LLVM IR
|
*** Transforming a dialect to another dialect or LLVM IR
|
||||||
|
@ -506,4 +508,3 @@ This framework allows for transforming a set of illegal operations to a set of l
|
||||||
*** Rewrite Patterns
|
*** Rewrite Patterns
|
||||||
*** Type Converter
|
*** Type Converter
|
||||||
** Full vs Partial Conversion
|
** Full vs Partial Conversion
|
||||||
** Dealing with Pass failures
|
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
|
|
||||||
#include "serene/passes.h"
|
#include "serene/passes.h"
|
||||||
#include "serene/slir/dialect.h"
|
#include "serene/slir/dialect.h"
|
||||||
|
#include "serene/utils.h"
|
||||||
|
|
||||||
#include <llvm/Support/Casting.h>
|
#include <llvm/Support/Casting.h>
|
||||||
#include <mlir/Dialect/LLVMIR/LLVMDialect.h>
|
#include <mlir/Dialect/LLVMIR/LLVMDialect.h>
|
||||||
|
@ -52,12 +53,7 @@ ValueOpLowering::matchAndRewrite(serene::slir::ValueOp op,
|
||||||
// TODO: use a mechanism to generate unique names
|
// TODO: use a mechanism to generate unique names
|
||||||
auto fn = rewriter.create<mlir::FuncOp>(loc, "randomname", func_type);
|
auto fn = rewriter.create<mlir::FuncOp>(loc, "randomname", func_type);
|
||||||
|
|
||||||
if (!fn) {
|
auto *entryBlock = fn.addEntryBlock();
|
||||||
op.emitOpError("Value Rewrite fn is null");
|
|
||||||
return mlir::failure();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto entryBlock = fn.addEntryBlock();
|
|
||||||
rewriter.setInsertionPointToStart(entryBlock);
|
rewriter.setInsertionPointToStart(entryBlock);
|
||||||
|
|
||||||
// Since we only support i64 at the moment we use ConstantIntOp
|
// Since we only support i64 at the moment we use ConstantIntOp
|
||||||
|
@ -66,12 +62,7 @@ ValueOpLowering::matchAndRewrite(serene::slir::ValueOp op,
|
||||||
rewriter.getI64Type())
|
rewriter.getI64Type())
|
||||||
.getResult();
|
.getResult();
|
||||||
|
|
||||||
mlir::ReturnOp returnOp = rewriter.create<mlir::ReturnOp>(loc, retVal);
|
UNUSED(rewriter.create<mlir::ReturnOp>(loc, retVal));
|
||||||
|
|
||||||
if (!returnOp) {
|
|
||||||
op.emitError("Value Rewrite returnOp is null");
|
|
||||||
return mlir::failure();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn.setPrivate();
|
fn.setPrivate();
|
||||||
|
|
||||||
|
@ -113,14 +104,10 @@ FnOpLowering::matchAndRewrite(serene::slir::FnOp op,
|
||||||
auto func_type = rewriter.getFunctionType(arg_types, rewriter.getI64Type());
|
auto func_type = rewriter.getFunctionType(arg_types, rewriter.getI64Type());
|
||||||
auto fn = rewriter.create<mlir::FuncOp>(loc, name, func_type);
|
auto fn = rewriter.create<mlir::FuncOp>(loc, name, func_type);
|
||||||
|
|
||||||
if (!fn) {
|
|
||||||
op.emitError("Value Rewrite fn is null");
|
|
||||||
return mlir::failure();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto *entryBlock = fn.addEntryBlock();
|
auto *entryBlock = fn.addEntryBlock();
|
||||||
|
|
||||||
rewriter.setInsertionPointToStart(entryBlock);
|
rewriter.setInsertionPointToStart(entryBlock);
|
||||||
|
|
||||||
auto retVal =
|
auto retVal =
|
||||||
rewriter
|
rewriter
|
||||||
.create<mlir::ConstantIntOp>(loc, (int64_t)3, rewriter.getI64Type())
|
.create<mlir::ConstantIntOp>(loc, (int64_t)3, rewriter.getI64Type())
|
||||||
|
|
|
@ -74,8 +74,9 @@ void SLIRToLLVMDialect::runOnOperation() {
|
||||||
// We want to completely lower to LLVM, so we use a `FullConversion`. This
|
// We want to completely lower to LLVM, so we use a `FullConversion`. This
|
||||||
// ensures that only legal operations will remain after the conversion.
|
// ensures that only legal operations will remain after the conversion.
|
||||||
auto module = getOperation();
|
auto module = getOperation();
|
||||||
if (failed(applyFullConversion(module, target, std::move(patterns))))
|
if (failed(applyFullConversion(module, target, std::move(patterns)))) {
|
||||||
signalPassFailure();
|
signalPassFailure();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
std::unique_ptr<mlir::Pass> createSLIRLowerToLLVMDialectPass() {
|
std::unique_ptr<mlir::Pass> createSLIRLowerToLLVMDialectPass() {
|
||||||
|
|
Loading…
Reference in New Issue