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

source code of flang/lib/Optimizer/Analysis/TBAAForest.cpp