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) ME=$(cd "$(dirname "$0")/." >/dev/null 2>&1 ; pwd -P)
CMAKEARGS_DEBUG=" -DCMAKE_BUILD_TYPE=Debug -DSERENE_WITH_MLIR_CL_OPTION=ON" 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 # The scan-build utility scans the build for bugs checkout the man page
scanbuild="scan-build --force-analyze-debug-code --use-analyzer=$(which clang)" scanbuild="scan-build --force-analyze-debug-code --use-analyzer=$(which clang)"

View File

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

View File

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

View File

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

View File

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

View File

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