Skip to content
This repository was archived by the owner on Mar 24, 2022. It is now read-only.

Commit 71152a1

Browse files
committed
add lucetc flag to select heap pinning
1 parent 3cd23d7 commit 71152a1

File tree

5 files changed

+36
-3
lines changed

5 files changed

+36
-3
lines changed

lucet-module/src/module_data.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ pub struct ModuleFeatures {
5959
pub lzcnt: bool,
6060
pub popcnt: bool,
6161
pub instruction_count: bool,
62+
pub pinned_heap: bool,
6263
_hidden: (),
6364
}
6465

@@ -75,6 +76,7 @@ impl ModuleFeatures {
7576
lzcnt: false,
7677
popcnt: false,
7778
instruction_count: false,
79+
pinned_heap: false,
7880
_hidden: (),
7981
}
8082
}

lucet-spectest/src/script.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ impl ScriptEnv {
7474
true,
7575
&None,
7676
false,
77+
false,
7778
)
7879
.map_err(program_error)?;
7980

lucetc/lucetc/options.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,12 @@ SSE3 but not AVX:
453453
.takes_value(false)
454454
.help("Instrument the produced binary to count the number of wasm operations the translated program executes")
455455
)
456+
.arg(
457+
Arg::with_name("pinned_heap")
458+
.long("--pinned-heap-reg")
459+
.takes_value(false)
460+
.help("This feature is not stable - it may be removed in the future! Pin a register to use as this module's heap base. Typically improves performance.")
461+
)
456462
.arg(
457463
Arg::with_name("error_style")
458464
.long("error-style")

lucetc/src/compiler.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ pub struct Compiler<'a> {
5656
count_instructions: bool,
5757
module_translation_state: ModuleTranslationState,
5858
canonicalize_nans: bool,
59+
pinned_heap: bool,
5960
}
6061

6162
impl<'a> Compiler<'a> {
@@ -69,8 +70,9 @@ impl<'a> Compiler<'a> {
6970
count_instructions: bool,
7071
validator: &Option<Validator>,
7172
canonicalize_nans: bool,
73+
pinned_heap: bool,
7274
) -> Result<Self, Error> {
73-
let isa = Self::target_isa(target.clone(), opt_level, &cpu_features, canonicalize_nans)?;
75+
let isa = Self::target_isa(target.clone(), opt_level, &cpu_features, canonicalize_nans, pinned_heap)?;
7476

7577
let frontend_config = isa.frontend_config();
7678
let mut module_info = ModuleInfo::new(frontend_config.clone());
@@ -127,12 +129,14 @@ impl<'a> Compiler<'a> {
127129
module_translation_state,
128130
target,
129131
canonicalize_nans,
132+
pinned_heap,
130133
})
131134
}
132135

133136
pub fn module_features(&self) -> ModuleFeatures {
134137
let mut mf: ModuleFeatures = (&self.cpu_features).into();
135138
mf.instruction_count = self.count_instructions;
139+
mf.pinned_heap = self.pinned_heap;
136140
mf
137141
}
138142

@@ -239,6 +243,7 @@ impl<'a> Compiler<'a> {
239243
self.opt_level,
240244
&self.cpu_features,
241245
self.canonicalize_nans,
246+
self.pinned_heap,
242247
)?,
243248
))
244249
}
@@ -248,17 +253,20 @@ impl<'a> Compiler<'a> {
248253
opt_level: OptLevel,
249254
cpu_features: &CpuFeatures,
250255
canonicalize_nans: bool,
256+
pinned_heap: bool,
251257
) -> Result<Box<dyn TargetIsa>, Error> {
252258
let mut flags_builder = settings::builder();
253259
let isa_builder = cpu_features.isa_builder(target)?;
254260
flags_builder.enable("enable_verifier").unwrap();
255261
flags_builder.enable("is_pic").unwrap();
256-
flags_builder.enable("enable_pinned_reg").unwrap();
257-
flags_builder.enable("use_pinned_reg_as_heap_base").unwrap();
258262
flags_builder.set("opt_level", opt_level.to_flag()).unwrap();
259263
if canonicalize_nans {
260264
flags_builder.enable("enable_nan_canonicalization").unwrap();
261265
}
266+
if pinned_heap {
267+
flags_builder.enable("enable_pinned_reg").unwrap();
268+
flags_builder.enable("use_pinned_reg_as_heap_base").unwrap();
269+
}
262270
Ok(isa_builder.finish(settings::Flags::new(flags_builder)))
263271
}
264272
}

lucetc/src/lib.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ pub struct Lucetc {
5555
verify: bool,
5656
count_instructions: bool,
5757
canonicalize_nans: bool,
58+
pinned_heap: bool,
5859
}
5960

6061
pub trait AsLucetc {
@@ -116,6 +117,8 @@ pub trait LucetcOpts {
116117
fn with_count_instructions(self, enable_count: bool) -> Self;
117118
fn canonicalize_nans(&mut self, enable_canonicalize_nans: bool);
118119
fn with_canonicalize_nans(self, enable_canonicalize_nans: bool) -> Self;
120+
fn pinned_heap(&mut self, enable_pinned_heap: bool);
121+
fn with_pinned_heap(self, enable_pinned_heap: bool) -> Self;
119122
}
120123

121124
impl<T: AsLucetc> LucetcOpts for T {
@@ -265,6 +268,15 @@ impl<T: AsLucetc> LucetcOpts for T {
265268
self.canonicalize_nans(enable_nans_canonicalization);
266269
self
267270
}
271+
272+
fn pinned_heap(&mut self, enable_pinned_heap: bool) {
273+
self.as_lucetc().pinned_heap = enable_pinned_heap;
274+
}
275+
276+
fn with_pinned_heap(mut self, enable_pinned_heap: bool) -> Self {
277+
self.pinned_heap(enable_pinned_heap);
278+
self
279+
}
268280
}
269281

270282
impl Lucetc {
@@ -285,6 +297,7 @@ impl Lucetc {
285297
verify: false,
286298
count_instructions: false,
287299
canonicalize_nans: false,
300+
pinned_heap: false,
288301
}
289302
}
290303

@@ -305,6 +318,7 @@ impl Lucetc {
305318
verify: false,
306319
count_instructions: false,
307320
canonicalize_nans: false,
321+
pinned_heap: false,
308322
})
309323
}
310324

@@ -349,6 +363,7 @@ impl Lucetc {
349363
self.count_instructions,
350364
&self.validator,
351365
self.canonicalize_nans,
366+
self.pinned_heap,
352367
)?;
353368
let obj = compiler.object_file()?;
354369
obj.write(output.as_ref())?;
@@ -369,6 +384,7 @@ impl Lucetc {
369384
self.count_instructions,
370385
&self.validator,
371386
self.canonicalize_nans,
387+
self.pinned_heap,
372388
)?;
373389

374390
compiler.cranelift_funcs()?.write(&output)?;

0 commit comments

Comments
 (0)