Skip to content

Commit 94aa8bc

Browse files
committed
fixing gcc memcpy
Signed-off-by: Karan Janthe <[email protected]>
1 parent 2544376 commit 94aa8bc

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

compiler/rustc_codegen_gcc/src/builder.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use gccjit::{
1010
use rustc_abi as abi;
1111
use rustc_abi::{Align, HasDataLayout, Size, TargetDataLayout, WrappingRange};
1212
use rustc_apfloat::{Float, Round, Status, ieee};
13+
use rustc_ast::expand::typetree::FncTree;
1314
use rustc_codegen_ssa::MemFlags;
1415
use rustc_codegen_ssa::common::{
1516
AtomicRmwBinOp, IntPredicate, RealPredicate, SynchronizationScope, TypeKind,
@@ -1368,18 +1369,27 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
13681369
_src_align: Align,
13691370
size: RValue<'gcc>,
13701371
flags: MemFlags,
1372+
tt: Option<FncTree>,
13711373
) {
13721374
assert!(!flags.contains(MemFlags::NONTEMPORAL), "non-temporal memcpy not supported");
13731375
let size = self.intcast(size, self.type_size_t(), false);
13741376
let _is_volatile = flags.contains(MemFlags::VOLATILE);
13751377
let dst = self.pointercast(dst, self.type_i8p());
13761378
let src = self.pointercast(src, self.type_ptr_to(self.type_void()));
13771379
let memcpy = self.context.get_builtin_function("memcpy");
1380+
1381+
// Create the memcpy call
1382+
let call = self.context.new_call(self.___location, memcpy, &[dst, src, size]);
1383+
1384+
// TypeTree metadata for memcpy: when Enzyme encounters a memcpy during autodiff,
1385+
if let Some(_tt) = tt {
1386+
// TODO(KMJ-007): implement TypeTree support for gcc backend
1387+
// For now, we just ignore the TypeTree since gcc backend doesn't support autodiff yet
1388+
// When autodiff support is added to gcc backend, this should attach TypeTree information
1389+
// as function attributes similar to how LLVM backend does it.
1390+
}
13781391
// TODO(antoyo): handle aligns and is_volatile.
1379-
self.block.add_eval(
1380-
self.___location,
1381-
self.context.new_call(self.___location, memcpy, &[dst, src, size]),
1382-
);
1392+
self.block.add_eval(self.___location, call);
13831393
}
13841394

13851395
fn memmove(

compiler/rustc_codegen_gcc/src/intrinsic/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,7 @@ impl<'gcc, 'tcx> ArgAbiExt<'gcc, 'tcx> for ArgAbi<'tcx, Ty<'tcx>> {
771771
scratch_align,
772772
bx.const_usize(self.layout.size.bytes()),
773773
MemFlags::empty(),
774+
None,
774775
);
775776

776777
bx.lifetime_end(scratch, scratch_size);

0 commit comments

Comments
 (0)