<html>
<head>
<meta content="text/html; charset=windows-1252"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<br>
<div class="moz-cite-prefix">On 12/23/2014 10:41 AM, Chris Lattner
wrote:<br>
</div>
<blockquote
cite="mid:F154CC2B-8126-4D6E-B6C1-9AAB1984B434@apple.com"
type="cite">
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
On Dec 23, 2014, at 10:28 AM, Chris Bieneman <<a
moz-do-not-send="true" href="mailto:beanz@apple.com" class="">beanz@apple.com</a>>
wrote:<br class="">
<div>
<blockquote type="cite" class="">
<div class="">
<div style="font-family: Helvetica; font-size: 12px;
font-style: normal; font-variant: normal; font-weight:
normal; letter-spacing: normal; line-height: normal;
orphans: auto; text-align: start; text-indent: 0px;
text-transform: none; white-space: normal; widows: auto;
word-spacing: 0px; -webkit-text-stroke-width: 0px;"
class="">
<blockquote type="cite" class="">
<div class="">
<div class="" style="word-wrap: break-word;
-webkit-nbsp-mode: space; -webkit-line-break:
after-white-space;">
<div class="">
<blockquote type="cite" class="">
<div class="">
<div class="" style="word-wrap: break-word;
-webkit-nbsp-mode: space;
-webkit-line-break: after-white-space;">
<div class="">It should be straight-forward
to have something like
LLVMInitializeX86Target/RegisterTargetMachine
install the intrinsics into a registry.</div>
</div>
</div>
</blockquote>
<br class="">
</div>
<div class="">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.</div>
</div>
</div>
</blockquote>
<br class="">
</div>
<div style="font-family: Helvetica; font-size: 12px;
font-style: normal; font-variant: normal; font-weight:
normal; letter-spacing: normal; line-height: normal;
orphans: auto; text-align: start; text-indent: 0px;
text-transform: none; white-space: normal; widows: auto;
word-spacing: 0px; -webkit-text-stroke-width: 0px;"
class="">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.</div>
</div>
</blockquote>
<div><br class="">
</div>
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.</div>
<div><br class="">
</div>
<div>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.</div>
</blockquote>
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. <br>
<br>
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.
<br>
<br>
We then have code that looks like:<br>
switch(intrinsic_id) {<br>
case Intrinsic::llvm_X: {}<br>
case ....<br>
};<br>
if (isTargetArchitectureEnabled(X86)) {<br>
// We could even break this into a helper function...<br>
switch(intrinsic_id) {<br>
case Intrinsic::x86_X: {}<br>
case ....<br>
};<br>
}<br>
<br>
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.<br>
<br>
Philip<br>
<br>
<br>
<br>
<br>
<br>
<br>
</body>
</html>