Skip to content

Commit

Permalink
[ArcToLLVM] Add support for index dialect
Browse files Browse the repository at this point in the history
Support the index dialect when lowering from Arc to LLVM. Also fix a
minor issue in the lowering `SimGetPortOp`.
  • Loading branch information
fabianschuiki committed Oct 14, 2024
1 parent 822ac6b commit 2a8231b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
1 change: 1 addition & 0 deletions lib/Conversion/ArcToLLVM/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ add_circt_conversion_library(CIRCTArcToLLVM
MLIRArithToLLVM
MLIRControlFlowToLLVM
MLIRFuncToLLVM
MLIRIndexToLLVM
MLIRLLVMCommonConversion
MLIRSCFToControlFlow
MLIRTransforms
Expand Down
9 changes: 5 additions & 4 deletions lib/Conversion/ArcToLLVM/LowerArcToLLVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "mlir/Conversion/ArithToLLVM/ArithToLLVM.h"
#include "mlir/Conversion/ControlFlowToLLVM/ControlFlowToLLVM.h"
#include "mlir/Conversion/FuncToLLVM/ConvertFuncToLLVM.h"
#include "mlir/Conversion/IndexToLLVM/IndexToLLVM.h"
#include "mlir/Conversion/LLVMCommon/ConversionTarget.h"
#include "mlir/Conversion/LLVMCommon/TypeConverter.h"
#include "mlir/Conversion/SCFToControlFlow/SCFToControlFlow.h"
Expand Down Expand Up @@ -440,20 +441,19 @@ struct SimGetPortOpLowering : public ModelAwarePattern<arc::SimGetPortOp> {
.getValue());
ModelInfoMap &model = modelIt->second;

auto type = typeConverter->convertType(op.getValue().getType());
auto portIt = model.states.find(op.getPort());
if (portIt == model.states.end()) {
// If the port is not found in the state, it means the model does not
// actually set it. Thus this operation returns 0.
rewriter.replaceOpWithNewOp<LLVM::ConstantOp>(
op, typeConverter->convertType(op.getValue().getType()), 0);
rewriter.replaceOpWithNewOp<LLVM::ConstantOp>(op, type, 0);
return success();
}

StateInfo &port = portIt->second;
Value statePtr = createPtrToPortState(rewriter, op.getLoc(),
adaptor.getInstance(), port);
rewriter.replaceOpWithNewOp<LLVM::LoadOp>(op, op.getValue().getType(),
statePtr);
rewriter.replaceOpWithNewOp<LLVM::LoadOp>(op, type, statePtr);

return success();
}
Expand Down Expand Up @@ -613,6 +613,7 @@ void LowerArcToLLVMPass::runOnOperation() {
populateFuncToLLVMConversionPatterns(converter, patterns);
cf::populateControlFlowToLLVMConversionPatterns(converter, patterns);
arith::populateArithToLLVMConversionPatterns(converter, patterns);
index::populateIndexToLLVMConversionPatterns(converter, patterns);
populateAnyFunctionOpInterfaceTypeConversionPattern(patterns, converter);

// CIRCT patterns.
Expand Down
5 changes: 5 additions & 0 deletions tools/arcilator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,17 @@ set(libs
CIRCTSimTransforms
CIRCTSupport
CIRCTTransforms
MLIRArithDialect
MLIRBuiltinToLLVMIRTranslation
MLIRControlFlowDialect
MLIRDLTIDialect
MLIRFuncDialect
MLIRFuncInlinerExtension
MLIRIndexDialect
MLIRLLVMIRTransforms
MLIRLLVMToLLVMIRTranslation
MLIRParser
MLIRSCFDialect
MLIRTargetLLVMIRExport
)

Expand Down
2 changes: 2 additions & 0 deletions tools/arcilator/arcilator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "mlir/Dialect/DLTI/DLTI.h"
#include "mlir/Dialect/Func/Extensions/InlinerExtension.h"
#include "mlir/Dialect/Func/IR/FuncOps.h"
#include "mlir/Dialect/Index/IR/IndexDialect.h"
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
#include "mlir/Dialect/LLVMIR/Transforms/InlinerInterfaceImpl.h"
#include "mlir/Dialect/LLVMIR/Transforms/Passes.h"
Expand Down Expand Up @@ -596,6 +597,7 @@ static LogicalResult executeArcilator(MLIRContext &context) {
mlir::cf::ControlFlowDialect,
mlir::DLTIDialect,
mlir::func::FuncDialect,
mlir::index::IndexDialect,
mlir::LLVM::LLVMDialect,
mlir::scf::SCFDialect,
om::OMDialect,
Expand Down

0 comments on commit 2a8231b

Please sign in to comment.