Skip to content

Commit 158d454

Browse files
committed
addressing feedback
1 parent ced443a commit 158d454

File tree

4 files changed

+23
-40
lines changed

4 files changed

+23
-40
lines changed

Diff for: compiler/rustc_codegen_llvm/src/builder.rs

+15-15
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,21 @@ impl Drop for SBuilder<'_, '_> {
5252
}
5353
}
5454

55+
// All Builders must have an llfn associated with them
56+
#[must_use]
57+
pub(crate) struct Builder<'a, 'll, 'tcx> {
58+
pub llbuilder: &'ll mut llvm::Builder<'ll>,
59+
pub cx: &'a CodegenCx<'ll, 'tcx>,
60+
}
61+
62+
impl Drop for Builder<'_, '_, '_> {
63+
fn drop(&mut self) {
64+
unsafe {
65+
llvm::LLVMDisposeBuilder(&mut *(self.llbuilder as *mut _));
66+
}
67+
}
68+
}
69+
5570
impl<'a, 'll> SBuilder<'a, 'll> {
5671
fn build(cx: &'a SimpleCx<'ll>, llbb: &'ll BasicBlock) -> SBuilder<'a, 'll> {
5772
let bx = SBuilder::with_scx(cx);
@@ -160,21 +175,6 @@ impl<'a, 'll> SBuilder<'a, 'll> {
160175
}
161176
}
162177

163-
// All Builders must have an llfn associated with them
164-
#[must_use]
165-
pub(crate) struct Builder<'a, 'll, 'tcx> {
166-
pub llbuilder: &'ll mut llvm::Builder<'ll>,
167-
pub cx: &'a CodegenCx<'ll, 'tcx>,
168-
}
169-
170-
impl Drop for Builder<'_, '_, '_> {
171-
fn drop(&mut self) {
172-
unsafe {
173-
llvm::LLVMDisposeBuilder(&mut *(self.llbuilder as *mut _));
174-
}
175-
}
176-
}
177-
178178
/// Empty string, to be used where LLVM expects an instruction name, indicating
179179
/// that the instruction is to be left unnamed (i.e. numbered, in textual IR).
180180
// FIXME(eddyb) pass `&CStr` directly to FFI once it's a thin pointer.

Diff for: compiler/rustc_codegen_llvm/src/context.rs

-10
Original file line numberDiff line numberDiff line change
@@ -620,16 +620,6 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
620620
}
621621
}
622622
impl<'ll> SimpleCx<'ll> {
623-
pub(crate) fn func_params_types(&self, ty: &'ll Type) -> Vec<&'ll Type> {
624-
unsafe {
625-
let n_args = llvm::LLVMCountParamTypes(ty) as usize;
626-
let mut args = Vec::with_capacity(n_args);
627-
llvm::LLVMGetParamTypes(ty, args.as_mut_ptr());
628-
args.set_len(n_args);
629-
args
630-
}
631-
}
632-
633623
pub(crate) fn val_ty(&self, v: &'ll Value) -> &'ll Type {
634624
common::val_ty(v)
635625
}

Diff for: compiler/rustc_codegen_llvm/src/declare.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub(crate) fn declare_simple_fn<'ll>(
4040
visibility: llvm::Visibility,
4141
ty: &'ll Type,
4242
) -> &'ll Value {
43-
debug!("declare_raw_fn(name={:?}, ty={:?})", name, ty);
43+
debug!("declare_simple_fn(name={:?}, ty={:?})", name, ty);
4444
let llfn = unsafe {
4545
llvm::LLVMRustGetOrInsertFunction(cx.llmod, name.as_c_char_ptr(), name.len(), ty)
4646
};
@@ -65,13 +65,7 @@ pub(crate) fn declare_raw_fn<'ll, 'tcx>(
6565
ty: &'ll Type,
6666
) -> &'ll Value {
6767
debug!("declare_raw_fn(name={:?}, ty={:?})", name, ty);
68-
let llfn = unsafe {
69-
llvm::LLVMRustGetOrInsertFunction(cx.llmod, name.as_c_char_ptr(), name.len(), ty)
70-
};
71-
72-
llvm::SetFunctionCallConv(llfn, callconv);
73-
llvm::SetUnnamedAddress(llfn, unnamed);
74-
llvm::set_visibility(llfn, visibility);
68+
let llfn = declare_simple_fn(cx, name, callconv, unnamed, visibility, ty);
7569

7670
let mut attrs = SmallVec::<[_; 4]>::new();
7771

Diff for: compiler/rustc_codegen_llvm/src/type_.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ impl fmt::Debug for Type {
3535
}
3636
}
3737

38-
impl<'ll> CodegenCx<'ll, '_> {
38+
impl<'ll> CodegenCx<'ll, '_> {}
39+
impl<'ll> SimpleCx<'ll> {
3940
pub(crate) fn type_named_struct(&self, name: &str) -> &'ll Type {
4041
let name = SmallCStr::new(name);
4142
unsafe { llvm::LLVMStructCreateNamed(self.llcx, name.as_ptr()) }
@@ -44,13 +45,9 @@ impl<'ll> CodegenCx<'ll, '_> {
4445
pub(crate) fn set_struct_body(&self, ty: &'ll Type, els: &[&'ll Type], packed: bool) {
4546
unsafe { llvm::LLVMStructSetBody(ty, els.as_ptr(), els.len() as c_uint, packed as Bool) }
4647
}
47-
}
48-
impl<'ll> SimpleCx<'ll> {
4948
pub(crate) fn type_void(&self) -> &'ll Type {
5049
unsafe { llvm::LLVMVoidTypeInContext(self.llcx) }
5150
}
52-
}
53-
impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
5451
pub(crate) fn type_token(&self) -> &'ll Type {
5552
unsafe { llvm::LLVMTokenTypeInContext(self.llcx) }
5653
}
@@ -77,7 +74,8 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
7774
args
7875
}
7976
}
80-
77+
}
78+
impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
8179
pub(crate) fn type_bool(&self) -> &'ll Type {
8280
self.type_i8()
8381
}
@@ -122,7 +120,8 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
122120
assert_eq!(size % unit_size, 0);
123121
self.type_array(self.type_from_integer(unit), size / unit_size)
124122
}
125-
123+
}
124+
impl<'ll> SimpleCx<'ll> {
126125
pub(crate) fn type_variadic_func(&self, args: &[&'ll Type], ret: &'ll Type) -> &'ll Type {
127126
unsafe { llvm::LLVMFunctionType(ret, args.as_ptr(), args.len() as c_uint, True) }
128127
}

0 commit comments

Comments
 (0)