Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the next immediate instruction for a given instruction?

Tags:

llvm

llvm-ir

I am looking for a right way to get a next immediate instruction that follows a given instruction.

Let's assume that I have the following:

%10 = icmp slt i32 %8, %9
br i1 %10, label %11, label %17

I have a

  CmpInst *cmpInst = dyn_cast<CmpInst>(&V);

which corresponds to %10.

How do I get an access to the BranchInst that follows my CmpInst?

I assume that a solution should take both cases into account: when there is a next instruction and when there is no one i.e. it is the end of a BasicBlock.

like image 471
Stanislav Pankevich Avatar asked Mar 10 '23 01:03

Stanislav Pankevich


1 Answers

It turned out to be as simple as this:

Instruction *instruction = cmpInst->getNextNode();
like image 130
Stanislav Pankevich Avatar answered Apr 29 '23 16:04

Stanislav Pankevich