[llvm-commits] [llvm] r45642 - in /llvm/trunk/utils/TableGen: InstrInfoEmitter.cpp InstrInfoEmitter.h
Chris Lattner
sabre at nondot.org
Sat Jan 5 17:12:44 PST 2008
Author: lattner
Date: Sat Jan 5 19:12:44 2008
New Revision: 45642
URL: http://llvm.org/viewvc/llvm-project?rev=45642&view=rev
Log:
simplify some code
Modified:
llvm/trunk/utils/TableGen/InstrInfoEmitter.cpp
llvm/trunk/utils/TableGen/InstrInfoEmitter.h
Modified: llvm/trunk/utils/TableGen/InstrInfoEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/InstrInfoEmitter.cpp?rev=45642&r1=45641&r2=45642&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/InstrInfoEmitter.cpp (original)
+++ llvm/trunk/utils/TableGen/InstrInfoEmitter.cpp Sat Jan 5 19:12:44 2008
@@ -175,10 +175,7 @@
else
OS << Inst.Name;
- unsigned ItinClass = !IsItineraries ? 0 :
- ItinClassNumber(Inst.TheDef->getValueAsDef("Itinerary")->getName());
-
- OS << "\",\t" << ItinClass << ", 0";
+ OS << "\",\t" << getItinClassNumber(Inst.TheDef) << ", 0";
// Try to determine (from the pattern), if the instruction is a store.
bool isStore = false;
@@ -258,28 +255,23 @@
OS << " }, // Inst #" << Num << " = " << Inst.TheDef->getName() << "\n";
}
-struct LessRecord {
+struct RecordNameComparator {
bool operator()(const Record *Rec1, const Record *Rec2) const {
return Rec1->getName() < Rec2->getName();
}
};
+
void InstrInfoEmitter::GatherItinClasses() {
std::vector<Record*> DefList =
Records.getAllDerivedDefinitions("InstrItinClass");
- IsItineraries = !DefList.empty();
-
- if (!IsItineraries) return;
-
- std::sort(DefList.begin(), DefList.end(), LessRecord());
+ std::sort(DefList.begin(), DefList.end(), RecordNameComparator());
- for (unsigned i = 0, N = DefList.size(); i < N; i++) {
- Record *Def = DefList[i];
- ItinClassMap[Def->getName()] = i;
- }
+ for (unsigned i = 0, N = DefList.size(); i < N; i++)
+ ItinClassMap[DefList[i]->getName()] = i;
}
-unsigned InstrInfoEmitter::ItinClassNumber(std::string ItinName) {
- return ItinClassMap[ItinName];
+unsigned InstrInfoEmitter::getItinClassNumber(const Record *InstRec) {
+ return ItinClassMap[InstRec->getValueAsDef("Itinerary")->getName()];
}
void InstrInfoEmitter::emitShiftedValue(Record *R, StringInit *Val,
Modified: llvm/trunk/utils/TableGen/InstrInfoEmitter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/InstrInfoEmitter.h?rev=45642&r1=45641&r2=45642&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/InstrInfoEmitter.h (original)
+++ llvm/trunk/utils/TableGen/InstrInfoEmitter.h Sat Jan 5 19:12:44 2008
@@ -16,6 +16,7 @@
#define INSTRINFO_EMITTER_H
#include "TableGenBackend.h"
+#include "CodeGenDAGPatterns.h"
#include <vector>
#include <map>
@@ -28,11 +29,11 @@
class InstrInfoEmitter : public TableGenBackend {
RecordKeeper &Records;
- bool IsItineraries;
+ CodeGenDAGPatterns CDP;
std::map<std::string, unsigned> ItinClassMap;
public:
- InstrInfoEmitter(RecordKeeper &R) : Records(R), IsItineraries(false) {}
+ InstrInfoEmitter(RecordKeeper &R) : Records(R), CDP(R) { }
// run - Output the instruction set description, returning true on failure.
void run(std::ostream &OS);
@@ -46,7 +47,7 @@
std::map<std::vector<std::string>, unsigned> &OpInfo,
std::ostream &OS);
void GatherItinClasses();
- unsigned ItinClassNumber(std::string ItinName);
+ unsigned getItinClassNumber(const Record *InstRec);
void emitShiftedValue(Record *R, StringInit *Val, IntInit *Shift,
std::ostream &OS);
std::vector<std::string> GetOperandInfo(const CodeGenInstruction &Inst);
More information about the llvm-commits
mailing list