MLIR  21.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"
25 
26 #include "llvm/ADT/SetVector.h"
27 #include "llvm/IR/FPEnv.h"
28 
29 namespace llvm {
30 class BasicBlock;
31 class Function;
32 class IRBuilderBase;
33 class OpenMPIRBuilder;
34 class Value;
35 } // namespace llvm
36 
37 namespace mlir {
38 class Attribute;
39 class Block;
40 class Location;
41 
42 namespace LLVM {
43 
44 namespace detail {
45 class DebugTranslation;
46 class LoopAnnotationTranslation;
47 } // namespace detail
48 
49 class AliasScopeAttr;
50 class AliasScopeDomainAttr;
51 class DINodeAttr;
52 class LLVMFuncOp;
53 class ComdatSelectorOp;
54 
55 /// Implementation class for module translation. Holds a reference to the module
56 /// being translated, and the mappings between the original and the translated
57 /// functions, basic blocks and values. It is practically easier to hold these
58 /// mappings in one class since the conversion of control flow operations
59 /// needs to look up block and function mappings.
61  friend std::unique_ptr<llvm::Module>
62  mlir::translateModuleToLLVMIR(Operation *, llvm::LLVMContext &, StringRef,
63  bool);
64 
65 public:
66  /// Stores the mapping between a function name and its LLVM IR representation.
67  void mapFunction(StringRef name, llvm::Function *func) {
68  auto result = functionMapping.try_emplace(name, func);
69  (void)result;
70  assert(result.second &&
71  "attempting to map a function that is already mapped");
72  }
73 
74  /// Finds an LLVM IR function by its name.
75  llvm::Function *lookupFunction(StringRef name) const {
76  return functionMapping.lookup(name);
77  }
78 
79  /// Stores the mapping between an MLIR value and its LLVM IR counterpart.
80  void mapValue(Value mlir, llvm::Value *llvm) { mapValue(mlir) = llvm; }
81 
82  /// Provides write-once access to store the LLVM IR value corresponding to the
83  /// given MLIR value.
84  llvm::Value *&mapValue(Value value) {
85  llvm::Value *&llvm = valueMapping[value];
86  assert(llvm == nullptr &&
87  "attempting to map a value that is already mapped");
88  return llvm;
89  }
90 
91  /// Finds an LLVM IR value corresponding to the given MLIR value.
92  llvm::Value *lookupValue(Value value) const {
93  return valueMapping.lookup(value);
94  }
95 
96  /// Looks up remapped a list of remapped values.
98 
99  /// Stores the mapping between an MLIR block and LLVM IR basic block.
100  void mapBlock(Block *mlir, llvm::BasicBlock *llvm) {
101  auto result = blockMapping.try_emplace(mlir, llvm);
102  (void)result;
103  assert(result.second && "attempting to map a block that is already mapped");
104  }
105 
106  /// Finds an LLVM IR basic block that corresponds to the given MLIR block.
107  llvm::BasicBlock *lookupBlock(Block *block) const {
108  return blockMapping.lookup(block);
109  }
110 
111  /// Stores the mapping between an MLIR operation with successors and a
112  /// corresponding LLVM IR instruction.
113  void mapBranch(Operation *mlir, llvm::Instruction *llvm) {
114  auto result = branchMapping.try_emplace(mlir, llvm);
115  (void)result;
116  assert(result.second &&
117  "attempting to map a branch that is already mapped");
118  }
119 
120  /// Finds an LLVM IR instruction that corresponds to the given MLIR operation
121  /// with successors.
122  llvm::Instruction *lookupBranch(Operation *op) const {
123  return branchMapping.lookup(op);
124  }
125 
126  /// Stores a mapping between an MLIR call operation and a corresponding LLVM
127  /// call instruction.
128  void mapCall(Operation *mlir, llvm::CallInst *llvm) {
129  auto result = callMapping.try_emplace(mlir, llvm);
130  (void)result;
131  assert(result.second && "attempting to map a call that is already mapped");
132  }
133 
134  /// Finds an LLVM call instruction that corresponds to the given MLIR call
135  /// operation.
136  llvm::CallInst *lookupCall(Operation *op) const {
137  return callMapping.lookup(op);
138  }
139 
140  /// Maps a blockaddress operation to its corresponding placeholder LLVM
141  /// value.
142  void mapUnresolvedBlockAddress(BlockAddressOp op, llvm::Value *cst) {
143  auto result = unresolvedBlockAddressMapping.try_emplace(op, cst);
144  (void)result;
145  assert(result.second &&
146  "attempting to map a blockaddress operation that is already mapped");
147  }
148 
149  /// Maps a BlockAddressAttr to its corresponding LLVM basic block.
150  void mapBlockAddress(BlockAddressAttr attr, llvm::BasicBlock *block) {
151  auto result = blockAddressToLLVMMapping.try_emplace(attr, block);
152  (void)result;
153  assert(result.second &&
154  "attempting to map a blockaddress attribute that is already mapped");
155  }
156 
157  /// Finds the LLVM basic block that corresponds to the given BlockAddressAttr.
158  llvm::BasicBlock *lookupBlockAddress(BlockAddressAttr attr) const {
159  return blockAddressToLLVMMapping.lookup(attr);
160  }
161 
162  /// Removes the mapping for blocks contained in the region and values defined
163  /// in these blocks.
164  void forgetMapping(Region &region);
165 
166  /// Returns the LLVM metadata corresponding to a mlir LLVM dialect alias scope
167  /// attribute. Creates the metadata node if it has not been converted before.
168  llvm::MDNode *getOrCreateAliasScope(AliasScopeAttr aliasScopeAttr);
169 
170  /// Returns the LLVM metadata corresponding to an array of mlir LLVM dialect
171  /// alias scope attributes. Creates the metadata nodes if they have not been
172  /// converted before.
173  llvm::MDNode *
175 
176  // Sets LLVM metadata for memory operations that are in a parallel loop.
177  void setAccessGroupsMetadata(AccessGroupOpInterface op,
178  llvm::Instruction *inst);
179 
180  // Sets LLVM metadata for memory operations that have alias scope information.
181  void setAliasScopeMetadata(AliasAnalysisOpInterface op,
182  llvm::Instruction *inst);
183 
184  /// Sets LLVM TBAA metadata for memory operations that have TBAA attributes.
185  void setTBAAMetadata(AliasAnalysisOpInterface op, llvm::Instruction *inst);
186 
187  /// Sets LLVM dereferenceable metadata for operations that have
188  /// dereferenceable attributes.
189  void setDereferenceableMetadata(DereferenceableOpInterface op,
190  llvm::Instruction *inst);
191 
192  /// Sets LLVM profiling metadata for operations that have branch weights.
193  void setBranchWeightsMetadata(WeightedBranchOpInterface op);
194 
195  /// Sets LLVM loop metadata for branch operations that have a loop annotation
196  /// attribute.
197  void setLoopMetadata(Operation *op, llvm::Instruction *inst);
198 
199  /// Sets the disjoint flag attribute for the exported instruction `value`
200  /// given the original operation `op`. Asserts if the operation does
201  /// not implement the disjoint flag interface, and asserts if the value
202  /// is an instruction that implements the disjoint flag.
203  void setDisjointFlag(Operation *op, llvm::Value *value);
204 
205  /// Converts the type from MLIR LLVM dialect to LLVM.
206  llvm::Type *convertType(Type type);
207 
208  /// Returns the MLIR context of the module being translated.
209  MLIRContext &getContext() { return *mlirModule->getContext(); }
210 
211  /// Returns the LLVM context in which the IR is being constructed.
212  llvm::LLVMContext &getLLVMContext() const { return llvmModule->getContext(); }
213 
214  /// Finds an LLVM IR global value that corresponds to the given MLIR operation
215  /// defining a global value.
216  llvm::GlobalValue *lookupGlobal(Operation *op) {
217  return globalsMapping.lookup(op);
218  }
219 
220  /// Finds an LLVM IR global value that corresponds to the given MLIR operation
221  /// defining a global alias value.
222  llvm::GlobalValue *lookupAlias(Operation *op) {
223  return aliasesMapping.lookup(op);
224  }
225 
226  /// Returns the OpenMP IR builder associated with the LLVM IR module being
227  /// constructed.
228  llvm::OpenMPIRBuilder *getOpenMPBuilder();
229 
230  /// Returns the LLVM module in which the IR is being constructed.
231  llvm::Module *getLLVMModule() { return llvmModule.get(); }
232 
233  /// Translates the given location.
234  llvm::DILocation *translateLoc(Location loc, llvm::DILocalScope *scope);
235 
236  /// Translates the given LLVM DWARF expression metadata.
237  llvm::DIExpression *translateExpression(LLVM::DIExpressionAttr attr);
238 
239  /// Translates the given LLVM global variable expression metadata.
240  llvm::DIGlobalVariableExpression *
241  translateGlobalVariableExpression(LLVM::DIGlobalVariableExpressionAttr attr);
242 
243  /// Translates the given LLVM debug info metadata.
244  llvm::Metadata *translateDebugInfo(LLVM::DINodeAttr attr);
245 
246  /// Translates the given LLVM rounding mode metadata.
247  llvm::RoundingMode translateRoundingMode(LLVM::RoundingMode rounding);
248 
249  /// Translates the given LLVM FP exception behavior metadata.
250  llvm::fp::ExceptionBehavior
251  translateFPExceptionBehavior(LLVM::FPExceptionBehavior exceptionBehavior);
252 
253  /// Translates the contents of the given block to LLVM IR using this
254  /// translator. The LLVM IR basic block corresponding to the given block is
255  /// expected to exist in the mapping of this translator. Uses `builder` to
256  /// translate the IR, leaving it at the end of the block. If `ignoreArguments`
257  /// is set, does not produce PHI nodes for the block arguments. Otherwise, the
258  /// PHI nodes are constructed for block arguments but are _not_ connected to
259  /// the predecessors that may not exist yet.
260  LogicalResult convertBlock(Block &bb, bool ignoreArguments,
261  llvm::IRBuilderBase &builder) {
262  return convertBlockImpl(bb, ignoreArguments, builder,
263  /*recordInsertions=*/false);
264  }
265 
266  /// Translates parameter attributes of a call and adds them to the returned
267  /// AttrBuilder. Returns failure if any of the translations failed.
268  FailureOr<llvm::AttrBuilder> convertParameterAttrs(mlir::Location loc,
269  DictionaryAttr paramAttrs);
270 
271  /// Gets the named metadata in the LLVM IR module being constructed, creating
272  /// it if it does not exist.
273  llvm::NamedMDNode *getOrInsertNamedModuleMetadata(StringRef name);
274 
275  /// Creates a stack frame of type `T` on ModuleTranslation stack. `T` must
276  /// be derived from `StackFrameBase<T>` and constructible from the provided
277  /// arguments. Doing this before entering the region of the op being
278  /// translated makes the frame available when translating ops within that
279  /// region.
280  template <typename T, typename... Args>
281  void stackPush(Args &&...args) {
282  stack.stackPush<T>(std::forward<Args>(args)...);
283  }
284 
285  /// Pops the last element from the ModuleTranslation stack.
286  void stackPop() { stack.stackPop(); }
287 
288  /// Calls `callback` for every ModuleTranslation stack frame of type `T`
289  /// starting from the top of the stack.
290  template <typename T>
292  return stack.stackWalk(callback);
293  }
294 
295  /// RAII object calling stackPush/stackPop on construction/destruction.
296  template <typename T>
298 
299  SymbolTableCollection &symbolTable() { return symbolTableCollection; }
300 
301 private:
303  std::unique_ptr<llvm::Module> llvmModule);
305 
306  /// Converts individual components.
307  LogicalResult convertOperation(Operation &op, llvm::IRBuilderBase &builder,
308  bool recordInsertions = false);
309  LogicalResult convertFunctionSignatures();
310  LogicalResult convertFunctions();
311  LogicalResult convertComdats();
312 
313  LogicalResult convertUnresolvedBlockAddress();
314 
315  /// Handle conversion for both globals and global aliases.
316  ///
317  /// - Create named global variables that correspond to llvm.mlir.global
318  /// definitions, similarly Convert llvm.global_ctors and global_dtors ops.
319  /// - Create global alias that correspond to llvm.mlir.alias.
320  LogicalResult convertGlobalsAndAliases();
321  LogicalResult convertOneFunction(LLVMFuncOp func);
322  LogicalResult convertBlockImpl(Block &bb, bool ignoreArguments,
323  llvm::IRBuilderBase &builder,
324  bool recordInsertions);
325 
326  /// Returns the LLVM metadata corresponding to the given mlir LLVM dialect
327  /// TBAATagAttr.
328  llvm::MDNode *getTBAANode(TBAATagAttr tbaaAttr) const;
329 
330  /// Process tbaa LLVM Metadata operations and create LLVM
331  /// metadata nodes for them.
332  LogicalResult createTBAAMetadata();
333 
334  /// Process the ident LLVM Metadata, if it exists.
335  LogicalResult createIdentMetadata();
336 
337  /// Process the llvm.commandline LLVM Metadata, if it exists.
338  LogicalResult createCommandlineMetadata();
339 
340  /// Process the llvm.dependent_libraries LLVM Metadata, if it exists.
341  LogicalResult createDependentLibrariesMetadata();
342 
343  /// Translates dialect attributes attached to the given operation.
344  LogicalResult
345  convertDialectAttributes(Operation *op,
346  ArrayRef<llvm::Instruction *> instructions);
347 
348  /// Translates parameter attributes of a function and adds them to the
349  /// returned AttrBuilder. Returns failure if any of the translations failed.
350  FailureOr<llvm::AttrBuilder>
351  convertParameterAttrs(LLVMFuncOp func, int argIdx, DictionaryAttr paramAttrs);
352 
353  /// Original and translated module.
354  Operation *mlirModule;
355  std::unique_ptr<llvm::Module> llvmModule;
356  /// A converter for translating debug information.
357  std::unique_ptr<detail::DebugTranslation> debugTranslation;
358 
359  /// A converter for translating loop annotations.
360  std::unique_ptr<detail::LoopAnnotationTranslation> loopAnnotationTranslation;
361 
362  /// Builder for LLVM IR generation of OpenMP constructs.
363  std::unique_ptr<llvm::OpenMPIRBuilder> ompBuilder;
364 
365  /// Mappings between llvm.mlir.global definitions and corresponding globals.
367 
368  /// Mappings between llvm.mlir.alias definitions and corresponding global
369  /// aliases.
371 
372  /// A stateful object used to translate types.
373  TypeToLLVMIRTranslator typeTranslator;
374 
375  /// A dialect interface collection used for dispatching the translation to
376  /// specific dialects.
378 
379  /// Mappings between original and translated values, used for lookups.
380  llvm::StringMap<llvm::Function *> functionMapping;
381  DenseMap<Value, llvm::Value *> valueMapping;
383 
384  /// A mapping between MLIR LLVM dialect terminators and LLVM IR terminators
385  /// they are converted to. This allows for connecting PHI nodes to the source
386  /// values after all operations are converted.
388 
389  /// A mapping between MLIR LLVM dialect call operations and LLVM IR call
390  /// instructions. This allows for adding branch weights after the operations
391  /// have been converted.
393 
394  /// Mapping from an alias scope attribute to its LLVM metadata.
395  /// This map is populated lazily.
396  DenseMap<AliasScopeAttr, llvm::MDNode *> aliasScopeMetadataMapping;
397 
398  /// Mapping from an alias scope domain attribute to its LLVM metadata.
399  /// This map is populated lazily.
400  DenseMap<AliasScopeDomainAttr, llvm::MDNode *> aliasDomainMetadataMapping;
401 
402  /// Mapping from a tbaa attribute to its LLVM metadata.
403  /// This map is populated on module entry.
404  DenseMap<Attribute, llvm::MDNode *> tbaaMetadataMapping;
405 
406  /// Mapping from a comdat selector operation to its LLVM comdat struct.
407  /// This map is populated on module entry.
409 
410  /// Mapping from llvm.blockaddress operations to their corresponding LLVM
411  /// constant placeholders. After all basic blocks are translated, this
412  /// mapping is used to replace the placeholders with the LLVM block addresses.
413  DenseMap<BlockAddressOp, llvm::Value *> unresolvedBlockAddressMapping;
414 
415  /// Mapping from a BlockAddressAttr attribute to it's matching LLVM basic
416  /// block.
417  DenseMap<BlockAddressAttr, llvm::BasicBlock *> blockAddressToLLVMMapping;
418 
419  /// Stack of user-specified state elements, useful when translating operations
420  /// with regions.
421  StateStack stack;
422 
423  /// A cache for the symbol tables constructed during symbols lookup.
424  SymbolTableCollection symbolTableCollection;
425 };
426 
427 namespace detail {
428 /// For all blocks in the region that were converted to LLVM IR using the given
429 /// ModuleTranslation, connect the PHI nodes of the corresponding LLVM IR blocks
430 /// to the results of preceding blocks.
431 void connectPHINodes(Region &region, const ModuleTranslation &state);
432 
433 /// Create an LLVM IR constant of `llvmType` from the MLIR attribute `attr`.
434 /// This currently supports integer, floating point, splat and dense element
435 /// attributes and combinations thereof. Also, an array attribute with two
436 /// elements is supported to represent a complex constant. In case of error,
437 /// report it to `loc` and return nullptr.
438 llvm::Constant *getLLVMConstant(llvm::Type *llvmType, Attribute attr,
439  Location loc,
440  const ModuleTranslation &moduleTranslation);
441 
442 /// Creates a call to an LLVM IR intrinsic function with the given arguments.
443 llvm::CallInst *createIntrinsicCall(llvm::IRBuilderBase &builder,
444  llvm::Intrinsic::ID intrinsic,
445  ArrayRef<llvm::Value *> args = {},
446  ArrayRef<llvm::Type *> tys = {});
447 
448 /// Creates a call to a LLVM IR intrinsic defined by LLVM_IntrOpBase. This
449 /// resolves the overloads, and maps mixed MLIR value and attribute arguments to
450 /// LLVM values.
451 llvm::CallInst *createIntrinsicCall(
452  llvm::IRBuilderBase &builder, ModuleTranslation &moduleTranslation,
453  Operation *intrOp, llvm::Intrinsic::ID intrinsic, unsigned numResults,
454  ArrayRef<unsigned> overloadedResults, ArrayRef<unsigned> overloadedOperands,
455  ArrayRef<unsigned> immArgPositions,
456  ArrayRef<StringLiteral> immArgAttrNames);
457 
458 } // namespace detail
459 
460 } // namespace LLVM
461 } // namespace mlir
462 
463 #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:33
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
Implementation class for module translation.
void mapUnresolvedBlockAddress(BlockAddressOp op, llvm::Value *cst)
Maps a blockaddress operation to its corresponding placeholder LLVM value.
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.
FailureOr< llvm::AttrBuilder > convertParameterAttrs(mlir::Location loc, DictionaryAttr paramAttrs)
Translates parameter attributes of a call and adds them to the returned AttrBuilder.
WalkResult stackWalk(llvm::function_ref< WalkResult(T &)> callback)
Calls callback for every ModuleTranslation stack frame of type T starting from the top of the stack.
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.
void setDereferenceableMetadata(DereferenceableOpInterface op, llvm::Instruction *inst)
Sets LLVM dereferenceable metadata for operations that have dereferenceable attributes.
void setBranchWeightsMetadata(WeightedBranchOpInterface op)
Sets LLVM profiling metadata for operations that have branch weights.
SymbolTableCollection & symbolTable()
llvm::Type * convertType(Type type)
Converts the type from MLIR LLVM dialect to LLVM.
llvm::GlobalValue * lookupAlias(Operation *op)
Finds an LLVM IR global value that corresponds to the given MLIR operation defining a global alias va...
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.
void setDisjointFlag(Operation *op, llvm::Value *value)
Sets the disjoint flag attribute for the exported instruction value given the original operation op.
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::BasicBlock * lookupBlockAddress(BlockAddressAttr attr) const
Finds the LLVM basic block that corresponds to the given BlockAddressAttr.
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.
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 mapBlockAddress(BlockAddressAttr attr, llvm::BasicBlock *block)
Maps a BlockAddressAttr to its corresponding LLVM basic block.
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:76
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
WalkResult stackWalk(llvm::function_ref< WalkResult(T &)> callback)
Calls callback for every StateStack frame of type T starting from the top of the stack.
Definition: StateStack.h:72
void stackPop()
Pops the last element from the StateStack.
Definition: StateStack.h:67
void stackPush(Args &&...args)
Creates a stack frame of type T on StateStack.
Definition: StateStack.h:60
This class represents a collection of SymbolTables.
Definition: SymbolTable.h:283
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:387
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: WalkResult.h:29
The OpAsmOpInterface, see OpAsmInterface.td for more details.
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.
RAII object calling stackPush/stackPop on construction/destruction.
Definition: StateStack.h:106