MLIR  20.0.0git
ModuleImport.h
Go to the documentation of this file.
1 //===- ModuleImport.h - LLVM to MLIR 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 import of an LLVM IR module into an LLVM dialect
10 // module.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef MLIR_TARGET_LLVMIR_MODULEIMPORT_H
15 #define MLIR_TARGET_LLVMIR_MODULEIMPORT_H
16 
18 #include "mlir/IR/BuiltinOps.h"
22 
23 namespace llvm {
24 class BasicBlock;
25 class CallBase;
26 class DbgVariableIntrinsic;
27 class Function;
28 class Instruction;
29 class Value;
30 } // namespace llvm
31 
32 namespace mlir {
33 namespace LLVM {
34 
35 namespace detail {
36 class DataLayoutImporter;
37 class DebugImporter;
38 class LoopAnnotationImporter;
39 } // namespace detail
40 
41 /// Module import implementation class that provides methods to import globals
42 /// and functions from an LLVM module into an MLIR module. It holds mappings
43 /// between the original and translated globals, basic blocks, and values used
44 /// during the translation. Additionally, it keeps track of the current constant
45 /// insertion point since LLVM immediate values translate to MLIR operations
46 /// that are introduced at the beginning of the region.
47 class ModuleImport {
48 public:
49  ModuleImport(ModuleOp mlirModule, std::unique_ptr<llvm::Module> llvmModule,
50  bool emitExpensiveWarnings, bool importEmptyDICompositeTypes);
51 
52  /// Calls the LLVMImportInterface initialization that queries the registered
53  /// dialect interfaces for the supported LLVM IR intrinsics and metadata kinds
54  /// and builds the dispatch tables. Returns failure if multiple dialect
55  /// interfaces translate the same LLVM IR intrinsic.
56  LogicalResult initializeImportInterface() {
57  return iface.initializeImport(llvmModule->getContext());
58  }
59 
60  /// Converts all functions of the LLVM module to MLIR functions.
61  LogicalResult convertFunctions();
62 
63  /// Converts all comdat selectors of the LLVM module to MLIR comdat
64  /// operations.
65  LogicalResult convertComdats();
66 
67  /// Converts all global variables of the LLVM module to MLIR global variables.
68  LogicalResult convertGlobals();
69 
70  /// Converts the data layout of the LLVM module to an MLIR data layout
71  /// specification.
72  LogicalResult convertDataLayout();
73 
74  /// Stores the mapping between an LLVM value and its MLIR counterpart.
75  void mapValue(llvm::Value *llvm, Value mlir) { mapValue(llvm) = mlir; }
76 
77  /// Provides write-once access to store the MLIR value corresponding to the
78  /// given LLVM value.
79  Value &mapValue(llvm::Value *value) {
80  Value &mlir = valueMapping[value];
81  assert(mlir == nullptr &&
82  "attempting to map a value that is already mapped");
83  return mlir;
84  }
85 
86  /// Returns the MLIR value mapped to the given LLVM value.
87  Value lookupValue(llvm::Value *value) { return valueMapping.lookup(value); }
88 
89  /// Stores a mapping between an LLVM instruction and the imported MLIR
90  /// operation if the operation returns no result. Asserts if the operation
91  /// returns a result and should be added to valueMapping instead.
92  void mapNoResultOp(llvm::Instruction *llvm, Operation *mlir) {
94  }
95 
96  /// Provides write-once access to store the MLIR operation corresponding to
97  /// the given LLVM instruction if the operation returns no result. Asserts if
98  /// the operation returns a result and should be added to valueMapping
99  /// instead.
100  Operation *&mapNoResultOp(llvm::Instruction *inst) {
101  Operation *&mlir = noResultOpMapping[inst];
102  assert(inst->getType()->isVoidTy() &&
103  "attempting to map an operation that returns a result");
104  assert(mlir == nullptr &&
105  "attempting to map an operation that is already mapped");
106  return mlir;
107  }
108 
109  /// Returns the MLIR operation mapped to the given LLVM instruction. Queries
110  /// valueMapping and noResultOpMapping to support operations with and without
111  /// result.
112  Operation *lookupOperation(llvm::Instruction *inst) {
113  if (Value value = lookupValue(inst))
114  return value.getDefiningOp();
115  return noResultOpMapping.lookup(inst);
116  }
117 
118  /// Stores the mapping between an LLVM block and its MLIR counterpart.
119  void mapBlock(llvm::BasicBlock *llvm, Block *mlir) {
120  auto result = blockMapping.try_emplace(llvm, mlir);
121  (void)result;
122  assert(result.second && "attempting to map a block that is already mapped");
123  }
124 
125  /// Returns the MLIR block mapped to the given LLVM block.
126  Block *lookupBlock(llvm::BasicBlock *block) const {
127  return blockMapping.lookup(block);
128  }
129 
130  /// Converts an LLVM value to an MLIR value, or returns failure if the
131  /// conversion fails. Uses the `convertConstant` method to translate constant
132  /// LLVM values.
133  FailureOr<Value> convertValue(llvm::Value *value);
134 
135  /// Converts an LLVM metadata value to an MLIR value, or returns failure if
136  /// the conversion fails. Uses the `convertConstant` method to translate
137  /// constant LLVM values.
138  FailureOr<Value> convertMetadataValue(llvm::Value *value);
139 
140  /// Converts a range of LLVM values to a range of MLIR values using the
141  /// `convertValue` method, or returns failure if the conversion fails.
142  FailureOr<SmallVector<Value>> convertValues(ArrayRef<llvm::Value *> values);
143 
144  /// Converts `value` to an integer attribute. Asserts if the matching fails.
145  IntegerAttr matchIntegerAttr(llvm::Value *value);
146 
147  /// Converts `value` to a float attribute. Asserts if the matching fails.
148  FloatAttr matchFloatAttr(llvm::Value *value);
149 
150  /// Converts `value` to a local variable attribute. Asserts if the matching
151  /// fails.
152  DILocalVariableAttr matchLocalVariableAttr(llvm::Value *value);
153 
154  /// Converts `value` to a label attribute. Asserts if the matching fails.
155  DILabelAttr matchLabelAttr(llvm::Value *value);
156 
157  /// Converts `value` to a FP exception behavior attribute. Asserts if the
158  /// matching fails.
159  FPExceptionBehaviorAttr matchFPExceptionBehaviorAttr(llvm::Value *value);
160 
161  /// Converts `value` to a rounding mode attribute. Asserts if the matching
162  /// fails.
163  RoundingModeAttr matchRoundingModeAttr(llvm::Value *value);
164 
165  /// Converts `value` to an array of alias scopes or returns failure if the
166  /// conversion fails.
167  FailureOr<SmallVector<AliasScopeAttr>>
168  matchAliasScopeAttrs(llvm::Value *value);
169 
170  /// Translates the debug location.
171  Location translateLoc(llvm::DILocation *loc);
172 
173  /// Converts the type from LLVM to MLIR LLVM dialect.
174  Type convertType(llvm::Type *type) {
175  return typeTranslator.translateType(type);
176  }
177 
178  /// Imports `func` into the current module.
179  LogicalResult processFunction(llvm::Function *func);
180 
181  /// Converts function attributes of LLVM Function `func` into LLVM dialect
182  /// attributes of LLVMFuncOp `funcOp`.
183  void processFunctionAttributes(llvm::Function *func, LLVMFuncOp funcOp);
184 
185  /// Sets the integer overflow flags (nsw/nuw) attribute for the imported
186  /// operation `op` given the original instruction `inst`. Asserts if the
187  /// operation does not implement the integer overflow flag interface.
188  void setIntegerOverflowFlags(llvm::Instruction *inst, Operation *op) const;
189 
190  /// Sets the fastmath flags attribute for the imported operation `op` given
191  /// the original instruction `inst`. Asserts if the operation does not
192  /// implement the fastmath interface.
193  void setFastmathFlagsAttr(llvm::Instruction *inst, Operation *op) const;
194 
195  /// Converts !llvm.linker.options metadata to the llvm.linker.options
196  /// LLVM dialect operation.
197  LogicalResult convertLinkerOptionsMetadata();
198 
199  /// Converts !llvm.ident metadata to the llvm.ident LLVM ModuleOp attribute.
200  LogicalResult convertIdentMetadata();
201 
202  /// Converts all LLVM metadata nodes that translate to attributes such as
203  /// alias analysis or access group metadata, and builds a map from the
204  /// metadata nodes to the converted attributes.
205  /// Returns success if all conversions succeed and failure otherwise.
206  LogicalResult convertMetadata();
207 
208  /// Returns the MLIR attribute mapped to the given LLVM TBAA
209  /// metadata `node`.
210  Attribute lookupTBAAAttr(const llvm::MDNode *node) const {
211  return tbaaMapping.lookup(node);
212  }
213 
214  /// Returns the access group attributes that map to the access group nodes
215  /// starting from the access group metadata `node`. Returns failure, if any of
216  /// the attributes cannot be found.
217  FailureOr<SmallVector<AccessGroupAttr>>
218  lookupAccessGroupAttrs(const llvm::MDNode *node) const;
219 
220  /// Returns the loop annotation attribute that corresponds to the given LLVM
221  /// loop metadata `node`.
222  LoopAnnotationAttr translateLoopAnnotationAttr(const llvm::MDNode *node,
223  Location loc) const;
224 
225  /// Returns the alias scope attributes that map to the alias scope nodes
226  /// starting from the metadata `node`. Returns failure, if any of the
227  /// attributes cannot be found.
228  FailureOr<SmallVector<AliasScopeAttr>>
229  lookupAliasScopeAttrs(const llvm::MDNode *node) const;
230 
231  /// Adds a debug intrinsics to the list of intrinsics that should be converted
232  /// after the function conversion has finished.
233  void addDebugIntrinsic(llvm::CallInst *intrinsic);
234 
235  /// Converts the LLVM values for an intrinsic to mixed MLIR values and
236  /// attributes for LLVM_IntrOpBase. Attributes correspond to LLVM immargs. The
237  /// list `immArgPositions` contains the positions of immargs on the LLVM
238  /// intrinsic, and `immArgAttrNames` list (of the same length) contains the
239  /// corresponding MLIR attribute names.
240  LogicalResult
242  ArrayRef<unsigned> immArgPositions,
243  ArrayRef<StringLiteral> immArgAttrNames,
244  SmallVectorImpl<Value> &valuesOut,
246 
247 private:
248  /// Clears the accumulated state before processing a new region.
249  void clearRegionState() {
250  valueMapping.clear();
251  noResultOpMapping.clear();
252  blockMapping.clear();
253  debugIntrinsics.clear();
254  }
255  /// Sets the constant insertion point to the start of the given block.
256  void setConstantInsertionPointToStart(Block *block) {
257  constantInsertionBlock = block;
258  constantInsertionOp = nullptr;
259  }
260 
261  /// Converts an LLVM global variable into an MLIR LLVM dialect global
262  /// operation if a conversion exists. Otherwise, returns failure.
263  LogicalResult convertGlobal(llvm::GlobalVariable *globalVar);
264  /// Imports the magic globals "global_ctors" and "global_dtors".
265  LogicalResult convertGlobalCtorsAndDtors(llvm::GlobalVariable *globalVar);
266  /// Returns personality of `func` as a FlatSymbolRefAttr.
267  FlatSymbolRefAttr getPersonalityAsAttr(llvm::Function *func);
268  /// Imports `bb` into `block`, which must be initially empty.
269  LogicalResult processBasicBlock(llvm::BasicBlock *bb, Block *block);
270  /// Converts all debug intrinsics in `debugIntrinsics`. Assumes that the
271  /// function containing the intrinsics has been fully converted to MLIR.
272  LogicalResult processDebugIntrinsics();
273  /// Converts a single debug intrinsic.
274  LogicalResult processDebugIntrinsic(llvm::DbgVariableIntrinsic *dbgIntr,
275  DominanceInfo &domInfo);
276  /// Converts an LLVM intrinsic to an MLIR LLVM dialect operation if an MLIR
277  /// counterpart exists. Otherwise, returns failure.
278  LogicalResult convertIntrinsic(llvm::CallInst *inst);
279  /// Converts an LLVM instruction to an MLIR LLVM dialect operation if an MLIR
280  /// counterpart exists. Otherwise, returns failure.
281  LogicalResult convertInstruction(llvm::Instruction *inst);
282  /// Converts the metadata attached to the original instruction `inst` if
283  /// a dialect interfaces supports the specific kind of metadata and attaches
284  /// the resulting dialect attributes to the converted operation `op`. Emits a
285  /// warning if the conversion of a supported metadata kind fails.
286  void setNonDebugMetadataAttrs(llvm::Instruction *inst, Operation *op);
287  /// Imports `inst` and populates valueMapping[inst] with the result of the
288  /// imported operation or noResultOpMapping[inst] with the imported operation
289  /// if it has no result.
290  LogicalResult processInstruction(llvm::Instruction *inst);
291  /// Converts the `branch` arguments in the order of the phi's found in
292  /// `target` and appends them to the `blockArguments` to attach to the
293  /// generated branch operation. The `blockArguments` thus have the same order
294  /// as the phi's in `target`.
295  LogicalResult convertBranchArgs(llvm::Instruction *branch,
296  llvm::BasicBlock *target,
297  SmallVectorImpl<Value> &blockArguments);
298  /// Appends the converted result type and operands of `callInst` to the
299  /// `types` and `operands` arrays. For indirect calls, the method additionally
300  /// inserts the called function at the beginning of the `operands` array.
301  LogicalResult convertCallTypeAndOperands(llvm::CallBase *callInst,
302  SmallVectorImpl<Type> &types,
303  SmallVectorImpl<Value> &operands);
304  /// Converts the parameter attributes attached to `func` and adds them to the
305  /// `funcOp`.
306  void convertParameterAttributes(llvm::Function *func, LLVMFuncOp funcOp,
307  OpBuilder &builder);
308  /// Converts the AttributeSet of one parameter in LLVM IR to a corresponding
309  /// DictionaryAttr for the LLVM dialect.
310  DictionaryAttr convertParameterAttribute(llvm::AttributeSet llvmParamAttrs,
311  OpBuilder &builder);
312  /// Returns the builtin type equivalent to the given LLVM dialect type or
313  /// nullptr if there is no equivalent. The returned type can be used to create
314  /// an attribute for a GlobalOp or a ConstantOp.
315  Type getBuiltinTypeForAttr(Type type);
316  /// Returns `constant` as an attribute to attach to a GlobalOp or ConstantOp
317  /// or nullptr if the constant is not convertible. It supports scalar integer
318  /// and float constants as well as shaped types thereof including strings.
319  Attribute getConstantAsAttr(llvm::Constant *constant);
320  /// Returns the topologically sorted set of transitive dependencies needed to
321  /// convert the given constant.
322  SetVector<llvm::Constant *> getConstantsToConvert(llvm::Constant *constant);
323  /// Converts an LLVM constant to an MLIR value, or returns failure if the
324  /// conversion fails. The MLIR value may be produced by a ConstantOp,
325  /// AddressOfOp, NullOp, or a side-effect free operation (for ConstantExprs or
326  /// ConstantGEPs).
327  FailureOr<Value> convertConstant(llvm::Constant *constant);
328  /// Converts an LLVM constant and its transitive constant dependencies to MLIR
329  /// operations by converting them in topological order using the
330  /// `convertConstant` method, or returns failure if the conversion of any of
331  /// them fails. All operations are inserted at the start of the current
332  /// function entry block.
333  FailureOr<Value> convertConstantExpr(llvm::Constant *constant);
334  /// Returns a global comdat operation that serves as a container for LLVM
335  /// comdat selectors. Creates the global comdat operation on the first
336  /// invocation.
337  ComdatOp getGlobalComdatOp();
338  /// Performs conversion of LLVM TBAA metadata starting from
339  /// `node`. On exit from this function all nodes reachable
340  /// from `node` are converted, and tbaaMapping map is updated
341  /// (unless all dependencies have been converted by a previous
342  /// invocation of this function).
343  LogicalResult processTBAAMetadata(const llvm::MDNode *node);
344  /// Converts all LLVM access groups starting from `node` to MLIR access group
345  /// operations and stores a mapping from every nested access group node to the
346  /// translated attribute. Returns success if all conversions succeed and
347  /// failure otherwise.
348  LogicalResult processAccessGroupMetadata(const llvm::MDNode *node);
349  /// Converts all LLVM alias scopes and domains starting from `node` to MLIR
350  /// alias scope and domain attributes and stores a mapping from every nested
351  /// alias scope or alias domain node to the translated attribute. Returns
352  /// success if all conversions succeed and failure otherwise.
353  LogicalResult processAliasScopeMetadata(const llvm::MDNode *node);
354  /// Converts the given LLVM comdat struct to an MLIR comdat selector operation
355  /// and stores a mapping from the struct to the symbol pointing to the
356  /// translated operation.
357  void processComdat(const llvm::Comdat *comdat);
358 
359  /// Builder pointing at where the next instruction should be generated.
360  OpBuilder builder;
361  /// Block to insert the next constant into.
362  Block *constantInsertionBlock = nullptr;
363  /// Operation to insert the next constant after.
364  Operation *constantInsertionOp = nullptr;
365  /// Operation to insert the next global after.
366  Operation *globalInsertionOp = nullptr;
367  /// Operation to insert comdat selector operations into.
368  ComdatOp globalComdatOp = nullptr;
369  /// The current context.
370  MLIRContext *context;
371  /// The MLIR module being created.
372  ModuleOp mlirModule;
373  /// The LLVM module being imported.
374  std::unique_ptr<llvm::Module> llvmModule;
375  /// Nameless globals.
376  DenseMap<llvm::GlobalVariable *, FlatSymbolRefAttr> namelessGlobals;
377  /// Counter used to assign a unique ID to each nameless global.
378  unsigned namelessGlobalId = 0;
379 
380  /// A dialect interface collection used for dispatching the import to specific
381  /// dialects.
382  LLVMImportInterface iface;
383 
384  /// Function-local mapping between original and imported block.
385  DenseMap<llvm::BasicBlock *, Block *> blockMapping;
386  /// Function-local mapping between original and imported values.
387  DenseMap<llvm::Value *, Value> valueMapping;
388  /// Function-local mapping between original instructions and imported
389  /// operations for all operations that return no result. All operations that
390  /// return a result have a valueMapping entry instead.
391  DenseMap<llvm::Instruction *, Operation *> noResultOpMapping;
392  /// Function-local list of debug intrinsics that need to be imported after the
393  /// function conversion has finished.
394  SetVector<llvm::Instruction *> debugIntrinsics;
395  /// Mapping between LLVM alias scope and domain metadata nodes and
396  /// attributes in the LLVM dialect corresponding to these nodes.
397  DenseMap<const llvm::MDNode *, Attribute> aliasScopeMapping;
398  /// Mapping between LLVM TBAA metadata nodes and LLVM dialect TBAA attributes
399  /// corresponding to these nodes.
400  DenseMap<const llvm::MDNode *, Attribute> tbaaMapping;
401  /// Mapping between LLVM comdat structs and symbol references to LLVM dialect
402  /// comdat selector operations corresponding to these structs.
403  DenseMap<const llvm::Comdat *, SymbolRefAttr> comdatMapping;
404  /// The stateful type translator (contains named structs).
405  LLVM::TypeFromLLVMIRTranslator typeTranslator;
406  /// Stateful debug information importer.
407  std::unique_ptr<detail::DebugImporter> debugImporter;
408  /// Loop annotation importer.
409  std::unique_ptr<detail::LoopAnnotationImporter> loopAnnotationImporter;
410 
411  /// An option to control if expensive but uncritical diagnostics should be
412  /// emitted. Avoids generating warnings for unhandled debug intrinsics and
413  /// metadata that otherwise dominate the translation time for large inputs.
414  bool emitExpensiveWarnings;
415 };
416 
417 } // namespace LLVM
418 } // namespace mlir
419 
420 #endif // MLIR_TARGET_LLVMIR_MODULEIMPORT_H
Attributes are known-constant values of operations.
Definition: Attributes.h:25
Block represents an ordered list of Operations.
Definition: Block.h:31
LogicalResult initializeImport(llvm::LLVMContext &llvmContext)
Queries all registered dialect interfaces for the supported LLVM IR intrinsic and metadata kinds and ...
Module import implementation class that provides methods to import globals and functions from an LLVM...
Definition: ModuleImport.h:47
Location translateLoc(llvm::DILocation *loc)
Translates the debug location.
LogicalResult convertComdats()
Converts all comdat selectors of the LLVM module to MLIR comdat operations.
LogicalResult convertFunctions()
Converts all functions of the LLVM module to MLIR functions.
FailureOr< SmallVector< Value > > convertValues(ArrayRef< llvm::Value * > values)
Converts a range of LLVM values to a range of MLIR values using the convertValue method,...
Attribute lookupTBAAAttr(const llvm::MDNode *node) const
Returns the MLIR attribute mapped to the given LLVM TBAA metadata node.
Definition: ModuleImport.h:210
DILocalVariableAttr matchLocalVariableAttr(llvm::Value *value)
Converts value to a local variable attribute.
LogicalResult convertLinkerOptionsMetadata()
Converts !llvm.linker.options metadata to the llvm.linker.options LLVM dialect operation.
void mapBlock(llvm::BasicBlock *llvm, Block *mlir)
Stores the mapping between an LLVM block and its MLIR counterpart.
Definition: ModuleImport.h:119
void processFunctionAttributes(llvm::Function *func, LLVMFuncOp funcOp)
Converts function attributes of LLVM Function func into LLVM dialect attributes of LLVMFuncOp funcOp.
LogicalResult convertMetadata()
Converts all LLVM metadata nodes that translate to attributes such as alias analysis or access group ...
LogicalResult convertIntrinsicArguments(ArrayRef< llvm::Value * > values, ArrayRef< unsigned > immArgPositions, ArrayRef< StringLiteral > immArgAttrNames, SmallVectorImpl< Value > &valuesOut, SmallVectorImpl< NamedAttribute > &attrsOut)
Converts the LLVM values for an intrinsic to mixed MLIR values and attributes for LLVM_IntrOpBase.
Value & mapValue(llvm::Value *value)
Provides write-once access to store the MLIR value corresponding to the given LLVM value.
Definition: ModuleImport.h:79
FailureOr< Value > convertValue(llvm::Value *value)
Converts an LLVM value to an MLIR value, or returns failure if the conversion fails.
LogicalResult initializeImportInterface()
Calls the LLVMImportInterface initialization that queries the registered dialect interfaces for the s...
Definition: ModuleImport.h:56
void addDebugIntrinsic(llvm::CallInst *intrinsic)
Adds a debug intrinsics to the list of intrinsics that should be converted after the function convers...
LogicalResult convertIdentMetadata()
Converts !llvm.ident metadata to the llvm.ident LLVM ModuleOp attribute.
Block * lookupBlock(llvm::BasicBlock *block) const
Returns the MLIR block mapped to the given LLVM block.
Definition: ModuleImport.h:126
FailureOr< Value > convertMetadataValue(llvm::Value *value)
Converts an LLVM metadata value to an MLIR value, or returns failure if the conversion fails.
FailureOr< SmallVector< AliasScopeAttr > > lookupAliasScopeAttrs(const llvm::MDNode *node) const
Returns the alias scope attributes that map to the alias scope nodes starting from the metadata node.
void mapNoResultOp(llvm::Instruction *llvm, Operation *mlir)
Stores a mapping between an LLVM instruction and the imported MLIR operation if the operation returns...
Definition: ModuleImport.h:92
Type convertType(llvm::Type *type)
Converts the type from LLVM to MLIR LLVM dialect.
Definition: ModuleImport.h:174
Operation * lookupOperation(llvm::Instruction *inst)
Returns the MLIR operation mapped to the given LLVM instruction.
Definition: ModuleImport.h:112
DILabelAttr matchLabelAttr(llvm::Value *value)
Converts value to a label attribute. Asserts if the matching fails.
FloatAttr matchFloatAttr(llvm::Value *value)
Converts value to a float attribute. Asserts if the matching fails.
LoopAnnotationAttr translateLoopAnnotationAttr(const llvm::MDNode *node, Location loc) const
Returns the loop annotation attribute that corresponds to the given LLVM loop metadata node.
void setFastmathFlagsAttr(llvm::Instruction *inst, Operation *op) const
Sets the fastmath flags attribute for the imported operation op given the original instruction inst.
FailureOr< SmallVector< AliasScopeAttr > > matchAliasScopeAttrs(llvm::Value *value)
Converts value to an array of alias scopes or returns failure if the conversion fails.
Value lookupValue(llvm::Value *value)
Returns the MLIR value mapped to the given LLVM value.
Definition: ModuleImport.h:87
LogicalResult processFunction(llvm::Function *func)
Imports func into the current module.
RoundingModeAttr matchRoundingModeAttr(llvm::Value *value)
Converts value to a rounding mode attribute.
Operation *& mapNoResultOp(llvm::Instruction *inst)
Provides write-once access to store the MLIR operation corresponding to the given LLVM instruction if...
Definition: ModuleImport.h:100
void mapValue(llvm::Value *llvm, Value mlir)
Stores the mapping between an LLVM value and its MLIR counterpart.
Definition: ModuleImport.h:75
ModuleImport(ModuleOp mlirModule, std::unique_ptr< llvm::Module > llvmModule, bool emitExpensiveWarnings, bool importEmptyDICompositeTypes)
FailureOr< SmallVector< AccessGroupAttr > > lookupAccessGroupAttrs(const llvm::MDNode *node) const
Returns the access group attributes that map to the access group nodes starting from the access group...
LogicalResult convertGlobals()
Converts all global variables of the LLVM module to MLIR global variables.
void setIntegerOverflowFlags(llvm::Instruction *inst, Operation *op) const
Sets the integer overflow flags (nsw/nuw) attribute for the imported operation op given the original ...
FPExceptionBehaviorAttr matchFPExceptionBehaviorAttr(llvm::Value *value)
Converts value to a FP exception behavior attribute.
LogicalResult convertDataLayout()
Converts the data layout of the LLVM module to an MLIR data layout specification.
IntegerAttr matchIntegerAttr(llvm::Value *value)
Converts value to an integer attribute. Asserts if the matching fails.
Type translateType(llvm::Type *type)
Translates the given LLVM IR type to the MLIR LLVM dialect.
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
Definition: Location.h:63
Operation is the basic unit of execution within MLIR.
Definition: Operation.h:88
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
Definition: Types.h:74
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Definition: Value.h:96
The OpAsmOpInterface, see OpAsmInterface.td for more details.
Definition: CallGraph.h:229
Include the generated interface declarations.