MLIR 24.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
20
21namespace mlir {
22namespace LLVM {
23namespace detail {
24
25/// A helper class that converts LoopAnnotationAttrs and AccessGroupAttrs into
26/// corresponding llvm::MDNodes.
28public:
30 llvm::Module &llvmModule)
31 : moduleTranslation(moduleTranslation), llvmModule(llvmModule) {}
32
33 llvm::MDNode *translateLoopAnnotation(LoopAnnotationAttr attr, Operation *op);
34
35 /// Returns the LLVM metadata corresponding to an mlir LLVM dialect access
36 /// group attribute.
37 llvm::MDNode *getAccessGroup(AccessGroupAttr accessGroupAttr);
38
39 /// Returns the LLVM metadata corresponding to the access group attribute
40 /// referenced by the AccessGroupOpInterface or null if there are none.
41 llvm::MDNode *getAccessGroups(AccessGroupOpInterface op);
42
43 /// The ModuleTranslation owning this instance.
45
46private:
47 /// Returns the LLVM metadata corresponding to a llvm loop metadata attribute.
48 llvm::MDNode *lookupLoopMetadata(Attribute options) const {
49 return loopMetadataMapping.lookup(options);
50 }
51
52 void mapLoopMetadata(Attribute options, llvm::MDNode *metadata) {
53 auto result = loopMetadataMapping.try_emplace(options, metadata);
54 (void)result;
55 assert(result.second &&
56 "attempting to map loop options that was already mapped");
57 }
58
59 /// Mapping from an attribute describing loop metadata to its LLVM metadata.
60 /// The metadata is attached to Latch block branches with this attribute.
61 DenseMap<Attribute, llvm::MDNode *> loopMetadataMapping;
62
63 /// Mapping from an access group attribute to its LLVM metadata.
64 /// This map is populated on module entry and is used to annotate loops (as
65 /// identified via their branches) and contained memory accesses.
66 DenseMap<AccessGroupAttr, llvm::MDNode *> accessGroupMetadataMapping;
67
68 llvm::Module &llvmModule;
69};
70
71} // namespace detail
72} // namespace LLVM
73} // namespace mlir
74
75#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.
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:87
Include the generated interface declarations.
llvm::DenseMap< KeyT, ValueT, KeyInfoT, BucketT > DenseMap
Definition LLVM.h:123