problem with runOnLoop

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

problem with runOnLoop

neda 8664
hi all,

I want access to all basic blocks of function in a loop, so I used the following code:

bool parallel::runOnLoop(Loop *L, LPPassManager &LPM)
{
    for (Function::iterator bi= func->begin(); bi != func->end(); bi++){
       //
     }
}


First loop run without problem, but for second loop I get the following error:

libLLVM-2.9.so 0x0137d530
libLLVM-2.9.so 0x0137fa6c
2                 0x002a7400 __kernel_sigreturn + 0
3  parallel.so    0x002895e9 parallel::runOnLoop(llvm::Loop*, llvm::LPPassManager&) + 345
libLLVM-2.9.so 0x00982994 llvm::LPPassManager::runOnFunction(llvm::Function&) + 1156
libLLVM-2.9.so 0x00eb02c1 llvm::FPPassManager::runOnFunction(llvm::Function&) + 545
libLLVM-2.9.so 0x00eb03d7 llvm::FPPassManager::runOnModule(llvm::Module&) + 87
libLLVM-2.9.so 0x00eafde5 llvm::MPPassManager::runOnModule(llvm::Module&) + 517
libLLVM-2.9.so 0x00eaff8b llvm::PassManagerImpl::run(llvm::Module&) + 171
libLLVM-2.9.so 0x00eb008d llvm::PassManager::run(llvm::Module&) + 45
10 opt            0x0805b32f main + 5295
11 libc.so.6      0x002becc6 __libc_start_main + 230
12 opt            0x0804ff51
Stack dump:
0.    Program arguments: opt -dse -lda -memdep -basicaa -libcall-aa -scev-aa -globalsmodref-aa -load /home/llvm/src/Release+Debug+Profile+Asserts/lib/parallel.so -parallel -dot-cfg obj.o -o out.o
1.    Running pass 'Function Pass Manager' on module 'obj.o'.
2.    Running pass 'Loop Pass Manager' on function '@main'
3.    Running pass 'parallel World Pass' on basic block '%bb4'
Segmentation fault (core dumped)


_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: problem with runOnLoop

John Criswell-4
On 12/12/11 9:59 AM, neda 8664 wrote:
hi all,

I want access to all basic blocks of function in a loop, so I used the following code:

bool parallel::runOnLoop(Loop *L, LPPassManager &LPM)
{
    for (Function::iterator bi= func->begin(); bi != func->end(); bi++){
       //
     }
}


Are you modifying anything within this code (especially changes that add/remove basic blocks or change their Terminator instructions)?  Depending on what you're doing, you may be invalidating the basic block iterator bi.

-- John T.


First loop run without problem, but for second loop I get the following error:

libLLVM-2.9.so 0x0137d530
libLLVM-2.9.so 0x0137fa6c
2                 0x002a7400 __kernel_sigreturn + 0
3  parallel.so    0x002895e9 parallel::runOnLoop(llvm::Loop*, llvm::LPPassManager&) + 345
libLLVM-2.9.so 0x00982994 llvm::LPPassManager::runOnFunction(llvm::Function&) + 1156
libLLVM-2.9.so 0x00eb02c1 llvm::FPPassManager::runOnFunction(llvm::Function&) + 545
libLLVM-2.9.so 0x00eb03d7 llvm::FPPassManager::runOnModule(llvm::Module&) + 87
libLLVM-2.9.so 0x00eafde5 llvm::MPPassManager::runOnModule(llvm::Module&) + 517
libLLVM-2.9.so 0x00eaff8b llvm::PassManagerImpl::run(llvm::Module&) + 171
libLLVM-2.9.so 0x00eb008d llvm::PassManager::run(llvm::Module&) + 45
10 opt            0x0805b32f main + 5295
11 libc.so.6      0x002becc6 __libc_start_main + 230
12 opt            0x0804ff51
Stack dump:
0.    Program arguments: opt -dse -lda -memdep -basicaa -libcall-aa -scev-aa -globalsmodref-aa -load /home/llvm/src/Release+Debug+Profile+Asserts/lib/parallel.so -parallel -dot-cfg obj.o -o out.o
1.    Running pass 'Function Pass Manager' on module 'obj.o'.
2.    Running pass 'Loop Pass Manager' on function '@main'
3.    Running pass 'parallel World Pass' on basic block '%bb4'
Segmentation fault (core dumped)



_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev


_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: problem with runOnLoop

neda 8664

Thank you for your reply

Yes, I change them, so what should I do for another loops?

On Mon, Dec 12, 2011 at 7:54 PM, neda 8664 <[hidden email]> wrote:

Thank you for your reply

Yes, I change them, so what should I do for another loops?


On Mon, Dec 12, 2011 at 7:42 PM, John Criswell <[hidden email]> wrote:
On 12/12/11 9:59 AM, neda 8664 wrote:
hi all,

I want access to all basic blocks of function in a loop, so I used the following code:

bool parallel::runOnLoop(Loop *L, LPPassManager &LPM)
{
    for (Function::iterator bi= func->begin(); bi != func->end(); bi++){
       //
     }
}


Are you modifying anything within this code (especially changes that add/remove basic blocks or change their Terminator instructions)?  Depending on what you're doing, you may be invalidating the basic block iterator bi.

-- John T.


First loop run without problem, but for second loop I get the following error:

libLLVM-2.9.so 0x0137d530
libLLVM-2.9.so 0x0137fa6c
2                 0x002a7400 __kernel_sigreturn + 0
3  parallel.so    0x002895e9 parallel::runOnLoop(llvm::Loop*, llvm::LPPassManager&) + 345
libLLVM-2.9.so 0x00982994 llvm::LPPassManager::runOnFunction(llvm::Function&) + 1156
libLLVM-2.9.so 0x00eb02c1 llvm::FPPassManager::runOnFunction(llvm::Function&) + 545
libLLVM-2.9.so 0x00eb03d7 llvm::FPPassManager::runOnModule(llvm::Module&) + 87
libLLVM-2.9.so 0x00eafde5 llvm::MPPassManager::runOnModule(llvm::Module&) + 517
libLLVM-2.9.so 0x00eaff8b llvm::PassManagerImpl::run(llvm::Module&) + 171
libLLVM-2.9.so 0x00eb008d llvm::PassManager::run(llvm::Module&) + 45
10 opt            0x0805b32f main + 5295
11 libc.so.6      0x002becc6 __libc_start_main + 230
12 opt            0x0804ff51
Stack dump:
0.    Program arguments: opt -dse -lda -memdep -basicaa -libcall-aa -scev-aa -globalsmodref-aa -load /home/llvm/src/Release+Debug+Profile+Asserts/lib/parallel.so -parallel -dot-cfg obj.o -o out.o
1.    Running pass 'Function Pass Manager' on module 'obj.o'.
2.    Running pass 'Loop Pass Manager' on function '@main'
3.    Running pass 'parallel World Pass' on basic block '%bb4'
Segmentation fault (core dumped)



_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev




_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: problem with runOnLoop

John Criswell-4
On 12/12/11 10:25 AM, neda 8664 wrote:

Thank you for your reply

Yes, I change them, so what should I do for another loops?

I don't really know what you should do since I don't know what your code does.  All I know is that it's changing the function's control-flow graph.

If you're not modifying the structure of the loops in the function, then you can probably just fix the problem by using a worklist-style algorithm.  First loop through the basic blocks in the function and record in a std::vector<> or std::set<> (or some other C++ container) the set of basic blocks that you want to change.  After you do that, you can iterate through all the basic blocks in the container and start making modifications to them.

That will fix any iterator invalidation occurring with the for() loop.  That may work, but if I had been writing this pass, I would probably have made it a FunctionPass to ensure that the CFG changes don't confuse the PassManager.

-- John T.


On Mon, Dec 12, 2011 at 7:54 PM, neda 8664 <[hidden email]> wrote:

Thank you for your reply

Yes, I change them, so what should I do for another loops?


On Mon, Dec 12, 2011 at 7:42 PM, John Criswell <[hidden email]> wrote:
On 12/12/11 9:59 AM, neda 8664 wrote:
hi all,

I want access to all basic blocks of function in a loop, so I used the following code:

bool parallel::runOnLoop(Loop *L, LPPassManager &LPM)
{
    for (Function::iterator bi= func->begin(); bi != func->end(); bi++){
       //
     }
}


Are you modifying anything within this code (especially changes that add/remove basic blocks or change their Terminator instructions)?  Depending on what you're doing, you may be invalidating the basic block iterator bi.

-- John T.


First loop run without problem, but for second loop I get the following error:

libLLVM-2.9.so 0x0137d530
libLLVM-2.9.so 0x0137fa6c
2                 0x002a7400 __kernel_sigreturn + 0
3  parallel.so    0x002895e9 parallel::runOnLoop(llvm::Loop*, llvm::LPPassManager&) + 345
libLLVM-2.9.so 0x00982994 llvm::LPPassManager::runOnFunction(llvm::Function&) + 1156
libLLVM-2.9.so 0x00eb02c1 llvm::FPPassManager::runOnFunction(llvm::Function&) + 545
libLLVM-2.9.so 0x00eb03d7 llvm::FPPassManager::runOnModule(llvm::Module&) + 87
libLLVM-2.9.so 0x00eafde5 llvm::MPPassManager::runOnModule(llvm::Module&) + 517
libLLVM-2.9.so 0x00eaff8b llvm::PassManagerImpl::run(llvm::Module&) + 171
libLLVM-2.9.so 0x00eb008d llvm::PassManager::run(llvm::Module&) + 45
10 opt            0x0805b32f main + 5295
11 libc.so.6      0x002becc6 __libc_start_main + 230
12 opt            0x0804ff51
Stack dump:
0.    Program arguments: opt -dse -lda -memdep -basicaa -libcall-aa -scev-aa -globalsmodref-aa -load /home/llvm/src/Release+Debug+Profile+Asserts/lib/parallel.so -parallel -dot-cfg obj.o -o out.o
1.    Running pass 'Function Pass Manager' on module 'obj.o'.
2.    Running pass 'Loop Pass Manager' on function '@main'
3.    Running pass 'parallel World Pass' on basic block '%bb4'
Segmentation fault (core dumped)



_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev





_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: problem with runOnLoop

neda 8664

I am changing structure of loops, I used std::vector<> but i get same error, I can’t use FunctionPass  :(



On Mon, Dec 12, 2011 at 8:03 PM, John Criswell <[hidden email]> wrote:
On 12/12/11 10:25 AM, neda 8664 wrote:

Thank you for your reply

Yes, I change them, so what should I do for another loops?

I don't really know what you should do since I don't know what your code does.  All I know is that it's changing the function's control-flow graph.

If you're not modifying the structure of the loops in the function, then you can probably just fix the problem by using a worklist-style algorithm.  First loop through the basic blocks in the function and record in a std::vector<> or std::set<> (or some other C++ container) the set of basic blocks that you want to change.  After you do that, you can iterate through all the basic blocks in the container and start making modifications to them.

That will fix any iterator invalidation occurring with the for() loop.  That may work, but if I had been writing this pass, I would probably have made it a FunctionPass to ensure that the CFG changes don't confuse the PassManager.

-- John T.



On Mon, Dec 12, 2011 at 7:54 PM, neda 8664 <[hidden email]> wrote:

Thank you for your reply

Yes, I change them, so what should I do for another loops?


On Mon, Dec 12, 2011 at 7:42 PM, John Criswell <[hidden email]> wrote:
On 12/12/11 9:59 AM, neda 8664 wrote:
hi all,

I want access to all basic blocks of function in a loop, so I used the following code:

bool parallel::runOnLoop(Loop *L, LPPassManager &LPM)
{
    for (Function::iterator bi= func->begin(); bi != func->end(); bi++){
       //
     }
}


Are you modifying anything within this code (especially changes that add/remove basic blocks or change their Terminator instructions)?  Depending on what you're doing, you may be invalidating the basic block iterator bi.

-- John T.


First loop run without problem, but for second loop I get the following error:

libLLVM-2.9.so 0x0137d530
libLLVM-2.9.so 0x0137fa6c
2                 0x002a7400 __kernel_sigreturn + 0
3  parallel.so    0x002895e9 parallel::runOnLoop(llvm::Loop*, llvm::LPPassManager&) + 345
libLLVM-2.9.so 0x00982994 llvm::LPPassManager::runOnFunction(llvm::Function&) + 1156
libLLVM-2.9.so 0x00eb02c1 llvm::FPPassManager::runOnFunction(llvm::Function&) + 545
libLLVM-2.9.so 0x00eb03d7 llvm::FPPassManager::runOnModule(llvm::Module&) + 87
libLLVM-2.9.so 0x00eafde5 llvm::MPPassManager::runOnModule(llvm::Module&) + 517
libLLVM-2.9.so 0x00eaff8b llvm::PassManagerImpl::run(llvm::Module&) + 171
libLLVM-2.9.so 0x00eb008d llvm::PassManager::run(llvm::Module&) + 45
10 opt            0x0805b32f main + 5295
11 libc.so.6      0x002becc6 __libc_start_main + 230
12 opt            0x0804ff51
Stack dump:
0.    Program arguments: opt -dse -lda -memdep -basicaa -libcall-aa -scev-aa -globalsmodref-aa -load /home/llvm/src/Release+Debug+Profile+Asserts/lib/parallel.so -parallel -dot-cfg obj.o -o out.o
1.    Running pass 'Function Pass Manager' on module 'obj.o'.
2.    Running pass 'Loop Pass Manager' on function '@main'
3.    Running pass 'parallel World Pass' on basic block '%bb4'
Segmentation fault (core dumped)



_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev






_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: problem with runOnLoop

Devang Patel

On Dec 12, 2011, at 10:44 AM, neda 8664 wrote:

I am changing structure of loops,

LoopPass manager is walking loop nest while invoking each loop pass on a given loop. If you update structure of loops then you need to let loop pass manager know. 

I used std::vector<> but i get same error, I can’t use FunctionPass  :(

There must be a good reason. 

In any case, see LPPassManager (it is a FunctionPass :), which provides simple hooks to record deletion/creation of loops. If that does not work for you, you'll have to update LPPassManager to meet your needs.

-
Devang

_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: problem with runOnLoop

Alexandru Ionut Diaconescu
In reply to this post by John Criswell-4
John Criswell <criswell <at> illinois.edu> writes:

>
>
>     On 12/12/11 9:59 AM, neda 8664 wrote:
>    
>      
>       hi all,
>       I want access to all basic blocks of function in a loop, so I used
>       the following code:bool parallel::runOnLoop(Loop *L, LPPassManager
>           &LPM)
>           {
>               for (Function::iterator bi= func->begin(); bi !=
>           func->end(); bi++){
>                  //
>                }
>           }
>
>    
>     Are you modifying anything within this code (especially changes that
>     add/remove basic blocks or change their Terminator instructions)? 
>     Depending on what you're doing, you may be invalidating the basic
>     block iterator bi.
>     -- John T.
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev <at> cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>

Hello, I am getting same opt Stack dump error frequently as well. Also trying to
access basic blocks in runOnBasicBlock(BasicBlock &BB). This is at the 4th line
with errs():
Instruction* current = BB.getTerminator();
errs() << "\n last: "<<*current<<"\n";
Instruction* prev = current->getPrevNode();
errs()<<*prev<<"\n";
What can be the cause?




_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: problem with runOnLoop

Duncan Sands
On 18/12/12 10:34, Alex wrote:

> John Criswell <criswell <at> illinois.edu> writes:
>
>>
>>
>>      On 12/12/11 9:59 AM, neda 8664 wrote:
>>
>>
>>        hi all,
>>        I want access to all basic blocks of function in a loop, so I used
>>        the following code:bool parallel::runOnLoop(Loop *L, LPPassManager
>>            &LPM)
>>            {
>>                for (Function::iterator bi= func->begin(); bi !=
>>            func->end(); bi++){
>>                   //
>>                 }
>>            }
>>
>>
>>      Are you modifying anything within this code (especially changes that
>>      add/remove basic blocks or change their Terminator instructions)?
>>      Depending on what you're doing, you may be invalidating the basic
>>      block iterator bi.
>>      -- John T.
>>
>> _______________________________________________
>> LLVM Developers mailing list
>> LLVMdev <at> cs.uiuc.edu         http://llvm.cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>>
>
> Hello, I am getting same opt Stack dump error frequently as well. Also trying to
> access basic blocks in runOnBasicBlock(BasicBlock &BB). This is at the 4th line
> with errs():
> Instruction* current = BB.getTerminator();
> errs() << "\n last: "<<*current<<"\n";
> Instruction* prev = current->getPrevNode();
> errs()<<*prev<<"\n";
> What can be the cause?

This will happen if the terminator was the only instruction in the basic block.
Then prev will be pointing to rubbish.

Ciao, Duncan.

_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev