tejas tejas - 8 days ago 4x
C++ Question

How to check if the llvm callInst contains a bitcast?

My llvm ir looks something like this :

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)

I want to check if the call is an actual function call or the one with the bitcast. Does anyone know how to do this ?

I tried :

const CallInst *pInstCall = dyn_cast<CallInst>(&*it);
if (!pInstCall) continue;
dyn_cast<BitCastInst >(pInstCall->getCalledFunction());

But that doesn't seem to work.


You're looking for

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