<commit_before>#include "opt/pipeline/pipeliner.h"

#include "design/design_tool.h"
#include "design/design_util.h"
#include "iroha/i_design.h"
#include "iroha/resource_class.h"
#include "opt/loop/loop_block.h"
#include "opt/optimizer_log.h"
#include "opt/pipeline/reg_info.h"
#include "opt/pipeline/shape.h"
#include "opt/pipeline/stage_scheduler.h"

namespace iroha {
namespace opt {
namespace pipeline {

Pipeliner::Pipeliner(ITable *tab, StageScheduler *ssch, RegInfo *reg_info)
    : tab_(tab),
      ssch_(ssch),
      reg_info_(reg_info),
      lb_(ssch->GetLoop()),
      interval_(ssch_->GetInterval()),
      opt_log_(nullptr),
      prologue_st_(nullptr) {
  opt_log_ = tab->GetModule()->GetDesign()->GetOptimizerLog();
}

Pipeliner::~Pipeliner() {}

bool Pipeliner::Pipeline() {
  lb_->Annotate(opt_log_);
  ostream &os = opt_log_->GetDumpStream();
  os << "Pipeliner " << ssch_->GetMacroStageCount() << " states, "
     << lb_->GetLoopCount() << " loop, interval=" << interval_ << " <br/>\n";
  // prepare states.
  prologue_st_ = new IState(tab_);
  tab_->states_.push_back(prologue_st_);
  int plen = ssch_->GetPipelineStageLength();
  for (int i = 0; i < plen; ++i) {
    IState *st = new IState(tab_);
    pipeline_stages_.push_back(st);
    tab_->states_.push_back(st);
  }
  PrepareRegPipeline();
  Shape shape(ssch_);
  vector<pair<int, int>> loc = shape.GetPipelineLocation();
  for (pair<int, int> &p : loc) {
    PlaceState(p.first, p.second);
  }
  UpdatePipelineRegWrite();
  SetupCounter();
  SetupCounterIncrement();
  UpdateCounterRead();
  ConnectPipelineState();
  SetupExit();
  ConnectPipeline();
  return true;
}

void Pipeliner::PlaceState(int pidx, int lidx) {
  MacroStage &ms = ssch_->GetMacroStage(lidx);
  for (int st = 0; st < ms.stages_.size(); ++st) {
    IState *pst = pipeline_stages_[pidx * interval_ + st];
    ostream &os = opt_log_->State(pst);
    os << "[" << lidx;
    if (ms.stages_.size() > 1) {
      os << ":" << st;
    }
    os << "]";
    StageInsns &si = ms.stages_[st];
    for (IInsn *insn : si.insns_) {
      IResource *res = insn->GetResource();
      if (resource::IsTransition(*(res->GetClass()))) {
        continue;
      }
      IInsn *new_insn = new IInsn(res);
      UpdateRegs(pst, lidx, false, insn->inputs_, &new_insn->inputs_);
      UpdateRegs(pst, lidx, true, insn->outputs_, &new_insn->outputs_);
      pst->insns_.push_back(new_insn);
      insn_to_stage_[new_insn] = lidx;
    }
  }<commit_msg>Copy operand to copied insns.<commit_after>#include "opt/pipeline/pipeliner.h"

#include "design/design_tool.h"
#include "design/design_util.h"
#include "iroha/i_design.h"
#include "iroha/resource_class.h"
#include "opt/loop/loop_block.h"
#include "opt/optimizer_log.h"
#include "opt/pipeline/reg_info.h"
#include "opt/pipeline/shape.h"
#include "opt/pipeline/stage_scheduler.h"

namespace iroha {
namespace opt {
namespace pipeline {

Pipeliner::Pipeliner(ITable *tab, StageScheduler *ssch, RegInfo *reg_info)
    : tab_(tab),
      ssch_(ssch),
      reg_info_(reg_info),
      lb_(ssch->GetLoop()),
      interval_(ssch_->GetInterval()),
      opt_log_(nullptr),
      prologue_st_(nullptr) {
  opt_log_ = tab->GetModule()->GetDesign()->GetOptimizerLog();
}

Pipeliner::~Pipeliner() {}

bool Pipeliner::Pipeline() {
  lb_->Annotate(opt_log_);
  ostream &os = opt_log_->GetDumpStream();
  os << "Pipeliner " << ssch_->GetMacroStageCount() << " states, "
     << lb_->GetLoopCount() << " loop, interval=" << interval_ << " <br/>\n";
  // prepare states.
  prologue_st_ = new IState(tab_);
  tab_->states_.push_back(prologue_st_);
  int plen = ssch_->GetPipelineStageLength();
  for (int i = 0; i < plen; ++i) {
    IState *st = new IState(tab_);
    pipeline_stages_.push_back(st);
    tab_->states_.push_back(st);
  }
  PrepareRegPipeline();
  Shape shape(ssch_);
  vector<pair<int, int>> loc = shape.GetPipelineLocation();
  for (pair<int, int> &p : loc) {
    PlaceState(p.first, p.second);
  }
  UpdatePipelineRegWrite();
  SetupCounter();
  SetupCounterIncrement();
  UpdateCounterRead();
  ConnectPipelineState();
  SetupExit();
  ConnectPipeline();
  return true;
}

void Pipeliner::PlaceState(int pidx, int lidx) {
  MacroStage &ms = ssch_->GetMacroStage(lidx);
  for (int st = 0; st < ms.stages_.size(); ++st) {
    IState *pst = pipeline_stages_[pidx * interval_ + st];
    ostream &os = opt_log_->State(pst);
    os << "[" << lidx;
    if (ms.stages_.size() > 1) {
      os << ":" << st;
    }
    os << "]";
    StageInsns &si = ms.stages_[st];
    for (IInsn *insn : si.insns_) {
      IResource *res = insn->GetResource();
      if (resource::IsTransition(*(res->GetClass()))) {
        continue;
      }
      IInsn *new_insn = new IInsn(res);
      UpdateRegs(pst, lidx, false, insn->inputs_, &new_insn->inputs_);
      UpdateRegs(pst, lidx, true, insn->outputs_, &new_insn->outputs_);
      new_insn->SetOperand(insn->GetOperand());
      pst->insns_.push_back(new_insn);
      insn_to_stage_[new_insn] = lidx;
    }
  }
{'fraction_non_alphanumeric': 0.17039106145251395, 'fraction_numerical': 0.0011971268954509178, 'mean_word_length': 3.8622696411251214, 'pattern_counts': {'":': 2, '<': 63, '<?xml version=': 0, '>': 57, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '338460', 'n_tokens_mistral': 1864, 'n_tokens_neox': 1867, 'n_words': 331}