From ff1ebcc5fe19c7f9a3da9d505e66f07ac89700b4 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Sun, 13 Nov 2022 01:15:54 -0800 Subject: [PATCH] DecoderEmitter: Simplify addOneOperandFields. NFC Follow-up to d1fbdf5bf79219549bc1fde255186d02f646a46f --- llvm/utils/TableGen/DecoderEmitter.cpp | 66 +++++++++++----------------------- 1 file changed, 20 insertions(+), 46 deletions(-) diff --git a/llvm/utils/TableGen/DecoderEmitter.cpp b/llvm/utils/TableGen/DecoderEmitter.cpp index fe53350..087875b 100644 --- a/llvm/utils/TableGen/DecoderEmitter.cpp +++ b/llvm/utils/TableGen/DecoderEmitter.cpp @@ -1918,55 +1918,29 @@ static void addOneOperandFields(const Record &EncodingDef, const BitsInit &Bits, if (OpBit->getValue()) OpInfo.InitValue |= 1ULL << I; - unsigned Base = ~0U; - unsigned Width = 0; - unsigned Offset = 0; - - for (unsigned bi = 0; bi < Bits.getNumBits(); ++bi) { - VarInit *Var = nullptr; - VarBitInit *BI = dyn_cast(Bits.getBit(bi)); - if (BI) - Var = dyn_cast(BI->getBitVar()); - else - Var = dyn_cast(Bits.getBit(bi)); - - if (!Var) { - if (Base != ~0U) { - OpInfo.addField(Base, Width, Offset); - Base = ~0U; - Width = 0; - Offset = 0; - } - continue; - } - - if ((Var->getName() != OpName && - Var->getName() != TiedNames[std::string(OpName)])) { - if (Base != ~0U) { - OpInfo.addField(Base, Width, Offset); - Base = ~0U; - Width = 0; - Offset = 0; + for (unsigned I = 0, J = 0; I != Bits.getNumBits(); I = J) { + VarInit *Var; + unsigned Offset = 0; + for (; J != Bits.getNumBits(); ++J) { + VarBitInit *BJ = dyn_cast(Bits.getBit(J)); + if (BJ) { + Var = dyn_cast(BJ->getBitVar()); + if (I == J) + Offset = BJ->getBitNum(); + else if (BJ->getBitNum() != Offset + J - I) + break; + } else { + Var = dyn_cast(Bits.getBit(J)); } - continue; - } - - if (Base == ~0U) { - Base = bi; - Width = 1; - Offset = BI ? BI->getBitNum() : 0; - } else if (BI && BI->getBitNum() != Offset + Width) { - OpInfo.addField(Base, Width, Offset); - Base = bi; - Width = 1; - Offset = BI->getBitNum(); - } else { - ++Width; + if (!Var || (Var->getName() != OpName && + Var->getName() != TiedNames[std::string(OpName)])) + break; } + if (I == J) + ++J; + else + OpInfo.addField(I, J - I, Offset); } - - if (Base != ~0U) - OpInfo.addField(Base, Width, Offset); } static unsigned -- 2.7.4