使用llvm do循环展开,在拆分块时失败

使用llvm do循环展开,在拆分块时失败,llvm,unroll,Llvm,Unroll,我做llvm是为了一些基本的循环转换实践。 我要转换的目标循环如下所示: int main () { int j=0,i=0; int x[100][5000] = {0}; for (i = 0; i < 100; i = i+1){ for (j = 0; j < 5000; j = j+1){ x[i][j] = 2 * x[i][j]; } } return 0;

我做llvm是为了一些基本的循环转换实践。 我要转换的目标循环如下所示:

int main ()
{
    int j=0,i=0;
    int x[100][5000] = {0};  

    for (i = 0; i < 100; i = i+1){
        for (j = 0; j < 5000; j = j+1){
            x[i][j] = 2 * x[i][j];
        }       
    }
   return 0;
}
当我想要展开内部循环时,它是for.cond1、for.body3和for.inc这三个部分。我首先在指令分支拆分for.body3,然后想在它们之间插入新的展开块:

  %3 = load i32* %j, align 4
  %idxprom = sext i32 %3 to i64
  %4 = load i32* %i, align 4
  %idxprom4 = sext i32 %4 to i64
  %arrayidx = getelementptr inbounds [5000 x [100 x i32]]* %x, i32 0, i64 %idxprom4
  %arrayidx5 = getelementptr inbounds [100 x i32]* %arrayidx, i32 0, i64 %idxprom
  %5 = load i32* %arrayidx5, align 4
  %mul = mul nsw i32 2, %5
  %6 = load i32* %j, align 4
  %idxprom6 = sext i32 %6 to i64
  %7 = load i32* %i, align 4
  %idxprom7 = sext i32 %7 to i64
  %arrayidx8 = getelementptr inbounds [5000 x [100 x i32]]* %x, i32 0, i64 %idxprom7
  %arrayidx9 = getelementptr inbounds [100 x i32]* %arrayidx8, i32 0, i64 %idxprom6
  store i32 %mul, i32* %arrayidx9, align 4

  // insert new blocks here

  br label %for.inc
但当我在我的通行证上给出提示时,我犯了错误

我的指示:

BasicBlock *bb_new = bb->splitBasicBlock(inst_br);
错误:

Assertion (`HasInsideLoopSuccs && "Loop block has no in-loop successors!)
熟悉llvm的人能告诉我问题出在哪里吗?或者我是否有其他方法来分割块并插入展开块

HasInsideLopSuccs设置为以下LoopInfoImpl.h

// Check the individual blocks.
for ( ; BI != BE; ++BI) {
BlockT *BB = *BI;
bool HasInsideLoopSuccs = false;
bool HasInsideLoopPreds = false;
SmallVector<BlockT *, 2> OutsideLoopPreds;

typedef GraphTraits<BlockT*> BlockTraits;
for (typename BlockTraits::ChildIteratorType SI =
       BlockTraits::child_begin(BB), SE = BlockTraits::child_end(BB);
     SI != SE; ++SI)
  if (contains(*SI)) {
    HasInsideLoopSuccs = true;
    break;
  }

您的内部for循环是:

for (j = 0; j < 5000; j = i+1) {
为了避免无限循环

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);
                    /*Then the code get crashed!*/
            }
        }
    }

IndependentUnroll() : llvm::LoopPass(IndependentUnroll::ID) { }

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

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

};
for (j = 0; j < 5000; j = i+1) {
j = j + 1