-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[CodeGen] Migrate away from PointerUnion::{is,get} (NFC) #118600
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
[CodeGen] Migrate away from PointerUnion::{is,get} (NFC) #118600
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-clang-codegen @llvm/pr-subscribers-clang 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/118600.diff 3 Files Affected:
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 7c8d962fa5a920..3cefc9da66ddb8 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -4529,7 +4529,7 @@ void CodeGenFunction::EmitCallArgs(
ArgTypes.assign(MD->param_type_begin() + ParamsToSkip,
MD->param_type_end());
} else {
- const auto *FPT = Prototype.P.get<const FunctionProtoType *>();
+ const auto *FPT = cast<const FunctionProtoType *>(Prototype.P);
IsVariadic = FPT->isVariadic();
ExplicitCC = FPT->getExtInfo().getCC();
ArgTypes.assign(FPT->param_type_begin() + ParamsToSkip,
diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index 6a5860242035b2..2deb91f27e37b9 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -7770,7 +7770,7 @@ class MappableExprsHandler {
if (const auto *Base = Data.dyn_cast<const CXXRecordDecl *>())
getPlainLayout(Base, Layout, /*AsBase=*/true);
else
- Layout.push_back(Data.get<const FieldDecl *>());
+ Layout.push_back(cast<const FieldDecl *>(Data));
}
}
@@ -8333,9 +8333,9 @@ class MappableExprsHandler {
MapCombinedInfoTy &CombinedInfo, llvm::OpenMPIRBuilder &OMPBuilder,
const llvm::DenseSet<CanonicalDeclPtr<const Decl>> &SkipVarSet =
llvm::DenseSet<CanonicalDeclPtr<const Decl>>()) const {
- assert(CurDir.is<const OMPExecutableDirective *>() &&
+ assert(isa<const OMPExecutableDirective *>(CurDir) &&
"Expect a executable directive");
- const auto *CurExecDir = CurDir.get<const OMPExecutableDirective *>();
+ const auto *CurExecDir = cast<const OMPExecutableDirective *>(CurDir);
generateAllInfoForClauses(CurExecDir->clauses(), CombinedInfo, OMPBuilder,
SkipVarSet);
}
@@ -8345,9 +8345,9 @@ class MappableExprsHandler {
/// in \a CombinedInfo).
void generateAllInfoForMapper(MapCombinedInfoTy &CombinedInfo,
llvm::OpenMPIRBuilder &OMPBuilder) const {
- assert(CurDir.is<const OMPDeclareMapperDecl *>() &&
+ assert(isa<const OMPDeclareMapperDecl *>(CurDir) &&
"Expect a declare mapper directive");
- const auto *CurMapperDir = CurDir.get<const OMPDeclareMapperDecl *>();
+ const auto *CurMapperDir = cast<const OMPDeclareMapperDecl *>(CurDir);
generateAllInfoForClauses(CurMapperDir->clauses(), CombinedInfo,
OMPBuilder);
}
@@ -8519,9 +8519,9 @@ class MappableExprsHandler {
DeclComponentLists.emplace_back(MCL, OMPC_MAP_tofrom, Unknown,
/*IsImpicit = */ true, nullptr,
nullptr);
- assert(CurDir.is<const OMPExecutableDirective *>() &&
+ assert(isa<const OMPExecutableDirective *>(CurDir) &&
"Expect a executable directive");
- const auto *CurExecDir = CurDir.get<const OMPExecutableDirective *>();
+ const auto *CurExecDir = cast<const OMPExecutableDirective *>(CurDir);
bool HasMapBasePtr = false;
bool HasMapArraySec = false;
for (const auto *C : CurExecDir->getClausesOfKind<OMPMapClause>()) {
diff --git a/clang/lib/CodeGen/ConstantInitBuilder.cpp b/clang/lib/CodeGen/ConstantInitBuilder.cpp
index 549d5dd66b1230..7f7e90e0f47634 100644
--- a/clang/lib/CodeGen/ConstantInitBuilder.cpp
+++ b/clang/lib/CodeGen/ConstantInitBuilder.cpp
@@ -20,10 +20,10 @@ using namespace CodeGen;
llvm::Type *ConstantInitFuture::getType() const {
assert(Data && "dereferencing null future");
- if (Data.is<llvm::Constant*>()) {
- return Data.get<llvm::Constant*>()->getType();
+ if (const auto *C = dyn_cast<llvm::Constant *>(Data)) {
+ return C->getType();
} else {
- return Data.get<ConstantInitBuilderBase*>()->Buffer[0]->getType();
+ return cast<ConstantInitBuilderBase *>(Data)->Buffer[0]->getType();
}
}
@@ -37,8 +37,8 @@ void ConstantInitFuture::abandon() {
void ConstantInitFuture::installInGlobal(llvm::GlobalVariable *GV) {
assert(Data && "installing null future");
- if (Data.is<llvm::Constant*>()) {
- GV->setInitializer(Data.get<llvm::Constant*>());
+ if (auto *C = dyn_cast<llvm::Constant *>(Data)) {
+ GV->setInitializer(C);
} else {
auto &builder = *Data.get<ConstantInitBuilderBase*>();
assert(builder.Buffer.size() == 1);
|
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.