Skip to content

Commit ffc1681

Browse files
committedJul 3, 2018
[ARM][NFC] Refactor sequential access for DSP
With a view to support parallel operations that have their results stored to memory, refactor the consecutive access helper out so it could support stores instructions. Differential Revision: https://reviews.llvm.org/D48872 llvm-svn: 336195
1 parent aa02580 commit ffc1681

File tree

1 file changed

+27
-18
lines changed

1 file changed

+27
-18
lines changed
 

‎llvm/lib/Target/ARM/ARMParallelDSP.cpp

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ namespace {
4545
using ParallelMACList = SmallVector<ParallelMAC, 8>;
4646
using ReductionList = SmallVector<Reduction, 8>;
4747
using ValueList = SmallVector<Value*, 8>;
48-
using LoadInstList = SmallVector<LoadInst*, 8>;
48+
using MemInstList = SmallVector<Instruction*, 8>;
4949
using PMACPair = std::pair<ParallelMAC*,ParallelMAC*>;
5050
using PMACPairList = SmallVector<PMACPair, 8>;
5151
using Instructions = SmallVector<Instruction*,16>;
@@ -58,7 +58,7 @@ namespace {
5858
struct ParallelMAC {
5959
Instruction *Mul;
6060
ValueList VL; // List of all (narrow) operands of this Mul
61-
LoadInstList VecLd; // List of all load instructions of this Mul
61+
MemInstList VecLd; // List of all load instructions of this Mul
6262
MemLocList MemLocs; // All memory locations read by this Mul
6363

6464
ParallelMAC(Instruction *I, ValueList &V) : Mul(I), VL(V) {};
@@ -84,7 +84,7 @@ namespace {
8484
Module *M;
8585

8686
bool InsertParallelMACs(Reduction &Reduction, PMACPairList &PMACPairs);
87-
bool AreSequentialLoads(LoadInst *Ld0, LoadInst *Ld1, LoadInstList &VecLd);
87+
bool AreSequentialLoads(LoadInst *Ld0, LoadInst *Ld1, MemInstList &VecLd);
8888
PMACPairList CreateParallelMACPairs(ParallelMACList &Candidates);
8989
Instruction *CreateSMLADCall(LoadInst *VecLd0, LoadInst *VecLd1,
9090
Instruction *Acc, Instruction *InsertAfter);
@@ -254,8 +254,26 @@ static bool AreSymmetrical(const ValueList &VL0,
254254
return true;
255255
}
256256

257+
template<typename MemInst>
258+
static bool AreSequentialAccesses(MemInst *MemOp0, MemInst *MemOp1,
259+
MemInstList &VecMem, const DataLayout &DL,
260+
ScalarEvolution &SE) {
261+
if (!MemOp0->isSimple() || !MemOp1->isSimple()) {
262+
LLVM_DEBUG(dbgs() << "No, not touching volatile access\n");
263+
return false;
264+
}
265+
if (isConsecutiveAccess(MemOp0, MemOp1, DL, SE)) {
266+
VecMem.push_back(MemOp0);
267+
VecMem.push_back(MemOp1);
268+
LLVM_DEBUG(dbgs() << "OK: accesses are consecutive.\n");
269+
return true;
270+
}
271+
LLVM_DEBUG(dbgs() << "No, accesses aren't consecutive.\n");
272+
return false;
273+
}
274+
257275
bool ARMParallelDSP::AreSequentialLoads(LoadInst *Ld0, LoadInst *Ld1,
258-
LoadInstList &VecLd) {
276+
MemInstList &VecMem) {
259277
if (!Ld0 || !Ld1)
260278
return false;
261279

@@ -264,22 +282,12 @@ bool ARMParallelDSP::AreSequentialLoads(LoadInst *Ld0, LoadInst *Ld1,
264282
dbgs() << "Ld1:"; Ld1->dump();
265283
);
266284

267-
if (!Ld0->isSimple() || !Ld1->isSimple()) {
268-
LLVM_DEBUG(dbgs() << "No, not touching volatile loads\n");
269-
return false;
270-
}
271285
if (!Ld0->hasOneUse() || !Ld1->hasOneUse()) {
272286
LLVM_DEBUG(dbgs() << "No, load has more than one use.\n");
273287
return false;
274288
}
275-
if (isConsecutiveAccess(Ld0, Ld1, *DL, *SE)) {
276-
VecLd.push_back(Ld0);
277-
VecLd.push_back(Ld1);
278-
LLVM_DEBUG(dbgs() << "OK: loads are consecutive.\n");
279-
return true;
280-
}
281-
LLVM_DEBUG(dbgs() << "No, Ld0 and Ld1 aren't consecutive.\n");
282-
return false;
289+
290+
return AreSequentialAccesses<LoadInst>(Ld0, Ld1, VecMem, *DL, *SE);
283291
}
284292

285293
PMACPairList
@@ -349,8 +357,9 @@ bool ARMParallelDSP::InsertParallelMACs(Reduction &Reduction,
349357
LLVM_DEBUG(dbgs() << "Found parallel MACs!!\n";
350358
dbgs() << "- "; Pair.first->Mul->dump();
351359
dbgs() << "- "; Pair.second->Mul->dump());
352-
Acc = CreateSMLADCall(Pair.first->VecLd[0], Pair.second->VecLd[0], Acc,
353-
InsertAfter);
360+
auto *VecLd0 = cast<LoadInst>(Pair.first->VecLd[0]);
361+
auto *VecLd1 = cast<LoadInst>(Pair.second->VecLd[0]);
362+
Acc = CreateSMLADCall(VecLd0, VecLd1, Acc, InsertAfter);
354363
InsertAfter = Acc;
355364
}
356365

0 commit comments

Comments
 (0)
Please sign in to comment.