1//===- CodeGenInstruction.cpp - CodeGen Instruction Class Wrapper ---------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements the CodeGenInstruction class.
10//
11//===----------------------------------------------------------------------===//
12
13#include "CodeGenInstruction.h"
14#include "CodeGenTarget.h"
15#include "llvm/TableGen/Error.h"
16#include "llvm/TableGen/Record.h"
17#include <set>
18using namespace llvm;
19
20//===----------------------------------------------------------------------===//
21// CGIOperandList Implementation
22//===----------------------------------------------------------------------===//
23
24CGIOperandList::CGIOperandList(const Record *R) : TheDef(R) {
25 isPredicable = false;
26 hasOptionalDef = false;
27 isVariadic = false;
28
29 const DagInit *OutDI = R->getValueAsDag(FieldName: "OutOperandList");
30
31 if (const DefInit *Init = dyn_cast<DefInit>(Val: OutDI->getOperator())) {
32 if (Init->getDef()->getName() != "outs")
33 PrintFatalError(ErrorLoc: R->getLoc(),
34 Msg: R->getName() +
35 ": invalid def name for output list: use 'outs'");
36 } else {
37 PrintFatalError(ErrorLoc: R->getLoc(),
38 Msg: R->getName() + ": invalid output list: use 'outs'");
39 }
40
41 NumDefs = OutDI->getNumArgs();
42
43 const DagInit *InDI = R->getValueAsDag(FieldName: "InOperandList");
44 if (const DefInit *Init = dyn_cast<DefInit>(Val: InDI->getOperator())) {
45 if (Init->getDef()->getName() != "ins")
46 PrintFatalError(ErrorLoc: R->getLoc(),
47 Msg: R->getName() +
48 ": invalid def name for input list: use 'ins'");
49 } else {
50 PrintFatalError(ErrorLoc: R->getLoc(),
51 Msg: R->getName() + ": invalid input list: use 'ins'");
52 }
53
54 unsigned MIOperandNo = 0;
55 std::set<std::string> OperandNames;
56 unsigned e = InDI->getNumArgs() + OutDI->getNumArgs();
57 OperandList.reserve(n: e);
58 bool VariadicOuts = false;
59 for (unsigned i = 0; i != e; ++i) {
60 const Init *ArgInit;
61 StringRef ArgName;
62 if (i < NumDefs) {
63 ArgInit = OutDI->getArg(Num: i);
64 ArgName = OutDI->getArgNameStr(Num: i);
65 } else {
66 ArgInit = InDI->getArg(Num: i - NumDefs);
67 ArgName = InDI->getArgNameStr(Num: i - NumDefs);
68 }
69
70 const DagInit *SubArgDag = dyn_cast<DagInit>(Val: ArgInit);
71 if (SubArgDag)
72 ArgInit = SubArgDag->getOperator();
73
74 const DefInit *Arg = dyn_cast<DefInit>(Val: ArgInit);
75 if (!Arg)
76 PrintFatalError(ErrorLoc: R->getLoc(), Msg: "Illegal operand for the '" + R->getName() +
77 "' instruction!");
78
79 const Record *Rec = Arg->getDef();
80 StringRef PrintMethod = "printOperand";
81 StringRef EncoderMethod;
82 std::string OperandType = "OPERAND_UNKNOWN";
83 std::string OperandNamespace = "MCOI";
84 unsigned NumOps = 1;
85 const DagInit *MIOpInfo = nullptr;
86 if (Rec->isSubClassOf(Name: "RegisterOperand")) {
87 PrintMethod = Rec->getValueAsString(FieldName: "PrintMethod");
88 OperandType = Rec->getValueAsString(FieldName: "OperandType").str();
89 OperandNamespace = Rec->getValueAsString(FieldName: "OperandNamespace").str();
90 EncoderMethod = Rec->getValueAsString(FieldName: "EncoderMethod");
91 } else if (Rec->isSubClassOf(Name: "Operand")) {
92 PrintMethod = Rec->getValueAsString(FieldName: "PrintMethod");
93 OperandType = Rec->getValueAsString(FieldName: "OperandType").str();
94 OperandNamespace = Rec->getValueAsString(FieldName: "OperandNamespace").str();
95 // If there is an explicit encoder method, use it.
96 EncoderMethod = Rec->getValueAsString(FieldName: "EncoderMethod");
97 MIOpInfo = Rec->getValueAsDag(FieldName: "MIOperandInfo");
98
99 // Verify that MIOpInfo has an 'ops' root value.
100 if (!isa<DefInit>(Val: MIOpInfo->getOperator()) ||
101 cast<DefInit>(Val: MIOpInfo->getOperator())->getDef()->getName() != "ops")
102 PrintFatalError(ErrorLoc: R->getLoc(),
103 Msg: "Bad value for MIOperandInfo in operand '" +
104 Rec->getName() + "'\n");
105
106 // If we have MIOpInfo, then we have #operands equal to number of entries
107 // in MIOperandInfo.
108 if (unsigned NumArgs = MIOpInfo->getNumArgs())
109 NumOps = NumArgs;
110
111 if (Rec->isSubClassOf(Name: "PredicateOp"))
112 isPredicable = true;
113 else if (Rec->isSubClassOf(Name: "OptionalDefOperand"))
114 hasOptionalDef = true;
115 } else if (Rec->getName() == "variable_ops") {
116 if (i < NumDefs)
117 VariadicOuts = true;
118 isVariadic = true;
119 continue;
120 } else if (Rec->isSubClassOf(Name: "RegisterClassLike")) {
121 OperandType = "OPERAND_REGISTER";
122 } else if (!Rec->isSubClassOf(Name: "unknown_class")) {
123 PrintFatalError(ErrorLoc: R->getLoc(), Msg: "Unknown operand class '" + Rec->getName() +
124 "' in '" + R->getName() +
125 "' instruction!");
126 }
127
128 // Check that the operand has a name and that it's unique.
129 if (ArgName.empty())
130 PrintFatalError(ErrorLoc: R->getLoc(), Msg: "In instruction '" + R->getName() +
131 "', operand #" + Twine(i) +
132 " has no name!");
133 if (!OperandNames.insert(x: ArgName.str()).second)
134 PrintFatalError(ErrorLoc: R->getLoc(),
135 Msg: "In instruction '" + R->getName() + "', operand #" +
136 Twine(i) +
137 " has the same name as a previous operand!");
138
139 OperandInfo &OpInfo = OperandList.emplace_back(
140 args&: Rec, args&: ArgName, args&: PrintMethod, args: OperandNamespace + "::" + OperandType,
141 args&: MIOperandNo, args&: NumOps, args&: MIOpInfo);
142
143 if (SubArgDag) {
144 if (!MIOpInfo) {
145 PrintFatalError(ErrorLoc: R->getLoc(), Msg: "In instruction '" + R->getName() +
146 "', operand #" + Twine(i) + " has " +
147 Twine(SubArgDag->getNumArgs()) +
148 " sub-arg names, but no sub-operands");
149 }
150
151 unsigned NumSubArgs = SubArgDag->getNumArgs();
152 unsigned NumSubOps = MIOpInfo->getNumArgs();
153 if (NumSubArgs != NumSubOps) {
154 PrintFatalError(ErrorLoc: R->getLoc(),
155 Msg: "In instruction '" + R->getName() + "', operand #" +
156 Twine(i) + " has " + Twine(NumSubArgs) +
157 " sub-arg names, expected " + Twine(NumSubOps));
158 }
159
160 for (unsigned j = 0; j < NumOps; ++j) {
161 if (!isa<UnsetInit>(Val: SubArgDag->getArg(Num: j)))
162 PrintFatalError(ErrorLoc: R->getLoc(),
163 Msg: "In instruction '" + R->getName() + "', operand #" +
164 Twine(i) + " sub-arg #" + Twine(j) +
165 " has unexpected operand (expected only $name).");
166
167 StringRef SubArgName = SubArgDag->getArgNameStr(Num: j);
168 if (SubArgName.empty())
169 PrintFatalError(ErrorLoc: R->getLoc(), Msg: "In instruction '" + R->getName() +
170 "', operand #" + Twine(i) +
171 " has no name!");
172 if (!OperandNames.insert(x: SubArgName.str()).second)
173 PrintFatalError(ErrorLoc: R->getLoc(),
174 Msg: "In instruction '" + R->getName() + "', operand #" +
175 Twine(i) + " sub-arg #" + Twine(j) +
176 " has the same name as a previous operand!");
177
178 if (auto MaybeEncoderMethod =
179 cast<DefInit>(Val: MIOpInfo->getArg(Num: j))
180 ->getDef()
181 ->getValueAsOptionalString(FieldName: "EncoderMethod")) {
182 OpInfo.EncoderMethodNames[j] = *MaybeEncoderMethod;
183 }
184
185 OpInfo.SubOpNames[j] = SubArgName;
186 SubOpAliases[SubArgName] = {i, j};
187 }
188 } else if (!EncoderMethod.empty()) {
189 // If we have no explicit sub-op dag, but have an top-level encoder
190 // method, the single encoder will multiple sub-ops, itself.
191 OpInfo.EncoderMethodNames[0] = EncoderMethod;
192 }
193
194 MIOperandNo += NumOps;
195 }
196
197 if (VariadicOuts)
198 --NumDefs;
199}
200
201/// getOperandNamed - Return the index of the operand with the specified
202/// non-empty name. If the instruction does not have an operand with the
203/// specified name, abort.
204///
205unsigned CGIOperandList::getOperandNamed(StringRef Name) const {
206 std::optional<unsigned> OpIdx = findOperandNamed(Name);
207 if (OpIdx)
208 return *OpIdx;
209 PrintFatalError(ErrorLoc: TheDef->getLoc(), Msg: "'" + TheDef->getName() +
210 "' does not have an operand named '$" +
211 Name + "'!");
212}
213
214/// findOperandNamed - Query whether the instruction has an operand of the
215/// given name. If so, the index of the operand. Otherwise, return std::nullopt.
216std::optional<unsigned> CGIOperandList::findOperandNamed(StringRef Name) const {
217 assert(!Name.empty() && "Cannot search for operand with no name!");
218 for (const auto &[Index, Opnd] : enumerate(First: OperandList))
219 if (Opnd.Name == Name)
220 return Index;
221 return std::nullopt;
222}
223
224std::optional<std::pair<unsigned, unsigned>>
225CGIOperandList::findSubOperandAlias(StringRef Name) const {
226 assert(!Name.empty() && "Cannot search for operand with no name!");
227 auto SubOpIter = SubOpAliases.find(Key: Name);
228 if (SubOpIter != SubOpAliases.end())
229 return SubOpIter->second;
230 return std::nullopt;
231}
232
233std::pair<unsigned, unsigned>
234CGIOperandList::parseOperandName(StringRef Op, bool AllowWholeOp) const {
235 if (!Op.starts_with(Prefix: "$"))
236 PrintFatalError(ErrorLoc: TheDef->getLoc(),
237 Msg: TheDef->getName() + ": Illegal operand name: '" + Op + "'");
238
239 StringRef OpName = Op.substr(Start: 1);
240 StringRef SubOpName;
241
242 // Check to see if this is $foo.bar.
243 StringRef::size_type DotIdx = OpName.find_first_of(C: '.');
244 if (DotIdx != StringRef::npos) {
245 SubOpName = OpName.substr(Start: DotIdx + 1);
246 if (SubOpName.empty())
247 PrintFatalError(ErrorLoc: TheDef->getLoc(),
248 Msg: TheDef->getName() +
249 ": illegal empty suboperand name in '" + Op + "'");
250 OpName = OpName.substr(Start: 0, N: DotIdx);
251 }
252
253 if (auto SubOp = findSubOperandAlias(Name: OpName)) {
254 // Found a name for a piece of an operand, just return it directly.
255 if (!SubOpName.empty()) {
256 PrintFatalError(
257 ErrorLoc: TheDef->getLoc(),
258 Msg: TheDef->getName() +
259 ": Cannot use dotted suboperand name within suboperand '" +
260 OpName + "'");
261 }
262 return *SubOp;
263 }
264
265 unsigned OpIdx = getOperandNamed(Name: OpName);
266
267 if (SubOpName.empty()) { // If no suboperand name was specified:
268 // If one was needed, throw.
269 if (OperandList[OpIdx].MINumOperands > 1 && !AllowWholeOp &&
270 SubOpName.empty())
271 PrintFatalError(ErrorLoc: TheDef->getLoc(),
272 Msg: TheDef->getName() +
273 ": Illegal to refer to"
274 " whole operand part of complex operand '" +
275 Op + "'");
276
277 // Otherwise, return the operand.
278 return {OpIdx, 0U};
279 }
280
281 // Find the suboperand number involved.
282 const DagInit *MIOpInfo = OperandList[OpIdx].MIOperandInfo;
283 if (!MIOpInfo)
284 PrintFatalError(ErrorLoc: TheDef->getLoc(), Msg: TheDef->getName() +
285 ": unknown suboperand name in '" +
286 Op + "'");
287
288 // Find the operand with the right name.
289 for (unsigned i = 0, e = MIOpInfo->getNumArgs(); i != e; ++i)
290 if (MIOpInfo->getArgNameStr(Num: i) == SubOpName)
291 return {OpIdx, i};
292
293 // Otherwise, didn't find it!
294 PrintFatalError(ErrorLoc: TheDef->getLoc(), Msg: TheDef->getName() +
295 ": unknown suboperand name in '" + Op +
296 "'");
297 return {0U, 0U};
298}
299
300static void ParseConstraint(StringRef CStr, CGIOperandList &Ops,
301 const Record *Rec) {
302 // EARLY_CLOBBER: @early $reg
303 StringRef::size_type wpos = CStr.find_first_of(Chars: " \t");
304 StringRef::size_type start = CStr.find_first_not_of(Chars: " \t");
305 StringRef Tok = CStr.substr(Start: start, N: wpos - start);
306 if (Tok == "@earlyclobber") {
307 StringRef Name = CStr.substr(Start: wpos + 1);
308 wpos = Name.find_first_not_of(Chars: " \t");
309 if (wpos == StringRef::npos)
310 PrintFatalError(ErrorLoc: Rec->getLoc(),
311 Msg: "Illegal format for @earlyclobber constraint in '" +
312 Rec->getName() + "': '" + CStr + "'");
313 Name = Name.substr(Start: wpos);
314 std::pair<unsigned, unsigned> Op = Ops.parseOperandName(Op: Name, AllowWholeOp: false);
315
316 // Build the string for the operand
317 if (!Ops[Op.first].Constraints[Op.second].isNone())
318 PrintFatalError(ErrorLoc: Rec->getLoc(), Msg: "Operand '" + Name + "' of '" +
319 Rec->getName() +
320 "' cannot have multiple constraints!");
321 Ops[Op.first].Constraints[Op.second] =
322 CGIOperandList::ConstraintInfo::getEarlyClobber();
323 return;
324 }
325
326 // Only other constraint is "TIED_TO" for now.
327 StringRef::size_type pos = CStr.find_first_of(C: '=');
328 if (pos == StringRef::npos || pos == 0 ||
329 CStr.find_first_of(Chars: " \t", From: pos) != (pos + 1) ||
330 CStr.find_last_of(Chars: " \t", From: pos) != (pos - 1))
331 PrintFatalError(ErrorLoc: Rec->getLoc(), Msg: "Unrecognized constraint '" + CStr +
332 "' in '" + Rec->getName() + "'");
333 start = CStr.find_first_not_of(Chars: " \t");
334
335 // TIED_TO: $src1 = $dst
336 wpos = CStr.find_first_of(Chars: " \t", From: start);
337 if (wpos == StringRef::npos || wpos > pos)
338 PrintFatalError(ErrorLoc: Rec->getLoc(),
339 Msg: "Illegal format for tied-to constraint in '" +
340 Rec->getName() + "': '" + CStr + "'");
341 StringRef LHSOpName = CStr.substr(Start: start, N: wpos - start);
342 std::pair<unsigned, unsigned> LHSOp = Ops.parseOperandName(Op: LHSOpName, AllowWholeOp: false);
343
344 wpos = CStr.find_first_not_of(Chars: " \t", From: pos + 1);
345 if (wpos == StringRef::npos)
346 PrintFatalError(ErrorLoc: Rec->getLoc(),
347 Msg: "Illegal format for tied-to constraint: '" + CStr + "'");
348
349 StringRef RHSOpName = CStr.substr(Start: wpos);
350 std::pair<unsigned, unsigned> RHSOp = Ops.parseOperandName(Op: RHSOpName, AllowWholeOp: false);
351
352 // Sort the operands into order, which should put the output one
353 // first. But keep the original order, for use in diagnostics.
354 bool FirstIsDest = (LHSOp < RHSOp);
355 std::pair<unsigned, unsigned> DestOp = (FirstIsDest ? LHSOp : RHSOp);
356 StringRef DestOpName = (FirstIsDest ? LHSOpName : RHSOpName);
357 std::pair<unsigned, unsigned> SrcOp = (FirstIsDest ? RHSOp : LHSOp);
358 StringRef SrcOpName = (FirstIsDest ? RHSOpName : LHSOpName);
359
360 // Ensure one operand is a def and the other is a use.
361 if (DestOp.first >= Ops.NumDefs)
362 PrintFatalError(ErrorLoc: Rec->getLoc(), Msg: "Input operands '" + LHSOpName + "' and '" +
363 RHSOpName + "' of '" + Rec->getName() +
364 "' cannot be tied!");
365 if (SrcOp.first < Ops.NumDefs)
366 PrintFatalError(ErrorLoc: Rec->getLoc(), Msg: "Output operands '" + LHSOpName + "' and '" +
367 RHSOpName + "' of '" + Rec->getName() +
368 "' cannot be tied!");
369
370 // The constraint has to go on the operand with higher index, i.e.
371 // the source one. Check there isn't another constraint there
372 // already.
373 if (!Ops[SrcOp.first].Constraints[SrcOp.second].isNone())
374 PrintFatalError(ErrorLoc: Rec->getLoc(), Msg: "Operand '" + SrcOpName + "' of '" +
375 Rec->getName() +
376 "' cannot have multiple constraints!");
377
378 unsigned DestFlatOpNo = Ops.getFlattenedOperandNumber(Op: DestOp);
379 auto NewConstraint = CGIOperandList::ConstraintInfo::getTied(Op: DestFlatOpNo);
380
381 // Check that the earlier operand is not the target of another tie
382 // before making it the target of this one.
383 for (const CGIOperandList::OperandInfo &Op : Ops) {
384 for (unsigned i = 0; i < Op.MINumOperands; i++)
385 if (Op.Constraints[i] == NewConstraint)
386 PrintFatalError(ErrorLoc: Rec->getLoc(),
387 Msg: "Operand '" + DestOpName + "' of '" + Rec->getName() +
388 "' cannot have multiple operands tied to it!");
389 }
390
391 Ops[SrcOp.first].Constraints[SrcOp.second] = NewConstraint;
392}
393
394static void ParseConstraints(StringRef CStr, CGIOperandList &Ops,
395 const Record *Rec) {
396 if (CStr.empty())
397 return;
398
399 StringRef delims(",");
400 StringRef::size_type bidx, eidx;
401
402 bidx = CStr.find_first_not_of(Chars: delims);
403 while (bidx != StringRef::npos) {
404 eidx = CStr.find_first_of(Chars: delims, From: bidx);
405 if (eidx == StringRef::npos)
406 eidx = CStr.size();
407
408 ParseConstraint(CStr: CStr.substr(Start: bidx, N: eidx - bidx), Ops, Rec);
409 bidx = CStr.find_first_not_of(Chars: delims, From: eidx);
410 }
411}
412
413//===----------------------------------------------------------------------===//
414// CodeGenInstruction Implementation
415//===----------------------------------------------------------------------===//
416
417CodeGenInstruction::CodeGenInstruction(const Record *R)
418 : TheDef(R), Operands(R), InferredFrom(nullptr) {
419 Namespace = R->getValueAsString(FieldName: "Namespace");
420 AsmString = R->getValueAsString(FieldName: "AsmString");
421
422 isPreISelOpcode = R->getValueAsBit(FieldName: "isPreISelOpcode");
423 isReturn = R->getValueAsBit(FieldName: "isReturn");
424 isEHScopeReturn = R->getValueAsBit(FieldName: "isEHScopeReturn");
425 isBranch = R->getValueAsBit(FieldName: "isBranch");
426 isIndirectBranch = R->getValueAsBit(FieldName: "isIndirectBranch");
427 isCompare = R->getValueAsBit(FieldName: "isCompare");
428 isMoveImm = R->getValueAsBit(FieldName: "isMoveImm");
429 isMoveReg = R->getValueAsBit(FieldName: "isMoveReg");
430 isBitcast = R->getValueAsBit(FieldName: "isBitcast");
431 isSelect = R->getValueAsBit(FieldName: "isSelect");
432 isBarrier = R->getValueAsBit(FieldName: "isBarrier");
433 isCall = R->getValueAsBit(FieldName: "isCall");
434 isAdd = R->getValueAsBit(FieldName: "isAdd");
435 isTrap = R->getValueAsBit(FieldName: "isTrap");
436 canFoldAsLoad = R->getValueAsBit(FieldName: "canFoldAsLoad");
437 isPredicable = !R->getValueAsBit(FieldName: "isUnpredicable") &&
438 (Operands.isPredicable || R->getValueAsBit(FieldName: "isPredicable"));
439 isConvertibleToThreeAddress = R->getValueAsBit(FieldName: "isConvertibleToThreeAddress");
440 isCommutable = R->getValueAsBit(FieldName: "isCommutable");
441 isTerminator = R->getValueAsBit(FieldName: "isTerminator");
442 isReMaterializable = R->getValueAsBit(FieldName: "isReMaterializable");
443 hasDelaySlot = R->getValueAsBit(FieldName: "hasDelaySlot");
444 usesCustomInserter = R->getValueAsBit(FieldName: "usesCustomInserter");
445 hasPostISelHook = R->getValueAsBit(FieldName: "hasPostISelHook");
446 hasCtrlDep = R->getValueAsBit(FieldName: "hasCtrlDep");
447 isNotDuplicable = R->getValueAsBit(FieldName: "isNotDuplicable");
448 isRegSequence = R->getValueAsBit(FieldName: "isRegSequence");
449 isExtractSubreg = R->getValueAsBit(FieldName: "isExtractSubreg");
450 isInsertSubreg = R->getValueAsBit(FieldName: "isInsertSubreg");
451 isConvergent = R->getValueAsBit(FieldName: "isConvergent");
452 hasNoSchedulingInfo = R->getValueAsBit(FieldName: "hasNoSchedulingInfo");
453 FastISelShouldIgnore = R->getValueAsBit(FieldName: "FastISelShouldIgnore");
454 variadicOpsAreDefs = R->getValueAsBit(FieldName: "variadicOpsAreDefs");
455 isAuthenticated = R->getValueAsBit(FieldName: "isAuthenticated");
456
457 bool Unset;
458 mayLoad = R->getValueAsBitOrUnset(FieldName: "mayLoad", Unset);
459 mayLoad_Unset = Unset;
460 mayStore = R->getValueAsBitOrUnset(FieldName: "mayStore", Unset);
461 mayStore_Unset = Unset;
462 mayRaiseFPException = R->getValueAsBit(FieldName: "mayRaiseFPException");
463 hasSideEffects = R->getValueAsBitOrUnset(FieldName: "hasSideEffects", Unset);
464 hasSideEffects_Unset = Unset;
465
466 isAsCheapAsAMove = R->getValueAsBit(FieldName: "isAsCheapAsAMove");
467 hasExtraSrcRegAllocReq = R->getValueAsBit(FieldName: "hasExtraSrcRegAllocReq");
468 hasExtraDefRegAllocReq = R->getValueAsBit(FieldName: "hasExtraDefRegAllocReq");
469 isCodeGenOnly = R->getValueAsBit(FieldName: "isCodeGenOnly");
470 isPseudo = R->getValueAsBit(FieldName: "isPseudo");
471 isMeta = R->getValueAsBit(FieldName: "isMeta");
472 ImplicitDefs = R->getValueAsListOfDefs(FieldName: "Defs");
473 ImplicitUses = R->getValueAsListOfDefs(FieldName: "Uses");
474
475 // This flag is only inferred from the pattern.
476 hasChain = false;
477 hasChain_Inferred = false;
478
479 // Parse Constraints.
480 ParseConstraints(CStr: R->getValueAsString(FieldName: "Constraints"), Ops&: Operands, Rec: R);
481
482 // First check for a ComplexDeprecationPredicate.
483 if (R->getValue(Name: "ComplexDeprecationPredicate")) {
484 HasComplexDeprecationPredicate = true;
485 DeprecatedReason = R->getValueAsString(FieldName: "ComplexDeprecationPredicate").str();
486 } else if (const RecordVal *Dep = R->getValue(Name: "DeprecatedFeatureMask")) {
487 // Check if we have a Subtarget feature mask.
488 HasComplexDeprecationPredicate = false;
489 DeprecatedReason = Dep->getValue()->getAsString();
490 } else {
491 // This instruction isn't deprecated.
492 HasComplexDeprecationPredicate = false;
493 DeprecatedReason = "";
494 }
495}
496
497/// HasOneImplicitDefWithKnownVT - If the instruction has at least one
498/// implicit def and it has a known VT, return the VT, otherwise return
499/// MVT::Other.
500MVT CodeGenInstruction::HasOneImplicitDefWithKnownVT(
501 const CodeGenTarget &TargetInfo) const {
502 if (ImplicitDefs.empty())
503 return MVT::Other;
504
505 // Check to see if the first implicit def has a resolvable type.
506 const Record *FirstImplicitDef = ImplicitDefs[0];
507 assert(FirstImplicitDef->isSubClassOf("Register"));
508 const std::vector<ValueTypeByHwMode> &RegVTs =
509 TargetInfo.getRegisterVTs(R: FirstImplicitDef);
510 if (RegVTs.size() == 1 && RegVTs[0].isSimple())
511 return RegVTs[0].getSimple();
512 return MVT::Other;
513}
514
515/// FlattenAsmStringVariants - Flatten the specified AsmString to only
516/// include text from the specified variant, returning the new string.
517std::string CodeGenInstruction::FlattenAsmStringVariants(StringRef Cur,
518 unsigned Variant) {
519 std::string Res;
520
521 for (;;) {
522 // Find the start of the next variant string.
523 size_t VariantsStart = 0;
524 for (size_t e = Cur.size(); VariantsStart != e; ++VariantsStart)
525 if (Cur[VariantsStart] == '{' &&
526 (VariantsStart == 0 ||
527 (Cur[VariantsStart - 1] != '$' && Cur[VariantsStart - 1] != '\\')))
528 break;
529
530 // Add the prefix to the result.
531 Res += Cur.slice(Start: 0, End: VariantsStart);
532 if (VariantsStart == Cur.size())
533 break;
534
535 ++VariantsStart; // Skip the '{'.
536
537 // Scan to the end of the variants string.
538 size_t VariantsEnd = VariantsStart;
539 unsigned NestedBraces = 1;
540 for (size_t e = Cur.size(); VariantsEnd != e; ++VariantsEnd) {
541 if (Cur[VariantsEnd] == '}' && Cur[VariantsEnd - 1] != '\\') {
542 if (--NestedBraces == 0)
543 break;
544 } else if (Cur[VariantsEnd] == '{')
545 ++NestedBraces;
546 }
547
548 // Select the Nth variant (or empty).
549 StringRef Selection =
550 Cur.substr(Start: VariantsStart, N: VariantsEnd - VariantsStart);
551 for (unsigned i = 0; i != Variant; ++i)
552 Selection = Selection.split(Separator: '|').second;
553 Res += Selection.split(Separator: '|').first;
554
555 assert(VariantsEnd != Cur.size() &&
556 "Unterminated variants in assembly string!");
557 Cur = Cur.substr(Start: VariantsEnd + 1);
558 }
559
560 return Res;
561}
562
563bool CodeGenInstruction::isOperandImpl(StringRef OpListName, unsigned i,
564 StringRef PropertyName) const {
565 const DagInit *ConstraintList = TheDef->getValueAsDag(FieldName: OpListName);
566 if (!ConstraintList || i >= ConstraintList->getNumArgs())
567 return false;
568
569 const DefInit *Constraint = dyn_cast<DefInit>(Val: ConstraintList->getArg(Num: i));
570 if (!Constraint)
571 return false;
572
573 return Constraint->getDef()->isSubClassOf(Name: "TypedOperand") &&
574 Constraint->getDef()->getValueAsBit(FieldName: PropertyName);
575}
576