mirror of
https://github.com/RPCSX/llvm.git
synced 2025-04-06 18:21:51 +00:00
c++11: Tidy up tblgen w/ range loops.
IntrInfoEmitter cleanup. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@206553 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
bfe74b9bfb
commit
b08b9d7c09
@ -88,7 +88,7 @@ std::vector<std::string>
|
|||||||
InstrInfoEmitter::GetOperandInfo(const CodeGenInstruction &Inst) {
|
InstrInfoEmitter::GetOperandInfo(const CodeGenInstruction &Inst) {
|
||||||
std::vector<std::string> Result;
|
std::vector<std::string> Result;
|
||||||
|
|
||||||
for (unsigned i = 0, e = Inst.Operands.size(); i != e; ++i) {
|
for (auto &Op : Inst.Operands) {
|
||||||
// Handle aggregate operands and normal operands the same way by expanding
|
// Handle aggregate operands and normal operands the same way by expanding
|
||||||
// either case into a list of operands for this op.
|
// either case into a list of operands for this op.
|
||||||
std::vector<CGIOperandList::OperandInfo> OperandList;
|
std::vector<CGIOperandList::OperandInfo> OperandList;
|
||||||
@ -97,14 +97,14 @@ InstrInfoEmitter::GetOperandInfo(const CodeGenInstruction &Inst) {
|
|||||||
// registers in their multi-operand operands. It may also be an anonymous
|
// registers in their multi-operand operands. It may also be an anonymous
|
||||||
// operand, which has a single operand, but no declared class for the
|
// operand, which has a single operand, but no declared class for the
|
||||||
// operand.
|
// operand.
|
||||||
DagInit *MIOI = Inst.Operands[i].MIOperandInfo;
|
DagInit *MIOI = Op.MIOperandInfo;
|
||||||
|
|
||||||
if (!MIOI || MIOI->getNumArgs() == 0) {
|
if (!MIOI || MIOI->getNumArgs() == 0) {
|
||||||
// Single, anonymous, operand.
|
// Single, anonymous, operand.
|
||||||
OperandList.push_back(Inst.Operands[i]);
|
OperandList.push_back(Op);
|
||||||
} else {
|
} else {
|
||||||
for (unsigned j = 0, e = Inst.Operands[i].MINumOperands; j != e; ++j) {
|
for (unsigned j = 0, e = Op.MINumOperands; j != e; ++j) {
|
||||||
OperandList.push_back(Inst.Operands[i]);
|
OperandList.push_back(Op);
|
||||||
|
|
||||||
Record *OpR = cast<DefInit>(MIOI->getArg(j))->getDef();
|
Record *OpR = cast<DefInit>(MIOI->getArg(j))->getDef();
|
||||||
OperandList.back().Rec = OpR;
|
OperandList.back().Rec = OpR;
|
||||||
@ -134,24 +134,24 @@ InstrInfoEmitter::GetOperandInfo(const CodeGenInstruction &Inst) {
|
|||||||
|
|
||||||
// Predicate operands. Check to see if the original unexpanded operand
|
// Predicate operands. Check to see if the original unexpanded operand
|
||||||
// was of type PredicateOp.
|
// was of type PredicateOp.
|
||||||
if (Inst.Operands[i].Rec->isSubClassOf("PredicateOp"))
|
if (Op.Rec->isSubClassOf("PredicateOp"))
|
||||||
Res += "|(1<<MCOI::Predicate)";
|
Res += "|(1<<MCOI::Predicate)";
|
||||||
|
|
||||||
// Optional def operands. Check to see if the original unexpanded operand
|
// Optional def operands. Check to see if the original unexpanded operand
|
||||||
// was of type OptionalDefOperand.
|
// was of type OptionalDefOperand.
|
||||||
if (Inst.Operands[i].Rec->isSubClassOf("OptionalDefOperand"))
|
if (Op.Rec->isSubClassOf("OptionalDefOperand"))
|
||||||
Res += "|(1<<MCOI::OptionalDef)";
|
Res += "|(1<<MCOI::OptionalDef)";
|
||||||
|
|
||||||
// Fill in operand type.
|
// Fill in operand type.
|
||||||
Res += ", MCOI::";
|
Res += ", MCOI::";
|
||||||
assert(!Inst.Operands[i].OperandType.empty() && "Invalid operand type.");
|
assert(!Op.OperandType.empty() && "Invalid operand type.");
|
||||||
Res += Inst.Operands[i].OperandType;
|
Res += Op.OperandType;
|
||||||
|
|
||||||
// Fill in constraint info.
|
// Fill in constraint info.
|
||||||
Res += ", ";
|
Res += ", ";
|
||||||
|
|
||||||
const CGIOperandList::ConstraintInfo &Constraint =
|
const CGIOperandList::ConstraintInfo &Constraint =
|
||||||
Inst.Operands[i].Constraints[j];
|
Op.Constraints[j];
|
||||||
if (Constraint.isNone())
|
if (Constraint.isNone())
|
||||||
Res += "0";
|
Res += "0";
|
||||||
else if (Constraint.isEarlyClobber())
|
else if (Constraint.isEarlyClobber())
|
||||||
@ -177,16 +177,15 @@ void InstrInfoEmitter::EmitOperandInfo(raw_ostream &OS,
|
|||||||
|
|
||||||
OS << "\n";
|
OS << "\n";
|
||||||
const CodeGenTarget &Target = CDP.getTargetInfo();
|
const CodeGenTarget &Target = CDP.getTargetInfo();
|
||||||
for (CodeGenTarget::inst_iterator II = Target.inst_begin(),
|
for (const CodeGenInstruction *Inst : Target.instructions()) {
|
||||||
E = Target.inst_end(); II != E; ++II) {
|
std::vector<std::string> OperandInfo = GetOperandInfo(*Inst);
|
||||||
std::vector<std::string> OperandInfo = GetOperandInfo(**II);
|
|
||||||
unsigned &N = OperandInfoIDs[OperandInfo];
|
unsigned &N = OperandInfoIDs[OperandInfo];
|
||||||
if (N != 0) continue;
|
if (N != 0) continue;
|
||||||
|
|
||||||
N = ++OperandListNum;
|
N = ++OperandListNum;
|
||||||
OS << "static const MCOperandInfo OperandInfo" << N << "[] = { ";
|
OS << "static const MCOperandInfo OperandInfo" << N << "[] = { ";
|
||||||
for (unsigned i = 0, e = OperandInfo.size(); i != e; ++i)
|
for (const std::string &Info : OperandInfo)
|
||||||
OS << "{ " << OperandInfo[i] << " }, ";
|
OS << "{ " << Info << " }, ";
|
||||||
OS << "};\n";
|
OS << "};\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -206,14 +205,11 @@ void InstrInfoEmitter::initOperandMapData(
|
|||||||
OpNameMapTy &OperandMap) {
|
OpNameMapTy &OperandMap) {
|
||||||
|
|
||||||
unsigned NumOperands = 0;
|
unsigned NumOperands = 0;
|
||||||
for (unsigned i = 0, e = NumberedInstructions.size(); i != e; ++i) {
|
for (const CodeGenInstruction *Inst : NumberedInstructions) {
|
||||||
const CodeGenInstruction *Inst = NumberedInstructions[i];
|
if (!Inst->TheDef->getValueAsBit("UseNamedOperandTable"))
|
||||||
if (!Inst->TheDef->getValueAsBit("UseNamedOperandTable")) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
std::map<unsigned, unsigned> OpList;
|
std::map<unsigned, unsigned> OpList;
|
||||||
for (unsigned j = 0, je = Inst->Operands.size(); j != je; ++j) {
|
for (const auto &Info : Inst->Operands) {
|
||||||
const CGIOperandList::OperandInfo &Info = Inst->Operands[j];
|
|
||||||
StrUintMapIter I = Operands.find(Info.Name);
|
StrUintMapIter I = Operands.find(Info.Name);
|
||||||
|
|
||||||
if (I == Operands.end()) {
|
if (I == Operands.end()) {
|
||||||
@ -256,8 +252,8 @@ void InstrInfoEmitter::emitOperandNameMappings(raw_ostream &OS,
|
|||||||
OS << "namespace " << Namespace << " {\n";
|
OS << "namespace " << Namespace << " {\n";
|
||||||
OS << "namespace " << OpNameNS << " { \n";
|
OS << "namespace " << OpNameNS << " { \n";
|
||||||
OS << "enum {\n";
|
OS << "enum {\n";
|
||||||
for (StrUintMapIter i = Operands.begin(), e = Operands.end(); i != e; ++i)
|
for (const auto &Op : Operands)
|
||||||
OS << " " << i->first << " = " << i->second << ",\n";
|
OS << " " << Op.first << " = " << Op.second << ",\n";
|
||||||
|
|
||||||
OS << "OPERAND_LAST";
|
OS << "OPERAND_LAST";
|
||||||
OS << "\n};\n";
|
OS << "\n};\n";
|
||||||
@ -274,15 +270,13 @@ void InstrInfoEmitter::emitOperandNameMappings(raw_ostream &OS,
|
|||||||
if (!Operands.empty()) {
|
if (!Operands.empty()) {
|
||||||
OS << " static const int16_t OperandMap [][" << Operands.size()
|
OS << " static const int16_t OperandMap [][" << Operands.size()
|
||||||
<< "] = {\n";
|
<< "] = {\n";
|
||||||
for (OpNameMapTy::iterator i = OperandMap.begin(), e = OperandMap.end();
|
for (const auto &Entry : OperandMap) {
|
||||||
i != e; ++i) {
|
const std::map<unsigned, unsigned> &OpList = Entry.first;
|
||||||
const std::map<unsigned, unsigned> &OpList = i->first;
|
|
||||||
OS << "{";
|
OS << "{";
|
||||||
|
|
||||||
// Emit a row of the OperandMap table
|
// Emit a row of the OperandMap table
|
||||||
for (unsigned ii = 0, ie = Operands.size(); ii != ie; ++ii)
|
for (unsigned i = 0, e = Operands.size(); i != e; ++i)
|
||||||
OS << (OpList.count(ii) == 0 ? -1 : (int)OpList.find(ii)->second)
|
OS << (OpList.count(i) == 0 ? -1 : (int)OpList.find(i)->second) << ", ";
|
||||||
<< ", ";
|
|
||||||
|
|
||||||
OS << "},\n";
|
OS << "},\n";
|
||||||
}
|
}
|
||||||
@ -290,12 +284,9 @@ void InstrInfoEmitter::emitOperandNameMappings(raw_ostream &OS,
|
|||||||
|
|
||||||
OS << " switch(Opcode) {\n";
|
OS << " switch(Opcode) {\n";
|
||||||
unsigned TableIndex = 0;
|
unsigned TableIndex = 0;
|
||||||
for (OpNameMapTy::iterator i = OperandMap.begin(), e = OperandMap.end();
|
for (const auto &Entry : OperandMap) {
|
||||||
i != e; ++i) {
|
for (const std::string &Name : Entry.second)
|
||||||
std::vector<std::string> &OpcodeList = i->second;
|
OS << " case " << Name << ":\n";
|
||||||
|
|
||||||
for (unsigned ii = 0, ie = OpcodeList.size(); ii != ie; ++ii)
|
|
||||||
OS << " case " << OpcodeList[ii] << ":\n";
|
|
||||||
|
|
||||||
OS << " return OperandMap[" << TableIndex++ << "][NamedIdx];\n";
|
OS << " return OperandMap[" << TableIndex++ << "][NamedIdx];\n";
|
||||||
}
|
}
|
||||||
@ -328,9 +319,11 @@ void InstrInfoEmitter::emitOperandTypesEnum(raw_ostream &OS,
|
|||||||
OS << "namespace OpTypes { \n";
|
OS << "namespace OpTypes { \n";
|
||||||
OS << "enum OperandType {\n";
|
OS << "enum OperandType {\n";
|
||||||
|
|
||||||
for (unsigned oi = 0, oe = Operands.size(); oi != oe; ++oi) {
|
unsigned EnumVal = 0;
|
||||||
if (!Operands[oi]->isAnonymous())
|
for (const Record *Op : Operands) {
|
||||||
OS << " " << Operands[oi]->getName() << " = " << oi << ",\n";
|
if (!Op->isAnonymous())
|
||||||
|
OS << " " << Op->getName() << " = " << EnumVal << ",\n";
|
||||||
|
++EnumVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
OS << " OPERAND_TYPE_LIST_END" << "\n};\n";
|
OS << " OPERAND_TYPE_LIST_END" << "\n};\n";
|
||||||
@ -365,9 +358,8 @@ void InstrInfoEmitter::run(raw_ostream &OS) {
|
|||||||
unsigned ListNumber = 0;
|
unsigned ListNumber = 0;
|
||||||
|
|
||||||
// Emit all of the instruction's implicit uses and defs.
|
// Emit all of the instruction's implicit uses and defs.
|
||||||
for (CodeGenTarget::inst_iterator II = Target.inst_begin(),
|
for (const CodeGenInstruction *II : Target.instructions()) {
|
||||||
E = Target.inst_end(); II != E; ++II) {
|
Record *Inst = II->TheDef;
|
||||||
Record *Inst = (*II)->TheDef;
|
|
||||||
std::vector<Record*> Uses = Inst->getValueAsListOfDefs("Uses");
|
std::vector<Record*> Uses = Inst->getValueAsListOfDefs("Uses");
|
||||||
if (!Uses.empty()) {
|
if (!Uses.empty()) {
|
||||||
unsigned &IL = EmittedLists[Uses];
|
unsigned &IL = EmittedLists[Uses];
|
||||||
@ -391,29 +383,30 @@ void InstrInfoEmitter::run(raw_ostream &OS) {
|
|||||||
const std::vector<const CodeGenInstruction*> &NumberedInstructions =
|
const std::vector<const CodeGenInstruction*> &NumberedInstructions =
|
||||||
Target.getInstructionsByEnumValue();
|
Target.getInstructionsByEnumValue();
|
||||||
|
|
||||||
for (unsigned i = 0, e = NumberedInstructions.size(); i != e; ++i)
|
SequenceToOffsetTable<std::string> InstrNames;
|
||||||
emitRecord(*NumberedInstructions[i], i, InstrInfo, EmittedLists,
|
unsigned Num = 0;
|
||||||
OperandInfoIDs, OS);
|
for (const CodeGenInstruction *Inst : NumberedInstructions) {
|
||||||
|
// Keep a list of the instruction names.
|
||||||
|
InstrNames.add(Inst->TheDef->getName());
|
||||||
|
// Emit the record into the table.
|
||||||
|
emitRecord(*Inst, Num++, InstrInfo, EmittedLists, OperandInfoIDs, OS);
|
||||||
|
}
|
||||||
OS << "};\n\n";
|
OS << "};\n\n";
|
||||||
|
|
||||||
// Build an array of instruction names
|
// Emit the array of instruction names.
|
||||||
SequenceToOffsetTable<std::string> InstrNames;
|
|
||||||
for (unsigned i = 0, e = NumberedInstructions.size(); i != e; ++i) {
|
|
||||||
const CodeGenInstruction *Instr = NumberedInstructions[i];
|
|
||||||
InstrNames.add(Instr->TheDef->getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
InstrNames.layout();
|
InstrNames.layout();
|
||||||
OS << "extern const char " << TargetName << "InstrNameData[] = {\n";
|
OS << "extern const char " << TargetName << "InstrNameData[] = {\n";
|
||||||
InstrNames.emit(OS, printChar);
|
InstrNames.emit(OS, printChar);
|
||||||
OS << "};\n\n";
|
OS << "};\n\n";
|
||||||
|
|
||||||
OS << "extern const unsigned " << TargetName <<"InstrNameIndices[] = {";
|
OS << "extern const unsigned " << TargetName <<"InstrNameIndices[] = {";
|
||||||
for (unsigned i = 0, e = NumberedInstructions.size(); i != e; ++i) {
|
Num = 0;
|
||||||
if (i % 8 == 0)
|
for (const CodeGenInstruction *Inst : NumberedInstructions) {
|
||||||
|
// Newline every eight entries.
|
||||||
|
if (Num % 8 == 0)
|
||||||
OS << "\n ";
|
OS << "\n ";
|
||||||
const CodeGenInstruction *Instr = NumberedInstructions[i];
|
OS << InstrNames.get(Inst->TheDef->getName()) << "U, ";
|
||||||
OS << InstrNames.get(Instr->TheDef->getName()) << "U, ";
|
++Num;
|
||||||
}
|
}
|
||||||
|
|
||||||
OS << "\n};\n\n";
|
OS << "\n};\n\n";
|
||||||
@ -586,18 +579,16 @@ void InstrInfoEmitter::emitEnums(raw_ostream &OS) {
|
|||||||
|
|
||||||
OS << "namespace " << Namespace << " {\n";
|
OS << "namespace " << Namespace << " {\n";
|
||||||
OS << " enum {\n";
|
OS << " enum {\n";
|
||||||
for (unsigned i = 0, e = NumberedInstructions.size(); i != e; ++i) {
|
unsigned Num = 0;
|
||||||
OS << " " << NumberedInstructions[i]->TheDef->getName()
|
for (const CodeGenInstruction *Inst : NumberedInstructions)
|
||||||
<< "\t= " << i << ",\n";
|
OS << " " << Inst->TheDef->getName() << "\t= " << Num++ << ",\n";
|
||||||
}
|
|
||||||
OS << " INSTRUCTION_LIST_END = " << NumberedInstructions.size() << "\n";
|
OS << " INSTRUCTION_LIST_END = " << NumberedInstructions.size() << "\n";
|
||||||
OS << " };\n";
|
OS << " };\n";
|
||||||
OS << "namespace Sched {\n";
|
OS << "namespace Sched {\n";
|
||||||
OS << " enum {\n";
|
OS << " enum {\n";
|
||||||
for (unsigned i = 0, e = SchedModels.numInstrSchedClasses(); i != e; ++i) {
|
Num = 0;
|
||||||
OS << " " << SchedModels.getSchedClass(i).Name
|
for (const auto &Class : SchedModels.explicit_classes())
|
||||||
<< "\t= " << i << ",\n";
|
OS << " " << Class.Name << "\t= " << Num++ << ",\n";
|
||||||
}
|
|
||||||
OS << " SCHED_LIST_END = " << SchedModels.numInstrSchedClasses() << "\n";
|
OS << " SCHED_LIST_END = " << SchedModels.numInstrSchedClasses() << "\n";
|
||||||
OS << " };\n}\n}\n";
|
OS << " };\n}\n}\n";
|
||||||
OS << "} // End llvm namespace \n";
|
OS << "} // End llvm namespace \n";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user