未验证 提交 c595655b 编写于 作者: W winter-wang 提交者: GitHub

[IR] add positon member in block. (#54565)

上级 7d688871
......@@ -38,4 +38,10 @@ void Block::clear() {
ops_.pop_back();
}
}
void Block::SetParent(Region *parent, Region::iterator position) {
parent_ = parent;
position_ = position;
}
} // namespace ir
......@@ -17,8 +17,9 @@
#include <cstddef>
#include <list>
#include "paddle/ir/core/region.h"
namespace ir {
class Region;
class Operation;
class Block {
......@@ -47,16 +48,19 @@ class Block {
void push_front(Operation *op);
iterator insert(const_iterator iterator, Operation *op);
void clear();
operator Region::iterator() { return position_; }
private:
Block(Block &) = delete;
Block &operator=(const Block &) = delete;
// Allow access to 'SetParent'.
friend class Region;
void SetParent(Region *parent) { parent_ = parent; }
void SetParent(Region *parent, Region::iterator position);
private:
Region *parent_; // not owned
Region *parent_; // not owned
Region::iterator position_;
std::list<Operation *> ops_; // owned
};
} // namespace ir
......@@ -236,4 +236,9 @@ Region &Operation::GetRegion(unsigned index) {
return regions_[index];
}
void Operation::SetParent(Block *parent, const Block::iterator &position) {
parent_ = parent;
position_ = position;
}
} // namespace ir
......@@ -112,11 +112,9 @@ class alignas(8) Operation final {
}
};
// Allow access to 'SetParent'.
friend class Block;
void SetParent(Block *parent, const Block::iterator &position) {
parent_ = parent;
position_ = position;
}
void SetParent(Block *parent, const Block::iterator &position);
template <typename T>
struct CastUtil<
......
......@@ -18,27 +18,22 @@
namespace ir {
Region::~Region() { clear(); }
void Region::push_back(Block *block) {
block->SetParent(this);
blocks_.push_back(block);
}
void Region::push_back(Block *block) { insert(blocks_.end(), block); }
void Region::emplace_back() { push_back(new Block); }
void Region::push_front(Block *block) {
block->SetParent(this);
blocks_.push_front(block);
}
void Region::push_front(Block *block) { insert(blocks_.begin(), block); }
Region::iterator Region::insert(const_iterator position, Block *block) {
block->SetParent(this);
return blocks_.insert(position, block);
Region::iterator iter = blocks_.insert(position, block);
block->SetParent(this, iter);
return iter;
}
void Region::TakeBody(Region &&other) {
clear();
blocks_.swap(other.blocks_);
for (auto &block : blocks_) {
block->SetParent(this);
for (auto iter = blocks_.begin(); iter != blocks_.end(); ++iter) {
(*iter)->SetParent(this, iter);
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册