[LLVMdev] Loop unrolling a function

Skye Wanderman-Milne skye at cloudera.com
Thu Jan 16 11:15:43 PST 2014


Thanks for the advice! Kevin, I think you're right about the PassManagers
-- I was able to get loop unrolling working using a FunctionPassManager.
For future reference, the minimal passes that worked for me were
ScalarReplAggregates, LoopRotate, and LoopUnroll.


On Wed, Jan 15, 2014 at 2:49 PM, Kevin Modzelewski <kmod at dropbox.com> wrote:

> Hi Skye, I don't know exactly which pass / combination of passes do it,
> but I went through something similar with some success.  What I did was
> copy the body of
> lib/Transforms/IPO/PassManagerBuilder.cpp::populateModulePassManager()
> which is what I believe sets up the "standard" passes for opt.  That
> function adds the passes to a module passmanager, but it looks like almost
> all of the passes it adds are FunctionPass's, and I was able to add all
> those passes to my FunctionPassManager.  I wasn't focusing on loop
> unrolling but I just checked and this setup does unroll loops; if you want
> to find the minimal set maybe you could do something similar and then
> whittle down?
>
> My understanding (I don't know the pass manager infrastructure too well)
> is that the "larger" pass managers automatically create sub-managers, ie
> the module passmanager will create a function passmanager to run on all the
> functions, and I assume that the function passmanager will create a loop
> passmanager to run on the loops.  But again, I haven't traced through it
> that much so someone else might have to correct me.
>
> Kevin
>
>
> On Wed, Jan 15, 2014 at 2:18 PM, Skye Wanderman-Milne <skye at cloudera.com>wrote:
>
>> The loop rotation pass does modify the function, which I'm guessing means
>> that a FunctionPassManager can be used to run LoopPasses (this is not
>> obvious to me after looking through the FunctionPassManager code).
>> Unfortunately none of the other passes I'm using (ScalarEvolution, LCSSA,
>> IndVarSimplify, and LoopUnroll) appear to have an effect.
>>
>> I verified that the function can be loop unrolled by opt, so I'm
>> currently using opt to narrow down which passes are required to get this
>> result. Once I figure that out I'll see if I can get a FunctionPassManager
>> to run those passes over just the function. I am open to other suggestions
>> though :)
>>
>> Skye
>>
>>
>> On Tue, Jan 14, 2014 at 10:22 PM, Owen Anderson <resistor at mac.com> wrote:
>>
>>> Hi Skye,
>>>
>>> If I remember correctly, our loop unrolling pass requires loop rotation
>>> in order to be very effective.  Can you try adding that before you run the
>>> unroller to see if it helps?
>>>
>>> --Owen
>>>
>>> On Jan 14, 2014, at 09:32 PM, Skye Wanderman-Milne <skye at cloudera.com>
>>> wrote:
>>>
>>>  Hi all,
>>>
>>> I'm attempting to perform loop unrolling on a single function using the
>>> C++ API. Maybe I missed something in the docs, but I cannot figure out a
>>> way to do this. The function I'm working with is very simple, containing a
>>> single for loop and not much else. I compiled the function to IR using
>>> clang with no optimizations enabled.
>>>
>>> My initial plan was to first run the IndVarSimplify pass (as suggested
>>> here <http://llvm.org/docs/Passes.html#loop-unroll-unroll-loops>) and
>>> then the LoopUnroll pass on the function. I tried using a
>>> FunctionPassManager to do this, even though the docs state FPMs are used
>>> with FunctionPasses and not LoopPasses, which didn't complain but had no
>>> effect on the function. Is adding LoopPasses to a FPM supposed to be a
>>> no-op? Is this supposed to work and I'm not running the right combination
>>> of passes to get loop unrolling?
>>>
>>> I also tried creating a LoopInfo object over my function with a FPM so I
>>> could call UnrollLoop() manually, but the LoopInfo didn't return any loops,
>>> perhaps because I'm missing some preliminary passes.
>>>
>>> The last option I considered was copying the function into it's own
>>> module, using a PassManager, and then copying the function back into the
>>> original module. I didn't try this option as creating a valid stand-alone
>>> module with the single function will potentially be difficult.
>>>
>>> Does anyone have a suggestion for how to do this?
>>>
>>> Thanks,
>>> Skye
>>> _______________________________________________
>>> LLVM Developers mailing list
>>> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu
>>> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>>>
>>>
>>
>> _______________________________________________
>> LLVM Developers mailing list
>> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140116/b3be2cd7/attachment.html>


More information about the llvm-dev mailing list