Fix the wrong constant opretation

This commit is contained in:
Sameer Rahmani 2021-12-24 16:52:43 +00:00
parent aca81f8d61
commit 6d34e58665
6 changed files with 23 additions and 19 deletions

View File

@ -35,7 +35,7 @@ BUILD_DIR=$ROOT_DIR/build
ME=$(cd "$(dirname "$0")/." >/dev/null 2>&1 ; pwd -P)
CMAKEARGS_DEBUG=" -DCMAKE_BUILD_TYPE=Debug -DSERENE_WITH_MLIR_CL_OPTION=ON"
CMAKEARGS="-DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DSERENE_CCACHE_DIR=$HOME/.ccache"
CMAKEARGS="-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DSERENE_CCACHE_DIR=$HOME/.ccache"
# The scan-build utility scans the build for bugs checkout the man page
scanbuild="scan-build --force-analyze-debug-code --use-analyzer=$(which clang)"

View File

@ -33,6 +33,7 @@
#include <mlir/Support/LogicalResult.h>
#include <mlir/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.h>
#include <mlir/Target/LLVMIR/ModuleTranslation.h>
#include <stdexcept>
#include <utility>
@ -93,7 +94,7 @@ std::unique_ptr<llvm::Module> toLLVMIR(Generatable<T> &t) {
// Initialize LLVM targets.
llvm::InitializeNativeTarget();
llvm::InitializeNativeTargetAsmPrinter();
// llvm::InitializeNativeTargetAsmPrinter();
// TODO: replace this call with our own version of setupTargetTriple
mlir::ExecutionEngine::setupTargetTriple(llvmModule.get());

View File

@ -33,6 +33,7 @@
#include <mlir/Support/LogicalResult.h>
#include <mlir/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.h>
#include <mlir/Target/LLVMIR/ModuleTranslation.h>
#include <stdexcept>
#include <utility>
@ -89,7 +90,7 @@ std::unique_ptr<llvm::Module> toLLVMIR(Generatable<T> &t) {
// Initialize LLVM targets.
llvm::InitializeNativeTarget();
llvm::InitializeNativeTargetAsmPrinter();
// llvm::InitializeNativeTargetAsmPrinter();
// TODO: replace this call with our own version of setupTargetTriple
mlir::ExecutionEngine::setupTargetTriple(llvmModule.get());

View File

@ -168,6 +168,7 @@ target_link_libraries(serene PRIVATE
LLVMOrcJIT
MLIRLLVMToLLVMIRTranslation
LLVMX86AsmParser
#LLVMTarget
#LLVMX86AsmParser
${llvm_libs})

View File

@ -21,6 +21,7 @@
#include "serene/utils.h"
#include <llvm/Support/Casting.h>
#include <mlir/Dialect/Arithmetic/IR/Arithmetic.h>
#include <mlir/Dialect/LLVMIR/LLVMDialect.h>
#include <mlir/Dialect/MemRef/IR/MemRef.h>
#include <mlir/Dialect/StandardOps/IR/Ops.h>
@ -30,6 +31,8 @@
#include <mlir/Pass/Pass.h>
#include <mlir/Transforms/DialectConversion.h>
#include <cstdint>
namespace serene::passes {
// ----------------------------------------------------------------------------
@ -57,12 +60,10 @@ ValueOpLowering::matchAndRewrite(serene::slir::ValueOp op,
rewriter.setInsertionPointToStart(entryBlock);
// Since we only support i64 at the moment we use ConstantOp
auto retVal =
rewriter
.create<mlir::ConstantOp>(
loc, mlir::IntegerAttr::get(rewriter.getI64Type(), value),
rewriter.getI64Type())
.getResult();
auto retVal = rewriter
.create<mlir::arith::ConstantIntOp>(loc, (int64_t)value,
rewriter.getI64Type())
.getResult();
UNUSED(rewriter.create<mlir::ReturnOp>(loc, retVal));
@ -111,9 +112,8 @@ FnOpLowering::matchAndRewrite(serene::slir::FnOp op,
rewriter.setInsertionPointToStart(entryBlock);
auto retVal = rewriter
.create<mlir::ConstantOp>(
loc, mlir::IntegerAttr::get(rewriter.getI64Type(), 3),
rewriter.getI64Type())
.create<mlir::arith::ConstantIntOp>(loc, (int64_t)3,
rewriter.getI64Type())
.getResult();
rewriter.create<mlir::ReturnOp>(loc, retVal);
@ -142,7 +142,7 @@ struct SLIRToMLIRPass
// dialects do we want to lower to
void SLIRToMLIRPass::getDependentDialects(
mlir::DialectRegistry &registry) const {
registry.insert<mlir::StandardOpsDialect>();
registry.insert<mlir::StandardOpsDialect, mlir::arith::ArithmeticDialect>();
};
/// Return the current function being transformed.
@ -161,6 +161,7 @@ void SLIRToMLIRPass::runOnModule() {
// We define the specific operations, or dialects, that are legal targets for
// this lowering. In our case, we are lowering to the `Standard` dialects.
target.addLegalDialect<mlir::StandardOpsDialect>();
target.addLegalDialect<mlir::arith::ArithmeticDialect>();
// We also define the SLIR dialect as Illegal so that the conversion will fail
// if any of these operations are *not* converted.

View File

@ -39,12 +39,12 @@ target_link_libraries(serenec
PRIVATE
Serene::lib
MLIRPass
#MLIRPass
LLVMTarget
LLVMOption
lldDriver
lldELF
#LLVMTarget
#LLVMOption
#lldDriver
#lldELF
)
target_include_directories(serenec PRIVATE ${PROJECT_BINARY_DIR})