[llvm] ec37ebf - [NFC] Use SmallVector/ArrayRef in MachineOutliner/SuffixTree for small types
Jessica Paquette via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 3 16:41:53 PST 2023
Author: Jessica Paquette
Date: 2023-02-03T16:41:02-08:00
New Revision: ec37ebf59be78665caa679d46607a2f054155c55
URL: https://github.com/llvm/llvm-project/commit/ec37ebf59be78665caa679d46607a2f054155c55
DIFF: https://github.com/llvm/llvm-project/commit/ec37ebf59be78665caa679d46607a2f054155c55.diff
LOG: [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.
Added:
Modified:
llvm/include/llvm/Support/SuffixTree.h
llvm/lib/CodeGen/MachineOutliner.cpp
llvm/lib/Support/SuffixTree.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Support/SuffixTree.h b/llvm/include/llvm/Support/SuffixTree.h
index 162a1de72f1ab..70a12efd4a10e 100644
--- a/llvm/include/llvm/Support/SuffixTree.h
+++ b/llvm/include/llvm/Support/SuffixTree.h
@@ -145,7 +145,7 @@ class SuffixTree {
unsigned Length;
/// The start indices of each occurrence.
- std::vector<unsigned> StartIndices;
+ SmallVector<unsigned> StartIndices;
};
private:
@@ -232,7 +232,7 @@ class SuffixTree {
/// Construct a suffix tree from a sequence of unsigned integers.
///
/// \param Str The string to construct the suffix tree for.
- SuffixTree(const std::vector<unsigned> &Str);
+ SuffixTree(const ArrayRef<unsigned> &Str);
/// Iterator for finding all repeated substrings in the suffix tree.
struct RepeatedSubstringIterator {
@@ -244,7 +244,7 @@ class SuffixTree {
RepeatedSubstring RS;
/// The nodes left to visit.
- std::vector<SuffixTreeNode *> ToVisit;
+ SmallVector<SuffixTreeNode *> 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 @@ class SuffixTree {
N = nullptr;
// Each leaf node represents a repeat of a string.
- std::vector<SuffixTreeNode *> LeafChildren;
+ SmallVector<SuffixTreeNode *> 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 a7422f6f8d396..358a22f341eb6 100644
--- a/llvm/lib/CodeGen/MachineOutliner.cpp
+++ b/llvm/lib/CodeGen/MachineOutliner.cpp
@@ -136,11 +136,11 @@ struct InstructionMapper {
DenseMap<MachineBasicBlock *, unsigned> MBBFlagsMap;
/// The vector of unsigned integers that the module is mapped to.
- std::vector<unsigned> UnsignedVec;
+ SmallVector<unsigned> UnsignedVec;
/// Stores the location of the instruction associated with the integer
/// at index i in \p UnsignedVec for each index i.
- std::vector<MachineBasicBlock::iterator> InstrList;
+ SmallVector<MachineBasicBlock::iterator> 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<unsigned> &UnsignedVecForMBB,
- std::vector<MachineBasicBlock::iterator> &InstrListForMBB) {
+ SmallVector<unsigned> &UnsignedVecForMBB,
+ SmallVector<MachineBasicBlock::iterator> &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<unsigned> &UnsignedVecForMBB,
- std::vector<MachineBasicBlock::iterator> &InstrListForMBB) {
+ SmallVector<unsigned> &UnsignedVecForMBB,
+ SmallVector<MachineBasicBlock::iterator> &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<unsigned> UnsignedVecForMBB;
- std::vector<MachineBasicBlock::iterator> InstrListForMBB;
+ SmallVector<unsigned> UnsignedVecForMBB;
+ SmallVector<MachineBasicBlock::iterator> 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 0d419f12cd1d6..e2cd7b6073ac8 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<unsigned> &Str) : Str(Str) {
+SuffixTree::SuffixTree(const ArrayRef<unsigned> &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<std::pair<SuffixTreeNode *, unsigned>> ToVisit;
+ SmallVector<std::pair<SuffixTreeNode *, unsigned>> ToVisit;
// Current node being visited.
SuffixTreeNode *CurrNode = Root;
More information about the llvm-commits
mailing list