MLIR  20.0.0git
ModuleTranslation.h
Go to the documentation of this file.
1 //===- ModuleTranslation.h - MLIR to LLVM conversion ------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements the translation between an MLIR LLVM dialect module and
10 // the corresponding LLVMIR module. It only handles core LLVM IR operations.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef MLIR_TARGET_LLVMIR_MODULETRANSLATION_H
15 #define MLIR_TARGET_LLVMIR_MODULETRANSLATION_H
16 
18 #include "mlir/IR/Operation.h"
19 #include "mlir/IR/SymbolTable.h"
20 #include "mlir/IR/Value.h"
24 
25 #include "llvm/ADT/SetVector.h"
26 #include "llvm/Frontend/OpenMP/OMPIRBuilder.h"
27 
28 namespace llvm {
29 class BasicBlock;
30 class IRBuilderBase;
31 class Function;
32 class Value;
33 } // namespace llvm
34 
35 namespace mlir {
36 class Attribute;
37 class Block;
38 class Location;
39 
40 namespace LLVM {
41 
42 namespace detail {
43 class DebugTranslation;
44 class LoopAnnotationTranslation;
45 } // namespace detail
46 
47 class AliasScopeAttr;
48 class AliasScopeDomainAttr;
49 class DINodeAttr;
50 class LLVMFuncOp;
51 class ComdatSelectorOp;
52 
53 /// Implementation class for module translation. Holds a reference to the module
54 /// being translated, and the mappings between the original and the translated
55 /// functions, basic blocks and values. It is practically easier to hold these
56 /// mappings in one class since the conversion of control flow operations
57 /// needs to look up block and function mappings.
59  friend std::unique_ptr<llvm::Module>
60  mlir::translateModuleToLLVMIR(Operation *, llvm::LLVMContext &, StringRef,
61  bool);
62 
63 public:
64  /// Stores the mapping between a function name and its LLVM IR representation.
65  void mapFunction(StringRef name, llvm::Function *func) {
66  auto result = functionMapping.try_emplace(name, func);
67  (void)result;
68  assert(result.second &&
69  "attempting to map a function that is already mapped");
70  }
71 
72  /// Finds an LLVM IR function by its name.
73  llvm::Function *lookupFunction(StringRef name) const {
74  return functionMapping.lookup(name);
75  }
76 
77  /// Stores the mapping between an MLIR value and its LLVM IR counterpart.
78  void mapValue(Value mlir, llvm::Value *llvm) { mapValue(mlir) = llvm; }
79 
80  /// Provides write-once access to store the LLVM IR value corresponding to the
81  /// given MLIR value.
82  llvm::Value *&mapValue(Value value) {
83  llvm::Value *&llvm = valueMapping[value];
84  assert(llvm == nullptr &&
85  "attempting to map a value that is already mapped");
86  return llvm;
87  }
88 
89  /// Finds an LLVM IR value corresponding to the given MLIR value.
90  llvm::Value *lookupValue(Value value) const {
91  return valueMapping.lookup(value);
92  }
93 
94  /// Looks up remapped a list of remapped values.
96 
97  /// Stores the mapping between an MLIR block and LLVM IR basic block.
98  void mapBlock(Block *mlir, llvm::BasicBlock *llvm) {
99  auto result = blockMapping.try_emplace(mlir, llvm);
100  (void)result;
101  assert(result.second && "attempting to map a block that is already mapped");
102  }
103 
104  /// Finds an LLVM IR basic block that corresponds to the given MLIR block.
105  llvm::BasicBlock *lookupBlock(Block *block) const {
106  return blockMapping.lookup(block);
107  }
108 
109  /// Stores the mapping between an MLIR operation with successors and a
110  /// corresponding LLVM IR instruction.
111  void mapBranch(Operation *mlir, llvm::Instruction *llvm) {
112  auto result = branchMapping.try_emplace(mlir, llvm);
113  (void)result;
114  assert(result.second &&
115  "attempting to map a branch that is already mapped");
116  }
117 
118  /// Finds an LLVM IR instruction that corresponds to the given MLIR operation
119  /// with successors.
120  llvm::Instruction *lookupBranch(Operation *op) const {
121  return branchMapping.lookup(op);
122  }
123 
124  /// Stores a mapping between an MLIR call operation and a corresponding LLVM
125  /// call instruction.
126  void mapCall(Operation *mlir, llvm::CallInst *llvm) {
127  auto result = callMapping.try_emplace(mlir, llvm);
128  (void)result;
129  assert(result.second && "attempting to map a call that is already mapped");
130  }
131 
132  /// Finds an LLVM call instruction that corresponds to the given MLIR call
133  /// operation.
134  llvm::CallInst *lookupCall(Operation *op) const {
135  return callMapping.lookup(op);
136  }
137 
138  /// Removes the mapping for blocks contained in the region and values defined
139  /// in these blocks.
140  void forgetMapping(Region &region);
141 
142  /// Returns the LLVM metadata corresponding to a mlir LLVM dialect alias scope
143  /// attribute. Creates the metadata node if it has not been converted before.
144  llvm::MDNode *getOrCreateAliasScope(AliasScopeAttr aliasScopeAttr);
145 
146  /// Returns the LLVM metadata corresponding to an array of mlir LLVM dialect
147  /// alias scope attributes. Creates the metadata nodes if they have not been
148  /// converted before.
149  llvm::MDNode *
151 
152  // Sets LLVM metadata for memory operations that are in a parallel loop.
153  void setAccessGroupsMetadata(AccessGroupOpInterface op,
154  llvm::Instruction *inst);
155 
156  // Sets LLVM metadata for memory operations that have alias scope information.
157  void setAliasScopeMetadata(AliasAnalysisOpInterface op,
158  llvm::Instruction *inst);
159 
160  /// Sets LLVM TBAA metadata for memory operations that have TBAA attributes.
161  void setTBAAMetadata(AliasAnalysisOpInterface op, llvm::Instruction *inst);
162 
163  /// Sets LLVM profiling metadata for operations that have branch weights.
164  void setBranchWeightsMetadata(BranchWeightOpInterface op);
165 
166  /// Sets LLVM loop metadata for branch operations that have a loop annotation
167  /// attribute.
168  void setLoopMetadata(Operation *op, llvm::Instruction *inst);
169 
170  /// Converts the type from MLIR LLVM dialect to LLVM.
171  llvm::Type *convertType(Type type);
172 
173  /// Returns the MLIR context of the module being translated.
174  MLIRContext &getContext() { return *mlirModule->getContext(); }
175 
176  /// Returns the LLVM context in which the IR is being constructed.
177  llvm::LLVMContext &getLLVMContext() const { return llvmModule->getContext(); }
178 
179  /// Finds an LLVM IR global value that corresponds to the given MLIR operation
180  /// defining a global value.
181  llvm::GlobalValue *lookupGlobal(Operation *op) {
182  return globalsMapping.lookup(op);
183  }
184 
185  /// Returns the OpenMP IR builder associated with the LLVM IR module being
186  /// constructed.
187  llvm::OpenMPIRBuilder *getOpenMPBuilder();
188 
189  /// Returns the LLVM module in which the IR is being constructed.
190  llvm::Module *getLLVMModule() { return llvmModule.get(); }
191 
192  /// Translates the given location.
193  llvm::DILocation *translateLoc(Location loc, llvm::DILocalScope *scope);
194 
195  /// Translates the given LLVM DWARF expression metadata.
196  llvm::DIExpression *translateExpression(LLVM::DIExpressionAttr attr);
197 
198  /// Translates the given LLVM global variable expression metadata.
199  llvm::DIGlobalVariableExpression *
200  translateGlobalVariableExpression(LLVM::DIGlobalVariableExpressionAttr attr);
201 
202  /// Translates the given LLVM debug info metadata.
203  llvm::Metadata *translateDebugInfo(LLVM::DINodeAttr attr);
204 
205  /// Translates the given LLVM rounding mode metadata.
206  llvm::RoundingMode translateRoundingMode(LLVM::RoundingMode rounding);
207 
208  /// Translates the given LLVM FP exception behavior metadata.
209  llvm::fp::ExceptionBehavior
210  translateFPExceptionBehavior(LLVM::FPExceptionBehavior exceptionBehavior);
211 
212  /// Translates the contents of the given block to LLVM IR using this
213  /// translator. The LLVM IR basic block corresponding to the given block is
214  /// expected to exist in the mapping of this translator. Uses `builder` to
215  /// translate the IR, leaving it at the end of the block. If `ignoreArguments`
216  /// is set, does not produce PHI nodes for the block arguments. Otherwise, the
217  /// PHI nodes are constructed for block arguments but are _not_ connected to
218  /// the predecessors that may not exist yet.
219  LogicalResult convertBlock(Block &bb, bool ignoreArguments,
220  llvm::IRBuilderBase &builder) {
221  return convertBlockImpl(bb, ignoreArguments, builder,
222  /*recordInsertions=*/false);
223  }
224 
225  /// Gets the named metadata in the LLVM IR module being constructed, creating
226  /// it if it does not exist.
227  llvm::NamedMDNode *getOrInsertNamedModuleMetadata(StringRef name);
228 
229  /// Common CRTP base class for ModuleTranslation stack frames.
230  class StackFrame {
231  public:
232  virtual ~StackFrame() = default;
233  TypeID getTypeID() const { return typeID; }
234 
235  protected:
236  explicit StackFrame(TypeID typeID) : typeID(typeID) {}
237 
238  private:
239  const TypeID typeID;
240  virtual void anchor();
241  };
242 
243  /// Concrete CRTP base class for ModuleTranslation stack frames. When
244  /// translating operations with regions, users of ModuleTranslation can store
245  /// state on ModuleTranslation stack before entering the region and inspect
246  /// it when converting operations nested within that region. Users are
247  /// expected to derive this class and put any relevant information into fields
248  /// of the derived class. The usual isa/dyn_cast functionality is available
249  /// for instances of derived classes.
250  template <typename Derived>
251  class StackFrameBase : public StackFrame {
252  public:
253  explicit StackFrameBase() : StackFrame(TypeID::get<Derived>()) {}
254  };
255 
256  /// Creates a stack frame of type `T` on ModuleTranslation stack. `T` must
257  /// be derived from `StackFrameBase<T>` and constructible from the provided
258  /// arguments. Doing this before entering the region of the op being
259  /// translated makes the frame available when translating ops within that
260  /// region.
261  template <typename T, typename... Args>
262  void stackPush(Args &&...args) {
263  static_assert(
264  std::is_base_of<StackFrame, T>::value,
265  "can only push instances of StackFrame on ModuleTranslation stack");
266  stack.push_back(std::make_unique<T>(std::forward<Args>(args)...));
267  }
268 
269  /// Pops the last element from the ModuleTranslation stack.
270  void stackPop() { stack.pop_back(); }
271 
272  /// Calls `callback` for every ModuleTranslation stack frame of type `T`
273  /// starting from the top of the stack.
274  template <typename T>
275  WalkResult
276  stackWalk(llvm::function_ref<WalkResult(const T &)> callback) const {
277  static_assert(std::is_base_of<StackFrame, T>::value,
278  "expected T derived from StackFrame");
279  if (!callback)
280  return WalkResult::skip();
281  for (const std::unique_ptr<StackFrame> &frame : llvm::reverse(stack)) {
282  if (T *ptr = dyn_cast_or_null<T>(frame.get())) {
283  WalkResult result = callback(*ptr);
284  if (result.wasInterrupted())
285  return result;
286  }
287  }
288  return WalkResult::advance();
289  }
290 
291  /// RAII object calling stackPush/stackPop on construction/destruction.
292  template <typename T>
293  struct SaveStack {
294  template <typename... Args>
295  explicit SaveStack(ModuleTranslation &m, Args &&...args)
296  : moduleTranslation(m) {
297  moduleTranslation.stackPush<T>(std::forward<Args>(args)...);
298  }
299  ~SaveStack() { moduleTranslation.stackPop(); }
300 
301  private:
302  ModuleTranslation &moduleTranslation;
303  };
304 
305  SymbolTableCollection &symbolTable() { return symbolTableCollection; }
306 
307 private:
309  std::unique_ptr<llvm::Module> llvmModule);
311 
312  /// Converts individual components.
313  LogicalResult convertOperation(Operation &op, llvm::IRBuilderBase &builder,
314  bool recordInsertions = false);
315  LogicalResult convertFunctionSignatures();
316  LogicalResult convertFunctions();
317  LogicalResult convertComdats();
318  LogicalResult convertGlobals();
319  LogicalResult convertOneFunction(LLVMFuncOp func);
320  LogicalResult convertBlockImpl(Block &bb, bool ignoreArguments,
321  llvm::IRBuilderBase &builder,
322  bool recordInsertions);
323 
324  /// Returns the LLVM metadata corresponding to the given mlir LLVM dialect
325  /// TBAATagAttr.
326  llvm::MDNode *getTBAANode(TBAATagAttr tbaaAttr) const;
327 
328  /// Process tbaa LLVM Metadata operations and create LLVM
329  /// metadata nodes for them.
330  LogicalResult createTBAAMetadata();
331 
332  /// Translates dialect attributes attached to the given operation.
333  LogicalResult
334  convertDialectAttributes(Operation *op,
335  ArrayRef<llvm::Instruction *> instructions);
336 
337  /// Translates parameter attributes and adds them to the returned AttrBuilder.
338  /// Returns failure if any of the translations failed.
339  FailureOr<llvm::AttrBuilder>
340  convertParameterAttrs(LLVMFuncOp func, int argIdx, DictionaryAttr paramAttrs);
341 
342  /// Original and translated module.
343  Operation *mlirModule;
344  std::unique_ptr<llvm::Module> llvmModule;
345  /// A converter for translating debug information.
346  std::unique_ptr<detail::DebugTranslation> debugTranslation;
347 
348  /// A converter for translating loop annotations.
349  std::unique_ptr<detail::LoopAnnotationTranslation> loopAnnotationTranslation;
350 
351  /// Builder for LLVM IR generation of OpenMP constructs.
352  std::unique_ptr<llvm::OpenMPIRBuilder> ompBuilder;
353 
354  /// Mappings between llvm.mlir.global definitions and corresponding globals.
356 
357  /// A stateful object used to translate types.
358  TypeToLLVMIRTranslator typeTranslator;
359 
360  /// A dialect interface collection used for dispatching the translation to
361  /// specific dialects.
363 
364  /// Mappings between original and translated values, used for lookups.
365  llvm::StringMap<llvm::Function *> functionMapping;
366  DenseMap<Value, llvm::Value *> valueMapping;
368 
369  /// A mapping between MLIR LLVM dialect terminators and LLVM IR terminators
370  /// they are converted to. This allows for connecting PHI nodes to the source
371  /// values after all operations are converted.
373 
374  /// A mapping between MLIR LLVM dialect call operations and LLVM IR call
375  /// instructions. This allows for adding branch weights after the operations
376  /// have been converted.
378 
379  /// Mapping from an alias scope attribute to its LLVM metadata.
380  /// This map is populated lazily.
381  DenseMap<AliasScopeAttr, llvm::MDNode *> aliasScopeMetadataMapping;
382 
383  /// Mapping from an alias scope domain attribute to its LLVM metadata.
384  /// This map is populated lazily.
385  DenseMap<AliasScopeDomainAttr, llvm::MDNode *> aliasDomainMetadataMapping;
386 
387  /// Mapping from a tbaa attribute to its LLVM metadata.
388  /// This map is populated on module entry.
389  DenseMap<Attribute, llvm::MDNode *> tbaaMetadataMapping;
390 
391  /// Mapping from a comdat selector operation to its LLVM comdat struct.
392  /// This map is populated on module entry.
394 
395  /// Stack of user-specified state elements, useful when translating operations
396  /// with regions.
398 
399  /// A cache for the symbol tables constructed during symbols lookup.
400  SymbolTableCollection symbolTableCollection;
401 };
402 
403 namespace detail {
404 /// For all blocks in the region that were converted to LLVM IR using the given
405 /// ModuleTranslation, connect the PHI nodes of the corresponding LLVM IR blocks
406 /// to the results of preceding blocks.
407 void connectPHINodes(Region &region, const ModuleTranslation &state);
408 
409 /// Create an LLVM IR constant of `llvmType` from the MLIR attribute `attr`.
410 /// This currently supports integer, floating point, splat and dense element
411 /// attributes and combinations thereof. Also, an array attribute with two
412 /// elements is supported to represent a complex constant. In case of error,
413 /// report it to `loc` and return nullptr.
414 llvm::Constant *getLLVMConstant(llvm::Type *llvmType, Attribute attr,
415  Location loc,
416  const ModuleTranslation &moduleTranslation);
417 
418 /// Creates a call to an LLVM IR intrinsic function with the given arguments.
419 llvm::CallInst *createIntrinsicCall(llvm::IRBuilderBase &builder,
420  llvm::Intrinsic::ID intrinsic,
421  ArrayRef<llvm::Value *> args = {},
422  ArrayRef<llvm::Type *> tys = {});
423 
424 /// Creates a call to a LLVM IR intrinsic defined by LLVM_IntrOpBase. This
425 /// resolves the overloads, and maps mixed MLIR value and attribute arguments to
426 /// LLVM values.
427 llvm::CallInst *createIntrinsicCall(
428  llvm::IRBuilderBase &builder, ModuleTranslation &moduleTranslation,
429  Operation *intrOp, llvm::Intrinsic::ID intrinsic, unsigned numResults,
430  ArrayRef<unsigned> overloadedResults, ArrayRef<unsigned> overloadedOperands,
431  ArrayRef<unsigned> immArgPositions,
432  ArrayRef<StringLiteral> immArgAttrNames);
433 
434 } // namespace detail
435 
436 } // namespace LLVM
437 } // namespace mlir
438 
439 namespace llvm {
440 template <typename T>
442  static inline bool
443  doit(const ::mlir::LLVM::ModuleTranslation::StackFrame &frame) {
444  return frame.getTypeID() == ::mlir::TypeID::get<T>();
445  }
446 };
447 } // namespace llvm
448 
449 #endif // MLIR_TARGET_LLVMIR_MODULETRANSLATION_H
Attributes are known-constant values of operations.
Definition: Attributes.h:25
Block represents an ordered list of Operations.
Definition: Block.h:31
Interface collection for translation to LLVM IR, dispatches to a concrete interface implementation ba...
This class represents the base attribute for all debug info attributes.
Definition: LLVMAttrs.h:27
Concrete CRTP base class for ModuleTranslation stack frames.
Common CRTP base class for ModuleTranslation stack frames.
Implementation class for module translation.
llvm::fp::ExceptionBehavior translateFPExceptionBehavior(LLVM::FPExceptionBehavior exceptionBehavior)
Translates the given LLVM FP exception behavior metadata.
llvm::Value * lookupValue(Value value) const
Finds an LLVM IR value corresponding to the given MLIR value.
void mapCall(Operation *mlir, llvm::CallInst *llvm)
Stores a mapping between an MLIR call operation and a corresponding LLVM call instruction.
llvm::DIGlobalVariableExpression * translateGlobalVariableExpression(LLVM::DIGlobalVariableExpressionAttr attr)
Translates the given LLVM global variable expression metadata.
llvm::Value *& mapValue(Value value)
Provides write-once access to store the LLVM IR value corresponding to the given MLIR value.
void stackPush(Args &&...args)
Creates a stack frame of type T on ModuleTranslation stack.
llvm::NamedMDNode * getOrInsertNamedModuleMetadata(StringRef name)
Gets the named metadata in the LLVM IR module being constructed, creating it if it does not exist.
LogicalResult convertBlock(Block &bb, bool ignoreArguments, llvm::IRBuilderBase &builder)
Translates the contents of the given block to LLVM IR using this translator.
void mapBranch(Operation *mlir, llvm::Instruction *llvm)
Stores the mapping between an MLIR operation with successors and a corresponding LLVM IR instruction.
llvm::Instruction * lookupBranch(Operation *op) const
Finds an LLVM IR instruction that corresponds to the given MLIR operation with successors.
SmallVector< llvm::Value * > lookupValues(ValueRange values)
Looks up remapped a list of remapped values.
void mapFunction(StringRef name, llvm::Function *func)
Stores the mapping between a function name and its LLVM IR representation.
llvm::DILocation * translateLoc(Location loc, llvm::DILocalScope *scope)
Translates the given location.
llvm::BasicBlock * lookupBlock(Block *block) const
Finds an LLVM IR basic block that corresponds to the given MLIR block.
SymbolTableCollection & symbolTable()
void setBranchWeightsMetadata(BranchWeightOpInterface op)
Sets LLVM profiling metadata for operations that have branch weights.
llvm::Type * convertType(Type type)
Converts the type from MLIR LLVM dialect to LLVM.
llvm::RoundingMode translateRoundingMode(LLVM::RoundingMode rounding)
Translates the given LLVM rounding mode metadata.
void setTBAAMetadata(AliasAnalysisOpInterface op, llvm::Instruction *inst)
Sets LLVM TBAA metadata for memory operations that have TBAA attributes.
llvm::DIExpression * translateExpression(LLVM::DIExpressionAttr attr)
Translates the given LLVM DWARF expression metadata.
llvm::OpenMPIRBuilder * getOpenMPBuilder()
Returns the OpenMP IR builder associated with the LLVM IR module being constructed.
llvm::CallInst * lookupCall(Operation *op) const
Finds an LLVM call instruction that corresponds to the given MLIR call operation.
llvm::Metadata * translateDebugInfo(LLVM::DINodeAttr attr)
Translates the given LLVM debug info metadata.
llvm::LLVMContext & getLLVMContext() const
Returns the LLVM context in which the IR is being constructed.
llvm::GlobalValue * lookupGlobal(Operation *op)
Finds an LLVM IR global value that corresponds to the given MLIR operation defining a global value.
llvm::Module * getLLVMModule()
Returns the LLVM module in which the IR is being constructed.
llvm::Function * lookupFunction(StringRef name) const
Finds an LLVM IR function by its name.
llvm::MDNode * getOrCreateAliasScopes(ArrayRef< AliasScopeAttr > aliasScopeAttrs)
Returns the LLVM metadata corresponding to an array of mlir LLVM dialect alias scope attributes.
void mapBlock(Block *mlir, llvm::BasicBlock *llvm)
Stores the mapping between an MLIR block and LLVM IR basic block.
llvm::MDNode * getOrCreateAliasScope(AliasScopeAttr aliasScopeAttr)
Returns the LLVM metadata corresponding to a mlir LLVM dialect alias scope attribute.
WalkResult stackWalk(llvm::function_ref< WalkResult(const T &)> callback) const
Calls callback for every ModuleTranslation stack frame of type T starting from the top of the stack.
void stackPop()
Pops the last element from the ModuleTranslation stack.
void forgetMapping(Region &region)
Removes the mapping for blocks contained in the region and values defined in these blocks.
void setAliasScopeMetadata(AliasAnalysisOpInterface op, llvm::Instruction *inst)
void setAccessGroupsMetadata(AccessGroupOpInterface op, llvm::Instruction *inst)
MLIRContext & getContext()
Returns the MLIR context of the module being translated.
void mapValue(Value mlir, llvm::Value *llvm)
Stores the mapping between an MLIR value and its LLVM IR counterpart.
void setLoopMetadata(Operation *op, llvm::Instruction *inst)
Sets LLVM loop metadata for branch operations that have a loop annotation attribute.
Utility class to translate MLIR LLVM dialect types to LLVM IR.
Definition: TypeToLLVM.h:39
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
Definition: Location.h:63
MLIRContext is the top-level object for a collection of MLIR operations.
Definition: MLIRContext.h:60
Operation is the basic unit of execution within MLIR.
Definition: Operation.h:88
MLIRContext * getContext()
Return the context this operation is associated with.
Definition: Operation.h:216
This class contains a list of basic blocks and a link to the parent operation it is attached to.
Definition: Region.h:26
This class represents a collection of SymbolTables.
Definition: SymbolTable.h:283
This class provides an efficient unique identifier for a specific C++ type.
Definition: TypeID.h:104
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
Definition: Types.h:74
This class provides an abstraction over the different types of ranges over Values.
Definition: ValueRange.h:381
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Definition: Value.h:96
A utility result that is used to signal how to proceed with an ongoing walk:
Definition: Visitors.h:33
static WalkResult skip()
Definition: Visitors.h:52
static WalkResult advance()
Definition: Visitors.h:51
bool wasInterrupted() const
Returns true if the walk was interrupted.
Definition: Visitors.h:55
Include the generated interface declarations.
Definition: CallGraph.h:229
void connectPHINodes(Region &region, const ModuleTranslation &state)
For all blocks in the region that were converted to LLVM IR using the given ModuleTranslation,...
llvm::CallInst * createIntrinsicCall(llvm::IRBuilderBase &builder, llvm::Intrinsic::ID intrinsic, ArrayRef< llvm::Value * > args={}, ArrayRef< llvm::Type * > tys={})
Creates a call to an LLVM IR intrinsic function with the given arguments.
llvm::Constant * getLLVMConstant(llvm::Type *llvmType, Attribute attr, Location loc, const ModuleTranslation &moduleTranslation)
Create an LLVM IR constant of llvmType from the MLIR attribute attr.
Include the generated interface declarations.
std::unique_ptr< llvm::Module > translateModuleToLLVMIR(Operation *module, llvm::LLVMContext &llvmContext, llvm::StringRef name="LLVMDialectModule", bool disableVerification=false)
Translates a given LLVM dialect module into an LLVM IR module living in the given context.
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...
static bool doit(const ::mlir::LLVM::ModuleTranslation::StackFrame &frame)
RAII object calling stackPush/stackPop on construction/destruction.
SaveStack(ModuleTranslation &m, Args &&...args)