MLIR  20.0.0git
LoopAnnotationImporter.h
Go to the documentation of this file.
1 //===- LoopAnnotationImporter.h ---------------------------------*- 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 LLVMIR loop metadata and the
10 // corresponding MLIR representation.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef MLIR_LIB_TARGET_LLVMIR_LOOPANNOTATIONIMPORTER_H_
15 #define MLIR_LIB_TARGET_LLVMIR_LOOPANNOTATIONIMPORTER_H_
16 
19 
20 namespace mlir {
21 namespace LLVM {
22 namespace detail {
23 
24 /// A helper class that converts llvm.loop metadata nodes into corresponding
25 /// LoopAnnotationAttrs and llvm.access.group nodes into AccessGroupAttrs.
27 public:
29  : moduleImport(moduleImport), builder(builder) {}
30  LoopAnnotationAttr translateLoopAnnotation(const llvm::MDNode *node,
31  Location loc);
32 
33  /// Converts all LLVM access groups starting from node to MLIR access group
34  /// attributes. It stores a mapping from every nested access group node to the
35  /// translated attribute. Returns success if all conversions succeed and
36  /// failure otherwise.
37  LogicalResult translateAccessGroup(const llvm::MDNode *node, Location loc);
38 
39  /// Returns the access group attribute that map to the access group nodes
40  /// starting from the access group metadata node. Returns failure, if any of
41  /// the attributes cannot be found.
42  FailureOr<SmallVector<AccessGroupAttr>>
43  lookupAccessGroupAttrs(const llvm::MDNode *node) const;
44 
45  /// The ModuleImport owning this instance.
47 
48 private:
49  /// Returns the LLVM metadata corresponding to a llvm loop metadata attribute.
50  LoopAnnotationAttr lookupLoopMetadata(const llvm::MDNode *node) const {
51  return loopMetadataMapping.lookup(node);
52  }
53 
54  void mapLoopMetadata(const llvm::MDNode *metadata, LoopAnnotationAttr attr) {
55  auto result = loopMetadataMapping.try_emplace(metadata, attr);
56  (void)result;
57  assert(result.second &&
58  "attempting to map loop options that was already mapped");
59  }
60 
61  OpBuilder &builder;
63  /// Mapping between original LLVM access group metadata nodes and the imported
64  /// MLIR access group attributes.
66 };
67 
68 } // namespace detail
69 } // namespace LLVM
70 } // namespace mlir
71 
72 #endif // MLIR_LIB_TARGET_LLVMIR_LOOPANNOTATIONIMPORTER_H_
Module import implementation class that provides methods to import globals and functions from an LLVM...
Definition: ModuleImport.h:47
A helper class that converts llvm.loop metadata nodes into corresponding LoopAnnotationAttrs and llvm...
LoopAnnotationAttr translateLoopAnnotation(const llvm::MDNode *node, Location loc)
LoopAnnotationImporter(ModuleImport &moduleImport, OpBuilder &builder)
LogicalResult translateAccessGroup(const llvm::MDNode *node, Location loc)
Converts all LLVM access groups starting from node to MLIR access group attributes.
ModuleImport & moduleImport
The ModuleImport owning this instance.
FailureOr< SmallVector< AccessGroupAttr > > lookupAccessGroupAttrs(const llvm::MDNode *node) const
Returns the access group attribute that map to the access group nodes starting from the access group ...
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
Definition: Location.h:66
This class helps build Operations.
Definition: Builders.h:215
Include the generated interface declarations.