Skip to content

Commit 6dadd3c

Browse files
committed
pd-vm: jit unbox string/bytes on len/get/has
1 parent c1b1d6f commit 6dadd3c

9 files changed

Lines changed: 1972 additions & 96 deletions

File tree

pd-vm/src/lib.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,20 @@ pub use builtins::{
2828
language_builtin_specs,
2929
};
3030
pub use bytecode::{HostImport, OpCode, Program, TypeMap, Value, ValueType};
31+
pub fn builtin_call_index(name: &str) -> Option<u16> {
32+
use builtins::BuiltinFunction;
33+
34+
match name {
35+
"len" => Some(BuiltinFunction::Len.call_index()),
36+
"slice" => Some(BuiltinFunction::Slice.call_index()),
37+
"concat" => Some(BuiltinFunction::Concat.call_index()),
38+
"get" => Some(BuiltinFunction::Get.call_index()),
39+
"has" => Some(BuiltinFunction::Has.call_index()),
40+
"set" => Some(BuiltinFunction::Set.call_index()),
41+
"keys" => Some(BuiltinFunction::Keys.call_index()),
42+
_ => BuiltinFunction::from_namespaced_name(name).map(|builtin| builtin.call_index()),
43+
}
44+
}
3145
pub use compiler::diagnostics::{render_compile_error, render_source_error};
3246
pub use compiler::source_map::{LineSpanMapping, LoweredSource, SourceId, SourceMap, Span};
3347
pub use compiler::{

pd-vm/src/vm/jit/ir.rs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,38 @@ pub(crate) enum SsaInstKind {
107107
input: SsaValueId,
108108
tag: ValueType,
109109
},
110+
StringLen {
111+
text: SsaValueId,
112+
},
113+
BytesLen {
114+
bytes: SsaValueId,
115+
},
116+
StringSlice {
117+
text: SsaValueId,
118+
start: SsaValueId,
119+
length: SsaValueId,
120+
},
121+
BytesSlice {
122+
bytes: SsaValueId,
123+
start: SsaValueId,
124+
length: SsaValueId,
125+
},
126+
StringGet {
127+
text: SsaValueId,
128+
index: SsaValueId,
129+
},
130+
BytesGet {
131+
bytes: SsaValueId,
132+
index: SsaValueId,
133+
},
134+
StringConcat {
135+
lhs: SsaValueId,
136+
rhs: SsaValueId,
137+
},
138+
BytesConcat {
139+
lhs: SsaValueId,
140+
rhs: SsaValueId,
141+
},
110142
ArrayLen {
111143
array: SsaValueId,
112144
},
@@ -245,10 +277,25 @@ impl SsaInstKind {
245277
| Self::UnboxFloat { input }
246278
| Self::UnboxBool { input }
247279
| Self::UnboxHeapPtr { input, .. }
280+
| Self::StringLen { text: input }
281+
| Self::BytesLen { bytes: input }
248282
| Self::ArrayLen { array: input }
249283
| Self::MapLen { map: input }
250284
| Self::IntNeg { input }
251285
| Self::FloatNeg { input } => vec![*input],
286+
Self::StringSlice {
287+
text,
288+
start,
289+
length,
290+
} => vec![*text, *start, *length],
291+
Self::BytesSlice {
292+
bytes,
293+
start,
294+
length,
295+
} => vec![*bytes, *start, *length],
296+
Self::StringGet { text, index } => vec![*text, *index],
297+
Self::BytesGet { bytes, index } => vec![*bytes, *index],
298+
Self::StringConcat { lhs, rhs } | Self::BytesConcat { lhs, rhs } => vec![*lhs, *rhs],
252299
Self::ArrayGet { array, index } => vec![*array, *index],
253300
Self::ArrayHas { array, index } => vec![*array, *index],
254301
Self::MapGet { map, key } => vec![*map, *key],
@@ -751,6 +798,22 @@ fn render_inst_kind(kind: &SsaInstKind) -> String {
751798
SsaInstKind::UnboxFloat { input } => format!("unbox_float {input}"),
752799
SsaInstKind::UnboxBool { input } => format!("unbox_bool {input}"),
753800
SsaInstKind::UnboxHeapPtr { input, tag } => format!("unbox_ptr {input}, {tag:?}"),
801+
SsaInstKind::StringLen { text } => format!("string_len {text}"),
802+
SsaInstKind::BytesLen { bytes } => format!("bytes_len {bytes}"),
803+
SsaInstKind::StringSlice {
804+
text,
805+
start,
806+
length,
807+
} => format!("string_slice {text}, {start}, {length}"),
808+
SsaInstKind::BytesSlice {
809+
bytes,
810+
start,
811+
length,
812+
} => format!("bytes_slice {bytes}, {start}, {length}"),
813+
SsaInstKind::StringGet { text, index } => format!("string_get {text}, {index}"),
814+
SsaInstKind::BytesGet { bytes, index } => format!("bytes_get {bytes}, {index}"),
815+
SsaInstKind::StringConcat { lhs, rhs } => format!("string_concat {lhs}, {rhs}"),
816+
SsaInstKind::BytesConcat { lhs, rhs } => format!("bytes_concat {lhs}, {rhs}"),
754817
SsaInstKind::ArrayLen { array } => format!("array_len {array}"),
755818
SsaInstKind::ArrayGet { array, index } => format!("array_get {array}, {index}"),
756819
SsaInstKind::ArrayHas { array, index } => format!("array_has {array}, {index}"),

0 commit comments

Comments
 (0)