[Reland][Runtimes] Merge 'compile_commands.json' files from runtimes build (#116303)
[llvm-project.git] / mlir / lib / Target / LLVMIR / LoopAnnotationTranslation.h
blob0766cc23926a46c71af6523a6e08de168ba88230
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.
12 //===----------------------------------------------------------------------===//
14 #ifndef MLIR_LIB_TARGET_LLVMIR_LOOPANNOTATIONTRANSLATION_H_
15 #define MLIR_LIB_TARGET_LLVMIR_LOOPANNOTATIONTRANSLATION_H_
17 #include "mlir/Dialect/LLVMIR/LLVMDialect.h"
18 #include "mlir/Target/LLVMIR/ModuleTranslation.h"
20 namespace mlir {
21 namespace LLVM {
22 namespace detail {
24 /// A helper class that converts LoopAnnotationAttrs and AccessGroupAttrs into
25 /// corresponding llvm::MDNodes.
26 class LoopAnnotationTranslation {
27 public:
28 LoopAnnotationTranslation(ModuleTranslation &moduleTranslation,
29 llvm::Module &llvmModule)
30 : moduleTranslation(moduleTranslation), llvmModule(llvmModule) {}
32 llvm::MDNode *translateLoopAnnotation(LoopAnnotationAttr attr, Operation *op);
34 /// Returns the LLVM metadata corresponding to an mlir LLVM dialect access
35 /// group attribute.
36 llvm::MDNode *getAccessGroup(AccessGroupAttr accessGroupAttr);
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);
42 /// The ModuleTranslation owning this instance.
43 ModuleTranslation &moduleTranslation;
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);
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");
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;
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;
67 llvm::Module &llvmModule;
70 } // namespace detail
71 } // namespace LLVM
72 } // namespace mlir
74 #endif // MLIR_LIB_TARGET_LLVMIR_LOOPANNOTATIONTRANSLATION_H_