Jlm
JlmToMlirConverter.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2023 Magnus Sjalander <work@sjalander.com>
3  * See COPYING for terms of redistribution.
4  */
5 
6 #ifndef JLM_MLIR_BACKEND_JLMTOMLIRCONVERTER_HPP
7 #define JLM_MLIR_BACKEND_JLMTOMLIRCONVERTER_HPP
8 
9 // JLM
16 #include <jlm/rvsdg/gamma.hpp>
17 #include <jlm/rvsdg/theta.hpp>
18 
19 // MLIR RVSDG dialects
20 #include <RVSDG/RVSDGDialect.h>
21 #include <RVSDG/RVSDGPasses.h>
22 
23 // MLIR JLM dialects
24 #include <JLM/JLMDialect.h>
25 #include <JLM/JLMOps.h>
26 
27 // MLIR generic dialects
28 #include <mlir/Dialect/Arith/IR/Arith.h>
29 #include <mlir/Dialect/LLVMIR/LLVMDialect.h>
30 
31 namespace jlm::mlir
32 {
33 
34 class JlmToMlirConverter final
35 {
36 public:
38  : Context_(std::make_unique<::mlir::MLIRContext>())
39  {
40  Context_->getOrLoadDialect<::mlir::rvsdg::RVSDGDialect>();
41  Context_->getOrLoadDialect<::mlir::jlm::JLMDialect>();
42  Context_->getOrLoadDialect<::mlir::arith::ArithDialect>();
43  Context_->getOrLoadDialect<::mlir::LLVM::LLVMDialect>();
44  Builder_ = std::make_unique<::mlir::OpBuilder>(Context_.get());
45  }
46 
48 
50 
52  operator=(const JlmToMlirConverter &) = delete;
53 
56 
62  static void
63  Print(::mlir::rvsdg::OmegaNode & omega, const util::FilePath & filePath);
64 
72  ::mlir::rvsdg::OmegaNode
73  ConvertModule(const llvm::LlvmRvsdgModule & rvsdgModule);
74 
84  ::llvm::SmallVector<::mlir::Value>
85  ConvertRegion(rvsdg::Region & region, ::mlir::Block & block, bool isRoot = false);
86 
93  static ::llvm::SmallVector<::mlir::Value>
95  const rvsdg::Node & node,
96  const std::unordered_map<rvsdg::Output *, ::mlir::Value> & valueMap);
97 
105  ::mlir::Operation *
106  ConvertNode(
107  const rvsdg::Node & node,
108  ::mlir::Block & block,
109  const ::llvm::SmallVector<::mlir::Value> & inputs);
110 
117  ::mlir::Operation *
119  const jlm::llvm::FBinaryOperation & op,
120  ::llvm::SmallVector<::mlir::Value> inputs);
121 
128  ::mlir::Operation *
130  const jlm::llvm::FCmpOperation & op,
131  ::llvm::SmallVector<::mlir::Value> inputs);
132 
139  ::mlir::Operation *
141  const rvsdg::SimpleOperation & bitOp,
142  ::llvm::SmallVector<::mlir::Value> inputs);
143 
150  ::mlir::Operation *
152  const jlm::llvm::IntegerBinaryOperation & operation,
153  ::llvm::SmallVector<::mlir::Value> inputs);
154 
161  ::mlir::Operation *
162  BitCompareNode(const rvsdg::SimpleOperation & bitOp, ::llvm::SmallVector<::mlir::Value> inputs);
163 
170  ::mlir::Operation *
172  const llvm::PtrCmpOperation & pointerCompareOp,
173  ::llvm::SmallVector<::mlir::Value> inputs);
174 
182  ::mlir::Operation *
184  const rvsdg::SimpleNode & node,
185  ::mlir::Block & block,
186  const ::llvm::SmallVector<::mlir::Value> & inputs);
187 
195  ::mlir::Operation *
197  const rvsdg::LambdaNode & node,
198  ::mlir::Block & block,
199  const ::llvm::SmallVector<::mlir::Value> & inputs);
200 
208  ::mlir::Operation *
209  ConvertGamma(
210  const rvsdg::GammaNode & gammaNode,
211  ::mlir::Block & block,
212  const ::llvm::SmallVector<::mlir::Value> & inputs);
213 
214  ::mlir::Operation *
215  ConvertTheta(
216  const rvsdg::ThetaNode & thetaNode,
217  ::mlir::Block & block,
218  const ::llvm::SmallVector<::mlir::Value> & inputs);
219 
227  ::mlir::Operation *
228  ConvertDelta(
229  const rvsdg::DeltaNode & node,
230  ::mlir::Block & block,
231  const ::llvm::SmallVector<::mlir::Value> & inputs);
232 
238  ::mlir::FloatType
239  ConvertFPType(const llvm::fpsize size);
240 
246  ::mlir::FunctionType
247  ConvertFunctionType(const jlm::rvsdg::FunctionType & functionType);
248 
254  ::mlir::Type
255  ConvertType(const rvsdg::Type & type);
256 
262  ::llvm::SmallVector<::mlir::Type>
263  GetMemStateRange(size_t nresults);
264 
265  std::unique_ptr<::mlir::OpBuilder> Builder_;
266  std::unique_ptr<::mlir::MLIRContext> Context_;
267 };
268 
269 } // namespace jlm::mlir
270 
271 #endif // JLM_MLIR_BACKEND_JLMTOMLIRCONVERTER_HPP
::mlir::Operation * ConvertDelta(const rvsdg::DeltaNode &node, ::mlir::Block &block, const ::llvm::SmallVector<::mlir::Value > &inputs)
::llvm::SmallVector<::mlir::Value > ConvertRegion(rvsdg::Region &region, ::mlir::Block &block, bool isRoot=false)
::mlir::FloatType ConvertFPType(const llvm::fpsize size)
::mlir::FunctionType ConvertFunctionType(const jlm::rvsdg::FunctionType &functionType)
::mlir::Operation * ConvertTheta(const rvsdg::ThetaNode &thetaNode, ::mlir::Block &block, const ::llvm::SmallVector<::mlir::Value > &inputs)
JlmToMlirConverter(const JlmToMlirConverter &)=delete
::mlir::Type ConvertType(const rvsdg::Type &type)
::mlir::Operation * ConvertNode(const rvsdg::Node &node, ::mlir::Block &block, const ::llvm::SmallVector<::mlir::Value > &inputs)
::mlir::Operation * BitCompareNode(const rvsdg::SimpleOperation &bitOp, ::llvm::SmallVector<::mlir::Value > inputs)
::llvm::SmallVector<::mlir::Type > GetMemStateRange(size_t nresults)
::mlir::Operation * ConvertPointerCompareNode(const llvm::PtrCmpOperation &pointerCompareOp, ::llvm::SmallVector<::mlir::Value > inputs)
JlmToMlirConverter & operator=(JlmToMlirConverter &&)=delete
std::unique_ptr<::mlir::MLIRContext > Context_
::mlir::Operation * ConvertGamma(const rvsdg::GammaNode &gammaNode, ::mlir::Block &block, const ::llvm::SmallVector<::mlir::Value > &inputs)
static void Print(::mlir::rvsdg::OmegaNode &omega, const util::FilePath &filePath)
static ::llvm::SmallVector<::mlir::Value > GetConvertedInputs(const rvsdg::Node &node, const std::unordered_map< rvsdg::Output *, ::mlir::Value > &valueMap)
::mlir::Operation * ConvertFpBinaryNode(const jlm::llvm::FBinaryOperation &op, ::llvm::SmallVector<::mlir::Value > inputs)
JlmToMlirConverter & operator=(const JlmToMlirConverter &)=delete
::mlir::Operation * ConvertLambda(const rvsdg::LambdaNode &node, ::mlir::Block &block, const ::llvm::SmallVector<::mlir::Value > &inputs)
::mlir::Operation * ConvertIntegerBinaryOperation(const jlm::llvm::IntegerBinaryOperation &operation, ::llvm::SmallVector<::mlir::Value > inputs)
::mlir::Operation * ConvertBitBinaryNode(const rvsdg::SimpleOperation &bitOp, ::llvm::SmallVector<::mlir::Value > inputs)
::mlir::Operation * ConvertSimpleNode(const rvsdg::SimpleNode &node, ::mlir::Block &block, const ::llvm::SmallVector<::mlir::Value > &inputs)
::mlir::rvsdg::OmegaNode ConvertModule(const llvm::LlvmRvsdgModule &rvsdgModule)
std::unique_ptr<::mlir::OpBuilder > Builder_
::mlir::Operation * ConvertFpCompareNode(const jlm::llvm::FCmpOperation &op, ::llvm::SmallVector<::mlir::Value > inputs)
JlmToMlirConverter(JlmToMlirConverter &&)=delete
Delta node.
Definition: delta.hpp:129
Function type class.
Conditional operator / pattern matching.
Definition: gamma.hpp:99
Lambda node.
Definition: lambda.hpp:83
Represent acyclic RVSDG subgraphs.
Definition: region.hpp:213
static std::string type(const Node *n)
Definition: view.cpp:255