Skip to content

Commit 567962d

Browse files
committed
Add FFI bindings for Module::getInstructionCount()
Just to make it useable 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.
1 parent 8c7b921 commit 567962d

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/librustc_codegen_llvm/llvm/ffi.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1729,6 +1729,7 @@ extern "C" {
17291729
) -> LLVMRustResult;
17301730
pub fn LLVMRustSetLLVMOptions(Argc: c_int, Argv: *const *const c_char);
17311731
pub fn LLVMRustPrintPasses();
1732+
pub fn LLVMRustGetInstructionCount(M: &Module) -> u32;
17321733
pub fn LLVMRustSetNormalizedTarget(M: &Module, triple: *const c_char);
17331734
pub fn LLVMRustAddAlwaysInlinePass(P: &PassManagerBuilder, AddLifetimes: bool);
17341735
pub fn LLVMRustRunRestrictionPass(M: &Module, syms: *const *const c_char, len: size_t);

src/rustllvm/RustWrapper.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,14 @@ extern "C" char *LLVMRustGetLastError(void) {
8787
return Ret;
8888
}
8989

90+
extern "C" unsigned int LLVMRustGetInstructionCount(LLVMModuleRef M) {
91+
#if LLVM_VERSION_GE(7, 0)
92+
return unwrap(M)->getInstructionCount();
93+
#else
94+
report_fatal_error("Module::getInstructionCount not available before LLVM 7");
95+
#endif
96+
}
97+
9098
extern "C" void LLVMRustSetLastError(const char *Err) {
9199
free((void *)LastError);
92100
LastError = strdup(Err);

0 commit comments

Comments
 (0)