How to insert a operation in a expected place

Hi I would like to insert a op in front of listed op, so I do this

OpBuilder b;
...//Some code
auto ins_point = b.saveInsertionPoint();

What I expect is that op2 is in front of op1, however, it does not work.

The actual situation is more complicated, there can be multiple ops inserted in the middle and in different functions(recursive decent). And one of the specific op need to count the number of ops in between, and set up front of them.

Thus may I ask if it is possible to dealt with??

Thanks a lot!!!

I answered in the other thread you started, there is no need to create a duplicate. Insertion point identifies an op before which to insert new ops and doesn’t change when you create ops. So your saving and restoring does nothing.

1 Like