<div dir="ltr">To avoid collisions, I have LVI and JumpThreading ported. Will commit them when I have a moment to watch the bots.</div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Jun 12, 2016 at 2:28 AM, Sean Silva <span dir="ltr"><<a href="mailto:chisophugis@gmail.com" target="_blank">chisophugis@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><div class="gmail_extra"><br><div class="gmail_quote"><span class="">On Sun, Jun 12, 2016 at 12:48 AM, Sean Silva via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: silvas<br>
Date: Sun Jun 12 02:48:51 2016<br>
New Revision: 272505<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=272505&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=272505&view=rev</a><br>
Log:<br>
[PM] Port ReversePostOrderFunctionAttrs to the new PM<br>
<br>
Below are my super rough notes when porting. They can probably serve as<br>
a basic guide for porting other passes to the new PM. As I port more<br>
passes I'll expand and generalize this and make a proper<br>
docs/HowToPortToNewPassManager.rst document. There is also missing<br>
documentation for general concepts and API's in the new PM which will<br>
require some documentation.<br>
Once there is proper documentation in place we can put up a list of<br>
passes that have to be ported and game-ify/crowdsource the rest of the<br>
porting (at least of the middle end; the backend is still unclear).<br>
<br>
I will however be taking personal responsibility for ensuring that the<br>
LLD/ELF LTO pipeline is ported in a timely fashion. The remaining passes<br>
to be ported are (do something like<br>
`git grep "<the string in the bullet point below>"` to find the pass):<br>
<br>
General Scalar:<br>
[ ] Simplify the CFG<br></blockquote><div><br></div></span><div>Just noticed the simplifycfg is already ported. So scratch that one off the list.</div><span class="HOEnZb"><font color="#888888"><div><br></div><div>-- Sean Silva</div></font></span><div><div class="h5"><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
[ ] Jump Threading<br>
[ ] MemCpy Optimization<br>
[ ] Promote Memory to Register<br>
[ ] MergedLoadStoreMotion<br>
[ ] Lazy Value Information Analysis<br>
<br>
General IPO:<br>
[ ] Dead Argument Elimination<br>
[ ] Deduce function attributes in RPO<br>
<br>
Loop stuff / vectorization stuff:<br>
[ ] Alignment from assumptions<br>
[ ] Canonicalize natural loops<br>
[ ] Delete dead loops<br>
[ ] Loop Access Analysis<br>
[ ] Loop Invariant Code Motion<br>
[ ] Loop Vectorization<br>
[ ] SLP Vectorizer<br>
[ ] Unroll loops<br>
<br>
Devirtualization / CFI:<br>
[ ] Cross-DSO CFI<br>
[ ] Whole program devirtualization<br>
[ ] Lower bitset metadata<br>
<br>
CGSCC passes:<br>
[ ] Function Integration/Inlining<br>
[ ] Remove unused exception handling info<br>
[ ] Promote 'by reference' arguments to scalars<br>
<br>
Please let me know if you are interested in working on any of the passes<br>
in the above list (e.g. reply to the post-commit thread for this patch).<br>
I'll probably be tackling "General Scalar" and "General IPO" first FWIW.<br>
<br>
Steps as I port "Deduce function attributes in RPO"<br>
---------------------------------------------------<br>
<br>
(note: if you are doing any work based on these notes, please leave a<br>
note in the post-commit review thread for this commit with any<br>
improvements / suggestions / incompleteness you ran into!)<br>
<br>
Note: "Deduce function attributes in RPO" is a module pass.<br>
<br>
1. Do preparatory refactoring.<br>
<br>
Do preparatory factoring. In this case all I had to do was to pull out a static helper (r272503).<br>
(TODO: give more advice here e.g. if pass holds state or something)<br>
<br>
2. Rename the old pass class.<br>
<br>
llvm/lib/Transforms/IPO/FunctionAttrs.cpp<br>
Rename class ReversePostOrderFunctionAttrs -> ReversePostOrderFunctionAttrsLegacyPass<br>
in preparation for adding a class ReversePostOrderFunctionAttrs as the pass in the new PM.<br>
(edit: actually wait what? The new class name will be<br>
ReversePostOrderFunctionAttrsPass, so it doesn't conflict. So this step is<br>
sort of useless churn).<br>
<br>
llvm/include/llvm/InitializePasses.h<br>
llvm/lib/LTO/LTOCodeGenerator.cpp<br>
llvm/lib/Transforms/IPO/IPO.cpp<br>
llvm/lib/Transforms/IPO/FunctionAttrs.cpp<br>
Rename initializeReversePostOrderFunctionAttrsPass -> initializeReversePostOrderFunctionAttrsLegacyPassPass<br>
(note that the "PassPass" thing falls out of `s/ReversePostOrderFunctionAttrs/ReversePostOrderFunctionAttrsLegacyPass/`)<br>
Note that the INITIALIZE_PASS macro is what creates this identifier name, so renaming the class requires this renaming too.<br>
<br>
Note that createReversePostOrderFunctionAttrsPass does not need to be<br>
renamed since its name is not generated from the class name.<br>
<br>
3. Add the new PM pass class.<br>
<br>
In the new PM all passes need to have their<br>
declaration in a header somewhere, so you will often need to add a header.<br>
In this case<br>
llvm/include/llvm/Transforms/IPO/FunctionAttrs.h is already there because<br>
PostOrderFunctionAttrsPass was already ported.<br>
The file-level comment from the .cpp file can be used as the file-level<br>
comment for the new header. You may want to tweak the wording slightly<br>
from "this file implements" to "this file provides" or similar.<br>
<br>
Add declaration for the new PM pass in this header:<br>
<br>
    class ReversePostOrderFunctionAttrsPass<br>
        : public PassInfoMixin<ReversePostOrderFunctionAttrsPass> {<br>
    public:<br>
      PreservedAnalyses run(Module &M, AnalysisManager<Module> &AM);<br>
    };<br>
<br>
Its name should end with `Pass` for consistency (note that this doesn't<br>
collide with the names of most old PM passes). E.g. call it<br>
`<name of the old PM pass>Pass`.<br>
<br>
Also, move the doxygen comment from the old PM pass to the declaration of<br>
this class in the header.<br>
Also, include the declaration for the new PM class<br>
`llvm/Transforms/IPO/FunctionAttrs.h` at the top of the file (in this case,<br>
it was already done when the other pass in this file was ported).<br>
<br>
Now define the `run` method for the new class.<br>
The main things here are:<br>
a) Use AM.getResult<...>(M) to get results instead of `getAnalysis<...>()`<br>
<br>
b) If the old PM pass would have returned "false" (i.e. `Changed ==<br>
false`), then you should return PreservedAnalyses::all();<br>
<br>
c) In the old PM getAnalysisUsage method, observe the calls<br>
   `AU.addPreserved<...>();`.<br>
<br>
   In the case `Changed == true`, for each preserved analysis you should do<br>
   call `PA.preserve<...>()` on a PreservedAnalyses object and return it.<br>
   E.g.:<br>
<br>
       PreservedAnalyses PA;<br>
       PA.preserve<CallGraphAnalysis>();<br>
       return PA;<br>
<br>
Note that calls to skipModule/skipFunction are not supported in the new PM<br>
currently, so optnone and optimization bisect support do not work. You can<br>
just drop those calls for now.<br>
<br>
4. Add the pass to the new PM pass registry to make it available in opt.<br>
<br>
In llvm/lib/Passes/PassBuilder.cpp add a #include for your header.<br>
`#include "llvm/Transforms/IPO/FunctionAttrs.h"`<br>
In this case there is already an include (from when<br>
PostOrderFunctionAttrsPass was ported).<br>
<br>
Add your pass to llvm/lib/Passes/PassRegistry.def<br>
In this case, I added<br>
`MODULE_PASS("rpo-functionattrs", ReversePostOrderFunctionAttrsPass())`<br>
The string is from the `INITIALIZE_PASS*` macros used in the old pass<br>
manager.<br>
<br>
Then choose a test that uses the pass and use the new PM `-passes=...` to<br>
run it.<br>
E.g. in this case there is a test that does:<br>
; RUN: opt < %s -basicaa -functionattrs -rpo-functionattrs -S | FileCheck %s<br>
I have added the line:<br>
; RUN: opt < %s -aa-pipeline=basic-aa -passes='require<targetlibinfo>,cgscc(function-attrs),rpo-functionattrs' -S | FileCheck %s<br>
The `-aa-pipeline=basic-aa` and<br>
`require<targetlibinfo>,cgscc(function-attrs)` are what is needed to run<br>
functionattrs in the new PM (note that in the new PM "functionattrs"<br>
becomes "function-attrs" for some reason). This is just pulled from<br>
`readattrs.ll` which contains the change from when functionattrs was ported<br>
to the new PM.<br>
Adding rpo-functionattrs causes the pass that was just ported to run.<br>
<br>
Modified:<br>
    llvm/trunk/include/llvm/InitializePasses.h<br>
    llvm/trunk/include/llvm/Transforms/IPO/FunctionAttrs.h<br>
    llvm/trunk/lib/LTO/LTOCodeGenerator.cpp<br>
    llvm/trunk/lib/Passes/PassRegistry.def<br>
    llvm/trunk/lib/Transforms/IPO/FunctionAttrs.cpp<br>
    llvm/trunk/lib/Transforms/IPO/IPO.cpp<br>
    llvm/trunk/test/Transforms/FunctionAttrs/norecurse.ll<br>
<br>
Modified: llvm/trunk/include/llvm/InitializePasses.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/InitializePasses.h?rev=272505&r1=272504&r2=272505&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/InitializePasses.h?rev=272505&r1=272504&r2=272505&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/InitializePasses.h (original)<br>
+++ llvm/trunk/include/llvm/InitializePasses.h Sun Jun 12 02:48:51 2016<br>
@@ -279,7 +279,7 @@ void initializeRegionPrinterPass(PassReg<br>
 void initializeRegionViewerPass(PassRegistry&);<br>
 void initializeRegisterCoalescerPass(PassRegistry&);<br>
 void initializeRenameIndependentSubregsPass(PassRegistry&);<br>
-void initializeReversePostOrderFunctionAttrsPass(PassRegistry&);<br>
+void initializeReversePostOrderFunctionAttrsLegacyPassPass(PassRegistry&);<br>
 void initializeRewriteStatepointsForGCPass(PassRegistry&);<br>
 void initializeRewriteSymbolsPass(PassRegistry&);<br>
 void initializeSCCPLegacyPassPass(PassRegistry &);<br>
<br>
Modified: llvm/trunk/include/llvm/Transforms/IPO/FunctionAttrs.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/IPO/FunctionAttrs.h?rev=272505&r1=272504&r2=272505&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/IPO/FunctionAttrs.h?rev=272505&r1=272504&r2=272505&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/Transforms/IPO/FunctionAttrs.h (original)<br>
+++ llvm/trunk/include/llvm/Transforms/IPO/FunctionAttrs.h Sun Jun 12 02:48:51 2016<br>
@@ -37,6 +37,21 @@ struct PostOrderFunctionAttrsPass : Pass<br>
 /// in post-order.<br>
 Pass *createPostOrderFunctionAttrsLegacyPass();<br>
<br>
+/// A pass to do RPO deduction and propagation of function attributes.<br>
+///<br>
+/// This pass provides a general RPO or "top down" propagation of<br>
+/// function attributes. For a few (rare) cases, we can deduce significantly<br>
+/// more about function attributes by working in RPO, so this pass<br>
+/// provides the compliment to the post-order pass above where the majority of<br>
+/// deduction is performed.<br>
+// FIXME: Currently there is no RPO CGSCC pass structure to slide into and so<br>
+// this is a boring module pass, but eventually it should be an RPO CGSCC pass<br>
+// when such infrastructure is available.<br>
+class ReversePostOrderFunctionAttrsPass<br>
+    : public PassInfoMixin<ReversePostOrderFunctionAttrsPass> {<br>
+public:<br>
+  PreservedAnalyses run(Module &M, AnalysisManager<Module> &AM);<br>
+};<br>
 }<br>
<br>
 #endif // LLVM_TRANSFORMS_IPO_FUNCTIONATTRS_H<br>
<br>
Modified: llvm/trunk/lib/LTO/LTOCodeGenerator.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/LTO/LTOCodeGenerator.cpp?rev=272505&r1=272504&r2=272505&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/LTO/LTOCodeGenerator.cpp?rev=272505&r1=272504&r2=272505&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/LTO/LTOCodeGenerator.cpp (original)<br>
+++ llvm/trunk/lib/LTO/LTOCodeGenerator.cpp Sun Jun 12 02:48:51 2016<br>
@@ -122,7 +122,7 @@ void LTOCodeGenerator::initializeLTOPass<br>
   initializeSROA_DTPass(R);<br>
   initializeSROA_SSAUpPass(R);<br>
   initializePostOrderFunctionAttrsLegacyPassPass(R);<br>
-  initializeReversePostOrderFunctionAttrsPass(R);<br>
+  initializeReversePostOrderFunctionAttrsLegacyPassPass(R);<br>
   initializeGlobalsAAWrapperPassPass(R);<br>
   initializeLICMPass(R);<br>
   initializeMergedLoadStoreMotionPass(R);<br>
<br>
Modified: llvm/trunk/lib/Passes/PassRegistry.def<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Passes/PassRegistry.def?rev=272505&r1=272504&r2=272505&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Passes/PassRegistry.def?rev=272505&r1=272504&r2=272505&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Passes/PassRegistry.def (original)<br>
+++ llvm/trunk/lib/Passes/PassRegistry.def Sun Jun 12 02:48:51 2016<br>
@@ -56,6 +56,7 @@ MODULE_PASS("print-profile-summary", Pro<br>
 MODULE_PASS("print-callgraph", CallGraphPrinterPass(dbgs()))<br>
 MODULE_PASS("print", PrintModulePass(dbgs()))<br>
 MODULE_PASS("print-lcg", LazyCallGraphPrinterPass(dbgs()))<br>
+MODULE_PASS("rpo-functionattrs", ReversePostOrderFunctionAttrsPass())<br>
 MODULE_PASS("sample-profile", SampleProfileLoaderPass())<br>
 MODULE_PASS("strip-dead-prototypes", StripDeadPrototypesPass())<br>
 MODULE_PASS("verify", VerifierPass())<br>
<br>
Modified: llvm/trunk/lib/Transforms/IPO/FunctionAttrs.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/FunctionAttrs.cpp?rev=272505&r1=272504&r2=272505&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/FunctionAttrs.cpp?rev=272505&r1=272504&r2=272505&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Transforms/IPO/FunctionAttrs.cpp (original)<br>
+++ llvm/trunk/lib/Transforms/IPO/FunctionAttrs.cpp Sun Jun 12 02:48:51 2016<br>
@@ -1137,20 +1137,10 @@ bool PostOrderFunctionAttrsLegacyPass::r<br>
 }<br>
<br>
 namespace {<br>
-/// A pass to do RPO deduction and propagation of function attributes.<br>
-///<br>
-/// This pass provides a general RPO or "top down" propagation of<br>
-/// function attributes. For a few (rare) cases, we can deduce significantly<br>
-/// more about function attributes by working in RPO, so this pass<br>
-/// provides the compliment to the post-order pass above where the majority of<br>
-/// deduction is performed.<br>
-// FIXME: Currently there is no RPO CGSCC pass structure to slide into and so<br>
-// this is a boring module pass, but eventually it should be an RPO CGSCC pass<br>
-// when such infrastructure is available.<br>
-struct ReversePostOrderFunctionAttrs : public ModulePass {<br>
+struct ReversePostOrderFunctionAttrsLegacyPass : public ModulePass {<br>
   static char ID; // Pass identification, replacement for typeid<br>
-  ReversePostOrderFunctionAttrs() : ModulePass(ID) {<br>
-    initializeReversePostOrderFunctionAttrsPass(*PassRegistry::getPassRegistry());<br>
+  ReversePostOrderFunctionAttrsLegacyPass() : ModulePass(ID) {<br>
+    initializeReversePostOrderFunctionAttrsLegacyPassPass(*PassRegistry::getPassRegistry());<br>
   }<br>
<br>
   bool runOnModule(Module &M) override;<br>
@@ -1163,15 +1153,15 @@ struct ReversePostOrderFunctionAttrs : p<br>
 };<br>
 }<br>
<br>
-char ReversePostOrderFunctionAttrs::ID = 0;<br>
-INITIALIZE_PASS_BEGIN(ReversePostOrderFunctionAttrs, "rpo-functionattrs",<br>
+char ReversePostOrderFunctionAttrsLegacyPass::ID = 0;<br>
+INITIALIZE_PASS_BEGIN(ReversePostOrderFunctionAttrsLegacyPass, "rpo-functionattrs",<br>
                       "Deduce function attributes in RPO", false, false)<br>
 INITIALIZE_PASS_DEPENDENCY(CallGraphWrapperPass)<br>
-INITIALIZE_PASS_END(ReversePostOrderFunctionAttrs, "rpo-functionattrs",<br>
+INITIALIZE_PASS_END(ReversePostOrderFunctionAttrsLegacyPass, "rpo-functionattrs",<br>
                     "Deduce function attributes in RPO", false, false)<br>
<br>
 Pass *llvm::createReversePostOrderFunctionAttrsPass() {<br>
-  return new ReversePostOrderFunctionAttrs();<br>
+  return new ReversePostOrderFunctionAttrsLegacyPass();<br>
 }<br>
<br>
 static bool addNoRecurseAttrsTopDown(Function &F) {<br>
@@ -1229,7 +1219,7 @@ static bool deduceFunctionAttributeInRPO<br>
   return Changed;<br>
 }<br>
<br>
-bool ReversePostOrderFunctionAttrs::runOnModule(Module &M) {<br>
+bool ReversePostOrderFunctionAttrsLegacyPass::runOnModule(Module &M) {<br>
   if (skipModule(M))<br>
     return false;<br>
<br>
@@ -1237,3 +1227,15 @@ bool ReversePostOrderFunctionAttrs::runO<br>
<br>
   return deduceFunctionAttributeInRPO(M, CG);<br>
 }<br>
+<br>
+PreservedAnalyses<br>
+ReversePostOrderFunctionAttrsPass::run(Module &M, AnalysisManager<Module> &AM) {<br>
+  auto &CG = AM.getResult<CallGraphAnalysis>(M);<br>
+<br>
+  bool Changed = deduceFunctionAttributeInRPO(M, CG);<br>
+  if (!Changed)<br>
+    return PreservedAnalyses::all();<br>
+  PreservedAnalyses PA;<br>
+  PA.preserve<CallGraphAnalysis>();<br>
+  return PA;<br>
+}<br>
<br>
Modified: llvm/trunk/lib/Transforms/IPO/IPO.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/IPO.cpp?rev=272505&r1=272504&r2=272505&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/IPO.cpp?rev=272505&r1=272504&r2=272505&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Transforms/IPO/IPO.cpp (original)<br>
+++ llvm/trunk/lib/Transforms/IPO/IPO.cpp Sun Jun 12 02:48:51 2016<br>
@@ -43,7 +43,7 @@ void llvm::initializeIPO(PassRegistry &R<br>
   initializeMergeFunctionsPass(Registry);<br>
   initializePartialInlinerPass(Registry);<br>
   initializePostOrderFunctionAttrsLegacyPassPass(Registry);<br>
-  initializeReversePostOrderFunctionAttrsPass(Registry);<br>
+  initializeReversePostOrderFunctionAttrsLegacyPassPass(Registry);<br>
   initializePruneEHPass(Registry);<br>
   initializeStripDeadPrototypesLegacyPassPass(Registry);<br>
   initializeStripSymbolsPass(Registry);<br>
<br>
Modified: llvm/trunk/test/Transforms/FunctionAttrs/norecurse.ll<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/FunctionAttrs/norecurse.ll?rev=272505&r1=272504&r2=272505&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/FunctionAttrs/norecurse.ll?rev=272505&r1=272504&r2=272505&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/test/Transforms/FunctionAttrs/norecurse.ll (original)<br>
+++ llvm/trunk/test/Transforms/FunctionAttrs/norecurse.ll Sun Jun 12 02:48:51 2016<br>
@@ -1,4 +1,5 @@<br>
 ; RUN: opt < %s -basicaa -functionattrs -rpo-functionattrs -S | FileCheck %s<br>
+; RUN: opt < %s -aa-pipeline=basic-aa -passes='require<targetlibinfo>,cgscc(function-attrs),rpo-functionattrs' -S | FileCheck %s<br>
<br>
 ; CHECK: define i32 @leaf() #0<br>
 define i32 @leaf() {<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></div><br></div></div>
</blockquote></div><br></div>