Skip to content

Commit 75e2a26

Browse files
committed
Improve dummy argument identification
Make sure they're not block arguments not on functions. Encapsulate the check.
1 parent fd358af commit 75e2a26

File tree

3 files changed

+28
-29
lines changed

3 files changed

+28
-29
lines changed

flang/include/flang/Optimizer/Analysis/AliasAnalysis.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ struct AliasAnalysis {
9393

9494
/// Return the memory source of a value.
9595
Source getSource(mlir::Value);
96+
97+
/// Return true if `v` is a dummy argument.
98+
static bool isDummyArgument(mlir::Value v);
9699
};
97100

98101
inline llvm::raw_ostream &operator<<(llvm::raw_ostream &os,

flang/lib/Optimizer/Analysis/AliasAnalysis.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,6 @@ using namespace mlir;
2828
// AliasAnalysis: alias
2929
//===----------------------------------------------------------------------===//
3030

31-
static bool isDummyArgument(mlir::Value v) {
32-
auto blockArg{v.dyn_cast<mlir::BlockArgument>()};
33-
if (!blockArg)
34-
return false;
35-
36-
return blockArg.getOwner()->isEntryBlock();
37-
}
38-
3931
/// Temporary function to skip through all the no op operations
4032
/// TODO: Generalize support of fir.load
4133
static mlir::Value getOriginalDef(mlir::Value v) {
@@ -429,4 +421,13 @@ AliasAnalysis::Source AliasAnalysis::getSource(mlir::Value v) {
429421
return {v, type, ty, attributes, approximateSource};
430422
}
431423

424+
bool AliasAnalysis::isDummyArgument(mlir::Value v) {
425+
auto blockArg{v.dyn_cast<mlir::BlockArgument>()};
426+
if (!blockArg)
427+
return false;
428+
auto *owner{blockArg.getOwner()};
429+
return owner->isEntryBlock() &&
430+
mlir::isa<mlir::FunctionOpInterface>(owner->getParentOp());
431+
}
432+
432433
} // namespace fir

flang/lib/Optimizer/Transforms/AddAliasTags.cpp

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -170,29 +170,24 @@ void AddAliasTagsPass::runOnAliasInterface(fir::FirAliasTagOpInterface op,
170170
LLVM_DEBUG(llvm::dbgs().indent(2) << "Found reference to direct " << name
171171
<< " at " << *op << "\n");
172172
tag = state.getFuncTree(func).directDataTree.getTag(name);
173-
} else {
174-
bool sourceIsDummyArgument = false;
175-
if (auto blockArg =
176-
source.u.get<mlir::Value>().dyn_cast<mlir::BlockArgument>())
177-
sourceIsDummyArgument = blockArg.getOwner()->isEntryBlock();
178-
if (sourceIsDummyArgument) {
179-
std::string name = getFuncArgName(source.u.get<mlir::Value>());
180-
if (!name.empty()) {
181-
LLVM_DEBUG(llvm::dbgs().indent(2)
182-
<< "Found reference to direct from dummy argument " << name
183-
<< " at " << *op << "\n");
184-
tag = state.getFuncTree(func).directDataTree.getTag(name);
185-
} else {
186-
LLVM_DEBUG(llvm::dbgs().indent(2)
187-
<< "WARN: for direct, couldn't find a name for dummy "
188-
<< "argument " << *op << "\n");
189-
}
173+
} else if (fir::AliasAnalysis::isDummyArgument(
174+
source.u.get<mlir::Value>())) {
175+
std::string name = getFuncArgName(source.u.get<mlir::Value>());
176+
if (!name.empty()) {
177+
LLVM_DEBUG(llvm::dbgs().indent(2)
178+
<< "Found reference to direct from dummy argument " << name
179+
<< " at " << *op << "\n");
180+
tag = state.getFuncTree(func).directDataTree.getTag(name);
190181
} else {
191-
// SourceKind::Direct is likely to be extended to more cases in the
192-
// future
193-
LLVM_DEBUG(llvm::dbgs().indent(2) << "Can't get name for direct "
194-
<< source << " at " << *op << "\n");
182+
LLVM_DEBUG(llvm::dbgs().indent(2)
183+
<< "WARN: for direct, couldn't find a name for dummy "
184+
<< "argument " << *op << "\n");
195185
}
186+
} else {
187+
// SourceKind::Direct is likely to be extended to more cases in the
188+
// future
189+
LLVM_DEBUG(llvm::dbgs().indent(2) << "Can't get name for direct "
190+
<< source << " at " << *op << "\n");
196191
}
197192

198193
// TBAA for local allocations

0 commit comments

Comments
 (0)