google / google/xls

[XLScc] unroll pragmas are sensitive to whitespace

Open
#942 0 comments 0 reactions 1 assignee Claimed by @spurserh View on GitHub
xlscc
Dominant language
C++
Stars
1.9k
Forks
283
Avg merge
2d 10h
Merged PRs (30d)
135

Description

Consider:
```
int Calc(const int (&dat)[10]) {
int acc = 0;
#pragma hls_unroll yes
// Extra newline here
for (int i = 0; i < 10; i++) {
acc += dat[i];
}
return acc;
}

class MyBlock {
public:
__xls_channel d_in;
__xls_channel d_out;
void Run() {
int dat[10];
for (int i = 0; i < 10; i++) {
dat[i] = d_in.read();
}
d_out.write(Calc(dat));
}
};
```

Looking at the generated IR, the Calc loop isn't actually unrolled:
```
chan d_in(bits[32], id=0, kind=streaming, ops=receive_only, flow_control=ready_valid, metadata="""""")
chan d_out(bits[32], id=1, kind=streaming, ops=send_only, flow_control=ready_valid, metadata="""""")
chan __for_1_ctx_out((bits[32], bits[32][10], ((), ())), id=2, kind=streaming, ops=send_receive, flow_control=ready_valid, fifo_depth=0, metadata="""""")
chan __for_1_ctx_in((bits[32], bits[32][10], ((), ())), id=3, kind=streaming, ops=send_receive, flow_control=ready_valid, fifo_depth=0, metadata="""""")
chan __for_2_ctx_out((bits[32], bits[32], bits[32][10]), id=4, kind=streaming, ops=send_receive, flow_control=ready_valid, fifo_depth=0, metadata="""""")
chan __for_2_ctx_in((bits[32], bits[32], bits[32][10]), id=5, kind=streaming, ops=send_receive, flow_control=ready_valid, fifo_depth=0, metadata="""""")
```
(note that additional context channel for the second loop)

If the extra comment/newline after `#pragma` is removed, the loop is correctly unrolled.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.