From 56277e3e10d204e26e7884c4d978b82fd1620f02 Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Thu, 11 Feb 2021 21:02:50 -0800 Subject: [PATCH] [TableGen] Make the map in InfoByHwMode protected. NFCI Switch some for loops to just use the begin()/end() implementations in the InfoByHwMode struct. Add a method to insert into the map for the one case that was modifying the map directly. --- llvm/utils/TableGen/CodeEmitterGen.cpp | 4 ++-- llvm/utils/TableGen/CodeGenRegisters.cpp | 2 +- llvm/utils/TableGen/FixedLenDecoderEmitter.cpp | 4 ++-- llvm/utils/TableGen/InfoByHwMode.h | 5 +++++ 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/llvm/utils/TableGen/CodeEmitterGen.cpp b/llvm/utils/TableGen/CodeEmitterGen.cpp index 3b77f09..24cb485 100644 --- a/llvm/utils/TableGen/CodeEmitterGen.cpp +++ b/llvm/utils/TableGen/CodeEmitterGen.cpp @@ -272,7 +272,7 @@ std::string CodeEmitterGen::getInstructionCase(Record *R, EncodingInfoByHwMode EBM(DI->getDef(), HWM); Case += " switch (HwMode) {\n"; Case += " default: llvm_unreachable(\"Unhandled HwMode\");\n"; - for (auto &KV : EBM.Map) { + for (auto &KV : EBM) { Case += " case " + itostr(KV.first) + ": {\n"; Case += getInstructionCaseForEncoding(R, KV.second, Target); Case += " break;\n"; @@ -409,7 +409,7 @@ void CodeEmitterGen::run(raw_ostream &o) { if (const RecordVal *RV = R->getValue("EncodingInfos")) { if (DefInit *DI = dyn_cast_or_null(RV->getValue())) { EncodingInfoByHwMode EBM(DI->getDef(), HWM); - for (auto &KV : EBM.Map) { + for (auto &KV : EBM) { BitsInit *BI = KV.second->getValueAsBitsInit("Inst"); BitWidth = std::max(BitWidth, BI->getNumBits()); HwModes.insert(KV.first); diff --git a/llvm/utils/TableGen/CodeGenRegisters.cpp b/llvm/utils/TableGen/CodeGenRegisters.cpp index d0c9db4..5ef3cf9 100644 --- a/llvm/utils/TableGen/CodeGenRegisters.cpp +++ b/llvm/utils/TableGen/CodeGenRegisters.cpp @@ -796,7 +796,7 @@ CodeGenRegisterClass::CodeGenRegisterClass(CodeGenRegBank &RegBank, Record *R) RI.RegSize = RI.SpillSize = Size ? Size : VTs[0].getSimple().getSizeInBits(); RI.SpillAlignment = R->getValueAsInt("Alignment"); - RSI.Map.insert({DefaultMode, RI}); + RSI.insertRegSizeForMode(DefaultMode, RI); } CopyCost = R->getValueAsInt("CopyCost"); diff --git a/llvm/utils/TableGen/FixedLenDecoderEmitter.cpp b/llvm/utils/TableGen/FixedLenDecoderEmitter.cpp index e4ecb5d..b5a280b 100644 --- a/llvm/utils/TableGen/FixedLenDecoderEmitter.cpp +++ b/llvm/utils/TableGen/FixedLenDecoderEmitter.cpp @@ -2418,7 +2418,7 @@ void FixedLenDecoderEmitter::run(raw_ostream &o) { if (auto *DI = dyn_cast_or_null(RV->getValue())) { const CodeGenHwModes &HWM = Target.getHwModes(); EncodingInfoByHwMode EBM(DI->getDef(), HWM); - for (auto &KV : EBM.Map) + for (auto &KV : EBM) HwModeNames.insert(HWM.getMode(KV.first).Name); } } @@ -2436,7 +2436,7 @@ void FixedLenDecoderEmitter::run(raw_ostream &o) { if (DefInit *DI = dyn_cast_or_null(RV->getValue())) { const CodeGenHwModes &HWM = Target.getHwModes(); EncodingInfoByHwMode EBM(DI->getDef(), HWM); - for (auto &KV : EBM.Map) { + for (auto &KV : EBM) { NumberedEncodings.emplace_back(KV.second, NumberedInstruction, HWM.getMode(KV.first).Name); HwModeNames.insert(HWM.getMode(KV.first).Name); diff --git a/llvm/utils/TableGen/InfoByHwMode.h b/llvm/utils/TableGen/InfoByHwMode.h index d92e590..4233a58 100644 --- a/llvm/utils/TableGen/InfoByHwMode.h +++ b/llvm/utils/TableGen/InfoByHwMode.h @@ -114,6 +114,7 @@ struct InfoByHwMode { Map.insert(std::make_pair(DefaultMode, I)); } +protected: MapType Map; }; @@ -178,6 +179,10 @@ struct RegSizeInfoByHwMode : public InfoByHwMode { bool hasStricterSpillThan(const RegSizeInfoByHwMode &I) const; void writeToStream(raw_ostream &OS) const; + + void insertRegSizeForMode(unsigned Mode, RegSizeInfo Info) { + Map.insert(std::make_pair(Mode, Info)); + } }; raw_ostream &operator<<(raw_ostream &OS, const ValueTypeByHwMode &T); -- 2.7.4