[LLVMdev] [RFC] Stripping unusable intrinsics
Philip Reames
listmail at philipreames.com
Mon Dec 29 11:19:08 PST 2014
On 12/23/2014 10:41 AM, Chris Lattner wrote:
> On Dec 23, 2014, at 10:28 AM, Chris Bieneman <beanz at apple.com
> <mailto:beanz at apple.com>> wrote:
>>>> It should be straight-forward to have something like
>>>> LLVMInitializeX86Target/RegisterTargetMachine install the
>>>> intrinsics into a registry.
>>>
>>> I tried doing that a few years ago. It’s not nearly as easy as it
>>> sounds because we’ve got hardcoded references to various target
>>> intrinsics scattered throughout the code.
>>
>> I was just writing to say exactly this. There are a number of ways we
>> could work toward something like this. I’m completely in favor of a
>> world where Intrinsics are properties of the targets and don’t leach
>> out, however today they do in a lot of places.
>
> What are the specific problems here? Anything that does an equality
> comparison with the IntrinsicID can be changed to do strcmp with the
> name. That would handle the one-off cases like
> InstCombiner::SimplifyDemandedUseBits in InstCombine.
>
> The other cases in InstCombine could be handled similarly, but may be
> better handled by adding a intrinsic behavior query APIs to the
> intrinsic registry, or would be better handled (eventually) by adding
> new attributes to the intrinsics themselves.
I find the idea of replacing a bunch of case statements in a switch with
string comparisons to be highly objectionable. This would be a marked
decrease both in readability and maintainability. I also don't see how
it helps reduce code bloat.
Let me make an alternate proposal. Let's separate out the target
specific cases into their own switch. We can introduce a function along
the lines of isTargetArchitectureEnabled(X86) which internally is
implemented via macros, but externally is just a function call.
We then have code that looks like:
switch(intrinsic_id) {
case Intrinsic::llvm_X: {}
case ....
};
if (isTargetArchitectureEnabled(X86)) {
// We could even break this into a helper function...
switch(intrinsic_id) {
case Intrinsic::x86_X: {}
case ....
};
}
If we've done our jobs right in the optimizer, we should be able to
constant fold that condition at compile time and merge the active
switches back into a single switch case. If the architecture isn't
enabled, the code will trivially fold away. All without (visible)
macros or changing the use of intrinsic ids.
Philip
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20141229/601cd091/attachment.html>
More information about the llvm-dev
mailing list