[llvm] 146ef7a - [TableGen] Remove unnecessary const_cast and use range-based for loops. NFC (#130717)

via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 11 09:21:14 PDT 2025


Author: Craig Topper
Date: 2025-03-11T09:21:10-07:00
New Revision: 146ef7a5f44af68e969dfb66918ae49810864aec

URL: https://github.com/llvm/llvm-project/commit/146ef7a5f44af68e969dfb66918ae49810864aec
DIFF: https://github.com/llvm/llvm-project/commit/146ef7a5f44af68e969dfb66918ae49810864aec.diff

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

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

Added: 
    

Modified: 
    llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp

Removed: 
    


################################################################################
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)


        


More information about the llvm-commits mailing list