1 | //===- TBAAForest.cpp - Per-functon TBAA Trees ----------------------------===// |
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 | #include "flang/Optimizer/Analysis/TBAAForest.h" |
10 | #include <mlir/Dialect/LLVMIR/LLVMAttrs.h> |
11 | |
12 | mlir::LLVM::TBAATagAttr |
13 | fir::TBAATree::SubtreeState::getTag(llvm::StringRef uniqueName) const { |
14 | std::string id = (parentId + "/" + uniqueName).str(); |
15 | mlir::LLVM::TBAATypeDescriptorAttr type = |
16 | mlir::LLVM::TBAATypeDescriptorAttr::get( |
17 | context, id, mlir::LLVM::TBAAMemberAttr::get(parent, 0)); |
18 | return mlir::LLVM::TBAATagAttr::get(type, type, 0); |
19 | // return tag; |
20 | } |
21 | |
22 | mlir::LLVM::TBAATagAttr fir::TBAATree::SubtreeState::getTag() const { |
23 | return mlir::LLVM::TBAATagAttr::get(parent, parent, 0); |
24 | } |
25 | |
26 | fir::TBAATree fir::TBAATree::buildTree(mlir::StringAttr func) { |
27 | llvm::StringRef funcName = func.getValue(); |
28 | std::string rootId = ("Flang function root " + funcName).str(); |
29 | mlir::MLIRContext *ctx = func.getContext(); |
30 | mlir::LLVM::TBAARootAttr funcRoot = |
31 | mlir::LLVM::TBAARootAttr::get(ctx, mlir::StringAttr::get(ctx, rootId)); |
32 | |
33 | static constexpr llvm::StringRef anyAccessTypeDescId = "any access" ; |
34 | mlir::LLVM::TBAATypeDescriptorAttr anyAccess = |
35 | mlir::LLVM::TBAATypeDescriptorAttr::get( |
36 | ctx, anyAccessTypeDescId, |
37 | mlir::LLVM::TBAAMemberAttr::get(funcRoot, 0)); |
38 | |
39 | static constexpr llvm::StringRef anyDataAccessTypeDescId = "any data access" ; |
40 | mlir::LLVM::TBAATypeDescriptorAttr dataRoot = |
41 | mlir::LLVM::TBAATypeDescriptorAttr::get( |
42 | ctx, anyDataAccessTypeDescId, |
43 | mlir::LLVM::TBAAMemberAttr::get(anyAccess, 0)); |
44 | |
45 | static constexpr llvm::StringRef boxMemberTypeDescId = "descriptor member" ; |
46 | mlir::LLVM::TBAATypeDescriptorAttr boxMemberTypeDesc = |
47 | mlir::LLVM::TBAATypeDescriptorAttr::get( |
48 | ctx, boxMemberTypeDescId, |
49 | mlir::LLVM::TBAAMemberAttr::get(anyAccess, 0)); |
50 | |
51 | return TBAATree{anyAccess, dataRoot, boxMemberTypeDesc}; |
52 | } |
53 | |
54 | fir::TBAATree::TBAATree(mlir::LLVM::TBAATypeDescriptorAttr anyAccess, |
55 | mlir::LLVM::TBAATypeDescriptorAttr dataRoot, |
56 | mlir::LLVM::TBAATypeDescriptorAttr boxMemberTypeDesc) |
57 | : targetDataTree(dataRoot.getContext(), "target data" , dataRoot), |
58 | globalDataTree(dataRoot.getContext(), "global data" , |
59 | targetDataTree.getRoot()), |
60 | allocatedDataTree(dataRoot.getContext(), "allocated data" , |
61 | targetDataTree.getRoot()), |
62 | dummyArgDataTree(dataRoot.getContext(), "dummy arg data" , dataRoot), |
63 | directDataTree(dataRoot.getContext(), "direct data" , |
64 | targetDataTree.getRoot()), |
65 | anyAccessDesc(anyAccess), boxMemberTypeDesc(boxMemberTypeDesc), |
66 | anyDataTypeDesc(dataRoot) {} |
67 | |