From 13ac0c234e114241515f0d937060fb8283cf7e31 Mon Sep 17 00:00:00 2001 From: MerryMage Date: Fri, 24 Feb 2017 20:19:50 +0000 Subject: [PATCH] reg_alloc: Differentiate between ReadLock and WriteLock --- src/backend_x64/reg_alloc.cpp | 16 ++++++---------- src/backend_x64/reg_alloc.h | 10 +++++++++- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/backend_x64/reg_alloc.cpp b/src/backend_x64/reg_alloc.cpp index efb31e46..6f9a1f6d 100644 --- a/src/backend_x64/reg_alloc.cpp +++ b/src/backend_x64/reg_alloc.cpp @@ -124,7 +124,7 @@ HostLoc RegAlloc::UseHostLocReg(IR::Inst* use_inst, HostLocList desired_location const bool can_use_current_location = std::find(desired_locations.begin(), desired_locations.end(), current_location) != desired_locations.end(); if (can_use_current_location) { - LocInfo(current_location).Lock(); + LocInfo(current_location).ReadLock(); return current_location; } @@ -139,7 +139,7 @@ HostLoc RegAlloc::UseHostLocReg(IR::Inst* use_inst, HostLocList desired_location MoveOutOfTheWay(destination_location); Move(destination_location, current_location); } - LocInfo(destination_location).Lock(); + LocInfo(destination_location).ReadLock(); return destination_location; } @@ -169,21 +169,21 @@ HostLoc RegAlloc::UseScratchHostLocReg(IR::Inst* use_inst, HostLocList desired_l const bool can_use_current_location = std::find(desired_locations.begin(), desired_locations.end(), current_location) != desired_locations.end(); if (can_use_current_location && !LocInfo(current_location).IsLocked()) { MoveOutOfTheWay(current_location); - LocInfo(current_location).Lock(); + LocInfo(current_location).WriteLock(); return current_location; } const HostLoc destination_location = SelectARegister(desired_locations); MoveOutOfTheWay(destination_location); CopyToScratch(destination_location, current_location); - LocInfo(destination_location).Lock(); + LocInfo(destination_location).WriteLock(); return destination_location; } HostLoc RegAlloc::ScratchHostLocReg(HostLocList desired_locations) { HostLoc location = SelectARegister(desired_locations); MoveOutOfTheWay(location); - LocInfo(location).Lock(); + LocInfo(location).WriteLock(); return location; } @@ -261,11 +261,7 @@ void RegAlloc::SpillRegister(HostLoc loc) { ASSERT_MSG(!LocInfo(loc).IsLocked(), "Registers that have been allocated must not be spilt"); HostLoc new_loc = FindFreeSpill(); - - EmitMove(code, new_loc, loc); - - LocInfo(new_loc) = LocInfo(loc); - LocInfo(loc) = {}; + Move(new_loc, loc); } HostLoc RegAlloc::FindFreeSpill() const { diff --git a/src/backend_x64/reg_alloc.h b/src/backend_x64/reg_alloc.h index 360f8a9f..3bbc5a04 100644 --- a/src/backend_x64/reg_alloc.h +++ b/src/backend_x64/reg_alloc.h @@ -38,9 +38,15 @@ public: return std::find(values.begin(), values.end(), inst) != values.end(); } - void Lock() { + void ReadLock() { + ASSERT(!is_scratch); is_being_used = true; } + void WriteLock() { + ASSERT(!is_being_used); + is_being_used = true; + is_scratch = true; + } void AddValue(IR::Inst* inst) { values.push_back(inst); } @@ -50,11 +56,13 @@ public: values.erase(to_erase, values.end()); is_being_used = false; + is_scratch = false; } private: std::vector values; bool is_being_used = false; + bool is_scratch = false; }; class RegAlloc final {