Question

How do I get the whole name of an operator in LLVM?

I'm iterating through blocks, and then, in each of their instructions, I try to get the operator name, but I do only get a part of it. Running the following code:

virtual bool runOnBasicBlock(BasicBlock &bb) {
    for (auto it(bb.begin()); it != bb.end(); ++it) {
        errs() << it->getName() << '\t' << *it << '\n';
    }
}

I get output lines like:

icmp        %cmp = icmp slt i32 %i.0, %argc
icmp        %cmp1 = icmp sgt i32 %call, %max.0
add       %inc = add nsw i32 %i.0, 1

I'd like to get icmp slt, icmp sgt, and add nsw, instead of icmp and add.

Était-ce utile?

La solution

Well, slt, sgt and others for icmp are just arguments. You can access them with getPredicate (a method of CmpInst). Also see the useful function getPredicateText in lib/IR/AsmWriter.cpp.

For stuff like nsw, check out the method hasNoSignedWrap and similar methods.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top