xref: /llvm-project/bolt/include/bolt/Passes/StackAvailableExpressions.h (revision 4c106cfdf7cf7eec861ad3983a3dd9a9e8f3a8ae)
1 //===- bolt/Passes/StackAvailableExpressions.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_STACKAVAILABLEEXPRESSIONS_H
10 #define BOLT_PASSES_STACKAVAILABLEEXPRESSIONS_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 
22 class FrameAnalysis;
23 class RegAnalysis;
24 
25 class StackAvailableExpressions
26     : public InstrsDataflowAnalysis<StackAvailableExpressions> {
27   friend class DataflowAnalysis<StackAvailableExpressions, BitVector>;
28 
29 public:
30   StackAvailableExpressions(const RegAnalysis &RA, const FrameAnalysis &FA,
31                             BinaryFunction &BF);
~StackAvailableExpressions()32   virtual ~StackAvailableExpressions() {}
33 
run()34   void run() { InstrsDataflowAnalysis<StackAvailableExpressions>::run(); }
35 
36 protected:
37   const RegAnalysis &RA;
38   const FrameAnalysis &FA;
39 
40   void preflight();
41   BitVector getStartingStateAtBB(const BinaryBasicBlock &BB);
42   BitVector getStartingStateAtPoint(const MCInst &Point);
43   void doConfluence(BitVector &StateOut, const BitVector &StateIn);
44   /// Define the function computing the kill set -- whether expression Y, a
45   /// tracked expression, will be considered to be dead after executing X.
46   bool doesXKillsY(const MCInst *X, const MCInst *Y);
47   BitVector computeNext(const MCInst &Point, const BitVector &Cur);
48 
getAnnotationName()49   StringRef getAnnotationName() const {
50     return StringRef("StackAvailableExpressions");
51   }
52 };
53 
54 } // namespace bolt
55 } // namespace llvm
56 
57 #endif
58