Skip to content

Commit 09482b8

Browse files
committed
Fix typos, remove todos, add every HIR instruction to effects_of
1 parent 7afe36f commit 09482b8

3 files changed

Lines changed: 108 additions & 48 deletions

File tree

zjit/src/hir.rs

Lines changed: 105 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,11 +1060,19 @@ impl Insn {
10601060
const allocates: Effect = Effect::read_write(abstract_heaps::PC.union(abstract_heaps::Allocator), abstract_heaps::Allocator);
10611061
match &self {
10621062
Insn::Const { .. } => effects::Empty,
1063-
Insn::Param => effects::Empty,
1063+
Insn::Param { .. } => effects::Empty,
10641064
Insn::StringCopy { .. } => allocates,
1065+
Insn::StringIntern { .. } => effects::Any,
1066+
Insn::StringConcat { .. } => effects::Any,
1067+
Insn::StringGetbyte { .. } => Effect::read_write(abstract_heaps::Other, abstract_heaps::Empty),
1068+
Insn::StringSetbyteFixnum { .. } => effects::Any,
1069+
Insn::StringAppend { .. } => effects::Any,
1070+
Insn::StringAppendCodepoint { .. } => effects::Any,
1071+
Insn::ToRegexp { .. } => effects::Any,
1072+
Insn::PutSpecialObject { .. } => effects::Any,
1073+
Insn::ToArray { .. } => effects::Any,
1074+
Insn::ToNewArray { .. } => effects::Any,
10651075
Insn::NewArray { .. } => allocates,
1066-
// TODO(Jacob): Can we further constrain the read effects from Any?
1067-
Insn::ArrayLength { .. } => Effect::write(abstract_heaps::Empty),
10681076
Insn::NewHash { elements, .. } => {
10691077
// NewHash's operands may be hashed and compared for equality, which could have
10701078
// side-effects. Empty hashes are definitely elidable.
@@ -1075,30 +1083,60 @@ impl Insn {
10751083
effects::Any
10761084
}
10771085
},
1086+
Insn::NewRange { .. } => effects::Any,
1087+
Insn::NewRangeFixnum { .. } => allocates,
10781088
Insn::ArrayDup { .. } => allocates,
1089+
Insn::ArrayHash { .. } => effects::Any,
1090+
Insn::ArrayMax { .. } => effects::Any,
1091+
Insn::ArrayInclude { .. } => effects::Any,
1092+
Insn::ArrayPackBuffer { .. } => effects::Any,
1093+
Insn::DupArrayInclude { .. } => effects::Any,
1094+
Insn::ArrayExtend { .. } => effects::Any,
1095+
Insn::ArrayPush { .. } => effects::Any,
1096+
Insn::ArrayArefFixnum { .. } => effects::Any,
1097+
Insn::ArrayAset { .. } => effects::Any,
1098+
Insn::ArrayPop { .. } => effects::Any,
1099+
Insn::ArrayLength { .. } => Effect::write(abstract_heaps::Empty),
1100+
Insn::HashAref { .. } => effects::Any,
1101+
Insn::HashAset { .. } => effects::Any,
10791102
Insn::HashDup { .. } => allocates,
1103+
Insn::ObjectAlloc { .. } => effects::Any,
1104+
Insn::ObjectAllocClass { .. } => allocates,
10801105
Insn::Test { .. } => effects::Empty,
1081-
Insn::Snapshot { .. } => effects::Empty,
1082-
Insn::FixnumAdd { .. } => effects::Empty,
1083-
Insn::FixnumSub { .. } => effects::Empty,
1084-
Insn::FixnumMult { .. } => effects::Empty,
1085-
Insn::FixnumEq { .. } => effects::Empty,
1086-
Insn::FixnumNeq { .. } => effects::Empty,
1087-
Insn::FixnumLt { .. } => effects::Empty,
1088-
Insn::FixnumLe { .. } => effects::Empty,
1089-
Insn::FixnumGt { .. } => effects::Empty,
1090-
Insn::FixnumGe { .. } => effects::Empty,
1091-
Insn::FixnumAnd { .. } => effects::Empty,
1092-
Insn::FixnumOr { .. } => effects::Empty,
1093-
Insn::FixnumXor { .. } => effects::Empty,
1094-
Insn::FixnumLShift { .. } => effects::Empty,
1095-
Insn::FixnumRShift { .. } => effects::Empty,
1096-
Insn::GetLocal { .. } => Effect::read_write(abstract_heaps::Locals, abstract_heaps::Empty),
1097-
Insn::IsNil { .. } => effects::Empty,
1098-
Insn::LoadPC => Effect::read_write(abstract_heaps::PC, abstract_heaps::Empty),
1099-
Insn::LoadEC => effects::Empty,
1100-
Insn::LoadSelf => Effect::read_write(abstract_heaps::Frame, abstract_heaps::Empty),
1106+
Insn::IsNil { .. } => effects::Empty,
1107+
Insn::IsMethodCfunc { .. } => effects::Any,
1108+
Insn::IsBitEqual { .. } => effects::Empty,
1109+
Insn::IsBitNotEqual { .. } => effects::Any,
1110+
Insn::BoxBool { .. } => effects::Empty,
1111+
Insn::BoxFixnum { .. } => effects::Empty,
1112+
Insn::UnboxFixnum { .. } => effects::Any,
1113+
Insn::FixnumAref { .. } => effects::Empty,
1114+
Insn::Defined { .. } => effects::Any,
1115+
Insn::GetConstantPath { .. } => effects::Any,
1116+
Insn::IsBlockGiven { .. } => Effect::read_write(abstract_heaps::Other, abstract_heaps::Empty),
1117+
Insn::FixnumBitCheck { .. } => effects::Any,
1118+
Insn::IsA { .. } => effects::Empty,
1119+
Insn::GetGlobal { .. } => effects::Any,
1120+
Insn::SetGlobal { .. } => effects::Any,
1121+
Insn::GetIvar { .. } => effects::Any,
1122+
Insn::SetIvar { .. } => effects::Any,
1123+
Insn::DefinedIvar { .. } => effects::Any,
1124+
Insn::LoadPC { .. } => Effect::read_write(abstract_heaps::PC, abstract_heaps::Empty),
1125+
Insn::LoadEC { .. } => effects::Empty,
1126+
Insn::LoadSelf { .. } => Effect::read_write(abstract_heaps::Frame, abstract_heaps::Empty),
11011127
Insn::LoadField { .. } => Effect::read_write(abstract_heaps::Other, abstract_heaps::Empty),
1128+
Insn::StoreField { .. } => effects::Any,
1129+
Insn::WriteBarrier { .. } => effects::Any,
1130+
Insn::GetLocal { .. } => Effect::read_write(abstract_heaps::Locals, abstract_heaps::Empty),
1131+
Insn::SetLocal { .. } => effects::Any,
1132+
Insn::GetSpecialSymbol { .. } => effects::Any,
1133+
Insn::GetSpecialNumber { .. } => effects::Any,
1134+
Insn::GetClassVar { .. } => effects::Any,
1135+
Insn::SetClassVar { .. } => effects::Any,
1136+
Insn::Snapshot { .. } => effects::Empty,
1137+
Insn::Jump(_) => effects::Any,
1138+
Insn::IfTrue { .. } => effects::Any,
1139+
Insn::IfFalse { .. } => effects::Any,
11021140
Insn::CCall { elidable, .. } => {
11031141
if *elidable {
11041142
Effect::write(abstract_heaps::Allocator)
@@ -1107,27 +1145,57 @@ impl Insn {
11071145
effects::Any
11081146
}
11091147
},
1110-
Insn::CCallWithFrame { elidable, .. } => {
1148+
Insn::CCallWithFrame { elidable, .. } => {
11111149
if *elidable {
11121150
Effect::write(abstract_heaps::Allocator)
11131151
}
11141152
else {
11151153
effects::Any
11161154
}
11171155
},
1118-
Insn::ObjectAllocClass { .. } => allocates,
1119-
Insn::NewRangeFixnum { .. } => allocates,
1120-
// TODO(Jacob): Double check this one
1121-
Insn::StringGetbyte { .. } => Effect::read_write(abstract_heaps::Other, abstract_heaps::Empty),
1122-
// TODO(Jacob): This reads EP (LEP?) and read effects can likely be bounded better
1123-
Insn::IsBlockGiven => Effect::read_write(abstract_heaps::Other, abstract_heaps::Empty),
1124-
Insn::BoxFixnum { .. } => effects::Empty,
1125-
Insn::BoxBool { .. } => effects::Empty,
1126-
Insn::IsBitEqual { .. } => effects::Empty,
1127-
// TODO(Jacob): Maybe this gets a stronger read effect?
1128-
Insn::FixnumAref { .. } => effects::Empty,
1129-
Insn::IsA { .. } => effects::Empty,
1130-
_ => Effect::read_write(abstract_heaps::Any, abstract_heaps::Any),
1156+
Insn::CCallVariadic { .. } => effects::Any,
1157+
Insn::SendWithoutBlock { .. } => effects::Any,
1158+
Insn::Send { .. } => effects::Any,
1159+
Insn::SendForward { .. } => effects::Any,
1160+
Insn::InvokeSuper { .. } => effects::Any,
1161+
Insn::InvokeBlock { .. } => effects::Any,
1162+
Insn::SendWithoutBlockDirect { .. } => effects::Any,
1163+
Insn::InvokeBuiltin { .. } => effects::Any,
1164+
Insn::EntryPoint { .. } => effects::Any,
1165+
Insn::Return { .. } => effects::Any,
1166+
Insn::Throw { .. } => effects::Any,
1167+
Insn::FixnumAdd { .. } => effects::Empty,
1168+
Insn::FixnumSub { .. } => effects::Empty,
1169+
Insn::FixnumMult { .. } => effects::Empty,
1170+
Insn::FixnumDiv { .. } => effects::Any,
1171+
Insn::FixnumMod { .. } => effects::Any,
1172+
Insn::FixnumEq { .. } => effects::Empty,
1173+
Insn::FixnumNeq { .. } => effects::Empty,
1174+
Insn::FixnumLt { .. } => effects::Empty,
1175+
Insn::FixnumLe { .. } => effects::Empty,
1176+
Insn::FixnumGt { .. } => effects::Empty,
1177+
Insn::FixnumGe { .. } => effects::Empty,
1178+
Insn::FixnumAnd { .. } => effects::Empty,
1179+
Insn::FixnumOr { .. } => effects::Empty,
1180+
Insn::FixnumXor { .. } => effects::Empty,
1181+
Insn::FixnumLShift { .. } => effects::Empty,
1182+
Insn::FixnumRShift { .. } => effects::Empty,
1183+
Insn::ObjToString { .. } => effects::Any,
1184+
Insn::AnyToString { .. } => effects::Any,
1185+
Insn::GuardType { .. } => effects::Any,
1186+
Insn::GuardTypeNot { .. } => effects::Any,
1187+
Insn::GuardBitEquals { .. } => effects::Any,
1188+
Insn::GuardShape { .. } => effects::Any,
1189+
Insn::GuardBlockParamProxy { .. } => effects::Any,
1190+
Insn::GuardNotFrozen { .. } => effects::Any,
1191+
Insn::GuardNotShared { .. } => effects::Any,
1192+
Insn::GuardGreaterEq { .. } => effects::Any,
1193+
Insn::GuardLess { .. } => effects::Any,
1194+
Insn::PatchPoint { .. } => effects::Any,
1195+
Insn::SideExit { .. } => effects::Any,
1196+
Insn::IncrCounter(_) => effects::Any,
1197+
Insn::IncrCounterPtr { .. } => effects::Any,
1198+
Insn::CheckInterrupts { .. } => effects::Any,
11311199
}
11321200
}
11331201

zjit/src/hir_effect/gen_hir_effect.rb

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Generate hir_effect.inc.rs. To do this, we build up a DAG that
22
# represents the ZJIT effect hierarchy.
3-
# TODO(Jacob): Make sure this function works after all the types and effects replacements
43

54
require 'set'
65

@@ -102,8 +101,8 @@ def add_union name, effect_names
102101
}
103102
puts " pub const AllBitPatterns: [(&str, #{$int_label}); #{$bits.size}] = ["
104103
# Sort the bit patterns by decreasing value so that we can print the densest
105-
# possible to-string representation of an Effect. For example, CSigned instead of
106-
# CInt8|CInt16|...
104+
# possible to-string representation of an Effect. For example, Frame instead of
105+
# PC|Stack|Locals
107106
$numeric_bits.sort_by {|key, val| -val}.each {|effect_name, _|
108107
puts " (\"#{effect_name}\", #{effect_name}),"
109108
}
@@ -129,10 +128,3 @@ def add_union name, effect_names
129128
puts " pub const #{effect_name}: Effect = Effect::promote(abstract_heaps::#{effect_name});"
130129
}
131130
puts "}"
132-
133-
# puts "pub mod effects {
134-
# use super::*;"
135-
# $bits.keys.sort.map {|effect_name|
136-
# puts " pub const #{effect_name}: AbstractHeap = AbstractHeap::from_bits(bits::#{effect_name});"
137-
# }
138-
# puts "}"

zjit/src/hir_effect/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ include!("hir_effect.inc.rs");
2323
///
2424
/// Lattice Top corresponds to the "Any" effect. All bits are set and any effect is possible.
2525
/// Lattice Bottom corresponds to the "None" effect. No bits are set and no effects are possible.
26-
/// Elements between Boabstract_heapsp have effects corresponding to the bits that are set.
26+
/// Elements between abstract_heaps have effects corresponding to the bits that are set.
2727
/// This enables more complex analyses compared to prior ZJIT implementations such as "has_effect",
2828
/// a function that returns a boolean value. Such functions impose an implicit single bit effect
2929
/// system. This explicit design with a lattice allows us many bits for effects.

0 commit comments

Comments
 (0)