1 //===- TBAAForest.cpp - Per-functon TBAA Trees ----------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "flang/Optimizer/Analysis/TBAAForest.h"
10 #include <mlir/Dialect/LLVMIR/LLVMAttrs.h>
12 mlir::LLVM::TBAATagAttr
13 fir::TBAATree::SubtreeState::getTag(llvm::StringRef uniqueName
) const {
14 // mlir::LLVM::TBAATagAttr &tag = tagDedup[uniqueName];
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);
25 fir::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
));
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));
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));
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));
50 return TBAATree
{anyAccess
, dataRoot
, boxMemberTypeDesc
};
53 fir::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
) {}