在 LLVM 中检测整数比较条件

Detecting Integer Comparison conditional in LLVM

#include <stdio.h>
#include <string.h>

int main (){
    unsigned short int a = 10;
    if (a == 10){
     //something
    }
}

在 LLVM pass 中,我如何检测 2 个操作数整数比较条件语句,如上所示:(a == 10)?请让我知道我应该在 LLVM api.

中寻找什么

你有一个ICmpInst,它的操作数是整数。由于两个操作数必须具有相同的类型,isa<ICmpInst>(foo) && isa<IntegerType>(foo->getOperand(0)) 足以识别特定指令是否是您要检测的类型。