Search code examples
llvmllvm-clangllvm-gccllvm-c++-api

llvm - write a pass that checks if a function is present in a file


What I'm trying to achieve here is simple. I need my pass to go through the functions in a file (and hence, FunctionPass) and check if one of them is the one I'm looking for. I want to achieve this in a clean, simple way.

So far, I'm extracting the following info from the functions in the file I'm running the pass over:

  • Name
  • Return Type
  • Number + type of arguments

I already have this info for the function I'm looking for and I've thought about comparing this info with the one extracted to see if there's a match.

But is there a better way of doing this?


Solution

  • You can try Module->getFunction(StringRef name) if you have the name of the function in modulePass.
    see: llvm::Module Class Reference