Skip to content

Commit 3a73d1c

Browse files
committed
Reduce the amount of repetition
1 parent 6d65d1b commit 3a73d1c

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7506,18 +7506,22 @@ SDValue RISCVTargetLowering::lowerINIT_TRAMPOLINE(SDValue Op,
75067506
SDValue FunctionAddress = Op.getOperand(2);
75077507
SDValue StaticChain = Op.getOperand(3);
75087508

7509-
// Store the given static chain in the trampoline buffer.
7510-
SDValue Addr = DAG.getNode(ISD::ADD, dl, MVT::i64, Trmp,
7511-
DAG.getConstant(StaticChainOffset, dl, MVT::i64));
7512-
OutChains[4] = DAG.getStore(Root, dl, StaticChain, Addr,
7513-
MachinePointerInfo(TrmpAddr, StaticChainOffset));
7514-
7515-
// Store the given function address in the trampoline buffer.
7516-
Addr = DAG.getNode(ISD::ADD, dl, MVT::i64, Trmp,
7517-
DAG.getConstant(FunctionAddressOffset, dl, MVT::i64));
7518-
OutChains[5] =
7519-
DAG.getStore(Root, dl, FunctionAddress, Addr,
7520-
MachinePointerInfo(TrmpAddr, FunctionAddressOffset));
7509+
// Store the given static chain and function pointer in the trampoline buffer.
7510+
struct OffsetValuePair {
7511+
unsigned Offset;
7512+
SDValue Value;
7513+
} OffsetValues[] = {
7514+
{StaticChainOffset, StaticChain},
7515+
{FunctionAddressOffset, FunctionAddress},
7516+
};
7517+
for (auto [Idx, OffsetValue] : llvm::enumerate(OffsetValues)) {
7518+
SDValue Addr =
7519+
DAG.getNode(ISD::ADD, dl, MVT::i64, Trmp,
7520+
DAG.getConstant(OffsetValue.Offset, dl, MVT::i64));
7521+
OutChains[Idx + 4] =
7522+
DAG.getStore(Root, dl, OffsetValue.Value, Addr,
7523+
MachinePointerInfo(TrmpAddr, OffsetValue.Offset));
7524+
}
75217525

75227526
SDValue StoreToken = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, OutChains);
75237527

0 commit comments

Comments
 (0)