1
Fork 0

Rollup merge of #65720 - icefoxen:LLVMgetInstructionCount, r=rkruppe

Add FFI bindings for LLVM's Module::getInstructionCount()

Just to make it usable for profiling and such inside
rustc itself.  It was vaguely useful in
https://wiki.alopex.li/WhereRustcSpendsItsTime and I figured
I might as well upstream it; I may or may not ever get around
to doing more with it (hopefully I will), but it may be useful
for others.
This commit is contained in:
Pietro Albini 2019-11-05 09:49:50 +01:00 committed by GitHub
commit 7976d5720a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 0 deletions

View file

@ -1729,6 +1729,7 @@ extern "C" {
) -> LLVMRustResult;
pub fn LLVMRustSetLLVMOptions(Argc: c_int, Argv: *const *const c_char);
pub fn LLVMRustPrintPasses();
pub fn LLVMRustGetInstructionCount(M: &Module) -> u32;
pub fn LLVMRustSetNormalizedTarget(M: &Module, triple: *const c_char);
pub fn LLVMRustAddAlwaysInlinePass(P: &PassManagerBuilder, AddLifetimes: bool);
pub fn LLVMRustRunRestrictionPass(M: &Module, syms: *const *const c_char, len: size_t);

View file

@ -87,6 +87,14 @@ extern "C" char *LLVMRustGetLastError(void) {
return Ret;
}
extern "C" unsigned int LLVMRustGetInstructionCount(LLVMModuleRef M) {
#if LLVM_VERSION_GE(7, 0)
return unwrap(M)->getInstructionCount();
#else
report_fatal_error("Module::getInstructionCount not available before LLVM 7");
#endif
}
extern "C" void LLVMRustSetLastError(const char *Err) {
free((void *)LastError);
LastError = strdup(Err);