//
// The LLVM Compiler Infrastructure
//
-// This file was developed by Chris Lattner and is distributed under the
-// University of Illinois Open Source License. See LICENSE.TXT for details.
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
InlineAsm::InlineAsm(const FunctionType *Ty, const std::string &asmString,
const std::string &constraints, bool hasSideEffects)
- : Value(PointerType::get(Ty), Value::InlineAsmVal), AsmString(asmString),
+ : Value(PointerType::getUnqual(Ty),
+ Value::InlineAsmVal),
+ AsmString(asmString),
Constraints(constraints), HasSideEffects(hasSideEffects) {
// Do various checks on the constraint string and type.
// Initialize
Type = isInput;
isEarlyClobber = false;
- isIndirectOutput = false;
- hasMatchingInput = false;
+ MatchingInput = -1;
isCommutative = false;
+ isIndirect = false;
- // Parse the prefix.
+ // Parse prefixes.
if (*I == '~') {
Type = isClobber;
++I;
} else if (*I == '=') {
++I;
Type = isOutput;
- if (I != E && *I == '=') {
- isIndirectOutput = true;
- ++I;
- }
+ }
+
+ if (*I == '*') {
+ isIndirect = true;
+ ++I;
}
if (I == E) return true; // Just a prefix, like "==" or "~".
Type != isInput)
return true; // Invalid constraint number.
+ // If Operand N already has a matching input, reject this. An output
+ // can't be constrained to the same value as multiple inputs.
+ if (ConstraintsSoFar[N].hasMatchingInput())
+ return true;
+
// Note that operand #n has a matching input.
- ConstraintsSoFar[N].hasMatchingInput = true;
+ ConstraintsSoFar[N].MatchingInput = ConstraintsSoFar.size();
} else {
// Single letter constraint.
Codes.push_back(std::string(I, I+1));
if (Constraints.empty() && !ConstStr.empty()) return false;
unsigned NumOutputs = 0, NumInputs = 0, NumClobbers = 0;
+ unsigned NumIndirect = 0;
for (unsigned i = 0, e = Constraints.size(); i != e; ++i) {
switch (Constraints[i].Type) {
case InlineAsm::isOutput:
- if (!Constraints[i].isIndirectOutput) {
- if (NumInputs || NumClobbers) return false; // outputs come first.
+ if ((NumInputs-NumIndirect) != 0 || NumClobbers != 0)
+ return false; // outputs before inputs and clobbers.
+ if (!Constraints[i].isIndirect) {
++NumOutputs;
break;
}
- // FALLTHROUGH for IndirectOutputs.
+ ++NumIndirect;
+ // FALLTHROUGH for Indirect Outputs.
case InlineAsm::isInput:
if (NumClobbers) return false; // inputs before clobbers.
++NumInputs;
break;
}
}
-
- if (NumOutputs > 1) return false; // Only one result allowed so far.
- if ((Ty->getReturnType() != Type::VoidTy) != NumOutputs)
- return false; // NumOutputs = 1 iff has a result type.
+ switch (NumOutputs) {
+ case 0:
+ if (Ty->getReturnType() != Type::VoidTy) return false;
+ break;
+ case 1:
+ if (isa<StructType>(Ty->getReturnType())) return false;
+ break;
+ default:
+ const StructType *STy = dyn_cast<StructType>(Ty->getReturnType());
+ if (STy == 0 || STy->getNumElements() != NumOutputs)
+ return false;
+ break;
+ }
if (Ty->getNumParams() != NumInputs) return false;
return true;
}
+