[PATCH] D53490: [MIR] Provide a default alignment for stack objects
Francis Visoiu Mistrih via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 22 04:35:03 PDT 2018
thegameg created this revision.
thegameg added reviewers: MatzeB, qcolombet, dsanders, bogner.
Herald added a subscriber: javed.absar.
Currently, stack objects without alignment cause div by 0 in estimateStackSize.
See PR36459 <https://llvm.org/PR36459>.
https://reviews.llvm.org/D53490
Files:
lib/CodeGen/MIRParser/MIRParser.cpp
test/CodeGen/MIR/AArch64/stack-align-zero.mir
Index: test/CodeGen/MIR/AArch64/stack-align-zero.mir
===================================================================
--- /dev/null
+++ test/CodeGen/MIR/AArch64/stack-align-zero.mir
@@ -0,0 +1,12 @@
+# RUN: llc -run-pass=none -o - -mtriple=aarch64-- %s | FileCheck %s
+# Check that the stack object alignment is never 0, even if it's not specified.
+---
+name: foo
+tracksRegLiveness: true
+stack:
+ - { id : 0, size: 8 }
+# CHECK: - { id: 0, name: '', type: default, offset: 0, size: 8, alignment: 16
+body: |
+ bb.0:
+ RET_ReallyLR
+...
Index: lib/CodeGen/MIRParser/MIRParser.cpp
===================================================================
--- lib/CodeGen/MIRParser/MIRParser.cpp
+++ lib/CodeGen/MIRParser/MIRParser.cpp
@@ -28,6 +28,7 @@
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineModuleInfo.h"
#include "llvm/CodeGen/MachineRegisterInfo.h"
+#include "llvm/CodeGen/TargetFrameLowering.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/DebugInfo.h"
#include "llvm/IR/DiagnosticInfo.h"
@@ -562,6 +563,21 @@
return Error;
}
+static unsigned GetStackObjectAlignment(const yaml::MachineStackObject &Object,
+ const MachineFunction &MF) {
+ const Function &F = MF.getFunction();
+ // If set in the YAML, use that one.
+ unsigned Alignment = Object.Alignment;
+ if (Alignment)
+ return Alignment;
+
+ // Try to get the default stack alignment from the IR function attrs.
+ if (F.hasFnAttribute(Attribute::StackAlignment))
+ return F.getFnStackAlignment();
+ else
+ return MF.getSubtarget().getFrameLowering()->getStackAlignment();
+}
+
bool MIRParserImpl::initializeFrameInfo(PerFunctionMIParsingState &PFS,
const yaml::MachineFunction &YamlMF) {
MachineFunction &MF = PFS.MF;
@@ -640,7 +656,7 @@
ObjectIdx = MFI.CreateVariableSizedObject(Object.Alignment, Alloca);
else
ObjectIdx = MFI.CreateStackObject(
- Object.Size, Object.Alignment,
+ Object.Size, GetStackObjectAlignment(Object, MF),
Object.Type == yaml::MachineStackObject::SpillSlot, Alloca);
MFI.setObjectOffset(ObjectIdx, Object.Offset);
MFI.setStackID(ObjectIdx, Object.StackID);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53490.170387.patch
Type: text/x-patch
Size: 2278 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181022/9af99368/attachment.bin>
More information about the llvm-commits
mailing list