Skip to content

Commit df18f16

Browse files
committed
Separate access to Direct data from Global data
1 parent ba1bbbe commit df18f16

File tree

4 files changed

+29
-8
lines changed

4 files changed

+29
-8
lines changed

flang/include/flang/Optimizer/Analysis/TBAAForest.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ struct TBAATree {
5555
SubtreeState globalDataTree;
5656
SubtreeState allocatedDataTree;
5757
SubtreeState dummyArgDataTree;
58+
SubtreeState directDataTree;
5859
mlir::LLVM::TBAATypeDescriptorAttr anyAccessDesc;
5960
mlir::LLVM::TBAATypeDescriptorAttr boxMemberTypeDesc;
6061
mlir::LLVM::TBAATypeDescriptorAttr anyDataTypeDesc;

flang/lib/Optimizer/Analysis/TBAAForest.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,6 @@ fir::TBAATree::TBAATree(mlir::LLVM::TBAATypeDescriptorAttr anyAccess,
5656
: globalDataTree(dataRoot.getContext(), "global data", dataRoot),
5757
allocatedDataTree(dataRoot.getContext(), "allocated data", dataRoot),
5858
dummyArgDataTree(dataRoot.getContext(), "dummy arg data", dataRoot),
59+
directDataTree(dataRoot.getContext(), "direct data", dataRoot),
5960
anyAccessDesc(anyAccess), boxMemberTypeDesc(boxMemberTypeDesc),
6061
anyDataTypeDesc(dataRoot) {}

flang/lib/Optimizer/Transforms/AddAliasTags.cpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ static llvm::cl::opt<bool>
3838
static llvm::cl::opt<bool>
3939
enableGlobals("globals-tbaa", llvm::cl::init(true), llvm::cl::Hidden,
4040
llvm::cl::desc("Add TBAA tags to global variables"));
41+
static llvm::cl::opt<bool>
42+
enableDirect("direct-tbaa", llvm::cl::init(true), llvm::cl::Hidden,
43+
llvm::cl::desc("Add TBAA tags to direct variables"));
4144
// This is **known unsafe** (misscompare in spec2017/wrf_r). It should
4245
// not be enabled by default.
4346
// The code is kept so that these may be tried with new benchmarks to see if
@@ -151,14 +154,29 @@ void AddAliasTagsPass::runOnAliasInterface(fir::FirAliasTagOpInterface op,
151154

152155
// TBAA for global variables
153156
} else if (enableGlobals &&
154-
(source.kind == fir::AliasAnalysis::SourceKind::Global ||
155-
source.kind == fir::AliasAnalysis::SourceKind::Direct)) {
157+
source.kind == fir::AliasAnalysis::SourceKind::Global) {
156158
mlir::SymbolRefAttr glbl = source.u.get<mlir::SymbolRefAttr>();
157159
const char *name = glbl.getRootReference().data();
158160
LLVM_DEBUG(llvm::dbgs().indent(2) << "Found reference to global " << name
159161
<< " at " << *op << "\n");
160162
tag = state.getFuncTree(func).globalDataTree.getTag(name);
161163

164+
// TBAA for SourceKind::Direct
165+
} else if (enableDirect &&
166+
source.kind == fir::AliasAnalysis::SourceKind::Direct) {
167+
if (source.u.is<mlir::SymbolRefAttr>()) {
168+
mlir::SymbolRefAttr glbl = source.u.get<mlir::SymbolRefAttr>();
169+
const char *name = glbl.getRootReference().data();
170+
LLVM_DEBUG(llvm::dbgs().indent(2) << "Found reference to direct " << name
171+
<< " at " << *op << "\n");
172+
tag = state.getFuncTree(func).directDataTree.getTag(name);
173+
} else {
174+
// SourceKind::Direct is likely to be extended to cases which are not a
175+
// SymbolRefAttr in the future
176+
LLVM_DEBUG(llvm::dbgs().indent(2) << "Can't get name for direct "
177+
<< source << " at " << *op << "\n");
178+
}
179+
162180
// TBAA for local allocations
163181
} else if (enableLocalAllocs &&
164182
source.kind == fir::AliasAnalysis::SourceKind::Allocate) {

flang/test/Transforms/tbaa2.fir

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,15 @@
4949
// CHECK: #[[ANY_DATA:.+]] = #llvm.tbaa_type_desc<id = "any data access", members = {<#[[ANY_ACCESS]], 0>}>
5050
// CHECK: #[[ANY_GLBL:.+]] = #llvm.tbaa_type_desc<id = "global data", members = {<#[[ANY_DATA]], 0>}>
5151
// CHECK: #[[ANY_ARG:.+]] = #llvm.tbaa_type_desc<id = "dummy arg data", members = {<#[[ANY_DATA]], 0>}>
52+
// CHECK: #[[ANY_DIRECT:.+]] = #llvm.tbaa_type_desc<id = "direct data", members = {<#[[ANY_DATA]], 0>}>
5253
// CHECK: #[[GLBL_ZSTART:.+]] = #llvm.tbaa_type_desc<id = "global data/_QMmodEzstart", members = {<#[[ANY_GLBL]], 0>}>
5354
// CHECK: #[[GLBL_ZSTOP:.+]] = #llvm.tbaa_type_desc<id = "global data/_QMmodEzstop", members = {<#[[ANY_GLBL]], 0>}>
5455
// CHECK: #[[GLBL_YSTART:.+]] = #llvm.tbaa_type_desc<id = "global data/_QMmodEystart", members = {<#[[ANY_GLBL]], 0>}>
5556
// CHECK: #[[GLBL_YSTOP:.+]] = #llvm.tbaa_type_desc<id = "global data/_QMmodEystop", members = {<#[[ANY_GLBL]], 0>}>
5657
// CHECK: #[[GLBL_XSTART:.+]] = #llvm.tbaa_type_desc<id = "global data/_QMmodExstart", members = {<#[[ANY_GLBL]], 0>}>
5758
// CHECK: #[[ARG_LOW:.+]] = #llvm.tbaa_type_desc<id = "dummy arg data/_QMmodFcalleeElow", members = {<#[[ANY_ARG]], 0>}>
58-
// CHECK: #[[GLBL_A:.+]] = #llvm.tbaa_type_desc<id = "global data/_QMmodEa", members = {<#[[ANY_GLBL]], 0>}>
59-
// CHECK: #[[GLBL_B:.+]] = #llvm.tbaa_type_desc<id = "global data/_QMmodEb", members = {<#[[ANY_GLBL]], 0>}>
59+
// CHECK: #[[DIRECT_A:.+]] = #llvm.tbaa_type_desc<id = "direct data/_QMmodEa", members = {<#[[ANY_DIRECT]], 0>}>
60+
// CHECK: #[[DIRECT_B:.+]] = #llvm.tbaa_type_desc<id = "direct data/_QMmodEb", members = {<#[[ANY_DIRECT]], 0>}>
6061
// CHECK: #[[ARG_Z:.+]] = #llvm.tbaa_type_desc<id = "dummy arg data/_QMmodFcalleeEz", members = {<#[[ANY_ARG]], 0>}>
6162
// CHECK: #[[GLBL_DYINV:.+]] = #llvm.tbaa_type_desc<id = "global data/_QMmodEdyinv", members = {<#[[ANY_GLBL]], 0>}>
6263
// CHECK: #[[ARG_Y:.+]] = #llvm.tbaa_type_desc<id = "dummy arg data/_QMmodFcalleeEy", members = {<#[[ANY_ARG]], 0>}>
@@ -67,8 +68,8 @@
6768
// CHECK: #[[GLBL_YSTOP_TAG:.+]] = #llvm.tbaa_tag<base_type = #[[GLBL_YSTOP]], access_type = #[[GLBL_YSTOP]], offset = 0>
6869
// CHECK: #[[GLBL_XSTART_TAG:.+]] = #llvm.tbaa_tag<base_type = #[[GLBL_XSTART]], access_type = #[[GLBL_XSTART]], offset = 0>
6970
// CHECK: #[[ARG_LOW_TAG:.+]] = #llvm.tbaa_tag<base_type = #[[ARG_LOW]], access_type = #[[ARG_LOW]], offset = 0>
70-
// CHECK: #[[GLBL_A_TAG:.+]] = #llvm.tbaa_tag<base_type = #[[GLBL_A]], access_type = #[[GLBL_A]], offset = 0>
71-
// CHECK: #[[GLBL_B_TAG:.+]] = #llvm.tbaa_tag<base_type = #[[GLBL_B]], access_type = #[[GLBL_B]], offset = 0>
71+
// CHECK: #[[DIRECT_A_TAG:.+]] = #llvm.tbaa_tag<base_type = #[[DIRECT_A]], access_type = #[[DIRECT_A]], offset = 0>
72+
// CHECK: #[[DIRECT_B_TAG:.+]] = #llvm.tbaa_tag<base_type = #[[DIRECT_B]], access_type = #[[DIRECT_B]], offset = 0>
7273
// CHECK: #[[ARG_Z_TAG:.+]] = #llvm.tbaa_tag<base_type = #[[ARG_Z]], access_type = #[[ARG_Z]], offset = 0>
7374
// CHECK: #[[GLBL_DYINV_TAG:.+]] = #llvm.tbaa_tag<base_type = #[[GLBL_DYINV]], access_type = #[[GLBL_DYINV]], offset = 0>
7475
// CHECK: #[[ARG_Y_TAG:.+]] = #llvm.tbaa_tag<base_type = #[[ARG_Y]], access_type = #[[ARG_Y]], offset = 0>
@@ -315,7 +316,7 @@
315316
// CHECK: %[[VAL_83:.*]]:3 = fir.box_dims %[[VAL_79]], %[[VAL_4]] : (!fir.box<!fir.heap<!fir.array<?xf32>>>, index) -> (index, index, index)
316317
// CHECK: %[[VAL_84:.*]] = fir.shape_shift %[[VAL_83]]#0, %[[VAL_83]]#1 : (index, index) -> !fir.shapeshift<1>
317318
// CHECK: %[[VAL_85:.*]] = fir.array_coor %[[VAL_82]](%[[VAL_84]]) %[[VAL_81]] : (!fir.heap<!fir.array<?xf32>>, !fir.shapeshift<1>, i64) -> !fir.ref<f32>
318-
// CHECK: %[[VAL_86:.*]] = fir.load %[[VAL_85]] {tbaa = [#[[GLBL_A_TAG]]]} : !fir.ref<f32>
319+
// CHECK: %[[VAL_86:.*]] = fir.load %[[VAL_85]] {tbaa = [#[[DIRECT_A_TAG]]]} : !fir.ref<f32>
319320
// load from box
320321
// CHECK: %[[VAL_87:.*]] = fir.load %[[VAL_35]] : !fir.ref<!fir.box<!fir.heap<!fir.array<?x?x?xf32>>>>
321322
// load from local allocation
@@ -338,7 +339,7 @@
338339
// CHECK: %[[VAL_102:.*]]:3 = fir.box_dims %[[VAL_100]], %[[VAL_4]] : (!fir.box<!fir.heap<!fir.array<?xf32>>>, index) -> (index, index, index)
339340
// CHECK: %[[VAL_103:.*]] = fir.shape_shift %[[VAL_102]]#0, %[[VAL_102]]#1 : (index, index) -> !fir.shapeshift<1>
340341
// CHECK: %[[VAL_104:.*]] = fir.array_coor %[[VAL_101]](%[[VAL_103]]) %[[VAL_81]] : (!fir.heap<!fir.array<?xf32>>, !fir.shapeshift<1>, i64) -> !fir.ref<f32>
341-
// CHECK: %[[VAL_105:.*]] = fir.load %[[VAL_104]] {tbaa = [#[[GLBL_B_TAG]]]} : !fir.ref<f32>
342+
// CHECK: %[[VAL_105:.*]] = fir.load %[[VAL_104]] {tbaa = [#[[DIRECT_B_TAG]]]} : !fir.ref<f32>
342343
// CHECK: %[[VAL_106:.*]] = fir.array_coor %[[VAL_39]] %[[VAL_89]], %[[VAL_81]], %[[VAL_91]] : (!fir.box<!fir.array<?x?x?xf32>>, i64, i64, i64) -> !fir.ref<f32>
343344
// CHECK: %[[VAL_107:.*]] = fir.load %[[VAL_106]] {tbaa = [#[[ARG_Z_TAG]]]} : !fir.ref<f32>
344345
// CHECK: %[[VAL_108:.*]] = arith.subi %[[VAL_80]], %[[VAL_6]] : i32

0 commit comments

Comments
 (0)