diff options
author | Fangrui Song <i@maskray.me> | 2022-05-11 20:27:11 -0700 |
---|---|---|
committer | Fangrui Song <i@maskray.me> | 2022-05-11 20:27:12 -0700 |
commit | bb353df589b87527bc28666bc29c506c86d7f978 (patch) | |
tree | 360fd6403dca001365ad41b70adcb5e8c7cafb6c /llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | |
parent | 50f5cef39140e038486d6a8640cc7306fb924b06 (diff) | |
download | llvm-bb353df589b87527bc28666bc29c506c86d7f978.zip llvm-bb353df589b87527bc28666bc29c506c86d7f978.tar.gz llvm-bb353df589b87527bc28666bc29c506c86d7f978.tar.bz2 |
[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.
Diffstat (limited to 'llvm/lib/Bitcode/Writer/BitcodeWriter.cpp')
-rw-r--r-- | llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 32 |
1 files changed, 13 insertions, 19 deletions
diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp index 1288c91..b4cafd4 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. |