annotate llvm/lib/IR/InlineAsm.cpp @ 266:00f31e85ec16 default tip

Added tag current for changeset 31d058e83c98
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sat, 14 Oct 2023 10:13:55 +0900
parents c4bab56944e8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 //===- InlineAsm.cpp - Implement the InlineAsm class ----------------------===//
anatofuz
parents:
diff changeset
2 //
anatofuz
parents:
diff changeset
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
anatofuz
parents:
diff changeset
4 // See https://llvm.org/LICENSE.txt for license information.
anatofuz
parents:
diff changeset
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
anatofuz
parents:
diff changeset
6 //
anatofuz
parents:
diff changeset
7 //===----------------------------------------------------------------------===//
anatofuz
parents:
diff changeset
8 //
anatofuz
parents:
diff changeset
9 // This file implements the InlineAsm class.
anatofuz
parents:
diff changeset
10 //
anatofuz
parents:
diff changeset
11 //===----------------------------------------------------------------------===//
anatofuz
parents:
diff changeset
12
anatofuz
parents:
diff changeset
13 #include "llvm/IR/InlineAsm.h"
anatofuz
parents:
diff changeset
14 #include "ConstantsContext.h"
anatofuz
parents:
diff changeset
15 #include "LLVMContextImpl.h"
anatofuz
parents:
diff changeset
16 #include "llvm/ADT/StringRef.h"
anatofuz
parents:
diff changeset
17 #include "llvm/IR/DerivedTypes.h"
anatofuz
parents:
diff changeset
18 #include "llvm/IR/LLVMContext.h"
anatofuz
parents:
diff changeset
19 #include "llvm/IR/Value.h"
anatofuz
parents:
diff changeset
20 #include "llvm/Support/Casting.h"
anatofuz
parents:
diff changeset
21 #include "llvm/Support/Compiler.h"
236
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
22 #include "llvm/Support/Errc.h"
150
anatofuz
parents:
diff changeset
23 #include <algorithm>
anatofuz
parents:
diff changeset
24 #include <cassert>
anatofuz
parents:
diff changeset
25 #include <cctype>
anatofuz
parents:
diff changeset
26 #include <cstdlib>
anatofuz
parents:
diff changeset
27
anatofuz
parents:
diff changeset
28 using namespace llvm;
anatofuz
parents:
diff changeset
29
anatofuz
parents:
diff changeset
30 InlineAsm::InlineAsm(FunctionType *FTy, const std::string &asmString,
anatofuz
parents:
diff changeset
31 const std::string &constraints, bool hasSideEffects,
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
32 bool isAlignStack, AsmDialect asmDialect, bool canThrow)
150
anatofuz
parents:
diff changeset
33 : Value(PointerType::getUnqual(FTy), Value::InlineAsmVal),
anatofuz
parents:
diff changeset
34 AsmString(asmString), Constraints(constraints), FTy(FTy),
anatofuz
parents:
diff changeset
35 HasSideEffects(hasSideEffects), IsAlignStack(isAlignStack),
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
36 Dialect(asmDialect), CanThrow(canThrow) {
236
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
37 #ifndef NDEBUG
150
anatofuz
parents:
diff changeset
38 // Do various checks on the constraint string and type.
236
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
39 cantFail(verify(getFunctionType(), constraints));
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
40 #endif
150
anatofuz
parents:
diff changeset
41 }
anatofuz
parents:
diff changeset
42
anatofuz
parents:
diff changeset
43 InlineAsm *InlineAsm::get(FunctionType *FTy, StringRef AsmString,
anatofuz
parents:
diff changeset
44 StringRef Constraints, bool hasSideEffects,
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
45 bool isAlignStack, AsmDialect asmDialect,
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
46 bool canThrow) {
150
anatofuz
parents:
diff changeset
47 InlineAsmKeyType Key(AsmString, Constraints, FTy, hasSideEffects,
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
48 isAlignStack, asmDialect, canThrow);
150
anatofuz
parents:
diff changeset
49 LLVMContextImpl *pImpl = FTy->getContext().pImpl;
anatofuz
parents:
diff changeset
50 return pImpl->InlineAsms.getOrCreate(PointerType::getUnqual(FTy), Key);
anatofuz
parents:
diff changeset
51 }
anatofuz
parents:
diff changeset
52
anatofuz
parents:
diff changeset
53 void InlineAsm::destroyConstant() {
anatofuz
parents:
diff changeset
54 getType()->getContext().pImpl->InlineAsms.remove(this);
anatofuz
parents:
diff changeset
55 delete this;
anatofuz
parents:
diff changeset
56 }
anatofuz
parents:
diff changeset
57
anatofuz
parents:
diff changeset
58 FunctionType *InlineAsm::getFunctionType() const {
anatofuz
parents:
diff changeset
59 return FTy;
anatofuz
parents:
diff changeset
60 }
anatofuz
parents:
diff changeset
61
236
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
62 void InlineAsm::collectAsmStrs(SmallVectorImpl<StringRef> &AsmStrs) const {
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
63 StringRef AsmStr(AsmString);
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
64 AsmStrs.clear();
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
65
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
66 // TODO: 1) Unify delimiter for inline asm, we also meet other delimiters
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
67 // for example "\0A", ";".
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
68 // 2) Enhance StringRef. Some of the special delimiter ("\0") can't be
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
69 // split in StringRef. Also empty StringRef can not call split (will stuck).
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
70 if (AsmStr.empty())
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
71 return;
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
72 AsmStr.split(AsmStrs, "\n\t", -1, false);
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
73 }
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
74
150
anatofuz
parents:
diff changeset
75 /// Parse - Analyze the specified string (e.g. "==&{eax}") and fill in the
anatofuz
parents:
diff changeset
76 /// fields in this structure. If the constraint string is not understood,
anatofuz
parents:
diff changeset
77 /// return true, otherwise return false.
anatofuz
parents:
diff changeset
78 bool InlineAsm::ConstraintInfo::Parse(StringRef Str,
anatofuz
parents:
diff changeset
79 InlineAsm::ConstraintInfoVector &ConstraintsSoFar) {
anatofuz
parents:
diff changeset
80 StringRef::iterator I = Str.begin(), E = Str.end();
anatofuz
parents:
diff changeset
81 unsigned multipleAlternativeCount = Str.count('|') + 1;
anatofuz
parents:
diff changeset
82 unsigned multipleAlternativeIndex = 0;
anatofuz
parents:
diff changeset
83 ConstraintCodeVector *pCodes = &Codes;
anatofuz
parents:
diff changeset
84
anatofuz
parents:
diff changeset
85 // Initialize
anatofuz
parents:
diff changeset
86 isMultipleAlternative = multipleAlternativeCount > 1;
anatofuz
parents:
diff changeset
87 if (isMultipleAlternative) {
anatofuz
parents:
diff changeset
88 multipleAlternatives.resize(multipleAlternativeCount);
anatofuz
parents:
diff changeset
89 pCodes = &multipleAlternatives[0].Codes;
anatofuz
parents:
diff changeset
90 }
anatofuz
parents:
diff changeset
91 Type = isInput;
anatofuz
parents:
diff changeset
92 isEarlyClobber = false;
anatofuz
parents:
diff changeset
93 MatchingInput = -1;
anatofuz
parents:
diff changeset
94 isCommutative = false;
anatofuz
parents:
diff changeset
95 isIndirect = false;
anatofuz
parents:
diff changeset
96 currentAlternativeIndex = 0;
anatofuz
parents:
diff changeset
97
anatofuz
parents:
diff changeset
98 // Parse prefixes.
anatofuz
parents:
diff changeset
99 if (*I == '~') {
anatofuz
parents:
diff changeset
100 Type = isClobber;
anatofuz
parents:
diff changeset
101 ++I;
anatofuz
parents:
diff changeset
102
anatofuz
parents:
diff changeset
103 // '{' must immediately follow '~'.
anatofuz
parents:
diff changeset
104 if (I != E && *I != '{')
anatofuz
parents:
diff changeset
105 return true;
anatofuz
parents:
diff changeset
106 } else if (*I == '=') {
anatofuz
parents:
diff changeset
107 ++I;
anatofuz
parents:
diff changeset
108 Type = isOutput;
236
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
109 } else if (*I == '!') {
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
110 ++I;
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
111 Type = isLabel;
150
anatofuz
parents:
diff changeset
112 }
anatofuz
parents:
diff changeset
113
anatofuz
parents:
diff changeset
114 if (*I == '*') {
anatofuz
parents:
diff changeset
115 isIndirect = true;
anatofuz
parents:
diff changeset
116 ++I;
anatofuz
parents:
diff changeset
117 }
anatofuz
parents:
diff changeset
118
anatofuz
parents:
diff changeset
119 if (I == E) return true; // Just a prefix, like "==" or "~".
anatofuz
parents:
diff changeset
120
anatofuz
parents:
diff changeset
121 // Parse the modifiers.
anatofuz
parents:
diff changeset
122 bool DoneWithModifiers = false;
anatofuz
parents:
diff changeset
123 while (!DoneWithModifiers) {
anatofuz
parents:
diff changeset
124 switch (*I) {
anatofuz
parents:
diff changeset
125 default:
anatofuz
parents:
diff changeset
126 DoneWithModifiers = true;
anatofuz
parents:
diff changeset
127 break;
anatofuz
parents:
diff changeset
128 case '&': // Early clobber.
anatofuz
parents:
diff changeset
129 if (Type != isOutput || // Cannot early clobber anything but output.
anatofuz
parents:
diff changeset
130 isEarlyClobber) // Reject &&&&&&
anatofuz
parents:
diff changeset
131 return true;
anatofuz
parents:
diff changeset
132 isEarlyClobber = true;
anatofuz
parents:
diff changeset
133 break;
anatofuz
parents:
diff changeset
134 case '%': // Commutative.
anatofuz
parents:
diff changeset
135 if (Type == isClobber || // Cannot commute clobbers.
anatofuz
parents:
diff changeset
136 isCommutative) // Reject %%%%%
anatofuz
parents:
diff changeset
137 return true;
anatofuz
parents:
diff changeset
138 isCommutative = true;
anatofuz
parents:
diff changeset
139 break;
anatofuz
parents:
diff changeset
140 case '#': // Comment.
anatofuz
parents:
diff changeset
141 case '*': // Register preferencing.
anatofuz
parents:
diff changeset
142 return true; // Not supported.
anatofuz
parents:
diff changeset
143 }
anatofuz
parents:
diff changeset
144
anatofuz
parents:
diff changeset
145 if (!DoneWithModifiers) {
anatofuz
parents:
diff changeset
146 ++I;
anatofuz
parents:
diff changeset
147 if (I == E) return true; // Just prefixes and modifiers!
anatofuz
parents:
diff changeset
148 }
anatofuz
parents:
diff changeset
149 }
anatofuz
parents:
diff changeset
150
anatofuz
parents:
diff changeset
151 // Parse the various constraints.
anatofuz
parents:
diff changeset
152 while (I != E) {
anatofuz
parents:
diff changeset
153 if (*I == '{') { // Physical register reference.
anatofuz
parents:
diff changeset
154 // Find the end of the register name.
anatofuz
parents:
diff changeset
155 StringRef::iterator ConstraintEnd = std::find(I+1, E, '}');
anatofuz
parents:
diff changeset
156 if (ConstraintEnd == E) return true; // "{foo"
anatofuz
parents:
diff changeset
157 pCodes->push_back(std::string(StringRef(I, ConstraintEnd + 1 - I)));
anatofuz
parents:
diff changeset
158 I = ConstraintEnd+1;
anatofuz
parents:
diff changeset
159 } else if (isdigit(static_cast<unsigned char>(*I))) { // Matching Constraint
anatofuz
parents:
diff changeset
160 // Maximal munch numbers.
anatofuz
parents:
diff changeset
161 StringRef::iterator NumStart = I;
anatofuz
parents:
diff changeset
162 while (I != E && isdigit(static_cast<unsigned char>(*I)))
anatofuz
parents:
diff changeset
163 ++I;
anatofuz
parents:
diff changeset
164 pCodes->push_back(std::string(StringRef(NumStart, I - NumStart)));
anatofuz
parents:
diff changeset
165 unsigned N = atoi(pCodes->back().c_str());
anatofuz
parents:
diff changeset
166 // Check that this is a valid matching constraint!
anatofuz
parents:
diff changeset
167 if (N >= ConstraintsSoFar.size() || ConstraintsSoFar[N].Type != isOutput||
anatofuz
parents:
diff changeset
168 Type != isInput)
anatofuz
parents:
diff changeset
169 return true; // Invalid constraint number.
anatofuz
parents:
diff changeset
170
anatofuz
parents:
diff changeset
171 // If Operand N already has a matching input, reject this. An output
anatofuz
parents:
diff changeset
172 // can't be constrained to the same value as multiple inputs.
anatofuz
parents:
diff changeset
173 if (isMultipleAlternative) {
anatofuz
parents:
diff changeset
174 if (multipleAlternativeIndex >=
anatofuz
parents:
diff changeset
175 ConstraintsSoFar[N].multipleAlternatives.size())
anatofuz
parents:
diff changeset
176 return true;
anatofuz
parents:
diff changeset
177 InlineAsm::SubConstraintInfo &scInfo =
anatofuz
parents:
diff changeset
178 ConstraintsSoFar[N].multipleAlternatives[multipleAlternativeIndex];
anatofuz
parents:
diff changeset
179 if (scInfo.MatchingInput != -1)
anatofuz
parents:
diff changeset
180 return true;
anatofuz
parents:
diff changeset
181 // Note that operand #n has a matching input.
anatofuz
parents:
diff changeset
182 scInfo.MatchingInput = ConstraintsSoFar.size();
anatofuz
parents:
diff changeset
183 assert(scInfo.MatchingInput >= 0);
anatofuz
parents:
diff changeset
184 } else {
anatofuz
parents:
diff changeset
185 if (ConstraintsSoFar[N].hasMatchingInput() &&
anatofuz
parents:
diff changeset
186 (size_t)ConstraintsSoFar[N].MatchingInput !=
anatofuz
parents:
diff changeset
187 ConstraintsSoFar.size())
anatofuz
parents:
diff changeset
188 return true;
anatofuz
parents:
diff changeset
189 // Note that operand #n has a matching input.
anatofuz
parents:
diff changeset
190 ConstraintsSoFar[N].MatchingInput = ConstraintsSoFar.size();
anatofuz
parents:
diff changeset
191 assert(ConstraintsSoFar[N].MatchingInput >= 0);
anatofuz
parents:
diff changeset
192 }
anatofuz
parents:
diff changeset
193 } else if (*I == '|') {
anatofuz
parents:
diff changeset
194 multipleAlternativeIndex++;
anatofuz
parents:
diff changeset
195 pCodes = &multipleAlternatives[multipleAlternativeIndex].Codes;
anatofuz
parents:
diff changeset
196 ++I;
anatofuz
parents:
diff changeset
197 } else if (*I == '^') {
anatofuz
parents:
diff changeset
198 // Multi-letter constraint
anatofuz
parents:
diff changeset
199 // FIXME: For now assuming these are 2-character constraints.
anatofuz
parents:
diff changeset
200 pCodes->push_back(std::string(StringRef(I + 1, 2)));
anatofuz
parents:
diff changeset
201 I += 3;
anatofuz
parents:
diff changeset
202 } else if (*I == '@') {
anatofuz
parents:
diff changeset
203 // Multi-letter constraint
anatofuz
parents:
diff changeset
204 ++I;
anatofuz
parents:
diff changeset
205 unsigned char C = static_cast<unsigned char>(*I);
anatofuz
parents:
diff changeset
206 assert(isdigit(C) && "Expected a digit!");
anatofuz
parents:
diff changeset
207 int N = C - '0';
anatofuz
parents:
diff changeset
208 assert(N > 0 && "Found a zero letter constraint!");
anatofuz
parents:
diff changeset
209 ++I;
anatofuz
parents:
diff changeset
210 pCodes->push_back(std::string(StringRef(I, N)));
anatofuz
parents:
diff changeset
211 I += N;
anatofuz
parents:
diff changeset
212 } else {
anatofuz
parents:
diff changeset
213 // Single letter constraint.
anatofuz
parents:
diff changeset
214 pCodes->push_back(std::string(StringRef(I, 1)));
anatofuz
parents:
diff changeset
215 ++I;
anatofuz
parents:
diff changeset
216 }
anatofuz
parents:
diff changeset
217 }
anatofuz
parents:
diff changeset
218
anatofuz
parents:
diff changeset
219 return false;
anatofuz
parents:
diff changeset
220 }
anatofuz
parents:
diff changeset
221
anatofuz
parents:
diff changeset
222 /// selectAlternative - Point this constraint to the alternative constraint
anatofuz
parents:
diff changeset
223 /// indicated by the index.
anatofuz
parents:
diff changeset
224 void InlineAsm::ConstraintInfo::selectAlternative(unsigned index) {
anatofuz
parents:
diff changeset
225 if (index < multipleAlternatives.size()) {
anatofuz
parents:
diff changeset
226 currentAlternativeIndex = index;
anatofuz
parents:
diff changeset
227 InlineAsm::SubConstraintInfo &scInfo =
anatofuz
parents:
diff changeset
228 multipleAlternatives[currentAlternativeIndex];
anatofuz
parents:
diff changeset
229 MatchingInput = scInfo.MatchingInput;
anatofuz
parents:
diff changeset
230 Codes = scInfo.Codes;
anatofuz
parents:
diff changeset
231 }
anatofuz
parents:
diff changeset
232 }
anatofuz
parents:
diff changeset
233
anatofuz
parents:
diff changeset
234 InlineAsm::ConstraintInfoVector
anatofuz
parents:
diff changeset
235 InlineAsm::ParseConstraints(StringRef Constraints) {
anatofuz
parents:
diff changeset
236 ConstraintInfoVector Result;
anatofuz
parents:
diff changeset
237
anatofuz
parents:
diff changeset
238 // Scan the constraints string.
anatofuz
parents:
diff changeset
239 for (StringRef::iterator I = Constraints.begin(),
anatofuz
parents:
diff changeset
240 E = Constraints.end(); I != E; ) {
anatofuz
parents:
diff changeset
241 ConstraintInfo Info;
anatofuz
parents:
diff changeset
242
anatofuz
parents:
diff changeset
243 // Find the end of this constraint.
anatofuz
parents:
diff changeset
244 StringRef::iterator ConstraintEnd = std::find(I, E, ',');
anatofuz
parents:
diff changeset
245
anatofuz
parents:
diff changeset
246 if (ConstraintEnd == I || // Empty constraint like ",,"
anatofuz
parents:
diff changeset
247 Info.Parse(StringRef(I, ConstraintEnd-I), Result)) {
anatofuz
parents:
diff changeset
248 Result.clear(); // Erroneous constraint?
anatofuz
parents:
diff changeset
249 break;
anatofuz
parents:
diff changeset
250 }
anatofuz
parents:
diff changeset
251
anatofuz
parents:
diff changeset
252 Result.push_back(Info);
anatofuz
parents:
diff changeset
253
anatofuz
parents:
diff changeset
254 // ConstraintEnd may be either the next comma or the end of the string. In
anatofuz
parents:
diff changeset
255 // the former case, we skip the comma.
anatofuz
parents:
diff changeset
256 I = ConstraintEnd;
anatofuz
parents:
diff changeset
257 if (I != E) {
anatofuz
parents:
diff changeset
258 ++I;
anatofuz
parents:
diff changeset
259 if (I == E) {
anatofuz
parents:
diff changeset
260 Result.clear();
anatofuz
parents:
diff changeset
261 break;
anatofuz
parents:
diff changeset
262 } // don't allow "xyz,"
anatofuz
parents:
diff changeset
263 }
anatofuz
parents:
diff changeset
264 }
anatofuz
parents:
diff changeset
265
anatofuz
parents:
diff changeset
266 return Result;
anatofuz
parents:
diff changeset
267 }
anatofuz
parents:
diff changeset
268
236
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
269 static Error makeStringError(const char *Msg) {
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
270 return createStringError(errc::invalid_argument, Msg);
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
271 }
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
272
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
273 Error InlineAsm::verify(FunctionType *Ty, StringRef ConstStr) {
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
274 if (Ty->isVarArg())
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
275 return makeStringError("inline asm cannot be variadic");
150
anatofuz
parents:
diff changeset
276
anatofuz
parents:
diff changeset
277 ConstraintInfoVector Constraints = ParseConstraints(ConstStr);
anatofuz
parents:
diff changeset
278
anatofuz
parents:
diff changeset
279 // Error parsing constraints.
236
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
280 if (Constraints.empty() && !ConstStr.empty())
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
281 return makeStringError("failed to parse constraints");
150
anatofuz
parents:
diff changeset
282
anatofuz
parents:
diff changeset
283 unsigned NumOutputs = 0, NumInputs = 0, NumClobbers = 0;
236
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
284 unsigned NumIndirect = 0, NumLabels = 0;
150
anatofuz
parents:
diff changeset
285
236
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
286 for (const ConstraintInfo &Constraint : Constraints) {
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
287 switch (Constraint.Type) {
150
anatofuz
parents:
diff changeset
288 case InlineAsm::isOutput:
236
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
289 if ((NumInputs-NumIndirect) != 0 || NumClobbers != 0 || NumLabels != 0)
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
290 return makeStringError("output constraint occurs after input, "
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
291 "clobber or label constraint");
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
292
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
293 if (!Constraint.isIndirect) {
150
anatofuz
parents:
diff changeset
294 ++NumOutputs;
anatofuz
parents:
diff changeset
295 break;
anatofuz
parents:
diff changeset
296 }
anatofuz
parents:
diff changeset
297 ++NumIndirect;
236
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
298 [[fallthrough]]; // We fall through for Indirect Outputs.
150
anatofuz
parents:
diff changeset
299 case InlineAsm::isInput:
236
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
300 if (NumClobbers)
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
301 return makeStringError("input constraint occurs after clobber "
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
302 "constraint");
150
anatofuz
parents:
diff changeset
303 ++NumInputs;
anatofuz
parents:
diff changeset
304 break;
anatofuz
parents:
diff changeset
305 case InlineAsm::isClobber:
anatofuz
parents:
diff changeset
306 ++NumClobbers;
anatofuz
parents:
diff changeset
307 break;
236
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
308 case InlineAsm::isLabel:
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
309 if (NumClobbers)
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
310 return makeStringError("label constraint occurs after clobber "
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
311 "constraint");
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
312
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
313 ++NumLabels;
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
314 break;
150
anatofuz
parents:
diff changeset
315 }
anatofuz
parents:
diff changeset
316 }
anatofuz
parents:
diff changeset
317
anatofuz
parents:
diff changeset
318 switch (NumOutputs) {
anatofuz
parents:
diff changeset
319 case 0:
236
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
320 if (!Ty->getReturnType()->isVoidTy())
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
321 return makeStringError("inline asm without outputs must return void");
150
anatofuz
parents:
diff changeset
322 break;
anatofuz
parents:
diff changeset
323 case 1:
236
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
324 if (Ty->getReturnType()->isStructTy())
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
325 return makeStringError("inline asm with one output cannot return struct");
150
anatofuz
parents:
diff changeset
326 break;
anatofuz
parents:
diff changeset
327 default:
anatofuz
parents:
diff changeset
328 StructType *STy = dyn_cast<StructType>(Ty->getReturnType());
anatofuz
parents:
diff changeset
329 if (!STy || STy->getNumElements() != NumOutputs)
236
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
330 return makeStringError("number of output constraints does not match "
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
331 "number of return struct elements");
150
anatofuz
parents:
diff changeset
332 break;
anatofuz
parents:
diff changeset
333 }
anatofuz
parents:
diff changeset
334
236
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
335 if (Ty->getNumParams() != NumInputs)
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
336 return makeStringError("number of input constraints does not match number "
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
337 "of parameters");
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
338
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
339 // We don't have access to labels here, NumLabels will be checked separately.
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
340 return Error::success();
150
anatofuz
parents:
diff changeset
341 }