From 524ba5d33e17c193cea3d055b7b15a4830f01e80 Mon Sep 17 00:00:00 2001 From: Jay Foad Date: Wed, 16 Jul 2025 16:07:35 +0100 Subject: [PATCH 1/2] [TableGen] Add some -time-phases support in CodeGenRegisters --- llvm/utils/TableGen/Common/CodeGenRegisters.cpp | 11 ++++++++++- llvm/utils/TableGen/Common/CodeGenRegisters.h | 2 ++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/llvm/utils/TableGen/Common/CodeGenRegisters.cpp b/llvm/utils/TableGen/Common/CodeGenRegisters.cpp index 28b542f09e8c0..1730139ec0712 100644 --- a/llvm/utils/TableGen/Common/CodeGenRegisters.cpp +++ b/llvm/utils/TableGen/Common/CodeGenRegisters.cpp @@ -30,6 +30,7 @@ #include "llvm/Support/raw_ostream.h" #include "llvm/TableGen/Error.h" #include "llvm/TableGen/Record.h" +#include "llvm/TableGen/TGTimer.h" #include #include #include @@ -1130,7 +1131,7 @@ CodeGenRegisterCategory::CodeGenRegisterCategory(CodeGenRegBank &RegBank, CodeGenRegBank::CodeGenRegBank(const RecordKeeper &Records, const CodeGenHwModes &Modes) - : CGH(Modes) { + : Records(Records), CGH(Modes) { // Configure register Sets to understand register classes and tuples. Sets.addFieldExpander("RegisterClass", "MemberList"); Sets.addFieldExpander("CalleeSavedRegs", "SaveList"); @@ -2202,7 +2203,9 @@ void CodeGenRegBank::computeDerivedInfo() { // Compute a weight for each register unit created during getSubRegs. // This may create adopted register units (with unit # >= NumNativeRegUnits). + Records.getTimer().startTimer("Compute reg unit weights"); computeRegUnitWeights(); + Records.getTimer().stopTimer(); // Compute a unique set of RegUnitSets. One for each RegClass and inferred // supersets for the union of overlapping sets. @@ -2450,6 +2453,8 @@ void CodeGenRegBank::computeInferredRegisterClasses() { // added. auto FirstNewRC = std::prev(RegClasses.end()); + Records.getTimer().startTimer("Compute inferred register classes"); + // Visit all register classes, including the ones being added by the loop. // Watch out for iterator invalidation here. for (auto I = RegClasses.begin(), E = RegClasses.end(); I != E; ++I) { @@ -2481,6 +2486,8 @@ void CodeGenRegBank::computeInferredRegisterClasses() { } } + Records.getTimer().startTimer("Extend super-register classes"); + // Compute the transitive closure for super-register classes. // // By iterating over sub-register indices in topological order, we only ever @@ -2491,6 +2498,8 @@ void CodeGenRegBank::computeInferredRegisterClasses() { for (CodeGenRegisterClass &SubRC : RegClasses) SubRC.extendSuperRegClasses(SubIdx); } + + Records.getTimer().stopTimer(); } /// getRegisterClassForRegister - Find the register class that contains the diff --git a/llvm/utils/TableGen/Common/CodeGenRegisters.h b/llvm/utils/TableGen/Common/CodeGenRegisters.h index 5e6fff0f775ea..81aa663b8f11e 100644 --- a/llvm/utils/TableGen/Common/CodeGenRegisters.h +++ b/llvm/utils/TableGen/Common/CodeGenRegisters.h @@ -607,6 +607,8 @@ typedef SmallVector TopoSigId; // CodeGenRegBank - Represent a target's registers and the relations between // them. class CodeGenRegBank { + const RecordKeeper &Records; + SetTheory Sets; const CodeGenHwModes &CGH; From 2d6763b7fba891f8dfd2755a57c707dc34f4bb6d Mon Sep 17 00:00:00 2001 From: Jay Foad Date: Thu, 17 Jul 2025 16:15:23 +0100 Subject: [PATCH 2/2] Tweak position of startTimer --- llvm/utils/TableGen/Common/CodeGenRegisters.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/llvm/utils/TableGen/Common/CodeGenRegisters.cpp b/llvm/utils/TableGen/Common/CodeGenRegisters.cpp index 1730139ec0712..f78427940b276 100644 --- a/llvm/utils/TableGen/Common/CodeGenRegisters.cpp +++ b/llvm/utils/TableGen/Common/CodeGenRegisters.cpp @@ -2449,12 +2449,12 @@ void CodeGenRegBank::computeInferredRegisterClasses() { // and assigned EnumValues yet. That means getSubClasses(), // getSuperClasses(), and hasSubClass() functions are defunct. + Records.getTimer().startTimer("Compute inferred register classes"); + // Use one-before-the-end so it doesn't move forward when new elements are // added. auto FirstNewRC = std::prev(RegClasses.end()); - Records.getTimer().startTimer("Compute inferred register classes"); - // Visit all register classes, including the ones being added by the loop. // Watch out for iterator invalidation here. for (auto I = RegClasses.begin(), E = RegClasses.end(); I != E; ++I) {