22
22
#include " mlir/Target/LLVMIR/LLVMTranslationInterface.h"
23
23
#include " mlir/Target/LLVMIR/TypeTranslation.h"
24
24
25
+ #include " llvm/ADT/SetVector.h"
25
26
#include " llvm/Frontend/OpenMP/OMPIRBuilder.h"
26
27
#include " llvm/IR/BasicBlock.h"
27
28
#include " llvm/IR/Function.h"
@@ -160,6 +161,29 @@ class ModuleTranslation {
160
161
return globalsMapping.lookup (op);
161
162
}
162
163
164
+ // / Returns the OpenMP IR builder associated with the LLVM IR module being
165
+ // / constructed.
166
+ llvm::OpenMPIRBuilder *getOpenMPBuilder () {
167
+ if (!ompBuilder) {
168
+ ompBuilder = std::make_unique<llvm::OpenMPIRBuilder>(*llvmModule);
169
+ ompBuilder->initialize ();
170
+ }
171
+ return ompBuilder.get ();
172
+ }
173
+
174
+ // / Translates the given location.
175
+ const llvm::DILocation *translateLoc (Location loc, llvm::DILocalScope *scope);
176
+
177
+ // / Translates the contents of the given block to LLVM IR using this
178
+ // / translator. The LLVM IR basic block corresponding to the given block is
179
+ // / expected to exist in the mapping of this translator. Uses `builder` to
180
+ // / translate the IR, leaving it at the end of the block. If `ignoreArguments`
181
+ // / is set, does not produce PHI nodes for the block arguments. Otherwise, the
182
+ // / PHI nodes are constructed for block arguments but are _not_ connected to
183
+ // / the predecessors that may not exist yet.
184
+ LogicalResult convertBlock (Block &bb, bool ignoreArguments,
185
+ llvm::IRBuilder<> &builder);
186
+
163
187
protected:
164
188
// / Translate the given MLIR module expressed in MLIR LLVM IR dialect into an
165
189
// / LLVM IR module. The MLIR LLVM IR dialect holds a pointer to an
@@ -170,19 +194,6 @@ class ModuleTranslation {
170
194
171
195
virtual LogicalResult convertOperation (Operation &op,
172
196
llvm::IRBuilder<> &builder);
173
- virtual LogicalResult convertOmpOperation (Operation &op,
174
- llvm::IRBuilder<> &builder);
175
- virtual LogicalResult convertOmpParallel (Operation &op,
176
- llvm::IRBuilder<> &builder);
177
- virtual LogicalResult convertOmpMaster (Operation &op,
178
- llvm::IRBuilder<> &builder);
179
- void convertOmpOpRegions (Region ®ion, StringRef blockName,
180
- llvm::BasicBlock &sourceBlock,
181
- llvm::BasicBlock &continuationBlock,
182
- llvm::IRBuilder<> &builder,
183
- LogicalResult &bodyGenStatus);
184
- virtual LogicalResult convertOmpWsLoop (Operation &opInst,
185
- llvm::IRBuilder<> &builder);
186
197
187
198
static std::unique_ptr<llvm::Module>
188
199
prepareLLVMModule (Operation *m, llvm::LLVMContext &llvmContext,
@@ -196,8 +207,6 @@ class ModuleTranslation {
196
207
LogicalResult convertFunctions ();
197
208
LogicalResult convertGlobals ();
198
209
LogicalResult convertOneFunction (LLVMFuncOp func);
199
- LogicalResult convertBlock (Block &bb, bool ignoreArguments,
200
- llvm::IRBuilder<> &builder);
201
210
202
211
// / Original and translated module.
203
212
Operation *mlirModule;
@@ -232,6 +241,16 @@ class ModuleTranslation {
232
241
DenseMap<Operation *, llvm::Instruction *> branchMapping;
233
242
};
234
243
244
+ namespace detail {
245
+ // / For all blocks in the region that were converted to LLVM IR using the given
246
+ // / ModuleTranslation, connect the PHI nodes of the corresponding LLVM IR blocks
247
+ // / to the results of preceding blocks.
248
+ void connectPHINodes (Region ®ion, const ModuleTranslation &state);
249
+
250
+ // / Get a topologically sorted list of blocks of the given region.
251
+ llvm::SetVector<Block *> getTopologicallySortedBlocks (Region ®ion);
252
+ } // namespace detail
253
+
235
254
} // namespace LLVM
236
255
} // namespace mlir
237
256
0 commit comments