如何检查 llvm callInst 是否包含位广播?

voi*_*urn 1 c++ llvm llvm-ir

我的 llvm ir 看起来像这样:

call void bitcast (void (%struct.type1*, %opencl.image2d_t addrspace(1)*, i32, %struct.type1*)* @_Z36functype1 to void (%struct.type2*, %opencl.image2d_t addrspace(1)*, i32, %struct.type1*)*)(%struct.type2* sret %19, %opencl.image2d_t addrspace(1)* %237, i32 %238, %struct.type1* byval %sic_payload)
Run Code Online (Sandbox Code Playgroud)

我想检查该调用是实际的函数调用还是带有位广播的调用。有谁知道如何做到这一点 ?

我试过 :

const CallInst *pInstCall = dyn_cast<CallInst>(&*it);
if (!pInstCall) continue;
dyn_cast<BitCastInst >(pInstCall->getCalledFunction());
Run Code Online (Sandbox Code Playgroud)

但这似乎不起作用。

Jok*_*oky 5

您正在寻找

if (auto *CstExpr = dyn_cast<ConstantExpr>(it->getOperand(0))) {
  // BitCastInst is an *Instrution*, here you have a *ConstantExpr* Bitcast
  if (CstExpr.isCast()) {
     // do something...
  }
}
Run Code Online (Sandbox Code Playgroud)