What would cause instructions to NOT make it into the module?

As i've been adding to my code generation phase, calling various LLVM APIs, I often dump the module to see how things are progressing. Suddenly, somewhere I've made a change that keeps the code I'm generating from actually appearing in the module. What might cause that? I'm not tripping any asserts or getting other errors.

I can dump the individual instructions and they look good, but if I dump the module, I don't see any of them.

Any idea what's causing this?

Thanks!

Any idea what's causing this?

Try running the verifier pass (the one that is invoked by `opt -verify`).

-- Sean Silva

I'm not sure how to do this. I'm writing a Cocoa app that calls the LLVM API directly; I don't use any of the command-line tools. Is there a way to verify via API? I think I've actually done this for individual types, dunno about for a whole module.

It is a pass that can be run like any other pass. See createVerifierPass().

-- Sean Silva

From: llvmdev-bounces@cs.uiuc.edu [mailto:llvmdev-bounces@cs.uiuc.edu]
On Behalf Of Sean Silva
Subject: Re: [LLVMdev] What would cause instructions to NOT make it into the module?

It is a pass that can be run like any other pass. See createVerifierPass().

You can also just call verifyModule() with the appropriate parameters; it's defined in include/llvm/Analysis/Verifier.h.

- Chuck

THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.

Thank you. The modules verify fine, but at least one of my functions (I only tested one) does not, and generates this output:

Referencing function in another module!
  %0 = call i8* @malloc(i64 72)
Referencing function in another module!
  call void @decodeField(%struct.PDField* null, %struct.PDPacket* %3, void (%struct.PDField*, %struct.PDPacket*)* @packetMarker.completionProc, i8* null)

I have verified that I only ever call new llvm::Module() once, and I only use the globalLLVMContext, or that module's context. Is it possible some part of the API is creating a module for use internally?

When I dump my (only) module, it does show those two external functions declared:

declare i8* @malloc(i64)
declare void @decodeField(%struct.PDField*, %struct.PDPacket*, void (%struct.PDField*, %struct.PDPacket*)*, i8*)

But my module does NOT show the function I tried to verify (that generated the verification error above).

It turns out, many of the APIs will happily accept a NULL module. I tracked down where I was failing to pass the module to the classes that were calling LLVM. Now all is well again.

Thank you for the tip!