Skip to content

Commit 37886d1

Browse files
committed
fixing gcc memcpy
Signed-off-by: Karan Janthe <[email protected]>
1 parent 3ee6f4c commit 37886d1

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,
@@ -1364,18 +1365,27 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
13641365
_src_align: Align,
13651366
size: RValue<'gcc>,
13661367
flags: MemFlags,
1368+
tt: Option<FncTree>,
13671369
) {
13681370
assert!(!flags.contains(MemFlags::NONTEMPORAL), "non-temporal memcpy not supported");
13691371
let size = self.intcast(size, self.type_size_t(), false);
13701372
let _is_volatile = flags.contains(MemFlags::VOLATILE);
13711373
let dst = self.pointercast(dst, self.type_i8p());
13721374
let src = self.pointercast(src, self.type_ptr_to(self.type_void()));
13731375
let memcpy = self.context.get_builtin_function("memcpy");
1376+
1377+
// Create the memcpy call
1378+
let call = self.context.new_call(self.location, memcpy, &[dst, src, size]);
1379+
1380+
// TypeTree metadata for memcpy: when Enzyme encounters a memcpy during autodiff,
1381+
if let Some(_tt) = tt {
1382+
// TODO(KMJ-007): implement TypeTree support for gcc backend
1383+
// For now, we just ignore the TypeTree since gcc backend doesn't support autodiff yet
1384+
// When autodiff support is added to gcc backend, this should attach TypeTree information
1385+
// as function attributes similar to how LLVM backend does it.
1386+
}
13741387
// TODO(antoyo): handle aligns and is_volatile.
1375-
self.block.add_eval(
1376-
self.location,
1377-
self.context.new_call(self.location, memcpy, &[dst, src, size]),
1378-
);
1388+
self.block.add_eval(self.location, call);
13791389
}
13801390

13811391
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)