未验证 提交 a1475914 编写于 作者: G gouzil 提交者: GitHub

[IR Operation] Elden chapter 1.3 (#55657)

上级 c4204bbf
...@@ -94,7 +94,12 @@ void BindBlock(py::module *m) { ...@@ -94,7 +94,12 @@ void BindBlock(py::module *m) {
void BindOperation(py::module *m) { void BindOperation(py::module *m) {
py::class_<Operation> op(*m, "Operation"); py::class_<Operation> op(*m, "Operation");
op.def("name", &Operation::name) op.def("name", &Operation::name)
.def("get_parent", &Operation::GetParent, return_value_policy::reference) .def("get_parent",
py::overload_cast<>(&Operation::GetParent),
return_value_policy::reference)
.def("get_parent",
py::overload_cast<>(&Operation::GetParent, py::const_),
return_value_policy::reference)
.def("num_results", &Operation::num_results) .def("num_results", &Operation::num_results)
.def("result", &Operation::result) .def("result", &Operation::result)
.def("operands", .def("operands",
......
...@@ -210,7 +210,7 @@ Attribute Operation::attribute(const std::string &key) const { ...@@ -210,7 +210,7 @@ Attribute Operation::attribute(const std::string &key) const {
return attributes_.at(key); return attributes_.at(key);
} }
Region *Operation::GetParentRegion() const { Region *Operation::GetParentRegion() {
return parent_ ? parent_->GetParent() : nullptr; return parent_ ? parent_->GetParent() : nullptr;
} }
...@@ -218,8 +218,8 @@ Operation *Operation::GetParentOp() const { ...@@ -218,8 +218,8 @@ Operation *Operation::GetParentOp() const {
return parent_ ? parent_->GetParentOp() : nullptr; return parent_ ? parent_->GetParentOp() : nullptr;
} }
Program *Operation::GetParentProgram() { const Program *Operation::GetParentProgram() const {
Operation *op = this; Operation *op = const_cast<Operation *>(this);
while (Operation *parent_op = op->GetParentOp()) { while (Operation *parent_op = op->GetParentOp()) {
op = parent_op; op = parent_op;
} }
......
...@@ -109,13 +109,23 @@ class IR_API alignas(8) Operation final { ...@@ -109,13 +109,23 @@ class IR_API alignas(8) Operation final {
return info_.HasInterface<Interface>(); return info_.HasInterface<Interface>();
} }
Block *GetParent() const { return parent_; } const Block *GetParent() const { return parent_; }
Region *GetParentRegion() const; Block *GetParent() {
return const_cast<Block *>(
const_cast<const Operation *>(this)->GetParent());
}
Region *GetParentRegion();
Operation *GetParentOp() const; Operation *GetParentOp() const;
Program *GetParentProgram(); const Program *GetParentProgram() const;
Program *GetParentProgram() {
return const_cast<Program *>(
const_cast<const Operation *>(this)->GetParentProgram());
}
operator Block::iterator() { return position_; } operator Block::iterator() { return position_; }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册