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

Hi Martin,

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.

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

There's always the hypothetical

    template<typename T> llvm::Triple giveMeATripleDamnYou(const T &);

Just keep adding implementations until you stop needing to. :wink:

Cheers.

Tim.

Haha :slight_smile: