From 2423fc419c1f5d0b07553905860f70338a1742c8 Mon Sep 17 00:00:00 2001 From: Quentin Colombet Date: Wed, 6 Apr 2016 16:33:26 +0000 Subject: [PATCH] [RegisterBankInfo] Add a verify method for the PartialMapping helper class. This verifies that the PartialMapping can be accomadated into the related register bank. llvm-svn: 265555 --- .../llvm/CodeGen/GlobalISel/RegisterBankInfo.h | 5 +++++ llvm/lib/CodeGen/GlobalISel/RegisterBankInfo.cpp | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/llvm/include/llvm/CodeGen/GlobalISel/RegisterBankInfo.h b/llvm/include/llvm/CodeGen/GlobalISel/RegisterBankInfo.h index 31e6687..6ec3eea 100644 --- a/llvm/include/llvm/CodeGen/GlobalISel/RegisterBankInfo.h +++ b/llvm/include/llvm/CodeGen/GlobalISel/RegisterBankInfo.h @@ -52,6 +52,11 @@ public: /// Print this partial mapping on \p OS; void print(raw_ostream &OS) const; + + /// Check that the Mask is compatible with the RegBank. + /// Indeed, if the RegBank cannot accomadate the "active bits" of the mask, + /// there is no way this mapping is valid. + void verify() const; }; /// Helper struct that represents how a value is mapped through diff --git a/llvm/lib/CodeGen/GlobalISel/RegisterBankInfo.cpp b/llvm/lib/CodeGen/GlobalISel/RegisterBankInfo.cpp index d882779..ef8cbead 100644 --- a/llvm/lib/CodeGen/GlobalISel/RegisterBankInfo.cpp +++ b/llvm/lib/CodeGen/GlobalISel/RegisterBankInfo.cpp @@ -181,6 +181,25 @@ void RegisterBankInfo::PartialMapping::dump() const { dbgs() << '\n'; } +void RegisterBankInfo::PartialMapping::verify() const { + assert(RegBank && "Register bank not set"); + // Check what is the minimum width that will live into RegBank. + // RegBank will have to, at least, accomodate all the bits between the first + // and last bits active in Mask. + // If Mask is zero, then ActiveWidth is 0. + unsigned ActiveWidth = 0; + // Otherwise, remove the trailing and leading zeros from the bitwidth. + // 0..0 ActiveWidth 0..0. + if (Mask.getBoolValue()) + ActiveWidth = Mask.getBitWidth() - Mask.countLeadingZeros() - + Mask.countTrailingZeros(); + (void)ActiveWidth; + assert(ActiveWidth <= Mask.getBitWidth() && + "Wrong computation of ActiveWidth, overflow?"); + assert(RegBank->getSize() >= ActiveWidth && + "Register bank too small for Mask"); +} + void RegisterBankInfo::PartialMapping::print(raw_ostream &OS) const { SmallString<128> MaskStr; Mask.toString(MaskStr, /*Radix*/ 2, /*Signed*/ 0, /*formatAsCLiteral*/ true); -- 2.7.4