-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[flang] Migrate away from PointerUnion::{is,get} (NFC) #120880
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[flang] Migrate away from PointerUnion::{is,get} (NFC) #120880
Conversation
Note that PointerUnion::{is,get} have been soft deprecated in PointerUnion.h: // FIXME: Replace the uses of is(), get() and dyn_cast() with // isa<T>, cast<T> and the llvm::dyn_cast<T> I'm not touching PointerUnion::dyn_cast for now because it's a bit complicated; we could blindly migrate it to dyn_cast_if_present, but we should probably use dyn_cast when the operand is known to be non-null.
@llvm/pr-subscribers-flang-codegen @llvm/pr-subscribers-flang-fir-hlfir Author: Kazu Hirata (kazutakahirata) ChangesNote that PointerUnion::{is,get} have been soft deprecated in // FIXME: Replace the uses of is(), get() and dyn_cast() with I'm not touching PointerUnion::dyn_cast for now because it's a bit Full diff: https://github.com/llvm/llvm-project/pull/120880.diff 3 Files Affected:
diff --git a/flang/lib/Optimizer/CodeGen/CodeGen.cpp b/flang/lib/Optimizer/CodeGen/CodeGen.cpp
index 1714b9e191db76..7bee0232b0d46d 100644
--- a/flang/lib/Optimizer/CodeGen/CodeGen.cpp
+++ b/flang/lib/Optimizer/CodeGen/CodeGen.cpp
@@ -1613,12 +1613,13 @@ struct EmboxCommonConversion : public fir::FIROpConversion<OP> {
if (gepArgs.size() != 1)
fir::emitFatalError(loc,
"corrupted substring GEP in fir.embox/fir.rebox");
- mlir::Type outterOffsetTy = gepArgs[0].get<mlir::Value>().getType();
+ mlir::Type outterOffsetTy =
+ llvm::cast<mlir::Value>(gepArgs[0]).getType();
mlir::Value cast =
this->integerCast(loc, rewriter, outterOffsetTy, *substringOffset);
gepArgs[0] = rewriter.create<mlir::LLVM::AddOp>(
- loc, outterOffsetTy, gepArgs[0].get<mlir::Value>(), cast);
+ loc, outterOffsetTy, llvm::cast<mlir::Value>(gepArgs[0]), cast);
}
}
mlir::Type llvmPtrTy = ::getLlvmPtrType(resultTy.getContext());
diff --git a/flang/lib/Optimizer/Transforms/AddAliasTags.cpp b/flang/lib/Optimizer/Transforms/AddAliasTags.cpp
index f1e70875de0ba7..e6fc2ed992e38a 100644
--- a/flang/lib/Optimizer/Transforms/AddAliasTags.cpp
+++ b/flang/lib/Optimizer/Transforms/AddAliasTags.cpp
@@ -227,7 +227,7 @@ void AddAliasTagsPass::runOnAliasInterface(fir::FirAliasTagOpInterface op,
source.kind == fir::AliasAnalysis::SourceKind::Argument) {
LLVM_DEBUG(llvm::dbgs().indent(2)
<< "Found reference to dummy argument at " << *op << "\n");
- std::string name = getFuncArgName(source.origin.u.get<mlir::Value>());
+ std::string name = getFuncArgName(llvm::cast<mlir::Value>(source.origin.u));
if (!name.empty())
tag = state.getFuncTreeWithScope(func, scopeOp)
.dummyArgDataTree.getTag(name);
@@ -240,7 +240,7 @@ void AddAliasTagsPass::runOnAliasInterface(fir::FirAliasTagOpInterface op,
} else if (enableGlobals &&
source.kind == fir::AliasAnalysis::SourceKind::Global &&
!source.isBoxData()) {
- mlir::SymbolRefAttr glbl = source.origin.u.get<mlir::SymbolRefAttr>();
+ mlir::SymbolRefAttr glbl = llvm::cast<mlir::SymbolRefAttr>(source.origin.u);
const char *name = glbl.getRootReference().data();
LLVM_DEBUG(llvm::dbgs().indent(2) << "Found reference to global " << name
<< " at " << *op << "\n");
@@ -250,8 +250,7 @@ void AddAliasTagsPass::runOnAliasInterface(fir::FirAliasTagOpInterface op,
} else if (enableDirect &&
source.kind == fir::AliasAnalysis::SourceKind::Global &&
source.isBoxData()) {
- if (source.origin.u.is<mlir::SymbolRefAttr>()) {
- mlir::SymbolRefAttr glbl = source.origin.u.get<mlir::SymbolRefAttr>();
+ if (auto glbl = llvm::dyn_cast<mlir::SymbolRefAttr>(source.origin.u)) {
const char *name = glbl.getRootReference().data();
LLVM_DEBUG(llvm::dbgs().indent(2) << "Found reference to direct " << name
<< " at " << *op << "\n");
@@ -269,7 +268,7 @@ void AddAliasTagsPass::runOnAliasInterface(fir::FirAliasTagOpInterface op,
source.kind == fir::AliasAnalysis::SourceKind::Allocate) {
std::optional<llvm::StringRef> name;
mlir::Operation *sourceOp =
- source.origin.u.get<mlir::Value>().getDefiningOp();
+ llvm::cast<mlir::Value>(source.origin.u).getDefiningOp();
if (auto alloc = mlir::dyn_cast_or_null<fir::AllocaOp>(sourceOp))
name = alloc.getUniqName();
else if (auto alloc = mlir::dyn_cast_or_null<fir::AllocMemOp>(sourceOp))
diff --git a/flang/lib/Optimizer/Transforms/StackArrays.cpp b/flang/lib/Optimizer/Transforms/StackArrays.cpp
index f9281000d21f0b..bdcb8199b790de 100644
--- a/flang/lib/Optimizer/Transforms/StackArrays.cpp
+++ b/flang/lib/Optimizer/Transforms/StackArrays.cpp
@@ -76,8 +76,9 @@ class InsertionPoint {
/// Get contained pointer type or nullptr
template <class T>
T *tryGetPtr() const {
- if (location.is<T *>())
- return location.get<T *>();
+ // Use llvm::dyn_cast_if_present because location may be null here.
+ if (T *ptr = llvm::dyn_cast_if_present<T *>(location))
+ return ptr;
return nullptr;
}
|
Note that PointerUnion::{is,get} have been soft deprecated in
PointerUnion.h:
// FIXME: Replace the uses of is(), get() and dyn_cast() with
// isa, cast and the llvm::dyn_cast
I'm not touching PointerUnion::dyn_cast for now because it's a bit
complicated; we could blindly migrate it to dyn_cast_if_present, but
we should probably use dyn_cast when the operand is known to be
non-null.