aboutsummaryrefslogtreecommitdiff
path: root/backend/lib/CodeGen/MachineFunctionRecords.cpp
diff options
context:
space:
mode:
authorRichard-Qin-X <richard.qin.001@gmail.com>2026-08-09 17:03:19 +0800
committerRichard-Qin-X <richard.qin.001@gmail.com>2026-08-09 17:03:19 +0800
commit495c675771f43cfa12ab7a426a538be72fec1805 (patch)
tree4107223d6c6ef2e74d56064aa21b196307502342 /backend/lib/CodeGen/MachineFunctionRecords.cpp
parentda8bc76b4bf7d1a7b025d6c8ef5809551467dcc7 (diff)
downloadrcc-project-495c675771f43cfa12ab7a426a538be72fec1805.tar.gz
rcc-project-495c675771f43cfa12ab7a426a538be72fec1805.tar.xz
[CodeGen] Implement machine optimization and scheduling
Diffstat (limited to 'backend/lib/CodeGen/MachineFunctionRecords.cpp')
-rw-r--r--backend/lib/CodeGen/MachineFunctionRecords.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/backend/lib/CodeGen/MachineFunctionRecords.cpp b/backend/lib/CodeGen/MachineFunctionRecords.cpp
index 0a21581..18ac596 100644
--- a/backend/lib/CodeGen/MachineFunctionRecords.cpp
+++ b/backend/lib/CodeGen/MachineFunctionRecords.cpp
@@ -127,6 +127,38 @@ Expected<void> MachineFunctionRecords::addCalledGlobal(MachineCalledGlobal Calle
return {};
}
+Expected<void>
+MachineFunctionRecords::replaceInstructionReference(MachineInstrStableID OldInstruction,
+ MachineInstrStableID NewInstruction) {
+ if (!OldInstruction.isValid() || !NewInstruction.isValid()) {
+ return makeUnexpected(ErrorCode::InvalidArgument,
+ "instruction-record replacement requires two valid stable IDs");
+ }
+ if (OldInstruction == NewInstruction)
+ return {};
+ for (const MachineCallSiteInfo &CallSite : CallSites) {
+ if (CallSite.CallInstruction == NewInstruction) {
+ return makeUnexpected(ErrorCode::InvalidArgument,
+ "replacement instruction already owns a call-site record");
+ }
+ }
+ for (const MachineCalledGlobal &CalledGlobal : CalledGlobals) {
+ if (CalledGlobal.CallInstruction == NewInstruction) {
+ return makeUnexpected(ErrorCode::InvalidArgument,
+ "replacement instruction already owns a called-global record");
+ }
+ }
+ for (MachineCallSiteInfo &CallSite : CallSites) {
+ if (CallSite.CallInstruction == OldInstruction)
+ CallSite.CallInstruction = NewInstruction;
+ }
+ for (MachineCalledGlobal &CalledGlobal : CalledGlobals) {
+ if (CalledGlobal.CallInstruction == OldInstruction)
+ CalledGlobal.CallInstruction = NewInstruction;
+ }
+ return {};
+}
+
Expected<void> MachineFunctionRecords::addPrefetchTarget(MachinePrefetchTarget Target) {
if (std::ranges::find(PrefetchTargets, Target) != PrefetchTargets.end()) {
return makeUnexpected(ErrorCode::InvalidArgument, "prefetch target is already recorded");