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

question about Firrtl(IR) optimization #142

Open
YingkunZhou opened this issue Dec 22, 2018 · 11 comments
Open

question about Firrtl(IR) optimization #142

YingkunZhou opened this issue Dec 22, 2018 · 11 comments

Comments

@YingkunZhou
Copy link

YingkunZhou commented Dec 22, 2018

// See LICENSE.txt for license details.
package solutions

import chisel3._

// Problem:
//
// 'out' should be the sum of 'in0' and 'in1'
// Adder width should be parametrized
//
class Adder(val w: Int) extends Module {
  val io = IO(new Bundle {
    val in0 = Input(UInt(w.W))
    val in1 = Input(UInt(w.W))
    val out = Output(UInt(w.W))
  })
  io.out := io.in0 + io.in1
}

above is the scala code for Adder in $TUT_DIR/src/main/scala/problems/
when I run ./run-solution.sh Adder --backend-name verilator
I got the corresponding Verilog code
module Adder(
input clock,
input reset,
input [7:0] io_in0,
input [7:0] io_in1,
output [7:0] io_out
);
wire [8:0] _T_11; // @[Adder.scala 17:20]
assign _T_11 = io_in0 + io_in1; // @[Adder.scala 17:20]
assign io_out = io_in0 + io_in1; // @[Adder.scala 17:10]
endmodule

Here assign _T_11 = io_in0 + io_in1; // @[Adder.scala 17:20] is a line of deadcode, which in my eyes wastes a build-in adder thus should be eliminated. And it is easy to fulfill using dead code elimination for IR. So is it a bug for current chisel3 implementation?

@edwardcwang
Copy link
Member

While I'm not sure why FIRRTL generated _T_11, synthesis tools will almost always prune those kinds of lines so it will not consume any physical resources.

@YingkunZhou
Copy link
Author

But you cannot expect that synthesis tools will do these things.

@edwardcwang
Copy link
Member

From our experience it usually does. Feel free to ask some others or try it yourself.

@grebe
Copy link
Contributor

grebe commented Dec 22, 2018

@YingkunZhou it is definitely fair to say that _T_11 shouldn't be there, regardless of how it impacts final QoR. Is there firrtl output you can also post? It should be in the same directory as the verilog and have a ".fir" file extension. I think this is a backend problem more than a frontend problem, but having firrtl would be helpful in verifying that. Perhaps something is being const-prop'd and then DCE is not being run afterwards.

@YingkunZhou
Copy link
Author

;buildInfoPackage: chisel3, version: 3.1.5, scalaVersion: 2.11.12, sbtVersion: 1.1.1, builtAtString: 2018-12-14 23:45:23.572, builtAtMillis: 1544831123572
circuit Adder :
module Adder :
input clock : Clock
input reset : UInt<1>
output io : {flip in0 : UInt<8>, flip in1 : UInt<8>, out : UInt<8>}

node _T_11 = add(io.in0, io.in1) @[Adder.scala 17:20]
node _T_12 = tail(_T_11, 1) @[Adder.scala 17:20]
io.out <= _T_12 @[Adder.scala 17:10]

@YingkunZhou
Copy link
Author

not familiar with firrtl, though

@grebe
Copy link
Contributor

grebe commented Dec 23, 2018

My output is

module Adder( // @[:test.fir@2.2]
  input        clock, // @[:test.fir@3.4]
  input        reset, // @[:test.fir@4.4]
  input  [7:0] io_in0, // @[:test.fir@5.4]
  input  [7:0] io_in1, // @[:test.fir@5.4]
  output [7:0] io_out // @[:test.fir@5.4]
);
  assign io_out = io_in0 + io_in1; // @[Adder.scala 17:10:test.fir@9.4]
endmodule

Perhaps the tutorial is using an older version of firrtl?

@YingkunZhou
Copy link
Author

so you use master branch? I forget when and how I installed firrtl

@shunshou
Copy link
Member

shunshou commented Dec 23, 2018 via email

@shunshou
Copy link
Member

shunshou commented Dec 23, 2018 via email

@grebe
Copy link
Contributor

grebe commented Dec 23, 2018

You may not have installed firrtl- it's included as a dependency of chisel (see here). Perhaps forcing the latest 3.1.5 for chisel will fix things? The release is a little over a week old.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants