From: Alkis Evlogimenos
BasicBlock *pb = ...;+
Instruction *pi = ...;
Instruction *newInst = new Instruction(...);
pb->getInstList().insert(pi, newInst); // inserts newInst before pi in pb
BasicBlock *pb = ...;+ +
Instruction *pi = ...;
Instruction *newInst = new Instruction(...);
pb->getInstList().insert(pi, newInst); // inserts newInst before pi in pb
Appending to the end of a BasicBlock is so common that + the Instruction class and Instruction-derived + classes provide constructors which take a pointer to a + BasicBlock to be appended to. For example code that + looked like:
+ +BasicBlock *pb = ...;+ +
Instruction *newInst = new Instruction(...);
pb->getInstList().push_back(newInst); // appends newInst to pb
becomes:
+ +BasicBlock *pb = ...;+ +
Instruction *newInst = new Instruction(..., pb);
which is much cleaner, especially if you are creating + long instruction streams.