From acb3fbc2c0cb858f572232106b2b95eba8f9b774 Mon Sep 17 00:00:00 2001 From: Andrea Di Biagio Date: Tue, 12 Feb 2019 16:18:57 +0000 Subject: [PATCH] [MCA] Improved debug prints. NFC llvm-svn: 353852 --- include/llvm/MCA/Support.h | 19 ++++--------------- lib/MCA/Stages/ExecuteStage.cpp | 3 ++- lib/MCA/Support.cpp | 21 +++++++++++++++++++-- 3 files changed, 25 insertions(+), 18 deletions(-) diff --git a/include/llvm/MCA/Support.h b/include/llvm/MCA/Support.h index de38c9ccd7a..fc36ed492d1 100644 --- a/include/llvm/MCA/Support.h +++ b/include/llvm/MCA/Support.h @@ -60,24 +60,13 @@ public: return (Denominator == 1) ? Numerator : (double)Numerator / Denominator; } + unsigned getNumerator() const { return Numerator; } + unsigned getDenominator() const { return Denominator; } + // Add the components of RHS to this instance. Instead of calculating // the final value here, we keep track of the numerator and denominator // separately, to reduce floating point error. - ResourceCycles &operator+=(const ResourceCycles &RHS) { - if (Denominator == RHS.Denominator) - Numerator += RHS.Numerator; - else { - // Create a common denominator for LHS and RHS by calculating the least - // common multiple from the GCD. - unsigned GCD = GreatestCommonDivisor64(Denominator, RHS.Denominator); - unsigned LCM = (Denominator * RHS.Denominator) / GCD; - unsigned LHSNumerator = Numerator * (LCM / Denominator); - unsigned RHSNumerator = RHS.Numerator * (LCM / RHS.Denominator); - Numerator = LHSNumerator + RHSNumerator; - Denominator = LCM; - } - return *this; - } + ResourceCycles &operator+=(const ResourceCycles &RHS); }; /// Populates vector Masks with processor resource masks. diff --git a/lib/MCA/Stages/ExecuteStage.cpp b/lib/MCA/Stages/ExecuteStage.cpp index 2060fcdbe39..9e0bd26e6d0 100644 --- a/lib/MCA/Stages/ExecuteStage.cpp +++ b/lib/MCA/Stages/ExecuteStage.cpp @@ -188,9 +188,10 @@ void ExecuteStage::notifyInstructionIssued( LLVM_DEBUG({ dbgs() << "[E] Instruction Issued: #" << IR << '\n'; for (const std::pair &Resource : Used) { + assert(Resource.second.getDenominator() == 1 && "Invalid cycles!"); dbgs() << "[E] Resource Used: [" << Resource.first.first << '.' << Resource.first.second << "], "; - dbgs() << "cycles: " << Resource.second << '\n'; + dbgs() << "cycles: " << Resource.second.getNumerator() << '\n'; } }); diff --git a/lib/MCA/Support.cpp b/lib/MCA/Support.cpp index e11062f4d72..ce1f0f6f211 100644 --- a/lib/MCA/Support.cpp +++ b/lib/MCA/Support.cpp @@ -20,6 +20,22 @@ namespace mca { #define DEBUG_TYPE "llvm-mca" +ResourceCycles &ResourceCycles::operator+=(const ResourceCycles &RHS) { + if (Denominator == RHS.Denominator) + Numerator += RHS.Numerator; + else { + // Create a common denominator for LHS and RHS by calculating the least + // common multiple from the GCD. + unsigned GCD = GreatestCommonDivisor64(Denominator, RHS.Denominator); + unsigned LCM = (Denominator * RHS.Denominator) / GCD; + unsigned LHSNumerator = Numerator * (LCM / Denominator); + unsigned RHSNumerator = RHS.Numerator * (LCM / RHS.Denominator); + Numerator = LHSNumerator + RHSNumerator; + Denominator = LCM; + } + return *this; +} + void computeProcResourceMasks(const MCSchedModel &SM, MutableArrayRef Masks) { unsigned ProcResourceID = 0; @@ -56,8 +72,9 @@ void computeProcResourceMasks(const MCSchedModel &SM, << "\n"); for (unsigned I = 0, E = SM.getNumProcResourceKinds(); I < E; ++I) { const MCProcResourceDesc &Desc = *SM.getProcResource(I); - LLVM_DEBUG(dbgs() << '[' << I << "] " << Desc.Name << " - " << Masks[I] - << '\n'); + LLVM_DEBUG(dbgs() << '[' << format_decimal(I,2) << "] " << " - " + << format_hex(Masks[I],16) << " - " + << Desc.Name << '\n'); } #endif }