Skip to content

Commit 9d0a506

Browse files
committed
All CommonMethods now real methods (not static)
1 parent d1ee489 commit 9d0a506

File tree

7 files changed

+31
-32
lines changed

7 files changed

+31
-32
lines changed

src/librustc_codegen_llvm/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1258,7 +1258,7 @@ fn compile_codegen_unit<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
12581258
if !cx.used_statics.borrow().is_empty() {
12591259
let name = const_cstr!("llvm.used");
12601260
let section = const_cstr!("llvm.metadata");
1261-
let array = CodegenCx::c_array(Type::i8(&cx).ptr_to(), &*cx.used_statics.borrow());
1261+
let array = cx.c_array(Type::i8(&cx).ptr_to(), &*cx.used_statics.borrow());
12621262

12631263
unsafe {
12641264
let g = llvm::LLVMAddGlobal(cx.llmod,

src/librustc_codegen_llvm/common.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -323,13 +323,13 @@ impl<'ll, 'tcx : 'll> CommonMethods for CodegenCx<'ll, 'tcx, &'ll Value> {
323323
&self.c_struct_in_context(&self.llcx, elts, packed)
324324
}
325325

326-
fn c_array(ty: &'ll Type, elts: &[&'ll Value]) -> &'ll Value {
326+
fn c_array(&self, ty: &'ll Type, elts: &[&'ll Value]) -> &'ll Value {
327327
unsafe {
328328
return llvm::LLVMConstArray(ty, elts.as_ptr(), elts.len() as c_uint);
329329
}
330330
}
331331

332-
fn c_vector(elts: &[&'ll Value]) -> &'ll Value {
332+
fn c_vector(&self, elts: &[&'ll Value]) -> &'ll Value {
333333
unsafe {
334334
return llvm::LLVMConstVector(elts.as_ptr(), elts.len() as c_uint);
335335
}
@@ -339,7 +339,7 @@ impl<'ll, 'tcx : 'll> CommonMethods for CodegenCx<'ll, 'tcx, &'ll Value> {
339339
&self.c_bytes_in_context(&self.llcx, bytes)
340340
}
341341

342-
fn const_get_elt(v: &'ll Value, idx: u64) -> &'ll Value {
342+
fn const_get_elt(&self, v: &'ll Value, idx: u64) -> &'ll Value {
343343
unsafe {
344344
assert_eq!(idx as c_uint as u64, idx);
345345
let us = &[idx as c_uint];
@@ -352,9 +352,9 @@ impl<'ll, 'tcx : 'll> CommonMethods for CodegenCx<'ll, 'tcx, &'ll Value> {
352352
}
353353
}
354354

355-
fn const_get_real(v: &'ll Value) -> Option<(f64, bool)> {
355+
fn const_get_real(&self, v: &'ll Value) -> Option<(f64, bool)> {
356356
unsafe {
357-
if Self::is_const_real(v) {
357+
if self.is_const_real(v) {
358358
let mut loses_info: llvm::Bool = ::std::mem::uninitialized();
359359
let r = llvm::LLVMConstRealGetDouble(v, &mut loses_info);
360360
let loses_info = if loses_info == 1 { true } else { false };
@@ -365,27 +365,27 @@ impl<'ll, 'tcx : 'll> CommonMethods for CodegenCx<'ll, 'tcx, &'ll Value> {
365365
}
366366
}
367367

368-
fn const_to_uint(v: &'ll Value) -> u64 {
368+
fn const_to_uint(&self, v: &'ll Value) -> u64 {
369369
unsafe {
370370
llvm::LLVMConstIntGetZExtValue(v)
371371
}
372372
}
373373

374-
fn is_const_integral(v: &'ll Value) -> bool {
374+
fn is_const_integral(&self, v: &'ll Value) -> bool {
375375
unsafe {
376376
llvm::LLVMIsAConstantInt(v).is_some()
377377
}
378378
}
379379

380-
fn is_const_real(v: &'ll Value) -> bool {
380+
fn is_const_real(&self, v: &'ll Value) -> bool {
381381
unsafe {
382382
llvm::LLVMIsAConstantFP(v).is_some()
383383
}
384384
}
385385

386-
fn const_to_opt_u128(v: &'ll Value, sign_ext: bool) -> Option<u128> {
386+
fn const_to_opt_u128(&self, v: &'ll Value, sign_ext: bool) -> Option<u128> {
387387
unsafe {
388-
if Self::is_const_integral(v) {
388+
if self.is_const_integral(v) {
389389
let (mut lo, mut hi) = (0u64, 0u64);
390390
let success = llvm::LLVMRustConstInt128Get(v, sign_ext,
391391
&mut hi, &mut lo);

src/librustc_codegen_llvm/glue.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ pub fn size_and_align_of_dst(
3434
let (size, align) = bx.cx().size_and_align_of(t);
3535
debug!("size_and_align_of_dst t={} info={:?} size: {:?} align: {:?}",
3636
t, info, size, align);
37-
let size = CodegenCx::c_usize(bx.cx(), size.bytes());
38-
let align = CodegenCx::c_usize(bx.cx(), align.abi());
37+
let size = bx.cx().c_usize(size.bytes());
38+
let align = bx.cx().c_usize(align.abi());
3939
return (size, align);
4040
}
4141
match t.sty {
@@ -49,8 +49,8 @@ pub fn size_and_align_of_dst(
4949
// The info in this case is the length of the str, so the size is that
5050
// times the unit size.
5151
let (size, align) = bx.cx().size_and_align_of(unit);
52-
(bx.mul(info.unwrap(), CodegenCx::c_usize(bx.cx(), size.bytes())),
53-
CodegenCx::c_usize(bx.cx(), align.abi()))
52+
(bx.mul(info.unwrap(), bx.cx().c_usize(size.bytes())),
53+
bx.cx().c_usize(align.abi()))
5454
}
5555
_ => {
5656
let cx = bx.cx();
@@ -93,8 +93,8 @@ pub fn size_and_align_of_dst(
9393

9494
// Choose max of two known alignments (combined value must
9595
// be aligned according to more restrictive of the two).
96-
let align = match (CodegenCx::const_to_opt_u128(sized_align, false),
97-
CodegenCx::const_to_opt_u128(unsized_align, false)) {
96+
let align = match (bx.cx().const_to_opt_u128(sized_align, false),
97+
bx.cx().const_to_opt_u128(unsized_align, false)) {
9898
(Some(sized_align), Some(unsized_align)) => {
9999
// If both alignments are constant, (the sized_align should always be), then
100100
// pick the correct alignment statically.

src/librustc_codegen_llvm/interfaces/common.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,16 @@ pub trait CommonMethods : Backend + CommonWriteMethods {
4040
elts: &[Self::Value],
4141
packed: bool
4242
) -> Self::Value;
43-
fn c_array(ty: Self::Type, elts: &[Self::Value]) -> Self::Value;
44-
fn c_vector(elts: &[Self::Value]) -> Self::Value;
43+
fn c_array(&self, ty: Self::Type, elts: &[Self::Value]) -> Self::Value;
44+
fn c_vector(&self, elts: &[Self::Value]) -> Self::Value;
4545
fn c_bytes(&self, bytes: &[u8]) -> Self::Value;
4646

47-
fn const_get_elt(v: Self::Value, idx: u64) -> Self::Value;
48-
fn const_get_real(v: Self::Value) -> Option<(f64, bool)>;
49-
fn const_to_uint(v: Self::Value) -> u64;
50-
fn is_const_integral(v: Self::Value) -> bool;
51-
fn is_const_real(v: Self::Value) -> bool;
52-
fn const_to_opt_u128(v: Self::Value, sign_ext: bool) -> Option<u128>;
47+
fn const_get_elt(&self, v: Self::Value, idx: u64) -> Self::Value;
48+
fn const_get_real(&self, v: Self::Value) -> Option<(f64, bool)>;
49+
fn const_to_uint(&self, v: Self::Value) -> u64;
50+
fn is_const_integral(&self, v: Self::Value) -> bool;
51+
fn is_const_real(&self, v: Self::Value) -> bool;
52+
fn const_to_opt_u128(&self, v: Self::Value, sign_ext: bool) -> Option<u128>;
5353
}
5454

5555
pub trait CommonWriteMethods : Backend {

src/librustc_codegen_llvm/intrinsic.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,8 +1116,8 @@ fn generic_simd_intrinsic(
11161116
let indices: Option<Vec<_>> = (0..n)
11171117
.map(|i| {
11181118
let arg_idx = i;
1119-
let val = CodegenCx::const_get_elt(vector, i as u64);
1120-
match CodegenCx::const_to_opt_u128(val, true) {
1119+
let val = bx.cx().const_get_elt(vector, i as u64);
1120+
match bx.cx().const_to_opt_u128(val, true) {
11211121
None => {
11221122
emit_error!("shuffle index #{} is not a constant", arg_idx);
11231123
None
@@ -1138,7 +1138,7 @@ fn generic_simd_intrinsic(
11381138

11391139
return Ok(bx.shuffle_vector(args[0].immediate(),
11401140
args[1].immediate(),
1141-
CodegenCx::c_vector(&indices)))
1141+
bx.cx().c_vector(&indices)))
11421142
}
11431143

11441144
if name == "simd_insert" {
@@ -1564,7 +1564,7 @@ fn generic_simd_intrinsic(
15641564
// code is generated
15651565
// * if the accumulator of the fmul isn't 1, incorrect
15661566
// code is generated
1567-
match CodegenCx::const_get_real(acc) {
1567+
match bx.cx().const_get_real(acc) {
15681568
None => return_error!("accumulator of {} is not a constant", $name),
15691569
Some((v, loses_info)) => {
15701570
if $name.contains("mul") && v != 1.0_f64 {

src/librustc_codegen_llvm/mir/block.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ impl FunctionCx<'a, 'll, 'tcx, &'ll Value> {
324324

325325
mir::TerminatorKind::Assert { ref cond, expected, ref msg, target, cleanup } => {
326326
let cond = self.codegen_operand(&bx, cond).immediate();
327-
let mut const_cond = CodegenCx::const_to_opt_u128(cond, false).map(|c| c == 1);
327+
let mut const_cond = bx.cx().const_to_opt_u128(cond, false).map(|c| c == 1);
328328

329329
// This case can currently arise only from functions marked
330330
// with #[rustc_inherit_overflow_checks] and inlined from

src/librustc_codegen_llvm/mir/rvalue.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ use base;
2020
use builder::Builder;
2121
use callee;
2222
use common::{self, IntPredicate, RealPredicate};
23-
use context::CodegenCx;
2423
use consts;
2524
use monomorphize;
2625
use type_::Type;
@@ -110,7 +109,7 @@ impl FunctionCx<'a, 'll, 'tcx, &'ll Value> {
110109
let size = bx.cx().c_usize(dest.layout.size.bytes());
111110

112111
// Use llvm.memset.p0i8.* to initialize all zero arrays
113-
if CodegenCx::is_const_integral(v) && CodegenCx::const_to_uint(v) == 0 {
112+
if bx.cx().is_const_integral(v) && bx.cx().const_to_uint(v) == 0 {
114113
let fill = bx.cx().c_u8(0);
115114
base::call_memset(&bx, start, fill, size, align, false);
116115
return bx;

0 commit comments

Comments
 (0)