Skip to content

Commit b71c429

Browse files
committed
Remove type_variadic_func and typ_array from cg_ssa
1 parent 0e166bb commit b71c429

File tree

5 files changed

+80
-73
lines changed

5 files changed

+80
-73
lines changed

src/librustc_codegen_llvm/builder.rs

Lines changed: 51 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,37 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
652652
OperandRef { val, layout: place.layout }
653653
}
654654

655+
fn write_operand_repeatedly(
656+
mut self,
657+
cg_elem: OperandRef<'tcx, &'ll Value>,
658+
count: u64,
659+
dest: PlaceRef<'tcx, &'ll Value>,
660+
) -> Self {
661+
let zero = self.const_usize(0);
662+
let count = self.const_usize(count);
663+
let start = dest.project_index(&mut self, zero).llval;
664+
let end = dest.project_index(&mut self, count).llval;
665+
666+
let mut header_bx = self.build_sibling_block("repeat_loop_header");
667+
let mut body_bx = self.build_sibling_block("repeat_loop_body");
668+
let next_bx = self.build_sibling_block("repeat_loop_next");
669+
670+
self.br(header_bx.llbb());
671+
let current = header_bx.phi(self.val_ty(start), &[start], &[self.llbb()]);
672+
673+
let keep_going = header_bx.icmp(IntPredicate::IntNE, current, end);
674+
header_bx.cond_br(keep_going, body_bx.llbb(), next_bx.llbb());
655675

676+
let align = dest.align.restrict_for_offset(dest.layout.field(self.cx(), 0).size);
677+
cg_elem.val.store(&mut body_bx,
678+
PlaceRef::new_sized(current, cg_elem.layout, align));
679+
680+
let next = body_bx.inbounds_gep(current, &[self.const_usize(1)]);
681+
body_bx.br(header_bx.llbb());
682+
header_bx.add_incoming_to_phi(current, next, body_bx.llbb());
683+
684+
next_bx
685+
}
656686

657687
fn range_metadata(&mut self, load: &'ll Value, range: Range<u128>) {
658688
if self.sess().target.target.arch == "amdgpu" {
@@ -873,20 +903,6 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
873903
}
874904

875905
/* Miscellaneous instructions */
876-
fn phi(&mut self, ty: &'ll Type, vals: &[&'ll Value], bbs: &[&'ll BasicBlock]) -> &'ll Value {
877-
self.count_insn("addincoming");
878-
assert_eq!(vals.len(), bbs.len());
879-
let phi = unsafe {
880-
llvm::LLVMBuildPhi(self.llbuilder, ty, noname())
881-
};
882-
unsafe {
883-
llvm::LLVMAddIncoming(phi, vals.as_ptr(),
884-
bbs.as_ptr(),
885-
vals.len() as c_uint);
886-
phi
887-
}
888-
}
889-
890906
fn inline_asm_call(&mut self, asm: &CStr, cons: &CStr,
891907
inputs: &[&'ll Value], output: &'ll Type,
892908
volatile: bool, alignstack: bool,
@@ -1188,13 +1204,6 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
11881204
}
11891205
}
11901206

1191-
fn add_incoming_to_phi(&mut self, phi: &'ll Value, val: &'ll Value, bb: &'ll BasicBlock) {
1192-
self.count_insn("addincoming");
1193-
unsafe {
1194-
llvm::LLVMAddIncoming(phi, &val, &bb, 1 as c_uint);
1195-
}
1196-
}
1197-
11981207
fn set_invariant_load(&mut self, load: &'ll Value) {
11991208
unsafe {
12001209
llvm::LLVMSetMetadata(load, llvm::MD_invariant_load as c_uint,
@@ -1526,4 +1535,25 @@ impl Builder<'a, 'll, 'tcx> {
15261535
let ptr = self.pointercast(ptr, self.cx.type_i8p());
15271536
self.call(lifetime_intrinsic, &[self.cx.const_u64(size), ptr], None);
15281537
}
1538+
1539+
fn phi(&mut self, ty: &'ll Type, vals: &[&'ll Value], bbs: &[&'ll BasicBlock]) -> &'ll Value {
1540+
self.count_insn("addincoming");
1541+
assert_eq!(vals.len(), bbs.len());
1542+
let phi = unsafe {
1543+
llvm::LLVMBuildPhi(self.llbuilder, ty, noname())
1544+
};
1545+
unsafe {
1546+
llvm::LLVMAddIncoming(phi, vals.as_ptr(),
1547+
bbs.as_ptr(),
1548+
vals.len() as c_uint);
1549+
phi
1550+
}
1551+
}
1552+
1553+
fn add_incoming_to_phi(&mut self, phi: &'ll Value, val: &'ll Value, bb: &'ll BasicBlock) {
1554+
self.count_insn("addincoming");
1555+
unsafe {
1556+
llvm::LLVMAddIncoming(phi, &val, &bb, 1 as c_uint);
1557+
}
1558+
}
15291559
}

src/librustc_codegen_llvm/type_.rs

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,23 @@ impl CodegenCx<'ll, 'tcx> {
141141
assert_eq!(size % unit_size, 0);
142142
self.type_array(self.type_from_integer(unit), size / unit_size)
143143
}
144+
145+
crate fn type_variadic_func(
146+
&self,
147+
args: &[&'ll Type],
148+
ret: &'ll Type
149+
) -> &'ll Type {
150+
unsafe {
151+
llvm::LLVMFunctionType(ret, args.as_ptr(),
152+
args.len() as c_uint, True)
153+
}
154+
}
155+
156+
crate fn type_array(&self, ty: &'ll Type, len: u64) -> &'ll Type {
157+
unsafe {
158+
llvm::LLVMRustArrayType(ty, len)
159+
}
160+
}
144161
}
145162

146163
impl BaseTypeMethods<'tcx> for CodegenCx<'ll, 'tcx> {
@@ -208,17 +225,6 @@ impl BaseTypeMethods<'tcx> for CodegenCx<'ll, 'tcx> {
208225
}
209226
}
210227

211-
fn type_variadic_func(
212-
&self,
213-
args: &[&'ll Type],
214-
ret: &'ll Type
215-
) -> &'ll Type {
216-
unsafe {
217-
llvm::LLVMFunctionType(ret, args.as_ptr(),
218-
args.len() as c_uint, True)
219-
}
220-
}
221-
222228
fn type_struct(
223229
&self,
224230
els: &[&'ll Type],
@@ -231,13 +237,6 @@ impl BaseTypeMethods<'tcx> for CodegenCx<'ll, 'tcx> {
231237
}
232238
}
233239

234-
235-
fn type_array(&self, ty: &'ll Type, len: u64) -> &'ll Type {
236-
unsafe {
237-
llvm::LLVMRustArrayType(ty, len)
238-
}
239-
}
240-
241240
fn type_kind(&self, ty: &'ll Type) -> TypeKind {
242241
unsafe {
243242
llvm::LLVMRustGetTypeKind(ty).to_generic()

src/librustc_codegen_ssa/mir/rvalue.rs

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,11 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
8787
if dest.layout.is_zst() {
8888
return bx;
8989
}
90-
let zero = bx.cx().const_usize(0);
91-
let start = dest.project_index(&mut bx, zero).llval;
9290

9391
if let OperandValue::Immediate(v) = cg_elem.val {
94-
let size = bx.cx().const_usize(dest.layout.size.bytes());
92+
let zero = bx.const_usize(0);
93+
let start = dest.project_index(&mut bx, zero).llval;
94+
let size = bx.const_usize(dest.layout.size.bytes());
9595

9696
// Use llvm.memset.p0i8.* to initialize all zero arrays
9797
if bx.cx().is_const_integral(v) && bx.cx().const_to_uint(v) == 0 {
@@ -108,28 +108,7 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
108108
}
109109
}
110110

111-
let count = bx.cx().const_usize(count);
112-
let end = dest.project_index(&mut bx, count).llval;
113-
114-
let mut header_bx = bx.build_sibling_block("repeat_loop_header");
115-
let mut body_bx = bx.build_sibling_block("repeat_loop_body");
116-
let next_bx = bx.build_sibling_block("repeat_loop_next");
117-
118-
bx.br(header_bx.llbb());
119-
let current = header_bx.phi(bx.cx().val_ty(start), &[start], &[bx.llbb()]);
120-
121-
let keep_going = header_bx.icmp(IntPredicate::IntNE, current, end);
122-
header_bx.cond_br(keep_going, body_bx.llbb(), next_bx.llbb());
123-
124-
let align = dest.align.restrict_for_offset(dest.layout.field(bx.cx(), 0).size);
125-
cg_elem.val.store(&mut body_bx,
126-
PlaceRef::new_sized(current, cg_elem.layout, align));
127-
128-
let next = body_bx.inbounds_gep(current, &[bx.cx().const_usize(1)]);
129-
body_bx.br(header_bx.llbb());
130-
header_bx.add_incoming_to_phi(current, next, body_bx.llbb());
131-
132-
next_bx
111+
bx.write_operand_repeatedly(cg_elem, count, dest)
133112
}
134113

135114
mir::Rvalue::Aggregate(ref kind, ref operands) => {

src/librustc_codegen_ssa/traits/builder.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,14 @@ pub trait BuilderMethods<'a, 'tcx: 'a>:
116116
fn load_operand(&mut self, place: PlaceRef<'tcx, Self::Value>)
117117
-> OperandRef<'tcx, Self::Value>;
118118

119+
/// Called for Rvalue::Repeat when the elem is neither a ZST nor optimizable using memset.
120+
fn write_operand_repeatedly(
121+
self,
122+
elem: OperandRef<'tcx, Self::Value>,
123+
count: u64,
124+
dest: PlaceRef<'tcx, Self::Value>,
125+
) -> Self;
126+
119127
fn range_metadata(&mut self, load: Self::Value, range: Range<u128>);
120128
fn nonnull_metadata(&mut self, load: Self::Value);
121129

@@ -156,12 +164,6 @@ pub trait BuilderMethods<'a, 'tcx: 'a>:
156164
fn icmp(&mut self, op: IntPredicate, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
157165
fn fcmp(&mut self, op: RealPredicate, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
158166

159-
fn phi(
160-
&mut self,
161-
ty: Self::Type,
162-
vals: &[Self::Value],
163-
bbs: &[Self::BasicBlock],
164-
) -> Self::Value;
165167
fn inline_asm_call(
166168
&mut self,
167169
asm: &CStr,
@@ -255,7 +257,6 @@ pub trait BuilderMethods<'a, 'tcx: 'a>:
255257
) -> Self::Value;
256258
fn atomic_fence(&mut self, order: AtomicOrdering, scope: SynchronizationScope);
257259
fn add_case(&mut self, s: Self::Value, on_val: Self::Value, dest: Self::BasicBlock);
258-
fn add_incoming_to_phi(&mut self, phi: Self::Value, val: Self::Value, bb: Self::BasicBlock);
259260
fn set_invariant_load(&mut self, load: Self::Value);
260261

261262
/// Called for `StorageLive`

src/librustc_codegen_ssa/traits/type_.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ pub trait BaseTypeMethods<'tcx>: Backend<'tcx> {
2323
fn type_f64(&self) -> Self::Type;
2424

2525
fn type_func(&self, args: &[Self::Type], ret: Self::Type) -> Self::Type;
26-
fn type_variadic_func(&self, args: &[Self::Type], ret: Self::Type) -> Self::Type;
2726
fn type_struct(&self, els: &[Self::Type], packed: bool) -> Self::Type;
28-
fn type_array(&self, ty: Self::Type, len: u64) -> Self::Type;
2927
fn type_kind(&self, ty: Self::Type) -> TypeKind;
3028
fn type_ptr_to(&self, ty: Self::Type) -> Self::Type;
3129
fn element_type(&self, ty: Self::Type) -> Self::Type;

0 commit comments

Comments
 (0)