Why there is no difference when i change the level of optimizaition in llvmlite?

224 Views Asked by At

I am trying to use optimization passes of llvmlite for my own program. I have defined the following function for my code as pass function:

def create_pass_manager_builder(opt=3, loop_vectorize=False, slp_vectorize=False):
    pmb = llvm.create_pass_manager_builder()
    pmb.opt_level = opt
    pmb.loop_vectorize = loop_vectorize
    pmb.populate = populate
    pmb.add_dead_code_elimination_pass = add_dead_code_elimination_pass
    pmb.slp_vectorize = slp_vectorize
    pmb.inlining_threshold = _inlining_threshold(opt)
    return pmb

and I try to run it using the following:

module_ref = llvm1.parse_assembly(str(module))
pmb = llvm.create_pass_manager_builder()
pmb.opt_level = 3
pm = llvm.create_module_pass_manager()
pmb.populate(pm)
pm.run(module_ref)

Having this I do have some optimization for my code. However, when I change the optimization level from 3 to 2 or 0, there is no difference for optimization.How can i change the level of optimization and see the difference?

1

There are 1 best solutions below

0
On

Optimizations do not use optimization level on its own. It's rather up to you how you build pass manager or in this case how populate function does it. Digging a little bit I found that in your case when you just use module pass manager, your populate function will call this one http://llvm.org/doxygen/PassManagerBuilder_8cpp_source.html#l00402 there are some references to optLevel and you can check if optimizations depending on it are actually applicable for your code. If code you optimize is not going through these optimizations then you'll see no difference.

Another concern is I'm not exactly sure if you're calling proper create_pass_manager_builder function which has actually some default definition in llvmlite with fixed opt level to 2. I guess this should be

pmb = create_pass_manager_builder()

rather than

pmb = llvm.create_pass_manager_builder()