CtrlBlock.scala 17.8 KB
Newer Older
L
Lemover 已提交
1 2
/***************************************************************************************
* Copyright (c) 2020-2021 Institute of Computing Technology, Chinese Academy of Sciences
Y
Yinan Xu 已提交
3
* Copyright (c) 2020-2021 Peng Cheng Laboratory
L
Lemover 已提交
4 5 6 7 8 9 10 11 12 13 14 15 16
*
* XiangShan is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
*          http://license.coscl.org.cn/MulanPSL2
*
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
*
* See the Mulan PSL v2 for more details.
***************************************************************************************/

17 18
package xiangshan.backend

19
import chipsalliance.rocketchip.config.Parameters
20 21
import chisel3._
import chisel3.util._
22 23
import difftest._
import freechips.rocketchip.diplomacy.{LazyModule, LazyModuleImp}
Y
Yinan Xu 已提交
24
import utils._
25
import xiangshan._
26
import xiangshan.backend.decode.{DecodeStage, ImmUnion}
27
import xiangshan.backend.dispatch.{Dispatch, DispatchQueue}
28
import xiangshan.backend.fu.PFEvent
29
import xiangshan.backend.rename.{Rename, RenameTableWrapper}
30
import xiangshan.backend.rob.{Rob, RobCSRIO, RobLsqIO}
31 32
import xiangshan.frontend.FtqRead
import xiangshan.mem.mdp.{LFST, SSIT, WaitTable}
33

34
class CtrlToFtqIO(implicit p: Parameters) extends XSBundle {
Y
Yinan Xu 已提交
35
  val rob_commits = Vec(CommitWidth, Valid(new RobCommitInfo))
36 37 38
  val stage2Redirect = Valid(new Redirect)
}

39
class RedirectGenerator(implicit p: Parameters) extends XSModule
40
  with HasCircularQueuePtrHelper {
L
ljw 已提交
41
  val numRedirect = exuParameters.JmpCnt + exuParameters.AluCnt
L
LinJiawei 已提交
42
  val io = IO(new Bundle() {
J
Jiawei Lin 已提交
43
    val hartId = Input(UInt(8.W))
L
ljw 已提交
44
    val exuMispredict = Vec(numRedirect, Flipped(ValidIO(new ExuOutput)))
L
ljw 已提交
45
    val loadReplay = Flipped(ValidIO(new Redirect))
46
    val flush = Input(Bool())
Z
zoujr 已提交
47
    val stage1PcRead = Vec(numRedirect+1, new FtqRead(UInt(VAddrBits.W)))
L
LinJiawei 已提交
48
    val stage2Redirect = ValidIO(new Redirect)
L
LinJiawei 已提交
49
    val stage3Redirect = ValidIO(new Redirect)
50
    val memPredUpdate = Output(new MemPredUpdateReq)
Z
zoujr 已提交
51
    val memPredPcRead = new FtqRead(UInt(VAddrBits.W)) // read req send form stage 2
L
LinJiawei 已提交
52 53 54 55
  })
  /*
        LoadQueue  Jump  ALU0  ALU1  ALU2  ALU3   exception    Stage1
          |         |      |    |     |     |         |
L
LinJiawei 已提交
56
          |============= reg & compare =====|         |       ========
L
LinJiawei 已提交
57 58 59 60
                            |                         |
                            |                         |
                            |                         |        Stage2
                            |                         |
L
LinJiawei 已提交
61 62 63 64 65 66 67 68
                    redirect (flush backend)          |
                    |                                 |
               === reg ===                            |       ========
                    |                                 |
                    |----- mux (exception first) -----|        Stage3
                            |
                redirect (send to frontend)
   */
L
ljw 已提交
69 70 71 72
  private class Wrapper(val n: Int) extends Bundle {
    val redirect = new Redirect
    val valid = Bool()
    val idx = UInt(log2Up(n).W)
73
  }
74
  def selectOldestRedirect(xs: Seq[Valid[Redirect]]): Vec[Bool] = {
Y
Yinan Xu 已提交
75
    val compareVec = (0 until xs.length).map(i => (0 until i).map(j => isAfter(xs(j).bits.robIdx, xs(i).bits.robIdx)))
76 77 78 79 80 81
    val resultOnehot = VecInit((0 until xs.length).map(i => Cat((0 until xs.length).map(j =>
      (if (j < i) !xs(j).valid || compareVec(i)(j)
      else if (j == i) xs(i).valid
      else !xs(j).valid || !compareVec(j)(i))
    )).andR))
    resultOnehot
L
LinJiawei 已提交
82 83
  }

84
  val redirects = io.exuMispredict.map(_.bits.redirect) :+ io.loadReplay.bits
Y
Yinan Xu 已提交
85 86
  val stage1FtqReadPcs =
    (io.stage1PcRead zip redirects).map{ case (r, redirect) =>
87 88
      r(redirect.ftqIdx, redirect.ftqOffset)
    }
L
ljw 已提交
89 90

  def getRedirect(exuOut: Valid[ExuOutput]): ValidIO[Redirect] = {
L
LinJiawei 已提交
91
    val redirect = Wire(Valid(new Redirect))
L
ljw 已提交
92 93
    redirect.valid := exuOut.valid && exuOut.bits.redirect.cfiUpdate.isMisPred
    redirect.bits := exuOut.bits.redirect
L
LinJiawei 已提交
94
    redirect
L
ljw 已提交
95
  }
L
LinJiawei 已提交
96

L
ljw 已提交
97
  val jumpOut = io.exuMispredict.head
98 99
  val allRedirect = VecInit(io.exuMispredict.map(x => getRedirect(x)) :+ io.loadReplay)
  val oldestOneHot = selectOldestRedirect(allRedirect)
100
  val needFlushVec = VecInit(allRedirect.map(_.bits.robIdx.needFlush(io.stage2Redirect) || io.flush))
101
  val oldestValid = VecInit(oldestOneHot.zip(needFlushVec).map{ case (v, f) => v && !f }).asUInt.orR
102
  val oldestExuOutput = Mux1H(io.exuMispredict.indices.map(oldestOneHot), io.exuMispredict)
103
  val oldestRedirect = Mux1H(oldestOneHot, allRedirect)
104

L
LinJiawei 已提交
105
  val s1_jumpTarget = RegEnable(jumpOut.bits.redirect.cfiUpdate.target, jumpOut.valid)
106 107 108 109 110
  val s1_imm12_reg = RegNext(oldestExuOutput.bits.uop.ctrl.imm(11, 0))
  val s1_pd = RegNext(oldestExuOutput.bits.uop.cf.pd)
  val s1_redirect_bits_reg = RegNext(oldestRedirect.bits)
  val s1_redirect_valid_reg = RegNext(oldestValid)
  val s1_redirect_onehot = RegNext(oldestOneHot)
L
LinJiawei 已提交
111 112

  // stage1 -> stage2
113
  io.stage2Redirect.valid := s1_redirect_valid_reg && !io.flush
L
LinJiawei 已提交
114 115
  io.stage2Redirect.bits := s1_redirect_bits_reg

116 117
  val s1_isReplay = s1_redirect_onehot.last
  val s1_isJump = s1_redirect_onehot.head
118
  val real_pc = Mux1H(s1_redirect_onehot, stage1FtqReadPcs)
L
ljw 已提交
119 120
  val brTarget = real_pc + SignExt(ImmUnion.B.toImm32(s1_imm12_reg), XLEN)
  val snpc = real_pc + Mux(s1_pd.isRVC, 2.U, 4.U)
121
  val target = Mux(s1_isReplay,
122
    real_pc, // replay from itself
L
ljw 已提交
123 124
    Mux(s1_redirect_bits_reg.cfiUpdate.taken,
      Mux(s1_isJump, s1_jumpTarget, brTarget),
L
LinJiawei 已提交
125
      snpc
L
LinJiawei 已提交
126 127
    )
  )
128

129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
  val stage2CfiUpdate = io.stage2Redirect.bits.cfiUpdate
  stage2CfiUpdate.pc := real_pc
  stage2CfiUpdate.pd := s1_pd
  stage2CfiUpdate.predTaken := s1_redirect_bits_reg.cfiUpdate.predTaken
  stage2CfiUpdate.target := target
  stage2CfiUpdate.taken := s1_redirect_bits_reg.cfiUpdate.taken
  stage2CfiUpdate.isMisPred := s1_redirect_bits_reg.cfiUpdate.isMisPred

  val s2_target = RegEnable(target, enable = s1_redirect_valid_reg)
  val s2_pc = RegEnable(real_pc, enable = s1_redirect_valid_reg)
  val s2_redirect_bits_reg = RegEnable(s1_redirect_bits_reg, enable = s1_redirect_valid_reg)
  val s2_redirect_valid_reg = RegNext(s1_redirect_valid_reg && !io.flush, init = false.B)

  io.stage3Redirect.valid := s2_redirect_valid_reg
  io.stage3Redirect.bits := s2_redirect_bits_reg

145 146 147
  // get pc from ftq
  // valid only if redirect is caused by load violation
  // store_pc is used to update store set
148
  val store_pc = io.memPredPcRead(s1_redirect_bits_reg.stFtqIdx, s1_redirect_bits_reg.stFtqOffset)
149 150 151 152 153 154 155 156 157 158

  // update load violation predictor if load violation redirect triggered
  io.memPredUpdate.valid := RegNext(s1_isReplay && s1_redirect_valid_reg, init = false.B)
  // update wait table
  io.memPredUpdate.waddr := RegNext(XORFold(real_pc(VAddrBits-1, 1), MemPredPCWidth))
  io.memPredUpdate.wdata := true.B
  // update store set
  io.memPredUpdate.ldpc := RegNext(XORFold(real_pc(VAddrBits-1, 1), MemPredPCWidth))
  // store pc is ready 1 cycle after s1_isReplay is judged
  io.memPredUpdate.stpc := XORFold(store_pc(VAddrBits-1, 1), MemPredPCWidth)
159

W
William Wang 已提交
160 161 162 163
  // recover runahead checkpoint if redirect
  if (!env.FPGAPlatform) {
    val runahead_redirect = Module(new DifftestRunaheadRedirectEvent)
    runahead_redirect.io.clock := clock
J
Jiawei Lin 已提交
164
    runahead_redirect.io.coreid := io.hartId
W
William Wang 已提交
165 166 167 168 169
    runahead_redirect.io.valid := io.stage3Redirect.valid
    runahead_redirect.io.pc :=  s2_pc // for debug only
    runahead_redirect.io.target_pc := s2_target // for debug only
    runahead_redirect.io.checkpoint_id := io.stage3Redirect.bits.debug_runahead_checkpoint_id // make sure it is right
  }
L
LinJiawei 已提交
170 171
}

172 173
class CtrlBlock(implicit p: Parameters) extends LazyModule
  with HasWritebackSink with HasWritebackSource {
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
  val rob = LazyModule(new Rob)

  override def addWritebackSink(source: Seq[HasWritebackSource], index: Option[Seq[Int]]): HasWritebackSink = {
    rob.addWritebackSink(Seq(this), Some(Seq(writebackSinks.length)))
    super.addWritebackSink(source, index)
  }

  lazy val module = new CtrlBlockImp(this)

  override lazy val writebackSourceParams: Seq[WritebackSourceParams] = {
    writebackSinksParams
  }
  override lazy val writebackSourceImp: HasWritebackSourceImp = module

  override def generateWritebackIO(
    thisMod: Option[HasWritebackSource] = None,
    thisModImp: Option[HasWritebackSourceImp] = None
  ): Unit = {
    module.io.writeback.zip(writebackSinksImp(thisMod, thisModImp)).foreach(x => x._1 := x._2)
  }
}

class CtrlBlockImp(outer: CtrlBlock)(implicit p: Parameters) extends LazyModuleImp(outer)
197 198 199 200 201
  with HasXSParameter
  with HasCircularQueuePtrHelper
  with HasWritebackSourceImp
  with HasPerfEvents
{
202 203
  val writebackLengths = outer.writebackSinksParams.map(_.length)

204
  val io = IO(new Bundle {
J
Jiawei Lin 已提交
205
    val hartId = Input(UInt(8.W))
206
    val frontend = Flipped(new FrontendToCtrlIO)
207 208
    val allocPregs = Vec(RenameWidth, Output(new ResetPregStateReq))
    val dispatch = Vec(3*dpParams.IntDqDeqWidth, DecoupledIO(new MicroOp))
209 210 211 212 213 214
    // from int block
    val exuRedirect = Vec(exuParameters.AluCnt + exuParameters.JmpCnt, Flipped(ValidIO(new ExuOutput)))
    val stIn = Vec(exuParameters.StuCnt, Flipped(ValidIO(new ExuInput)))
    val memoryViolation = Flipped(ValidIO(new Redirect))
    val jumpPc = Output(UInt(VAddrBits.W))
    val jalr_target = Output(UInt(VAddrBits.W))
Y
Yinan Xu 已提交
215
    val robio = new Bundle {
Y
Yinan Xu 已提交
216
      // to int block
Y
Yinan Xu 已提交
217
      val toCSR = new RobCSRIO
218
      val exception = ValidIO(new ExceptionInfo)
Y
Yinan Xu 已提交
219
      // to mem block
Y
Yinan Xu 已提交
220
      val lsq = new RobLsqIO
Y
Yinan Xu 已提交
221
    }
222
    val csrCtrl = Input(new CustomCSRCtrlIO)
223 224
    val perfInfo = Output(new Bundle{
      val ctrlInfo = new Bundle {
Y
Yinan Xu 已提交
225
        val robFull   = Input(Bool())
226 227 228 229 230
        val intdqFull = Input(Bool())
        val fpdqFull  = Input(Bool())
        val lsdqFull  = Input(Bool())
      }
    })
231
    val writeback = MixedVec(writebackLengths.map(num => Vec(num, Flipped(ValidIO(new ExuOutput)))))
232 233 234 235
    // redirect out
    val redirect = ValidIO(new Redirect)
    val debug_int_rat = Vec(32, Output(UInt(PhyRegIdxWidth.W)))
    val debug_fp_rat = Vec(32, Output(UInt(PhyRegIdxWidth.W)))
236 237
  })

238 239 240 241 242 243 244 245 246 247 248 249 250
  override def writebackSource: Option[Seq[Seq[Valid[ExuOutput]]]] = {
    Some(io.writeback.map(writeback => {
      val exuOutput = WireInit(writeback)
      val timer = GTimer()
      for ((wb_next, wb) <- exuOutput.zip(writeback)) {
        wb_next.valid := RegNext(wb.valid && !wb.bits.uop.robIdx.needFlush(stage2Redirect))
        wb_next.bits := RegNext(wb.bits)
        wb_next.bits.uop.debugInfo.writebackTime := timer
      }
      exuOutput
    }))
  }

251
  val decode = Module(new DecodeStage)
252
  val rat = Module(new RenameTableWrapper)
253 254
  val ssit = Module(new SSIT)
  val waittable = Module(new WaitTable)
255
  val rename = Module(new Rename)
256
  val dispatch = Module(new Dispatch)
257 258 259
  val intDq = Module(new DispatchQueue(dpParams.IntDqSize, RenameWidth, dpParams.IntDqDeqWidth))
  val fpDq = Module(new DispatchQueue(dpParams.FpDqSize, RenameWidth, dpParams.FpDqDeqWidth))
  val lsDq = Module(new DispatchQueue(dpParams.LsDqSize, RenameWidth, dpParams.LsDqDeqWidth))
L
LinJiawei 已提交
260
  val redirectGen = Module(new RedirectGenerator)
261

262
  val rob = outer.rob.module
263

264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283
  val robPcRead = io.frontend.fromFtq.getRobFlushPcRead
  val flushPC = robPcRead(rob.io.flushOut.bits.ftqIdx, rob.io.flushOut.bits.ftqOffset)

  val flushRedirect = Wire(Valid(new Redirect))
  flushRedirect.valid := RegNext(rob.io.flushOut.valid)
  flushRedirect.bits := RegEnable(rob.io.flushOut.bits, rob.io.flushOut.valid)
  flushRedirect.bits.cfiUpdate.target := Mux(io.robio.toCSR.isXRet || rob.io.exception.valid,
    io.robio.toCSR.trapTarget,
    Mux(flushRedirect.bits.flushItself(),
      flushPC, // replay inst
      flushPC + 4.U // flush pipe
    )
  )

  val flushRedirectReg = Wire(Valid(new Redirect))
  flushRedirectReg.valid := RegNext(flushRedirect.valid, init = false.B)
  flushRedirectReg.bits := RegEnable(flushRedirect.bits, enable = flushRedirect.valid)

  val stage2Redirect = Mux(flushRedirect.valid, flushRedirect, redirectGen.io.stage2Redirect)
  val stage3Redirect = Mux(flushRedirectReg.valid, flushRedirectReg, redirectGen.io.stage3Redirect)
L
LinJiawei 已提交
284

285
  val exuRedirect = io.exuRedirect.map(x => {
L
ljw 已提交
286
    val valid = x.valid && x.bits.redirectValid
287
    val killedByOlder = x.bits.uop.robIdx.needFlush(stage2Redirect)
L
ljw 已提交
288 289 290 291
    val delayed = Wire(Valid(new ExuOutput))
    delayed.valid := RegNext(valid && !killedByOlder, init = false.B)
    delayed.bits := RegEnable(x.bits, x.valid)
    delayed
L
LinJiawei 已提交
292
  })
L
ljw 已提交
293
  val loadReplay = Wire(Valid(new Redirect))
294
  loadReplay.valid := RegNext(io.memoryViolation.valid &&
295
    !io.memoryViolation.bits.robIdx.needFlush(stage2Redirect),
L
ljw 已提交
296 297
    init = false.B
  )
298
  loadReplay.bits := RegEnable(io.memoryViolation.bits, io.memoryViolation.valid)
299 300
  io.frontend.fromFtq.getRedirectPcRead <> redirectGen.io.stage1PcRead
  io.frontend.fromFtq.getMemPredPcRead <> redirectGen.io.memPredPcRead
J
Jiawei Lin 已提交
301
  redirectGen.io.hartId := io.hartId
L
ljw 已提交
302
  redirectGen.io.exuMispredict <> exuRedirect
L
ljw 已提交
303
  redirectGen.io.loadReplay <> loadReplay
304
  redirectGen.io.flush := flushRedirect.valid
305

306 307 308 309 310 311 312 313 314 315 316 317
  val frontendFlush = DelayN(flushRedirect, 5)
  val frontendStage2Redirect = Mux(frontendFlush.valid, frontendFlush, redirectGen.io.stage2Redirect)
  for (i <- 0 until CommitWidth) {
    io.frontend.toFtq.rob_commits(i).valid := RegNext(rob.io.commits.valid(i) && !rob.io.commits.isWalk)
    io.frontend.toFtq.rob_commits(i).bits := RegNext(rob.io.commits.info(i))
  }
  io.frontend.toFtq.stage2Redirect := frontendStage2Redirect
  val pendingRedirect = RegInit(false.B)
  when (stage2Redirect.valid) {
    pendingRedirect := true.B
  }.elsewhen (RegNext(io.frontend.toFtq.stage2Redirect.valid)) {
    pendingRedirect := false.B
L
LinJiawei 已提交
318
  }
Y
Yinan Xu 已提交
319

320
  decode.io.in <> io.frontend.cfVec
Y
Yinan Xu 已提交
321
  decode.io.csrCtrl := RegNext(io.csrCtrl)
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345

  // memory dependency predict
  // when decode, send fold pc to mdp
  for (i <- 0 until DecodeWidth) {
    val mdp_foldpc = Mux(
      decode.io.out(i).fire(),
      decode.io.in(i).bits.foldpc,
      rename.io.in(i).bits.cf.foldpc
    )
    ssit.io.raddr(i) := mdp_foldpc
    waittable.io.raddr(i) := mdp_foldpc
  }
  // currently, we only update mdp info when isReplay
  ssit.io.update <> RegNext(redirectGen.io.memPredUpdate)
  ssit.io.csrCtrl := RegNext(io.csrCtrl)
  waittable.io.update <> RegNext(redirectGen.io.memPredUpdate)
  waittable.io.csrCtrl := RegNext(io.csrCtrl)

  // LFST lookup and update
  val lfst = Module(new LFST)
  lfst.io.redirect <> RegNext(io.redirect)
  lfst.io.storeIssue <> RegNext(io.stIn)
  lfst.io.csrCtrl <> RegNext(io.csrCtrl)
  lfst.io.dispatch <> dispatch.io.lfst
346

347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363
  rat.io.robCommits := rob.io.commits
  for ((r, i) <- rat.io.intReadPorts.zipWithIndex) {
    val raddr = decode.io.out(i).bits.ctrl.lsrc.take(2) :+ decode.io.out(i).bits.ctrl.ldest
    r.map(_.addr).zip(raddr).foreach(x => x._1 := x._2)
    rename.io.intReadPorts(i) := r.map(_.data)
    r.foreach(_.hold := !rename.io.in(i).ready)
  }
  rat.io.intRenamePorts := rename.io.intRenamePorts
  for ((r, i) <- rat.io.fpReadPorts.zipWithIndex) {
    val raddr = decode.io.out(i).bits.ctrl.lsrc.take(3) :+ decode.io.out(i).bits.ctrl.ldest
    r.map(_.addr).zip(raddr).foreach(x => x._1 := x._2)
    rename.io.fpReadPorts(i) := r.map(_.data)
    r.foreach(_.hold := !rename.io.in(i).ready)
  }
  rat.io.fpRenamePorts := rename.io.fpRenamePorts
  rat.io.debug_int_rat <> io.debug_int_rat
  rat.io.debug_fp_rat <> io.debug_fp_rat
L
LinJiawei 已提交
364

365
  // pipeline between decode and rename
366
  for (i <- 0 until RenameWidth) {
L
LinJiawei 已提交
367
    PipelineConnect(decode.io.out(i), rename.io.in(i), rename.io.in(i).ready,
368
      stage2Redirect.valid || pendingRedirect)
369
  }
370

371
  rename.io.redirect <> stage2Redirect
Y
Yinan Xu 已提交
372
  rename.io.robCommits <> rob.io.commits
373 374
  rename.io.ssit <> ssit.io.rdata
  rename.io.waittable <> RegNext(waittable.io.rdata)
375

376 377
  // pipeline between rename and dispatch
  for (i <- 0 until RenameWidth) {
378
    PipelineConnect(rename.io.out(i), dispatch.io.fromRename(i), dispatch.io.recv(i), stage2Redirect.valid)
379 380
  }

J
Jiawei Lin 已提交
381
  dispatch.io.hartId := io.hartId
382
  dispatch.io.redirect <> stage2Redirect
Y
Yinan Xu 已提交
383
  dispatch.io.enqRob <> rob.io.enq
384 385 386 387 388 389 390 391 392 393 394
  dispatch.io.toIntDq <> intDq.io.enq
  dispatch.io.toFpDq <> fpDq.io.enq
  dispatch.io.toLsDq <> lsDq.io.enq
  dispatch.io.allocPregs <> io.allocPregs
  dispatch.io.singleStep := false.B

  intDq.io.redirect <> stage2Redirect
  fpDq.io.redirect <> stage2Redirect
  lsDq.io.redirect <> stage2Redirect

  io.dispatch <> intDq.io.deq ++ lsDq.io.deq ++ fpDq.io.deq
Y
Yinan Xu 已提交
395

396 397 398
  val pingpong = RegInit(false.B)
  pingpong := !pingpong
  val jumpInst = Mux(pingpong && (exuParameters.AluCnt > 2).B, io.dispatch(2).bits, io.dispatch(0).bits)
399 400 401 402 403
  val jumpPcRead = io.frontend.fromFtq.getJumpPcRead
  io.jumpPc := jumpPcRead(jumpInst.cf.ftqPtr, jumpInst.cf.ftqOffset)
  val jumpTargetRead = io.frontend.fromFtq.target_read
  io.jalr_target := jumpTargetRead(jumpInst.cf.ftqPtr, jumpInst.cf.ftqOffset)

J
Jiawei Lin 已提交
404
  rob.io.hartId := io.hartId
Y
Yinan Xu 已提交
405
  rob.io.redirect <> stage2Redirect
406
  outer.rob.generateWritebackIO(Some(outer), Some(this))
L
LinJiawei 已提交
407

408
  io.redirect <> stage2Redirect
409

Y
Yinan Xu 已提交
410 411 412 413 414
  // rob to int block
  io.robio.toCSR <> rob.io.csr
  io.robio.toCSR.perfinfo.retiredInstr <> RegNext(rob.io.csr.perfinfo.retiredInstr)
  io.robio.exception := rob.io.exception
  io.robio.exception.bits.uop.cf.pc := flushPC
415

Y
Yinan Xu 已提交
416 417
  // rob to mem block
  io.robio.lsq <> rob.io.lsq
418

Y
Yinan Xu 已提交
419
  io.perfInfo.ctrlInfo.robFull := RegNext(rob.io.robFull)
420 421 422
  io.perfInfo.ctrlInfo.intdqFull := RegNext(intDq.io.dqFull)
  io.perfInfo.ctrlInfo.fpdqFull := RegNext(fpDq.io.dqFull)
  io.perfInfo.ctrlInfo.lsdqFull := RegNext(lsDq.io.dqFull)
423 424

  val pfevent = Module(new PFEvent)
425
  pfevent.io.distribute_csr := RegNext(io.csrCtrl.distribute_csr)
426
  val csrevents = pfevent.io.hpmevent.slice(8,16)
427

428
  val perfinfo = IO(new Bundle(){
429 430 431
    val perfEventsRs      = Input(Vec(NumRs, new PerfEvent))
    val perfEventsEu0     = Input(Vec(6, new PerfEvent))
    val perfEventsEu1     = Input(Vec(6, new PerfEvent))
432 433
  })

434 435 436 437
  val allPerfEvents = Seq(decode, rename, dispatch, intDq, fpDq, lsDq, rob).flatMap(_.getPerf)
  val hpmEvents = allPerfEvents ++ perfinfo.perfEventsEu0 ++ perfinfo.perfEventsEu1 ++ perfinfo.perfEventsRs
  val perfEvents = HPerfMonitor(csrevents, hpmEvents).getPerfEvents
  generatePerfEvent()
438
}