Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upFix the representation of C void pointers in LLVM IR #11539
Conversation
This comment has been minimized.
This comment has been minimized.
|
Could you post some before/after code of what this change in types enables? It's also probably worth adding to the comment on the definition of |
This comment has been minimized.
This comment has been minimized.
|
Test code: fn main() {
let x = ~3;
}Compile with define internal void @main::hd4b0664c300788adah::v0.0({ i64, %tydesc*, i8*, i8*, i8 }* nocapture readnone) unnamed_addr #0 {
"function top level":
%1 = tail call %"enum.std::libc::types::common::c95::c_void[#1]"* @malloc(i64 8)
%2 = icmp eq %"enum.std::libc::types::common::c95::c_void[#1]"* %1, null
br i1 %2, label %_ZN2rt11global_heap10malloc_raw19h000735e5ce40b7f3aR4v0.9E.exit.thread, label %cond.i
_ZN2rt11global_heap10malloc_raw19h000735e5ce40b7f3aR4v0.9E.exit.thread: ; preds = %"function top level"
tail call void @abort()
call void @llvm.trap()
unreachable
cond.i: ; preds = %"function top level"
%3 = bitcast %"enum.std::libc::types::common::c95::c_void[#1]"* %1 to i64*
store i64 3, i64* %3, align 8
tail call void @free(%"enum.std::libc::types::common::c95::c_void[#1]"* %1) #1
ret void
}After: define internal void @main::hd4b0664c300788adah::v0.0({ i64, %tydesc*, i8*, i8*, i8 }* nocapture readnone) unnamed_addr #0 {
"_ZN13_$UP$$LP$$RP$9glue_drop19h82dc7f896d315c35a8E.exit":
ret void
} |
This comment has been minimized.
This comment has been minimized.
|
Before:
After:
|
This comment has been minimized.
This comment has been minimized.
|
I played around a bit, and I think we can get the same optimization with #[repr(u8)]
pub enum c_void {
priv variant1,
priv variant2,
}In order for |
This comment has been minimized.
This comment has been minimized.
|
The test suite isn't built with LTO. With LTO we get: Before:
After:
The "before" numbers are probably faster than before, because I copied the benchmarks into their own file and we still get better inlining behaviour when there is only one user of a function. |
This comment has been minimized.
This comment has been minimized.
alexcrichton
commented on 5902263
Jan 14, 2014
|
r+, thanks! |
This comment has been minimized.
This comment has been minimized.
|
saw approval from alexcrichton |
This comment has been minimized.
This comment has been minimized.
|
merging dotdash/rust/void_type_fixup = 5902263 into auto |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
fast-forwarding master to auto = b77a7e7 |
dotdash commentedJan 14, 2014
Currently, we have c_void defined to be represented as an empty struct,
but LLVM expects C's void* to be represented as i8*. That means we
currently generate code in which LLVM doesn't recognize malloc() and
free() and can't apply certain optimization that would remove calls to
those functions.