Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PIR]Move Operation::operand_index() into Operand::index() #59791

Merged
merged 4 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions paddle/fluid/pir/transforms/transform_general_functions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ std::vector<std::pair<Operation*, int32_t>> GetUseOpsForOutput(Operation* op,
auto result = op->result(index);
std::vector<std::pair<Operation*, int32_t>> use_ops;
for (auto it = result.use_begin(); it != result.use_end(); ++it) {
use_ops.push_back(
std::make_pair(it->owner(), it->owner()->operand_index(*it)));
use_ops.push_back(std::make_pair(it->owner(), it->index()));
}
return use_ops;
}
Expand Down
5 changes: 5 additions & 0 deletions paddle/pir/core/op_operand.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ Operation *OpOperand::owner() const {
return impl_->owner();
}

uint32_t OpOperand::index() const {
CHECK_OPOPEREND_NULL_IMPL(index);
return impl_->index();
}

void OpOperand::RemoveFromUdChain() {
CHECK_OPOPEREND_NULL_IMPL(RemoveFromUdChain);
return impl_->RemoveFromUdChain();
Expand Down
4 changes: 3 additions & 1 deletion paddle/pir/core/op_operand.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.

#pragma once

#include <cstdint>
#include "paddle/pir/core/dll_decl.h"

namespace pir {
Expand Down Expand Up @@ -57,6 +57,8 @@ class IR_API OpOperand {

Operation *owner() const;

uint32_t index() const;

void RemoveFromUdChain();

friend Operation;
Expand Down
8 changes: 8 additions & 0 deletions paddle/pir/core/op_operand_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "paddle/pir/core/op_operand_impl.h"
#include "paddle/pir/core/operation.h"
#include "paddle/pir/core/value_impl.h"

namespace pir {
Expand Down Expand Up @@ -40,6 +41,13 @@ OpOperandImpl::OpOperandImpl(pir::Value source, pir::Operation *owner)
InsertToUdChain();
}

uint32_t OpOperandImpl::index() const {
const char *start =
reinterpret_cast<const char *>(owner_) + sizeof(Operation);
const char *end = reinterpret_cast<const char *>(this);
return (end - start) / sizeof(OpOperandImpl);
}

void OpOperandImpl::InsertToUdChain() {
prev_use_addr_ = source_.impl()->first_use_addr();
next_use_ = source_.impl()->first_use();
Expand Down
3 changes: 3 additions & 0 deletions paddle/pir/core/op_operand_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

#pragma once
#include <cstdint>
#include "paddle/pir/core/value.h"

namespace pir {
Expand All @@ -33,6 +34,8 @@ class OpOperandImpl {

void set_source(Value value);

uint32_t index() const;

/// Remove this op_operand from the current use list.
void RemoveFromUdChain();

Expand Down
11 changes: 0 additions & 11 deletions paddle/pir/core/operation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -245,17 +245,6 @@ std::vector<Value> Operation::operands_source() const {
return res;
}

int32_t Operation::operand_index(const OpOperand &op_operand) const {
int32_t res = -1;
for (uint32_t i = 0; i < num_operands(); ++i) {
if (op_operand == operand(i)) {
res = i;
break;
}
}
return res;
}

///
/// \brief op successor related public interfaces
///
Expand Down
1 change: 0 additions & 1 deletion paddle/pir/core/operation.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ class IR_API alignas(8) Operation final
std::vector<OpOperand> operands();
Value operand_source(uint32_t index) const;
std::vector<Value> operands_source() const;
int32_t operand_index(const OpOperand &op_operand) const;

///
/// \brief op successor related public interfaces
Expand Down