Skip to content

Commit

Permalink
[RISCV] Make X5 allocatable for JALR on CPUs without RAS
Browse files Browse the repository at this point in the history
Some microarchitectures may not support RAS, then we don't need to
reserve X5 register for JALR.

If RAS is supported, we will select the register allocation order
without X5 (because alternative orders should be subsets of the
default order).
  • Loading branch information
wangpc-pp committed Jan 17, 2024
1 parent baa39b7 commit 333963a
Show file tree
Hide file tree
Showing 4 changed files with 159 additions and 209 deletions.
3 changes: 3 additions & 0 deletions llvm/lib/Target/RISCV/RISCVFeatures.td
Original file line number Diff line number Diff line change
Expand Up @@ -970,6 +970,9 @@ def FeatureFastUnalignedAccess
def FeaturePostRAScheduler : SubtargetFeature<"use-postra-scheduler",
"UsePostRAScheduler", "true", "Schedule again after register allocation">;

def FeatureNoRAS : SubtargetFeature<"no-ras", "HasRAS", "false",
"Hasn't RAS (Return Address Stack)">;

def TuneNoOptimizedZeroStrideLoad
: SubtargetFeature<"no-optimized-zero-stride-load", "HasOptimizedZeroStrideLoad",
"false", "Hasn't optimized (perform fewer memory operations)"
Expand Down
20 changes: 17 additions & 3 deletions llvm/lib/Target/RISCV/RISCVRegisterInfo.td
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,13 @@ def GPRNoX0X2 : GPRRegisterClass<(sub GPR, X0, X2)>;
// stack on some microarchitectures. Also remove the reserved registers X0, X2,
// X3, and X4 as it reduces the number of register classes that get synthesized
// by tablegen.
def GPRJALR : GPRRegisterClass<(sub GPR, (sequence "X%u", 0, 5))>;
// If RAS is supported, we select the alternative register order without X5.
def GPRJALR : GPRRegisterClass<(sub GPR, (sequence "X%u", 0, 4))> {
list<dag> AltOrders = [(sub GPR, (sequence "X%u", 0, 5))];
code AltOrderSelect = [{
return MF.getSubtarget<RISCVSubtarget>().hasRAS();
}];
}

def GPRC : GPRRegisterClass<(add (sequence "X%u", 10, 15),
(sequence "X%u", 8, 9))>;
Expand All @@ -162,9 +168,17 @@ def GPRC : GPRRegisterClass<(add (sequence "X%u", 10, 15),
// restored to the saved value before the tail call, which would clobber a call
// address. We shouldn't use x5 since that is a hint for to pop the return
// address stack on some microarchitectures.
def GPRTC : GPRRegisterClass<(add (sequence "X%u", 6, 7),
// If RAS is supported, we select the alternative register order without X5.
def GPRTC : GPRRegisterClass<(add (sequence "X%u", 5, 7),
(sequence "X%u", 10, 17),
(sequence "X%u", 28, 31))>;
(sequence "X%u", 28, 31))> {
list<dag> AltOrders = [(add (sequence "X%u", 6, 7),
(sequence "X%u", 10, 17),
(sequence "X%u", 28, 31))];
code AltOrderSelect = [{
return MF.getSubtarget<RISCVSubtarget>().hasRAS();
}];
}

def SP : GPRRegisterClass<(add X2)>;

Expand Down
Loading

0 comments on commit 333963a

Please sign in to comment.