From ec37ebf59be78665caa679d46607a2f054155c55 Mon Sep 17 00:00:00 2001 From: Jessica Paquette Date: Fri, 3 Feb 2023 16:08:50 -0800 Subject: [PATCH] [NFC] Use SmallVector/ArrayRef in MachineOutliner/SuffixTree for small types The MachineOutliner + SuffixTree both used `std::vector` everywhere because I didn't know any better at the time. At least for small types, such as `unsigned` and iterators, I can't see any particular reason to use std::vector over `SmallVector` here. --- llvm/include/llvm/Support/SuffixTree.h | 8 ++++---- llvm/lib/CodeGen/MachineOutliner.cpp | 16 ++++++++-------- llvm/lib/Support/SuffixTree.cpp | 4 ++-- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/llvm/include/llvm/Support/SuffixTree.h b/llvm/include/llvm/Support/SuffixTree.h index 162a1de72f1a..70a12efd4a10 100644 --- a/llvm/include/llvm/Support/SuffixTree.h +++ b/llvm/include/llvm/Support/SuffixTree.h @@ -145,7 +145,7 @@ public: unsigned Length; /// The start indices of each occurrence. - std::vector StartIndices; + SmallVector StartIndices; }; private: @@ -232,7 +232,7 @@ public: /// Construct a suffix tree from a sequence of unsigned integers. /// /// \param Str The string to construct the suffix tree for. - SuffixTree(const std::vector &Str); + SuffixTree(const ArrayRef &Str); /// Iterator for finding all repeated substrings in the suffix tree. struct RepeatedSubstringIterator { @@ -244,7 +244,7 @@ public: RepeatedSubstring RS; /// The nodes left to visit. - std::vector ToVisit; + SmallVector ToVisit; /// The minimum length of a repeated substring to find. /// Since we're outlining, we want at least two instructions in the range. @@ -260,7 +260,7 @@ public: N = nullptr; // Each leaf node represents a repeat of a string. - std::vector LeafChildren; + SmallVector LeafChildren; // Continue visiting nodes until we find one which repeats more than once. while (!ToVisit.empty()) { diff --git a/llvm/lib/CodeGen/MachineOutliner.cpp b/llvm/lib/CodeGen/MachineOutliner.cpp index a7422f6f8d39..358a22f341eb 100644 --- a/llvm/lib/CodeGen/MachineOutliner.cpp +++ b/llvm/lib/CodeGen/MachineOutliner.cpp @@ -136,11 +136,11 @@ struct InstructionMapper { DenseMap MBBFlagsMap; /// The vector of unsigned integers that the module is mapped to. - std::vector UnsignedVec; + SmallVector UnsignedVec; /// Stores the location of the instruction associated with the integer /// at index i in \p UnsignedVec for each index i. - std::vector InstrList; + SmallVector InstrList; // Set if we added an illegal number in the previous step. // Since each illegal number is unique, we only need one of them between @@ -157,8 +157,8 @@ struct InstructionMapper { unsigned mapToLegalUnsigned( MachineBasicBlock::iterator &It, bool &CanOutlineWithPrevInstr, bool &HaveLegalRange, unsigned &NumLegalInBlock, - std::vector &UnsignedVecForMBB, - std::vector &InstrListForMBB) { + SmallVector &UnsignedVecForMBB, + SmallVector &InstrListForMBB) { // We added something legal, so we should unset the AddedLegalLastTime // flag. AddedIllegalLastTime = false; @@ -211,8 +211,8 @@ struct InstructionMapper { /// \returns The integer that \p *It was mapped to. unsigned mapToIllegalUnsigned( MachineBasicBlock::iterator &It, bool &CanOutlineWithPrevInstr, - std::vector &UnsignedVecForMBB, - std::vector &InstrListForMBB) { + SmallVector &UnsignedVecForMBB, + SmallVector &InstrListForMBB) { // Can't outline an illegal instruction. Set the flag. CanOutlineWithPrevInstr = false; @@ -287,8 +287,8 @@ struct InstructionMapper { // FIXME: Should this all just be handled in the target, rather than using // repeated calls to getOutliningType? - std::vector UnsignedVecForMBB; - std::vector InstrListForMBB; + SmallVector UnsignedVecForMBB; + SmallVector InstrListForMBB; LLVM_DEBUG(dbgs() << "*** Mapping outlinable ranges ***\n"); for (auto &OutlinableRange : OutlinableRanges) { diff --git a/llvm/lib/Support/SuffixTree.cpp b/llvm/lib/Support/SuffixTree.cpp index 0d419f12cd1d..e2cd7b6073ac 100644 --- a/llvm/lib/Support/SuffixTree.cpp +++ b/llvm/lib/Support/SuffixTree.cpp @@ -16,7 +16,7 @@ using namespace llvm; -SuffixTree::SuffixTree(const std::vector &Str) : Str(Str) { +SuffixTree::SuffixTree(const ArrayRef &Str) : Str(Str) { Root = insertInternalNode(nullptr, EmptyIdx, EmptyIdx, 0); Active.Node = Root; @@ -70,7 +70,7 @@ SuffixTreeNode *SuffixTree::insertInternalNode(SuffixTreeNode *Parent, void SuffixTree::setSuffixIndices() { // List of nodes we need to visit along with the current length of the // string. - std::vector> ToVisit; + SmallVector> ToVisit; // Current node being visited. SuffixTreeNode *CurrNode = Root;