<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Wed, Jul 1, 2015 at 6:38 PM David Blaikie <<a href="mailto:dblaikie@gmail.com">dblaikie@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Jul 1, 2015 at 6:28 PM, Eric Christopher <span dir="ltr"><<a href="mailto:echristo@gmail.com" target="_blank">echristo@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><br><div class="gmail_quote"><div><div><div dir="ltr">On Wed, Jul 1, 2015 at 6:26 PM David Blaikie <<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Jul 1, 2015 at 6:11 PM, Eric Christopher <span dir="ltr"><<a href="mailto:echristo@gmail.com" target="_blank">echristo@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: echristo<br>
Date: Wed Jul  1 20:11:47 2015<br>
New Revision: 241220<br>
<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject-3Frev-3D241220-26view-3Drev&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=aOF-tUFSDFwB2ymTmURed0ATzMOxkxu6E6wwg5ycqn4&s=soIO-NXqZ5mlNtM372Shna54HeKJ54nzOrxAdXfxN4Q&e=" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=241220&view=rev</a><br>
Log:<br>
Add a routine to TargetTransformInfo that will allow targets to look<br>
at the attributes on a function to determine whether or not to allow<br>
inlining.<br>
<br>
Modified:<br>
    llvm/trunk/include/llvm/Analysis/TargetTransformInfo.h<br>
    llvm/trunk/include/llvm/Analysis/TargetTransformInfoImpl.h<br>
    llvm/trunk/lib/Analysis/IPA/InlineCost.cpp<br>
    llvm/trunk/lib/Analysis/TargetTransformInfo.cpp<br>
<br>
Modified: llvm/trunk/include/llvm/Analysis/TargetTransformInfo.h<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_llvm_trunk_include_llvm_Analysis_TargetTransformInfo.h-3Frev-3D241220-26r1-3D241219-26r2-3D241220-26view-3Ddiff&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=aOF-tUFSDFwB2ymTmURed0ATzMOxkxu6E6wwg5ycqn4&s=GRp8Vy-u2GL1p0AN_Mv_iwzHCStMI0TOHkx2XjqdtJU&e=" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/TargetTransformInfo.h?rev=241220&r1=241219&r2=241220&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/Analysis/TargetTransformInfo.h (original)<br>
+++ llvm/trunk/include/llvm/Analysis/TargetTransformInfo.h Wed Jul  1 20:11:47 2015<br>
@@ -519,6 +519,11 @@ public:<br>
   Value *getOrCreateResultFromMemIntrinsic(IntrinsicInst *Inst,<br>
                                            Type *ExpectedType) const;<br>
<br>
+  /// \returns True if the two functions have compatible attributes for inlining<br>
+  /// purposes.<br>
+  bool hasCompatibleFunctionAttributes(const Function *Caller,<br>
+                                       const Function *Callee) const;<br></blockquote></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><br>Given that it gets the whole function, perhaps it should be "areCompatibleFunctions"? (they could look at other properties of the function)<br><br></div></div></div></div></blockquote><div><br></div></div></div><div>Naming is hard. No particular preference here so if you like this one I'll happily change it :)</div></div></div></blockquote><div><br></div></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>Right - well, while we're discussing it, is "compatible" fairly unambiguous here - I would imagine there are many senses in which two functions may be compatible? I'm wondering if it would be helpful to clarify what kind of compatibility this test is about. Maybe even "isInlinable"</div></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div></div></div></div></div></blockquote><div><br></div><div>Yeah. I was trying to make it fairly specific without having a 40 character name for the function. :\</div><div><br></div><div>I'll take any and all naming help :)</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><span><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>Otherwise, can the attribute set/list/container be passed directly, not exposing the whole function to TTI?<br> </div></div></div></div></blockquote><div><br></div></span><div>They could look at other properties, also if you take a look at the x86 one it makes it a bit more obvious that I'm using the function to get parsed subtarget attributes there.</div></div></div></blockquote></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><br>Right - but other implementations (or this one) might look at other properties eventually. Or it might be useful to be able to just mock up some subtarget attributes (perhaps the subtarget attributes of some other function - not the caller, but a potential caller (function splitting? "I'm considering splitting out half of this function & want to see if the attributes would be OK for inlining this call - but don't look at the rest of the original function, it's not entirely important")).<br><br>But yeah, no idea what's appropriate/useful/sufficient in TTI, I haven't looked at its API or have much of a sense of how things are done. +Chandler, since he's tangentially involved given the inliner work, in case any of what I'm rambling about makes sense to him. Otherwise we'll just assume I lack sufficiently useful context here.<br><br></div></div></div></div></blockquote><div><br></div><div>Oh, no I was saying that we didn't want to just pass in the bits etc because we might want to look at other things - agreeing with you :)</div><div><br></div><div>-eric</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>- Dave<br> </div></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><span><font color="#888888"><div><br></div><div>-eric</div></font></span><div><div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+<br>
   /// @}<br>
<br>
 private:<br>
@@ -619,6 +624,8 @@ public:<br>
                                   MemIntrinsicInfo &Info) = 0;<br>
   virtual Value *getOrCreateResultFromMemIntrinsic(IntrinsicInst *Inst,<br>
                                                    Type *ExpectedType) = 0;<br>
+  virtual bool hasCompatibleFunctionAttributes(const Function *Caller,<br>
+                                               const Function *Callee) const = 0;<br>
 };<br>
<br>
 template <typename T><br>
@@ -804,6 +811,10 @@ public:<br>
                                            Type *ExpectedType) override {<br>
     return Impl.getOrCreateResultFromMemIntrinsic(Inst, ExpectedType);<br>
   }<br>
+  bool hasCompatibleFunctionAttributes(const Function *Caller,<br>
+                                       const Function *Callee) const override {<br>
+    return Impl.hasCompatibleFunctionAttributes(Caller, Callee);<br>
+  }<br>
 };<br>
<br>
 template <typename T><br>
<br>
Modified: llvm/trunk/include/llvm/Analysis/TargetTransformInfoImpl.h<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_llvm_trunk_include_llvm_Analysis_TargetTransformInfoImpl.h-3Frev-3D241220-26r1-3D241219-26r2-3D241220-26view-3Ddiff&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=aOF-tUFSDFwB2ymTmURed0ATzMOxkxu6E6wwg5ycqn4&s=tRKuhWXbbo4LoyKj4BjRC8PtURzBs1qPokzrFzWbN0U&e=" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/TargetTransformInfoImpl.h?rev=241220&r1=241219&r2=241220&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/Analysis/TargetTransformInfoImpl.h (original)<br>
+++ llvm/trunk/include/llvm/Analysis/TargetTransformInfoImpl.h Wed Jul  1 20:11:47 2015<br>
@@ -335,6 +335,14 @@ public:<br>
                                            Type *ExpectedType) {<br>
     return nullptr;<br>
   }<br>
+<br>
+  bool hasCompatibleFunctionAttributes(const Function *Caller,<br>
+                                       const Function *Callee) const {<br>
+    return (Caller->getFnAttribute("target-cpu") ==<br>
+            Callee->getFnAttribute("target-cpu")) &&<br>
+           (Caller->getFnAttribute("target-features") ==<br>
+            Callee->getFnAttribute("target-features"));<br>
+  }<br>
 };<br>
<br>
 /// \brief CRTP base class for use as a mix-in that aids implementing<br>
<br>
Modified: llvm/trunk/lib/Analysis/IPA/InlineCost.cpp<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_llvm_trunk_lib_Analysis_IPA_InlineCost.cpp-3Frev-3D241220-26r1-3D241219-26r2-3D241220-26view-3Ddiff&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=aOF-tUFSDFwB2ymTmURed0ATzMOxkxu6E6wwg5ycqn4&s=7yWiZRrWQ_5ooE2zxzBqXLeGkpWrsPGp7viegLFNwto&e=" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/IPA/InlineCost.cpp?rev=241220&r1=241219&r2=241220&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Analysis/IPA/InlineCost.cpp (original)<br>
+++ llvm/trunk/lib/Analysis/IPA/InlineCost.cpp Wed Jul  1 20:11:47 2015<br>
@@ -1344,9 +1344,9 @@ static bool attributeMatches(Function *F<br>
 /// \brief Test that there are no attribute conflicts between Caller and Callee<br>
 ///        that prevent inlining.<br>
 static bool functionsHaveCompatibleAttributes(Function *Caller,<br>
-                                              Function *Callee) {<br>
-  return attributeMatches(Caller, Callee, "target-cpu") &&<br>
-         attributeMatches(Caller, Callee, "target-features") &&<br>
+                                              Function *Callee,<br>
+                                              TargetTransformInfo &TTI) {<br>
+  return TTI.hasCompatibleFunctionAttributes(Caller, Callee) &&<br>
          attributeMatches(Caller, Callee, Attribute::SanitizeAddress) &&<br>
          attributeMatches(Caller, Callee, Attribute::SanitizeMemory) &&<br>
          attributeMatches(Caller, Callee, Attribute::SanitizeThread);<br>
@@ -1368,7 +1368,8 @@ InlineCost InlineCostAnalysis::getInline<br>
<br>
   // Never inline functions with conflicting attributes (unless callee has<br>
   // always-inline attribute).<br>
-  if (!functionsHaveCompatibleAttributes(CS.getCaller(), Callee))<br>
+  if (!functionsHaveCompatibleAttributes(CS.getCaller(), Callee,<br>
+                                         TTIWP->getTTI(*Callee)))<br>
     return llvm::InlineCost::getNever();<br>
<br>
   // Don't inline this call if the caller has the optnone attribute.<br>
<br>
Modified: llvm/trunk/lib/Analysis/TargetTransformInfo.cpp<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_llvm_trunk_lib_Analysis_TargetTransformInfo.cpp-3Frev-3D241220-26r1-3D241219-26r2-3D241220-26view-3Ddiff&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=aOF-tUFSDFwB2ymTmURed0ATzMOxkxu6E6wwg5ycqn4&s=7ejhd56iHlub3ey6qmXAQy14nwzuLs0mkL72-fqTRW0&e=" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/TargetTransformInfo.cpp?rev=241220&r1=241219&r2=241220&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Analysis/TargetTransformInfo.cpp (original)<br>
+++ llvm/trunk/lib/Analysis/TargetTransformInfo.cpp Wed Jul  1 20:11:47 2015<br>
@@ -284,6 +284,11 @@ Value *TargetTransformInfo::getOrCreateR<br>
   return TTIImpl->getOrCreateResultFromMemIntrinsic(Inst, ExpectedType);<br>
 }<br>
<br>
+bool TargetTransformInfo::hasCompatibleFunctionAttributes(<br>
+    const Function *Caller, const Function *Callee) const {<br>
+  return TTIImpl->hasCompatibleFunctionAttributes(Caller, Callee);<br>
+}<br>
+<br>
 TargetTransformInfo::Concept::~Concept() {}<br>
<br>
 TargetIRAnalysis::TargetIRAnalysis() : TTICallback(&getDefaultTTI) {}<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu" target="_blank">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div></div></div></blockquote></div></div></div></div>
</blockquote></div></div></div></blockquote></div></div>