Skip to content

Commit 8ce4a8f

Browse files
committed
[CodeGen] Refactor CreateStackTemporary
I've created a new variant of CreateStackTemporary that takes TypeSize and Align arguments, and made the older instances of CreateStackTemporary call this new function. This refactoring is in preparation for more patches in this area related to scalable vectors and improving the alignment calculations. Differential Revision: https://reviews.llvm.org/D79933
1 parent 4042ada commit 8ce4a8f

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

llvm/include/llvm/CodeGen/SelectionDAG.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1595,6 +1595,9 @@ class SelectionDAG {
15951595

15961596
void dump() const;
15971597

1598+
/// Create a stack temporary based on the size in bytes and the alignment
1599+
SDValue CreateStackTemporary(TypeSize Bytes, Align Alignment);
1600+
15981601
/// Create a stack temporary, suitable for holding the specified value type.
15991602
/// If minAlign is specified, the slot size will have at least that alignment.
16001603
SDValue CreateStackTemporary(EVT VT, unsigned minAlign = 1);

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1995,28 +1995,26 @@ SDValue SelectionDAG::expandVACopy(SDNode *Node) {
19951995
MachinePointerInfo(VD));
19961996
}
19971997

1998+
SDValue SelectionDAG::CreateStackTemporary(TypeSize Bytes, Align Alignment) {
1999+
MachineFrameInfo &MFI = MF->getFrameInfo();
2000+
int FrameIdx = MFI.CreateStackObject(Bytes, Alignment, false);
2001+
return getFrameIndex(FrameIdx, TLI->getFrameIndexTy(getDataLayout()));
2002+
}
2003+
19982004
SDValue SelectionDAG::CreateStackTemporary(EVT VT, unsigned minAlign) {
1999-
MachineFrameInfo &MFI = getMachineFunction().getFrameInfo();
2000-
unsigned ByteSize = VT.getStoreSize();
20012005
Type *Ty = VT.getTypeForEVT(*getContext());
2002-
unsigned StackAlign =
2003-
std::max((unsigned)getDataLayout().getPrefTypeAlignment(Ty), minAlign);
2004-
2005-
int FrameIdx = MFI.CreateStackObject(ByteSize, StackAlign, false);
2006-
return getFrameIndex(FrameIdx, TLI->getFrameIndexTy(getDataLayout()));
2006+
Align StackAlign =
2007+
std::max(getDataLayout().getPrefTypeAlign(Ty), Align(minAlign));
2008+
return CreateStackTemporary(VT.getStoreSize(), StackAlign);
20072009
}
20082010

20092011
SDValue SelectionDAG::CreateStackTemporary(EVT VT1, EVT VT2) {
2010-
unsigned Bytes = std::max(VT1.getStoreSize(), VT2.getStoreSize());
2012+
TypeSize Bytes = std::max(VT1.getStoreSize(), VT2.getStoreSize());
20112013
Type *Ty1 = VT1.getTypeForEVT(*getContext());
20122014
Type *Ty2 = VT2.getTypeForEVT(*getContext());
20132015
const DataLayout &DL = getDataLayout();
2014-
unsigned Align =
2015-
std::max(DL.getPrefTypeAlignment(Ty1), DL.getPrefTypeAlignment(Ty2));
2016-
2017-
MachineFrameInfo &MFI = getMachineFunction().getFrameInfo();
2018-
int FrameIdx = MFI.CreateStackObject(Bytes, Align, false);
2019-
return getFrameIndex(FrameIdx, TLI->getFrameIndexTy(getDataLayout()));
2016+
Align Align = std::max(DL.getPrefTypeAlign(Ty1), DL.getPrefTypeAlign(Ty2));
2017+
return CreateStackTemporary(Bytes, Align);
20202018
}
20212019

20222020
SDValue SelectionDAG::FoldSetCC(EVT VT, SDValue N1, SDValue N2,

0 commit comments

Comments
 (0)