Liveness Analysis Pass
[oota-llvm.git] / include / llvm / CodeGen / StackMapLivenessAnalysis.h
1 //===--- StackMapLivenessAnalysis - StackMap Liveness Analysis --*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This pass calculates the liveness for each basic block in a function and
11 // attaches the register live-out information to a stackmap or patchpoint
12 // intrinsic if present.
13 //
14 //===----------------------------------------------------------------------===//
15
16 #ifndef LLVM_CODEGEN_STACKMAP_LIVENESS_ANALYSIS_H
17 #define LLVM_CODEGEN_STACKMAP_LIVENESS_ANALYSIS_H
18
19 #include "llvm/CodeGen/LivePhysRegs.h"
20 #include "llvm/CodeGen/MachineFunctionPass.h"
21
22
23 namespace llvm {
24
25 /// \brief This pass calculates the liveness information for each basic block in
26 /// a function and attaches the register live-out information to a stackmap or
27 /// patchpoint intrinsic if present.
28 ///
29 /// This is an optional pass that has to be explicitely enabled via the
30 /// -enable-stackmap-liveness flag. The pass skips functions that don't have any
31 /// stackmap or patchpoint intrinsics. The information provided by this pass is
32 /// optional and not required by the aformentioned intrinsics to function.
33 class StackMapLiveness : public MachineFunctionPass {
34   MachineFunction *MF;
35   const TargetRegisterInfo *TRI;
36   LivePhysRegs LiveRegs;
37 public:
38   static char ID;
39
40   /// \brief Default construct and initialize the pass.
41   StackMapLiveness();
42
43   /// \brief Tell the pass manager which passes we depend on and what
44   /// information we preserve.
45   virtual void getAnalysisUsage(AnalysisUsage &AU) const;
46
47   /// \brief Calculate the liveness information for the given machine function.
48   virtual bool runOnMachineFunction(MachineFunction &MF);
49
50 private:
51   /// \brief Performs the actual liveness calculation for the function.
52   bool calculateLiveness();
53
54   /// \brief Add the current register live set to the instruction.
55   void addLiveOutSetToMI(MachineInstr &MI);
56
57   /// \brief Create a register mask and initialize it with the registers from
58   /// the register live set.
59   uint32_t *createRegisterMask() const;
60
61   /// \brief Print the current register live set for debugging.
62   void printLiveOutSet(raw_ostream &OS) const;
63 };
64
65 } // end llvm namespace
66
67 #endif // end LLVM_CODEGEN_STACKMAP_LIVENESS_ANALYSIS_H