@@ -48,12 +48,21 @@ static llvm::cl::opt<bool>
48
48
llvm::cl::Hidden,
49
49
llvm::cl::desc(" Add TBAA tags to local allocations." ));
50
50
51
+ // Engineering option to triage TBAA tags attachment for accesses
52
+ // of allocatable entities.
53
+ static llvm::cl::opt<unsigned > localAllocsThreshold (
54
+ " local-alloc-tbaa-threshold" , llvm::cl::init(0 ), llvm::cl::ReallyHidden,
55
+ llvm::cl::desc(" If present, stops generating TBAA tags for accesses of "
56
+ " local allocations after N accesses in a module" ));
57
+
51
58
namespace {
52
59
53
60
// / Shared state per-module
54
61
class PassState {
55
62
public:
56
- PassState (mlir::DominanceInfo &domInfo) : domInfo(domInfo) {}
63
+ PassState (mlir::DominanceInfo &domInfo,
64
+ std::optional<unsigned > localAllocsThreshold)
65
+ : domInfo(domInfo), localAllocsThreshold(localAllocsThreshold) {}
57
66
// / memoised call to fir::AliasAnalysis::getSource
58
67
inline const fir::AliasAnalysis::Source &getSource (mlir::Value value) {
59
68
if (!analysisCache.contains (value))
@@ -84,6 +93,11 @@ class PassState {
84
93
// (e.g. !fir.ref<!fir.type<Derived{f:!fir.box<!fir.heap<f32>>}>>).
85
94
bool typeReferencesDescriptor (mlir::Type type);
86
95
96
+ // Returns true if we can attach a TBAA tag to an access of an allocatable
97
+ // entities. It checks if localAllocsThreshold allows the next tag
98
+ // attachment.
99
+ bool attachLocalAllocTag ();
100
+
87
101
private:
88
102
mlir::DominanceInfo &domInfo;
89
103
fir::AliasAnalysis analysis;
@@ -103,6 +117,8 @@ class PassState {
103
117
// Local pass cache for derived types that contain descriptor
104
118
// member(s), to avoid the cost of isRecordWithDescriptorMember().
105
119
llvm::DenseSet<mlir::Type> typesContainingDescriptors;
120
+
121
+ std::optional<unsigned > localAllocsThreshold;
106
122
};
107
123
108
124
// Process fir.dummy_scope operations in the given func:
@@ -169,6 +185,19 @@ bool PassState::typeReferencesDescriptor(mlir::Type type) {
169
185
return false ;
170
186
}
171
187
188
+ bool PassState::attachLocalAllocTag () {
189
+ if (!localAllocsThreshold)
190
+ return true ;
191
+ if (*localAllocsThreshold == 0 ) {
192
+ LLVM_DEBUG (llvm::dbgs ().indent (2 )
193
+ << " WARN: not assigning TBAA tag for an allocated entity access "
194
+ " due to the threshold\n " );
195
+ return false ;
196
+ }
197
+ --*localAllocsThreshold;
198
+ return true ;
199
+ }
200
+
172
201
class AddAliasTagsPass : public fir ::impl::AddAliasTagsBase<AddAliasTagsPass> {
173
202
public:
174
203
void runOnOperation () override ;
@@ -335,16 +364,16 @@ void AddAliasTagsPass::runOnAliasInterface(fir::FirAliasTagOpInterface op,
335
364
LLVM_DEBUG (llvm::dbgs ().indent (2 )
336
365
<< " WARN: unknown defining op for SourceKind::Allocate " << *op
337
366
<< " \n " );
338
- } else if (source.isPointer ()) {
367
+ } else if (source.isPointer () && state. attachLocalAllocTag () ) {
339
368
LLVM_DEBUG (llvm::dbgs ().indent (2 )
340
369
<< " Found reference to allocation at " << *op << " \n " );
341
370
tag = state.getFuncTreeWithScope (func, scopeOp).targetDataTree .getTag ();
342
- } else if (name) {
371
+ } else if (name && state. attachLocalAllocTag () ) {
343
372
LLVM_DEBUG (llvm::dbgs ().indent (2 ) << " Found reference to allocation "
344
373
<< name << " at " << *op << " \n " );
345
374
tag = state.getFuncTreeWithScope (func, scopeOp)
346
375
.allocatedDataTree .getTag (*name);
347
- } else {
376
+ } else if (state. attachLocalAllocTag ()) {
348
377
LLVM_DEBUG (llvm::dbgs ().indent (2 )
349
378
<< " WARN: couldn't find a name for allocation " << *op
350
379
<< " \n " );
@@ -372,7 +401,9 @@ void AddAliasTagsPass::runOnOperation() {
372
401
// thinks the pass operates on), then the real work of the pass is done in
373
402
// runOnAliasInterface
374
403
auto &domInfo = getAnalysis<mlir::DominanceInfo>();
375
- PassState state (domInfo);
404
+ PassState state (domInfo, localAllocsThreshold.getPosition ()
405
+ ? std::optional<unsigned >(localAllocsThreshold)
406
+ : std::nullopt);
376
407
377
408
mlir::ModuleOp mod = getOperation ();
378
409
mod.walk (
0 commit comments