9#ifndef FORTRAN_OPTIMIZER_ANALYSIS_TBAA_FOREST_H
10#define FORTRAN_OPTIMIZER_ANALYSIS_TBAA_FOREST_H
12#include "flang/Optimizer/Dialect/FIROpsSupport.h"
13#include "mlir/Dialect/Func/IR/FuncOps.h"
14#include "mlir/Dialect/LLVMIR/LLVMAttrs.h"
15#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
16#include "mlir/IR/Attributes.h"
17#include "mlir/IR/MLIRContext.h"
18#include "llvm/ADT/DenseMap.h"
41 mlir::LLVM::TBAATagAttr getTag(llvm::StringRef uniqueId)
const;
45 mlir::LLVM::TBAANodeAttr grandParent)
46 : parentId{std::move(name)}, context(ctx) {
47 parent = mlir::LLVM::TBAATypeDescriptorAttr::get(
48 context, parentId, mlir::LLVM::TBAAMemberAttr::get(grandParent, 0));
51 const std::string parentId;
52 mlir::MLIRContext *
const context;
53 mlir::LLVM::TBAATypeDescriptorAttr parent;
54 llvm::DenseMap<llvm::StringRef, mlir::LLVM::TBAATagAttr> tagDedup;
61 mlir::LLVM::TBAATypeDescriptorAttr anyAccessDesc;
62 mlir::LLVM::TBAATypeDescriptorAttr boxMemberTypeDesc;
63 mlir::LLVM::TBAATypeDescriptorAttr anyDataTypeDesc;
65 static TBAATree buildTree(mlir::StringAttr functionName);
68 TBAATree(mlir::LLVM::TBAATypeDescriptorAttr anyAccess,
69 mlir::LLVM::TBAATypeDescriptorAttr dataRoot,
70 mlir::LLVM::TBAATypeDescriptorAttr boxMemberTypeDesc);
80 explicit TBAAForrest(
bool separatePerFunction =
true)
81 : separatePerFunction{separatePerFunction} {}
83 inline const TBAATree &operator[](mlir::func::FuncOp func) {
84 return getFuncTree(func.getSymNameAttr());
86 inline const TBAATree &operator[](mlir::LLVM::LLVMFuncOp func) {
89 mlir::Attribute attr = func->getAttr(getInternalFuncNameAttrName());
91 return getFuncTree(mlir::cast<mlir::StringAttr>(attr));
93 return getFuncTree(func.getSymNameAttr());
101 inline const TBAATree &getFuncTreeWithScope(mlir::func::FuncOp func,
102 llvm::StringRef scope) {
103 mlir::StringAttr name = func.getSymNameAttr();
105 name = mlir::StringAttr::get(name.getContext(),
106 llvm::Twine(name) +
" - " + scope);
107 return getFuncTree(name);
111 const TBAATree &getFuncTree(mlir::StringAttr symName) {
112 if (!separatePerFunction)
113 symName = mlir::StringAttr::get(symName.getContext(),
"");
114 if (!trees.contains(symName))
115 trees.insert({symName, TBAATree::buildTree(symName)});
116 return trees.at(symName);
120 const bool separatePerFunction;
122 llvm::DenseMap<mlir::StringAttr, TBAATree> trees;
Definition: TBAAForest.h:78
Definition: TBAAForest.h:34
Definition: AbstractConverter.h:31
Definition: TBAAForest.h:28