@@ -7221,18 +7221,22 @@ SDValue RISCVTargetLowering::lowerINIT_TRAMPOLINE(SDValue Op,
72217221 SDValue FunctionAddress = Op.getOperand(2);
72227222 SDValue StaticChain = Op.getOperand(3);
72237223
7224- // Store the given static chain in the trampoline buffer.
7225- SDValue Addr = DAG.getNode(ISD::ADD, dl, MVT::i64, Trmp,
7226- DAG.getConstant(StaticChainOffset, dl, MVT::i64));
7227- OutChains[4] = DAG.getStore(Root, dl, StaticChain, Addr,
7228- MachinePointerInfo(TrmpAddr, StaticChainOffset));
7229-
7230- // Store the given function address in the trampoline buffer.
7231- Addr = DAG.getNode(ISD::ADD, dl, MVT::i64, Trmp,
7232- DAG.getConstant(FunctionAddressOffset, dl, MVT::i64));
7233- OutChains[5] =
7234- DAG.getStore(Root, dl, FunctionAddress, Addr,
7235- MachinePointerInfo(TrmpAddr, FunctionAddressOffset));
7224+ // Store the given static chain and function pointer in the trampoline buffer.
7225+ struct OffsetValuePair {
7226+ unsigned Offset;
7227+ SDValue Value;
7228+ } OffsetValues[] = {
7229+ {StaticChainOffset, StaticChain},
7230+ {FunctionAddressOffset, FunctionAddress},
7231+ };
7232+ for (auto [Idx, OffsetValue] : llvm::enumerate(OffsetValues)) {
7233+ SDValue Addr =
7234+ DAG.getNode(ISD::ADD, dl, MVT::i64, Trmp,
7235+ DAG.getConstant(OffsetValue.Offset, dl, MVT::i64));
7236+ OutChains[Idx + 4] =
7237+ DAG.getStore(Root, dl, OffsetValue.Value, Addr,
7238+ MachinePointerInfo(TrmpAddr, OffsetValue.Offset));
7239+ }
72367240
72377241 SDValue StoreToken = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, OutChains);
72387242
0 commit comments