<div dir="ltr">Any thoughts on the layering issues (OptBisect depending on analyses, but is part of IR, which Analysis depends on)? Can we remove the default OptBisect behaivor & require callers to set an OptPassGate instead? (& move OptBisect somewhere up - to Analysis or further up)<br><br><div class="gmail_quote"><div dir="ltr">On Thu, Apr 5, 2018 at 3:32 AM Fedor Sergeev via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: fedor.sergeev<br>
Date: Thu Apr 5 03:29:37 2018<br>
New Revision: 329267<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=329267&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=329267&view=rev</a><br>
Log:<br>
allow custom OptBisect classes set to LLVMContext<br>
<br>
This patch introduces a way to set custom OptPassGate instances to LLVMContext.<br>
A new instance field OptBisector and a new method setOptBisect() are added<br>
to the LLVMContext classes. These changes allow to set a custom OptBisect class<br>
that can make its own decisions on skipping optional passes.<br>
<br>
Another important feature of this change is ability to set different instances<br>
of OptPassGate to different LLVMContexts. So the different contexts can be used<br>
independently in several compiling threads of one process.<br>
<br>
One unit test is added.<br>
<br>
Patch by Yevgeny Rouban.<br>
<br>
Reviewers: andrew.w.kaylor, fedor.sergeev, vsk, dberlin, Eugene.Zelenko, reames, skatkov<br>
Reviewed By: andrew.w.kaylor, fedor.sergeev<br>
Differential Revision: <a href="https://reviews.llvm.org/D44464" rel="noreferrer" target="_blank">https://reviews.llvm.org/D44464</a><br>
<br>
Modified:<br>
llvm/trunk/include/llvm/IR/LLVMContext.h<br>
llvm/trunk/lib/IR/LLVMContext.cpp<br>
llvm/trunk/lib/IR/LLVMContextImpl.cpp<br>
llvm/trunk/lib/IR/LLVMContextImpl.h<br>
llvm/trunk/unittests/IR/LegacyPassManagerTest.cpp<br>
<br>
Modified: llvm/trunk/include/llvm/IR/LLVMContext.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/LLVMContext.h?rev=329267&r1=329266&r2=329267&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/LLVMContext.h?rev=329267&r1=329266&r2=329267&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/IR/LLVMContext.h (original)<br>
+++ llvm/trunk/include/llvm/IR/LLVMContext.h Thu Apr 5 03:29:37 2018<br>
@@ -315,9 +315,16 @@ public:<br>
return OptionRegistry::instance().template get<ValT, Base, Mem>();<br>
}<br>
<br>
- /// \brief Access the object which manages optimization bisection for failure<br>
- /// analysis.<br>
- OptPassGate &getOptPassGate();<br>
+ /// \brief Access the object which can disable optional passes and individual<br>
+ /// optimizations at compile time.<br>
+ OptPassGate &getOptPassGate() const;<br>
+<br>
+ /// \brief Set the object which can disable optional passes and individual<br>
+ /// optimizations at compile time.<br>
+ ///<br>
+ /// The lifetime of the object must be guaranteed to extend as long as the<br>
+ /// LLVMContext is used by compilation.<br>
+ void setOptPassGate(OptPassGate&);<br>
<br>
private:<br>
// Module needs access to the add/removeModule methods.<br>
<br>
Modified: llvm/trunk/lib/IR/LLVMContext.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/LLVMContext.cpp?rev=329267&r1=329266&r2=329267&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/LLVMContext.cpp?rev=329267&r1=329266&r2=329267&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/IR/LLVMContext.cpp (original)<br>
+++ llvm/trunk/lib/IR/LLVMContext.cpp Thu Apr 5 03:29:37 2018<br>
@@ -332,10 +332,14 @@ void LLVMContext::setDiscardValueNames(b<br>
pImpl->DiscardValueNames = Discard;<br>
}<br>
<br>
-OptPassGate &LLVMContext::getOptPassGate() {<br>
+OptPassGate &LLVMContext::getOptPassGate() const {<br>
return pImpl->getOptPassGate();<br>
}<br>
<br>
+void LLVMContext::setOptPassGate(OptPassGate& OPG) {<br>
+ pImpl->setOptPassGate(OPG);<br>
+}<br>
+<br>
const DiagnosticHandler *LLVMContext::getDiagHandlerPtr() const {<br>
return pImpl->DiagHandler.get();<br>
}<br>
<br>
Modified: llvm/trunk/lib/IR/LLVMContextImpl.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/LLVMContextImpl.cpp?rev=329267&r1=329266&r2=329267&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/LLVMContextImpl.cpp?rev=329267&r1=329266&r2=329267&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/IR/LLVMContextImpl.cpp (original)<br>
+++ llvm/trunk/lib/IR/LLVMContextImpl.cpp Thu Apr 5 03:29:37 2018<br>
@@ -233,6 +233,12 @@ void LLVMContextImpl::getSyncScopeNames(<br>
/// enabled in order to enable a consistent bisect count.<br>
static ManagedStatic<OptBisect> OptBisector;<br>
<br>
-OptPassGate &LLVMContextImpl::getOptPassGate() {<br>
- return *OptBisector;<br>
+OptPassGate &LLVMContextImpl::getOptPassGate() const {<br>
+ if (!OPG)<br>
+ OPG = &(*OptBisector);<br>
+ return *OPG;<br>
+}<br>
+<br>
+void LLVMContextImpl::setOptPassGate(OptPassGate& OPG) {<br>
+ this->OPG = &OPG;<br>
}<br>
<br>
Modified: llvm/trunk/lib/IR/LLVMContextImpl.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/LLVMContextImpl.h?rev=329267&r1=329266&r2=329267&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/LLVMContextImpl.h?rev=329267&r1=329266&r2=329267&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/IR/LLVMContextImpl.h (original)<br>
+++ llvm/trunk/lib/IR/LLVMContextImpl.h Thu Apr 5 03:29:37 2018<br>
@@ -1355,9 +1355,18 @@ public:<br>
/// Destroy the ConstantArrays if they are not used.<br>
void dropTriviallyDeadConstantArrays();<br>
<br>
- /// \brief Access the object which manages optimization bisection for failure<br>
- /// analysis.<br>
- OptPassGate &getOptPassGate();<br>
+ mutable OptPassGate *OPG = nullptr;<br>
+<br>
+ /// \brief Access the object which can disable optional passes and individual<br>
+ /// optimizations at compile time.<br>
+ OptPassGate &getOptPassGate() const;<br>
+<br>
+ /// \brief Set the object which can disable optional passes and individual<br>
+ /// optimizations at compile time.<br>
+ ///<br>
+ /// The lifetime of the object must be guaranteed to extend as long as the<br>
+ /// LLVMContext is used by compilation.<br>
+ void setOptPassGate(OptPassGate&);<br>
};<br>
<br>
} // end namespace llvm<br>
<br>
Modified: llvm/trunk/unittests/IR/LegacyPassManagerTest.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/IR/LegacyPassManagerTest.cpp?rev=329267&r1=329266&r2=329267&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/IR/LegacyPassManagerTest.cpp?rev=329267&r1=329266&r2=329267&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/unittests/IR/LegacyPassManagerTest.cpp (original)<br>
+++ llvm/trunk/unittests/IR/LegacyPassManagerTest.cpp Thu Apr 5 03:29:37 2018<br>
@@ -26,6 +26,7 @@<br>
#include "llvm/IR/Instructions.h"<br>
#include "llvm/IR/LLVMContext.h"<br>
#include "llvm/IR/Module.h"<br>
+#include "llvm/IR/OptBisect.h"<br>
#include "llvm/Pass.h"<br>
#include "llvm/Support/MathExtras.h"<br>
#include "llvm/Support/raw_ostream.h"<br>
@@ -396,6 +397,67 @@ namespace llvm {<br>
delete M;<br>
}<br>
<br>
+ // Skips or runs optional passes.<br>
+ struct CustomOptPassGate : public OptPassGate {<br>
+ bool Skip;<br>
+ CustomOptPassGate(bool Skip) : Skip(Skip) { }<br>
+ bool shouldRunPass(const Pass *P, const Module &U) { return !Skip; }<br>
+ };<br>
+<br>
+ // Optional module pass.<br>
+ struct ModuleOpt: public ModulePass {<br>
+ char run = 0;<br>
+ static char ID;<br>
+ ModuleOpt() : ModulePass(ID) { }<br>
+ bool runOnModule(Module &M) override {<br>
+ if (!skipModule(M))<br>
+ run++;<br>
+ return false;<br>
+ }<br>
+ };<br>
+ char ModuleOpt::ID=0;<br>
+<br>
+ TEST(PassManager, CustomOptPassGate) {<br>
+ LLVMContext Context0;<br>
+ LLVMContext Context1;<br>
+ LLVMContext Context2;<br>
+ CustomOptPassGate SkipOptionalPasses(true);<br>
+ CustomOptPassGate RunOptionalPasses(false);<br>
+<br>
+ Module M0("custom-opt-bisect", Context0);<br>
+ Module M1("custom-opt-bisect", Context1);<br>
+ Module M2("custom-opt-bisect2", Context2);<br>
+ struct ModuleOpt *mOpt0 = new ModuleOpt();<br>
+ struct ModuleOpt *mOpt1 = new ModuleOpt();<br>
+ struct ModuleOpt *mOpt2 = new ModuleOpt();<br>
+<br>
+ mOpt0->run = mOpt1->run = mOpt2->run = 0;<br>
+<br>
+ legacy::PassManager Passes0;<br>
+ legacy::PassManager Passes1;<br>
+ legacy::PassManager Passes2;<br>
+<br>
+ Passes0.add(mOpt0);<br>
+ Passes1.add(mOpt1);<br>
+ Passes2.add(mOpt2);<br>
+<br>
+ Context1.setOptPassGate(SkipOptionalPasses);<br>
+ Context2.setOptPassGate(RunOptionalPasses);<br>
+<br>
+ Passes0.run(M0);<br>
+ Passes1.run(M1);<br>
+ Passes2.run(M2);<br>
+<br>
+ // By default optional passes are run.<br>
+ EXPECT_EQ(1, mOpt0->run);<br>
+<br>
+ // The first context skips optional passes.<br>
+ EXPECT_EQ(0, mOpt1->run);<br>
+<br>
+ // The second context runs optional passes.<br>
+ EXPECT_EQ(1, mOpt2->run);<br>
+ }<br>
+<br>
Module *makeLLVMModule(LLVMContext &Context) {<br>
// Module Construction<br>
Module *mod = new Module("test-mem", Context);<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div></div>