blob: 20edef5a71c99e673349d996fa9239389082777f [file] [log] [blame]
Chris Lattnerea2d52d2008-01-06 01:35:39 +00001//===- CodeGenInstruction.cpp - CodeGen Instruction Class Wrapper ---------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the CodeGenInstruction class.
11//
12//===----------------------------------------------------------------------===//
13
14#include "CodeGenInstruction.h"
Chris Lattner7bc5d9b2010-03-27 20:09:24 +000015#include "CodeGenTarget.h"
Chandler Carruth91d19d82012-12-04 10:37:14 +000016#include "llvm/ADT/STLExtras.h"
Chris Lattnerea2d52d2008-01-06 01:35:39 +000017#include "llvm/ADT/StringExtras.h"
Chris Lattnerb625dd22010-11-06 07:06:09 +000018#include "llvm/ADT/StringMap.h"
Chandler Carruth91d19d82012-12-04 10:37:14 +000019#include "llvm/TableGen/Error.h"
20#include "llvm/TableGen/Record.h"
Chris Lattnerea2d52d2008-01-06 01:35:39 +000021#include <set>
22using namespace llvm;
23
Chris Lattnerd8adec72010-11-01 04:03:32 +000024//===----------------------------------------------------------------------===//
25// CGIOperandList Implementation
26//===----------------------------------------------------------------------===//
Jim Grosbach2a282f22009-12-16 19:43:02 +000027
Chris Lattnerd8adec72010-11-01 04:03:32 +000028CGIOperandList::CGIOperandList(Record *R) : TheDef(R) {
29 isPredicable = false;
Chris Lattnerea2d52d2008-01-06 01:35:39 +000030 hasOptionalDef = false;
Chris Lattnerf376c992008-01-07 05:19:29 +000031 isVariadic = false;
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +000032
David Greeneaf8ee2c2011-07-29 22:43:06 +000033 DagInit *OutDI = R->getValueAsDag("OutOperandList");
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +000034
Sean Silvafb509ed2012-10-10 20:24:43 +000035 if (DefInit *Init = dyn_cast<DefInit>(OutDI->getOperator())) {
Chris Lattner0f037472010-03-18 20:56:35 +000036 if (Init->getDef()->getName() != "outs")
Joerg Sonnenberger635debe2012-10-25 20:33:17 +000037 PrintFatalError(R->getName() + ": invalid def name for output list: use 'outs'");
Chris Lattner5f418ea2010-03-18 20:50:52 +000038 } else
Joerg Sonnenberger635debe2012-10-25 20:33:17 +000039 PrintFatalError(R->getName() + ": invalid output list: use 'outs'");
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +000040
Chris Lattner1f22d272010-03-18 21:07:39 +000041 NumDefs = OutDI->getNumArgs();
Chris Lattnerd8adec72010-11-01 04:03:32 +000042
David Greeneaf8ee2c2011-07-29 22:43:06 +000043 DagInit *InDI = R->getValueAsDag("InOperandList");
Sean Silvafb509ed2012-10-10 20:24:43 +000044 if (DefInit *Init = dyn_cast<DefInit>(InDI->getOperator())) {
Chris Lattner0f037472010-03-18 20:56:35 +000045 if (Init->getDef()->getName() != "ins")
Joerg Sonnenberger635debe2012-10-25 20:33:17 +000046 PrintFatalError(R->getName() + ": invalid def name for input list: use 'ins'");
Chris Lattner5f418ea2010-03-18 20:50:52 +000047 } else
Joerg Sonnenberger635debe2012-10-25 20:33:17 +000048 PrintFatalError(R->getName() + ": invalid input list: use 'ins'");
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +000049
Chris Lattnerea2d52d2008-01-06 01:35:39 +000050 unsigned MIOperandNo = 0;
51 std::set<std::string> OperandNames;
Chris Lattner1f22d272010-03-18 21:07:39 +000052 for (unsigned i = 0, e = InDI->getNumArgs()+OutDI->getNumArgs(); i != e; ++i){
David Greeneaf8ee2c2011-07-29 22:43:06 +000053 Init *ArgInit;
Chris Lattner1f22d272010-03-18 21:07:39 +000054 std::string ArgName;
55 if (i < NumDefs) {
56 ArgInit = OutDI->getArg(i);
57 ArgName = OutDI->getArgName(i);
58 } else {
59 ArgInit = InDI->getArg(i-NumDefs);
60 ArgName = InDI->getArgName(i-NumDefs);
61 }
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +000062
Sean Silvafb509ed2012-10-10 20:24:43 +000063 DefInit *Arg = dyn_cast<DefInit>(ArgInit);
Chris Lattnerea2d52d2008-01-06 01:35:39 +000064 if (!Arg)
Joerg Sonnenberger635debe2012-10-25 20:33:17 +000065 PrintFatalError("Illegal operand for the '" + R->getName() + "' instruction!");
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +000066
Chris Lattnerea2d52d2008-01-06 01:35:39 +000067 Record *Rec = Arg->getDef();
68 std::string PrintMethod = "printOperand";
Jim Grosbach51a12eb2010-10-12 22:21:57 +000069 std::string EncoderMethod;
Benjamin Kramerc8dc46b2011-07-14 21:47:18 +000070 std::string OperandType = "OPERAND_UNKNOWN";
Chris Lattnerea2d52d2008-01-06 01:35:39 +000071 unsigned NumOps = 1;
Craig Topper24064772014-04-15 07:20:03 +000072 DagInit *MIOpInfo = nullptr;
Owen Andersona84be6c2011-06-27 21:06:21 +000073 if (Rec->isSubClassOf("RegisterOperand")) {
74 PrintMethod = Rec->getValueAsString("PrintMethod");
75 } else if (Rec->isSubClassOf("Operand")) {
Chris Lattnerea2d52d2008-01-06 01:35:39 +000076 PrintMethod = Rec->getValueAsString("PrintMethod");
Benjamin Kramerc8dc46b2011-07-14 21:47:18 +000077 OperandType = Rec->getValueAsString("OperandType");
Jim Grosbach51a12eb2010-10-12 22:21:57 +000078 // If there is an explicit encoder method, use it.
Chris Lattner63274cb2010-11-15 05:19:05 +000079 EncoderMethod = Rec->getValueAsString("EncoderMethod");
Chris Lattnerea2d52d2008-01-06 01:35:39 +000080 MIOpInfo = Rec->getValueAsDag("MIOperandInfo");
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +000081
Chris Lattnerea2d52d2008-01-06 01:35:39 +000082 // Verify that MIOpInfo has an 'ops' root value.
Sean Silva88eb8dd2012-10-10 20:24:47 +000083 if (!isa<DefInit>(MIOpInfo->getOperator()) ||
84 cast<DefInit>(MIOpInfo->getOperator())->getDef()->getName() != "ops")
Joerg Sonnenberger635debe2012-10-25 20:33:17 +000085 PrintFatalError("Bad value for MIOperandInfo in operand '" + Rec->getName() +
86 "'\n");
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +000087
Chris Lattnerea2d52d2008-01-06 01:35:39 +000088 // If we have MIOpInfo, then we have #operands equal to number of entries
89 // in MIOperandInfo.
90 if (unsigned NumArgs = MIOpInfo->getNumArgs())
91 NumOps = NumArgs;
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +000092
Tim Northover42180442013-08-22 09:57:11 +000093 if (Rec->isSubClassOf("PredicateOp"))
Chris Lattnerea2d52d2008-01-06 01:35:39 +000094 isPredicable = true;
95 else if (Rec->isSubClassOf("OptionalDefOperand"))
96 hasOptionalDef = true;
97 } else if (Rec->getName() == "variable_ops") {
Chris Lattnerf376c992008-01-07 05:19:29 +000098 isVariadic = true;
Chris Lattnerea2d52d2008-01-06 01:35:39 +000099 continue;
Benjamin Kramerc8dc46b2011-07-14 21:47:18 +0000100 } else if (Rec->isSubClassOf("RegisterClass")) {
101 OperandType = "OPERAND_REGISTER";
102 } else if (!Rec->isSubClassOf("PointerLikeRegClass") &&
Owen Anderson16ba4b22012-09-11 23:47:08 +0000103 !Rec->isSubClassOf("unknown_class"))
Joerg Sonnenberger635debe2012-10-25 20:33:17 +0000104 PrintFatalError("Unknown operand class '" + Rec->getName() +
105 "' in '" + R->getName() + "' instruction!");
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +0000106
Chris Lattnerea2d52d2008-01-06 01:35:39 +0000107 // Check that the operand has a name and that it's unique.
Chris Lattner1f22d272010-03-18 21:07:39 +0000108 if (ArgName.empty())
Benjamin Kramer48e7e852014-03-29 17:17:15 +0000109 PrintFatalError("In instruction '" + R->getName() + "', operand #" +
110 Twine(i) + " has no name!");
Chris Lattner1f22d272010-03-18 21:07:39 +0000111 if (!OperandNames.insert(ArgName).second)
Benjamin Kramer48e7e852014-03-29 17:17:15 +0000112 PrintFatalError("In instruction '" + R->getName() + "', operand #" +
113 Twine(i) + " has the same name as a previous operand!");
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +0000114
Jim Grosbach51a12eb2010-10-12 22:21:57 +0000115 OperandList.push_back(OperandInfo(Rec, ArgName, PrintMethod, EncoderMethod,
Benjamin Kramerc8dc46b2011-07-14 21:47:18 +0000116 OperandType, MIOperandNo, NumOps,
117 MIOpInfo));
Chris Lattnerea2d52d2008-01-06 01:35:39 +0000118 MIOperandNo += NumOps;
119 }
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +0000120
121
Chris Lattnerdd3b09c2010-11-01 05:34:34 +0000122 // 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);
Chris Lattnerea2d52d2008-01-06 01:35:39 +0000126}
127
Chris Lattnerd8adec72010-11-01 04:03:32 +0000128
Chris Lattnerea2d52d2008-01-06 01:35:39 +0000129/// getOperandNamed - Return the index of the operand with the specified
130/// non-empty name. If the instruction does not have an operand with the
Joerg Sonnenberger635debe2012-10-25 20:33:17 +0000131/// specified name, abort.
Chris Lattnerea2d52d2008-01-06 01:35:39 +0000132///
Chris Lattnerd8adec72010-11-01 04:03:32 +0000133unsigned CGIOperandList::getOperandNamed(StringRef Name) const {
Jim Grosbach191ad7c2010-10-11 18:25:51 +0000134 unsigned OpIdx;
135 if (hasOperandNamed(Name, OpIdx)) return OpIdx;
Benjamin Kramer48e7e852014-03-29 17:17:15 +0000136 PrintFatalError("'" + TheDef->getName() +
137 "' does not have an operand named '$" + Name + "'!");
Chris Lattnerea2d52d2008-01-06 01:35:39 +0000138}
139
Jim Grosbach191ad7c2010-10-11 18:25:51 +0000140/// 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.
Chris Lattnerd8adec72010-11-01 04:03:32 +0000143bool CGIOperandList::hasOperandNamed(StringRef Name, unsigned &OpIdx) const {
Jim Grosbach191ad7c2010-10-11 18:25:51 +0000144 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) {
147 OpIdx = i;
148 return true;
149 }
150 return false;
151}
152
Jim Grosbach38c4f4b2009-12-15 19:28:13 +0000153std::pair<unsigned,unsigned>
Chris Lattnerd8adec72010-11-01 04:03:32 +0000154CGIOperandList::ParseOperandName(const std::string &Op, bool AllowWholeOp) {
Chris Lattnerea2d52d2008-01-06 01:35:39 +0000155 if (Op.empty() || Op[0] != '$')
Joerg Sonnenberger635debe2012-10-25 20:33:17 +0000156 PrintFatalError(TheDef->getName() + ": Illegal operand name: '" + Op + "'");
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +0000157
Chris Lattnerea2d52d2008-01-06 01:35:39 +0000158 std::string OpName = Op.substr(1);
159 std::string SubOpName;
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +0000160
Chris Lattnerea2d52d2008-01-06 01:35:39 +0000161 // 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())
Joerg Sonnenberger635debe2012-10-25 20:33:17 +0000166 PrintFatalError(TheDef->getName() + ": illegal empty suboperand name in '" +Op +"'");
Chris Lattnerea2d52d2008-01-06 01:35:39 +0000167 OpName = OpName.substr(0, DotIdx);
168 }
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +0000169
Chris Lattnerea2d52d2008-01-06 01:35:39 +0000170 unsigned OpIdx = getOperandNamed(OpName);
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +0000171
Chris Lattnerea2d52d2008-01-06 01:35:39 +0000172 if (SubOpName.empty()) { // If no suboperand name was specified:
173 // If one was needed, throw.
174 if (OperandList[OpIdx].MINumOperands > 1 && !AllowWholeOp &&
175 SubOpName.empty())
Joerg Sonnenberger635debe2012-10-25 20:33:17 +0000176 PrintFatalError(TheDef->getName() + ": Illegal to refer to"
177 " whole operand part of complex operand '" + Op + "'");
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +0000178
Chris Lattnerea2d52d2008-01-06 01:35:39 +0000179 // Otherwise, return the operand.
180 return std::make_pair(OpIdx, 0U);
181 }
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +0000182
Chris Lattnerea2d52d2008-01-06 01:35:39 +0000183 // Find the suboperand number involved.
David Greeneaf8ee2c2011-07-29 22:43:06 +0000184 DagInit *MIOpInfo = OperandList[OpIdx].MIOperandInfo;
Craig Topper24064772014-04-15 07:20:03 +0000185 if (!MIOpInfo)
Joerg Sonnenberger635debe2012-10-25 20:33:17 +0000186 PrintFatalError(TheDef->getName() + ": unknown suboperand name in '" + Op + "'");
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +0000187
Chris Lattnerea2d52d2008-01-06 01:35:39 +0000188 // 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);
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +0000192
Chris Lattnerea2d52d2008-01-06 01:35:39 +0000193 // Otherwise, didn't find it!
Joerg Sonnenberger635debe2012-10-25 20:33:17 +0000194 PrintFatalError(TheDef->getName() + ": unknown suboperand name in '" + Op + "'");
Aaron Ballman414a0cd2013-08-16 01:43:31 +0000195 return std::make_pair(0U, 0U);
Chris Lattnerea2d52d2008-01-06 01:35:39 +0000196}
Chris Lattner7bc5d9b2010-03-27 20:09:24 +0000197
Chris Lattnerd8adec72010-11-01 04:03:32 +0000198static 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)
Joerg Sonnenberger635debe2012-10-25 20:33:17 +0000207 PrintFatalError("Illegal format for @earlyclobber constraint: '" + CStr + "'");
Chris Lattnerd8adec72010-11-01 04:03:32 +0000208 Name = Name.substr(wpos);
209 std::pair<unsigned,unsigned> Op = Ops.ParseOperandName(Name, false);
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +0000210
Chris Lattnerd8adec72010-11-01 04:03:32 +0000211 // Build the string for the operand
212 if (!Ops[Op.first].Constraints[Op.second].isNone())
Joerg Sonnenberger635debe2012-10-25 20:33:17 +0000213 PrintFatalError("Operand '" + Name + "' cannot have multiple constraints!");
Chris Lattnerd8adec72010-11-01 04:03:32 +0000214 Ops[Op.first].Constraints[Op.second] =
215 CGIOperandList::ConstraintInfo::getEarlyClobber();
216 return;
217 }
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +0000218
Chris Lattnerd8adec72010-11-01 04:03:32 +0000219 // 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);
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +0000224
Chris Lattnerd8adec72010-11-01 04:03:32 +0000225 // TIED_TO: $src1 = $dst
226 wpos = Name.find_first_of(" \t");
227 if (wpos == std::string::npos)
Joerg Sonnenberger635debe2012-10-25 20:33:17 +0000228 PrintFatalError("Illegal format for tied-to constraint: '" + CStr + "'");
Chris Lattnerd8adec72010-11-01 04:03:32 +0000229 std::string DestOpName = Name.substr(0, wpos);
230 std::pair<unsigned,unsigned> DestOp = Ops.ParseOperandName(DestOpName, false);
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +0000231
Chris Lattnerd8adec72010-11-01 04:03:32 +0000232 Name = CStr.substr(pos+1);
233 wpos = Name.find_first_not_of(" \t");
234 if (wpos == std::string::npos)
Joerg Sonnenberger635debe2012-10-25 20:33:17 +0000235 PrintFatalError("Illegal format for tied-to constraint: '" + CStr + "'");
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +0000236
Lang Hamescdd40bd2012-10-20 22:44:13 +0000237 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);
242 }
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +0000243
Chris Lattnerd8adec72010-11-01 04:03:32 +0000244 unsigned FlatOpNo = Ops.getFlattenedOperandNumber(SrcOp);
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +0000245
Chris Lattnerd8adec72010-11-01 04:03:32 +0000246 if (!Ops[DestOp.first].Constraints[DestOp.second].isNone())
Joerg Sonnenberger635debe2012-10-25 20:33:17 +0000247 PrintFatalError("Operand '" + DestOpName +
248 "' cannot have multiple constraints!");
Chris Lattnerd8adec72010-11-01 04:03:32 +0000249 Ops[DestOp.first].Constraints[DestOp.second] =
Jim Grosbach7b03fbd2011-11-15 01:05:12 +0000250 CGIOperandList::ConstraintInfo::getTied(FlatOpNo);
Chris Lattnerd8adec72010-11-01 04:03:32 +0000251}
252
253static void ParseConstraints(const std::string &CStr, CGIOperandList &Ops) {
Chris Lattnerd8adec72010-11-01 04:03:32 +0000254 if (CStr.empty()) return;
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +0000255
Chris Lattnerd8adec72010-11-01 04:03:32 +0000256 const std::string delims(",");
257 std::string::size_type bidx, eidx;
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +0000258
Chris Lattnerd8adec72010-11-01 04:03:32 +0000259 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();
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +0000264
Chris Lattnerd8adec72010-11-01 04:03:32 +0000265 ParseConstraint(CStr.substr(bidx, eidx - bidx), Ops);
266 bidx = CStr.find_first_not_of(delims, eidx);
267 }
268}
269
270void CGIOperandList::ProcessDisableEncoding(std::string DisableEncoding) {
271 while (1) {
Chris Lattner5cf753c2011-07-21 06:21:31 +0000272 std::pair<StringRef, StringRef> P = getToken(DisableEncoding, " ,\t");
273 std::string OpName = P.first;
274 DisableEncoding = P.second;
Chris Lattnerd8adec72010-11-01 04:03:32 +0000275 if (OpName.empty()) break;
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +0000276
Chris Lattnerd8adec72010-11-01 04:03:32 +0000277 // Figure out which operand this is.
278 std::pair<unsigned,unsigned> Op = ParseOperandName(OpName, false);
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +0000279
Chris Lattnerd8adec72010-11-01 04:03:32 +0000280 // 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;
284 }
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +0000285
Chris Lattnerd8adec72010-11-01 04:03:32 +0000286}
287
288//===----------------------------------------------------------------------===//
289// CodeGenInstruction Implementation
290//===----------------------------------------------------------------------===//
291
Jakob Stoklund Olesen94ed4d42012-08-24 00:31:16 +0000292CodeGenInstruction::CodeGenInstruction(Record *R)
Craig Topper24064772014-04-15 07:20:03 +0000293 : TheDef(R), Operands(R), InferredFrom(nullptr) {
Chris Lattnerd8adec72010-11-01 04:03:32 +0000294 Namespace = R->getValueAsString("Namespace");
295 AsmString = R->getValueAsString("AsmString");
296
297 isReturn = R->getValueAsBit("isReturn");
298 isBranch = R->getValueAsBit("isBranch");
299 isIndirectBranch = R->getValueAsBit("isIndirectBranch");
300 isCompare = R->getValueAsBit("isCompare");
Evan Cheng7f8ab6e2010-11-17 20:13:28 +0000301 isMoveImm = R->getValueAsBit("isMoveImm");
Evan Cheng880e299d2011-03-15 05:09:26 +0000302 isBitcast = R->getValueAsBit("isBitcast");
Jakob Stoklund Olesen2382d322012-08-16 23:11:47 +0000303 isSelect = R->getValueAsBit("isSelect");
Chris Lattnerd8adec72010-11-01 04:03:32 +0000304 isBarrier = R->getValueAsBit("isBarrier");
305 isCall = R->getValueAsBit("isCall");
306 canFoldAsLoad = R->getValueAsBit("canFoldAsLoad");
Chris Lattnerd8adec72010-11-01 04:03:32 +0000307 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");
Andrew Trick52363bd2011-09-20 18:22:31 +0000314 hasPostISelHook = R->getValueAsBit("hasPostISelHook");
Chris Lattnerd8adec72010-11-01 04:03:32 +0000315 hasCtrlDep = R->getValueAsBit("hasCtrlDep");
316 isNotDuplicable = R->getValueAsBit("isNotDuplicable");
Quentin Colombetd533cdf2014-08-11 22:17:14 +0000317 isRegSequence = R->getValueAsBit("isRegSequence");
Quentin Colombet7e75cba2014-08-20 21:51:26 +0000318 isExtractSubreg = R->getValueAsBit("isExtractSubreg");
Jakob Stoklund Olesenaf507bf2012-08-23 19:34:46 +0000319
Craig Topperbc9486b2014-02-05 09:10:40 +0000320 bool Unset;
321 mayLoad = R->getValueAsBitOrUnset("mayLoad", Unset);
322 mayLoad_Unset = Unset;
323 mayStore = R->getValueAsBitOrUnset("mayStore", Unset);
324 mayStore_Unset = Unset;
325 hasSideEffects = R->getValueAsBitOrUnset("hasSideEffects", Unset);
326 hasSideEffects_Unset = Unset;
Chris Lattnerd8adec72010-11-01 04:03:32 +0000327 neverHasSideEffects = R->getValueAsBit("neverHasSideEffects");
Jakob Stoklund Olesenaf507bf2012-08-23 19:34:46 +0000328
Chris Lattnerd8adec72010-11-01 04:03:32 +0000329 isAsCheapAsAMove = R->getValueAsBit("isAsCheapAsAMove");
330 hasExtraSrcRegAllocReq = R->getValueAsBit("hasExtraSrcRegAllocReq");
331 hasExtraDefRegAllocReq = R->getValueAsBit("hasExtraDefRegAllocReq");
Jim Grosbach4c08a9f2011-07-07 00:48:02 +0000332 isCodeGenOnly = R->getValueAsBit("isCodeGenOnly");
Jim Grosbachf3fd36e2011-07-06 21:33:38 +0000333 isPseudo = R->getValueAsBit("isPseudo");
Chris Lattnerd8adec72010-11-01 04:03:32 +0000334 ImplicitDefs = R->getValueAsListOfDefs("Defs");
335 ImplicitUses = R->getValueAsListOfDefs("Uses");
336
337 if (neverHasSideEffects + hasSideEffects > 1)
Joerg Sonnenberger635debe2012-10-25 20:33:17 +0000338 PrintFatalError(R->getName() + ": multiple conflicting side-effect flags set!");
Chris Lattnerd8adec72010-11-01 04:03:32 +0000339
340 // Parse Constraints.
341 ParseConstraints(R->getValueAsString("Constraints"), Operands);
342
343 // Parse the DisableEncoding field.
344 Operands.ProcessDisableEncoding(R->getValueAsString("DisableEncoding"));
Joey Gouly0e76fa72013-09-12 10:28:05 +0000345
346 // First check for a ComplexDeprecationPredicate.
347 if (R->getValue("ComplexDeprecationPredicate")) {
348 HasComplexDeprecationPredicate = true;
349 DeprecatedReason = R->getValueAsString("ComplexDeprecationPredicate");
350 } else if (RecordVal *Dep = R->getValue("DeprecatedFeatureMask")) {
351 // Check if we have a Subtarget feature mask.
352 HasComplexDeprecationPredicate = false;
353 DeprecatedReason = Dep->getValue()->getAsString();
354 } else {
355 // This instruction isn't deprecated.
356 HasComplexDeprecationPredicate = false;
357 DeprecatedReason = "";
358 }
Chris Lattnerd8adec72010-11-01 04:03:32 +0000359}
Chris Lattner7bc5d9b2010-03-27 20:09:24 +0000360
361/// HasOneImplicitDefWithKnownVT - If the instruction has at least one
362/// implicit def and it has a known VT, return the VT, otherwise return
363/// MVT::Other.
364MVT::SimpleValueType CodeGenInstruction::
365HasOneImplicitDefWithKnownVT(const CodeGenTarget &TargetInfo) const {
366 if (ImplicitDefs.empty()) return MVT::Other;
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +0000367
Chris Lattner7bc5d9b2010-03-27 20:09:24 +0000368 // Check to see if the first implicit def has a resolvable type.
369 Record *FirstImplicitDef = ImplicitDefs[0];
370 assert(FirstImplicitDef->isSubClassOf("Register"));
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +0000371 const std::vector<MVT::SimpleValueType> &RegVTs =
Chris Lattner7bc5d9b2010-03-27 20:09:24 +0000372 TargetInfo.getRegisterVTs(FirstImplicitDef);
373 if (RegVTs.size() == 1)
374 return RegVTs[0];
375 return MVT::Other;
376}
377
Chris Lattner25d9c7f2010-11-01 01:07:14 +0000378
379/// FlattenAsmStringVariants - Flatten the specified AsmString to only
380/// include text from the specified variant, returning the new string.
381std::string CodeGenInstruction::
382FlattenAsmStringVariants(StringRef Cur, unsigned Variant) {
383 std::string Res = "";
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +0000384
Chris Lattner25d9c7f2010-11-01 01:07:14 +0000385 for (;;) {
386 // Find the start of the next variant string.
387 size_t VariantsStart = 0;
388 for (size_t e = Cur.size(); VariantsStart != e; ++VariantsStart)
389 if (Cur[VariantsStart] == '{' &&
390 (VariantsStart == 0 || (Cur[VariantsStart-1] != '$' &&
391 Cur[VariantsStart-1] != '\\')))
392 break;
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +0000393
Chris Lattner25d9c7f2010-11-01 01:07:14 +0000394 // Add the prefix to the result.
395 Res += Cur.slice(0, VariantsStart);
396 if (VariantsStart == Cur.size())
397 break;
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +0000398
Chris Lattner25d9c7f2010-11-01 01:07:14 +0000399 ++VariantsStart; // Skip the '{'.
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +0000400
Chris Lattner25d9c7f2010-11-01 01:07:14 +0000401 // Scan to the end of the variants string.
402 size_t VariantsEnd = VariantsStart;
403 unsigned NestedBraces = 1;
404 for (size_t e = Cur.size(); VariantsEnd != e; ++VariantsEnd) {
405 if (Cur[VariantsEnd] == '}' && Cur[VariantsEnd-1] != '\\') {
406 if (--NestedBraces == 0)
407 break;
408 } else if (Cur[VariantsEnd] == '{')
409 ++NestedBraces;
410 }
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +0000411
Chris Lattner25d9c7f2010-11-01 01:07:14 +0000412 // Select the Nth variant (or empty).
413 StringRef Selection = Cur.slice(VariantsStart, VariantsEnd);
414 for (unsigned i = 0; i != Variant; ++i)
415 Selection = Selection.split('|').second;
416 Res += Selection.split('|').first;
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +0000417
Chris Lattner25d9c7f2010-11-01 01:07:14 +0000418 assert(VariantsEnd != Cur.size() &&
419 "Unterminated variants in assembly string!");
420 Cur = Cur.substr(VariantsEnd + 1);
421 }
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +0000422
Chris Lattner25d9c7f2010-11-01 01:07:14 +0000423 return Res;
424}
425
Chris Lattner488c2012010-11-01 04:05:41 +0000426
427//===----------------------------------------------------------------------===//
428/// CodeGenInstAlias Implementation
429//===----------------------------------------------------------------------===//
430
Bob Wilsonb9b24222011-01-26 19:44:55 +0000431/// tryAliasOpMatch - This is a helper function for the CodeGenInstAlias
432/// constructor. It checks if an argument in an InstAlias pattern matches
433/// the corresponding operand of the instruction. It returns true on a
434/// successful match, with ResOp set to the result operand to be used.
David Greeneaf8ee2c2011-07-29 22:43:06 +0000435bool CodeGenInstAlias::tryAliasOpMatch(DagInit *Result, unsigned AliasOpNo,
Bob Wilsonb9b24222011-01-26 19:44:55 +0000436 Record *InstOpRec, bool hasSubOps,
Jakob Stoklund Olesend7b66962012-08-22 23:33:58 +0000437 ArrayRef<SMLoc> Loc, CodeGenTarget &T,
Bob Wilsonb9b24222011-01-26 19:44:55 +0000438 ResultOperand &ResOp) {
David Greeneaf8ee2c2011-07-29 22:43:06 +0000439 Init *Arg = Result->getArg(AliasOpNo);
Sean Silvafb509ed2012-10-10 20:24:43 +0000440 DefInit *ADI = dyn_cast<DefInit>(Arg);
Craig Topper24064772014-04-15 07:20:03 +0000441 Record *ResultRecord = ADI ? ADI->getDef() : nullptr;
Bob Wilsonb9b24222011-01-26 19:44:55 +0000442
443 if (ADI && ADI->getDef() == InstOpRec) {
444 // If the operand is a record, it must have a name, and the record type
445 // must match up with the instruction's argument type.
446 if (Result->getArgName(AliasOpNo).empty())
Benjamin Kramer48e7e852014-03-29 17:17:15 +0000447 PrintFatalError(Loc, "result argument #" + Twine(AliasOpNo) +
448 " must have a name!");
Tim Northover3e38d292014-03-29 09:03:22 +0000449 ResOp = ResultOperand(Result->getArgName(AliasOpNo), ResultRecord);
Bob Wilsonb9b24222011-01-26 19:44:55 +0000450 return true;
451 }
452
Jim Grosbach6acb1482011-10-28 16:43:40 +0000453 // For register operands, the source register class can be a subclass
454 // of the instruction register class, not just an exact match.
Tim Northover3e38d292014-03-29 09:03:22 +0000455 if (InstOpRec->isSubClassOf("RegisterOperand"))
456 InstOpRec = InstOpRec->getValueAsDef("RegClass");
457
458 if (ADI && ADI->getDef()->isSubClassOf("RegisterOperand"))
459 ADI = ADI->getDef()->getValueAsDef("RegClass")->getDefInit();
460
Jim Grosbach6acb1482011-10-28 16:43:40 +0000461 if (ADI && ADI->getDef()->isSubClassOf("RegisterClass")) {
462 if (!InstOpRec->isSubClassOf("RegisterClass"))
463 return false;
Jim Grosbachd1f1b792011-10-28 22:32:53 +0000464 if (!T.getRegisterClass(InstOpRec)
465 .hasSubClass(&T.getRegisterClass(ADI->getDef())))
466 return false;
Tim Northover3e38d292014-03-29 09:03:22 +0000467 ResOp = ResultOperand(Result->getArgName(AliasOpNo), ResultRecord);
Jim Grosbachd1f1b792011-10-28 22:32:53 +0000468 return true;
Jim Grosbach6acb1482011-10-28 16:43:40 +0000469 }
470
Bob Wilsonb9b24222011-01-26 19:44:55 +0000471 // Handle explicit registers.
472 if (ADI && ADI->getDef()->isSubClassOf("Register")) {
Jim Grosbacha7b2d442011-08-19 20:33:06 +0000473 if (InstOpRec->isSubClassOf("OptionalDefOperand")) {
474 DagInit *DI = InstOpRec->getValueAsDag("MIOperandInfo");
475 // The operand info should only have a single (register) entry. We
476 // want the register class of it.
Sean Silva88eb8dd2012-10-10 20:24:47 +0000477 InstOpRec = cast<DefInit>(DI->getArg(0))->getDef();
Jim Grosbacha7b2d442011-08-19 20:33:06 +0000478 }
479
Bob Wilsonb9b24222011-01-26 19:44:55 +0000480 if (!InstOpRec->isSubClassOf("RegisterClass"))
481 return false;
482
Jakob Stoklund Olesend7bc5c22011-06-15 04:50:36 +0000483 if (!T.getRegisterClass(InstOpRec)
484 .contains(T.getRegBank().getReg(ADI->getDef())))
Joerg Sonnenberger635debe2012-10-25 20:33:17 +0000485 PrintFatalError(Loc, "fixed register " + ADI->getDef()->getName() +
486 " is not a member of the " + InstOpRec->getName() +
487 " register class!");
Bob Wilsonb9b24222011-01-26 19:44:55 +0000488
489 if (!Result->getArgName(AliasOpNo).empty())
Joerg Sonnenberger635debe2012-10-25 20:33:17 +0000490 PrintFatalError(Loc, "result fixed register argument must "
491 "not have a name!");
Bob Wilsonb9b24222011-01-26 19:44:55 +0000492
Tim Northover3e38d292014-03-29 09:03:22 +0000493 ResOp = ResultOperand(ResultRecord);
Bob Wilsonb9b24222011-01-26 19:44:55 +0000494 return true;
495 }
496
497 // Handle "zero_reg" for optional def operands.
498 if (ADI && ADI->getDef()->getName() == "zero_reg") {
499
500 // Check if this is an optional def.
Jim Grosbach29cdcda2011-11-15 01:46:57 +0000501 // Tied operands where the source is a sub-operand of a complex operand
502 // need to represent both operands in the alias destination instruction.
503 // Allow zero_reg for the tied portion. This can and should go away once
504 // the MC representation of things doesn't use tied operands at all.
505 //if (!InstOpRec->isSubClassOf("OptionalDefOperand"))
506 // throw TGError(Loc, "reg0 used for result that is not an "
507 // "OptionalDefOperand!");
Bob Wilsonb9b24222011-01-26 19:44:55 +0000508
Craig Topper24064772014-04-15 07:20:03 +0000509 ResOp = ResultOperand(static_cast<Record*>(nullptr));
Bob Wilsonb9b24222011-01-26 19:44:55 +0000510 return true;
511 }
512
Jim Grosbachd1f1b792011-10-28 22:32:53 +0000513 // Literal integers.
Sean Silvafb509ed2012-10-10 20:24:43 +0000514 if (IntInit *II = dyn_cast<IntInit>(Arg)) {
Bob Wilsonb9b24222011-01-26 19:44:55 +0000515 if (hasSubOps || !InstOpRec->isSubClassOf("Operand"))
516 return false;
517 // Integer arguments can't have names.
518 if (!Result->getArgName(AliasOpNo).empty())
Benjamin Kramer48e7e852014-03-29 17:17:15 +0000519 PrintFatalError(Loc, "result argument #" + Twine(AliasOpNo) +
Joerg Sonnenberger635debe2012-10-25 20:33:17 +0000520 " must not have a name!");
Bob Wilsonb9b24222011-01-26 19:44:55 +0000521 ResOp = ResultOperand(II->getValue());
522 return true;
523 }
524
Pete Cooper2cfdfe52014-08-07 05:47:04 +0000525 // Bits<n> (also used for 0bxx literals)
526 if (BitsInit *BI = dyn_cast<BitsInit>(Arg)) {
527 if (hasSubOps || !InstOpRec->isSubClassOf("Operand"))
528 return false;
529 if (!BI->isComplete())
530 return false;
531 // Convert the bits init to an integer and use that for the result.
532 IntInit *II =
533 dyn_cast_or_null<IntInit>(BI->convertInitializerTo(IntRecTy::get()));
534 if (!II)
535 return false;
536 ResOp = ResultOperand(II->getValue());
537 return true;
538 }
539
Jim Grosbachd1f1b792011-10-28 22:32:53 +0000540 // If both are Operands with the same MVT, allow the conversion. It's
541 // up to the user to make sure the values are appropriate, just like
542 // for isel Pat's.
543 if (InstOpRec->isSubClassOf("Operand") &&
544 ADI->getDef()->isSubClassOf("Operand")) {
545 // FIXME: What other attributes should we check here? Identical
546 // MIOperandInfo perhaps?
547 if (InstOpRec->getValueInit("Type") != ADI->getDef()->getValueInit("Type"))
548 return false;
549 ResOp = ResultOperand(Result->getArgName(AliasOpNo), ADI->getDef());
550 return true;
551 }
552
Bob Wilsonb9b24222011-01-26 19:44:55 +0000553 return false;
554}
555
Tim Northover60091cf2014-05-15 13:36:01 +0000556unsigned CodeGenInstAlias::ResultOperand::getMINumOperands() const {
557 if (!isRecord())
558 return 1;
559
560 Record *Rec = getRecord();
561 if (!Rec->isSubClassOf("Operand"))
562 return 1;
563
564 DagInit *MIOpInfo = Rec->getValueAsDag("MIOperandInfo");
565 if (MIOpInfo->getNumArgs() == 0) {
566 // Unspecified, so it defaults to 1
567 return 1;
568 }
569
570 return MIOpInfo->getNumArgs();
571}
572
Tim Northoverd8d65a62014-05-15 11:16:32 +0000573CodeGenInstAlias::CodeGenInstAlias(Record *R, unsigned Variant,
574 CodeGenTarget &T)
575 : TheDef(R) {
Chris Lattnerdd3b09c2010-11-01 05:34:34 +0000576 Result = R->getValueAsDag("ResultInst");
Tim Northoverd8d65a62014-05-15 11:16:32 +0000577 AsmString = R->getValueAsString("AsmString");
578 AsmString = CodeGenInstruction::FlattenAsmStringVariants(AsmString, Variant);
579
Chris Lattner8ffd1292010-11-06 06:39:47 +0000580
581 // Verify that the root of the result is an instruction.
Sean Silvafb509ed2012-10-10 20:24:43 +0000582 DefInit *DI = dyn_cast<DefInit>(Result->getOperator());
Craig Topper24064772014-04-15 07:20:03 +0000583 if (!DI || !DI->getDef()->isSubClassOf("Instruction"))
Joerg Sonnenberger635debe2012-10-25 20:33:17 +0000584 PrintFatalError(R->getLoc(),
585 "result of inst alias should be an instruction");
Chris Lattner8ffd1292010-11-06 06:39:47 +0000586
587 ResultInst = &T.getInstruction(DI->getDef());
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +0000588
Chris Lattnerb625dd22010-11-06 07:06:09 +0000589 // NameClass - If argument names are repeated, we need to verify they have
590 // the same class.
591 StringMap<Record*> NameClass;
Bob Wilsona48eacc2011-01-20 18:38:10 +0000592 for (unsigned i = 0, e = Result->getNumArgs(); i != e; ++i) {
Sean Silvafb509ed2012-10-10 20:24:43 +0000593 DefInit *ADI = dyn_cast<DefInit>(Result->getArg(i));
Bob Wilsona48eacc2011-01-20 18:38:10 +0000594 if (!ADI || Result->getArgName(i).empty())
595 continue;
596 // Verify we don't have something like: (someinst GR16:$foo, GR32:$foo)
597 // $foo can exist multiple times in the result list, but it must have the
598 // same type.
599 Record *&Entry = NameClass[Result->getArgName(i)];
600 if (Entry && Entry != ADI->getDef())
Joerg Sonnenberger635debe2012-10-25 20:33:17 +0000601 PrintFatalError(R->getLoc(), "result value $" + Result->getArgName(i) +
602 " is both " + Entry->getName() + " and " +
603 ADI->getDef()->getName() + "!");
Bob Wilsona48eacc2011-01-20 18:38:10 +0000604 Entry = ADI->getDef();
605 }
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +0000606
Chris Lattner76030522010-11-06 06:54:38 +0000607 // Decode and validate the arguments of the result.
Chris Lattner8188fb22010-11-06 07:31:43 +0000608 unsigned AliasOpNo = 0;
609 for (unsigned i = 0, e = ResultInst->Operands.size(); i != e; ++i) {
Bob Wilsonb9b24222011-01-26 19:44:55 +0000610
Jim Grosbach29cdcda2011-11-15 01:46:57 +0000611 // Tied registers don't have an entry in the result dag unless they're part
612 // of a complex operand, in which case we include them anyways, as we
613 // don't have any other way to specify the whole operand.
614 if (ResultInst->Operands[i].MINumOperands == 1 &&
615 ResultInst->Operands[i].getTiedRegister() != -1)
Chris Lattner8188fb22010-11-06 07:31:43 +0000616 continue;
617
618 if (AliasOpNo >= Result->getNumArgs())
Joerg Sonnenberger635debe2012-10-25 20:33:17 +0000619 PrintFatalError(R->getLoc(), "not enough arguments for instruction!");
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +0000620
Bob Wilsonb9b24222011-01-26 19:44:55 +0000621 Record *InstOpRec = ResultInst->Operands[i].Rec;
622 unsigned NumSubOps = ResultInst->Operands[i].MINumOperands;
623 ResultOperand ResOp(static_cast<int64_t>(0));
624 if (tryAliasOpMatch(Result, AliasOpNo, InstOpRec, (NumSubOps > 1),
625 R->getLoc(), T, ResOp)) {
Owen Andersonda6bd3e2012-06-08 00:25:03 +0000626 // If this is a simple operand, or a complex operand with a custom match
627 // class, then we can match is verbatim.
628 if (NumSubOps == 1 ||
629 (InstOpRec->getValue("ParserMatchClass") &&
630 InstOpRec->getValueAsDef("ParserMatchClass")
631 ->getValueAsString("Name") != "Imm")) {
632 ResultOperands.push_back(ResOp);
633 ResultInstOperandIndex.push_back(std::make_pair(i, -1));
634 ++AliasOpNo;
635
636 // Otherwise, we need to match each of the suboperands individually.
637 } else {
638 DagInit *MIOI = ResultInst->Operands[i].MIOperandInfo;
639 for (unsigned SubOp = 0; SubOp != NumSubOps; ++SubOp) {
Sean Silva88eb8dd2012-10-10 20:24:47 +0000640 Record *SubRec = cast<DefInit>(MIOI->getArg(SubOp))->getDef();
Owen Andersonda6bd3e2012-06-08 00:25:03 +0000641
642 // Take care to instantiate each of the suboperands with the correct
643 // nomenclature: $foo.bar
644 ResultOperands.push_back(
645 ResultOperand(Result->getArgName(AliasOpNo) + "." +
646 MIOI->getArgName(SubOp), SubRec));
647 ResultInstOperandIndex.push_back(std::make_pair(i, SubOp));
648 }
649 ++AliasOpNo;
650 }
Chris Lattner76030522010-11-06 06:54:38 +0000651 continue;
652 }
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +0000653
Bob Wilsonb9b24222011-01-26 19:44:55 +0000654 // If the argument did not match the instruction operand, and the operand
655 // is composed of multiple suboperands, try matching the suboperands.
656 if (NumSubOps > 1) {
David Greeneaf8ee2c2011-07-29 22:43:06 +0000657 DagInit *MIOI = ResultInst->Operands[i].MIOperandInfo;
Bob Wilsonb9b24222011-01-26 19:44:55 +0000658 for (unsigned SubOp = 0; SubOp != NumSubOps; ++SubOp) {
659 if (AliasOpNo >= Result->getNumArgs())
Joerg Sonnenberger635debe2012-10-25 20:33:17 +0000660 PrintFatalError(R->getLoc(), "not enough arguments for instruction!");
Sean Silva88eb8dd2012-10-10 20:24:47 +0000661 Record *SubRec = cast<DefInit>(MIOI->getArg(SubOp))->getDef();
Bob Wilsonb9b24222011-01-26 19:44:55 +0000662 if (tryAliasOpMatch(Result, AliasOpNo, SubRec, false,
663 R->getLoc(), T, ResOp)) {
664 ResultOperands.push_back(ResOp);
665 ResultInstOperandIndex.push_back(std::make_pair(i, SubOp));
666 ++AliasOpNo;
667 } else {
Benjamin Kramer48e7e852014-03-29 17:17:15 +0000668 PrintFatalError(R->getLoc(), "result argument #" + Twine(AliasOpNo) +
Bob Wilsonb9b24222011-01-26 19:44:55 +0000669 " does not match instruction operand class " +
670 (SubOp == 0 ? InstOpRec->getName() :SubRec->getName()));
671 }
672 }
Chris Lattnerb6f8e822010-11-06 19:25:43 +0000673 continue;
674 }
Benjamin Kramer48e7e852014-03-29 17:17:15 +0000675 PrintFatalError(R->getLoc(), "result argument #" + Twine(AliasOpNo) +
Joerg Sonnenberger635debe2012-10-25 20:33:17 +0000676 " does not match instruction operand class " +
677 InstOpRec->getName());
Chris Lattner76030522010-11-06 06:54:38 +0000678 }
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +0000679
Chris Lattner8188fb22010-11-06 07:31:43 +0000680 if (AliasOpNo != Result->getNumArgs())
Joerg Sonnenberger635debe2012-10-25 20:33:17 +0000681 PrintFatalError(R->getLoc(), "too many operands for instruction!");
Chris Lattner488c2012010-11-01 04:05:41 +0000682}