Skip to content

Commit 4aeb57b

Browse files
committed
improve dispatch_loop Instruction::InstallVerifyAttr
see #3175 (comment)
1 parent e4d9692 commit 4aeb57b

File tree

2 files changed

+54
-25
lines changed

2 files changed

+54
-25
lines changed

build/instructions_template.rs

Lines changed: 53 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,30 +1171,63 @@ fn generate_instruction_preface() -> TokenStream {
11711171
#[inline]
11721172
pub fn registers(&self) -> Vec<RegType> {
11731173
match *self {
1174-
Instruction::GetConstant(_, _, r) => vec![r],
1175-
Instruction::GetList(_, r) => vec![r],
1176-
Instruction::GetPartialString(_, _, r) => vec![r],
1177-
Instruction::GetStructure(_, _, _, r) => vec![r],
1178-
Instruction::GetVariable(r, t) => vec![r, temp_v!(t)],
1179-
Instruction::GetValue(r, t) => vec![r, temp_v!(t)],
1180-
Instruction::UnifyLocalValue(r) => vec![r],
1181-
Instruction::UnifyVariable(r) => vec![r],
1182-
Instruction::PutConstant(_, _, r) => vec![r],
1183-
Instruction::PutList(_, r) => vec![r],
1184-
Instruction::PutPartialString(_, _, r) => vec![r],
1185-
Instruction::PutStructure(_, _, r) => vec![r],
1186-
Instruction::PutValue(r, t) => vec![r, temp_v!(t)],
1187-
Instruction::PutVariable(r, t) => vec![r, temp_v!(t)],
1188-
Instruction::SetLocalValue(r) => vec![r],
1189-
Instruction::SetVariable(r) => vec![r],
1190-
Instruction::SetValue(r) => vec![r],
1191-
Instruction::GetLevel(r) => vec![r],
1192-
Instruction::GetPrevLevel(r) => vec![r],
1193-
Instruction::GetCutPoint(r) => vec![r],
1174+
Instruction::GetVariable(r, t)
1175+
| Instruction::GetValue(r, t)
1176+
| Instruction::PutValue(r, t)
1177+
| Instruction::PutVariable(r, t) => vec![r, temp_v!(t)],
1178+
Instruction::GetConstant(_, _, r)
1179+
| Instruction::GetList(_, r)
1180+
| Instruction::GetPartialString(_, _, r)
1181+
| Instruction::GetStructure(_, _, _, r)
1182+
| Instruction::UnifyLocalValue(r)
1183+
| Instruction::UnifyVariable(r)
1184+
| Instruction::PutConstant(_, _, r)
1185+
| Instruction::PutList(_, r)
1186+
| Instruction::PutPartialString(_, _, r)
1187+
| Instruction::PutStructure(_, _, r)
1188+
| Instruction::SetLocalValue(r)
1189+
| Instruction::SetVariable(r)
1190+
| Instruction::SetValue(r)
1191+
| Instruction::GetLevel(r)
1192+
| Instruction::GetPrevLevel(r)
1193+
| Instruction::GetCutPoint(r) => vec![r],
11941194
_ => vec![],
11951195
}
11961196
}
11971197

1198+
#[inline]
1199+
pub fn max_temp_register(&self) -> usize {
1200+
match *self {
1201+
Instruction::GetVariable(r, t)
1202+
| Instruction::GetValue(r, t)
1203+
| Instruction::PutValue(r, t)
1204+
| Instruction::PutVariable(r, t) => match r {
1205+
RegType::Perm(_) => t,
1206+
RegType::Temp(t2) => t.max(t2)
1207+
},
1208+
Instruction::GetConstant(_, _, r)
1209+
| Instruction::GetList(_, r)
1210+
| Instruction::GetPartialString(_, _, r)
1211+
| Instruction::GetStructure(_, _, _, r)
1212+
| Instruction::UnifyLocalValue(r)
1213+
| Instruction::UnifyVariable(r)
1214+
| Instruction::PutConstant(_, _, r)
1215+
| Instruction::PutList(_, r)
1216+
| Instruction::PutPartialString(_, _, r)
1217+
| Instruction::PutStructure(_, _, r)
1218+
| Instruction::SetLocalValue(r)
1219+
| Instruction::SetVariable(r)
1220+
| Instruction::SetValue(r)
1221+
| Instruction::GetLevel(r)
1222+
| Instruction::GetPrevLevel(r)
1223+
| Instruction::GetCutPoint(r) => match r {
1224+
RegType::Perm(_) => 0,
1225+
RegType::Temp(t) => t
1226+
},
1227+
_ => 0,
1228+
}
1229+
}
1230+
11981231
#[inline]
11991232
pub fn to_indexing_line_mut(&mut self) -> Option<&mut Vec<IndexingLine>> {
12001233
match self {

src/machine/dispatch.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -605,11 +605,7 @@ impl Machine {
605605
// Scan registers of all instructions to find out how many to save
606606
let arity = self.code[current_pred_start..current_pred_end]
607607
.iter()
608-
.flat_map(Instruction::registers)
609-
.flat_map(|r| match r {
610-
RegType::Temp(t) => Some(t),
611-
_ => None,
612-
})
608+
.map(Instruction::max_temp_register)
613609
.max()
614610
.unwrap_or(0);
615611

0 commit comments

Comments
 (0)