How to get the next immediate instruction for a given instruction?
Asked Answered
O

2

6

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.

Owenism answered 17/5, 2017 at 20:27 Comment(0)
O
9

It turned out to be as simple as this:

Instruction *instruction = cmpInst->getNextNode();
Owenism answered 17/5, 2017 at 21:19 Comment(0)
A
1

I agree with the previous answer cmpInst->getNextNode(), which appears in several projects I have seen.

However, according to another answer in link, the getNextNode() is an internal implementation details of stuff deep inside LLVM API. Thus, I prefer to using cmpInst->getNextNonDebugInstruction(), which could skip intrinsic instructions such as call void @llvm.dbg.declare(...).

Aeciospore answered 17/2, 2021 at 2:52 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.