MLIR  19.0.0git
LoopAnnotationTranslation.h
Go to the documentation of this file.
1 //===- LoopAnnotationTranslation.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 an MLIR loop annotations and
10 // the corresponding LLVMIR metadata representation.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef MLIR_LIB_TARGET_LLVMIR_LOOPANNOTATIONTRANSLATION_H_
15 #define MLIR_LIB_TARGET_LLVMIR_LOOPANNOTATIONTRANSLATION_H_
16 
19 
20 namespace mlir {
21 namespace LLVM {
22 namespace detail {
23 
24 /// A helper class that converts LoopAnnotationAttrs and AccessGroupAttrs into
25 /// corresponding llvm::MDNodes.
27 public:
29  llvm::Module &llvmModule)
30  : moduleTranslation(moduleTranslation), llvmModule(llvmModule) {}
31 
32  llvm::MDNode *translateLoopAnnotation(LoopAnnotationAttr attr, Operation *op);
33 
34  /// Returns the LLVM metadata corresponding to an mlir LLVM dialect access
35  /// group attribute.
36  llvm::MDNode *getAccessGroup(AccessGroupAttr accessGroupAttr);
37 
38  /// Returns the LLVM metadata corresponding to the access group attribute
39  /// referenced by the AccessGroupOpInterface or null if there are none.
40  llvm::MDNode *getAccessGroups(AccessGroupOpInterface op);
41 
42  /// The ModuleTranslation owning this instance.
44 
45 private:
46  /// Returns the LLVM metadata corresponding to a llvm loop metadata attribute.
47  llvm::MDNode *lookupLoopMetadata(Attribute options) const {
48  return loopMetadataMapping.lookup(options);
49  }
50 
51  void mapLoopMetadata(Attribute options, llvm::MDNode *metadata) {
52  auto result = loopMetadataMapping.try_emplace(options, metadata);
53  (void)result;
54  assert(result.second &&
55  "attempting to map loop options that was already mapped");
56  }
57 
58  /// Mapping from an attribute describing loop metadata to its LLVM metadata.
59  /// The metadata is attached to Latch block branches with this attribute.
60  DenseMap<Attribute, llvm::MDNode *> loopMetadataMapping;
61 
62  /// Mapping from an access group attribute to its LLVM metadata.
63  /// This map is populated on module entry and is used to annotate loops (as
64  /// identified via their branches) and contained memory accesses.
65  DenseMap<AccessGroupAttr, llvm::MDNode *> accessGroupMetadataMapping;
66 
67  llvm::Module &llvmModule;
68 };
69 
70 } // namespace detail
71 } // namespace LLVM
72 } // namespace mlir
73 
74 #endif // MLIR_LIB_TARGET_LLVMIR_LOOPANNOTATIONTRANSLATION_H_
static llvm::ManagedStatic< PassManagerOptions > options
Attributes are known-constant values of operations.
Definition: Attributes.h:25
Implementation class for module translation.
A helper class that converts LoopAnnotationAttrs and AccessGroupAttrs into corresponding llvm::MDNode...
llvm::MDNode * translateLoopAnnotation(LoopAnnotationAttr attr, Operation *op)
LoopAnnotationTranslation(ModuleTranslation &moduleTranslation, llvm::Module &llvmModule)
llvm::MDNode * getAccessGroups(AccessGroupOpInterface op)
Returns the LLVM metadata corresponding to the access group attribute referenced by the AccessGroupOp...
ModuleTranslation & moduleTranslation
The ModuleTranslation owning this instance.
llvm::MDNode * getAccessGroup(AccessGroupAttr accessGroupAttr)
Returns the LLVM metadata corresponding to an mlir LLVM dialect access group attribute.
Operation is the basic unit of execution within MLIR.
Definition: Operation.h:88
Include the generated interface declarations.