-
Notifications
You must be signed in to change notification settings - Fork 260
Implement live variable analysis #213
Comments
We would like to implement such an analysis. Based on our insights into MLIR we propose the following high-level interface for this new analysis: namespace mlir {
class ValueSet;
class LivenessValueInfo {
public:
/// Returns all values that are live at this
/// point in time. Note that this refers to the
/// associated operation of the underlying value.
const ValueSet &live() const;
/// Returns the last operation the associated value
/// was seen as live.
Operation *endOfLife() const;
};
class LivenessBlockInfo {
public:
/// Returns all values that are live at the beginning
// of the block.
const ValueSet &in() const;
/// Returns all values that are live at the end
// of the block.
const ValueSet &out() const;
};
class Liveness {
public:
/// Creates a new Liveness analysis that computed liveness
/// information for all associated regions.
Liveness(Operation *op);
/// Resolves liveness info (if any) for the given value.
LivenessValueInfo *getLiveness(Value *value) const;
/// Resolves liveness info (if any) for the given block.
LivenessBlockInfo *getLiveness(Block *block) const;
};
} This interface should satisfy common use-cases like straight-forward register allocation. |
Looks good! For 'getLiveness(Value *value)', you could instead have a
to (1) avoid the situation where a Value isn't defined by an op (because it could also be a block argument) and (2) to allow computing this information at ops that have zero results. In addition, I think you need a 'const LivenessValueInfo/LivenessBlockInfo *' on getLiveness or a void getLiveness(Value *value, LivenessValueInfo &info). |
@bondhugula What benefit does computing on an Operation with zero results have? @dfki-mako Without looking at how you intend to implement it(and/or use it) I don't have too many comments at this point, but the main one is that I don't understand the There is some previous art of computing SSA liveness in LLVM: As well as an implementation in IREE(on MLIR): I have also written a full SSA liveness analysis for a custom LLVM backend, of which partially inspired the IREE implementation. I'm happy to review any PRs you have, or help in any way I can. |
IIUC, the getLiveness method is providing liveness info (live-in's and live-out's) at that program point -- as such, it makes sense for any operation (within the op regions that the Liveness instance was constructed on). ~ Uday |
Ohh sorry, I missed the comment. At least for register allocation, you want the ranges of the program that a value is live and don't necessarily work at a per-op level. |
@bondhugula, @River707 Thank you for your feedback on our first proposal. @bondhugula The return of a @River707 |
Thanks, everything you suggest sounds good to me. My comment on liveness at a point was due to the comment on your method LivenessValueInfo::live(). Clearly, live ranges are what you may first/usually need for buffer assignment, etc., and so you could just go with an interface for that. |
It would be great to have a shared implementation for live variable analysis in core that could be used by various resource allocation schemes in tensorflow and others.
The text was updated successfully, but these errors were encountered: