Skip to content

Commit 35619c7

Browse files
authored
[RISCV] Add tune info for mem* expansion (#118439)
So that CPUs can tune these options.
1 parent f7261e9 commit 35619c7

File tree

3 files changed

+71
-3
lines changed

3 files changed

+71
-3
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1544,6 +1544,20 @@ RISCVTargetLowering::RISCVTargetLowering(const TargetMachine &TM,
15441544
// corresponding branch. This information is used in CGP/SelectOpt to decide
15451545
// when to convert selects into branches.
15461546
PredictableSelectIsExpensive = Subtarget.predictableSelectIsExpensive();
1547+
1548+
MaxStoresPerMemsetOptSize = Subtarget.getMaxStoresPerMemset(/*OptSize=*/true);
1549+
MaxStoresPerMemset = Subtarget.getMaxStoresPerMemset(/*OptSize=*/false);
1550+
1551+
MaxGluedStoresPerMemcpy = Subtarget.getMaxGluedStoresPerMemcpy();
1552+
MaxStoresPerMemcpyOptSize = Subtarget.getMaxStoresPerMemcpy(/*OptSize=*/true);
1553+
MaxStoresPerMemcpy = Subtarget.getMaxStoresPerMemcpy(/*OptSize=*/false);
1554+
1555+
MaxStoresPerMemmoveOptSize =
1556+
Subtarget.getMaxStoresPerMemmove(/*OptSize=*/true);
1557+
MaxStoresPerMemmove = Subtarget.getMaxStoresPerMemmove(/*OptSize=*/false);
1558+
1559+
MaxLoadsPerMemcmpOptSize = Subtarget.getMaxLoadsPerMemcmp(/*OptSize=*/true);
1560+
MaxLoadsPerMemcmp = Subtarget.getMaxLoadsPerMemcmp(/*OptSize=*/false);
15471561
}
15481562

15491563
EVT RISCVTargetLowering::getSetCCResultType(const DataLayout &DL,

llvm/lib/Target/RISCV/RISCVProcessors.td

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,32 @@ class RISCVTuneInfo {
2424

2525
// Tail duplication threshold at -O3.
2626
bits<32> TailDupAggressiveThreshold = 6;
27+
28+
bits<32> MaxStoresPerMemsetOptSize = 4;
29+
bits<32> MaxStoresPerMemset = 8;
30+
31+
bits<32> MaxGluedStoresPerMemcpy = 0;
32+
bits<32> MaxStoresPerMemcpyOptSize = 4;
33+
bits<32> MaxStoresPerMemcpy = 8;
34+
35+
bits<32> MaxStoresPerMemmoveOptSize = 4;
36+
bits<32> MaxStoresPerMemmove = 8;
37+
38+
bits<32> MaxLoadsPerMemcmpOptSize = 4;
39+
bits<32> MaxLoadsPerMemcmp = 8;
2740
}
2841

2942
def RISCVTuneInfoTable : GenericTable {
3043
let FilterClass = "RISCVTuneInfo";
3144
let CppTypeName = "RISCVTuneInfo";
3245
let Fields = ["Name", "PrefFunctionAlignment", "PrefLoopAlignment",
33-
"CacheLineSize", "PrefetchDistance",
34-
"MinPrefetchStride", "MaxPrefetchIterationsAhead",
35-
"MinimumJumpTableEntries", "TailDupAggressiveThreshold"];
46+
"CacheLineSize", "PrefetchDistance", "MinPrefetchStride",
47+
"MaxPrefetchIterationsAhead", "MinimumJumpTableEntries",
48+
"TailDupAggressiveThreshold", "MaxStoresPerMemsetOptSize",
49+
"MaxStoresPerMemset", "MaxGluedStoresPerMemcpy",
50+
"MaxStoresPerMemcpyOptSize", "MaxStoresPerMemcpy",
51+
"MaxStoresPerMemmoveOptSize", "MaxStoresPerMemmove",
52+
"MaxLoadsPerMemcmpOptSize", "MaxLoadsPerMemcmp"];
3653
}
3754

3855
def getRISCVTuneInfo : SearchIndex {

llvm/lib/Target/RISCV/RISCVSubtarget.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,19 @@ struct RISCVTuneInfo {
5353

5454
// Tail duplication threshold at -O3.
5555
unsigned TailDupAggressiveThreshold;
56+
57+
unsigned MaxStoresPerMemsetOptSize;
58+
unsigned MaxStoresPerMemset;
59+
60+
unsigned MaxGluedStoresPerMemcpy;
61+
unsigned MaxStoresPerMemcpyOptSize;
62+
unsigned MaxStoresPerMemcpy;
63+
64+
unsigned MaxStoresPerMemmoveOptSize;
65+
unsigned MaxStoresPerMemmove;
66+
67+
unsigned MaxLoadsPerMemcmpOptSize;
68+
unsigned MaxLoadsPerMemcmp;
5669
};
5770

5871
#define GET_RISCVTuneInfoTable_DECL
@@ -325,6 +338,30 @@ class RISCVSubtarget : public RISCVGenSubtargetInfo {
325338
return TuneInfo->TailDupAggressiveThreshold;
326339
}
327340

341+
unsigned getMaxStoresPerMemset(bool OptSize) const {
342+
return OptSize ? TuneInfo->MaxStoresPerMemsetOptSize
343+
: TuneInfo->MaxStoresPerMemset;
344+
}
345+
346+
unsigned getMaxGluedStoresPerMemcpy() const {
347+
return TuneInfo->MaxGluedStoresPerMemcpy;
348+
}
349+
350+
unsigned getMaxStoresPerMemcpy(bool OptSize) const {
351+
return OptSize ? TuneInfo->MaxStoresPerMemcpyOptSize
352+
: TuneInfo->MaxStoresPerMemcpy;
353+
}
354+
355+
unsigned getMaxStoresPerMemmove(bool OptSize) const {
356+
return OptSize ? TuneInfo->MaxStoresPerMemmoveOptSize
357+
: TuneInfo->MaxStoresPerMemmove;
358+
}
359+
360+
unsigned getMaxLoadsPerMemcmp(bool OptSize) const {
361+
return OptSize ? TuneInfo->MaxLoadsPerMemcmpOptSize
362+
: TuneInfo->MaxLoadsPerMemcmp;
363+
}
364+
328365
void overrideSchedPolicy(MachineSchedPolicy &Policy,
329366
unsigned NumRegionInstrs) const override;
330367
};

0 commit comments

Comments
 (0)