From 91b978e15774039f991cf91048dc4cc74726744b Mon Sep 17 00:00:00 2001 From: Manman Ren Date: Mon, 4 Feb 2013 23:45:08 +0000 Subject: [Stack Alignment] emit warning instead of a hard error Per discussion in rdar://13127907, we should emit a hard error only if people write code where the requested alignment is larger than achievable and assumes the low bits are zeros. A warning should be good enough when we are not sure if the source code assumes the low bits are zeros. rdar://13127907 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@174336 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/MachineFunction.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/CodeGen/MachineFunction.cpp') diff --git a/lib/CodeGen/MachineFunction.cpp b/lib/CodeGen/MachineFunction.cpp index 3d7d20d416..4a9a62a704 100644 --- a/lib/CodeGen/MachineFunction.cpp +++ b/lib/CodeGen/MachineFunction.cpp @@ -479,11 +479,11 @@ static inline unsigned clampStackAlignment(bool ShouldClamp, unsigned PrefAlign, if (!ShouldClamp || PrefAlign <= StackAlign) return PrefAlign; if (Alloca && MinAlign > StackAlign) - Alloca->getParent()->getContext().emitError(Alloca, - "Requested Minimal Alignment exceeds the Stack Alignment!"); + Alloca->getParent()->getContext().emitWarning(Alloca, + "Requested alignment exceeds the stack alignment!"); else assert(MinAlign <= StackAlign && - "Requested Minimal Alignment exceeds the Stack Alignment!"); + "Requested alignment exceeds the stack alignment!"); return StackAlign; } -- cgit v1.2.3-70-g09d2 From e6dc59891fc53d65b3f6d19772d26e23e0cc1cac Mon Sep 17 00:00:00 2001 From: Jakob Stoklund Olesen Date: Tue, 5 Feb 2013 18:21:56 +0000 Subject: Remove liveout lists from MachineRegisterInfo. All targets are now adding return value registers as implicit uses on return instructions, and there is no longer a need for the live out lists. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@174417 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/CodeGen/MachineRegisterInfo.h | 15 ++++----------- lib/CodeGen/MachineFunction.cpp | 7 ------- lib/CodeGen/MachineInstr.cpp | 4 ++-- lib/CodeGen/MachineRegisterInfo.cpp | 7 ------- 4 files changed, 6 insertions(+), 27 deletions(-) (limited to 'lib/CodeGen/MachineFunction.cpp') diff --git a/include/llvm/CodeGen/MachineRegisterInfo.h b/include/llvm/CodeGen/MachineRegisterInfo.h index 36427e90ca..b3d2d9e17b 100644 --- a/include/llvm/CodeGen/MachineRegisterInfo.h +++ b/include/llvm/CodeGen/MachineRegisterInfo.h @@ -99,13 +99,11 @@ class MachineRegisterInfo { /// started. BitVector ReservedRegs; - /// LiveIns/LiveOuts - Keep track of the physical registers that are - /// livein/liveout of the function. Live in values are typically arguments in - /// registers, live out values are typically return values in registers. - /// LiveIn values are allowed to have virtual registers associated with them, - /// stored in the second element. + /// Keep track of the physical registers that are live in to the function. + /// Live in values are typically arguments in registers, live out values are + /// typically return values in registers. LiveIn values are allowed to have + /// virtual registers associated with them, stored in the second element. std::vector > LiveIns; - std::vector LiveOuts; MachineRegisterInfo(const MachineRegisterInfo&) LLVM_DELETED_FUNCTION; void operator=(const MachineRegisterInfo&) LLVM_DELETED_FUNCTION; @@ -468,7 +466,6 @@ public: void addLiveIn(unsigned Reg, unsigned vreg = 0) { LiveIns.push_back(std::make_pair(Reg, vreg)); } - void addLiveOut(unsigned Reg) { LiveOuts.push_back(Reg); } // Iteration support for live in/out sets. These sets are kept in sorted // order by their register number. @@ -478,12 +475,8 @@ public: livein_iterator livein_begin() const { return LiveIns.begin(); } livein_iterator livein_end() const { return LiveIns.end(); } bool livein_empty() const { return LiveIns.empty(); } - liveout_iterator liveout_begin() const { return LiveOuts.begin(); } - liveout_iterator liveout_end() const { return LiveOuts.end(); } - bool liveout_empty() const { return LiveOuts.empty(); } bool isLiveIn(unsigned Reg) const; - bool isLiveOut(unsigned Reg) const; /// getLiveInPhysReg - If VReg is a live-in virtual register, return the /// corresponding live-in physical register. diff --git a/lib/CodeGen/MachineFunction.cpp b/lib/CodeGen/MachineFunction.cpp index 4a9a62a704..1898222005 100644 --- a/lib/CodeGen/MachineFunction.cpp +++ b/lib/CodeGen/MachineFunction.cpp @@ -346,13 +346,6 @@ void MachineFunction::print(raw_ostream &OS, SlotIndexes *Indexes) const { } OS << '\n'; } - if (RegInfo && !RegInfo->liveout_empty()) { - OS << "Function Live Outs:"; - for (MachineRegisterInfo::liveout_iterator - I = RegInfo->liveout_begin(), E = RegInfo->liveout_end(); I != E; ++I) - OS << ' ' << PrintReg(*I, TRI); - OS << '\n'; - } for (const_iterator BB = begin(), E = end(); BB != E; ++BB) { OS << '\n'; diff --git a/lib/CodeGen/MachineInstr.cpp b/lib/CodeGen/MachineInstr.cpp index d8b5fd4ea3..32d066894b 100644 --- a/lib/CodeGen/MachineInstr.cpp +++ b/lib/CodeGen/MachineInstr.cpp @@ -1515,12 +1515,12 @@ void MachineInstr::print(raw_ostream &OS, const TargetMachine *TM, unsigned Reg = MO.getReg(); if (TargetRegisterInfo::isPhysicalRegister(Reg)) { const MachineRegisterInfo &MRI = MF->getRegInfo(); - if (MRI.use_empty(Reg) && !MRI.isLiveOut(Reg)) { + if (MRI.use_empty(Reg)) { bool HasAliasLive = false; for (MCRegAliasIterator AI(Reg, TM->getRegisterInfo(), true); AI.isValid(); ++AI) { unsigned AliasReg = *AI; - if (!MRI.use_empty(AliasReg) || MRI.isLiveOut(AliasReg)) { + if (!MRI.use_empty(AliasReg)) { HasAliasLive = true; break; } diff --git a/lib/CodeGen/MachineRegisterInfo.cpp b/lib/CodeGen/MachineRegisterInfo.cpp index 21877e52c2..a777f52cb2 100644 --- a/lib/CodeGen/MachineRegisterInfo.cpp +++ b/lib/CodeGen/MachineRegisterInfo.cpp @@ -283,13 +283,6 @@ bool MachineRegisterInfo::isLiveIn(unsigned Reg) const { return false; } -bool MachineRegisterInfo::isLiveOut(unsigned Reg) const { - for (liveout_iterator I = liveout_begin(), E = liveout_end(); I != E; ++I) - if (*I == Reg) - return true; - return false; -} - /// getLiveInPhysReg - If VReg is a live-in virtual register, return the /// corresponding live-in physical register. unsigned MachineRegisterInfo::getLiveInPhysReg(unsigned VReg) const { -- cgit v1.2.3-70-g09d2 From 8f637adbd383afc2defb5d3f75433b6f2c25d527 Mon Sep 17 00:00:00 2001 From: Bob Wilson Date: Fri, 8 Feb 2013 20:35:15 +0000 Subject: Revert 172027 and 174336. Remove diagnostics about over-aligned stack objects. Aside from the question of whether we report a warning or an error when we can't satisfy a requested stack object alignment, the current implementation of this is not good. We're not providing any source location in the diagnostics and the current warning is not connected to any warning group so you can't control it. We could improve the source location somewhat, but we can do a much better job if this check is implemented in the front-end, so let's do that instead. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@174741 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/CodeGen/MachineFrameInfo.h | 19 ++------- lib/CodeGen/MachineFunction.cpp | 48 +++++++++-------------- lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp | 3 +- lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp | 3 +- test/CodeGen/ARM/alloc-no-stack-realign-error.ll | 19 --------- test/CodeGen/ARM/alloc-no-stack-realign.ll | 2 +- 6 files changed, 24 insertions(+), 70 deletions(-) delete mode 100644 test/CodeGen/ARM/alloc-no-stack-realign-error.ll (limited to 'lib/CodeGen/MachineFunction.cpp') diff --git a/include/llvm/CodeGen/MachineFrameInfo.h b/include/llvm/CodeGen/MachineFrameInfo.h index 0748b9ab24..93d77287d7 100644 --- a/include/llvm/CodeGen/MachineFrameInfo.h +++ b/include/llvm/CodeGen/MachineFrameInfo.h @@ -493,23 +493,11 @@ public: return Objects[ObjectIdx+NumFixedObjects].Size == ~0ULL; } - /// CreateStackObjectWithMinAlign - Create a new statically sized stack - /// object, returning a nonnegative identifier to represent it. This function - /// takes a preferred alignment and a minimal alignment. - /// - int CreateStackObjectWithMinAlign(uint64_t Size, unsigned PrefAlignment, - unsigned MinAlignment, bool isSS, - bool MayNeedSP = false, const AllocaInst *Alloca = 0); - /// CreateStackObject - Create a new statically sized stack object, returning - /// a nonnegative identifier to represent it. Will not emit an error when - /// Alignment can't be satisfied. + /// a nonnegative identifier to represent it. /// int CreateStackObject(uint64_t Size, unsigned Alignment, bool isSS, - bool MayNeedSP = false, const AllocaInst *Alloca = 0) { - return CreateStackObjectWithMinAlign(Size, Alignment, 0, isSS, - MayNeedSP, Alloca); - } + bool MayNeedSP = false, const AllocaInst *Alloca = 0); /// CreateSpillStackObject - Create a new statically sized stack object that /// represents a spill slot, returning a nonnegative identifier to represent @@ -529,8 +517,7 @@ public: /// variable sized object is created, whether or not the index returned is /// actually used. /// - int CreateVariableSizedObject(unsigned PrefAlignment, unsigned MinAlignment, - const AllocaInst *Alloca = 0); + int CreateVariableSizedObject(unsigned Alignment); /// getCalleeSavedInfo - Returns a reference to call saved info vector for the /// current function. diff --git a/lib/CodeGen/MachineFunction.cpp b/lib/CodeGen/MachineFunction.cpp index 1898222005..5e04f2d8a3 100644 --- a/lib/CodeGen/MachineFunction.cpp +++ b/lib/CodeGen/MachineFunction.cpp @@ -466,32 +466,24 @@ void MachineFrameInfo::ensureMaxAlignment(unsigned Align) { } /// clampStackAlignment - Clamp the alignment if requested and emit a warning. -static inline unsigned clampStackAlignment(bool ShouldClamp, unsigned PrefAlign, - unsigned MinAlign, unsigned StackAlign, - const AllocaInst *Alloca = 0) { - if (!ShouldClamp || PrefAlign <= StackAlign) - return PrefAlign; - if (Alloca && MinAlign > StackAlign) - Alloca->getParent()->getContext().emitWarning(Alloca, - "Requested alignment exceeds the stack alignment!"); - else - assert(MinAlign <= StackAlign && - "Requested alignment exceeds the stack alignment!"); +static inline unsigned clampStackAlignment(bool ShouldClamp, unsigned Align, + unsigned StackAlign) { + if (!ShouldClamp || Align <= StackAlign) + return Align; + DEBUG(dbgs() << "Warning: requested alignment " << Align + << " exceeds the stack alignment " << StackAlign + << " when stack realignment is off" << '\n'); return StackAlign; } -/// CreateStackObjectWithMinAlign - Create a new statically sized stack -/// object, returning a nonnegative identifier to represent it. This function -/// takes a preferred alignment and a minimal alignment. +/// CreateStackObject - Create a new statically sized stack object, returning +/// a nonnegative identifier to represent it. /// -int MachineFrameInfo::CreateStackObjectWithMinAlign(uint64_t Size, - unsigned PrefAlignment, unsigned MinAlignment, - bool isSS, bool MayNeedSP, const AllocaInst *Alloca) { +int MachineFrameInfo::CreateStackObject(uint64_t Size, unsigned Alignment, + bool isSS, bool MayNeedSP, const AllocaInst *Alloca) { assert(Size != 0 && "Cannot allocate zero size stack objects!"); - unsigned Alignment = clampStackAlignment( - !TFI.isStackRealignable() || !RealignOption, - PrefAlignment, MinAlignment, - TFI.getStackAlignment(), Alloca); + Alignment = clampStackAlignment(!TFI.isStackRealignable() || !RealignOption, + Alignment, TFI.getStackAlignment()); Objects.push_back(StackObject(Size, Alignment, 0, false, isSS, MayNeedSP, Alloca)); int Index = (int)Objects.size() - NumFixedObjects - 1; @@ -507,8 +499,7 @@ int MachineFrameInfo::CreateStackObjectWithMinAlign(uint64_t Size, int MachineFrameInfo::CreateSpillStackObject(uint64_t Size, unsigned Alignment) { Alignment = clampStackAlignment(!TFI.isStackRealignable() || !RealignOption, - Alignment, 0, - TFI.getStackAlignment()); + Alignment, TFI.getStackAlignment()); CreateStackObject(Size, Alignment, true, false); int Index = (int)Objects.size() - NumFixedObjects - 1; ensureMaxAlignment(Alignment); @@ -520,13 +511,10 @@ int MachineFrameInfo::CreateSpillStackObject(uint64_t Size, /// variable sized object is created, whether or not the index returned is /// actually used. /// -int MachineFrameInfo::CreateVariableSizedObject(unsigned PrefAlignment, - unsigned MinAlignment, const AllocaInst *Alloca) { +int MachineFrameInfo::CreateVariableSizedObject(unsigned Alignment) { HasVarSizedObjects = true; - unsigned Alignment = clampStackAlignment( - !TFI.isStackRealignable() || !RealignOption, - PrefAlignment, MinAlignment, - TFI.getStackAlignment(), Alloca); + Alignment = clampStackAlignment(!TFI.isStackRealignable() || !RealignOption, + Alignment, TFI.getStackAlignment()); Objects.push_back(StackObject(0, Alignment, 0, false, false, true, 0)); ensureMaxAlignment(Alignment); return (int)Objects.size()-NumFixedObjects-1; @@ -547,7 +535,7 @@ int MachineFrameInfo::CreateFixedObject(uint64_t Size, int64_t SPOffset, unsigned StackAlign = TFI.getStackAlignment(); unsigned Align = MinAlign(SPOffset, StackAlign); Align = clampStackAlignment(!TFI.isStackRealignable() || !RealignOption, - Align, 0, TFI.getStackAlignment()); + Align, TFI.getStackAlignment()); Objects.insert(Objects.begin(), StackObject(Size, Align, SPOffset, Immutable, /*isSS*/ false, /*NeedSP*/ false, diff --git a/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp b/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp index 229c50be9a..b46edad7a3 100644 --- a/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp +++ b/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp @@ -95,8 +95,7 @@ void FunctionLoweringInfo::set(const Function &fn, MachineFunction &mf) { (TySize >= 8 && isa(Ty) && cast(Ty)->getElementType()->isIntegerTy(8))); StaticAllocaMap[AI] = - MF->getFrameInfo()->CreateStackObjectWithMinAlign(TySize, Align, - AI->getAlignment(), false, + MF->getFrameInfo()->CreateStackObject(TySize, Align, false, MayNeedSP, AI); } diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp index e0d664314a..405e1e8def 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp @@ -3259,8 +3259,7 @@ void SelectionDAGBuilder::visitAlloca(const AllocaInst &I) { // Inform the Frame Information that we have just allocated a variable-sized // object. - FuncInfo.MF->getFrameInfo()->CreateVariableSizedObject(Align ? Align : 1, - I.getAlignment(), &I); + FuncInfo.MF->getFrameInfo()->CreateVariableSizedObject(Align ? Align : 1); } void SelectionDAGBuilder::visitLoad(const LoadInst &I) { diff --git a/test/CodeGen/ARM/alloc-no-stack-realign-error.ll b/test/CodeGen/ARM/alloc-no-stack-realign-error.ll deleted file mode 100644 index 9b4d12ae8a..0000000000 --- a/test/CodeGen/ARM/alloc-no-stack-realign-error.ll +++ /dev/null @@ -1,19 +0,0 @@ -; RUN: llc < %s -mtriple=armv7-apple-ios -O0 -realign-stack=0 2>&1 | FileCheck %s - -; rdar://12713765 -@T3_retval = common global <16 x float> zeroinitializer, align 16 - -; If alignment for alloc is smaller than or equal to stack alignment, but the -; preferred type alignment is bigger, the alignment will be clamped. -; If alignment for alloca is bigger than stack alignment, the compiler -; will emit a warning. -define void @test(<16 x float>* noalias sret %agg.result) nounwind ssp { -entry: -; CHECK: warning: Requested alignment exceeds the stack alignment! - %retval = alloca <16 x float>, align 16 - %0 = load <16 x float>* @T3_retval, align 16 - store <16 x float> %0, <16 x float>* %retval - %1 = load <16 x float>* %retval - store <16 x float> %1, <16 x float>* %agg.result, align 16 - ret void -} diff --git a/test/CodeGen/ARM/alloc-no-stack-realign.ll b/test/CodeGen/ARM/alloc-no-stack-realign.ll index 94adc9c67d..273041dee3 100644 --- a/test/CodeGen/ARM/alloc-no-stack-realign.ll +++ b/test/CodeGen/ARM/alloc-no-stack-realign.ll @@ -39,7 +39,7 @@ entry: ; NO-REALIGN: add [[R2:r[0-9]+]], [[R1:r[0-9]+]], #16 ; NO-REALIGN: vst1.64 ; NO-REALIGN: vst1.64 - %retval = alloca <16 x float>, align 4 + %retval = alloca <16 x float>, align 16 %0 = load <16 x float>* @T3_retval, align 16 store <16 x float> %0, <16 x float>* %retval %1 = load <16 x float>* %retval -- cgit v1.2.3-70-g09d2