[LLVMdev] Having problem about split basic block

Chang May iiiyyykimoa at gmail.com
Mon Nov 24 20:15:25 PST 2014


Hi,

I am using llvm to do some basic loop transformation practice. My target
loop is simple as following:


int x[5000][100] = {0};
    for (j = 0; j < 100; j = j+1){
    for (i = 0; i < 5000; i = i+1){
    x[i][j] = 2;
    }
    }

*What I want to do is to unroll the inner-loop and see how's the speed
change.*
*I first tried to use Looppass to achieve my goal:*

class IndependentUnroll : public llvm::LoopPass
{
public:

virtual void unroll(llvm::Loop *L){

            for (Loop::block_iterator block = L->block_begin(); block !=
L->block_end(); block++) {
                BasicBlock *bb = *block;
                /* Handle loop body.  */
                if (string(bb->getName()).find("for.body3") !=
string::npos) {
                        Instruction *inst = &bb->back();
                      BasicBlock *new_bb = bb->splitBasicBlock(inst);
*                                /*I try to split the block and insert new
instruction*
*                                   But my code crashed here*/*
                      }
}
        }
 IndependentUnroll() : llvm::LoopPass(IndependentUnroll::ID) { }

virtual bool runOnLoop(llvm::Loop *L, llvm::LPPassManager &LPM) {

if (L->getLoopDepth() == 1){
unroll(L);
}
}
static char ID;

};

*And I get the error:*

opt: /home/morris/llvm-3.2/include/llvm/Analysis/LoopInfoImpl.h:297: void
llvm::LoopBase<N, M>::verifyLoop() const [with BlockT = llvm::BasicBlock,
LoopT = llvm::Loop]: Assertion `HasInsideLoopSuccs && "Loop block has no
in-loop successors!"' failed.
0  opt             0x00000000016befda
1  opt             0x00000000016becb0
2  libpthread.so.0 0x00007f95d58e2cb0
3  libc.so.6       0x00007f95d4d380d5 gsignal + 53
4  libc.so.6       0x00007f95d4d3b83b abort + 379
5  libc.so.6       0x00007f95d4d30d9e
6  libc.so.6       0x00007f95d4d30e42
7  opt             0x0000000001405631 llvm::LoopBase<llvm::BasicBlock,
llvm::Loop>::verifyLoop() const + 1441
8  opt             0x000000000140e482
llvm::LPPassManager::runOnFunction(llvm::Function&) + 1354
9  opt             0x00000000015cad3c
llvm::FPPassManager::runOnFunction(llvm::Function&) + 388
10 opt             0x00000000015caf57
llvm::FPPassManager::runOnModule(llvm::Module&) + 107
11 opt             0x00000000015cb29a
llvm::MPPassManager::runOnModule(llvm::Module&) + 456
12 opt             0x00000000015cb7c9
llvm::PassManagerImpl::run(llvm::Module&) + 125
13 opt             0x00000000015cb97d llvm::PassManager::run(llvm::Module&)
+ 39
14 opt             0x00000000008c1904 main + 5346
15 libc.so.6       0x00007f95d4d2376d __libc_start_main + 237
16 opt             0x00000000008b1809

*Can anyone tell me what is the reason of this situation?*
*By the way I can successfully unroll same loop if I write the my pass with
FunctionPass (the same code but traverse by runOnfinction)*

*Thank you!*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20141124/171337f5/attachment.html>


More information about the llvm-dev mailing list