Guys,<div><br></div><div>What I want to do is to hack global opt pass, which needs ScalarEvolution analysis. However opt crashed saying</div><div>"opt: /home/xchen/llvm/include/llvm/PassAnalysisSupport.h:242: AnalysisType& llvm::Pass::getAnalysisID(const void*, llvm::Function&) [with AnalysisType = llvm::ScalarEvolution]: Assertion `ResultPass && "Unable to find requested analysis info"' failed.".</div>
<div><br></div><div>My question is what should I do to require ScalarEvolution analysis in a Module pass???</div><div><br></div><div>Steps to reproduce(bc file attached in case you do not have clang installed):</div><div>
<br></div><div>1. Makefile looks like this:</div><div><div>all:</div><div>    clang test.c -disable-llvm-optzns -emit-llvm -S</div><div>    llvm-as test.s -o test.bc</div><div>    opt test.bc -loop-unroll -globalopt -loop-unroll -inline -loop-idiom -o out.bc</div>
<div>    llvm-dis < out.bc > out.ll</div></div><div>2. test.c:</div><div><div>#include <stdio.h></div><div><br></div><div>int A[100];</div><div>static int toBeInlined(int A[100]) {</div><div>    int ans = 0;</div>
<div>    for (int i=0; i<100; ++i)</div><div>        ans+=A[i];</div><div>    return ans;</div><div>}</div><div><br></div><div>int main() {</div><div>    for (int i=0; i<100; ++i)</div><div>        if (i%3==0)</div>
<div>            A[i] = i;</div><div>        else</div><div>            A[i] = i+1;</div><div>    int ans = toBeInlined(A);</div><div>    printf("%d\n", ans);</div><div>    return 0;</div><div>}</div></div><div>
<br></div><div>3. globalopt:</div><div><div>--- GlobalOpt.cpp       (revision 162438)</div><div>+++ GlobalOpt.cpp       (working copy)</div><div>@@ -38,6 +38,7 @@</div><div> #include "llvm/ADT/SmallVector.h"</div>
<div> #include "llvm/ADT/Statistic.h"</div><div> #include "llvm/ADT/STLExtras.h"</div><div>+#include "llvm/Analysis/ScalarEvolutionExpander.h"</div><div> #include <algorithm></div><div>
 using namespace llvm;</div><div><br></div><div>@@ -63,6 +64,7 @@</div><div>   struct GlobalOpt : public ModulePass {</div><div>     virtual void getAnalysisUsage(AnalysisUsage &AU) const {</div><div>       AU.addRequired<TargetLibraryInfo>();</div>
<div>+      AU.addRequired<ScalarEvolution>();</div><div>     }</div><div>     static char ID; // Pass identification, replacement for typeid</div><div>     GlobalOpt() : ModulePass(ID) {</div><div>@@ -92,6 +94,7 @@</div>
<div> INITIALIZE_PASS_BEGIN(GlobalOpt, "globalopt",</div><div>                 "Global Variable Optimizer", false, false)</div><div> INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfo)</div><div>+INITIALIZE_PASS_DEPENDENCY(ScalarEvolution)</div>
<div> INITIALIZE_PASS_END(GlobalOpt, "globalopt",</div><div>                 "Global Variable Optimizer", false, false)</div><div><br></div><div>@@ -2087,6 +2090,7 @@</div><div>     if (!F->hasName() && !F->isDeclaration())</div>
<div>       F->setLinkage(GlobalValue::InternalLinkage);</div><div>     F->removeDeadConstantUsers();</div><div>+  ScalarEvolution *SE = &getAnalysis<ScalarEvolution>(*F);      ------------------------------------> CRASH here:</div>
<div>     if (F->isDefTriviallyDead()) {</div><div>       F->eraseFromParent();</div><div>       Changed = true;</div></div><div> </div><div>4. core dump</div><div><div>#0  0x000000386de30265 in raise () from /lib64/libc.so.6</div>
<div>#1  0x000000386de31d10 in abort () from /lib64/libc.so.6</div><div>#2  0x000000386de296e6 in __assert_fail () from /lib64/libc.so.6</div><div>#3  0x000000000058dbe1 in llvm::Pass::getAnalysisID<llvm::ScalarEvolution> (this=0x10e9ef0, PI=0x10d3120, F=</div>
<div>    ...) at /home/xchen/llvm/include/llvm/PassAnalysisSupport.h:242</div><div>#4  0x000000000058dc4c in llvm::Pass::getAnalysis<llvm::ScalarEvolution> (this=0x10e9ef0, F=...)</div><div>    at /home/xchen/llvm/include/llvm/PassAnalysisSupport.h:231</div>
<div>#5  0x0000000000577f60 in (anonymous namespace)::GlobalOpt::OptimizeFunctions (this=0x10e9ef0, M=...)</div><div>    at /home/xchen/llvm/lib/Transforms/IPO/GlobalOpt.cpp:2093</div><div>#6  0x00000000005824c5 in (anonymous namespace)::GlobalOpt::runOnModule (this=0x10e9ef0, M=...)</div>
<div>    at /home/xchen/llvm/lib/Transforms/IPO/GlobalOpt.cpp:3130</div><div>#7  0x0000000000a50c69 in llvm::MPPassManager::runOnModule (this=0x10f4120, M=...)</div><div>    at /home/xchen/llvm/lib/VMCore/PassManager.cpp:1572</div>
<div>#8  0x0000000000a520d9 in llvm::PassManagerImpl::run (this=0x10f44a0, M=...)</div><div>    at /home/xchen/llvm/lib/VMCore/PassManager.cpp:1655</div><div>#9  0x0000000000a5213b in llvm::PassManager::run (this=0x7fffffffd510, M=...)</div>
<div>    at /home/xchen/llvm/lib/VMCore/PassManager.cpp:1684</div><div>#10 0x0000000000541e77 in main (argc=9, argv=0x7fffffffd778) at /home/xchen/llvm/tools/opt/opt.cpp:745</div></div><div><br></div>