1 //===- CodeGenInstruction.cpp - CodeGen Instruction Class Wrapper ---------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the CodeGenInstruction class.
12 //===----------------------------------------------------------------------===//
14 #include "CodeGenInstruction.h"
15 #include "CodeGenTarget.h"
16 #include "llvm/ADT/STLExtras.h"
17 #include "llvm/ADT/StringExtras.h"
18 #include "llvm/ADT/StringMap.h"
19 #include "llvm/TableGen/Error.h"
20 #include "llvm/TableGen/Record.h"
24 //===----------------------------------------------------------------------===//
25 // CGIOperandList Implementation
26 //===----------------------------------------------------------------------===//
28 CGIOperandList::CGIOperandList(Record *R) : TheDef(R) {
30 hasOptionalDef = false;
33 DagInit *OutDI = R->getValueAsDag("OutOperandList");
35 if (DefInit *Init = dyn_cast<DefInit>(OutDI->getOperator())) {
36 if (Init->getDef()->getName() != "outs")
37 PrintFatalError(R->getName() + ": invalid def name for output list: use 'outs'");
39 PrintFatalError(R->getName() + ": invalid output list: use 'outs'");
41 NumDefs = OutDI->getNumArgs();
43 DagInit *InDI = R->getValueAsDag("InOperandList");
44 if (DefInit *Init = dyn_cast<DefInit>(InDI->getOperator())) {
45 if (Init->getDef()->getName() != "ins")
46 PrintFatalError(R->getName() + ": invalid def name for input list: use 'ins'");
48 PrintFatalError(R->getName() + ": invalid input list: use 'ins'");
50 unsigned MIOperandNo = 0;
51 std::set<std::string> OperandNames;
52 for (unsigned i = 0, e = InDI->getNumArgs()+OutDI->getNumArgs(); i != e; ++i){
56 ArgInit = OutDI->getArg(i);
57 ArgName = OutDI->getArgName(i);
59 ArgInit = InDI->getArg(i-NumDefs);
60 ArgName = InDI->getArgName(i-NumDefs);
63 DefInit *Arg = dyn_cast<DefInit>(ArgInit);
65 PrintFatalError("Illegal operand for the '" + R->getName() + "' instruction!");
67 Record *Rec = Arg->getDef();
68 std::string PrintMethod = "printOperand";
69 std::string EncoderMethod;
70 std::string OperandType = "OPERAND_UNKNOWN";
72 DagInit *MIOpInfo = nullptr;
73 if (Rec->isSubClassOf("RegisterOperand")) {
74 PrintMethod = Rec->getValueAsString("PrintMethod");
75 } else if (Rec->isSubClassOf("Operand")) {
76 PrintMethod = Rec->getValueAsString("PrintMethod");
77 OperandType = Rec->getValueAsString("OperandType");
78 // If there is an explicit encoder method, use it.
79 EncoderMethod = Rec->getValueAsString("EncoderMethod");
80 MIOpInfo = Rec->getValueAsDag("MIOperandInfo");
82 // Verify that MIOpInfo has an 'ops' root value.
83 if (!isa<DefInit>(MIOpInfo->getOperator()) ||
84 cast<DefInit>(MIOpInfo->getOperator())->getDef()->getName() != "ops")
85 PrintFatalError("Bad value for MIOperandInfo in operand '" + Rec->getName() +
88 // If we have MIOpInfo, then we have #operands equal to number of entries
90 if (unsigned NumArgs = MIOpInfo->getNumArgs())
93 if (Rec->isSubClassOf("PredicateOp"))
95 else if (Rec->isSubClassOf("OptionalDefOperand"))
96 hasOptionalDef = true;
97 } else if (Rec->getName() == "variable_ops") {
100 } else if (Rec->isSubClassOf("RegisterClass")) {
101 OperandType = "OPERAND_REGISTER";
102 } else if (!Rec->isSubClassOf("PointerLikeRegClass") &&
103 !Rec->isSubClassOf("unknown_class"))
104 PrintFatalError("Unknown operand class '" + Rec->getName() +
105 "' in '" + R->getName() + "' instruction!");
107 // Check that the operand has a name and that it's unique.
109 PrintFatalError("In instruction '" + R->getName() + "', operand #" +
110 Twine(i) + " has no name!");
111 if (!OperandNames.insert(ArgName).second)
112 PrintFatalError("In instruction '" + R->getName() + "', operand #" +
113 Twine(i) + " has the same name as a previous operand!");
115 OperandList.push_back(OperandInfo(Rec, ArgName, PrintMethod, EncoderMethod,
116 OperandType, MIOperandNo, NumOps,
118 MIOperandNo += NumOps;
122 // Make sure the constraints list for each operand is large enough to hold
123 // constraint info, even if none is present.
124 for (unsigned i = 0, e = OperandList.size(); i != e; ++i)
125 OperandList[i].Constraints.resize(OperandList[i].MINumOperands);
129 /// getOperandNamed - Return the index of the operand with the specified
130 /// non-empty name. If the instruction does not have an operand with the
131 /// specified name, abort.
133 unsigned CGIOperandList::getOperandNamed(StringRef Name) const {
135 if (hasOperandNamed(Name, OpIdx)) return OpIdx;
136 PrintFatalError("'" + TheDef->getName() +
137 "' does not have an operand named '$" + Name + "'!");
140 /// hasOperandNamed - Query whether the instruction has an operand of the
141 /// given name. If so, return true and set OpIdx to the index of the
142 /// operand. Otherwise, return false.
143 bool CGIOperandList::hasOperandNamed(StringRef Name, unsigned &OpIdx) const {
144 assert(!Name.empty() && "Cannot search for operand with no name!");
145 for (unsigned i = 0, e = OperandList.size(); i != e; ++i)
146 if (OperandList[i].Name == Name) {
153 std::pair<unsigned,unsigned>
154 CGIOperandList::ParseOperandName(const std::string &Op, bool AllowWholeOp) {
155 if (Op.empty() || Op[0] != '$')
156 PrintFatalError(TheDef->getName() + ": Illegal operand name: '" + Op + "'");
158 std::string OpName = Op.substr(1);
159 std::string SubOpName;
161 // Check to see if this is $foo.bar.
162 std::string::size_type DotIdx = OpName.find_first_of(".");
163 if (DotIdx != std::string::npos) {
164 SubOpName = OpName.substr(DotIdx+1);
165 if (SubOpName.empty())
166 PrintFatalError(TheDef->getName() + ": illegal empty suboperand name in '" +Op +"'");
167 OpName = OpName.substr(0, DotIdx);
170 unsigned OpIdx = getOperandNamed(OpName);
172 if (SubOpName.empty()) { // If no suboperand name was specified:
173 // If one was needed, throw.
174 if (OperandList[OpIdx].MINumOperands > 1 && !AllowWholeOp &&
176 PrintFatalError(TheDef->getName() + ": Illegal to refer to"
177 " whole operand part of complex operand '" + Op + "'");
179 // Otherwise, return the operand.
180 return std::make_pair(OpIdx, 0U);
183 // Find the suboperand number involved.
184 DagInit *MIOpInfo = OperandList[OpIdx].MIOperandInfo;
186 PrintFatalError(TheDef->getName() + ": unknown suboperand name in '" + Op + "'");
188 // Find the operand with the right name.
189 for (unsigned i = 0, e = MIOpInfo->getNumArgs(); i != e; ++i)
190 if (MIOpInfo->getArgName(i) == SubOpName)
191 return std::make_pair(OpIdx, i);
193 // Otherwise, didn't find it!
194 PrintFatalError(TheDef->getName() + ": unknown suboperand name in '" + Op + "'");
195 return std::make_pair(0U, 0U);
198 static void ParseConstraint(const std::string &CStr, CGIOperandList &Ops) {
199 // EARLY_CLOBBER: @early $reg
200 std::string::size_type wpos = CStr.find_first_of(" \t");
201 std::string::size_type start = CStr.find_first_not_of(" \t");
202 std::string Tok = CStr.substr(start, wpos - start);
203 if (Tok == "@earlyclobber") {
204 std::string Name = CStr.substr(wpos+1);
205 wpos = Name.find_first_not_of(" \t");
206 if (wpos == std::string::npos)
207 PrintFatalError("Illegal format for @earlyclobber constraint: '" + CStr + "'");
208 Name = Name.substr(wpos);
209 std::pair<unsigned,unsigned> Op = Ops.ParseOperandName(Name, false);
211 // Build the string for the operand
212 if (!Ops[Op.first].Constraints[Op.second].isNone())
213 PrintFatalError("Operand '" + Name + "' cannot have multiple constraints!");
214 Ops[Op.first].Constraints[Op.second] =
215 CGIOperandList::ConstraintInfo::getEarlyClobber();
219 // Only other constraint is "TIED_TO" for now.
220 std::string::size_type pos = CStr.find_first_of('=');
221 assert(pos != std::string::npos && "Unrecognized constraint");
222 start = CStr.find_first_not_of(" \t");
223 std::string Name = CStr.substr(start, pos - start);
225 // TIED_TO: $src1 = $dst
226 wpos = Name.find_first_of(" \t");
227 if (wpos == std::string::npos)
228 PrintFatalError("Illegal format for tied-to constraint: '" + CStr + "'");
229 std::string DestOpName = Name.substr(0, wpos);
230 std::pair<unsigned,unsigned> DestOp = Ops.ParseOperandName(DestOpName, false);
232 Name = CStr.substr(pos+1);
233 wpos = Name.find_first_not_of(" \t");
234 if (wpos == std::string::npos)
235 PrintFatalError("Illegal format for tied-to constraint: '" + CStr + "'");
237 std::string SrcOpName = Name.substr(wpos);
238 std::pair<unsigned,unsigned> SrcOp = Ops.ParseOperandName(SrcOpName, false);
239 if (SrcOp > DestOp) {
240 std::swap(SrcOp, DestOp);
241 std::swap(SrcOpName, DestOpName);
244 unsigned FlatOpNo = Ops.getFlattenedOperandNumber(SrcOp);
246 if (!Ops[DestOp.first].Constraints[DestOp.second].isNone())
247 PrintFatalError("Operand '" + DestOpName +
248 "' cannot have multiple constraints!");
249 Ops[DestOp.first].Constraints[DestOp.second] =
250 CGIOperandList::ConstraintInfo::getTied(FlatOpNo);
253 static void ParseConstraints(const std::string &CStr, CGIOperandList &Ops) {
254 if (CStr.empty()) return;
256 const std::string delims(",");
257 std::string::size_type bidx, eidx;
259 bidx = CStr.find_first_not_of(delims);
260 while (bidx != std::string::npos) {
261 eidx = CStr.find_first_of(delims, bidx);
262 if (eidx == std::string::npos)
263 eidx = CStr.length();
265 ParseConstraint(CStr.substr(bidx, eidx - bidx), Ops);
266 bidx = CStr.find_first_not_of(delims, eidx);
270 void CGIOperandList::ProcessDisableEncoding(std::string DisableEncoding) {
272 std::pair<StringRef, StringRef> P = getToken(DisableEncoding, " ,\t");
273 std::string OpName = P.first;
274 DisableEncoding = P.second;
275 if (OpName.empty()) break;
277 // Figure out which operand this is.
278 std::pair<unsigned,unsigned> Op = ParseOperandName(OpName, false);
280 // Mark the operand as not-to-be encoded.
281 if (Op.second >= OperandList[Op.first].DoNotEncode.size())
282 OperandList[Op.first].DoNotEncode.resize(Op.second+1);
283 OperandList[Op.first].DoNotEncode[Op.second] = true;
288 //===----------------------------------------------------------------------===//
289 // CodeGenInstruction Implementation
290 //===----------------------------------------------------------------------===//
292 CodeGenInstruction::CodeGenInstruction(Record *R)
293 : TheDef(R), Operands(R), InferredFrom(nullptr) {
294 Namespace = R->getValueAsString("Namespace");
295 AsmString = R->getValueAsString("AsmString");
297 isReturn = R->getValueAsBit("isReturn");
298 isBranch = R->getValueAsBit("isBranch");
299 isIndirectBranch = R->getValueAsBit("isIndirectBranch");
300 isCompare = R->getValueAsBit("isCompare");
301 isMoveImm = R->getValueAsBit("isMoveImm");
302 isBitcast = R->getValueAsBit("isBitcast");
303 isSelect = R->getValueAsBit("isSelect");
304 isBarrier = R->getValueAsBit("isBarrier");
305 isCall = R->getValueAsBit("isCall");
306 canFoldAsLoad = R->getValueAsBit("canFoldAsLoad");
307 isPredicable = Operands.isPredicable || R->getValueAsBit("isPredicable");
308 isConvertibleToThreeAddress = R->getValueAsBit("isConvertibleToThreeAddress");
309 isCommutable = R->getValueAsBit("isCommutable");
310 isTerminator = R->getValueAsBit("isTerminator");
311 isReMaterializable = R->getValueAsBit("isReMaterializable");
312 hasDelaySlot = R->getValueAsBit("hasDelaySlot");
313 usesCustomInserter = R->getValueAsBit("usesCustomInserter");
314 hasPostISelHook = R->getValueAsBit("hasPostISelHook");
315 hasCtrlDep = R->getValueAsBit("hasCtrlDep");
316 isNotDuplicable = R->getValueAsBit("isNotDuplicable");
317 isRegSequence = R->getValueAsBit("isRegSequence");
318 isExtractSubreg = R->getValueAsBit("isExtractSubreg");
319 isInsertSubreg = R->getValueAsBit("isInsertSubreg");
322 mayLoad = R->getValueAsBitOrUnset("mayLoad", Unset);
323 mayLoad_Unset = Unset;
324 mayStore = R->getValueAsBitOrUnset("mayStore", Unset);
325 mayStore_Unset = Unset;
326 hasSideEffects = R->getValueAsBitOrUnset("hasSideEffects", Unset);
327 hasSideEffects_Unset = Unset;
329 isAsCheapAsAMove = R->getValueAsBit("isAsCheapAsAMove");
330 hasExtraSrcRegAllocReq = R->getValueAsBit("hasExtraSrcRegAllocReq");
331 hasExtraDefRegAllocReq = R->getValueAsBit("hasExtraDefRegAllocReq");
332 isCodeGenOnly = R->getValueAsBit("isCodeGenOnly");
333 isPseudo = R->getValueAsBit("isPseudo");
334 ImplicitDefs = R->getValueAsListOfDefs("Defs");
335 ImplicitUses = R->getValueAsListOfDefs("Uses");
337 // Parse Constraints.
338 ParseConstraints(R->getValueAsString("Constraints"), Operands);
340 // Parse the DisableEncoding field.
341 Operands.ProcessDisableEncoding(R->getValueAsString("DisableEncoding"));
343 // First check for a ComplexDeprecationPredicate.
344 if (R->getValue("ComplexDeprecationPredicate")) {
345 HasComplexDeprecationPredicate = true;
346 DeprecatedReason = R->getValueAsString("ComplexDeprecationPredicate");
347 } else if (RecordVal *Dep = R->getValue("DeprecatedFeatureMask")) {
348 // Check if we have a Subtarget feature mask.
349 HasComplexDeprecationPredicate = false;
350 DeprecatedReason = Dep->getValue()->getAsString();
352 // This instruction isn't deprecated.
353 HasComplexDeprecationPredicate = false;
354 DeprecatedReason = "";
358 /// HasOneImplicitDefWithKnownVT - If the instruction has at least one
359 /// implicit def and it has a known VT, return the VT, otherwise return
361 MVT::SimpleValueType CodeGenInstruction::
362 HasOneImplicitDefWithKnownVT(const CodeGenTarget &TargetInfo) const {
363 if (ImplicitDefs.empty()) return MVT::Other;
365 // Check to see if the first implicit def has a resolvable type.
366 Record *FirstImplicitDef = ImplicitDefs[0];
367 assert(FirstImplicitDef->isSubClassOf("Register"));
368 const std::vector<MVT::SimpleValueType> &RegVTs =
369 TargetInfo.getRegisterVTs(FirstImplicitDef);
370 if (RegVTs.size() == 1)
376 /// FlattenAsmStringVariants - Flatten the specified AsmString to only
377 /// include text from the specified variant, returning the new string.
378 std::string CodeGenInstruction::
379 FlattenAsmStringVariants(StringRef Cur, unsigned Variant) {
380 std::string Res = "";
383 // Find the start of the next variant string.
384 size_t VariantsStart = 0;
385 for (size_t e = Cur.size(); VariantsStart != e; ++VariantsStart)
386 if (Cur[VariantsStart] == '{' &&
387 (VariantsStart == 0 || (Cur[VariantsStart-1] != '$' &&
388 Cur[VariantsStart-1] != '\\')))
391 // Add the prefix to the result.
392 Res += Cur.slice(0, VariantsStart);
393 if (VariantsStart == Cur.size())
396 ++VariantsStart; // Skip the '{'.
398 // Scan to the end of the variants string.
399 size_t VariantsEnd = VariantsStart;
400 unsigned NestedBraces = 1;
401 for (size_t e = Cur.size(); VariantsEnd != e; ++VariantsEnd) {
402 if (Cur[VariantsEnd] == '}' && Cur[VariantsEnd-1] != '\\') {
403 if (--NestedBraces == 0)
405 } else if (Cur[VariantsEnd] == '{')
409 // Select the Nth variant (or empty).
410 StringRef Selection = Cur.slice(VariantsStart, VariantsEnd);
411 for (unsigned i = 0; i != Variant; ++i)
412 Selection = Selection.split('|').second;
413 Res += Selection.split('|').first;
415 assert(VariantsEnd != Cur.size() &&
416 "Unterminated variants in assembly string!");
417 Cur = Cur.substr(VariantsEnd + 1);
424 //===----------------------------------------------------------------------===//
425 /// CodeGenInstAlias Implementation
426 //===----------------------------------------------------------------------===//
428 /// tryAliasOpMatch - This is a helper function for the CodeGenInstAlias
429 /// constructor. It checks if an argument in an InstAlias pattern matches
430 /// the corresponding operand of the instruction. It returns true on a
431 /// successful match, with ResOp set to the result operand to be used.
432 bool CodeGenInstAlias::tryAliasOpMatch(DagInit *Result, unsigned AliasOpNo,
433 Record *InstOpRec, bool hasSubOps,
434 ArrayRef<SMLoc> Loc, CodeGenTarget &T,
435 ResultOperand &ResOp) {
436 Init *Arg = Result->getArg(AliasOpNo);
437 DefInit *ADI = dyn_cast<DefInit>(Arg);
438 Record *ResultRecord = ADI ? ADI->getDef() : nullptr;
440 if (ADI && ADI->getDef() == InstOpRec) {
441 // If the operand is a record, it must have a name, and the record type
442 // must match up with the instruction's argument type.
443 if (Result->getArgName(AliasOpNo).empty())
444 PrintFatalError(Loc, "result argument #" + Twine(AliasOpNo) +
445 " must have a name!");
446 ResOp = ResultOperand(Result->getArgName(AliasOpNo), ResultRecord);
450 // For register operands, the source register class can be a subclass
451 // of the instruction register class, not just an exact match.
452 if (InstOpRec->isSubClassOf("RegisterOperand"))
453 InstOpRec = InstOpRec->getValueAsDef("RegClass");
455 if (ADI && ADI->getDef()->isSubClassOf("RegisterOperand"))
456 ADI = ADI->getDef()->getValueAsDef("RegClass")->getDefInit();
458 if (ADI && ADI->getDef()->isSubClassOf("RegisterClass")) {
459 if (!InstOpRec->isSubClassOf("RegisterClass"))
461 if (!T.getRegisterClass(InstOpRec)
462 .hasSubClass(&T.getRegisterClass(ADI->getDef())))
464 ResOp = ResultOperand(Result->getArgName(AliasOpNo), ResultRecord);
468 // Handle explicit registers.
469 if (ADI && ADI->getDef()->isSubClassOf("Register")) {
470 if (InstOpRec->isSubClassOf("OptionalDefOperand")) {
471 DagInit *DI = InstOpRec->getValueAsDag("MIOperandInfo");
472 // The operand info should only have a single (register) entry. We
473 // want the register class of it.
474 InstOpRec = cast<DefInit>(DI->getArg(0))->getDef();
477 if (!InstOpRec->isSubClassOf("RegisterClass"))
480 if (!T.getRegisterClass(InstOpRec)
481 .contains(T.getRegBank().getReg(ADI->getDef())))
482 PrintFatalError(Loc, "fixed register " + ADI->getDef()->getName() +
483 " is not a member of the " + InstOpRec->getName() +
486 if (!Result->getArgName(AliasOpNo).empty())
487 PrintFatalError(Loc, "result fixed register argument must "
490 ResOp = ResultOperand(ResultRecord);
494 // Handle "zero_reg" for optional def operands.
495 if (ADI && ADI->getDef()->getName() == "zero_reg") {
497 // Check if this is an optional def.
498 // Tied operands where the source is a sub-operand of a complex operand
499 // need to represent both operands in the alias destination instruction.
500 // Allow zero_reg for the tied portion. This can and should go away once
501 // the MC representation of things doesn't use tied operands at all.
502 //if (!InstOpRec->isSubClassOf("OptionalDefOperand"))
503 // throw TGError(Loc, "reg0 used for result that is not an "
504 // "OptionalDefOperand!");
506 ResOp = ResultOperand(static_cast<Record*>(nullptr));
511 if (IntInit *II = dyn_cast<IntInit>(Arg)) {
512 if (hasSubOps || !InstOpRec->isSubClassOf("Operand"))
514 // Integer arguments can't have names.
515 if (!Result->getArgName(AliasOpNo).empty())
516 PrintFatalError(Loc, "result argument #" + Twine(AliasOpNo) +
517 " must not have a name!");
518 ResOp = ResultOperand(II->getValue());
522 // Bits<n> (also used for 0bxx literals)
523 if (BitsInit *BI = dyn_cast<BitsInit>(Arg)) {
524 if (hasSubOps || !InstOpRec->isSubClassOf("Operand"))
526 if (!BI->isComplete())
528 // Convert the bits init to an integer and use that for the result.
530 dyn_cast_or_null<IntInit>(BI->convertInitializerTo(IntRecTy::get()));
533 ResOp = ResultOperand(II->getValue());
537 // If both are Operands with the same MVT, allow the conversion. It's
538 // up to the user to make sure the values are appropriate, just like
540 if (InstOpRec->isSubClassOf("Operand") && ADI &&
541 ADI->getDef()->isSubClassOf("Operand")) {
542 // FIXME: What other attributes should we check here? Identical
543 // MIOperandInfo perhaps?
544 if (InstOpRec->getValueInit("Type") != ADI->getDef()->getValueInit("Type"))
546 ResOp = ResultOperand(Result->getArgName(AliasOpNo), ADI->getDef());
553 unsigned CodeGenInstAlias::ResultOperand::getMINumOperands() const {
557 Record *Rec = getRecord();
558 if (!Rec->isSubClassOf("Operand"))
561 DagInit *MIOpInfo = Rec->getValueAsDag("MIOperandInfo");
562 if (MIOpInfo->getNumArgs() == 0) {
563 // Unspecified, so it defaults to 1
567 return MIOpInfo->getNumArgs();
570 CodeGenInstAlias::CodeGenInstAlias(Record *R, unsigned Variant,
573 Result = R->getValueAsDag("ResultInst");
574 AsmString = R->getValueAsString("AsmString");
575 AsmString = CodeGenInstruction::FlattenAsmStringVariants(AsmString, Variant);
578 // Verify that the root of the result is an instruction.
579 DefInit *DI = dyn_cast<DefInit>(Result->getOperator());
580 if (!DI || !DI->getDef()->isSubClassOf("Instruction"))
581 PrintFatalError(R->getLoc(),
582 "result of inst alias should be an instruction");
584 ResultInst = &T.getInstruction(DI->getDef());
586 // NameClass - If argument names are repeated, we need to verify they have
588 StringMap<Record*> NameClass;
589 for (unsigned i = 0, e = Result->getNumArgs(); i != e; ++i) {
590 DefInit *ADI = dyn_cast<DefInit>(Result->getArg(i));
591 if (!ADI || Result->getArgName(i).empty())
593 // Verify we don't have something like: (someinst GR16:$foo, GR32:$foo)
594 // $foo can exist multiple times in the result list, but it must have the
596 Record *&Entry = NameClass[Result->getArgName(i)];
597 if (Entry && Entry != ADI->getDef())
598 PrintFatalError(R->getLoc(), "result value $" + Result->getArgName(i) +
599 " is both " + Entry->getName() + " and " +
600 ADI->getDef()->getName() + "!");
601 Entry = ADI->getDef();
604 // Decode and validate the arguments of the result.
605 unsigned AliasOpNo = 0;
606 for (unsigned i = 0, e = ResultInst->Operands.size(); i != e; ++i) {
608 // Tied registers don't have an entry in the result dag unless they're part
609 // of a complex operand, in which case we include them anyways, as we
610 // don't have any other way to specify the whole operand.
611 if (ResultInst->Operands[i].MINumOperands == 1 &&
612 ResultInst->Operands[i].getTiedRegister() != -1)
615 if (AliasOpNo >= Result->getNumArgs())
616 PrintFatalError(R->getLoc(), "not enough arguments for instruction!");
618 Record *InstOpRec = ResultInst->Operands[i].Rec;
619 unsigned NumSubOps = ResultInst->Operands[i].MINumOperands;
620 ResultOperand ResOp(static_cast<int64_t>(0));
621 if (tryAliasOpMatch(Result, AliasOpNo, InstOpRec, (NumSubOps > 1),
622 R->getLoc(), T, ResOp)) {
623 // If this is a simple operand, or a complex operand with a custom match
624 // class, then we can match is verbatim.
625 if (NumSubOps == 1 ||
626 (InstOpRec->getValue("ParserMatchClass") &&
627 InstOpRec->getValueAsDef("ParserMatchClass")
628 ->getValueAsString("Name") != "Imm")) {
629 ResultOperands.push_back(ResOp);
630 ResultInstOperandIndex.push_back(std::make_pair(i, -1));
633 // Otherwise, we need to match each of the suboperands individually.
635 DagInit *MIOI = ResultInst->Operands[i].MIOperandInfo;
636 for (unsigned SubOp = 0; SubOp != NumSubOps; ++SubOp) {
637 Record *SubRec = cast<DefInit>(MIOI->getArg(SubOp))->getDef();
639 // Take care to instantiate each of the suboperands with the correct
640 // nomenclature: $foo.bar
641 ResultOperands.push_back(
642 ResultOperand(Result->getArgName(AliasOpNo) + "." +
643 MIOI->getArgName(SubOp), SubRec));
644 ResultInstOperandIndex.push_back(std::make_pair(i, SubOp));
651 // If the argument did not match the instruction operand, and the operand
652 // is composed of multiple suboperands, try matching the suboperands.
654 DagInit *MIOI = ResultInst->Operands[i].MIOperandInfo;
655 for (unsigned SubOp = 0; SubOp != NumSubOps; ++SubOp) {
656 if (AliasOpNo >= Result->getNumArgs())
657 PrintFatalError(R->getLoc(), "not enough arguments for instruction!");
658 Record *SubRec = cast<DefInit>(MIOI->getArg(SubOp))->getDef();
659 if (tryAliasOpMatch(Result, AliasOpNo, SubRec, false,
660 R->getLoc(), T, ResOp)) {
661 ResultOperands.push_back(ResOp);
662 ResultInstOperandIndex.push_back(std::make_pair(i, SubOp));
665 PrintFatalError(R->getLoc(), "result argument #" + Twine(AliasOpNo) +
666 " does not match instruction operand class " +
667 (SubOp == 0 ? InstOpRec->getName() :SubRec->getName()));
672 PrintFatalError(R->getLoc(), "result argument #" + Twine(AliasOpNo) +
673 " does not match instruction operand class " +
674 InstOpRec->getName());
677 if (AliasOpNo != Result->getNumArgs())
678 PrintFatalError(R->getLoc(), "too many operands for instruction!");