1 //===- bolt/Passes/StackAllocationAnalysis.h --------------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef BOLT_PASSES_STACKALLOCATIONANALYSIS_H 10 #define BOLT_PASSES_STACKALLOCATIONANALYSIS_H 11 12 #include "bolt/Passes/DataflowAnalysis.h" 13 #include "llvm/Support/CommandLine.h" 14 15 namespace opts { 16 extern llvm::cl::opt<bool> TimeOpts; 17 } 18 19 namespace llvm { 20 namespace bolt { 21 class StackPointerTracking; 22 23 /// Perform a dataflow analysis to track the value of SP as an offset relative 24 /// to the CFA. 25 class StackAllocationAnalysis 26 : public InstrsDataflowAnalysis<StackAllocationAnalysis, 27 /*Backward=*/false> { 28 friend class DataflowAnalysis<StackAllocationAnalysis, BitVector>; 29 30 StackPointerTracking &SPT; 31 32 public: StackAllocationAnalysis(BinaryFunction & BF,StackPointerTracking & SPT,MCPlusBuilder::AllocatorIdTy AllocId)33 StackAllocationAnalysis(BinaryFunction &BF, StackPointerTracking &SPT, 34 MCPlusBuilder::AllocatorIdTy AllocId) 35 : InstrsDataflowAnalysis<StackAllocationAnalysis, false>(BF, AllocId), 36 SPT(SPT) {} ~StackAllocationAnalysis()37 virtual ~StackAllocationAnalysis() {} 38 run()39 void run() { InstrsDataflowAnalysis<StackAllocationAnalysis, false>::run(); } 40 41 protected: 42 void preflight(); 43 44 BitVector getStartingStateAtBB(const BinaryBasicBlock &BB); 45 46 BitVector getStartingStateAtPoint(const MCInst &Point); 47 48 void doConfluence(BitVector &StateOut, const BitVector &StateIn); 49 50 BitVector doKill(const MCInst &Point, const BitVector &StateIn, 51 int DeallocSize); 52 53 void doConfluenceWithLP(BitVector &StateOut, const BitVector &StateIn, 54 const MCInst &Invoke); 55 56 BitVector computeNext(const MCInst &Point, const BitVector &Cur); 57 getAnnotationName()58 StringRef getAnnotationName() const { 59 return StringRef("StackAllocationAnalysis"); 60 } 61 }; 62 63 } // end namespace bolt 64 } // end namespace llvm 65 66 #endif 67