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