Skip to content

[TableGen] Remove unnecessary const_cast and use range-based for loops. NFC #130717

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
merged 1 commit into from
Mar 11, 2025

Conversation

topperc
Copy link
Collaborator

@topperc topperc commented Mar 11, 2025

In order to use a range-based loop, I reduced a needed const_cast to only the one line that needed it.

…s. NFC

In order to use a range-based loop, I reduced a needed const_cast
to only the one line that needed it.
@topperc topperc requested review from arsenm and jurahul March 11, 2025 05:09
@llvmbot
Copy link
Member

llvmbot commented Mar 11, 2025

@llvm/pr-subscribers-tablegen

Author: Craig Topper (topperc)

Changes

In order to use a range-based loop, I reduced a needed const_cast to only the one line that needed it.


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

1 Files Affected:

  • (modified) llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp (+3-7)
diff --git a/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp b/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp
index 59148a96d8e92..ed3ec924afd47 100644
--- a/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp
+++ b/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp
@@ -4139,23 +4139,19 @@ void CodeGenDAGPatterns::InferInstructionFlags() {
 
   // If requested by the target, guess any undefined properties.
   if (Target.guessInstructionProperties()) {
-    for (unsigned i = 0, e = Instructions.size(); i != e; ++i) {
-      CodeGenInstruction *InstInfo =
-          const_cast<CodeGenInstruction *>(Instructions[i]);
+    for (const CodeGenInstruction *InstInfo : Instructions) {
       if (InstInfo->InferredFrom)
         continue;
       // The mayLoad and mayStore flags default to false.
       // Conservatively assume hasSideEffects if it wasn't explicit.
       if (InstInfo->hasSideEffects_Unset)
-        InstInfo->hasSideEffects = true;
+        const_cast<CodeGenInstruction *>(InstInfo)->hasSideEffects = true;
     }
     return;
   }
 
   // Complain about any flags that are still undefined.
-  for (unsigned i = 0, e = Instructions.size(); i != e; ++i) {
-    CodeGenInstruction *InstInfo =
-        const_cast<CodeGenInstruction *>(Instructions[i]);
+  for (const CodeGenInstruction *InstInfo : Instructions) {
     if (InstInfo->InferredFrom)
       continue;
     if (InstInfo->hasSideEffects_Unset)

@topperc topperc merged commit 146ef7a into llvm:main Mar 11, 2025
13 checks passed
@topperc topperc deleted the pr/const_cast branch March 11, 2025 16:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants