From bb353df589b87527bc28666bc29c506c86d7f978 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Wed, 11 May 2022 20:27:11 -0700 Subject: [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. --- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 32 +++++++++++++------------------ 1 file changed, 13 insertions(+), 19 deletions(-) (limited to 'llvm/lib/Bitcode/Writer/BitcodeWriter.cpp') diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp index 1288c91c4eba..b4cafd49ba07 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 BlockAddressUsersStack { BA }; - SmallPtrSet BlockAddressUsersVisited { BA }; - - while (!BlockAddressUsersStack.empty()) { - Value *V = BlockAddressUsersStack.pop_back_val(); - + SmallVector Worklist{BA}; + SmallPtrSet Visited{BA}; + while (!Worklist.empty()) { + Value *V = Worklist.pop_back_val(); for (User *U : V->users()) { - if ((isa(U) || isa(U)) && - !BlockAddressUsersVisited.contains(U)) { - BlockAddressUsersStack.push_back(U); - BlockAddressUsersVisited.insert(U); - } - if (auto *I = dyn_cast(U)) { - Function *P = I->getParent()->getParent(); + Function *P = I->getFunction(); if (P != &F) BlockAddressUsers.insert(P); - } + } else if (isa(U) && !isa(U) && + Visited.insert(U).second) + Worklist.push_back(U); } } } } if (!BlockAddressUsers.empty()) { - SmallVector 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. -- cgit v1.2.3