Re ducing LLVM's memory usage

Hi,

I am working on a binary translator and use LLVM for this.
In the process, I generate millions of constants (immediate values in the
source binary code).
The problem is that these constants seem to be not cleaned when I delete the
LLVM code (using Function::deleteBody() ) and as a result the memory usage
keeps growing. I browsed the forum and found that constants "live forever"
by design.

Is there are simple way of cleaning the used memory without destroying
everything (unloading the ExecutionEngine, freeing the module, calling
llvm_shutdown) ? Ideally I would like something which brings everything to
the state just after I created the JIT engine for the first time.

Thanks,
Vitaly C.

Hi Vitaly,

Vitaly C. wrote:

Hi,

I am working on a binary translator and use LLVM for this.
In the process, I generate millions of constants (immediate values in the
source binary code).
The problem is that these constants seem to be not cleaned when I delete the
LLVM code (using Function::deleteBody() ) and as a result the memory usage
keeps growing. I browsed the forum and found that constants "live forever"
by design.
  
Right.

Is there are simple way of cleaning the used memory without destroying
everything (unloading the ExecutionEngine, freeing the module, calling
llvm_shutdown) ? Ideally I would like something which brings everything to
the state just after I created the JIT engine for the first time.

+1 :slight_smile: Being on the JIT side also, that would be a great feature. I know there is a plan to support parallel compilation between LLVM modules, and this may involve a self-sufficient module (ie constants, types will be deleted at deletion of the module), but I don't know what's the status of the project.

Nicolas

Hi

Vitaly C. wrote:

Is there are simple way of cleaning the used memory without destroying
everything (unloading the ExecutionEngine, freeing the module, calling
llvm_shutdown) ? Ideally I would like something which brings everything to
the state just after I created the JIT engine for the first time.

I've tried to run the Fibonacci example with Valgrind after having added
delete EE and llvm_shutdown in the main of fibonacci.cpp. Unfortunately, it
gives me a lot of definitely lost blocks.
I also have similar problems with my own code: there is a lot of lost
ConstantInts. From what I saw in the LLVM code, constants are put in a
statically managed structure which is supposed to be cleaned at shutdown.

Vitaly C.

Is there are simple way of cleaning the used memory without destroying
everything (unloading the ExecutionEngine, freeing the module, calling
llvm_shutdown) ? Ideally I would like something which brings everything to
the state just after I created the JIT engine for the first time.

I've tried to run the Fibonacci example with Valgrind after having added
delete EE and llvm_shutdown in the main of fibonacci.cpp. Unfortunately, it
gives me a lot of definitely lost blocks.
I also have similar problems with my own code: there is a lot of lost
ConstantInts. From what I saw in the LLVM code, constants are put in a
statically managed structure which is supposed to be cleaned at shutdown.

The leakage of Constant* is a known issue.
In attach I send a fairly complete suppression file for valgrind (use with --suppressions=valgrind.supp) that will suppress the known problems from the report.

Nuno

valgrind.supp (1.9 KB)