Open lucasreis1 opened 1 year ago
@llvm/issue-subscribers-orcjit
I've been doing more digging and was able to replicate this with different functions that do not include the always_inline
attr. It seems that any function definition that the inlining pass removes after inilning will result in this issue. This includes functions with attributes such as alwaysinline
, inlinehint
, or even with no relevant attributes.
The common denominator here seems to come from the linkage type: linkonce_odr
, which is very favorable for inling but still needs to be present in the symbol table from the perspective of the MU. What's the best approach here? Does the IRMU need to change its approach to generating symbols favorable for inlining, or should the optimization callee be responsible for removing definitions from the MU after inlining?
It's not usually safe to remove symbols from the interface of a MaterializationUnit
. They can be omitted when the MU is created, but then they can't be searched for directly, which is a problem if anyone wants to look them up.
I think we should probably change linkonce_odr
to weak_odr
when the module is added to the JIT. This could result in extra memory consumption when linkonce_odr
s that had been optimized away are emitted, but that's probably better than making them invisible.
Actually after talking to @ributzka I think the better option might be to leave linkonce_odr
symbols out of the interface, since that's how TextAPI would treat them by default.
ORC has a provision for weak symbols that "show up late", e.g. weak definitions of constant pool entries produced during codegen -- we could use this to model linkonce_odr
definitions that don't get fully inlined away.
Faced this issue while dealing with an optimization pipeline that focuses on inlining.
If a function has the
always_inline
attribute andlinkonce_odr
linkage, it is registered as a symbol for materialization by the MU. After optimization, passes discard the definition in IR and no symbol is generated. The symbol request is then left dangling by the MU.Quick module to reproduce:
I have not done in-depth testing, but I'm pretty sure any standard optimization pipeline done by the new pass manager would trigger this, as the function is marked as
always_inline
.