|
|
|
@ -461,11 +461,21 @@ void ControlFlowGraph::LiveVariableAnalysis() {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (auto* op : ops_) {
|
|
|
|
|
unlived_vars_[op] = std::set<std::string>();
|
|
|
|
|
for (auto& var : this->LiveIn(op)) {
|
|
|
|
|
if (!this->LiveOut(op).count(var)) {
|
|
|
|
|
unlived_vars_[op].insert(var);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ControlFlowGraph::RenameVarInCFGGraph(const std::string& old_node,
|
|
|
|
|
const std::string& new_node,
|
|
|
|
|
int begin_idx) {
|
|
|
|
|
std::vector<bool> need_update(ops_.size(), false);
|
|
|
|
|
// update graph from begin idx to the end
|
|
|
|
|
for (size_t i = begin_idx; i != ops_.size(); ++i) {
|
|
|
|
|
auto* op = ops_[i];
|
|
|
|
@ -480,15 +490,27 @@ void ControlFlowGraph::RenameVarInCFGGraph(const std::string& old_node,
|
|
|
|
|
if (live_in_[op].find(old_node) != live_in_[op].end()) {
|
|
|
|
|
live_in_[op].erase(old_node);
|
|
|
|
|
live_in_[op].insert(new_node);
|
|
|
|
|
need_update[i] = true;
|
|
|
|
|
}
|
|
|
|
|
if (live_out_[op].find(old_node) != live_out_[op].end()) {
|
|
|
|
|
live_out_[op].erase(old_node);
|
|
|
|
|
live_out_[op].insert(new_node);
|
|
|
|
|
need_update[i] = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (size_t i = begin_idx; i < ops_.size(); ++i) {
|
|
|
|
|
if (!need_update[i]) continue;
|
|
|
|
|
auto* op = ops_[i];
|
|
|
|
|
for (auto& var : this->LiveIn(op)) {
|
|
|
|
|
if (!this->LiveOut(op).count(var)) {
|
|
|
|
|
unlived_vars_[op].insert(var);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const std::set<std::string> ControlFlowGraph::LiveIn(ir::Node* op) const {
|
|
|
|
|
const std::set<std::string>& ControlFlowGraph::LiveIn(ir::Node* op) const {
|
|
|
|
|
auto it = live_in_.find(op);
|
|
|
|
|
PADDLE_ENFORCE(
|
|
|
|
|
it != live_in_.end(),
|
|
|
|
@ -496,7 +518,7 @@ const std::set<std::string> ControlFlowGraph::LiveIn(ir::Node* op) const {
|
|
|
|
|
return it->second;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const std::set<std::string> ControlFlowGraph::LiveOut(ir::Node* op) const {
|
|
|
|
|
const std::set<std::string>& ControlFlowGraph::LiveOut(ir::Node* op) const {
|
|
|
|
|
auto it = live_out_.find(op);
|
|
|
|
|
PADDLE_ENFORCE(
|
|
|
|
|
it != live_out_.end(),
|
|
|
|
@ -504,15 +526,24 @@ const std::set<std::string> ControlFlowGraph::LiveOut(ir::Node* op) const {
|
|
|
|
|
return it->second;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const std::set<std::string> ControlFlowGraph::Use(ir::Node* op) const {
|
|
|
|
|
const std::set<std::string>& ControlFlowGraph::Use(ir::Node* op) const {
|
|
|
|
|
auto it = uses_.find(op);
|
|
|
|
|
PADDLE_ENFORCE(
|
|
|
|
|
it != uses_.end(),
|
|
|
|
|
string::Sprintf("Expect %s in live_out, but Not Found.", op->Name()));
|
|
|
|
|
string::Sprintf("Expect %s in use, but Not Found.", op->Name()));
|
|
|
|
|
return it->second;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const std::set<std::string>& ControlFlowGraph::Unlived(ir::Node* op) const {
|
|
|
|
|
auto it = unlived_vars_.find(op);
|
|
|
|
|
PADDLE_ENFORCE(
|
|
|
|
|
it != unlived_vars_.end(),
|
|
|
|
|
string::Sprintf("Expect %s in unlived_set, but Not Found.", op->Name()));
|
|
|
|
|
return it->second;
|
|
|
|
|
return it->second;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const std::vector<ir::Node*> ControlFlowGraph::Ops() const { return ops_; }
|
|
|
|
|
const std::vector<ir::Node*>& ControlFlowGraph::Ops() const { return ops_; }
|
|
|
|
|
|
|
|
|
|
std::vector<ir::Node*>& ControlFlowGraph::Ops() { return ops_; }
|
|
|
|
|
|
|
|
|
|