aboutsummaryrefslogtreecommitdiff
path: root/backend/unittests
diff options
context:
space:
mode:
authorRichard-Qin-X <richard.qin.001@gmail.com>2026-08-12 02:23:11 +0800
committerRichard-Qin-X <richard.qin.001@gmail.com>2026-08-12 02:23:11 +0800
commit33c887caf02b28fd45cf7cf966537e123081ff53 (patch)
tree3ec2a7942b9c63a035ffc06031d18706a9ec7d71 /backend/unittests
parent16b269164d072f3c0be713decc977c5c5f44f5e8 (diff)
downloadrcc-project-33c887caf02b28fd45cf7cf966537e123081ff53.tar.gz
rcc-project-33c887caf02b28fd45cf7cf966537e123081ff53.tar.xz
[RISCV] Legalize G_FRAME_INDEX for p0
Diffstat (limited to 'backend/unittests')
-rw-r--r--backend/unittests/Target/RISCVCodeGenTest.cpp50
1 files changed, 50 insertions, 0 deletions
diff --git a/backend/unittests/Target/RISCVCodeGenTest.cpp b/backend/unittests/Target/RISCVCodeGenTest.cpp
index 97728ae..d07387a 100644
--- a/backend/unittests/Target/RISCVCodeGenTest.cpp
+++ b/backend/unittests/Target/RISCVCodeGenTest.cpp
@@ -1626,6 +1626,55 @@ void testVAArgLegalization(TestContext &Context) {
"va_arg expansion must attach typed MMOs to every concrete memory access");
}
+void testFrameIndexLegalization(TestContext &Context) {
+ auto Target = rcc::riscv::createTargetDescription();
+ Context.expect(Target.has_value(),
+ "RV64GC target must be available for frame-index legalization");
+ if (!Target)
+ return;
+ auto Function = rcc::MachineFunction::create("riscv_frame_index",
+ rcc::MachineFunctionStableID::fromValue(104));
+ if (!Function)
+ return;
+ auto Block = (*Function)->createBasicBlock();
+ auto Pointer = rcc::LLT::makePointer(0, 64);
+ auto OtherAddressSpace = rcc::LLT::makePointer(1, 64);
+ rcc::StackObjectDesc StackSlot;
+ StackSlot.Size = 8;
+ StackSlot.Align = *rcc::Alignment::create(8);
+ auto Frame = (*Function)->frameInfo().createObject(StackSlot);
+ if (!Block || !Pointer || !OtherAddressSpace || !Frame || !(*Function)->appendBlock(**Block))
+ return;
+ auto Result = (*Function)->registerInfo().createVirtualRegister(*Pointer);
+ auto UnsupportedResult = (*Function)->registerInfo().createVirtualRegister(*OtherAddressSpace);
+ if (!Result || !UnsupportedResult)
+ return;
+
+ rcc::MachineIRBuilder Builder(**Function, *Target);
+ if (!Builder.setInsertPoint(**Block))
+ return;
+ auto Legal = Builder.buildInstr(rcc::opcode(rcc::GenericOpcode::G_FRAME_INDEX));
+ if (!Legal || !Legal->addDef(*Result) || !Legal->addFrameIndex(*Frame))
+ return;
+ auto BuiltLegal = Legal->build();
+ auto Unsupported = Builder.buildInstr(rcc::opcode(rcc::GenericOpcode::G_FRAME_INDEX));
+ if (!BuiltLegal || !Unsupported || !Unsupported->addDef(*UnsupportedResult) ||
+ !Unsupported->addFrameIndex(*Frame)) {
+ return;
+ }
+ auto BuiltUnsupported = Unsupported->build();
+ if (!BuiltUnsupported)
+ return;
+
+ auto LegalAction = rcc::riscv::legalizerInfo().classify(**BuiltLegal, **Function, *Target);
+ auto UnsupportedAction =
+ rcc::riscv::legalizerInfo().classify(**BuiltUnsupported, **Function, *Target);
+ Context.expect(LegalAction && *LegalAction == rcc::LegalizationAction::Legal,
+ "RV64GC must legalize G_FRAME_INDEX for p0");
+ Context.expect(UnsupportedAction && *UnsupportedAction == rcc::LegalizationAction::Unsupported,
+ "RV64GC must reject G_FRAME_INDEX outside p0");
+}
+
void testMemoryOffsetSelection(TestContext &Context) {
auto Target = rcc::riscv::createTargetDescription();
Context.expect(Target.has_value(), "RV64GC target must be available for memory selection");
@@ -1711,6 +1760,7 @@ int main() {
testUnsupportedTypes(Context);
testVACopyLegalization(Context);
testVAArgLegalization(Context);
+ testFrameIndexLegalization(Context);
testMemoryOffsetSelection(Context);
return Context.result();
}