diff options
author | Chris Lattner <sabre@nondot.org> | 2010-11-06 07:31:43 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2010-11-06 07:31:43 +0000 |
commit | 414098571b19fc248fda2be194082cfd012d2729 (patch) | |
tree | 6bef9db250e1b7c6f95c6ec9960d6533e197361e /utils/TableGen/CodeGenInstruction.cpp | |
parent | 662e5a30e864e71111b885d3da3cdd184772035d (diff) |
fix some bugs in the alias support, unblocking changing of "clr" aliases
from c++ hacks to proper .td InstAlias definitions. Change them!
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@118330 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils/TableGen/CodeGenInstruction.cpp')
-rw-r--r-- | utils/TableGen/CodeGenInstruction.cpp | 43 |
1 files changed, 28 insertions, 15 deletions
diff --git a/utils/TableGen/CodeGenInstruction.cpp b/utils/TableGen/CodeGenInstruction.cpp index c32a58649b..73b7b78d09 100644 --- a/utils/TableGen/CodeGenInstruction.cpp +++ b/utils/TableGen/CodeGenInstruction.cpp @@ -400,30 +400,35 @@ CodeGenInstAlias::CodeGenInstAlias(Record *R, CodeGenTarget &T) : TheDef(R) { ResultInst = &T.getInstruction(DI->getDef()); - // Check number of arguments in the result. - if (ResultInst->Operands.size() != Result->getNumArgs()) - throw TGError(R->getLoc(), "result has " + utostr(Result->getNumArgs()) + - " arguments, but " + ResultInst->TheDef->getName() + - " instruction expects " + utostr(ResultInst->Operands.size())+ - " operands!"); - // NameClass - If argument names are repeated, we need to verify they have // the same class. StringMap<Record*> NameClass; // Decode and validate the arguments of the result. - for (unsigned i = 0, e = Result->getNumArgs(); i != e; ++i) { - Init *Arg = Result->getArg(i); + unsigned AliasOpNo = 0; + for (unsigned i = 0, e = ResultInst->Operands.size(); i != e; ++i) { + // Tied registers don't have an entry in the result dag. + if (ResultInst->Operands[i].getTiedRegister() != -1) + continue; + + if (AliasOpNo >= Result->getNumArgs()) + throw TGError(R->getLoc(), "result has " + utostr(Result->getNumArgs()) + + " arguments, but " + ResultInst->TheDef->getName() + + " instruction expects " + + utostr(ResultInst->Operands.size()) + " operands!"); + + + Init *Arg = Result->getArg(AliasOpNo); // If the operand is a record, it must have a name, and the record type must // match up with the instruction's argument type. if (DefInit *ADI = dynamic_cast<DefInit*>(Arg)) { - if (Result->getArgName(i).empty()) - throw TGError(R->getLoc(), "result argument #" + utostr(i) + + if (Result->getArgName(AliasOpNo).empty()) + throw TGError(R->getLoc(), "result argument #" + utostr(AliasOpNo) + " must have a name!"); if (ADI->getDef() != ResultInst->Operands[i].Rec) - throw TGError(R->getLoc(), "result argument #" + utostr(i) + + throw TGError(R->getLoc(), "result argument #" + utostr(AliasOpNo) + " declared with class " + ADI->getDef()->getName() + ", instruction operand is class " + ResultInst->Operands[i].Rec->getName()); @@ -431,18 +436,26 @@ CodeGenInstAlias::CodeGenInstAlias(Record *R, CodeGenTarget &T) : TheDef(R) { // Verify we don't have something like: (someinst GR16:$foo, GR32:$foo) // $foo can exist multiple times in the result list, but it must have the // same type. - Record *&Entry = NameClass[Result->getArgName(i)]; + Record *&Entry = NameClass[Result->getArgName(AliasOpNo)]; if (Entry && Entry != ADI->getDef()) - throw TGError(R->getLoc(), "result value $" + Result->getArgName(i) + + throw TGError(R->getLoc(), "result value $" + + Result->getArgName(AliasOpNo) + " is both " + Entry->getName() + " and " + ADI->getDef()->getName() + "!"); // Now that it is validated, add it. - ResultOperands.push_back(ResultOperand(Result->getArgName(i), + ResultOperands.push_back(ResultOperand(Result->getArgName(AliasOpNo), ADI->getDef())); + ++AliasOpNo; continue; } throw TGError(R->getLoc(), "result of inst alias has unknown operand type"); } + + if (AliasOpNo != Result->getNumArgs()) + throw TGError(R->getLoc(), "result has " + utostr(Result->getNumArgs()) + + " arguments, but " + ResultInst->TheDef->getName() + + " instruction expects " + utostr(ResultInst->Operands.size())+ + " operands!"); } |