revit
revit

Reputation: 411

Find out Function type in llvm

I am iterating over the Module's function lists as shown below. I am seeking for a way to find out if a Function *f is a declaration or a definition. (By dumping the function it seems that the list contains the two types.)

for (Module::iterator f = M->begin(), fend = M->end(); f != fend; ++f) {
  ...
}

Upvotes: 3

Views: 1729

Answers (1)

dejvuth
dejvuth

Reputation: 7146

From the Function manual:

If the BasicBlock list is empty, this indicates that the Function is actually a function declaration: the actual body of the function hasn’t been linked in yet.

and in the next section on Important Public Members of the Function, you'll find the function you want:

bool isDeclaration()

Return whether or not the Function has a body defined. If the function is “external”, it does not have a body, and thus must be resolved by linking with a function defined in a different translation unit.

which does the emptiness check for you.

Upvotes: 4

Related Questions