diff --git a/MiniC/TP04/AllInMemAllocator.py b/MiniC/TP04/AllInMemAllocator.py index 7e73a27..7b08b30 100644 --- a/MiniC/TP04/AllInMemAllocator.py +++ b/MiniC/TP04/AllInMemAllocator.py @@ -18,15 +18,15 @@ class AllInMemAllocator(Allocator): s_index = 0 for arg in old_instr.args(): if isinstance(arg, Temporary): - # TODO: don't ld/sd when nothing changed (eg don't ld a destination only, - # TODO: don't sd a source only) s_index += 1 - before.append(RiscV.ld( - S[s_index], arg.get_alloced_loc() - )) - after.append(RiscV.sd( - S[s_index], arg.get_alloced_loc() - )) + if arg in old_instr.used(): # needs to be read first + before.append(RiscV.ld( + S[s_index], arg.get_alloced_loc() + )) + if arg in old_instr.defined(): # needs to be stored after + after.append(RiscV.sd( + S[s_index], arg.get_alloced_loc() + )) new_args.append(S[s_index]) else: new_args.append(arg)