Skip to content
This repository was archived by the owner on Jul 7, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions lib/llvm/src/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,13 @@ fn translate_mem_intrinsic(
// start optimizing these libcalls.
let args = [dst_arg, src_arg, len_arg];

let funcname = strings.get_extname(name);
let libcall = match name {
"memcpy" => ir::LibCall::Memcpy,
"memmove" => ir::LibCall::Memmove,
"memset" => ir::LibCall::Memset,
_ => panic!("not handled {}", name)
};

// TODO: Translate the calling convention.
let mut sig = ir::Signature::new(CallConv::SystemV);
sig.params.resize(3, ir::AbiParam::new(pointer_type));
Expand All @@ -868,7 +874,7 @@ fn translate_mem_intrinsic(
sig.returns.resize(1, ir::AbiParam::new(pointer_type));
let signature = ctx.builder.import_signature(sig);
let data = ir::ExtFuncData {
name: funcname,
name: ir::ExternalName::LibCall(libcall),
signature,
colocated: false, // TODO: Set the colocated flag based on the visibility.
};
Expand Down
8 changes: 8 additions & 0 deletions lib/llvm/src/string_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ impl StringTable {
.0
.as_str()
}
ir::ExternalName::LibCall(libcall) => {
match libcall {
ir::LibCall::Memcpy => "memcpy",
ir::LibCall::Memmove => "memmove",
ir::LibCall::Memset => "memset",
_ => panic!("unhandled LibCall {}", libcall),
}
}
_ => panic!("non-user names not yet implemented"),
}
}
Expand Down
24 changes: 16 additions & 8 deletions lib/llvm/src/translate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,22 @@ pub fn translate_module(
// Collect externally referenced symbols for the module.
for func_ref in func.il.dfg.ext_funcs.keys() {
let name = &func.il.dfg.ext_funcs[func_ref].name;
// If this function is defined inside the module, don't list it
// as an import.
let c_str = ffi::CString::new(result.strings.get_str(name))
.map_err(|err| err.description().to_string())?;
let llvm_str = c_str.as_ptr();
let llvm_func = unsafe { LLVMGetNamedFunction(llvm_mod, llvm_str) };
if llvm_func.is_null() || unsafe { LLVMIsDeclaration(llvm_func) } != 0 {
result.imports.push((name.clone(), SymbolKind::Function));
match name {
ir::ExternalName::User{..} => {
// If this function is defined inside the module, don't list it
// as an import.
let c_str = ffi::CString::new(result.strings.get_str(name))
.map_err(|err| err.description().to_string())?;
let llvm_str = c_str.as_ptr();
let llvm_func = unsafe { LLVMGetNamedFunction(llvm_mod, llvm_str) };
if llvm_func.is_null() || unsafe { LLVMIsDeclaration(llvm_func) } != 0 {
result.imports.push((name.clone(), SymbolKind::Function));
}
}
ir::ExternalName::LibCall{..} => {
result.imports.push((name.clone(), SymbolKind::Function));
}
_ => panic!("unhandled: {}", name)
}
}
for global_var in func.il.global_values.keys() {
Expand Down