Skip to content

Commit a1937d2

Browse files
authored
[ComplexDeinterleaving] Use LLVM ADTs (NFC) (#154754)
This swaps out STL types for their LLVM equivalents. This is recommended in the LLVM coding standards: https://llvm.org/docs/CodingStandards.html#c-standard-library
1 parent 2191f5a commit a1937d2

File tree

1 file changed

+28
-26
lines changed

1 file changed

+28
-26
lines changed

llvm/lib/CodeGen/ComplexDeinterleavingPass.cpp

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
//===----------------------------------------------------------------------===//
6161

6262
#include "llvm/CodeGen/ComplexDeinterleavingPass.h"
63+
#include "llvm/ADT/AllocatorList.h"
6364
#include "llvm/ADT/MapVector.h"
6465
#include "llvm/ADT/Statistic.h"
6566
#include "llvm/Analysis/TargetLibraryInfo.h"
@@ -263,6 +264,7 @@ class ComplexDeinterleavingGraph {
263264
};
264265

265266
using Addend = std::pair<Value *, bool>;
267+
using AddendList = BumpPtrList<Addend>;
266268
using CompositeNode = ComplexDeinterleavingCompositeNode::CompositeNode;
267269

268270
// Helper struct for holding info about potential partial multiplication
@@ -291,7 +293,7 @@ class ComplexDeinterleavingGraph {
291293
SmallPtrSet<Instruction *, 16> FinalInstructions;
292294

293295
/// Root instructions are instructions from which complex computation starts
294-
std::map<Instruction *, CompositeNode *> RootToNode;
296+
DenseMap<Instruction *, CompositeNode *> RootToNode;
295297

296298
/// Topologically sorted root instructions
297299
SmallVector<Instruction *, 1> OrderedRoots;
@@ -339,7 +341,7 @@ class ComplexDeinterleavingGraph {
339341
/// ComplexDeinterleavingOperation::ReductionPHI node replacement. It is then
340342
/// used in the ComplexDeinterleavingOperation::ReductionOperation node
341343
/// replacement process.
342-
std::map<PHINode *, PHINode *> OldToNewPHI;
344+
DenseMap<PHINode *, PHINode *> OldToNewPHI;
343345

344346
CompositeNode *prepareCompositeNode(ComplexDeinterleavingOperation Operation,
345347
Value *R, Value *I) {
@@ -417,28 +419,28 @@ class ComplexDeinterleavingGraph {
417419
/// and \p ImagAddens. If \p Accumulator is not null, add the result to it.
418420
/// Return nullptr if it is not possible to construct a complex number.
419421
/// \p Flags are needed to generate symmetric Add and Sub operations.
420-
CompositeNode *identifyAdditions(std::list<Addend> &RealAddends,
421-
std::list<Addend> &ImagAddends,
422+
CompositeNode *identifyAdditions(AddendList &RealAddends,
423+
AddendList &ImagAddends,
422424
std::optional<FastMathFlags> Flags,
423425
CompositeNode *Accumulator);
424426

425427
/// Extract one addend that have both real and imaginary parts positive.
426-
CompositeNode *extractPositiveAddend(std::list<Addend> &RealAddends,
427-
std::list<Addend> &ImagAddends);
428+
CompositeNode *extractPositiveAddend(AddendList &RealAddends,
429+
AddendList &ImagAddends);
428430

429431
/// Determine if sum of multiplications of complex numbers can be formed from
430432
/// \p RealMuls and \p ImagMuls. If \p Accumulator is not null, add the result
431433
/// to it. Return nullptr if it is not possible to construct a complex number.
432-
CompositeNode *identifyMultiplications(std::vector<Product> &RealMuls,
433-
std::vector<Product> &ImagMuls,
434+
CompositeNode *identifyMultiplications(SmallVectorImpl<Product> &RealMuls,
435+
SmallVectorImpl<Product> &ImagMuls,
434436
CompositeNode *Accumulator);
435437

436438
/// Go through pairs of multiplication (one Real and one Imag) and find all
437439
/// possible candidates for partial multiplication and put them into \p
438440
/// Candidates. Returns true if all Product has pair with common operand
439-
bool collectPartialMuls(const std::vector<Product> &RealMuls,
440-
const std::vector<Product> &ImagMuls,
441-
std::vector<PartialMulCandidate> &Candidates);
441+
bool collectPartialMuls(ArrayRef<Product> RealMuls,
442+
ArrayRef<Product> ImagMuls,
443+
SmallVectorImpl<PartialMulCandidate> &Candidates);
442444

443445
/// If the code is compiled with -Ofast or expressions have `reassoc` flag,
444446
/// the order of complex computation operations may be significantly altered,
@@ -1255,8 +1257,8 @@ ComplexDeinterleavingGraph::identifyReassocNodes(Instruction *Real,
12551257
// Collect multiplications and addend instructions from the given instruction
12561258
// while traversing it operands. Additionally, verify that all instructions
12571259
// have the same fast math flags.
1258-
auto Collect = [&Flags](Instruction *Insn, std::vector<Product> &Muls,
1259-
std::list<Addend> &Addends) -> bool {
1260+
auto Collect = [&Flags](Instruction *Insn, SmallVectorImpl<Product> &Muls,
1261+
AddendList &Addends) -> bool {
12601262
SmallVector<PointerIntPair<Value *, 1, bool>> Worklist = {{Insn, true}};
12611263
SmallPtrSet<Value *, 8> Visited;
12621264
while (!Worklist.empty()) {
@@ -1336,8 +1338,8 @@ ComplexDeinterleavingGraph::identifyReassocNodes(Instruction *Real,
13361338
return true;
13371339
};
13381340

1339-
std::vector<Product> RealMuls, ImagMuls;
1340-
std::list<Addend> RealAddends, ImagAddends;
1341+
SmallVector<Product> RealMuls, ImagMuls;
1342+
AddendList RealAddends, ImagAddends;
13411343
if (!Collect(Real, RealMuls, RealAddends) ||
13421344
!Collect(Imag, ImagMuls, ImagAddends))
13431345
return nullptr;
@@ -1371,8 +1373,8 @@ ComplexDeinterleavingGraph::identifyReassocNodes(Instruction *Real,
13711373
}
13721374

13731375
bool ComplexDeinterleavingGraph::collectPartialMuls(
1374-
const std::vector<Product> &RealMuls, const std::vector<Product> &ImagMuls,
1375-
std::vector<PartialMulCandidate> &PartialMulCandidates) {
1376+
ArrayRef<Product> RealMuls, ArrayRef<Product> ImagMuls,
1377+
SmallVectorImpl<PartialMulCandidate> &PartialMulCandidates) {
13761378
// Helper function to extract a common operand from two products
13771379
auto FindCommonInstruction = [](const Product &Real,
13781380
const Product &Imag) -> Value * {
@@ -1423,18 +1425,18 @@ bool ComplexDeinterleavingGraph::collectPartialMuls(
14231425

14241426
ComplexDeinterleavingGraph::CompositeNode *
14251427
ComplexDeinterleavingGraph::identifyMultiplications(
1426-
std::vector<Product> &RealMuls, std::vector<Product> &ImagMuls,
1428+
SmallVectorImpl<Product> &RealMuls, SmallVectorImpl<Product> &ImagMuls,
14271429
CompositeNode *Accumulator = nullptr) {
14281430
if (RealMuls.size() != ImagMuls.size())
14291431
return nullptr;
14301432

1431-
std::vector<PartialMulCandidate> Info;
1433+
SmallVector<PartialMulCandidate> Info;
14321434
if (!collectPartialMuls(RealMuls, ImagMuls, Info))
14331435
return nullptr;
14341436

14351437
// Map to store common instruction to node pointers
1436-
std::map<Value *, CompositeNode *> CommonToNode;
1437-
std::vector<bool> Processed(Info.size(), false);
1438+
DenseMap<Value *, CompositeNode *> CommonToNode;
1439+
SmallVector<bool> Processed(Info.size(), false);
14381440
for (unsigned I = 0; I < Info.size(); ++I) {
14391441
if (Processed[I])
14401442
continue;
@@ -1463,8 +1465,8 @@ ComplexDeinterleavingGraph::identifyMultiplications(
14631465
}
14641466
}
14651467

1466-
std::vector<bool> ProcessedReal(RealMuls.size(), false);
1467-
std::vector<bool> ProcessedImag(ImagMuls.size(), false);
1468+
SmallVector<bool> ProcessedReal(RealMuls.size(), false);
1469+
SmallVector<bool> ProcessedImag(ImagMuls.size(), false);
14681470
CompositeNode *Result = Accumulator;
14691471
for (auto &PMI : Info) {
14701472
if (ProcessedReal[PMI.RealIdx] || ProcessedImag[PMI.ImagIdx])
@@ -1580,7 +1582,7 @@ ComplexDeinterleavingGraph::identifyMultiplications(
15801582

15811583
ComplexDeinterleavingGraph::CompositeNode *
15821584
ComplexDeinterleavingGraph::identifyAdditions(
1583-
std::list<Addend> &RealAddends, std::list<Addend> &ImagAddends,
1585+
AddendList &RealAddends, AddendList &ImagAddends,
15841586
std::optional<FastMathFlags> Flags, CompositeNode *Accumulator = nullptr) {
15851587
if (RealAddends.size() != ImagAddends.size())
15861588
return nullptr;
@@ -1671,8 +1673,8 @@ ComplexDeinterleavingGraph::identifyAdditions(
16711673
}
16721674

16731675
ComplexDeinterleavingGraph::CompositeNode *
1674-
ComplexDeinterleavingGraph::extractPositiveAddend(
1675-
std::list<Addend> &RealAddends, std::list<Addend> &ImagAddends) {
1676+
ComplexDeinterleavingGraph::extractPositiveAddend(AddendList &RealAddends,
1677+
AddendList &ImagAddends) {
16761678
for (auto ItR = RealAddends.begin(); ItR != RealAddends.end(); ++ItR) {
16771679
for (auto ItI = ImagAddends.begin(); ItI != ImagAddends.end(); ++ItI) {
16781680
auto [R, IsPositiveR] = *ItR;

0 commit comments

Comments
 (0)