Martin J. O'Riordan via llvm-dev
2018-Jan-01 12:42 UTC
[llvm-dev] Inspecting 'Triple' from arbitrary source files
Hi LLVM-Devs, Sometimes when I am experimenting with a change for my out-of-tree target, I find that to get it working I have to make changes to the target-independent sources for LLVM. Generally I do not like to do this, but sometimes I have not been able to find a pure target-specific solution to the problem I am working on, and have to make these changes in the target-independent code. But LLVM can be configured to support code-generation for multiple targets, so what I would like to do is always make my changes to these files check the 'Triple' and only implement the change when the target is my experimental target. Is there a general purpose way of accessing the current 'Triple' from any where in the code so that I can add these checks? In many places, I can access it via some argument to a function, or from a member of the class to which the function belongs, but this is not always possible. In the longer term, I always strive to find a proper target-specific solution to this, but during prototyping and exploring, making temporary changes to the target-independent code is the best way until I understand how to best implement the final version. Thanks and welcome to 2018, MartinO
Tim Northover via llvm-dev
2018-Jan-01 14:10 UTC
[llvm-dev] Inspecting 'Triple' from arbitrary source files
Hi Martin, On 1 January 2018 at 12:42, Martin J. O'Riordan via llvm-dev <llvm-dev at lists.llvm.org> wrote:> Is there a general purpose way of accessing the current 'Triple' from any > where in the code so that I can add these checks? In many places, I can > access it via some argument to a function, or from a member of the class to > which the function belongs, but this is not always possible.Normally this would be handled by adding target-specific hooks describing the behaviour or optimization rather than inspecting the triple directly. There are various classes dotted through the pipeline designed to provide this information (TargetTransformInfo and TargetMachine being the most obvious).> During prototyping and exploring, making temporary changes to > the target-independent code is the best way until I understand how to best > implement the final version.For purely personal hacks I'd go via Module::getTargetTriple myself, but then for personal hacks I probably wouldn't even bother checking the target. Cheers. Tim.
Martin J. O'Riordan via llvm-dev
2018-Jan-01 17:00 UTC
[llvm-dev] Inspecting 'Triple' from arbitrary source files
Thanks Tim, Sometimes my hacks last longer than I want as it isn't always apparent how I can implement it properly. At the moment I am looking at changes I need to 'MachineBasicBlock::ReplaceUsesOfBlockWith'. It is most likely that I need to handle the issue in a different way, but the change I need works here for my target for the time being, but breaks X86 which I also build for (single clang, multiple targets). But eventually I retire these hacks as the correct solution becomes apparent, I personally hate messing around with the target-independent code for a target-specific purpose as it breaks the abstractions. All the best and thanks again, MartinO -----Original Message----- From: Tim Northover [mailto:t.p.northover at gmail.com] Sent: 01 January 2018 14:10 To: Martin J. O'Riordan <MartinO at theheart.ie> Cc: LLVM Developers <llvm-dev at lists.llvm.org> Subject: Re: [llvm-dev] Inspecting 'Triple' from arbitrary source files Hi Martin, On 1 January 2018 at 12:42, Martin J. O'Riordan via llvm-dev <llvm-dev at lists.llvm.org> wrote:> Is there a general purpose way of accessing the current 'Triple' from > any where in the code so that I can add these checks? In many places, > I can access it via some argument to a function, or from a member of > the class to which the function belongs, but this is not always possible.Normally this would be handled by adding target-specific hooks describing the behaviour or optimization rather than inspecting the triple directly. There are various classes dotted through the pipeline designed to provide this information (TargetTransformInfo and TargetMachine being the most obvious).> During prototyping and exploring, making temporary changes to the > target-independent code is the best way until I understand how to best > implement the final version.For purely personal hacks I'd go via Module::getTargetTriple myself, but then for personal hacks I probably wouldn't even bother checking the target. Cheers. Tim.