llvm / circt

Circuit IR Compilers and Tools
https://circt.org
Other
1.67k stars 298 forks source link

[Question] A way to getOrAddInnerSym from external programs? #6524

Closed SpriteOvO closed 9 months ago

SpriteOvO commented 11 months ago

Last week, I implemented probe related stuff in Chisel binder (chipsalliance/chisel#3668). In CIRCT, firrtl.ref.rwprobe needs a target attribute with InnerRefAttr type. So I filled inner_sym attribute for all ops that have it. It worked fine then.

In recent days, I've noticed that CIRCT complains an error if an op's inner_sym is filled and not referenced later.

error: unable to lower due to symbol "_WIRE" with target not preserved by lowering

firtool doesn't have this problem, because firtool fills the inner_sym only when it needs to refer to an op result, via function getOrAddInnerSym (called from FIRStmtParser::parseRWProbe).

But in the external program, there is no such information as InnerSymbolNamespace and uint64_t fieldID (because they are private). What would be the best way to handle a situation like the target attribute of rwprobe?

SpriteOvO commented 9 months ago

Solved by set the inner_sym only when needed, by using mlirOperationSetInherentAttributeByName function. (code)

Thanks @seldridge's help!

seldridge commented 9 months ago

Nice! I'm glad you got this working.