[llvm] 5f4ae56 - [llvm] Remove uses of `std::vector<bool>`
Jan Svoboda via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 18 09:20:50 PST 2022
Author: Jan Svoboda
Date: 2022-01-18T18:20:45+01:00
New Revision: 5f4ae5645754043f087c2c4ac58c7bffb0921ce3
URL: https://github.com/llvm/llvm-project/commit/5f4ae5645754043f087c2c4ac58c7bffb0921ce3
DIFF: https://github.com/llvm/llvm-project/commit/5f4ae5645754043f087c2c4ac58c7bffb0921ce3.diff
LOG: [llvm] Remove uses of `std::vector<bool>`
LLVM Programmer’s Manual strongly discourages the use of `std::vector<bool>` and suggests `llvm::BitVector` as a possible replacement.
This patch does just that for llvm.
Reviewed By: dexonsmith
Differential Revision: https://reviews.llvm.org/D117121
Added:
Modified:
llvm/include/llvm/Analysis/BlockFrequencyInfoImpl.h
llvm/lib/Analysis/DevelopmentModeInlineAdvisor.cpp
llvm/lib/Transforms/Utils/SampleProfileInference.cpp
llvm/tools/llvm-lto/llvm-lto.cpp
llvm/tools/llvm-rc/ResourceScriptParser.cpp
llvm/tools/llvm-rc/ResourceScriptStmt.h
llvm/tools/llvm-readobj/ELFDumper.cpp
llvm/unittests/Analysis/AssumeBundleQueriesTest.cpp
llvm/utils/TableGen/CodeGenInstruction.h
llvm/utils/TableGen/GlobalISel/GIMatchTree.h
Removed:
################################################################################
diff --git a/llvm/include/llvm/Analysis/BlockFrequencyInfoImpl.h b/llvm/include/llvm/Analysis/BlockFrequencyInfoImpl.h
index f581b18bff176..858dd369dd0b8 100644
--- a/llvm/include/llvm/Analysis/BlockFrequencyInfoImpl.h
+++ b/llvm/include/llvm/Analysis/BlockFrequencyInfoImpl.h
@@ -14,6 +14,7 @@
#ifndef LLVM_ANALYSIS_BLOCKFREQUENCYINFOIMPL_H
#define LLVM_ANALYSIS_BLOCKFREQUENCYINFOIMPL_H
+#include "llvm/ADT/BitVector.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/GraphTraits.h"
@@ -1451,7 +1452,7 @@ void BlockFrequencyInfoImpl<BT>::iterativeInference(
// frequencies need to be updated based on the incoming edges.
// The set is dynamic and changes after every update. Initially all blocks
// with a positive frequency are active
- auto IsActive = std::vector<bool>(Freq.size(), false);
+ auto IsActive = BitVector(Freq.size(), false);
std::queue<size_t> ActiveSet;
for (size_t I = 0; I < Freq.size(); I++) {
if (Freq[I] > 0) {
diff --git a/llvm/lib/Analysis/DevelopmentModeInlineAdvisor.cpp b/llvm/lib/Analysis/DevelopmentModeInlineAdvisor.cpp
index 94a60f6a75c19..4a792fce51d14 100644
--- a/llvm/lib/Analysis/DevelopmentModeInlineAdvisor.cpp
+++ b/llvm/lib/Analysis/DevelopmentModeInlineAdvisor.cpp
@@ -14,6 +14,7 @@
#include "llvm/Support/Casting.h"
#if defined(LLVM_HAVE_TF_API)
+#include "llvm/ADT/BitVector.h"
#include "llvm/Analysis/CallGraph.h"
#include "llvm/Analysis/InlineSizeEstimatorAnalysis.h"
#include "llvm/Analysis/MLInlineAdvisor.h"
@@ -112,7 +113,7 @@ class TrainingLogger final {
StringRef LogFileName;
const ModelUnderTrainingRunner *const MUTR;
std::unique_ptr<Logger> L;
- std::vector<bool> Effects;
+ BitVector Effects;
/// There's at least one output. We'll set this to a
diff erent value if MUTR
/// is avaliable.
size_t OutputCount = 1;
diff --git a/llvm/lib/Transforms/Utils/SampleProfileInference.cpp b/llvm/lib/Transforms/Utils/SampleProfileInference.cpp
index 01b54c3d88c94..1d5582980af50 100644
--- a/llvm/lib/Transforms/Utils/SampleProfileInference.cpp
+++ b/llvm/lib/Transforms/Utils/SampleProfileInference.cpp
@@ -14,6 +14,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/Transforms/Utils/SampleProfileInference.h"
+#include "llvm/ADT/BitVector.h"
#include "llvm/Support/Debug.h"
#include <queue>
#include <set>
@@ -309,7 +310,7 @@ class FlowAdjuster {
private:
void joinIsolatedComponents() {
// Find blocks that are reachable from the source
- auto Visited = std::vector<bool>(NumBlocks(), false);
+ auto Visited = BitVector(NumBlocks(), false);
findReachable(Func.Entry, Visited);
// Iterate over all non-reachable blocks and adjust their weights
@@ -334,7 +335,7 @@ class FlowAdjuster {
/// Run BFS from a given block along the jumps with a positive flow and mark
/// all reachable blocks.
- void findReachable(uint64_t Src, std::vector<bool> &Visited) {
+ void findReachable(uint64_t Src, BitVector &Visited) {
if (Visited[Src])
return;
std::queue<uint64_t> Queue;
@@ -488,7 +489,7 @@ class FlowAdjuster {
std::vector<FlowBlock *> &UnknownSuccs) {
// Run BFS from SrcBlock and make sure all paths are going through unknown
// blocks and end at a non-unknown DstBlock
- auto Visited = std::vector<bool>(NumBlocks(), false);
+ auto Visited = BitVector(NumBlocks(), false);
std::queue<uint64_t> Queue;
DstBlock = nullptr;
@@ -800,7 +801,7 @@ void verifyWeights(const FlowFunction &Func) {
// Run BFS from the source along edges with positive flow
std::queue<uint64_t> Queue;
- auto Visited = std::vector<bool>(NumBlocks, false);
+ auto Visited = BitVector(NumBlocks, false);
Queue.push(Func.Entry);
Visited[Func.Entry] = true;
while (!Queue.empty()) {
diff --git a/llvm/tools/llvm-lto/llvm-lto.cpp b/llvm/tools/llvm-lto/llvm-lto.cpp
index 995ebacacb870..c9021b135c6cf 100644
--- a/llvm/tools/llvm-lto/llvm-lto.cpp
+++ b/llvm/tools/llvm-lto/llvm-lto.cpp
@@ -267,7 +267,7 @@ static cl::opt<bool>
namespace {
struct ModuleInfo {
- std::vector<bool> CanBeHidden;
+ BitVector CanBeHidden;
};
} // end anonymous namespace
diff --git a/llvm/tools/llvm-rc/ResourceScriptParser.cpp b/llvm/tools/llvm-rc/ResourceScriptParser.cpp
index 4045131dd7855..7cb4d02e3c58e 100644
--- a/llvm/tools/llvm-rc/ResourceScriptParser.cpp
+++ b/llvm/tools/llvm-rc/ResourceScriptParser.cpp
@@ -741,7 +741,7 @@ Expected<std::unique_ptr<VersionInfoStmt>> RCParser::parseVersionInfoStmt() {
// possibly preceded by a comma. Unfortunately, the tool behavior depends
// on them existing or not, so we need to memorize where we found them.
std::vector<IntOrString> Values;
- std::vector<bool> PrecedingCommas;
+ BitVector PrecedingCommas;
RETURN_IF_ERROR(consumeType(Kind::Comma));
while (!isNextTokenKind(Kind::Identifier) &&
!isNextTokenKind(Kind::BlockEnd)) {
diff --git a/llvm/tools/llvm-rc/ResourceScriptStmt.h b/llvm/tools/llvm-rc/ResourceScriptStmt.h
index 75117c12c7e65..4b659f083b40b 100644
--- a/llvm/tools/llvm-rc/ResourceScriptStmt.h
+++ b/llvm/tools/llvm-rc/ResourceScriptStmt.h
@@ -16,6 +16,7 @@
#include "ResourceScriptToken.h"
#include "ResourceVisitor.h"
+#include "llvm/ADT/BitVector.h"
#include "llvm/ADT/StringSet.h"
namespace llvm {
@@ -768,10 +769,10 @@ class VersionInfoValue : public VersionInfoStmt {
public:
StringRef Key;
std::vector<IntOrString> Values;
- std::vector<bool> HasPrecedingComma;
+ BitVector HasPrecedingComma;
VersionInfoValue(StringRef InfoKey, std::vector<IntOrString> &&Vals,
- std::vector<bool> &&CommasBeforeVals)
+ BitVector &&CommasBeforeVals)
: Key(InfoKey), Values(std::move(Vals)),
HasPrecedingComma(std::move(CommasBeforeVals)) {}
raw_ostream &log(raw_ostream &) const override;
diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp
index b0fba6d813a98..c95ba7cec704a 100644
--- a/llvm/tools/llvm-readobj/ELFDumper.cpp
+++ b/llvm/tools/llvm-readobj/ELFDumper.cpp
@@ -17,6 +17,7 @@
#include "StackMapPrinter.h"
#include "llvm-readobj.h"
#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/BitVector.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/MapVector.h"
@@ -3905,7 +3906,7 @@ void GNUELFDumper<ELFT>::printHashTableSymbols(const Elf_Hash &SysVHash) {
for (uint32_t Buc = 0; Buc < SysVHash.nbucket; Buc++) {
if (Buckets[Buc] == ELF::STN_UNDEF)
continue;
- std::vector<bool> Visited(SysVHash.nchain);
+ BitVector Visited(SysVHash.nchain);
for (uint32_t Ch = Buckets[Buc]; Ch < SysVHash.nchain; Ch = Chains[Ch]) {
if (Ch == ELF::STN_UNDEF)
break;
@@ -4653,7 +4654,7 @@ void GNUELFDumper<ELFT>::printHashHistogram(const Elf_Hash &HashTable) {
// Go over all buckets and and note chain lengths of each bucket (total
// unique chain lengths).
for (size_t B = 0; B < NBucket; B++) {
- std::vector<bool> Visited(NChain);
+ BitVector Visited(NChain);
for (size_t C = Buckets[B]; C < NChain; C = Chains[C]) {
if (C == ELF::STN_UNDEF)
break;
diff --git a/llvm/unittests/Analysis/AssumeBundleQueriesTest.cpp b/llvm/unittests/Analysis/AssumeBundleQueriesTest.cpp
index 5cceca0940282..87cf0c749f8de 100644
--- a/llvm/unittests/Analysis/AssumeBundleQueriesTest.cpp
+++ b/llvm/unittests/Analysis/AssumeBundleQueriesTest.cpp
@@ -433,7 +433,7 @@ static void RunRandTest(uint64_t Seed, int Size, int MinCount, int MaxCount,
Function *FnAssume = Intrinsic::getDeclaration(Mod.get(), Intrinsic::assume);
std::vector<Argument *> ShuffledArgs;
- std::vector<bool> HasArg;
+ BitVector HasArg;
for (auto &Arg : F->args()) {
ShuffledArgs.push_back(&Arg);
HasArg.push_back(false);
diff --git a/llvm/utils/TableGen/CodeGenInstruction.h b/llvm/utils/TableGen/CodeGenInstruction.h
index e35d2191ea458..e0ce5d4336024 100644
--- a/llvm/utils/TableGen/CodeGenInstruction.h
+++ b/llvm/utils/TableGen/CodeGenInstruction.h
@@ -13,6 +13,7 @@
#ifndef LLVM_UTILS_TABLEGEN_CODEGENINSTRUCTION_H
#define LLVM_UTILS_TABLEGEN_CODEGENINSTRUCTION_H
+#include "llvm/ADT/BitVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/MachineValueType.h"
#include "llvm/Support/SMLoc.h"
@@ -106,7 +107,7 @@ template <typename T> class ArrayRef;
/// DoNotEncode - Bools are set to true in this vector for each operand in
/// the DisableEncoding list. These should not be emitted by the code
/// emitter.
- std::vector<bool> DoNotEncode;
+ BitVector DoNotEncode;
/// MIOperandInfo - Default MI operand type. Note an operand may be made
/// up of multiple MI operands.
diff --git a/llvm/utils/TableGen/GlobalISel/GIMatchTree.h b/llvm/utils/TableGen/GlobalISel/GIMatchTree.h
index bf41a2e0e2346..56df37731c09a 100644
--- a/llvm/utils/TableGen/GlobalISel/GIMatchTree.h
+++ b/llvm/utils/TableGen/GlobalISel/GIMatchTree.h
@@ -588,7 +588,7 @@ class GIMatchTreeVRegDefPartitioner : public GIMatchTreePartitioner {
unsigned OpIdx;
std::vector<BitVector> TraversedEdges;
DenseMap<unsigned, unsigned> ResultToPartition;
- std::vector<bool> PartitionToResult;
+ BitVector PartitionToResult;
void addToPartition(bool Result, unsigned LeafIdx);
More information about the llvm-commits
mailing list