My Project
Liveness.h
Go to the documentation of this file.
1 //===- Liveness.h - Liveness analysis for MLIR ------------------*- C++ -*-===//
2 //
3 // Part of the MLIR 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 // This file contains an analysis for computing liveness information from a
10 // given top-level operation. The current version of the analysis uses a
11 // traditional algorithm to resolve detailed live-range information about all
12 // values within the specified regions. It is also possible to query liveness
13 // information on block level.
14 //
15 //===----------------------------------------------------------------------===//
16 
17 #ifndef MLIR_ANALYSIS_LIVENESS_H
18 #define MLIR_ANALYSIS_LIVENESS_H
19 
20 #include <vector>
21 
22 #include "mlir/Support/LLVM.h"
23 #include "llvm/ADT/ArrayRef.h"
24 #include "llvm/ADT/DenseMap.h"
25 #include "llvm/ADT/SmallPtrSet.h"
26 
27 namespace mlir {
28 
29 class Block;
30 class LivenessBlockInfo;
31 class Operation;
32 class Region;
33 class Value;
34 
47 class Liveness {
48 public:
49  using OperationListT = std::vector<Operation *>;
52 
53 public:
56  Liveness(Operation *op);
57 
59  Operation *getOperation() const { return operation; }
60 
67 
69  const LivenessBlockInfo *getLiveness(Block *block) const;
70 
72  const ValueSetT &getLiveIn(Block *block) const;
73 
75  const ValueSetT &getLiveOut(Block *block) const;
76 
79  bool isLastUse(Value value, Operation *operation) const;
80 
82  void dump() const;
83 
85  void print(raw_ostream &os) const;
86 
87 private:
89  void build(MutableArrayRef<Region> regions);
90 
91 private:
93  Operation *operation;
94 
96  BlockMapT blockMapping;
97 };
98 
101 public:
104 
105 public:
107  Block *getBlock() const { return block; }
108 
111  const ValueSetT &in() const { return inValues; }
112 
115  const ValueSetT &out() const { return outValues; }
116 
118  bool isLiveIn(Value value) const;
119 
121  bool isLiveOut(Value value) const;
122 
127  Operation *getStartOperation(Value value) const;
128 
131  Operation *getEndOperation(Value value, Operation *startOperation) const;
132 
133 private:
135  Block *block;
136 
138  ValueSetT inValues;
139 
141  ValueSetT outValues;
142 
143  friend class Liveness;
144 };
145 
146 } // end namespace mlir
147 
148 #endif // MLIR_ANALYSIS_LIVENESS_H
Definition: InferTypeOpInterface.cpp:20
Block * getBlock() const
Returns the underlying block.
Definition: Liveness.h:107
Definition: Operation.h:27
Block represents an ordered list of Operations.
Definition: Block.h:21
Definition: LLVM.h:48
This class represents liveness information on block level.
Definition: Liveness.h:100
void print(raw_ostream &os) const
Dumps the liveness information to the given stream.
Definition: Liveness.cpp:251
const ValueSetT & out() const
Definition: Liveness.h:115
Definition: LLVM.h:38
const ValueSetT & getLiveOut(Block *block) const
Returns a reference to a set containing live-out values (unordered).
Definition: Liveness.cpp:226
Definition: Liveness.h:47
Operation * getOperation() const
Returns the operation this analysis was constructed from.
Definition: Liveness.h:59
const LivenessBlockInfo * getLiveness(Block *block) const
Gets liveness info (if any) for the block.
Definition: Liveness.cpp:215
Definition: Value.h:38
Definition: LLVM.h:33
void dump() const
Dumps the liveness information in a human readable format.
Definition: Liveness.cpp:248
std::vector< Operation * > OperationListT
Definition: Liveness.h:49
bool isLastUse(Value value, Operation *operation) const
Definition: Liveness.cpp:232
OperationListT resolveLiveness(Value value) const
Gets liveness info (if any) for the given value.
Definition: Liveness.cpp:167
const ValueSetT & in() const
Definition: Liveness.h:111
Liveness(Operation *op)
Definition: Liveness.cpp:146
const ValueSetT & getLiveIn(Block *block) const
Returns a reference to a set containing live-in values (unordered).
Definition: Liveness.cpp:221
SmallPtrSet< Value, 16 > ValueSetT
Definition: Liveness.h:51