Renato Golin
2012-Oct-20 17:37 UTC
[LLVMdev] How to represent __attribute__((fastcall)) functions in the IL
On 19 October 2012 17:00, Duncan Sands <baldrick at free.fr> wrote:> That said, I also don't like the idea of filling the IR with tons of target > specific stuff.In this case, I think it's even worse than "aapcs" or "fastcall", that are target dependent, but at a higher level. Proposing at which register each variable will be, forces the front-ends to know all about all targets LLVM supports (the register names for x86_64 will be different than for x86, which will be different than ARM, Thumb, MIPS, etc). Which is not just a language/ABI issue, but hardware architecture one. Having the PCSBuilder / PCS pass, would decouple the front-end of the back-end, at least on PCS matters. However, I agree with you that we should not have function signatures that are different than their calls. -- cheers, --renato http://systemcall.org/
Chandler Carruth
2012-Oct-20 18:39 UTC
[LLVMdev] How to represent __attribute__((fastcall)) functions in the IL
On Sat, Oct 20, 2012 at 10:37 AM, Renato Golin <rengolin at systemcall.org> wrote:> On 19 October 2012 17:00, Duncan Sands <baldrick at free.fr> wrote: >> That said, I also don't like the idea of filling the IR with tons of target >> specific stuff. > > In this case, I think it's even worse than "aapcs" or "fastcall", that > are target dependent, but at a higher level. > > Proposing at which register each variable will be, forces the > front-ends to know all about all targets LLVM supports (the register > names for x86_64 will be different than for x86, which will be > different than ARM, Thumb, MIPS, etc). Which is not just a > language/ABI issue, but hardware architecture one.I don't really disagree with anyone who finds this a bit distasteful, but understand that we are already in an even worse situation. The frontend must in fact reason in extreme detail about the targets that LLVM supports, and these frontends already have the exact register positioning (if not naming) encoded in them. In addition, frontends must currently reason about exactly how each target in LLVM will choose to lower various arguments and return values of various types, and try to conjure up an LLVM type and parameter distribution which each target will lower into the exact registers which are mandated by the ABI for that target. So the situation today is that frontends have all of this target-specific information *and* there is an implicit, unspecified contract between the frontend, LLVM's IR, and each target backend about exactly how the lowering through these will occur in order to ensure that the actual code generated matches the ABI requirements the frontend is trying to encode. :: sigh :: While in theory, I would love it if the frontends could be unaware of such details, it seems impractical. The ABI is really tho combination of language and target, whether we like it or not. I think we just need a model for explicitly describing the required lowering, and hopefully in a way orthogonal to the LLVM IR type system so that we don't have to waste large amounts of IR complexity on shoving bits into and out of peculiar IR types. Unfortunately, I have no such concrete design in mind, and I certainly still think that the onstack thing is a step in the right direction. -Chandler> > Having the PCSBuilder / PCS pass, would decouple the front-end of the > back-end, at least on PCS matters. > > However, I agree with you that we should not have function signatures > that are different than their calls. > > -- > cheers, > --renato > > http://systemcall.org/
Daniel Dunbar
2012-Oct-20 19:58 UTC
[LLVMdev] How to represent __attribute__((fastcall)) functions in the IL
On Sat, Oct 20, 2012 at 11:39 AM, Chandler Carruth <chandlerc at google.com> wrote:> On Sat, Oct 20, 2012 at 10:37 AM, Renato Golin <rengolin at systemcall.org> wrote: >> On 19 October 2012 17:00, Duncan Sands <baldrick at free.fr> wrote: >>> That said, I also don't like the idea of filling the IR with tons of target >>> specific stuff. >> >> In this case, I think it's even worse than "aapcs" or "fastcall", that >> are target dependent, but at a higher level. >> >> Proposing at which register each variable will be, forces the >> front-ends to know all about all targets LLVM supports (the register >> names for x86_64 will be different than for x86, which will be >> different than ARM, Thumb, MIPS, etc). Which is not just a >> language/ABI issue, but hardware architecture one. > > I don't really disagree with anyone who finds this a bit distasteful, > but understand that we are already in an even worse situation. > > The frontend must in fact reason in extreme detail about the targets > that LLVM supports, and these frontends already have the exact > register positioning (if not naming) encoded in them. > > In addition, frontends must currently reason about exactly how each > target in LLVM will choose to lower various arguments and return > values of various types, and try to conjure up an LLVM type and > parameter distribution which each target will lower into the exact > registers which are mandated by the ABI for that target. > > So the situation today is that frontends have all of this > target-specific information *and* there is an implicit, unspecified > contract between the frontend, LLVM's IR, and each target backend > about exactly how the lowering through these will occur in order to > ensure that the actual code generated matches the ABI requirements the > frontend is trying to encode. :: sigh :: > > > While in theory, I would love it if the frontends could be unaware of > such details, it seems impractical. The ABI is really tho combination > of language and target, whether we like it or not. I think we just > need a model for explicitly describing the required lowering, and > hopefully in a way orthogonal to the LLVM IR type system so that we > don't have to waste large amounts of IR complexity on shoving bits > into and out of peculiar IR types. > > Unfortunately, I have no such concrete design in mind, and I certainly > still think that the onstack thing is a step in the right direction.+1 This is a good description of the situation. Adding more information to the IR is just making the current use of an implicit contract explicit. At the same time, the addition of this contract should give the frontend much more leverage to be explicit and get the right ABI without abusing the IR. In practice, that could result in across the board wins for compile time and for execution time in the cases our abusive IR doesn't get optimized well. The other piece of this is that currently the mid-level optimizers are really inhibited as far as what they can do to rewrite function calls arguments. Allowing things to be more explicit in the IR would go some ways towards allowing the mid-level optimizers to rewrite function arguments without changing the ABI. - Daniel> > -Chandler > >> >> Having the PCSBuilder / PCS pass, would decouple the front-end of the >> back-end, at least on PCS matters. >> >> However, I agree with you that we should not have function signatures >> that are different than their calls. >> >> -- >> cheers, >> --renato >> >> http://systemcall.org/ > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
James
2012-Oct-20 23:13 UTC
[LLVMdev] How to represent __attribute__((fastcall)) functions in the IL
Chandler Carruth-2 wrote> On Sat, Oct 20, 2012 at 10:37 AM, Renato Golin <> rengolin@> > wrote: >> On 19 October 2012 17:00, Duncan Sands <> baldrick@> > wrote: >>> That said, I also don't like the idea of filling the IR with tons of >>> target >>> specific stuff. >> >> In this case, I think it's even worse than "aapcs" or "fastcall", that >> are target dependent, but at a higher level. >> >> Proposing at which register each variable will be, forces the >> front-ends to know all about all targets LLVM supports (the register >> names for x86_64 will be different than for x86, which will be >> different than ARM, Thumb, MIPS, etc). Which is not just a >> language/ABI issue, but hardware architecture one. > > I don't really disagree with anyone who finds this a bit distasteful, > but understand that we are already in an even worse situation. > > The frontend must in fact reason in extreme detail about the targets > that LLVM supports, and these frontends already have the exact > register positioning (if not naming) encoded in them. > > In addition, frontends must currently reason about exactly how each > target in LLVM will choose to lower various arguments and return > values of various types, and try to conjure up an LLVM type and > parameter distribution which each target will lower into the exact > registers which are mandated by the ABI for that target. > > So the situation today is that frontends have all of this > target-specific information *and* there is an implicit, unspecified > contract between the frontend, LLVM's IR, and each target backend > about exactly how the lowering through these will occur in order to > ensure that the actual code generated matches the ABI requirements the > frontend is trying to encode. :: sigh :: > > > While in theory, I would love it if the frontends could be unaware of > such details, it seems impractical. The ABI is really tho combination > of language and target, whether we like it or not. I think we just > need a model for explicitly describing the required lowering, and > hopefully in a way orthogonal to the LLVM IR type system so that we > don't have to waste large amounts of IR complexity on shoving bits > into and out of peculiar IR types. > > Unfortunately, I have no such concrete design in mind, and I certainly > still think that the onstack thing is a step in the right direction.Why not move the ABI reasoning to the lowering stage instead, and simply specify which calling convention should be used in the function declaration? The complex reasoning that's currently in clang to determine the placement of each parameter could be moved to LLVM and called in the lowering phase. One problem as you say of course is that the ABI is tied to the language, and so some information is lost in the generation of the IR from the AST; i.e. it isn't obvious how to get an LLVM function back to what function / method / constructor it came from in the source language. However it wouldn't be impossible to attatch this needed information to the LLVM function when it's created so that the lowering code *can* have all the information it needs. The big win for this approach is lowering the bar for new frontends using ABIs which have lowering code already written. Another is that language interoperability is made significantly easier: if I want to call some code from language X, then all I have to do is tell LLVM to use language X's calling convention for this function and specify what the declaration in X looks like. Instead, at the moment, I'd have to duplicate the ABI logic for X to determine what the declaration looks like for the particular target I'm compiling on. Similarly, if I'm in language X and want to expose some functions as a C functions, I don't need to know the details of the C ABI. Food for thought anyway. James -- View this message in context: http://llvm.1065342.n5.nabble.com/How-to-represent-attribute-fastcall-functions-in-the-IL-tp50151p50218.html Sent from the LLVM - Dev mailing list archive at Nabble.com.
Renato Golin
2012-Oct-21 12:03 UTC
[LLVMdev] How to represent __attribute__((fastcall)) functions in the IL
On 20 October 2012 19:39, Chandler Carruth <chandlerc at google.com> wrote:> I think we just > need a model for explicitly describing the required lowering, and > hopefully in a way orthogonal to the LLVM IR type system so that we > don't have to waste large amounts of IR complexity on shoving bits > into and out of peculiar IR types.We're not against that. The proposal is to move away the complexity that front-ends need to handle by moving the code out to a PCSBuilder, that would do the bridge between the language and the target parts of the ABIs. The IR would probably still have inreg, onstack and others, but at least in a consistent way. We're not advocating for removing information from the IR, but to make it consistent across all front-ends, and hopefully easing the life of front-end engineers. This PCSBuilder could have several versions (or a collation of versions, via policies), so you could join the front and back parts of ABIs on the fly, but that's irrelevant for the discussion at this point.> Unfortunately, I have no such concrete design in mind, and I certainly > still think that the onstack thing is a step in the right direction.No arguments here. I'm happy with the 'onstack' flag. -- cheers, --renato http://systemcall.org/
Reasonably Related Threads
- [LLVMdev] How to represent __attribute__((fastcall)) functions in the IL
- [LLVMdev] How to represent __attribute__((fastcall)) functions in the IL
- [LLVMdev] How to represent __attribute__((fastcall)) functions in the IL
- [LLVMdev] How to represent __attribute__((fastcall)) functions in the IL
- [LLVMdev] How to represent __attribute__((fastcall)) functions in the IL