Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement AOT compilation for components #5160

Merged
merged 12 commits into from
Nov 2, 2022
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ libc = "0.2.60"
humantime = "2.0.0"
once_cell = { workspace = true }
listenfd = "1.0.0"
wat = { workspace = true }

[target.'cfg(unix)'.dependencies]
rustix = { workspace = true, features = ["mm", "param"] }
Expand Down Expand Up @@ -90,7 +91,7 @@ members = [
"examples/wasi/wasm",
"examples/tokio/wasm",
"fuzz",
"winch",
"winch",
"winch/codegen"
]
exclude = [
Expand Down
2 changes: 1 addition & 1 deletion cranelift/codegen/src/isa/aarch64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ impl TargetIsa for AArch64Backend {
Some(inst::unwind::systemv::create_cie())
}

fn text_section_builder(&self, num_funcs: u32) -> Box<dyn TextSectionBuilder> {
fn text_section_builder(&self, num_funcs: usize) -> Box<dyn TextSectionBuilder> {
Box::new(MachTextSectionBuilder::<inst::Inst>::new(num_funcs))
}

Expand Down
2 changes: 1 addition & 1 deletion cranelift/codegen/src/isa/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ pub trait TargetIsa: fmt::Display + Send + Sync {
/// The `num_labeled_funcs` argument here is the number of functions which
/// will be "labeled" or might have calls between them, typically the number
/// of defined functions in the object file.
fn text_section_builder(&self, num_labeled_funcs: u32) -> Box<dyn TextSectionBuilder>;
fn text_section_builder(&self, num_labeled_funcs: usize) -> Box<dyn TextSectionBuilder>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not totally clear to me what the motivation for changing this was. Not saying its necessarily wrong or anything but I'm just curious.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah there ended up being a lot of casts around this and having everything be usize removed all the casts, so I went ahead and updated this to usize.


/// The function alignment required by this ISA.
fn function_alignment(&self) -> u32;
Expand Down
2 changes: 1 addition & 1 deletion cranelift/codegen/src/isa/riscv64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ impl TargetIsa for Riscv64Backend {
Some(inst::unwind::systemv::create_cie())
}

fn text_section_builder(&self, num_funcs: u32) -> Box<dyn TextSectionBuilder> {
fn text_section_builder(&self, num_funcs: usize) -> Box<dyn TextSectionBuilder> {
Box::new(MachTextSectionBuilder::<inst::Inst>::new(num_funcs))
}

Expand Down
2 changes: 1 addition & 1 deletion cranelift/codegen/src/isa/s390x/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ impl TargetIsa for S390xBackend {
inst::unwind::systemv::map_reg(reg).map(|reg| reg.0)
}

fn text_section_builder(&self, num_funcs: u32) -> Box<dyn TextSectionBuilder> {
fn text_section_builder(&self, num_funcs: usize) -> Box<dyn TextSectionBuilder> {
Box::new(MachTextSectionBuilder::<inst::Inst>::new(num_funcs))
}

Expand Down
2 changes: 1 addition & 1 deletion cranelift/codegen/src/isa/x64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ impl TargetIsa for X64Backend {
inst::unwind::systemv::map_reg(reg).map(|reg| reg.0)
}

fn text_section_builder(&self, num_funcs: u32) -> Box<dyn TextSectionBuilder> {
fn text_section_builder(&self, num_funcs: usize) -> Box<dyn TextSectionBuilder> {
Box::new(MachTextSectionBuilder::<inst::Inst>::new(num_funcs))
}

Expand Down
12 changes: 6 additions & 6 deletions cranelift/codegen/src/machinst/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1612,9 +1612,9 @@ pub struct MachTextSectionBuilder<I: VCodeInst> {
}

impl<I: VCodeInst> MachTextSectionBuilder<I> {
pub fn new(num_funcs: u32) -> MachTextSectionBuilder<I> {
pub fn new(num_funcs: usize) -> MachTextSectionBuilder<I> {
let mut buf = MachBuffer::new();
buf.reserve_labels_for_blocks(num_funcs as usize);
buf.reserve_labels_for_blocks(num_funcs);
MachTextSectionBuilder {
buf,
next_func: 0,
Expand All @@ -1624,7 +1624,7 @@ impl<I: VCodeInst> MachTextSectionBuilder<I> {
}

impl<I: VCodeInst> TextSectionBuilder for MachTextSectionBuilder<I> {
fn append(&mut self, named: bool, func: &[u8], align: u32) -> u64 {
fn append(&mut self, labeled: bool, func: &[u8], align: u32) -> u64 {
// Conditionally emit an island if it's necessary to resolve jumps
// between functions which are too far away.
let size = func.len() as u32;
Expand All @@ -1634,7 +1634,7 @@ impl<I: VCodeInst> TextSectionBuilder for MachTextSectionBuilder<I> {

self.buf.align_to(align);
let pos = self.buf.cur_offset();
if named {
if labeled {
self.buf
.bind_label(MachLabel::from_block(BlockIndex::new(self.next_func)));
self.next_func += 1;
Expand All @@ -1643,8 +1643,8 @@ impl<I: VCodeInst> TextSectionBuilder for MachTextSectionBuilder<I> {
u64::from(pos)
}

fn resolve_reloc(&mut self, offset: u64, reloc: Reloc, addend: Addend, target: u32) -> bool {
let label = MachLabel::from_block(BlockIndex::new(target as usize));
fn resolve_reloc(&mut self, offset: u64, reloc: Reloc, addend: Addend, target: usize) -> bool {
let label = MachLabel::from_block(BlockIndex::new(target));
let offset = u32::try_from(offset).unwrap();
match I::LabelUse::from_reloc(reloc, addend) {
Some(label_use) => {
Expand Down
8 changes: 5 additions & 3 deletions cranelift/codegen/src/machinst/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,10 @@ impl CompiledCode {
pub trait TextSectionBuilder {
/// Appends `data` to the text section with the `align` specified.
///
/// If `labeled` is `true` then the offset of the final data is used to
/// resolve relocations in `resolve_reloc` in the future.
/// If `labeled` is `true` then this also binds the appended data to the
/// `n`th label for how many times this has been called with `labeled:
/// true`. The label target can be passed as the `target` argument to
/// `resolve_reloc`.
///
/// This function returns the offset at which the data was placed in the
/// text section.
Expand All @@ -418,7 +420,7 @@ pub trait TextSectionBuilder {
/// If this builder does not know how to handle `reloc` then this function
/// will return `false`. Otherwise this function will return `true` and this
/// relocation will be resolved in the final bytes returned by `finish`.
fn resolve_reloc(&mut self, offset: u64, reloc: Reloc, addend: Addend, target: u32) -> bool;
fn resolve_reloc(&mut self, offset: u64, reloc: Reloc, addend: Addend, target: usize) -> bool;

/// A debug-only option which is used to for
fn force_veneers(&mut self);
Expand Down
Loading