[llvm] [RISCV][GISEL] Legalize G_VAARG through expansion. (PR #73065)

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 28 08:54:20 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:

> > IRTranslator::translateVAArg uses getABITypeAlign which returns an Align and then converts that to an integer.
> 
> 
> 
> We're always going to get an `Align`, not a MaybeAlign. I think we can use Align. SDAG does use 0 to indicate the Hi part of the split, but we are not doing that today in GISel, so I don't think it matters?

Don't we need to add splitting to GlobalISel? We have RISC-V tests for it on SelectionDAG.

https://github.com/llvm/llvm-project/pull/73065


More information about the llvm-commits mailing list