<div dir="ltr">Rather than bending over backwards to keep all of this working, we should try to add the IR facilities needed to avoid these problems.<div><br></div><div>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</div><div><br></div><div><braindump> (and apologies if this is poorly structured or rambly)</div><div><br></div><div><br></div><div>I'm aware of at least two quite strange uses of metadata at the moment (Duncan, Eric, jump in with more I missed):</div><div>1) The need for an arbitrary (often target-specific) symbolic string in the IR that can be used with intrinsics and/or instructions</div><div>2) 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.</div><div><br></div><div>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.</div><div><br></div><div><br></div><div>#1</div><div>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.</div><div><br></div><div>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.</div><div><br></div><div>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:</div><div><br></div><div>  call i64 @llvm.read_register(<sigil>"sp")</div><div><br></div><div><br></div><div>#2</div><div>We need to make module flags a first class entity of the module, just like datalayout:</div><div><br></div><div>  &flag = ....</div><div><br></div><div>(syntax shamelessly stolen from Duncan's suggestion in IRC)</div><div><br></div><div>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.</div><div><br></div><div><br></div><div></braindump></div><div><br></div><div>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.</div><div><br></div><div>If there is broad consensus about the design points above, I'll paste them into two PRs as well for tracking.</div><div><br></div><div>-Chandler</div></div>