Skip to content

Commit a12b83f

Browse files
committed
[llvm][RISCV] Support RISCV vector tuple CodeGen and Calling Convention
This patch handles target lowering and calling convention. For target lowering, the vector tuple type represented as multiple scalable vectors is now changed to a single `MVT`, each `MVT` has a corresponding register class. The load/store of vector tuples are handled as the same way but need another vector insert/extract instructions to get sub-register group. Inline assembly constraint for vector tuple type can directly be modeled as "vr" which is identical to normal vector registers. For calling convention, it no longer needs an alternative algorithm to handle register allocation, this makes the code easier to maintain and read.
1 parent 6d2380f commit a12b83f

39 files changed

+101728
-107258
lines changed

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7283,17 +7283,19 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
72837283
EVT N1VT = N1.getValueType();
72847284
assert(VT.isVector() && N1VT.isVector() &&
72857285
"Extract subvector VTs must be vectors!");
7286-
assert(VT.getVectorElementType() == N1VT.getVectorElementType() &&
7287-
"Extract subvector VTs must have the same element type!");
7288-
assert((VT.isFixedLengthVector() || N1VT.isScalableVector()) &&
7286+
if (!N1VT.isRISCVVectorTuple())
7287+
assert(VT.getVectorElementType() == N1VT.getVectorElementType() &&
7288+
"Extract subvector VTs must have the same element type!");
7289+
assert((VT.isFixedLengthVector() || N1VT.isScalableVector() ||
7290+
N1VT.isRISCVVectorTuple()) &&
72897291
"Cannot extract a scalable vector from a fixed length vector!");
72907292
assert((VT.isScalableVector() != N1VT.isScalableVector() ||
72917293
VT.getVectorMinNumElements() <= N1VT.getVectorMinNumElements()) &&
72927294
"Extract subvector must be from larger vector to smaller vector!");
72937295
assert(N2C && "Extract subvector index must be a constant");
72947296
assert((VT.isScalableVector() != N1VT.isScalableVector() ||
7295-
(VT.getVectorMinNumElements() + N2C->getZExtValue()) <=
7296-
N1VT.getVectorMinNumElements()) &&
7297+
((N1VT.isRISCVVectorTuple() ? 0 : VT.getVectorMinNumElements()) +
7298+
N2C->getZExtValue()) <= N1VT.getVectorMinNumElements()) &&
72977299
"Extract subvector overflow!");
72987300
assert(N2C->getAPIntValue().getBitWidth() ==
72997301
TLI->getVectorIdxTy(getDataLayout()).getFixedSizeInBits() &&
@@ -7516,18 +7518,23 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
75167518
"Dest and insert subvector source types must match!");
75177519
assert(VT.isVector() && N2VT.isVector() &&
75187520
"Insert subvector VTs must be vectors!");
7519-
assert(VT.getVectorElementType() == N2VT.getVectorElementType() &&
7520-
"Insert subvector VTs must have the same element type!");
7521-
assert((VT.isScalableVector() || N2VT.isFixedLengthVector()) &&
7522-
"Cannot insert a scalable vector into a fixed length vector!");
7521+
if (!VT.isRISCVVectorTuple()) {
7522+
assert(VT.getVectorElementType() == N2VT.getVectorElementType() &&
7523+
"Insert subvector VTs must have the same element type!");
7524+
assert((VT.isScalableVector() || N2VT.isFixedLengthVector()) &&
7525+
"Cannot insert a scalable vector into a fixed length vector!");
7526+
}
7527+
if (VT.isRISCVVectorTuple())
7528+
assert((N2VT.isScalableVector() || N2VT.isRISCVVectorTuple()) &&
7529+
"Cannot insert a fixed length vector into a RISCV vector tuple!");
75237530
assert((VT.isScalableVector() != N2VT.isScalableVector() ||
75247531
VT.getVectorMinNumElements() >= N2VT.getVectorMinNumElements()) &&
75257532
"Insert subvector must be from smaller vector to larger vector!");
75267533
assert(isa<ConstantSDNode>(N3) &&
75277534
"Insert subvector index must be constant");
75287535
assert((VT.isScalableVector() != N2VT.isScalableVector() ||
7529-
(N2VT.getVectorMinNumElements() + N3->getAsZExtVal()) <=
7530-
VT.getVectorMinNumElements()) &&
7536+
((VT.isRISCVVectorTuple() ? 0 : N2VT.getVectorMinNumElements()) +
7537+
N3->getAsZExtVal()) <= VT.getVectorMinNumElements()) &&
75317538
"Insert subvector overflow!");
75327539
assert(N3->getAsAPIntVal().getBitWidth() ==
75337540
TLI->getVectorIdxTy(getDataLayout()).getFixedSizeInBits() &&

llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3055,7 +3055,7 @@ bool TargetLowering::SimplifyDemandedVectorElts(
30553055
return false;
30563056

30573057
// TODO: For now we assume we know nothing about scalable vectors.
3058-
if (VT.isScalableVector())
3058+
if (VT.isScalableVector() || VT.isRISCVVectorTuple())
30593059
return false;
30603060

30613061
assert(VT.getVectorNumElements() == NumElts &&

llvm/lib/CodeGen/TargetLoweringBase.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,6 +1382,10 @@ void TargetLoweringBase::computeRegisterProperties(
13821382
// Try to widen the vector.
13831383
for (unsigned nVT = i + 1; nVT <= MVT::LAST_VECTOR_VALUETYPE; ++nVT) {
13841384
MVT SVT = (MVT::SimpleValueType) nVT;
1385+
// Skip RISCV vector tuple types since they don't involve in any
1386+
// widen/narrow operation.
1387+
if (SVT.isRISCVVectorTuple())
1388+
continue;
13851389
if (SVT.getVectorElementType() == EltVT &&
13861390
SVT.isScalableVector() == IsScalable &&
13871391
SVT.getVectorElementCount().getKnownMinValue() >

llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1681,6 +1681,12 @@ MCRegister RISCVAsmParser::matchRegisterNameHelper(StringRef Name) const {
16811681
Reg = MatchRegisterAltName(Name);
16821682
if (isRVE() && Reg >= RISCV::X16 && Reg <= RISCV::X31)
16831683
Reg = RISCV::NoRegister;
1684+
1685+
// Replace vector tuple with the starting register, e.g. V4M4_V8M4 -> V4
1686+
for (int i = 30; i >= 0; --i)
1687+
if (Name.starts_with("V" + utostr(i)))
1688+
return RISCV::V0 + i;
1689+
16841690
return Reg;
16851691
}
16861692

0 commit comments

Comments
 (0)