Skip to content

Commit

Permalink
Enable stack probes on the cranelift JIT
Browse files Browse the repository at this point in the history
Signed-off-by: Afonso Bordado <[email protected]>
  • Loading branch information
afonso360 committed Aug 13, 2023
1 parent 60bbc55 commit 602c1fa
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions src/cranelift.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ use cranelift_codegen::{
AbiParam, Block, Endianness, FuncRef, Function, InstBuilder, LibCall, MemFlags, Signature,
SourceLoc, StackSlotData, StackSlotKind, TrapCode, Type, UserFuncName, Value,
},
isa::{CallConv, OwnedTargetIsa},
settings::{self, Configurable},
Context,
isa::OwnedTargetIsa,
settings::{self, Configurable}
};
use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext, Variable};
use cranelift_jit::{JITBuilder, JITModule};
Expand Down Expand Up @@ -67,8 +66,13 @@ pub(crate) struct CraneliftCompiler {
impl CraneliftCompiler {
pub(crate) fn new(helpers: HashMap<u32, ebpf::Helper>) -> Self {
let mut flag_builder = settings::builder();

flag_builder.set("opt_level", "speed").unwrap();

// Enable stack probes
flag_builder.enable("enable_probestack").unwrap();
flag_builder.set("probestack_strategy", "inline").unwrap();

let isa_builder = cranelift_native::builder().unwrap_or_else(|msg| {
panic!("host machine is not supported: {}", msg);
});
Expand Down Expand Up @@ -124,15 +128,15 @@ impl CraneliftCompiler {
AbiParam::new(I64),
],
returns: vec![AbiParam::new(I64)],
call_conv: CallConv::SystemV,
call_conv: self.isa.default_call_conv(),
};

let func_id = self
.module
.declare_function(name, Linkage::Local, &sig)
.unwrap();

let mut ctx = Context::new();
let mut ctx = self.module.make_context();
ctx.func = Function::with_name_signature(UserFuncName::testcase(name.as_bytes()), sig);
let mut func_ctx = FunctionBuilderContext::new();

Expand All @@ -153,6 +157,7 @@ impl CraneliftCompiler {

self.module.define_function(func_id, &mut ctx).unwrap();
self.module.finalize_definitions().unwrap();
self.module.clear_context(&mut ctx);

Ok(CraneliftProgram::new(self.module, func_id))
}
Expand Down Expand Up @@ -187,7 +192,7 @@ impl CraneliftCompiler {
AbiParam::new(I64),
],
returns: vec![AbiParam::new(I64)],
call_conv: CallConv::SystemV,
call_conv: self.isa.default_call_conv(),
};
let func_id = self
.module
Expand Down Expand Up @@ -925,15 +930,6 @@ impl CraneliftCompiler {
let ret = bcx.use_var(self.registers[0]);
bcx.ins().return_(&[ret]);
self.filled_blocks.insert(bcx.current_block().unwrap());

// // If we have multiple consecutive exit instructions we need to switch blocks.
// let (fallthrough, target) = self.insn_targets[&(insn_ptr as u32)];
// let next_pc = (insn_ptr + 1) as u32;
// let next_block = *self
// .insn_blocks
// .entry(next_pc)
// .or_insert_with(|| bcx.create_block());
// self.insn_blocks.insert(next_pc, next_block);
}
_ => unimplemented!("inst: {:?}", insn),
}
Expand Down

0 comments on commit 602c1fa

Please sign in to comment.