forked from OSchip/llvm-project
[Alignment][NFC] Convert MachineIRBuilder::buildDynStackAlloc to Align
Summary: The change in IRTranslator is not trivial but is NFC as far as I can tell. This is patch is part of a series to introduce an Alignment type. See this thread for context: http://lists.llvm.org/pipermail/llvm-dev/2019-July/133851.html See this patch for the introduction of the type: https://reviews.llvm.org/D64790 Reviewers: courbet Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D77292
This commit is contained in:
parent
1aee1ae532
commit
ca11c480e7
|
@ -379,7 +379,14 @@ public:
|
||||||
///
|
///
|
||||||
/// \return a MachineInstrBuilder for the newly created instruction.
|
/// \return a MachineInstrBuilder for the newly created instruction.
|
||||||
MachineInstrBuilder buildDynStackAlloc(const DstOp &Res, const SrcOp &Size,
|
MachineInstrBuilder buildDynStackAlloc(const DstOp &Res, const SrcOp &Size,
|
||||||
unsigned Align);
|
Align Alignment);
|
||||||
|
|
||||||
|
LLVM_ATTRIBUTE_DEPRECATED(inline MachineInstrBuilder buildDynStackAlloc(
|
||||||
|
const DstOp &Res, const SrcOp &Size,
|
||||||
|
unsigned Align),
|
||||||
|
"Use the version that takes MaybeAlign instead") {
|
||||||
|
return buildDynStackAlloc(Res, Size, assumeAligned(Align));
|
||||||
|
}
|
||||||
|
|
||||||
/// Build and insert \p Res = G_FRAME_INDEX \p Idx
|
/// Build and insert \p Res = G_FRAME_INDEX \p Idx
|
||||||
///
|
///
|
||||||
|
|
|
@ -1859,7 +1859,6 @@ bool IRTranslator::translateAlloca(const User &U,
|
||||||
|
|
||||||
// Now we're in the harder dynamic case.
|
// Now we're in the harder dynamic case.
|
||||||
Register NumElts = getOrCreateVReg(*AI.getArraySize());
|
Register NumElts = getOrCreateVReg(*AI.getArraySize());
|
||||||
|
|
||||||
Type *IntPtrIRTy = DL->getIntPtrType(AI.getType());
|
Type *IntPtrIRTy = DL->getIntPtrType(AI.getType());
|
||||||
LLT IntPtrTy = getLLTForType(*IntPtrIRTy, *DL);
|
LLT IntPtrTy = getLLTForType(*IntPtrIRTy, *DL);
|
||||||
if (MRI->getType(NumElts) != IntPtrTy) {
|
if (MRI->getType(NumElts) != IntPtrTy) {
|
||||||
|
@ -1878,22 +1877,20 @@ bool IRTranslator::translateAlloca(const User &U,
|
||||||
// Round the size of the allocation up to the stack alignment size
|
// Round the size of the allocation up to the stack alignment size
|
||||||
// by add SA-1 to the size. This doesn't overflow because we're computing
|
// by add SA-1 to the size. This doesn't overflow because we're computing
|
||||||
// an address inside an alloca.
|
// an address inside an alloca.
|
||||||
unsigned StackAlign =
|
Align StackAlign = MF->getSubtarget().getFrameLowering()->getStackAlign();
|
||||||
MF->getSubtarget().getFrameLowering()->getStackAlignment();
|
auto SAMinusOne = MIRBuilder.buildConstant(IntPtrTy, StackAlign.value() - 1);
|
||||||
auto SAMinusOne = MIRBuilder.buildConstant(IntPtrTy, StackAlign - 1);
|
|
||||||
auto AllocAdd = MIRBuilder.buildAdd(IntPtrTy, AllocSize, SAMinusOne,
|
auto AllocAdd = MIRBuilder.buildAdd(IntPtrTy, AllocSize, SAMinusOne,
|
||||||
MachineInstr::NoUWrap);
|
MachineInstr::NoUWrap);
|
||||||
auto AlignCst =
|
auto AlignCst =
|
||||||
MIRBuilder.buildConstant(IntPtrTy, ~(uint64_t)(StackAlign - 1));
|
MIRBuilder.buildConstant(IntPtrTy, ~(uint64_t)(StackAlign.value() - 1));
|
||||||
auto AlignedAlloc = MIRBuilder.buildAnd(IntPtrTy, AllocAdd, AlignCst);
|
auto AlignedAlloc = MIRBuilder.buildAnd(IntPtrTy, AllocAdd, AlignCst);
|
||||||
|
|
||||||
unsigned Align =
|
Align Alignment = max(AI.getAlign(), DL->getPrefTypeAlign(Ty));
|
||||||
std::max((unsigned)DL->getPrefTypeAlignment(Ty), AI.getAlignment());
|
if (Alignment <= StackAlign)
|
||||||
if (Align <= StackAlign)
|
Alignment = Align(1);
|
||||||
Align = 0;
|
MIRBuilder.buildDynStackAlloc(getOrCreateVReg(AI), AlignedAlloc, Alignment);
|
||||||
MIRBuilder.buildDynStackAlloc(getOrCreateVReg(AI), AlignedAlloc, Align);
|
|
||||||
|
|
||||||
MF->getFrameInfo().CreateVariableSizedObject(Align ? Align : 1, &AI);
|
MF->getFrameInfo().CreateVariableSizedObject(Alignment, &AI);
|
||||||
assert(MF->getFrameInfo().hasVarSizedObjects());
|
assert(MF->getFrameInfo().hasVarSizedObjects());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -162,12 +162,12 @@ MachineInstrBuilder MachineIRBuilder::buildDbgLabel(const MDNode *Label) {
|
||||||
|
|
||||||
MachineInstrBuilder MachineIRBuilder::buildDynStackAlloc(const DstOp &Res,
|
MachineInstrBuilder MachineIRBuilder::buildDynStackAlloc(const DstOp &Res,
|
||||||
const SrcOp &Size,
|
const SrcOp &Size,
|
||||||
unsigned Align) {
|
Align Alignment) {
|
||||||
assert(Res.getLLTTy(*getMRI()).isPointer() && "expected ptr dst type");
|
assert(Res.getLLTTy(*getMRI()).isPointer() && "expected ptr dst type");
|
||||||
auto MIB = buildInstr(TargetOpcode::G_DYN_STACKALLOC);
|
auto MIB = buildInstr(TargetOpcode::G_DYN_STACKALLOC);
|
||||||
Res.addDefToMIB(*getMRI(), MIB);
|
Res.addDefToMIB(*getMRI(), MIB);
|
||||||
Size.addSrcToMIB(MIB);
|
Size.addSrcToMIB(MIB);
|
||||||
MIB.addImm(Align);
|
MIB.addImm(Alignment.value());
|
||||||
return MIB;
|
return MIB;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ define i8* @test_simple_alloca(i32 %numelts) {
|
||||||
; CHECK: [[ADD:%[0-9]+]]:_(s64) = nuw G_ADD [[MUL]], [[C1]]
|
; CHECK: [[ADD:%[0-9]+]]:_(s64) = nuw G_ADD [[MUL]], [[C1]]
|
||||||
; CHECK: [[C2:%[0-9]+]]:_(s64) = G_CONSTANT i64 -16
|
; CHECK: [[C2:%[0-9]+]]:_(s64) = G_CONSTANT i64 -16
|
||||||
; CHECK: [[AND:%[0-9]+]]:_(s64) = G_AND [[ADD]], [[C2]]
|
; CHECK: [[AND:%[0-9]+]]:_(s64) = G_AND [[ADD]], [[C2]]
|
||||||
; CHECK: [[DYN_STACKALLOC:%[0-9]+]]:_(p0) = G_DYN_STACKALLOC [[AND]](s64), 0
|
; CHECK: [[DYN_STACKALLOC:%[0-9]+]]:_(p0) = G_DYN_STACKALLOC [[AND]](s64), 1
|
||||||
; CHECK: $x0 = COPY [[DYN_STACKALLOC]](p0)
|
; CHECK: $x0 = COPY [[DYN_STACKALLOC]](p0)
|
||||||
; CHECK: RET_ReallyLR implicit $x0
|
; CHECK: RET_ReallyLR implicit $x0
|
||||||
%addr = alloca i8, i32 %numelts
|
%addr = alloca i8, i32 %numelts
|
||||||
|
@ -51,7 +51,7 @@ define i128* @test_natural_alloca(i32 %numelts) {
|
||||||
; CHECK: [[ADD:%[0-9]+]]:_(s64) = nuw G_ADD [[MUL]], [[C1]]
|
; CHECK: [[ADD:%[0-9]+]]:_(s64) = nuw G_ADD [[MUL]], [[C1]]
|
||||||
; CHECK: [[C2:%[0-9]+]]:_(s64) = G_CONSTANT i64 -16
|
; CHECK: [[C2:%[0-9]+]]:_(s64) = G_CONSTANT i64 -16
|
||||||
; CHECK: [[AND:%[0-9]+]]:_(s64) = G_AND [[ADD]], [[C2]]
|
; CHECK: [[AND:%[0-9]+]]:_(s64) = G_AND [[ADD]], [[C2]]
|
||||||
; CHECK: [[DYN_STACKALLOC:%[0-9]+]]:_(p0) = G_DYN_STACKALLOC [[AND]](s64), 0
|
; CHECK: [[DYN_STACKALLOC:%[0-9]+]]:_(p0) = G_DYN_STACKALLOC [[AND]](s64), 1
|
||||||
; CHECK: $x0 = COPY [[DYN_STACKALLOC]](p0)
|
; CHECK: $x0 = COPY [[DYN_STACKALLOC]](p0)
|
||||||
; CHECK: RET_ReallyLR implicit $x0
|
; CHECK: RET_ReallyLR implicit $x0
|
||||||
%addr = alloca i128, i32 %numelts
|
%addr = alloca i128, i32 %numelts
|
||||||
|
|
Loading…
Reference in New Issue