Skip to content

Commit 24e73b3

Browse files
committed
Rename pure flag to can_move
1 parent bebf726 commit 24e73b3

File tree

209 files changed

+867
-866
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

209 files changed

+867
-866
lines changed

cranelift/codegen/src/inst_predicates.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ fn has_side_effect(func: &Function, inst: Inst) -> bool {
4141
/// Does the given instruction behave as a "pure" node with respect to
4242
/// aegraph semantics?
4343
///
44-
/// - Actual pure nodes (arithmetic, etc)
45-
/// - Loads with the `readonly`, `notrap`, and `pure` flags set
44+
/// - Trivially pure nodes (bitwise arithmetic, etc)
45+
/// - Loads with the `readonly`, `notrap`, and `can_move` flags set
4646
pub fn is_pure_for_egraph(func: &Function, inst: Inst) -> bool {
47-
let is_readonly_load = match func.dfg.insts[inst] {
47+
let is_pure_load = match func.dfg.insts[inst] {
4848
InstructionData::Load {
4949
opcode: Opcode::Load,
5050
flags,
5151
..
52-
} => flags.readonly() && flags.notrap() && flags.pure(),
52+
} => flags.readonly() && flags.notrap() && flags.can_move(),
5353
_ => false,
5454
};
5555

@@ -65,7 +65,7 @@ pub fn is_pure_for_egraph(func: &Function, inst: Inst) -> bool {
6565

6666
let op = func.dfg.insts[inst].opcode();
6767

68-
has_one_result && (is_readonly_load || (!op.can_load() && !trivially_has_side_effects(op)))
68+
has_one_result && (is_pure_load || (!op.can_load() && !trivially_has_side_effects(op)))
6969
}
7070

7171
/// Can the given instruction be merged into another copy of itself?

cranelift/codegen/src/ir/memflags.rs

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ pub struct MemFlags {
7373
// * 4 - checked flag
7474
// * 5/6 - alias region
7575
// * 7/8/9/10/11/12/13/14 - trap code
76-
// * 15 - pure flag
76+
// * 15 - can_move flag
7777
//
7878
// Current properties upheld are:
7979
//
@@ -112,11 +112,12 @@ const ALIAS_REGION_OFFSET: u16 = 5;
112112
const MASK_TRAP_CODE: u16 = 0b1111_1111 << TRAP_CODE_OFFSET;
113113
const TRAP_CODE_OFFSET: u16 = 7;
114114

115-
/// Whether the load's/store's safety is purely a function of its data
116-
/// dependencies (i.e. operands) and is not guarded by
117-
/// outside-the-data-flow-graph properties, like implicit bounds-checking
115+
/// Whether this memory operation may be freely moved by the optimizer so long
116+
/// as its data dependencies are satisfied. That is, by setting this flag, the
117+
/// producer is guaranteeing that this memory operation's safety is not guarded
118+
/// by outside-the-data-flow-graph properties, like implicit bounds-checking
118119
/// control dependencies.
119-
const BIT_PURE: u16 = 1 << 15;
120+
const BIT_CAN_MOVE: u16 = 1 << 15;
120121

121122
impl MemFlags {
122123
/// Create a new empty set of flags.
@@ -204,7 +205,7 @@ impl MemFlags {
204205
self.with_alias_region(Some(AliasRegion::Vmctx))
205206
}
206207
"checked" => self.with_checked(),
207-
"pure" => self.with_pure(),
208+
"can_move" => self.with_can_move(),
208209

209210
other => match TrapCode::from_str(other) {
210211
Ok(code) => self.with_trap_code(Some(code)),
@@ -272,7 +273,7 @@ impl MemFlags {
272273
/// This flag does *not* mean that the associated instruction can be
273274
/// code-motioned to arbitrary places in the function so long as its data
274275
/// dependencies are met. This only means that, given its current location
275-
/// in the function, it will never trap. See the `pure` method for more
276+
/// in the function, it will never trap. See the `can_move` method for more
276277
/// details.
277278
pub const fn notrap(self) -> bool {
278279
self.trap_code().is_none()
@@ -289,8 +290,8 @@ impl MemFlags {
289290
self.with_trap_code(None)
290291
}
291292

292-
/// Is this memory operation's safety (e.g. the validity of its `notrap` and
293-
/// `readonly` claims) purely a function of its data dependencies?
293+
/// Is this memory operation safe to move so long as its data dependencies
294+
/// remain satisfied?
294295
///
295296
/// If this is `true`, then it is okay to code motion this instruction to
296297
/// arbitrary locations, in the function, including across blocks and
@@ -304,18 +305,18 @@ impl MemFlags {
304305
/// bounds check, which is not reflected in its operands, and it would be
305306
/// unsafe to code motion it above the bounds check, even if its data
306307
/// dependencies would still be satisfied.
307-
pub const fn pure(self) -> bool {
308-
self.read_bit(BIT_PURE)
308+
pub const fn can_move(self) -> bool {
309+
self.read_bit(BIT_CAN_MOVE)
309310
}
310311

311-
/// Set the `pure` flag.
312-
pub const fn set_pure(&mut self) {
313-
*self = self.with_pure();
312+
/// Set the `can_move` flag.
313+
pub const fn set_can_move(&mut self) {
314+
*self = self.with_can_move();
314315
}
315316

316-
/// Set the `pure` flag, returning new flags.
317-
pub const fn with_pure(self) -> Self {
318-
self.with_bit(BIT_PURE)
317+
/// Set the `can_move` flag, returning new flags.
318+
pub const fn with_can_move(self) -> Self {
319+
self.with_bit(BIT_CAN_MOVE)
319320
}
320321

321322
/// Test if the `aligned` flag is set.
@@ -424,8 +425,8 @@ impl fmt::Display for MemFlags {
424425
if self.readonly() {
425426
write!(f, " readonly")?;
426427
}
427-
if self.pure() {
428-
write!(f, " pure")?;
428+
if self.can_move() {
429+
write!(f, " can_move")?;
429430
}
430431
if self.read_bit(BIT_BIG_ENDIAN) {
431432
write!(f, " big")?;

cranelift/filetests/filetests/egraph/load-hoist.clif

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ test optimize
22
set opt_level=speed_and_size
33
target x86_64
44

5-
function %pure_hoists(i64 vmctx, i64, i32, i32) -> i32 fast {
5+
function %can_move_hoists(i64 vmctx, i64, i32, i32) -> i32 fast {
66
gv0 = vmctx
77
gv1 = load.i64 notrap aligned readonly gv0+8
88
gv2 = load.i64 notrap aligned gv1
@@ -15,7 +15,7 @@ function %pure_hoists(i64 vmctx, i64, i32, i32) -> i32 fast {
1515
jump block2(v5, v2, v3) ; v5 = 0
1616

1717
block2(v6: i32, v7: i32, v15: i32):
18-
v9 = load.i64 notrap aligned readonly pure v0+80
18+
v9 = load.i64 notrap aligned readonly can_move v0+80
1919
v8 = uextend.i64 v7
2020
v10 = iadd v9, v8
2121
v11 = load.i32 little heap v10
@@ -37,13 +37,13 @@ function %pure_hoists(i64 vmctx, i64, i32, i32) -> i32 fast {
3737
return v12
3838
}
3939

40-
; check: v9 = load.i64 notrap aligned readonly pure v0+80
40+
; check: v9 = load.i64 notrap aligned readonly can_move v0+80
4141
; check: block2(v6: i32, v7: i32, v15: i32):
4242
; check: v10 = iadd.i64 v9, v8
4343
; check: v11 = load.i32 little heap v10
4444
; check: brif v19, block2(v12, v21, v19), block4
4545

46-
function %non_pure_does_not_hoist(i64 vmctx, i64, i32, i32) -> i32 fast {
46+
function %non_can_move_does_not_hoist(i64 vmctx, i64, i32, i32) -> i32 fast {
4747
gv0 = vmctx
4848
gv1 = load.i64 notrap aligned readonly gv0+8
4949
gv2 = load.i64 notrap aligned gv1

crates/cranelift/src/func_environ.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ impl<'module_environment> FuncEnvironment<'module_environment> {
298298
base: vmctx,
299299
offset: Offset32::new(i32::try_from(from_offset).unwrap()),
300300
global_type: pointer_type,
301-
flags: MemFlags::trusted().with_readonly().with_pure(),
301+
flags: MemFlags::trusted().with_readonly().with_can_move(),
302302
});
303303
(global, 0)
304304
}
@@ -316,7 +316,7 @@ impl<'module_environment> FuncEnvironment<'module_environment> {
316316
debug_assert!(self.vmstore_context_ptr.is_reserved_value());
317317
self.vmstore_context_ptr = builder.ins().load(
318318
pointer_type,
319-
ir::MemFlags::trusted().with_readonly().with_pure(),
319+
ir::MemFlags::trusted().with_readonly().with_can_move(),
320320
base,
321321
offset,
322322
);
@@ -810,7 +810,7 @@ impl<'module_environment> FuncEnvironment<'module_environment> {
810810
base: vmctx,
811811
offset: Offset32::new(i32::try_from(from_offset).unwrap()),
812812
global_type: pointer_type,
813-
flags: MemFlags::trusted().with_readonly().with_pure(),
813+
flags: MemFlags::trusted().with_readonly().with_can_move(),
814814
});
815815
let base_offset = i32::from(self.offsets.vmtable_definition_base());
816816
let current_elements_offset =
@@ -834,7 +834,7 @@ impl<'module_environment> FuncEnvironment<'module_environment> {
834834
flags: if Some(table.limits.min) == table.limits.max {
835835
// A fixed-size table can't be resized so its base address won't
836836
// change.
837-
MemFlags::trusted().with_readonly().with_pure()
837+
MemFlags::trusted().with_readonly().with_can_move()
838838
} else {
839839
MemFlags::trusted()
840840
},
@@ -1021,7 +1021,7 @@ impl<'module_environment> FuncEnvironment<'module_environment> {
10211021
base: vmctx,
10221022
offset: Offset32::new(i32::try_from(offset).unwrap()),
10231023
global_type: self.pointer_type(),
1024-
flags: MemFlags::trusted().with_readonly().with_pure(),
1024+
flags: MemFlags::trusted().with_readonly().with_can_move(),
10251025
});
10261026

10271027
let mt = memtype.map(|mt| {
@@ -1155,7 +1155,7 @@ impl<'module_environment> FuncEnvironment<'module_environment> {
11551155
) -> ir::Value {
11561156
let vmctx = self.vmctx_val(pos);
11571157
let pointer_type = self.pointer_type();
1158-
let mem_flags = ir::MemFlags::trusted().with_readonly().with_pure();
1158+
let mem_flags = ir::MemFlags::trusted().with_readonly().with_can_move();
11591159

11601160
// Load the base pointer of the array of `VMSharedTypeIndex`es.
11611161
let shared_indices = pos.ins().load(
@@ -1272,7 +1272,7 @@ impl<'a, 'func, 'module_env> Call<'a, 'func, 'module_env> {
12721272
let vmctx = self.env.vmctx(self.builder.func);
12731273
let base = self.builder.ins().global_value(pointer_type, vmctx);
12741274

1275-
let mem_flags = ir::MemFlags::trusted().with_readonly().with_pure();
1275+
let mem_flags = ir::MemFlags::trusted().with_readonly().with_can_move();
12761276

12771277
// Load the callee address.
12781278
let body_offset = i32::try_from(
@@ -2277,7 +2277,7 @@ impl FuncEnvironment<'_> {
22772277
if global_ty.mutability {
22782278
ir::MemFlags::trusted()
22792279
} else {
2280-
ir::MemFlags::trusted().with_readonly().with_pure()
2280+
ir::MemFlags::trusted().with_readonly().with_can_move()
22812281
},
22822282
)
22832283
}
@@ -2480,7 +2480,7 @@ impl FuncEnvironment<'_> {
24802480
}
24812481
};
24822482

2483-
let mut flags = MemFlags::trusted().with_checked().with_pure();
2483+
let mut flags = MemFlags::trusted().with_checked().with_can_move();
24842484
if !memory.memory_may_move(self.tunables) {
24852485
flags.set_readonly();
24862486
}

crates/cranelift/src/gc/enabled.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,7 +1244,7 @@ impl FuncEnvironment<'_> {
12441244
/// Get the GC heap's base pointer.
12451245
fn get_gc_heap_base(&mut self, builder: &mut FunctionBuilder) -> ir::Value {
12461246
let ptr_ty = self.pointer_type();
1247-
let flags = ir::MemFlags::trusted().with_readonly().with_pure();
1247+
let flags = ir::MemFlags::trusted().with_readonly().with_can_move();
12481248

12491249
let vmctx = self.vmctx(builder.func);
12501250
let vmctx = builder.ins().global_value(ptr_ty, vmctx);
@@ -1258,7 +1258,7 @@ impl FuncEnvironment<'_> {
12581258
/// Get the GC heap's bound.
12591259
fn get_gc_heap_bound(&mut self, builder: &mut FunctionBuilder) -> ir::Value {
12601260
let ptr_ty = self.pointer_type();
1261-
let flags = ir::MemFlags::trusted().with_readonly().with_pure();
1261+
let flags = ir::MemFlags::trusted().with_readonly().with_can_move();
12621262

12631263
let vmctx = self.vmctx(builder.func);
12641264
let vmctx = builder.ins().global_value(ptr_ty, vmctx);

tests/disas/basic-wat-test.wat

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@
1515
;; gv2 = load.i64 notrap aligned gv1+16
1616
;; gv3 = vmctx
1717
;; gv4 = load.i64 notrap aligned gv3+96
18-
;; gv5 = load.i64 notrap aligned readonly pure checked gv3+88
18+
;; gv5 = load.i64 notrap aligned readonly can_move checked gv3+88
1919
;; stack_limit = gv2
2020
;;
2121
;; block0(v0: i64, v1: i64, v2: i32, v3: i32):
2222
;; @0021 v5 = uextend.i64 v2
23-
;; @0021 v6 = load.i64 notrap aligned readonly pure checked v0+88
23+
;; @0021 v6 = load.i64 notrap aligned readonly can_move checked v0+88
2424
;; @0021 v7 = iadd v6, v5
2525
;; @0021 v8 = load.i32 little heap v7
2626
;; @0026 v9 = uextend.i64 v3
27-
;; @0026 v10 = load.i64 notrap aligned readonly pure checked v0+88
27+
;; @0026 v10 = load.i64 notrap aligned readonly can_move checked v0+88
2828
;; @0026 v11 = iadd v10, v9
2929
;; @0026 v12 = load.i32 little heap v11
3030
;; @0029 v13 = iadd v8, v12

tests/disas/duplicate-loads-dynamic-memory.wat

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@
2828
;; gv2 = load.i64 notrap aligned gv1+16
2929
;; gv3 = vmctx
3030
;; gv4 = load.i64 notrap aligned gv3+96
31-
;; gv5 = load.i64 notrap aligned pure checked gv3+88
31+
;; gv5 = load.i64 notrap aligned can_move checked gv3+88
3232
;; stack_limit = gv2
3333
;;
3434
;; block0(v0: i64, v1: i64, v2: i32):
3535
;; @0057 v6 = load.i64 notrap aligned v0+96
36-
;; @0057 v8 = load.i64 notrap aligned pure checked v0+88
36+
;; @0057 v8 = load.i64 notrap aligned can_move checked v0+88
3737
;; @0057 v5 = uextend.i64 v2
3838
;; @0057 v7 = icmp ugt v5, v6
3939
;; @0057 v10 = iconst.i64 0
@@ -52,12 +52,12 @@
5252
;; gv2 = load.i64 notrap aligned gv1+16
5353
;; gv3 = vmctx
5454
;; gv4 = load.i64 notrap aligned gv3+96
55-
;; gv5 = load.i64 notrap aligned pure checked gv3+88
55+
;; gv5 = load.i64 notrap aligned can_move checked gv3+88
5656
;; stack_limit = gv2
5757
;;
5858
;; block0(v0: i64, v1: i64, v2: i32):
5959
;; @0064 v6 = load.i64 notrap aligned v0+96
60-
;; @0064 v8 = load.i64 notrap aligned pure checked v0+88
60+
;; @0064 v8 = load.i64 notrap aligned can_move checked v0+88
6161
;; @0064 v5 = uextend.i64 v2
6262
;; @0064 v7 = icmp ugt v5, v6
6363
;; @0064 v12 = iconst.i64 0

tests/disas/duplicate-loads-static-memory.wat

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@
2323
;; gv2 = load.i64 notrap aligned gv1+16
2424
;; gv3 = vmctx
2525
;; gv4 = load.i64 notrap aligned gv3+96
26-
;; gv5 = load.i64 notrap aligned readonly pure checked gv3+88
26+
;; gv5 = load.i64 notrap aligned readonly can_move checked gv3+88
2727
;; stack_limit = gv2
2828
;;
2929
;; block0(v0: i64, v1: i64, v2: i32):
30-
;; @0057 v6 = load.i64 notrap aligned readonly pure checked v0+88
30+
;; @0057 v6 = load.i64 notrap aligned readonly can_move checked v0+88
3131
;; @0057 v5 = uextend.i64 v2
3232
;; @0057 v7 = iadd v6, v5
3333
;; @0057 v8 = load.i32 little heap v7
@@ -43,11 +43,11 @@
4343
;; gv2 = load.i64 notrap aligned gv1+16
4444
;; gv3 = vmctx
4545
;; gv4 = load.i64 notrap aligned gv3+96
46-
;; gv5 = load.i64 notrap aligned readonly pure checked gv3+88
46+
;; gv5 = load.i64 notrap aligned readonly can_move checked gv3+88
4747
;; stack_limit = gv2
4848
;;
4949
;; block0(v0: i64, v1: i64, v2: i32):
50-
;; @0064 v6 = load.i64 notrap aligned readonly pure checked v0+88
50+
;; @0064 v6 = load.i64 notrap aligned readonly can_move checked v0+88
5151
;; @0064 v5 = uextend.i64 v2
5252
;; @0064 v7 = iadd v6, v5
5353
;; @0064 v8 = iconst.i64 1234

tests/disas/dynamic-memory-no-spectre-access-same-index-different-offsets.wat

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@
4141
;; gv2 = load.i64 notrap aligned gv1+16
4242
;; gv3 = vmctx
4343
;; gv4 = load.i64 notrap aligned gv3+96
44-
;; gv5 = load.i64 notrap aligned pure checked gv3+88
44+
;; gv5 = load.i64 notrap aligned can_move checked gv3+88
4545
;; stack_limit = gv2
4646
;;
4747
;; block0(v0: i64, v1: i64, v2: i32):
4848
;; @0047 v7 = load.i64 notrap aligned v0+96
4949
;; @0047 v6 = uextend.i64 v2
5050
;; @0047 v8 = icmp ugt v6, v7
5151
;; @0047 trapnz v8, heap_oob
52-
;; @0047 v9 = load.i64 notrap aligned pure checked v0+88
52+
;; @0047 v9 = load.i64 notrap aligned can_move checked v0+88
5353
;; @0047 v10 = iadd v9, v6
5454
;; @0047 v11 = load.i32 little heap v10
5555
;; @004c v17 = iconst.i64 4
@@ -74,15 +74,15 @@
7474
;; gv2 = load.i64 notrap aligned gv1+16
7575
;; gv3 = vmctx
7676
;; gv4 = load.i64 notrap aligned gv3+96
77-
;; gv5 = load.i64 notrap aligned pure checked gv3+88
77+
;; gv5 = load.i64 notrap aligned can_move checked gv3+88
7878
;; stack_limit = gv2
7979
;;
8080
;; block0(v0: i64, v1: i64, v2: i32, v3: i32, v4: i32, v5: i32):
8181
;; @005d v7 = load.i64 notrap aligned v0+96
8282
;; @005d v6 = uextend.i64 v2
8383
;; @005d v8 = icmp ugt v6, v7
8484
;; @005d trapnz v8, heap_oob
85-
;; @005d v9 = load.i64 notrap aligned pure checked v0+88
85+
;; @005d v9 = load.i64 notrap aligned can_move checked v0+88
8686
;; @005d v10 = iadd v9, v6
8787
;; @005d store little heap v3, v10
8888
;; @0064 v16 = iconst.i64 4

tests/disas/dynamic-memory-yes-spectre-access-same-index-different-offsets.wat

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@
3737
;; gv2 = load.i64 notrap aligned gv1+16
3838
;; gv3 = vmctx
3939
;; gv4 = load.i64 notrap aligned gv3+96
40-
;; gv5 = load.i64 notrap aligned pure checked gv3+88
40+
;; gv5 = load.i64 notrap aligned can_move checked gv3+88
4141
;; stack_limit = gv2
4242
;;
4343
;; block0(v0: i64, v1: i64, v2: i32):
4444
;; @0047 v7 = load.i64 notrap aligned v0+96
45-
;; @0047 v9 = load.i64 notrap aligned pure checked v0+88
45+
;; @0047 v9 = load.i64 notrap aligned can_move checked v0+88
4646
;; @0047 v6 = uextend.i64 v2
4747
;; @0047 v8 = icmp ugt v6, v7
4848
;; @0047 v11 = iconst.i64 0
@@ -72,12 +72,12 @@
7272
;; gv2 = load.i64 notrap aligned gv1+16
7373
;; gv3 = vmctx
7474
;; gv4 = load.i64 notrap aligned gv3+96
75-
;; gv5 = load.i64 notrap aligned pure checked gv3+88
75+
;; gv5 = load.i64 notrap aligned can_move checked gv3+88
7676
;; stack_limit = gv2
7777
;;
7878
;; block0(v0: i64, v1: i64, v2: i32, v3: i32, v4: i32, v5: i32):
7979
;; @005d v7 = load.i64 notrap aligned v0+96
80-
;; @005d v9 = load.i64 notrap aligned pure checked v0+88
80+
;; @005d v9 = load.i64 notrap aligned can_move checked v0+88
8181
;; @005d v6 = uextend.i64 v2
8282
;; @005d v8 = icmp ugt v6, v7
8383
;; @005d v11 = iconst.i64 0

0 commit comments

Comments
 (0)