From 626b89daa4eb433f6e38057d5dfb30ad655ce54c Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 6 Jan 2008 01:20:13 +0000 Subject: [PATCH] further simplifications and cleanup llvm-svn: 45643 --- llvm/utils/TableGen/InstrInfoEmitter.cpp | 94 ++++++++++++++---------- llvm/utils/TableGen/InstrInfoEmitter.h | 10 ++- 2 files changed, 65 insertions(+), 39 deletions(-) diff --git a/llvm/utils/TableGen/InstrInfoEmitter.cpp b/llvm/utils/TableGen/InstrInfoEmitter.cpp index b3ca0aa91272..b406df3f1ba7 100644 --- a/llvm/utils/TableGen/InstrInfoEmitter.cpp +++ b/llvm/utils/TableGen/InstrInfoEmitter.cpp @@ -27,6 +27,33 @@ void InstrInfoEmitter::printDefList(const std::vector &Uses, OS << "0 };\n"; } +//===----------------------------------------------------------------------===// +// Instruction Itinerary Information. +//===----------------------------------------------------------------------===// + +struct RecordNameComparator { + bool operator()(const Record *Rec1, const Record *Rec2) const { + return Rec1->getName() < Rec2->getName(); + } +}; + +void InstrInfoEmitter::GatherItinClasses() { + std::vector DefList = + Records.getAllDerivedDefinitions("InstrItinClass"); + std::sort(DefList.begin(), DefList.end(), RecordNameComparator()); + + for (unsigned i = 0, N = DefList.size(); i < N; i++) + ItinClassMap[DefList[i]->getName()] = i; +} + +unsigned InstrInfoEmitter::getItinClassNumber(const Record *InstRec) { + return ItinClassMap[InstRec->getValueAsDef("Itinerary")->getName()]; +} + +//===----------------------------------------------------------------------===// +// Operand Info Emission. +//===----------------------------------------------------------------------===// + std::vector InstrInfoEmitter::GetOperandInfo(const CodeGenInstruction &Inst) { std::vector Result; @@ -88,6 +115,31 @@ InstrInfoEmitter::GetOperandInfo(const CodeGenInstruction &Inst) { return Result; } +void InstrInfoEmitter::EmitOperandInfo(std::ostream &OS, + OperandInfoMapTy &OperandInfoIDs) { + // ID #0 is for no operand info. + unsigned OperandListNum = 0; + OperandInfoIDs[std::vector()] = ++OperandListNum; + + OS << "\n"; + const CodeGenTarget &Target = CDP.getTargetInfo(); + for (CodeGenTarget::inst_iterator II = Target.inst_begin(), + E = Target.inst_end(); II != E; ++II) { + std::vector OperandInfo = GetOperandInfo(II->second); + unsigned &N = OperandInfoIDs[OperandInfo]; + if (N != 0) continue; + + N = ++OperandListNum; + OS << "static const TargetOperandInfo OperandInfo" << N << "[] = { "; + for (unsigned i = 0, e = OperandInfo.size(); i != e; ++i) + OS << "{ " << OperandInfo[i] << " }, "; + OS << "};\n"; + } +} + +//===----------------------------------------------------------------------===// +// Main Output. +//===----------------------------------------------------------------------===// // run - Emit the main instruction description records for the target... void InstrInfoEmitter::run(std::ostream &OS) { @@ -120,24 +172,10 @@ void InstrInfoEmitter::run(std::ostream &OS) { } } - std::map, unsigned> OperandInfosEmitted; - unsigned OperandListNum = 0; - OperandInfosEmitted[std::vector()] = ++OperandListNum; + OperandInfoMapTy OperandInfoIDs; // Emit all of the operand info records. - OS << "\n"; - for (CodeGenTarget::inst_iterator II = Target.inst_begin(), - E = Target.inst_end(); II != E; ++II) { - std::vector OperandInfo = GetOperandInfo(II->second); - unsigned &N = OperandInfosEmitted[OperandInfo]; - if (N == 0) { - N = ++OperandListNum; - OS << "static const TargetOperandInfo OperandInfo" << N << "[] = { "; - for (unsigned i = 0, e = OperandInfo.size(); i != e; ++i) - OS << "{ " << OperandInfo[i] << " }, "; - OS << "};\n"; - } - } + EmitOperandInfo(OS, OperandInfoIDs); // Emit all of the TargetInstrDescriptor records in their ENUM ordering. // @@ -148,7 +186,7 @@ void InstrInfoEmitter::run(std::ostream &OS) { for (unsigned i = 0, e = NumberedInstructions.size(); i != e; ++i) emitRecord(*NumberedInstructions[i], i, InstrInfo, EmittedLists, - OperandInfosEmitted, OS); + OperandInfoIDs, OS); OS << "};\n"; OS << "} // End llvm namespace \n"; } @@ -156,7 +194,7 @@ void InstrInfoEmitter::run(std::ostream &OS) { void InstrInfoEmitter::emitRecord(const CodeGenInstruction &Inst, unsigned Num, Record *InstrInfo, std::map, unsigned> &EmittedLists, - std::map, unsigned> &OpInfo, + const OperandInfoMapTy &OpInfo, std::ostream &OS) { int MinOperands; if (!Inst.OperandList.empty()) @@ -250,29 +288,11 @@ void InstrInfoEmitter::emitRecord(const CodeGenInstruction &Inst, unsigned Num, if (OperandInfo.empty()) OS << "0"; else - OS << "OperandInfo" << OpInfo[OperandInfo]; + OS << "OperandInfo" << OpInfo.find(OperandInfo)->second; OS << " }, // Inst #" << Num << " = " << Inst.TheDef->getName() << "\n"; } -struct RecordNameComparator { - bool operator()(const Record *Rec1, const Record *Rec2) const { - return Rec1->getName() < Rec2->getName(); - } -}; - -void InstrInfoEmitter::GatherItinClasses() { - std::vector DefList = - Records.getAllDerivedDefinitions("InstrItinClass"); - std::sort(DefList.begin(), DefList.end(), RecordNameComparator()); - - for (unsigned i = 0, N = DefList.size(); i < N; i++) - ItinClassMap[DefList[i]->getName()] = i; -} - -unsigned InstrInfoEmitter::getItinClassNumber(const Record *InstRec) { - return ItinClassMap[InstRec->getValueAsDef("Itinerary")->getName()]; -} void InstrInfoEmitter::emitShiftedValue(Record *R, StringInit *Val, IntInit *ShiftInt, std::ostream &OS) { diff --git a/llvm/utils/TableGen/InstrInfoEmitter.h b/llvm/utils/TableGen/InstrInfoEmitter.h index 5893d4473bf7..b6d02459a5cf 100644 --- a/llvm/utils/TableGen/InstrInfoEmitter.h +++ b/llvm/utils/TableGen/InstrInfoEmitter.h @@ -39,18 +39,24 @@ public: void run(std::ostream &OS); private: + typedef std::map, unsigned> OperandInfoMapTy; + void printDefList(const std::vector &Uses, unsigned Num, std::ostream &OS) const; void emitRecord(const CodeGenInstruction &Inst, unsigned Num, Record *InstrInfo, std::map, unsigned> &EL, - std::map, unsigned> &OpInfo, + const OperandInfoMapTy &OpInfo, std::ostream &OS); + void GatherItinClasses(); unsigned getItinClassNumber(const Record *InstRec); + + void EmitOperandInfo(std::ostream &OS, OperandInfoMapTy &OperandInfoIDs); + std::vector GetOperandInfo(const CodeGenInstruction &Inst); + void emitShiftedValue(Record *R, StringInit *Val, IntInit *Shift, std::ostream &OS); - std::vector GetOperandInfo(const CodeGenInstruction &Inst); }; } // End llvm namespace