llvm.org GIT mirror llvm / c0cc283
Reapply r183552. This time, use a standard type for the option to avoid template instantiation issue with non-standard type. Add a backend option to warn on a given stack size limit. Option: -mllvm -warn-stack-size=<limit> Output (if limit is exceeded): warning: Stack size limit exceeded (<actual size>) in <functionName>. The longer term plan is to hook that to a clang warning. PR:4072 <rdar://problem/13987214>. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@183595 91177308-0d34-0410-b5e6-96231b3b80d8 Quentin Colombet 6 years ago
3 changed file(s) with 61 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
3434 #include "llvm/Support/CommandLine.h"
3535 #include "llvm/Support/Compiler.h"
3636 #include "llvm/Support/Debug.h"
37 #include "llvm/Support/raw_ostream.h"
3738 #include "llvm/Target/TargetFrameLowering.h"
3839 #include "llvm/Target/TargetInstrInfo.h"
3940 #include "llvm/Target/TargetMachine.h"
4445
4546 char PEI::ID = 0;
4647 char &llvm::PrologEpilogCodeInserterID = PEI::ID;
48
49 static cl::opt
50 WarnStackSize("warn-stack-size", cl::Hidden, cl::init((unsigned)-1),
51 cl::desc("Warn for stack size bigger than the given"
52 " number"));
4753
4854 INITIALIZE_PASS_BEGIN(PEI, "prologepilog",
4955 "Prologue/Epilogue Insertion", false, false)
126132
127133 // Clear any vregs created by virtual scavenging.
128134 Fn.getRegInfo().clearVirtRegs();
135
136 // Warn on stack size when we exceeds the given limit.
137 MachineFrameInfo *MFI = Fn.getFrameInfo();
138 if (WarnStackSize.getNumOccurrences() > 0 &&
139 WarnStackSize < MFI->getStackSize())
140 errs() << "warning: Stack size limit exceeded (" << MFI->getStackSize()
141 << ") in " << Fn.getName() << ".\n";
129142
130143 delete RS;
131144 clearAllSets();
0 ; RUN: llc -mtriple thumbv7-apple-ios3.0.0 -warn-stack-size=80 < %s 2>&1 >/dev/null | FileCheck %s
1 ; Check the internal option that warns when the stack size exceeds the
2 ; given amount.
3 ;
4
5 ; CHECK-NOT: nowarn
6 define void @nowarn() nounwind ssp {
7 entry:
8 %buffer = alloca [12 x i8], align 1
9 %arraydecay = getelementptr inbounds [12 x i8]* %buffer, i64 0, i64 0
10 call void @doit(i8* %arraydecay) nounwind
11 ret void
12 }
13
14 ; CHECK: warning: Stack size limit exceeded (96) in warn.
15 define void @warn() nounwind ssp {
16 entry:
17 %buffer = alloca [80 x i8], align 1
18 %arraydecay = getelementptr inbounds [80 x i8]* %buffer, i64 0, i64 0
19 call void @doit(i8* %arraydecay) nounwind
20 ret void
21 }
22
23 declare void @doit(i8*)
0 ; RUN: llc -mtriple x86_64-apple-macosx10.8.0 -warn-stack-size=80 < %s 2>&1 >/dev/null | FileCheck %s
1 ; Check the internal option that warns when the stack size exceeds the
2 ; given amount.
3 ;
4
5 ; CHECK-NOT: nowarn
6 define void @nowarn() nounwind ssp {
7 entry:
8 %buffer = alloca [12 x i8], align 1
9 %arraydecay = getelementptr inbounds [12 x i8]* %buffer, i64 0, i64 0
10 call void @doit(i8* %arraydecay) nounwind
11 ret void
12 }
13
14 ; CHECK: warning: Stack size limit exceeded (104) in warn.
15 define void @warn() nounwind ssp {
16 entry:
17 %buffer = alloca [80 x i8], align 1
18 %arraydecay = getelementptr inbounds [80 x i8]* %buffer, i64 0, i64 0
19 call void @doit(i8* %arraydecay) nounwind
20 ret void
21 }
22
23 declare void @doit(i8*)