diff options
author | David Greene <greened@obbligato.org> | 2011-07-11 18:25:51 +0000 |
---|---|---|
committer | David Greene <greened@obbligato.org> | 2011-07-11 18:25:51 +0000 |
commit | d4a9066c93da9a5aab47ca228d82e796fdec70c0 (patch) | |
tree | f4533e3a9fe75aa310bd4682b254a053af0bfd73 /utils/TableGen/CodeEmitterGen.cpp | |
parent | 7ae0df41422193e65231a0f9526bfe66067c6532 (diff) |
[AVX] Make Inits Foldable
Manage Inits in a FoldingSet. This provides several benefits:
- Memory for Inits is properly managed
- Duplicate Inits are folded into Flyweights, saving memory
- It enforces const-correctness, protecting against certain classes
of bugs
The above benefits allow Inits to be used in more contexts, which in
turn provides more dynamism to TableGen. This enhanced capability
will be used by the AVX code generator to a fold common patterns
together.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@134907 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils/TableGen/CodeEmitterGen.cpp')
-rw-r--r-- | utils/TableGen/CodeEmitterGen.cpp | 38 |
1 files changed, 22 insertions, 16 deletions
diff --git a/utils/TableGen/CodeEmitterGen.cpp b/utils/TableGen/CodeEmitterGen.cpp index d828dfc25d..4b67854d3e 100644 --- a/utils/TableGen/CodeEmitterGen.cpp +++ b/utils/TableGen/CodeEmitterGen.cpp @@ -38,21 +38,25 @@ void CodeEmitterGen::reverseBits(std::vector<Record*> &Insts) { R->getValueAsBit("isPseudo")) continue; - BitsInit *BI = R->getValueAsBitsInit("Inst"); + const BitsInit *BI = R->getValueAsBitsInit("Inst"); unsigned numBits = BI->getNumBits(); - BitsInit *NewBI = new BitsInit(numBits); + + SmallVector<const Init *, 16> NewBits(numBits); + for (unsigned bit = 0, end = numBits / 2; bit != end; ++bit) { unsigned bitSwapIdx = numBits - bit - 1; - Init *OrigBit = BI->getBit(bit); - Init *BitSwap = BI->getBit(bitSwapIdx); - NewBI->setBit(bit, BitSwap); - NewBI->setBit(bitSwapIdx, OrigBit); + const Init *OrigBit = BI->getBit(bit); + const Init *BitSwap = BI->getBit(bitSwapIdx); + NewBits[bit] = BitSwap; + NewBits[bitSwapIdx] = OrigBit; } if (numBits % 2) { unsigned middle = (numBits + 1) / 2; - NewBI->setBit(middle, BI->getBit(middle)); + NewBits[middle] = BI->getBit(middle); } + + const BitsInit *NewBI = BitsInit::Create(NewBits.begin(), NewBits.end()); // Update the bits in reversed order so that emitInstrOpBits will get the // correct endianness. @@ -63,12 +67,14 @@ void CodeEmitterGen::reverseBits(std::vector<Record*> &Insts) { // If the VarBitInit at position 'bit' matches the specified variable then // return the variable bit position. Otherwise return -1. int CodeEmitterGen::getVariableBit(const std::string &VarName, - BitsInit *BI, int bit) { - if (VarBitInit *VBI = dynamic_cast<VarBitInit*>(BI->getBit(bit))) { - if (VarInit *VI = dynamic_cast<VarInit*>(VBI->getVariable())) + const BitsInit *BI, int bit) { + if (const VarBitInit *VBI = + dynamic_cast<const VarBitInit*>(BI->getBit(bit))) { + if (const VarInit *VI = dynamic_cast<const VarInit*>(VBI->getVariable())) if (VI->getName() == VarName) return VBI->getBitNum(); - } else if (VarInit *VI = dynamic_cast<VarInit*>(BI->getBit(bit))) { + } else if (const VarInit *VI = + dynamic_cast<const VarInit*>(BI->getBit(bit))) { if (VI->getName() == VarName) return 0; } @@ -77,8 +83,8 @@ int CodeEmitterGen::getVariableBit(const std::string &VarName, } void CodeEmitterGen:: -AddCodeToMergeInOperand(Record *R, BitsInit *BI, const std::string &VarName, - unsigned &NumberedOp, +AddCodeToMergeInOperand(Record *R, const BitsInit *BI, + const std::string &VarName, unsigned &NumberedOp, std::string &Case, CodeGenTarget &Target) { CodeGenInstruction &CGI = Target.getInstruction(R); @@ -181,7 +187,7 @@ std::string CodeEmitterGen::getInstructionCase(Record *R, CodeGenTarget &Target) { std::string Case; - BitsInit *BI = R->getValueAsBitsInit("Inst"); + const BitsInit *BI = R->getValueAsBitsInit("Inst"); const std::vector<RecordVal> &Vals = R->getValues(); unsigned NumberedOp = 0; @@ -238,12 +244,12 @@ void CodeEmitterGen::run(raw_ostream &o) { continue; } - BitsInit *BI = R->getValueAsBitsInit("Inst"); + const BitsInit *BI = R->getValueAsBitsInit("Inst"); // Start by filling in fixed values. unsigned Value = 0; for (unsigned i = 0, e = BI->getNumBits(); i != e; ++i) { - if (BitInit *B = dynamic_cast<BitInit*>(BI->getBit(e-i-1))) + if (const BitInit *B = dynamic_cast<const BitInit*>(BI->getBit(e-i-1))) Value |= B->getValue() << (e-i-1); } o << " " << Value << "U," << '\t' << "// " << R->getName() << "\n"; |