Chris Lattner | eef2fe7 | 2006-01-24 04:13:11 +0000 | [diff] [blame] | 1 | //===-- InlineAsm.cpp - Implement the InlineAsm class ---------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | f3ebc3f | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Chris Lattner | eef2fe7 | 2006-01-24 04:13:11 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the InlineAsm class. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 14 | #include "llvm/IR/InlineAsm.h" |
Jeffrey Yasskin | ade270e | 2010-03-21 20:37:19 +0000 | [diff] [blame] | 15 | #include "ConstantsContext.h" |
| 16 | #include "LLVMContextImpl.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 17 | #include "llvm/IR/DerivedTypes.h" |
Jeff Cohen | b24b66f | 2006-02-01 04:37:04 +0000 | [diff] [blame] | 18 | #include <algorithm> |
Chris Lattner | 8547e3a | 2006-01-26 00:48:33 +0000 | [diff] [blame] | 19 | #include <cctype> |
Chris Lattner | eef2fe7 | 2006-01-24 04:13:11 +0000 | [diff] [blame] | 20 | using namespace llvm; |
| 21 | |
Gordon Henriksen | 14a5569 | 2007-12-10 02:14:30 +0000 | [diff] [blame] | 22 | // Implement the first virtual method in this class in this file so the |
| 23 | // InlineAsm vtable is emitted here. |
| 24 | InlineAsm::~InlineAsm() { |
| 25 | } |
| 26 | |
David Blaikie | 71c9c9c | 2015-07-28 00:06:38 +0000 | [diff] [blame] | 27 | InlineAsm *InlineAsm::get(FunctionType *FTy, StringRef AsmString, |
Daniel Dunbar | ad36e8a | 2009-11-06 10:58:06 +0000 | [diff] [blame] | 28 | StringRef Constraints, bool hasSideEffects, |
Chad Rosier | d8c7610 | 2012-09-05 19:00:49 +0000 | [diff] [blame] | 29 | bool isAlignStack, AsmDialect asmDialect) { |
David Blaikie | 71c9c9c | 2015-07-28 00:06:38 +0000 | [diff] [blame] | 30 | InlineAsmKeyType Key(AsmString, Constraints, FTy, hasSideEffects, |
| 31 | isAlignStack, asmDialect); |
| 32 | LLVMContextImpl *pImpl = FTy->getContext().pImpl; |
| 33 | return pImpl->InlineAsms.getOrCreate(PointerType::getUnqual(FTy), Key); |
Chris Lattner | a2d810d | 2006-01-25 22:26:05 +0000 | [diff] [blame] | 34 | } |
| 35 | |
David Blaikie | 71c9c9c | 2015-07-28 00:06:38 +0000 | [diff] [blame] | 36 | InlineAsm::InlineAsm(FunctionType *FTy, const std::string &asmString, |
Jeffrey Yasskin | ade270e | 2010-03-21 20:37:19 +0000 | [diff] [blame] | 37 | const std::string &constraints, bool hasSideEffects, |
Chad Rosier | d8c7610 | 2012-09-05 19:00:49 +0000 | [diff] [blame] | 38 | bool isAlignStack, AsmDialect asmDialect) |
David Blaikie | 71c9c9c | 2015-07-28 00:06:38 +0000 | [diff] [blame] | 39 | : Value(PointerType::getUnqual(FTy), Value::InlineAsmVal), |
| 40 | AsmString(asmString), Constraints(constraints), FTy(FTy), |
| 41 | HasSideEffects(hasSideEffects), IsAlignStack(isAlignStack), |
| 42 | Dialect(asmDialect) { |
Chris Lattner | eef2fe7 | 2006-01-24 04:13:11 +0000 | [diff] [blame] | 43 | |
Chris Lattner | a2d810d | 2006-01-25 22:26:05 +0000 | [diff] [blame] | 44 | // Do various checks on the constraint string and type. |
Jeffrey Yasskin | ade270e | 2010-03-21 20:37:19 +0000 | [diff] [blame] | 45 | assert(Verify(getFunctionType(), constraints) && |
| 46 | "Function type not legal for constraints!"); |
| 47 | } |
| 48 | |
| 49 | void InlineAsm::destroyConstant() { |
Chris Lattner | b1ed91f | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 50 | getType()->getContext().pImpl->InlineAsms.remove(this); |
Jeffrey Yasskin | ade270e | 2010-03-21 20:37:19 +0000 | [diff] [blame] | 51 | delete this; |
Chris Lattner | eef2fe7 | 2006-01-24 04:13:11 +0000 | [diff] [blame] | 52 | } |
| 53 | |
Chris Lattner | 1d021a9 | 2011-07-15 23:15:45 +0000 | [diff] [blame] | 54 | FunctionType *InlineAsm::getFunctionType() const { |
David Blaikie | 71c9c9c | 2015-07-28 00:06:38 +0000 | [diff] [blame] | 55 | return FTy; |
Chris Lattner | eef2fe7 | 2006-01-24 04:13:11 +0000 | [diff] [blame] | 56 | } |
John Thompson | 1094c80 | 2010-09-13 18:15:37 +0000 | [diff] [blame] | 57 | |
| 58 | ///Default constructor. |
| 59 | InlineAsm::ConstraintInfo::ConstraintInfo() : |
John Thompson | 1094c80 | 2010-09-13 18:15:37 +0000 | [diff] [blame] | 60 | Type(isInput), isEarlyClobber(false), |
| 61 | MatchingInput(-1), isCommutative(false), |
Eric Christopher | 5f87834 | 2010-09-13 18:25:05 +0000 | [diff] [blame] | 62 | isIndirect(false), isMultipleAlternative(false), |
| 63 | currentAlternativeIndex(0) { |
John Thompson | 1094c80 | 2010-09-13 18:15:37 +0000 | [diff] [blame] | 64 | } |
| 65 | |
Chris Lattner | 7ed3101 | 2006-02-01 01:29:47 +0000 | [diff] [blame] | 66 | /// Parse - Analyze the specified string (e.g. "==&{eax}") and fill in the |
| 67 | /// fields in this structure. If the constraint string is not understood, |
| 68 | /// return true, otherwise return false. |
Daniel Dunbar | ad36e8a | 2009-11-06 10:58:06 +0000 | [diff] [blame] | 69 | bool InlineAsm::ConstraintInfo::Parse(StringRef Str, |
John Thompson | e8360b7 | 2010-10-29 17:29:13 +0000 | [diff] [blame] | 70 | InlineAsm::ConstraintInfoVector &ConstraintsSoFar) { |
Daniel Dunbar | d43b86d | 2009-07-25 06:02:13 +0000 | [diff] [blame] | 71 | StringRef::iterator I = Str.begin(), E = Str.end(); |
John Thompson | 1094c80 | 2010-09-13 18:15:37 +0000 | [diff] [blame] | 72 | unsigned multipleAlternativeCount = Str.count('|') + 1; |
| 73 | unsigned multipleAlternativeIndex = 0; |
John Thompson | e8360b7 | 2010-10-29 17:29:13 +0000 | [diff] [blame] | 74 | ConstraintCodeVector *pCodes = &Codes; |
Eric Christopher | f3e79e8 | 2015-02-10 21:15:06 +0000 | [diff] [blame] | 75 | |
Chris Lattner | 7ed3101 | 2006-02-01 01:29:47 +0000 | [diff] [blame] | 76 | // Initialize |
David Blaikie | dc3f01e | 2015-03-09 01:57:13 +0000 | [diff] [blame] | 77 | isMultipleAlternative = multipleAlternativeCount > 1; |
John Thompson | 1094c80 | 2010-09-13 18:15:37 +0000 | [diff] [blame] | 78 | if (isMultipleAlternative) { |
| 79 | multipleAlternatives.resize(multipleAlternativeCount); |
| 80 | pCodes = &multipleAlternatives[0].Codes; |
| 81 | } |
Chris Lattner | 7ed3101 | 2006-02-01 01:29:47 +0000 | [diff] [blame] | 82 | Type = isInput; |
| 83 | isEarlyClobber = false; |
Chris Lattner | 860df6e | 2008-10-17 16:47:46 +0000 | [diff] [blame] | 84 | MatchingInput = -1; |
Chris Lattner | de5a9f4 | 2006-02-23 23:36:53 +0000 | [diff] [blame] | 85 | isCommutative = false; |
Chris Lattner | c48e2c3 | 2007-04-28 01:02:58 +0000 | [diff] [blame] | 86 | isIndirect = false; |
John Thompson | 1094c80 | 2010-09-13 18:15:37 +0000 | [diff] [blame] | 87 | currentAlternativeIndex = 0; |
Chris Lattner | 7ed3101 | 2006-02-01 01:29:47 +0000 | [diff] [blame] | 88 | |
Chris Lattner | c48e2c3 | 2007-04-28 01:02:58 +0000 | [diff] [blame] | 89 | // Parse prefixes. |
Chris Lattner | 7ed3101 | 2006-02-01 01:29:47 +0000 | [diff] [blame] | 90 | if (*I == '~') { |
| 91 | Type = isClobber; |
| 92 | ++I; |
Akira Hatanaka | 489dece | 2014-09-05 22:30:32 +0000 | [diff] [blame] | 93 | |
| 94 | // '{' must immediately follow '~'. |
| 95 | if (I != E && *I != '{') |
| 96 | return true; |
Chris Lattner | 7ed3101 | 2006-02-01 01:29:47 +0000 | [diff] [blame] | 97 | } else if (*I == '=') { |
| 98 | ++I; |
| 99 | Type = isOutput; |
Chris Lattner | c48e2c3 | 2007-04-28 01:02:58 +0000 | [diff] [blame] | 100 | } |
Eric Christopher | f3e79e8 | 2015-02-10 21:15:06 +0000 | [diff] [blame] | 101 | |
Chris Lattner | c48e2c3 | 2007-04-28 01:02:58 +0000 | [diff] [blame] | 102 | if (*I == '*') { |
| 103 | isIndirect = true; |
| 104 | ++I; |
Chris Lattner | 7ed3101 | 2006-02-01 01:29:47 +0000 | [diff] [blame] | 105 | } |
Eric Christopher | f3e79e8 | 2015-02-10 21:15:06 +0000 | [diff] [blame] | 106 | |
Chris Lattner | 7ed3101 | 2006-02-01 01:29:47 +0000 | [diff] [blame] | 107 | if (I == E) return true; // Just a prefix, like "==" or "~". |
| 108 | |
| 109 | // Parse the modifiers. |
| 110 | bool DoneWithModifiers = false; |
| 111 | while (!DoneWithModifiers) { |
| 112 | switch (*I) { |
| 113 | default: |
| 114 | DoneWithModifiers = true; |
| 115 | break; |
Chris Lattner | de5a9f4 | 2006-02-23 23:36:53 +0000 | [diff] [blame] | 116 | case '&': // Early clobber. |
Chris Lattner | 7ed3101 | 2006-02-01 01:29:47 +0000 | [diff] [blame] | 117 | if (Type != isOutput || // Cannot early clobber anything but output. |
| 118 | isEarlyClobber) // Reject &&&&&& |
| 119 | return true; |
| 120 | isEarlyClobber = true; |
| 121 | break; |
Chris Lattner | de5a9f4 | 2006-02-23 23:36:53 +0000 | [diff] [blame] | 122 | case '%': // Commutative. |
| 123 | if (Type == isClobber || // Cannot commute clobbers. |
| 124 | isCommutative) // Reject %%%%% |
| 125 | return true; |
| 126 | isCommutative = true; |
| 127 | break; |
| 128 | case '#': // Comment. |
| 129 | case '*': // Register preferencing. |
| 130 | return true; // Not supported. |
Chris Lattner | 7ed3101 | 2006-02-01 01:29:47 +0000 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | if (!DoneWithModifiers) { |
| 134 | ++I; |
| 135 | if (I == E) return true; // Just prefixes and modifiers! |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | // Parse the various constraints. |
| 140 | while (I != E) { |
| 141 | if (*I == '{') { // Physical register reference. |
| 142 | // Find the end of the register name. |
Daniel Dunbar | d43b86d | 2009-07-25 06:02:13 +0000 | [diff] [blame] | 143 | StringRef::iterator ConstraintEnd = std::find(I+1, E, '}'); |
Chris Lattner | 7ed3101 | 2006-02-01 01:29:47 +0000 | [diff] [blame] | 144 | if (ConstraintEnd == E) return true; // "{foo" |
Alexander Potapenko | 7d68c26 | 2016-05-23 13:58:04 +0000 | [diff] [blame] | 145 | pCodes->push_back(StringRef(I, ConstraintEnd+1 - I)); |
Chris Lattner | 7ed3101 | 2006-02-01 01:29:47 +0000 | [diff] [blame] | 146 | I = ConstraintEnd+1; |
Guy Benyei | 83c74e9 | 2013-02-12 21:21:59 +0000 | [diff] [blame] | 147 | } else if (isdigit(static_cast<unsigned char>(*I))) { // Matching Constraint |
Chris Lattner | 7ed3101 | 2006-02-01 01:29:47 +0000 | [diff] [blame] | 148 | // Maximal munch numbers. |
Daniel Dunbar | d43b86d | 2009-07-25 06:02:13 +0000 | [diff] [blame] | 149 | StringRef::iterator NumStart = I; |
Guy Benyei | 83c74e9 | 2013-02-12 21:21:59 +0000 | [diff] [blame] | 150 | while (I != E && isdigit(static_cast<unsigned char>(*I))) |
Chris Lattner | 7ed3101 | 2006-02-01 01:29:47 +0000 | [diff] [blame] | 151 | ++I; |
Alexander Potapenko | 7d68c26 | 2016-05-23 13:58:04 +0000 | [diff] [blame] | 152 | pCodes->push_back(StringRef(NumStart, I - NumStart)); |
John Thompson | 1094c80 | 2010-09-13 18:15:37 +0000 | [diff] [blame] | 153 | unsigned N = atoi(pCodes->back().c_str()); |
Chris Lattner | 2f34a9e | 2006-02-02 00:23:53 +0000 | [diff] [blame] | 154 | // Check that this is a valid matching constraint! |
| 155 | if (N >= ConstraintsSoFar.size() || ConstraintsSoFar[N].Type != isOutput|| |
| 156 | Type != isInput) |
| 157 | return true; // Invalid constraint number. |
| 158 | |
Chris Lattner | 860df6e | 2008-10-17 16:47:46 +0000 | [diff] [blame] | 159 | // If Operand N already has a matching input, reject this. An output |
| 160 | // can't be constrained to the same value as multiple inputs. |
John Thompson | 1094c80 | 2010-09-13 18:15:37 +0000 | [diff] [blame] | 161 | if (isMultipleAlternative) { |
Karl Schimpf | f04a5d5 | 2015-09-03 15:41:37 +0000 | [diff] [blame] | 162 | if (multipleAlternativeIndex >= |
| 163 | ConstraintsSoFar[N].multipleAlternatives.size()) |
Karl Schimpf | 388fd5a | 2015-09-03 15:41:34 +0000 | [diff] [blame] | 164 | return true; |
John Thompson | 1094c80 | 2010-09-13 18:15:37 +0000 | [diff] [blame] | 165 | InlineAsm::SubConstraintInfo &scInfo = |
| 166 | ConstraintsSoFar[N].multipleAlternatives[multipleAlternativeIndex]; |
| 167 | if (scInfo.MatchingInput != -1) |
| 168 | return true; |
| 169 | // Note that operand #n has a matching input. |
| 170 | scInfo.MatchingInput = ConstraintsSoFar.size(); |
| 171 | } else { |
Benjamin Kramer | 9de151e | 2015-03-29 20:33:07 +0000 | [diff] [blame] | 172 | if (ConstraintsSoFar[N].hasMatchingInput() && |
Benjamin Kramer | 2739571 | 2015-03-29 20:49:03 +0000 | [diff] [blame] | 173 | (size_t)ConstraintsSoFar[N].MatchingInput != |
| 174 | ConstraintsSoFar.size()) |
John Thompson | 1094c80 | 2010-09-13 18:15:37 +0000 | [diff] [blame] | 175 | return true; |
| 176 | // Note that operand #n has a matching input. |
| 177 | ConstraintsSoFar[N].MatchingInput = ConstraintsSoFar.size(); |
| 178 | } |
| 179 | } else if (*I == '|') { |
| 180 | multipleAlternativeIndex++; |
| 181 | pCodes = &multipleAlternatives[multipleAlternativeIndex].Codes; |
| 182 | ++I; |
Eric Christopher | ca9b7bb | 2011-06-02 19:26:37 +0000 | [diff] [blame] | 183 | } else if (*I == '^') { |
| 184 | // Multi-letter constraint |
Eric Christopher | 1e3e893 | 2011-06-03 22:09:12 +0000 | [diff] [blame] | 185 | // FIXME: For now assuming these are 2-character constraints. |
Alexander Potapenko | 7d68c26 | 2016-05-23 13:58:04 +0000 | [diff] [blame] | 186 | pCodes->push_back(StringRef(I+1, 2)); |
Eric Christopher | 1e3e893 | 2011-06-03 22:09:12 +0000 | [diff] [blame] | 187 | I += 3; |
Chris Lattner | 7ed3101 | 2006-02-01 01:29:47 +0000 | [diff] [blame] | 188 | } else { |
| 189 | // Single letter constraint. |
Alexander Potapenko | 7d68c26 | 2016-05-23 13:58:04 +0000 | [diff] [blame] | 190 | pCodes->push_back(StringRef(I, 1)); |
Chris Lattner | 7ed3101 | 2006-02-01 01:29:47 +0000 | [diff] [blame] | 191 | ++I; |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | return false; |
| 196 | } |
| 197 | |
John Thompson | 1094c80 | 2010-09-13 18:15:37 +0000 | [diff] [blame] | 198 | /// selectAlternative - Point this constraint to the alternative constraint |
| 199 | /// indicated by the index. |
| 200 | void InlineAsm::ConstraintInfo::selectAlternative(unsigned index) { |
| 201 | if (index < multipleAlternatives.size()) { |
| 202 | currentAlternativeIndex = index; |
| 203 | InlineAsm::SubConstraintInfo &scInfo = |
| 204 | multipleAlternatives[currentAlternativeIndex]; |
| 205 | MatchingInput = scInfo.MatchingInput; |
| 206 | Codes = scInfo.Codes; |
| 207 | } |
| 208 | } |
| 209 | |
John Thompson | e8360b7 | 2010-10-29 17:29:13 +0000 | [diff] [blame] | 210 | InlineAsm::ConstraintInfoVector |
Daniel Dunbar | ad36e8a | 2009-11-06 10:58:06 +0000 | [diff] [blame] | 211 | InlineAsm::ParseConstraints(StringRef Constraints) { |
John Thompson | e8360b7 | 2010-10-29 17:29:13 +0000 | [diff] [blame] | 212 | ConstraintInfoVector Result; |
Chris Lattner | 8547e3a | 2006-01-26 00:48:33 +0000 | [diff] [blame] | 213 | |
| 214 | // Scan the constraints string. |
Daniel Dunbar | d43b86d | 2009-07-25 06:02:13 +0000 | [diff] [blame] | 215 | for (StringRef::iterator I = Constraints.begin(), |
| 216 | E = Constraints.end(); I != E; ) { |
Chris Lattner | 7ed3101 | 2006-02-01 01:29:47 +0000 | [diff] [blame] | 217 | ConstraintInfo Info; |
| 218 | |
| 219 | // Find the end of this constraint. |
Daniel Dunbar | d43b86d | 2009-07-25 06:02:13 +0000 | [diff] [blame] | 220 | StringRef::iterator ConstraintEnd = std::find(I, E, ','); |
Chris Lattner | 7ed3101 | 2006-02-01 01:29:47 +0000 | [diff] [blame] | 221 | |
| 222 | if (ConstraintEnd == I || // Empty constraint like ",," |
Benjamin Kramer | 5aaf677 | 2010-07-25 23:18:32 +0000 | [diff] [blame] | 223 | Info.Parse(StringRef(I, ConstraintEnd-I), Result)) { |
Chris Lattner | 2f34a9e | 2006-02-02 00:23:53 +0000 | [diff] [blame] | 224 | Result.clear(); // Erroneous constraint? |
Chris Lattner | c981b8e | 2006-01-26 02:21:59 +0000 | [diff] [blame] | 225 | break; |
| 226 | } |
Chris Lattner | 7ed3101 | 2006-02-01 01:29:47 +0000 | [diff] [blame] | 227 | |
| 228 | Result.push_back(Info); |
Chris Lattner | c981b8e | 2006-01-26 02:21:59 +0000 | [diff] [blame] | 229 | |
Chris Lattner | 7ed3101 | 2006-02-01 01:29:47 +0000 | [diff] [blame] | 230 | // ConstraintEnd may be either the next comma or the end of the string. In |
| 231 | // the former case, we skip the comma. |
| 232 | I = ConstraintEnd; |
Chris Lattner | c981b8e | 2006-01-26 02:21:59 +0000 | [diff] [blame] | 233 | if (I != E) { |
Chris Lattner | c981b8e | 2006-01-26 02:21:59 +0000 | [diff] [blame] | 234 | ++I; |
Eric Christopher | f3e79e8 | 2015-02-10 21:15:06 +0000 | [diff] [blame] | 235 | if (I == E) { |
| 236 | Result.clear(); |
| 237 | break; |
| 238 | } // don't allow "xyz," |
Chris Lattner | c981b8e | 2006-01-26 02:21:59 +0000 | [diff] [blame] | 239 | } |
| 240 | } |
| 241 | |
| 242 | return Result; |
| 243 | } |
| 244 | |
Chris Lattner | c981b8e | 2006-01-26 02:21:59 +0000 | [diff] [blame] | 245 | /// Verify - Verify that the specified constraint string is reasonable for the |
| 246 | /// specified function type, and otherwise validate the constraint string. |
Chris Lattner | 229907c | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 247 | bool InlineAsm::Verify(FunctionType *Ty, StringRef ConstStr) { |
Chris Lattner | c981b8e | 2006-01-26 02:21:59 +0000 | [diff] [blame] | 248 | if (Ty->isVarArg()) return false; |
| 249 | |
John Thompson | e8360b7 | 2010-10-29 17:29:13 +0000 | [diff] [blame] | 250 | ConstraintInfoVector Constraints = ParseConstraints(ConstStr); |
Chris Lattner | c981b8e | 2006-01-26 02:21:59 +0000 | [diff] [blame] | 251 | |
| 252 | // Error parsing constraints. |
| 253 | if (Constraints.empty() && !ConstStr.empty()) return false; |
| 254 | |
| 255 | unsigned NumOutputs = 0, NumInputs = 0, NumClobbers = 0; |
Chris Lattner | ee00d04 | 2008-05-22 04:46:38 +0000 | [diff] [blame] | 256 | unsigned NumIndirect = 0; |
Chris Lattner | c981b8e | 2006-01-26 02:21:59 +0000 | [diff] [blame] | 257 | |
| 258 | for (unsigned i = 0, e = Constraints.size(); i != e; ++i) { |
Chris Lattner | 7ed3101 | 2006-02-01 01:29:47 +0000 | [diff] [blame] | 259 | switch (Constraints[i].Type) { |
| 260 | case InlineAsm::isOutput: |
Chris Lattner | ee00d04 | 2008-05-22 04:46:38 +0000 | [diff] [blame] | 261 | if ((NumInputs-NumIndirect) != 0 || NumClobbers != 0) |
| 262 | return false; // outputs before inputs and clobbers. |
Chris Lattner | c48e2c3 | 2007-04-28 01:02:58 +0000 | [diff] [blame] | 263 | if (!Constraints[i].isIndirect) { |
Chris Lattner | 7ed3101 | 2006-02-01 01:29:47 +0000 | [diff] [blame] | 264 | ++NumOutputs; |
| 265 | break; |
| 266 | } |
Chris Lattner | ee00d04 | 2008-05-22 04:46:38 +0000 | [diff] [blame] | 267 | ++NumIndirect; |
Chris Lattner | c48e2c3 | 2007-04-28 01:02:58 +0000 | [diff] [blame] | 268 | // FALLTHROUGH for Indirect Outputs. |
Chris Lattner | 7ed3101 | 2006-02-01 01:29:47 +0000 | [diff] [blame] | 269 | case InlineAsm::isInput: |
Chris Lattner | 8547e3a | 2006-01-26 00:48:33 +0000 | [diff] [blame] | 270 | if (NumClobbers) return false; // inputs before clobbers. |
| 271 | ++NumInputs; |
| 272 | break; |
Chris Lattner | 7ed3101 | 2006-02-01 01:29:47 +0000 | [diff] [blame] | 273 | case InlineAsm::isClobber: |
Chris Lattner | 8547e3a | 2006-01-26 00:48:33 +0000 | [diff] [blame] | 274 | ++NumClobbers; |
| 275 | break; |
| 276 | } |
Chris Lattner | 8547e3a | 2006-01-26 00:48:33 +0000 | [diff] [blame] | 277 | } |
Chris Lattner | 8547e3a | 2006-01-26 00:48:33 +0000 | [diff] [blame] | 278 | |
Chris Lattner | 10748d8 | 2008-04-27 23:33:55 +0000 | [diff] [blame] | 279 | switch (NumOutputs) { |
| 280 | case 0: |
Benjamin Kramer | ccce8ba | 2010-01-05 13:12:22 +0000 | [diff] [blame] | 281 | if (!Ty->getReturnType()->isVoidTy()) return false; |
Chris Lattner | 10748d8 | 2008-04-27 23:33:55 +0000 | [diff] [blame] | 282 | break; |
| 283 | case 1: |
Duncan Sands | 19d0b47 | 2010-02-16 11:11:14 +0000 | [diff] [blame] | 284 | if (Ty->getReturnType()->isStructTy()) return false; |
Chris Lattner | 10748d8 | 2008-04-27 23:33:55 +0000 | [diff] [blame] | 285 | break; |
| 286 | default: |
Chris Lattner | 229907c | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 287 | StructType *STy = dyn_cast<StructType>(Ty->getReturnType()); |
Craig Topper | c620761 | 2014-04-09 06:08:46 +0000 | [diff] [blame] | 288 | if (!STy || STy->getNumElements() != NumOutputs) |
Chris Lattner | 10748d8 | 2008-04-27 23:33:55 +0000 | [diff] [blame] | 289 | return false; |
| 290 | break; |
| 291 | } |
Chris Lattner | 8547e3a | 2006-01-26 00:48:33 +0000 | [diff] [blame] | 292 | |
| 293 | if (Ty->getNumParams() != NumInputs) return false; |
Chris Lattner | a2d810d | 2006-01-25 22:26:05 +0000 | [diff] [blame] | 294 | return true; |
| 295 | } |