[llvm] [RISCV][GISEL] Legalize G_VAARG through expansion. (PR #73065)
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 27 18:23:28 PST 2023
================
@@ -7865,6 +7867,65 @@ LegalizerHelper::lowerVectorReduction(MachineInstr &MI) {
return UnableToLegalize;
}
+static Type *getTypeForLLT(LLT Ty, LLVMContext &C);
+
+LegalizerHelper::LegalizeResult LegalizerHelper::lowerVAArg(MachineInstr &MI) {
+ Observer.changingInstr(MI);
+ MachineFunction &MF = *MI.getMF();
+ const DataLayout &DL = MIRBuilder.getDataLayout();
+ LLVMContext &Ctx = MF.getFunction().getContext();
+ Register ListPtr = MI.getOperand(1).getReg();
+ LLT PtrTy = MRI.getType(ListPtr);
+
+ // LstPtr is a pointer to the head of the list. Get the address
+ // of the head of the list.
+ Align PtrAlignment = Align(DL.getABITypeAlign(getTypeForLLT(PtrTy, Ctx)));
+ MachineMemOperand *PtrLoadMMO =
+ MF.getMachineMemOperand(MachinePointerInfo::getUnknownStack(MF),
+ MachineMemOperand::MOLoad, PtrTy, PtrAlignment);
+ auto HeadOfList = MIRBuilder.buildLoad(PtrTy, ListPtr, *PtrLoadMMO).getReg(0);
+ Register VAList = HeadOfList;
+
+ const MaybeAlign MA(MI.getOperand(2).getImm());
----------------
topperc wrote:
I might have been wrong about that. It looks like the type legalizer in SelectionDAG sets the alignment to 0 to indicate when a ISD::VAARG has been split. We don't have narrowScalar support for G_VAARG yet so we haven't encountered the need for that yet.
Given the way it's used, an alignment of 1 would probably have worked equally well, but maybe 0 made it more obvious to anyone debugging?
https://github.com/llvm/llvm-project/pull/73065
More information about the llvm-commits
mailing list