Skip to content

Commit d7a528c

Browse files
committed
Relax some more constraints
1 parent c45a9b9 commit d7a528c

File tree

6 files changed

+42
-37
lines changed

6 files changed

+42
-37
lines changed

src/librustc_codegen_llvm/builder.rs

+18-18
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,13 @@ impl MemoryBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
441441
}
442442
}
443443

444+
fn set_invariant_load(&mut self, load: &'ll Value) {
445+
unsafe {
446+
llvm::LLVMSetMetadata(load, llvm::MD_invariant_load as c_uint,
447+
llvm::LLVMMDNodeInContext(self.cx.llcx, ptr::null(), 0));
448+
}
449+
}
450+
444451
fn memcpy(&mut self, dst: &'ll Value, dst_align: Align,
445452
src: &'ll Value, src_align: Align,
446453
size: &'ll Value, flags: MemFlags) {
@@ -999,6 +1006,17 @@ impl NumBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
9991006
llvm::LLVMBuildFCmp(self.llbuilder, op as c_uint, lhs, rhs, noname())
10001007
}
10011008
}
1009+
1010+
fn select(
1011+
&mut self, cond: &'ll Value,
1012+
then_val: &'ll Value,
1013+
else_val: &'ll Value,
1014+
) -> &'ll Value {
1015+
self.count_insn("select");
1016+
unsafe {
1017+
llvm::LLVMBuildSelect(self.llbuilder, cond, then_val, else_val, noname())
1018+
}
1019+
}
10021020
}
10031021

10041022
impl UnwindBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
@@ -1125,17 +1143,6 @@ impl UnwindBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
11251143

11261144
impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
11271145
/* Miscellaneous instructions */
1128-
fn select(
1129-
&mut self, cond: &'ll Value,
1130-
then_val: &'ll Value,
1131-
else_val: &'ll Value,
1132-
) -> &'ll Value {
1133-
self.count_insn("select");
1134-
unsafe {
1135-
llvm::LLVMBuildSelect(self.llbuilder, cond, then_val, else_val, noname())
1136-
}
1137-
}
1138-
11391146
fn extract_element(&mut self, vec: &'ll Value, idx: &'ll Value) -> &'ll Value {
11401147
self.count_insn("extractelement");
11411148
unsafe {
@@ -1171,13 +1178,6 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
11711178
}
11721179
}
11731180

1174-
fn set_invariant_load(&mut self, load: &'ll Value) {
1175-
unsafe {
1176-
llvm::LLVMSetMetadata(load, llvm::MD_invariant_load as c_uint,
1177-
llvm::LLVMMDNodeInContext(self.cx.llcx, ptr::null(), 0));
1178-
}
1179-
}
1180-
11811181
fn lifetime_start(&mut self, ptr: &'ll Value, size: Size) {
11821182
self.call_lifetime_intrinsic("llvm.lifetime.start", ptr, size);
11831183
}

src/librustc_codegen_ssa/glue.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,14 @@ use crate::common::IntPredicate;
77
use crate::meth;
88
use crate::traits::*;
99

10-
pub fn size_and_align_of_dst<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
10+
pub fn size_and_align_of_dst<
11+
'a,
12+
'tcx: 'a,
13+
Bx: MemoryBuilderMethods<'tcx> + NumBuilderMethods<'tcx>,
14+
>(
1115
bx: &mut Bx,
1216
t: Ty<'tcx>,
13-
info: Option<Bx::Value>
17+
info: Option<Bx::Value>,
1418
) -> (Bx::Value, Bx::Value) {
1519
let layout = bx.layout_of(t);
1620
debug!("size_and_align_of_dst(ty={}, info={:?}): layout: {:?}",

src/librustc_codegen_ssa/meth.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ impl<'a, 'tcx: 'a> VirtualIndex {
1818
VirtualIndex(index as u64 + 3)
1919
}
2020

21-
pub fn get_fn<Bx: BuilderMethods<'a, 'tcx>>(
21+
pub fn get_fn<Bx: MemoryBuilderMethods<'tcx>>(
2222
self,
2323
bx: &mut Bx,
2424
llvtable: Bx::Value,
@@ -40,7 +40,7 @@ impl<'a, 'tcx: 'a> VirtualIndex {
4040
ptr
4141
}
4242

43-
pub fn get_usize<Bx: BuilderMethods<'a, 'tcx>>(
43+
pub fn get_usize<Bx: MemoryBuilderMethods<'tcx>>(
4444
self,
4545
bx: &mut Bx,
4646
llvtable: Bx::Value

src/librustc_codegen_ssa/mir/operand.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -261,39 +261,39 @@ impl<'a, 'tcx: 'a, V: CodegenObject> OperandRef<'tcx, V> {
261261
}
262262

263263
impl<'a, 'tcx: 'a, V: CodegenObject> OperandValue<V> {
264-
pub fn store<Bx: BuilderMethods<'a, 'tcx, Value = V>>(
264+
pub fn store<Bx: MemoryBuilderMethods<'tcx, Value = V> + NumBuilderMethods<'tcx>>(
265265
self,
266266
bx: &mut Bx,
267267
dest: PlaceRef<'tcx, V>
268268
) {
269269
self.store_with_flags(bx, dest, MemFlags::empty());
270270
}
271271

272-
pub fn volatile_store<Bx: BuilderMethods<'a, 'tcx, Value = V>>(
272+
pub fn volatile_store<Bx: MemoryBuilderMethods<'tcx, Value = V> + NumBuilderMethods<'tcx>>(
273273
self,
274274
bx: &mut Bx,
275275
dest: PlaceRef<'tcx, V>
276276
) {
277277
self.store_with_flags(bx, dest, MemFlags::VOLATILE);
278278
}
279279

280-
pub fn unaligned_volatile_store<Bx: BuilderMethods<'a, 'tcx, Value = V>>(
280+
pub fn unaligned_volatile_store<Bx: MemoryBuilderMethods<'tcx, Value = V> + NumBuilderMethods<'tcx>>(
281281
self,
282282
bx: &mut Bx,
283283
dest: PlaceRef<'tcx, V>,
284284
) {
285285
self.store_with_flags(bx, dest, MemFlags::VOLATILE | MemFlags::UNALIGNED);
286286
}
287287

288-
pub fn nontemporal_store<Bx: BuilderMethods<'a, 'tcx, Value = V>>(
288+
pub fn nontemporal_store<Bx: MemoryBuilderMethods<'tcx, Value = V> + NumBuilderMethods<'tcx>>(
289289
self,
290290
bx: &mut Bx,
291291
dest: PlaceRef<'tcx, V>
292292
) {
293293
self.store_with_flags(bx, dest, MemFlags::NONTEMPORAL);
294294
}
295295

296-
fn store_with_flags<Bx: BuilderMethods<'a, 'tcx, Value = V>>(
296+
fn store_with_flags<Bx: MemoryBuilderMethods<'tcx, Value = V> + NumBuilderMethods<'tcx>>(
297297
self,
298298
bx: &mut Bx,
299299
dest: PlaceRef<'tcx, V>,

src/librustc_codegen_ssa/mir/place.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ impl<'a, 'tcx: 'a, V: CodegenObject> PlaceRef<'tcx, V> {
100100

101101
impl<'a, 'tcx: 'a, V: CodegenObject> PlaceRef<'tcx, V> {
102102
/// Access a field, at a point when the value's case is known.
103-
pub fn project_field<Bx: BuilderMethods<'a, 'tcx, Value = V>>(
103+
pub fn project_field<Bx: MemoryBuilderMethods<'tcx, Value = V> + NumBuilderMethods<'tcx>>(
104104
self, bx: &mut Bx,
105105
ix: usize,
106106
) -> Self {

src/librustc_codegen_ssa/traits/builder.rs

+10-9
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,10 @@ pub trait MemoryBuilderMethods<'tcx>: HasCodegen<'tcx> {
8181
fn ptrtoint(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
8282
fn inttoptr(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
8383

84+
// Optimization metadata
8485
fn range_metadata(&mut self, load: Self::Value, range: Range<u128>);
8586
fn nonnull_metadata(&mut self, load: Self::Value);
87+
fn set_invariant_load(&mut self, load: Self::Value);
8688

8789
// Bulk memory operations
8890
fn memcpy(
@@ -205,6 +207,14 @@ pub trait NumBuilderMethods<'tcx>: HasCodegen<'tcx> {
205207
fn fptrunc(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
206208
fn fpext(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
207209
fn fcmp(&mut self, op: RealPredicate, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
210+
211+
/// This is not really only for numbers, but often used functions which also use numbers
212+
fn select(
213+
&mut self,
214+
cond: Self::Value,
215+
then_val: Self::Value,
216+
else_val: Self::Value,
217+
) -> Self::Value;
208218
}
209219

210220
pub trait UnwindBuilderMethods<'tcx>: HasCodegen<'tcx> {
@@ -255,20 +265,11 @@ pub trait BuilderMethods<'a, 'tcx: 'a>:
255265
+ NumBuilderMethods<'tcx>
256266
+ UnwindBuilderMethods<'tcx>
257267
{
258-
fn select(
259-
&mut self,
260-
cond: Self::Value,
261-
then_val: Self::Value,
262-
else_val: Self::Value,
263-
) -> Self::Value;
264-
265268
fn extract_element(&mut self, vec: Self::Value, idx: Self::Value) -> Self::Value;
266269
fn vector_splat(&mut self, num_elts: usize, elt: Self::Value) -> Self::Value;
267270
fn extract_value(&mut self, agg_val: Self::Value, idx: u64) -> Self::Value;
268271
fn insert_value(&mut self, agg_val: Self::Value, elt: Self::Value, idx: u64) -> Self::Value;
269272

270-
fn set_invariant_load(&mut self, load: Self::Value);
271-
272273
/// Called for `StorageLive`
273274
fn lifetime_start(&mut self, ptr: Self::Value, size: Size);
274275

0 commit comments

Comments
 (0)