Skip to content

Commit

Permalink
[onert] Introduce replacing an input
Browse files Browse the repository at this point in the history
This commit introduces a function that replaces an input by position of input index sequence.

ONE-DCO-1.0-Signed-off-by: ragmani <[email protected]>
  • Loading branch information
ragmani committed Aug 29, 2024
1 parent f963350 commit 4ad8d73
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 0 deletions.
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

0 comments on commit 4ad8d73

Please sign in to comment.