CSE Doesn't Merge Source Locators
- Dominant language
- C++
- Stars
- 2.2k
- Forks
- 524
- Avg merge
- 3d 2h
- Merged PRs (30d)
- 46
Description
I've noticed that CSE doesn't seem to merge source locators. E.g., in the following, the source locator on the second `add` gets dropped:
```
circuit Foo:
module Foo:
input a: UInt<1>
input b: UInt<1>
node x = add(a, b)
node y = add(a, b)
```
Running with `circt-translate -import-firrtl cse.fir | circt-opt -cse -mlir-print-debuginfo -mlir-print-ir-after-all -mlir-print-ir-before-all` produces:
```
// -----// IR Dump Before CSE (cse) //----- //
module {
firrtl.circuit "Foo" {
firrtl.module @Foo(in %a: !firrtl.uint<1>, in %b: !firrtl.uint<1>) {
%0 = firrtl.add %a, %b : (!firrtl.uint<1>, !firrtl.uint<1>) -> !firrtl.uint<2> loc(#loc3)
%x = firrtl.node interesting_name %0 : !firrtl.uint<2> loc(#loc4)
%1 = firrtl.add %a, %b : (!firrtl.uint<1>, !firrtl.uint<1>) -> !firrtl.uint<2> loc(#loc5)
%y = firrtl.node interesting_name %1 : !firrtl.uint<2> loc(#loc6)
} loc(#loc2)
} loc(#loc1)
} loc(#loc)
#loc = loc("":1:1)
#loc1 = loc("":2:3)
#loc2 = loc("":3:5)
#loc3 = loc("":4:12)
#loc4 = loc("":5:12)
#loc5 = loc("":6:12)
#loc6 = loc("":7:12)
// -----// IR Dump After CSE (cse) //----- //
module {
firrtl.circuit "Foo" {
firrtl.module @Foo(in %a: !firrtl.uint<1>, in %b: !firrtl.uint<1>) {
%0 = firrtl.add %a, %b : (!firrtl.uint<1>, !firrtl.uint<1>) -> !firrtl.uint<2> loc(#loc3)
%x = firrtl.node interesting_name %0 : !firrtl.uint<2> loc(#loc4)
%y = firrtl.node interesting_name %0 : !firrtl.uint<2> loc(#loc5)
} loc(#loc2)
} loc(#loc1)
} loc(#loc)
#loc = loc("":1:1)
#loc1 = loc("":2:3)
#loc2 = loc("":3:5)
#loc3 = loc("":4:12)
#loc4 = loc("":5:12)
#loc5 = loc("":7:12)
module {
firrtl.circuit "Foo" {
firrtl.module @Foo(in %a: !firrtl.uint<1>, in %b: !firrtl.uint<1>) {
%0 = firrtl.add %a, %b : (!firrtl.uint<1>, !firrtl.uint<1>) -> !firrtl.uint<2> loc(#loc3)
%x = firrtl.node interesting_name %0 : !firrtl.uint<2> loc(#loc4)
%y = firrtl.node interesting_name %0 : !firrtl.uint<2> loc(#loc5)
} loc(#loc2)
} loc(#loc1)
} loc(#loc)
#loc = loc("":1:1)
#loc1 = loc("":2:3)
#loc2 = loc("":3:5)
#loc3 = loc("":4:12)
#loc4 = loc("":5:12)
#loc5 = loc("":7:12)
```
I would expect to see _the original_ `#loc5` (`:6:12`) to be merged with `#loc3`, but it instead is dropped. This may be an MLIR limitation.
Contributor guide
No contributing guide indexed for this repository
Research direction
Reproduce the issue with circt-translate -import-firrtl cse.fir piped to circt-opt -cse with debug locations and IR dumps enabled. Compare the source locators before and after CSE, and consider the issue complete when the original second add locator is retained or merged rather than dropped.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100