Skip to content

Commit dd7a81d

Browse files
committed
Let llsize_of be a ConstantInt
1 parent dd41f04 commit dd7a81d

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

src/librustc/middle/trans/machine.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -126,17 +126,16 @@ pub fn llbitsize_of_real(cx: @crate_ctxt, t: TypeRef) -> uint {
126126
}
127127
}
128128

129-
// Returns the "default" size of t, which is calculated by casting null to a
130-
// *T and then doing gep(1) on it and measuring the result. Really, look in
131-
// the LLVM sources. It does that. So this is likely similar to the ABI size
132-
// (i.e. including alignment-padding), but goodness knows which alignment it
133-
// winds up using. Probably the ABI one? Not recommended.
129+
/// Returns the size of the type as an LLVM constant integer value.
134130
pub fn llsize_of(cx: @crate_ctxt, t: TypeRef) -> ValueRef {
135-
unsafe {
136-
return llvm::LLVMConstIntCast(lib::llvm::llvm::LLVMSizeOf(t),
137-
cx.int_type,
138-
False);
139-
}
131+
// Once upon a time, this called LLVMSizeOf, which does a
132+
// getelementptr(1) on a null pointer and casts to an int, in
133+
// order to obtain the type size as a value without requiring the
134+
// target data layout. But we have the target data layout, so
135+
// there's no need for that contrivance. The instruction
136+
// selection DAG generator would flatten that GEP(1) node into a
137+
// constant of the type's alloc size, so let's save it some work.
138+
return C_uint(cx, llsize_of_alloc(cx, t));
140139
}
141140

142141
// Returns the "default" size of t (see above), or 1 if the size would

0 commit comments

Comments
 (0)