%4 = icmp sgt i32 %2, %3
For the above instruction, how can I check whether the icmp instruction contains sgt or slt?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
A direct answer to your question is to place this code in a custom
FunctionPass:You seem to be asking a lot of similar questions lately, so I want to give a more general piece of advice.
Each instruction you see in LLVM IR is just a textual representation of an instruction class that exists in the LLVM code base. In this case
icmprepresentsICmpInst, which is a subclass ofCmpInst. Once you know you’re dealing withCmpInst, it’s easy to see how to access its attributes just by reading the class declaration in the header file. For instance, it’s obvious that the “predicate” parameter of this instruction represents thatsgtand other predicates.But how do you know which class to look at. This is easily done with the LLVM C++ backend which dumps the equivalent C++ code needed to build some IR. For instance, given this piece of IR:
It will dump:
So you know just from looking at it that you need
ICmpInst, and also that the predicate isICMP_SGT.To run the C++ backend on some textual IR in a
.llfile you just do:Hope this helps!