diff --git a/utils/TableGen/CodeGenTarget.cpp b/utils/TableGen/CodeGenTarget.cpp index 7c153ece928..c18dff351f1 100644 --- a/utils/TableGen/CodeGenTarget.cpp +++ b/utils/TableGen/CodeGenTarget.cpp @@ -18,6 +18,7 @@ #include "Record.h" #include "llvm/ADT/StringExtras.h" #include "llvm/Support/CommandLine.h" +#include using namespace llvm; static cl::opt @@ -250,39 +251,48 @@ CodeGenInstruction::CodeGenInstruction(Record *R, const std::string &AsmStr) usesCustomDAGSchedInserter = R->getValueAsBit("usesCustomDAGSchedInserter"); hasVariableNumberOfOperands = false; + DagInit *DI; try { - DagInit *DI = R->getValueAsDag("OperandList"); - - unsigned MIOperandNo = 0; - for (unsigned i = 0, e = DI->getNumArgs(); i != e; ++i) - if (DefInit *Arg = dynamic_cast(DI->getArg(i))) { - Record *Rec = Arg->getDef(); - MVT::ValueType Ty; - std::string PrintMethod = "printOperand"; - unsigned NumOps = 1; - if (Rec->isSubClassOf("RegisterClass")) { - Ty = getValueType(Rec->getValueAsDef("RegType")); - } else if (Rec->isSubClassOf("Operand")) { - Ty = getValueType(Rec->getValueAsDef("Type")); - PrintMethod = Rec->getValueAsString("PrintMethod"); - NumOps = Rec->getValueAsInt("NumMIOperands"); - } else if (Rec->getName() == "variable_ops") { - hasVariableNumberOfOperands = true; - continue; - } else - throw "Unknown operand class '" + Rec->getName() + - "' in instruction '" + R->getName() + "' instruction!"; - - OperandList.push_back(OperandInfo(Rec, Ty, DI->getArgName(i), - PrintMethod, MIOperandNo, NumOps)); - MIOperandNo += NumOps; - } else { - throw "Illegal operand for the '" + R->getName() + "' instruction!"; - } + DI = R->getValueAsDag("OperandList"); } catch (...) { - // Error parsing operands list, just ignore it. + // Error getting operand list, just ignore it (sparcv9). AsmString.clear(); OperandList.clear(); + return; + } + + unsigned MIOperandNo = 0; + std::set OperandNames; + for (unsigned i = 0, e = DI->getNumArgs(); i != e; ++i) { + DefInit *Arg = dynamic_cast(DI->getArg(i)); + if (!Arg) + throw "Illegal operand for the '" + R->getName() + "' instruction!"; + + Record *Rec = Arg->getDef(); + MVT::ValueType Ty; + std::string PrintMethod = "printOperand"; + unsigned NumOps = 1; + if (Rec->isSubClassOf("RegisterClass")) { + Ty = getValueType(Rec->getValueAsDef("RegType")); + } else if (Rec->isSubClassOf("Operand")) { + Ty = getValueType(Rec->getValueAsDef("Type")); + PrintMethod = Rec->getValueAsString("PrintMethod"); + NumOps = Rec->getValueAsInt("NumMIOperands"); + } else if (Rec->getName() == "variable_ops") { + hasVariableNumberOfOperands = true; + continue; + } else + throw "Unknown operand class '" + Rec->getName() + + "' in instruction '" + R->getName() + "' instruction!"; + + if (!DI->getArgName(i).empty() && + !OperandNames.insert(DI->getArgName(i)).second) + throw "In instruction '" + R->getName() + "', operand #" + utostr(i) + + " has the same name as a previous operand!"; + + OperandList.push_back(OperandInfo(Rec, Ty, DI->getArgName(i), + PrintMethod, MIOperandNo, NumOps)); + MIOperandNo += NumOps; } }