Skip to content

[P0] Codegen pass mishandles promoted func args (neura.constant {value="%arg*"}) #154

@n0thingNoob

Description

@n0thingNoob

Summary

When function arguments are promoted to constants (via --promote-func-arg-to-const), the IR contains neura.constant ops whose value is a string like "%arg0". The current codegen incorrectly treats these as numeric immediates (e.g., #2) and/or yields an empty src in the generated YAML, causing downstream consumers to “not recognize” the operand.

Expected: codegen should preserve %arg* as symbolic operands and respect their mapping info.
Actual: %arg* is collapsed to a numeric immediate or results in an empty src.

Problem Description

When writing the FFT kernel like this:

void fft_cgra_kernel(float *data, const float *tw, long long N);

Compile/transform with the pass pipeline that includes --promote-func-arg-to-const.

Observe IR (example):

%0 = "neura.constant"() <{value = "%arg0"}> {mapping_locs = [{id = 2 : i32, resource = "tile", time_step = 12 : i32, x = 2 : i32, y = 0 : i32}]} : () -> !neura.data<!llvm.ptr, i1>
%1 = "neura.constant"() <{value = "%arg1"}> {mapping_locs = [{id = 14 : i32, resource = "tile", time_step = 12 : i32, x = 2 : i32, y = 3 : i32}]} : () -> !neura.data<!llvm.ptr, i1>
%2 = "neura.constant"() <{value = "%arg2"}> {mapping_locs = [{id = 10 : i32, resource = "tile", time_step = 12 : i32, x = 2 : i32, y = 2 : i32}]} : () -> !neura.data<i64, i1>

Run the codegen pass.

Inspect the emitted ASM/YAML: %arg* is turned into an immediate like #2 or the YAML has an empty src operand. (Fixed)

Current Solution

We currently directly output %arg* for both YAML and ASM files like this:
YAML
- opcode: "CONSTANT"
src_operands:
- operand: "%arg1"
color: "RED"
dst_operands:
- operand: "NORTH"
color: "RED"
ASM
PE(3,1):
{
CONSTANT, [%arg1, RED] -> [NORTH, RED]
} (t=3)

However, when implementing this in the simulator, we might need to further discuss this issue.

Metadata

Metadata

Assignees

Labels

questionFurther information is requested

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions