简体   繁体   English

自定义LLVM opt管道的替代方法有哪些?

[英]What are the alternative ways to customize LLVM opt pipeline?

Question

There is no way from command line to safely disable a specific pass in the O1/O2/O3 opt pipeline. 从命令行无法安全地禁用O1 / O2 / O3 opt管道中的特定传递。 What are the alternate ways to customize or tailor the opt pipeline of LLVM passes? 自定义或定制LLVM通道的选择管道有哪些替代方法?

Background and Problem 背景与问题

I am writing a pass to outline specific regions of code and I need to reduce the number of inputs & outputs to the outlined function. 我正在写通行证以概述代码的特定区域,我需要减少概述函数的输入和输出的数量。 In some cases, the opt tool raises some (invariant) GEP instructions (for example, from a loop body). 在某些情况下,opt工具会引发一些(不变的)GEP指令(例如,从循环体内)。 This happens with O1/O2/O3 flags. O1 / O2 / O3标志会发生这种情况。 I do not want this since it creates more number of inputs/outputs to my outlined function. 我不希望这样做,因为它为我概述的功能创建了更多的输入/输出。 I prefer to have the GEP done in the outlined function. 我更喜欢在概述的功能中完成GEP。

Failed attempts 尝试失败

  • The opt O1 pass arguments are shown below. opt O1传递参数如下所示。 I used "print-after" command in opt and looked at the IR to find that the "reassociate" transformation creates this change. 我在opt中使用了“ print-after”命令,并查看了IR,发现“重新关联”转换创建了此更改。 I went over the disable options in opt --help-hidden and I do not find a way to disable this specific pass or LICM. 我遍历了opt --help-hidden中的禁用选项,但没有找到禁用此特定通行证或LICM的方法。
  • I tried looking at the LLVM source code Reassociate.cpp. 我尝试查看LLVM源代码Reassociate.cpp。 I couldn't identify any ways to disable this specific transformation from the code either. 我也找不到任何方法可以从代码中禁用此特定的转换。
  • I have also tried to manually enter specific pass names to the opt command. 我也尝试过手动为opt命令输入特定的通行名称。 However some passes need the O1/2/3 flag to be set. 但是有些通行证需要设置O1 / 2/3标志。 If I do not set the flag, these passes do not make the necessary transformation. 如果我未设置标志,则这些传递不会进行必要的转换。 Example, I need the loop to be unrolled but it does not unroll without O1/2/3 flag, even if i explicitly enter the flag in the opt command. 例如,我需要展开循环,但是即使没有在opt命令中明确输入该标志,它也不会在没有O1 / 2/3标志的情况下展开。

Pass arguments in O1 stage 在O1阶段传递参数

 Pass Arguments:  -targetlibinfo -tti -targetpassconfig -tbaa -scoped-noalias 
    -assumption-cache-tracker -profile-summary-info -forceattrs -inferattrs 
    -ipsccp -called-value-propagation -globalopt -domtree -mem2reg -deadargelim 
    -domtree -basicaa -aa -loops -lazy-branch-prob -lazy-block-freq 
    -opt-remark-emitter -instcombine -simplifycfg -basiccg -globals-aa -prune-eh 
    -always-inline -functionattrs -domtree -sroa -basicaa -aa -memoryssa -early-cse-memssa 
    -speculative-execution -basicaa -aa -lazy-value-info -jump-threading -correlated-propagation 
    -simplifycfg -domtree -basicaa -aa -loops -lazy-branch-prob -lazy-block-freq 
    -opt-remark-emitter -instcombine -libcalls-shrinkwrap -loops -branch-prob -block-freq 
    -lazy-branch-prob -lazy-block-freq -opt-remark-emitter -pgo-memop-opt -basicaa -aa 
    -loops -lazy-branch-prob -lazy-block-freq -opt-remark-emitter -tailcallelim -simplifycfg 
    -reassociate -domtree -loops -loop-simplify -lcssa-verification -lcssa -basicaa -aa 
    -scalar-evolution -loop-rotate -licm -loop-unswitch -simplifycfg -domtree -basicaa -aa -loops
    -lazy-branch-prob -lazy-block-freq -opt-remark-emitter -instcombine -loop-simplify -lcssa-verification -lcssa -scalar-evolution -indvars
    -loop-idiom -loop-deletion -loop-unroll -phi-values -memdep -memcpyopt -sccp -demanded-bits -bdce -basicaa -aa -lazy-branch-prob
    -lazy-block-freq -opt-remark-emitter -instcombine -lazy-value-info -jump-threading -correlated-propagation -basicaa -aa -phi-values
    -memdep -dse -loops -loop-simplify -lcssa-verification -lcssa -basicaa -aa -scalar-evolution -licm -postdomtree -adce -simplifycfg 
    -domtree -basicaa -aa -loops -lazy-branch-prob -lazy-block-freq -opt-remark-emitter -instcombine -barrier -basiccg -rpo-functionattrs 
    -globalopt -globaldce -basiccg -globals-aa -float2int -domtree -loops -loop-simplify -lcssa-verification -lcssa -basicaa -aa -scalar-evolution
    -loop-rotate -loop-accesses -lazy-branch-prob -lazy-block-freq -opt-remark-emitter -loop-distribute -branch-prob -block-freq -scalar-evolution 
    -basicaa -aa -loop-accesses -demanded-bits -lazy-branch-prob -lazy-block-freq -opt-remark-emitter -loop-vectorize -loop-simplify -scalar-evolution 
    -aa -loop-accesses -loop-load-elim -basicaa -aa -lazy-branch-prob -lazy-block-freq -opt-remark-emitter -instcombine -simplifycfg -domtree
    -basicaa -aa -loops -lazy-branch-prob -lazy-block-freq -opt-remark-emitter -instcombine -loop-simplify -lcssa-verification -lcssa 
    -scalar-evolution -loop-unroll -lazy-branch-prob -lazy-block-freq -opt-remark-emitter -instcombine -loop-simplify -lcssa-verification 
    -lcssa -scalar-evolution -licm -alignment-from-assumptions -strip-dead-prototypes -domtree -loops -branch-prob -block-freq -loop-simplify
    -lcssa-verification -lcssa -basicaa -aa -scalar-evolution -branch-prob -block-freq -loop-sink -lazy-branch-prob -lazy-block-freq
    -opt-remark-emitter -instsimplify -div-rem-pairs -simplifycfg -domtree -sroa -verify -print-module

I think what I need is 我认为我需要的是

  • to move the definition close to its use (Any comments on how I can do this at IR stage?) or 使定义接近使用(对在IR阶段如何做到这一点有何评论?)或
  • find a way to safely disable a pass in the opt pipeline (licm, reassociate). 找到一种方法来安全地禁用opt管道中的传递(licm,重新关联)。 I believe this is not possible from command line. 我相信这不可能从命令行进行。 If I have to modify the LLVM source code locally (for hacking the opt pipeline to accomplish what I need), what would be the right place to do this safely? 如果我必须在本地修改LLVM源代码(以便破解opt管道来完成我需要的操作),那么安全地进行此操作的正确位置是什么? Any pointers will be helpful; 任何指针都会有所帮助; or 要么
  • to manually enter the passes I need to run in the opt command without any of the O1/O2/O3 flags But I am not able to find a way to do any of these that works. 手动输入通行证,我需要在没有任何O1 / O2 / O3标志的情况下在opt命令中运行,但是我无法找到一种方法来完成所有这些工作。 I am using LLVM release 7.00 . 我正在使用LLVM版本7.00

Possible solution? 可能的解决方案?

Can I add only the required passes (subset of the O1 pipeline) as AddRequired in getAnalysisUsage() in my pass definition and make opt run my pass with O0 flag enabled? 我可以在通行证定义中仅将所需的通行证(O1管道的子集)添加为getAnalysisUsage()中的AddRequired,并使opt在启用O0标志的情况下运行我的通行证吗? Will this work? 这样行吗? I can try this out. 我可以尝试一下。

According to this thread from summer 2018, there is no general way to disable a specific pass from clang: 根据2018年夏季以来的这一主题,没有通用的方法可以禁用来自clang的特定通行证:

Some passes have supported options to disable them, eg -fno-vectorize and -fno-unroll-loops, but there is no general option. 某些过程支持禁用它们的选项,例如-fno-vectorize和-fno-unroll-loops,但是没有通用选项。 Since it's not useful in general to disable arbitrary options, some handywork is required. 由于禁用任意选项通常没有用,因此需要一些手动操作。

The original poster in the thread seemed to be working on a patch to enable this behavior, but as far as I can tell it never landed. 该线程中的原始发布者似乎正在开发补丁来启用此行为,但据我所知它从未降落。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM