llvm - Remove Successors for each BB -


i need remove successors every basic block insert new ones

i tried code, doesn't work

void removesuccessor(terminatorinst *ti, unsigned succnum) {     assert(succnum < ti->getnumsuccessors() &&             "trying remove nonexistant successor!");      // if our old successor block contains phi nodes, remove entry in     // phi nodes comes branch...     //     basicblock *bb = ti->getparent();     ti->getsuccessor(succnum)->removepredecessor(bb);      terminatorinst *newti = 0;     switch (ti->getopcode()) {         case instruction::br:             // if conditional branch... convert unconditional branch.             if (ti->getnumsuccessors() == 2) {                 cast<branchinst>(ti)->setunconditionaldest(ti->getsuccessor(1-succnum));             } else {                    // otherwise convert return instruction...                 value *retval = 0;                  // create value return... if function doesn't return null...                 if (!(bb->getparent()->getreturntype())->isvoidty())                     retval = constant::getnullvalue(bb->getparent()->getreturntype());                 // create return...                 newti = 0;             }             break;          case instruction::invoke:    // should convert call         case instruction::switch:    // should remove entry         default:         case instruction::ret:       // cannot happen, has no successors!             assert(0 && "unhandled terminator instruction type in removesuccessor!");             abort();     }      if (newti)   // if it's different instruction, replace.         replaceinstwithinst(ti, newti); } 

example of results:

if.then:                                          ; preds = %for.inc, %entry, %for.body 

preds should not include %for.body according remove successors of %for.body before inserting new successors

beyond comment above asking clarifications, line seems fishy:

cast<branchinst>(ti)->setunconditionaldest(ti->getsuccessor(1-succnum)); 

from know setunconditionaldest() method have been removed years ago, version using? in case, recommend creating new unconditional branchinst, using replaceinstwithinst() replace conditional one.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -