summaryrefslogtreecommitdiffstats
path: root/include/llvm/Analysis/LiveValues.h
blob: b92cb7833a7e92a37004aa80191715e78fec5f4f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
//===- LiveValues.h - Liveness information for LLVM IR Values. ------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file defines the interface for the LLVM IR Value liveness
// analysis pass.
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_ANALYSIS_LIVEVALUES_H
#define LLVM_ANALYSIS_LIVEVALUES_H

#include "llvm/Pass.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/SmallPtrSet.h"

namespace llvm {

class DominatorTree;
class LoopInfo;
class Value;

/// LiveValues - Analysis that provides liveness information for
/// LLVM IR Values.
///
class LiveValues : public FunctionPass {
  DominatorTree *DT;
  LoopInfo *LI;

  /// Memo - A bunch of state to be associated with a value.
  ///
  struct Memo {
    /// Used - The set of blocks which contain a use of the value.
    ///
    SmallPtrSet<const BasicBlock *, 4> Used;

    /// LiveThrough - A conservative approximation of the set of blocks in
    /// which the value is live-through, meaning blocks properly dominated
    /// by the definition, and from which blocks containing uses of the
    /// value are reachable.
    ///
    SmallPtrSet<const BasicBlock *, 4> LiveThrough;

    /// Killed - A conservative approximation of the set of blocks in which
    /// the value is used and not live-out.
    ///
    SmallPtrSet<const BasicBlock *, 4> Killed;
  };

  /// Memos - Remembers the Memo for each Value. This is populated on
  /// demand.
  ///
  DenseMap<const Value *, Memo> Memos;

  /// getMemo - Retrieve an existing Memo for the given value if one
  /// is available, otherwise compute a new one.
  ///
  Memo &getMemo(const Value *V);

  /// compute - Compute a new Memo for the given value.
  ///
  Memo &compute(const Value *V);

public:
  static char ID;
  LiveValues();

  virtual void getAnalysisUsage(AnalysisUsage &AU) const;
  virtual bool runOnFunction(Function &F);
  virtual void releaseMemory();

  /// isUsedInBlock - Test if the given value is used in the given block.
  ///
  bool isUsedInBlock(const Value *V, const BasicBlock *BB);

  /// isLiveThroughBlock - Test if the given value is known to be
  /// live-through the given block, meaning that the block is properly
  /// dominated by the value's definition, and there exists a block
  /// reachable from it that contains a use. This uses a conservative
  /// approximation that errs on the side of returning false.
  ///
  bool isLiveThroughBlock(const Value *V, const BasicBlock *BB);

  /// isKilledInBlock - Test if the given value is known to be killed in
  /// the given block, meaning that the block contains a use of the value,
  /// and no blocks reachable from the block contain a use. This uses a
  /// conservative approximation that errs on the side of returning false.
  ///
  bool isKilledInBlock(const Value *V, const BasicBlock *BB);
};

}  // end namespace llvm

#endif
OpenPOWER on IntegriCloud