llvm.org GIT mirror llvm / 07b072b
Update StackProtector when coloring merges stack slots StackProtector keeps a ValueMap of alloca instructions to layout kind tags for use by PEI and other later passes. When stack coloring replaces one alloca with a bitcast to another one, the key replacement in this map does not work. Instead, provide an interface to manage this updating directly. This seems like an improvement over the old behavior, where the layout map would not get updated at all when the stack slots were merged. In practice, however, there is likely no observable difference because PEI only did anything special with 'large array' kinds, and if one large array is merged with another, than the replacement should already have been a large array. This is an attempt to unbreak the clang-x86_64-darwin11-RA builder. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199684 91177308-0d34-0410-b5e6-96231b3b80d8 Hal Finkel 6 years ago
3 changed file(s) with 32 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
118118 }
119119
120120 SSPLayoutKind getSSPLayout(const AllocaInst *AI) const;
121 void adjustForColoring(const AllocaInst *From, const AllocaInst *To);
121122
122123 virtual bool runOnFunction(Function &Fn);
123124 };
4242 #include "llvm/CodeGen/MachineRegisterInfo.h"
4343 #include "llvm/CodeGen/PseudoSourceValue.h"
4444 #include "llvm/CodeGen/SlotIndexes.h"
45 #include "llvm/CodeGen/StackProtector.h"
4546 #include "llvm/DebugInfo.h"
4647 #include "llvm/IR/Dominators.h"
4748 #include "llvm/IR/Function.h"
116117 VNInfo::Allocator VNInfoAllocator;
117118 /// SlotIndex analysis object.
118119 SlotIndexes *Indexes;
120 /// The stack protector object.
121 StackProtector *SP;
119122
120123 /// The list of lifetime markers found. These markers are to be removed
121124 /// once the coloring is done.
190193 "stack-coloring", "Merge disjoint stack slots", false, false)
191194 INITIALIZE_PASS_DEPENDENCY(MachineDominatorTree)
192195 INITIALIZE_PASS_DEPENDENCY(SlotIndexes)
196 INITIALIZE_PASS_DEPENDENCY(StackProtector)
193197 INITIALIZE_PASS_END(StackColoring,
194198 "stack-coloring", "Merge disjoint stack slots", false, false)
195199
197201 AU.addRequired();
198202 AU.addPreserved();
199203 AU.addRequired();
204 AU.addRequired();
200205 MachineFunctionPass::getAnalysisUsage(AU);
201206 }
202207
515520 Cast->insertAfter(Inst);
516521 Inst = Cast;
517522 }
523
524 // Allow the stack protector to adjust its value map to account for the
525 // upcoming replacement.
526 SP->adjustForColoring(From, To);
518527
519528 // Note that this will not replace uses in MMOs (which we'll update below),
520529 // or anywhere else (which is why we won't delete the original
673682 MF = &Func;
674683 MFI = MF->getFrameInfo();
675684 Indexes = &getAnalysis();
685 SP = &getAnalysis();
676686 BlockLiveness.clear();
677687 BasicBlocks.clear();
678688 BasicBlockNumbering.clear();
5454 StackProtector::SSPLayoutKind
5555 StackProtector::getSSPLayout(const AllocaInst *AI) const {
5656 return AI ? Layout.lookup(AI) : SSPLK_None;
57 }
58
59 void StackProtector::adjustForColoring(const AllocaInst *From,
60 const AllocaInst *To) {
61 // When coloring replaces one alloca with another, transfer the SSPLayoutKind
62 // tag from the remapped to the target alloca. The remapped alloca should
63 // have a size smaller than or equal to the replacement alloca.
64 SSPLayoutMap::iterator I = Layout.find(From);
65 if (I != Layout.end()) {
66 SSPLayoutKind Kind = I->second;
67 Layout.erase(I);
68
69 // Transfer the tag, but make sure that SSPLK_AddrOf does not overwrite
70 // SSPLK_SmallArray or SSPLK_LargeArray, and make sure that
71 // SSPLK_SmallArray does not overwrite SSPLK_LargeArray.
72 I = Layout.find(To);
73 if (I == Layout.end())
74 Layout.insert(std::make_pair(To, Kind));
75 else if (I->second != SSPLK_LargeArray && Kind != SSPLK_AddrOf)
76 I->second = Kind;
77 }
5778 }
5879
5980 bool StackProtector::runOnFunction(Function &Fn) {