Rather than bending over backwards to keep all of this working, we should try to add the IR facilities needed to avoid these problems.
This is the result of a discussion between myself Duncan and Eric (all of us probably relaying ideas from still other discussions) that I’m trying to write down here because none of us are going to be able to prioritize working on this soon. If anyone else ends up needing facilities related to this or having time to make this part of LLVM better, that would be awesome. Hence, a request for patches more than a request for comments. =D
(and apologies if this is poorly structured or rambly)
I’m aware of at least two quite strange uses of metadata at the moment (Duncan, Eric, jump in with more I missed):
- The need for an arbitrary (often target-specific) symbolic string in the IR that can be used with intrinsics and/or instructions
- The need to build up a nearly arbitrary record of the “flags” used to control the code generation of the module which need to be handled correctly at link time.
Neither of these fit the model of metadata. They aren’t really optional. They can’t be stripped while preserving correctness. They aren’t annotations at all. I’m suggesting they both need first class representation, and that this representation won’t really be complex or intrusive.
We need the ability to put semantic information in the IR that can be used by targets without extending the IR itself. In some cases we can do this with target-specific intrinsics, but those don’t always fit the problem and have their own set of challenges.
I think it would be nice if we just had a top level IR construct for symbolic strings. These should be allowed both inline (much like immediate constants) and potentially out-of-line like attributes. It is possible that this feature could be useful to simplify attributes or #2, but it seems simple and useful enough that I’m OK with it living on its own.
These symbolic strings would definitionally have no impact on the generated code. We could make them opaque Constants if that’s a useful API. If we don’t need the Constant API, I would do something similar to Duncan’s separation for metadata. My suspicion is that making these Constants would be convenient so they can be used as Values, with the understanding that it would be invalid to use them in arbitrary places, as they only have defined semantics in specific scenarios. The canonical example would be:
call i64 @llvm.read_register(“sp”)
We need to make module flags a first class entity of the module, just like datalayout:
&flag = …
(syntax shamelessly stolen from Duncan’s suggestion in IRC)
We can then actually specify exactly what the requirements are on module flags and how they are linked. We might be able to sink datalayout into this, or it might be better to keep separate, unsure. But having these be top-level real entities would be great.
Hope these thoughts are useful. Sadly I’m not going to be able to drive any of these any time soon. I get a similar impression from Duncan. But I think lots of us would be able to help if someone wanted to contribute work on this front.
If there is broad consensus about the design points above, I’ll paste them into two PRs as well for tracking.