Skip to content

Commit bbc56b4

Browse files
committed
start filling the offload call
1 parent 8e5152e commit bbc56b4

File tree

1 file changed

+18
-6
lines changed
  • compiler/rustc_codegen_llvm/src/back

1 file changed

+18
-6
lines changed

compiler/rustc_codegen_llvm/src/back/lto.rs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ fn enable_autodiff_settings(ad: &[config::AutoDiff]) {
632632
llvm::set_rust_rules(true);
633633
}
634634

635-
fn gen_globals<'ll>(cx: &'ll SimpleCx<'_>) -> (&'ll llvm::Type, &'ll llvm::Value) {
635+
fn gen_globals<'ll>(cx: &'ll SimpleCx<'_>) -> (&'ll llvm::Type, &'ll llvm::Value, &'ll llvm::Value, &'ll llvm::Value, &'ll llvm::Value, &'ll llvm::Type) {
636636
let offload_entry_ty = cx.type_named_struct("struct.__tgt_offload_entry");
637637
let kernel_arguments_ty = cx.type_named_struct("struct.__tgt_kernel_arguments");
638638
let tptr = cx.type_ptr();
@@ -708,7 +708,7 @@ fn gen_globals<'ll>(cx: &'ll SimpleCx<'_>) -> (&'ll llvm::Type, &'ll llvm::Value
708708
attributes::apply_to_llfn(bar, Function, &[nounwind]);
709709
attributes::apply_to_llfn(baz, Function, &[nounwind]);
710710

711-
(offload_entry_ty, at_one)
711+
(offload_entry_ty, at_one, foo, bar, baz, mapper_fn_ty)
712712
}
713713

714714
fn add_priv_unnamed_arr<'ll>(cx: &SimpleCx<'ll>, name: &str, vals: &[u64]) -> &'ll llvm::Value{
@@ -797,7 +797,7 @@ fn gen_define_handling<'ll>(cx: &'ll SimpleCx<'_>, offload_entry_ty: &'ll llvm::
797797
// 5. @.offloading.entry.__omp_offloading_86fafab6_c40006a1__Z3fooPSt7complexIdES1_S0_m_l7 = weak constant %struct.__tgt_offload_entry { i64 0, i16 1, i16 1, i32 0, ptr @.__omp_offloading_86fafab6_c40006a1__Z3fooPSt7complexIdES1_S0_m_l7.region_id, ptr @.offloading.entry_name, i64 0, i64 0, ptr null }, section "omp_offloading_entries", align 1
798798
}
799799

800-
fn gen_call_handling<'ll>(cx: &'ll SimpleCx<'_>, s_ident_t: &'ll llvm::Value) {
800+
fn gen_call_handling<'ll>(cx: &'ll SimpleCx<'_>, s_ident_t: &'ll llvm::Value, begin: &'ll llvm::Value, update: &'ll llvm::Value, end: &'ll llvm::Value, fn_ty: &'ll llvm::Type) {
801801

802802
let main_fn = cx.get_function("main");
803803
if let Some(main_fn) = main_fn {
@@ -810,10 +810,22 @@ fn gen_call_handling<'ll>(cx: &'ll SimpleCx<'_>, s_ident_t: &'ll llvm::Value) {
810810
return;
811811
};
812812
let kernel_call_bb = unsafe {llvm::LLVMGetInstructionParent(kernel_call)};
813-
let builder = SBuilder::build(cx, kernel_call_bb);
813+
let mut builder = SBuilder::build(cx, kernel_call_bb);
814814
unsafe {llvm::LLVMRustPositionBefore(builder.llbuilder, kernel_call)};
815815
dbg!("positioned builder, ready");
816816

817+
let nullptr = cx.const_null(cx.type_ptr());
818+
let args = vec![s_ident_t, cx.get_const_i64(u64::MAX), cx.get_const_i32(3), nullptr, nullptr, nullptr, nullptr, nullptr, nullptr];
819+
dbg!(&fn_ty);
820+
dbg!(&begin);
821+
dbg!(&args);
822+
builder.call(fn_ty, begin, &args, None);
823+
dbg!("called begin");
824+
//llty: &'ll Type,
825+
//llfn: &'ll Value,
826+
//args: &[&'ll Value],
827+
//funclet: Option<&Funclet<'ll>>,
828+
817829
// 1. set insert point before kernel call.
818830
// 2. generate all the GEPS and stores.
819831
// 3. generate __tgt_target_data calls.
@@ -880,7 +892,7 @@ pub(crate) fn run_pass_manager(
880892
SimpleCx::new(module.module_llvm.llmod(), &module.module_llvm.llcx, cgcx.pointer_size);
881893
if cx.get_function("gen_tgt_offload").is_some() {
882894

883-
let (offload_entry_ty, at_one) = gen_globals(&cx);
895+
let (offload_entry_ty, at_one, foo, bar, baz, fn_ty) = gen_globals(&cx);
884896

885897
dbg!("created struct");
886898
for num in 0..9 {
@@ -890,7 +902,7 @@ pub(crate) fn run_pass_manager(
890902
// TODO: replace num by proper fn name
891903
gen_define_handling(&cx, offload_entry_ty, num);
892904
}
893-
gen_call_handling(&cx, at_one);
905+
gen_call_handling(&cx, at_one, foo, bar, baz, fn_ty);
894906
} else {
895907
dbg!("no marker found");
896908
}

0 commit comments

Comments
 (0)