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

[onert] Introduce replacing an input #13840

Closed
Closed
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
1 change: 1 addition & 0 deletions runtime/onert/core/include/ir/IOperation.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ struct IOperation
virtual std::string name() const { return std::string{toString(opcode())}; }
virtual OpCode opcode() const = 0;

virtual void replaceInput(size_t pos, const OperandIndex &index) = 0;
virtual void replaceInputs(const OperandIndex &from, const OperandIndex &to) = 0;
virtual void replaceOutputs(const OperandIndex &from, const OperandIndex &to) = 0;
virtual const OperandIndexSequence &getInputs() const = 0;
Expand Down
1 change: 1 addition & 0 deletions runtime/onert/core/include/ir/OperandIndexSequence.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class OperandIndexSequence
const OperandIndex &at(IOIndex set_index) const { return _vec.at(set_index.value()); }
const OperandIndex &at(uint32_t index) const { return _vec.at(index); }
bool contains(const OperandIndex &index) const;
void replace(size_t pos, const OperandIndex &index);
void replace(const OperandIndex &from, const OperandIndex &to);
OperandIndexSequence operator|(ir::Remove filter) const
{
Expand Down
1 change: 1 addition & 0 deletions runtime/onert/core/include/ir/Operation.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class Operation : virtual public IOperation
virtual ~Operation();

public:
void replaceInput(size_t pos, const OperandIndex &index) override;
void replaceInputs(const OperandIndex &from, const OperandIndex &to) override;
void replaceOutputs(const OperandIndex &from, const OperandIndex &to) override;
OperandIndexSequence &getInputs() { return _inputs; }
Expand Down
7 changes: 7 additions & 0 deletions runtime/onert/core/src/ir/OperandIndexSequence.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "ir/OperandIndexSequence.h"

#include <algorithm>
#include <cassert>
#include <sstream>

namespace onert
Expand Down Expand Up @@ -50,6 +51,12 @@ bool OperandIndexSequence::contains(const OperandIndex &index) const
return std::find(_vec.begin(), _vec.end(), index) != _vec.end();
}

void OperandIndexSequence::replace(size_t pos, const OperandIndex &index)
{
assert(pos < _vec.size() && "OperandIndexSequence: Out of range");
_vec.at(pos) = index;
}

void OperandIndexSequence::replace(const OperandIndex &from, const OperandIndex &to)
{
std::replace(_vec.begin(), _vec.end(), from, to);
Expand Down
2 changes: 2 additions & 0 deletions runtime/onert/core/src/ir/Operation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ void Operation::setOutputs(const OperandIndexSequence &indexes)
_outputs = indexes;
}

void Operation::replaceInput(size_t pos, const OperandIndex &index) { _inputs.replace(pos, index); }

void Operation::replaceInputs(const OperandIndex &from, const OperandIndex &to)
{
_inputs.replace(from, to);
Expand Down