Skip to content

[llvm] Migrate away from PointerUnion::{is,get,dyn_cast} (NFC) #115681

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

Merged

Conversation

kazutakahirata
Copy link
Contributor

Note that PointerUnion::{is,get,dyn_cast} 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

Note that PointerUnion::{is,get,dyn_cast} 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>
@llvmbot
Copy link
Member

llvmbot commented Nov 11, 2024

@llvm/pr-subscribers-tablegen
@llvm/pr-subscribers-debuginfo

@llvm/pr-subscribers-llvm-globalisel

Author: Kazu Hirata (kazutakahirata)

Changes

Note that PointerUnion::{is,get,dyn_cast} 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>


Full diff: https://github.com/llvm/llvm-project/pull/115681.diff

2 Files Affected:

  • (modified) llvm/include/llvm/IR/DebugProgramInstruction.h (+12-12)
  • (modified) llvm/utils/TableGen/GlobalISelEmitter.cpp (+6-6)
diff --git a/llvm/include/llvm/IR/DebugProgramInstruction.h b/llvm/include/llvm/IR/DebugProgramInstruction.h
index a6605052ba83d3..e979d8840cbaf8 100644
--- a/llvm/include/llvm/IR/DebugProgramInstruction.h
+++ b/llvm/include/llvm/IR/DebugProgramInstruction.h
@@ -371,29 +371,29 @@ class DbgVariableRecord : public DbgRecord, protected DebugValueUser {
       return I == RHS.I;
     }
     const Value *operator*() const {
-      ValueAsMetadata *VAM = I.is<ValueAsMetadata *>()
-                                 ? I.get<ValueAsMetadata *>()
-                                 : *I.get<ValueAsMetadata **>();
+      ValueAsMetadata *VAM = isa<ValueAsMetadata *>(I)
+                                 ? cast<ValueAsMetadata *>(I)
+                                 : *cast<ValueAsMetadata **>(I);
       return VAM->getValue();
     };
     Value *operator*() {
-      ValueAsMetadata *VAM = I.is<ValueAsMetadata *>()
-                                 ? I.get<ValueAsMetadata *>()
-                                 : *I.get<ValueAsMetadata **>();
+      ValueAsMetadata *VAM = isa<ValueAsMetadata *>(I)
+                                 ? cast<ValueAsMetadata *>(I)
+                                 : *cast<ValueAsMetadata **>(I);
       return VAM->getValue();
     }
     location_op_iterator &operator++() {
-      if (I.is<ValueAsMetadata *>())
-        I = I.get<ValueAsMetadata *>() + 1;
+      if (auto *VAM = dyn_cast<ValueAsMetadata *>(I))
+        I = VAM + 1;
       else
-        I = I.get<ValueAsMetadata **>() + 1;
+        I = cast<ValueAsMetadata **>(I) + 1;
       return *this;
     }
     location_op_iterator &operator--() {
-      if (I.is<ValueAsMetadata *>())
-        I = I.get<ValueAsMetadata *>() - 1;
+      if (auto *VAM = dyn_cast<ValueAsMetadata *>(I))
+        I = VAM - 1;
       else
-        I = I.get<ValueAsMetadata **>() - 1;
+        I = cast<ValueAsMetadata **>(I) - 1;
       return *this;
     }
   };
diff --git a/llvm/utils/TableGen/GlobalISelEmitter.cpp b/llvm/utils/TableGen/GlobalISelEmitter.cpp
index 895743ad8230c8..a3344718cb3626 100644
--- a/llvm/utils/TableGen/GlobalISelEmitter.cpp
+++ b/llvm/utils/TableGen/GlobalISelEmitter.cpp
@@ -2118,9 +2118,9 @@ Expected<RuleMatcher> GlobalISelEmitter::runOnPattern(const PatternToMatch &P) {
         return failedImport(
             "Cannot infer register class for SUBREG_TO_REG operand #0");
       MatchedRC = *MaybeRegClass;
-    } else if (MatchedRC.get<const Record *>()->isSubClassOf("RegisterOperand"))
-      MatchedRC = MatchedRC.get<const Record *>()->getValueAsDef("RegClass");
-    else if (!MatchedRC.get<const Record *>()->isSubClassOf("RegisterClass"))
+    } else if (cast<const Record *>(MatchedRC)->isSubClassOf("RegisterOperand"))
+      MatchedRC = cast<const Record *>(MatchedRC)->getValueAsDef("RegClass");
+    else if (!cast<const Record *>(MatchedRC)->isSubClassOf("RegisterClass"))
       return failedImport("Dst MI def isn't a register class" + to_string(Dst));
 
     OperandMatcher &OM = InsnMatcher.getOperand(OpIdx);
@@ -2130,10 +2130,10 @@ Expected<RuleMatcher> GlobalISelEmitter::runOnPattern(const PatternToMatch &P) {
     // GIM_CheckIsSameOperand predicates by the defineOperand method.
     OM.setSymbolicName(getMangledRootDefName(DstIOperand.Name));
     M.defineOperand(OM.getSymbolicName(), OM);
-    if (MatchedRC.is<const Record *>())
-      MatchedRC = &Target.getRegisterClass(MatchedRC.get<const Record *>());
+    if (auto *R = dyn_cast<const Record *>(MatchedRC))
+      MatchedRC = &Target.getRegisterClass(R);
     OM.addPredicate<RegisterBankOperandMatcher>(
-        *MatchedRC.get<const CodeGenRegisterClass *>());
+        *cast<const CodeGenRegisterClass *>(MatchedRC));
     ++OpIdx;
   }
 

@llvmbot
Copy link
Member

llvmbot commented Nov 11, 2024

@llvm/pr-subscribers-llvm-ir

Author: Kazu Hirata (kazutakahirata)

Changes

Note that PointerUnion::{is,get,dyn_cast} 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>


Full diff: https://github.com/llvm/llvm-project/pull/115681.diff

2 Files Affected:

  • (modified) llvm/include/llvm/IR/DebugProgramInstruction.h (+12-12)
  • (modified) llvm/utils/TableGen/GlobalISelEmitter.cpp (+6-6)
diff --git a/llvm/include/llvm/IR/DebugProgramInstruction.h b/llvm/include/llvm/IR/DebugProgramInstruction.h
index a6605052ba83d3..e979d8840cbaf8 100644
--- a/llvm/include/llvm/IR/DebugProgramInstruction.h
+++ b/llvm/include/llvm/IR/DebugProgramInstruction.h
@@ -371,29 +371,29 @@ class DbgVariableRecord : public DbgRecord, protected DebugValueUser {
       return I == RHS.I;
     }
     const Value *operator*() const {
-      ValueAsMetadata *VAM = I.is<ValueAsMetadata *>()
-                                 ? I.get<ValueAsMetadata *>()
-                                 : *I.get<ValueAsMetadata **>();
+      ValueAsMetadata *VAM = isa<ValueAsMetadata *>(I)
+                                 ? cast<ValueAsMetadata *>(I)
+                                 : *cast<ValueAsMetadata **>(I);
       return VAM->getValue();
     };
     Value *operator*() {
-      ValueAsMetadata *VAM = I.is<ValueAsMetadata *>()
-                                 ? I.get<ValueAsMetadata *>()
-                                 : *I.get<ValueAsMetadata **>();
+      ValueAsMetadata *VAM = isa<ValueAsMetadata *>(I)
+                                 ? cast<ValueAsMetadata *>(I)
+                                 : *cast<ValueAsMetadata **>(I);
       return VAM->getValue();
     }
     location_op_iterator &operator++() {
-      if (I.is<ValueAsMetadata *>())
-        I = I.get<ValueAsMetadata *>() + 1;
+      if (auto *VAM = dyn_cast<ValueAsMetadata *>(I))
+        I = VAM + 1;
       else
-        I = I.get<ValueAsMetadata **>() + 1;
+        I = cast<ValueAsMetadata **>(I) + 1;
       return *this;
     }
     location_op_iterator &operator--() {
-      if (I.is<ValueAsMetadata *>())
-        I = I.get<ValueAsMetadata *>() - 1;
+      if (auto *VAM = dyn_cast<ValueAsMetadata *>(I))
+        I = VAM - 1;
       else
-        I = I.get<ValueAsMetadata **>() - 1;
+        I = cast<ValueAsMetadata **>(I) - 1;
       return *this;
     }
   };
diff --git a/llvm/utils/TableGen/GlobalISelEmitter.cpp b/llvm/utils/TableGen/GlobalISelEmitter.cpp
index 895743ad8230c8..a3344718cb3626 100644
--- a/llvm/utils/TableGen/GlobalISelEmitter.cpp
+++ b/llvm/utils/TableGen/GlobalISelEmitter.cpp
@@ -2118,9 +2118,9 @@ Expected<RuleMatcher> GlobalISelEmitter::runOnPattern(const PatternToMatch &P) {
         return failedImport(
             "Cannot infer register class for SUBREG_TO_REG operand #0");
       MatchedRC = *MaybeRegClass;
-    } else if (MatchedRC.get<const Record *>()->isSubClassOf("RegisterOperand"))
-      MatchedRC = MatchedRC.get<const Record *>()->getValueAsDef("RegClass");
-    else if (!MatchedRC.get<const Record *>()->isSubClassOf("RegisterClass"))
+    } else if (cast<const Record *>(MatchedRC)->isSubClassOf("RegisterOperand"))
+      MatchedRC = cast<const Record *>(MatchedRC)->getValueAsDef("RegClass");
+    else if (!cast<const Record *>(MatchedRC)->isSubClassOf("RegisterClass"))
       return failedImport("Dst MI def isn't a register class" + to_string(Dst));
 
     OperandMatcher &OM = InsnMatcher.getOperand(OpIdx);
@@ -2130,10 +2130,10 @@ Expected<RuleMatcher> GlobalISelEmitter::runOnPattern(const PatternToMatch &P) {
     // GIM_CheckIsSameOperand predicates by the defineOperand method.
     OM.setSymbolicName(getMangledRootDefName(DstIOperand.Name));
     M.defineOperand(OM.getSymbolicName(), OM);
-    if (MatchedRC.is<const Record *>())
-      MatchedRC = &Target.getRegisterClass(MatchedRC.get<const Record *>());
+    if (auto *R = dyn_cast<const Record *>(MatchedRC))
+      MatchedRC = &Target.getRegisterClass(R);
     OM.addPredicate<RegisterBankOperandMatcher>(
-        *MatchedRC.get<const CodeGenRegisterClass *>());
+        *cast<const CodeGenRegisterClass *>(MatchedRC));
     ++OpIdx;
   }
 

@kazutakahirata kazutakahirata merged commit b9fb6b6 into llvm:main Nov 11, 2024
8 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_001_PointerUnion_llvm branch November 11, 2024 08:00
Groverkss pushed a commit to iree-org/llvm-project that referenced this pull request Nov 15, 2024
…115681)

Note that PointerUnion::{is,get,dyn_cast} 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants