[llvm] bb353df - [Bitcode] Simplify code after FUNC_CODE_BLOCKADDR_USERS changes (D124878)

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Wed May 11 20:27:17 PDT 2022


Author: Fangrui Song
Date: 2022-05-11T20:27:12-07:00
New Revision: bb353df589b87527bc28666bc29c506c86d7f978

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

LOG: [Bitcode] Simplify code after FUNC_CODE_BLOCKADDR_USERS changes (D124878)

Switch to the more common `Constant && !GlobalValue` test.
Use the more common `Worklist/Visited` variable names.

Added: 
    

Modified: 
    llvm/lib/Bitcode/Writer/BitcodeWriter.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
index 1288c91c4ebae..b4cafd49ba072 100644
--- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -3402,35 +3402,29 @@ void ModuleBitcodeWriter::writeFunction(
     }
 
     if (BlockAddress *BA = BlockAddress::lookup(&BB)) {
-      SmallVector<Value *, 16> BlockAddressUsersStack { BA };
-      SmallPtrSet<Value *, 16> BlockAddressUsersVisited { BA };
-
-      while (!BlockAddressUsersStack.empty()) {
-        Value *V = BlockAddressUsersStack.pop_back_val();
-
+      SmallVector<Value *> Worklist{BA};
+      SmallPtrSet<Value *, 8> Visited{BA};
+      while (!Worklist.empty()) {
+        Value *V = Worklist.pop_back_val();
         for (User *U : V->users()) {
-          if ((isa<ConstantAggregate>(U) || isa<ConstantExpr>(U)) &&
-              !BlockAddressUsersVisited.contains(U)) {
-            BlockAddressUsersStack.push_back(U);
-            BlockAddressUsersVisited.insert(U);
-          }
-
           if (auto *I = dyn_cast<Instruction>(U)) {
-            Function *P = I->getParent()->getParent();
+            Function *P = I->getFunction();
             if (P != &F)
               BlockAddressUsers.insert(P);
-          }
+          } else if (isa<Constant>(U) && !isa<GlobalValue>(U) &&
+                     Visited.insert(U).second)
+            Worklist.push_back(U);
         }
       }
     }
   }
 
   if (!BlockAddressUsers.empty()) {
-    SmallVector<uint64_t, 4> Record;
-    Record.reserve(BlockAddressUsers.size());
-    for (Function *F : BlockAddressUsers)
-      Record.push_back(VE.getValueID(F));
-    Stream.EmitRecord(bitc::FUNC_CODE_BLOCKADDR_USERS, Record);
+    Vals.resize(BlockAddressUsers.size());
+    for (auto I : llvm::enumerate(BlockAddressUsers))
+      Vals[I.index()] = VE.getValueID(I.value());
+    Stream.EmitRecord(bitc::FUNC_CODE_BLOCKADDR_USERS, Vals);
+    Vals.clear();
   }
 
   // Emit names for all the instructions etc.


        


More information about the llvm-commits mailing list