<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><br style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);" class=""><span style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);" class="">I have a IR file, and I want to reproduce the O3 pass manually.</span><div style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);" class=""><br class=""></div><div style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);" class="">I use the following command to get the O3 pass: </div><div style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);" class=""><br class=""></div><div style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);" class="">opt -enable-new-pm=0 -O3 -debug-pass=Arguments main.ll</div><div style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);" class=""><br class=""></div><div style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);" class="">The pass I get:</div><div style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);" class=""><br class=""></div><div style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);" class=""><br class=""></div><div style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);" class=""><div class="">Pass Arguments: -tti -tbaa -scoped-noalias-aa -assumption-cache-tracker -targetlibinfo -verify -lower-expect -simplifycfg -domtree -sroa -early-cse</div><div class="">Pass Arguments: -targetlibinfo -tti -targetpassconfig -tbaa -scoped-noalias-aa -assumption-cache-tracker -profile-summary-info -annotation2metadata -forceattrs -inferattrs -domtree -callsite-splitting -ipsccp -called-value-propagation -globalopt -domtree -mem2reg -deadargelim -domtree -basic-aa -aa -loops -lazy-branch-prob -lazy-block-freq -opt-remark-emitter -instcombine -simplifycfg -basiccg -globals-aa -prune-eh -inline -openmp-opt-cgscc -function-attrs -argpromotion -domtree -sroa -basic-aa -aa -memoryssa -early-cse-memssa -speculative-execution -aa -lazy-value-info -jump-threading -correlated-propagation -simplifycfg -domtree -aggressive-instcombine -basic-aa -aa -loops -lazy-branch-prob -lazy-block-freq -opt-remark-emitter -instcombine -libcalls-shrinkwrap -loops -postdomtree -branch-prob -block-freq -lazy-branch-prob -lazy-block-freq -opt-remark-emitter -pgo-memop-opt -basic-aa -aa -loops -lazy-branch-prob -lazy-block-freq -opt-remark-emitter -tailcallelim -simplifycfg -reassociate -domtree -basic-aa -aa -memoryssa -loops -loop-simplify -lcssa-verification -lcssa -scalar-evolution -lazy-branch-prob -lazy-block-freq -licm -loop-rotate -licm -loop-unswitch -simplifycfg -domtree -basic-aa -aa -loops -lazy-branch-prob -lazy-block-freq -opt-remark-emitter -instcombine -loop-simplify -lcssa-verification -lcssa -scalar-evolution -loop-idiom -indvars -loop-deletion -loop-unroll -sroa -aa -mldst-motion -phi-values -aa -memdep -lazy-branch-prob -lazy-block-freq -opt-remark-emitter -gvn -sccp -demanded-bits -bdce -basic-aa -aa -lazy-branch-prob -lazy-block-freq -opt-remark-emitter -instcombine -lazy-value-info -jump-threading -correlated-propagation -postdomtree -adce -basic-aa -aa -memoryssa -memcpyopt -loops -dse -loop-simplify -lcssa-verification -lcssa -aa -scalar-evolution -lazy-branch-prob -lazy-block-freq -licm -simplifycfg -domtree -basic-aa -aa -loops -lazy-branch-prob -lazy-block-freq -opt-remark-emitter -instcombine -barrier -elim-avail-extern -basiccg -rpo-function-attrs -globalopt -globaldce -basiccg -globals-aa -domtree -float2int -lower-constant-intrinsics -loops -loop-simplify -lcssa-verification -lcssa -basic-aa -aa -scalar-evolution -loop-rotate -loop-accesses -lazy-branch-prob -lazy-block-freq -opt-remark-emitter -loop-distribute -postdomtree -branch-prob -block-freq -scalar-evolution -basic-aa -aa -loop-accesses -demanded-bits -lazy-branch-prob -lazy-block-freq -opt-remark-emitter -inject-tli-mappings -loop-vectorize -loop-simplify -scalar-evolution -aa -loop-accesses -lazy-branch-prob -lazy-block-freq -loop-load-elim -basic-aa -aa -lazy-branch-prob -lazy-block-freq -opt-remark-emitter -instcombine -simplifycfg -domtree -loops -scalar-evolution -basic-aa -aa -demanded-bits -lazy-branch-prob -lazy-block-freq -opt-remark-emitter -inject-tli-mappings -slp-vectorizer -vector-combine -opt-remark-emitter -instcombine -loop-simplify -lcssa-verification -lcssa -scalar-evolution -loop-unroll -lazy-branch-prob -lazy-block-freq -opt-remark-emitter -instcombine -memoryssa -loop-simplify -lcssa-verification -lcssa -scalar-evolution -lazy-branch-prob -lazy-block-freq -licm -opt-remark-emitter -transform-warning -alignment-from-assumptions -strip-dead-prototypes -globaldce -constmerge -cg-profile -domtree -loops -postdomtree -branch-prob -block-freq -loop-simplify -lcssa-verification -lcssa -basic-aa -aa -scalar-evolution -block-freq -loop-sink -lazy-branch-prob -lazy-block-freq -opt-remark-emitter -instsimplify -div-rem-pairs -simplifycfg -annotation-remarks -verify</div><div class="">Pass Arguments: -domtree</div><div class="">Pass Arguments: -targetlibinfo -domtree -loops -postdomtree -branch-prob -block-freq</div><div class="">Pass Arguments: -targetlibinfo -domtree -loops -postdomtree -branch-prob -block-freq</div><div class="">Pass Arguments: -targetlibinfo -domtree -loops -lazy-branch-prob -lazy-block-freq</div><div class=""><br class=""></div><div class="">But when I use the second sequence, I got an error message: </div><div class=""><br class=""></div><div class=""><div class="">LLVM ERROR: Trying to construct TargetPassConfig without a target machine. Scheduling a CodeGen pass without a target triple set?</div><div class="">PLEASE submit a bug report to <a href="https://bugs.llvm.org/" class="">https://bugs.llvm.org/</a> and include the crash backtrace.</div></div><div class=""><br class=""></div><div class=""><div class=""> #0 0x00007f5a4503010c llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/shane/llvm-project/llvm/lib/Support/Unix/Signals.inc:565:0</div><div class=""> #1 0x00007f5a450301c3 PrintStackTraceSignalHandler(void*) /home/shane/llvm-project/llvm/lib/Support/Unix/Signals.inc:632:0</div><div class=""> #2 0x00007f5a4502de70 llvm::sys::RunSignalHandlers() /home/shane/llvm-project/llvm/lib/Support/Signals.cpp:97:0</div><div class=""> #3 0x00007f5a4502fa8c SignalHandler(int) /home/shane/llvm-project/llvm/lib/Support/Unix/Signals.inc:407:0</div><div class=""> #4 0x00007f5a4444b4c0 (/lib/x86_64-linux-gnu/libc.so.6+0x354c0)</div><div class=""> #5 0x00007f5a4444b438 raise /build/glibc-S7Ft5T/glibc-2.23/signal/../sysdeps/unix/sysv/linux/raise.c:54:0</div><div class=""> #6 0x00007f5a4444d03a abort /build/glibc-S7Ft5T/glibc-2.23/stdlib/abort.c:91:0</div><div class=""> #7 0x00007f5a44ebd97a llvm::install_bad_alloc_error_handler(void (*)(void*, char const*, bool), void*) /home/shane/llvm-project/llvm/lib/Support/ErrorHandling.cpp:126:0</div><div class=""> #8 0x00007f5a44ebd771 llvm::report_fatal_error(llvm::StringRef, bool) /home/shane/llvm-project/llvm/lib/Support/ErrorHandling.cpp:86:0</div><div class=""> #9 0x00007f5a4b12f51d /home/shane/llvm-project/llvm/lib/CodeGen/TargetPassConfig.cpp:662:0</div><div class="">#10 0x00007f5a4b137206 llvm::Pass* llvm::callDefaultCtor<llvm::TargetPassConfig>() /home/shane/llvm-project/llvm/include/llvm/PassSupport.h:80:0</div><div class="">#11 0x00000000004dc41a main /home/shane/llvm-project/llvm/tools/opt/opt.cpp:933:0</div><div class="">#12 0x00007f5a44436840 __libc_start_main /build/glibc-S7Ft5T/glibc-2.23/csu/../csu/libc-start.c:325:0</div><div class="">#13 0x00000000004a1689 _start (/home/shane/llvm-project/build/bin/opt+0x4a1689)</div></div><div class=""><br class=""></div><div class="">Below is the command I use:</div><div class=""><br class=""></div><div class="">Step 1. </div><div class=""><br class=""></div><div class="">clang -O3 -Xclang -disable-llvm-optzns main.c -S -emit-llvm -o main.ll</div><div class=""><br class=""></div><div class="">Step 2. </div><div class=""><br class=""></div><div class="">opt -S -enable-new-pm=0 $theSeqenceAbove main.ll -o O3.ll</div></div><div style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);" class=""><br class=""></div><div style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);" class="">Then I got the error message.</div><div style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);" class=""><br class=""></div><div style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);" class="">I remove the pass “targetpasscongfig” and it didn’t show any error message anymore, but the IR is not same as -O3 flag. ( opt -S -enable-new-pm=0 -O3 main.ll -o O3.ll)</div><div style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);" class=""><br class=""></div><div style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);" class="">Is that a bug?</div><div style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);" class=""><br class=""></div><div style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);" class="">I’m using LLVM 14.0.0.</div><div style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);" class=""><br class=""></div><div style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);" class=""><br class=""></div><div style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);" class="">Thank you all!!!</div></body></html>