Implement changes from Chris's feedback.
[oota-llvm.git] / lib / VMCore / InlineAsm.cpp
index ca4ecad058c058ffea5fb897230cb5801800040c..524e294ab75f5b5a7efe3b1663413f0b4426246e 100644 (file)
@@ -2,8 +2,8 @@
 //
 //                     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.
 //
 //===----------------------------------------------------------------------===//
 //
@@ -34,7 +34,9 @@ InlineAsm *InlineAsm::get(const FunctionType *Ty, const std::string &AsmString,
 
 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.
@@ -55,7 +57,7 @@ bool InlineAsm::ConstraintInfo::Parse(const std::string &Str,
   // Initialize
   Type = isInput;
   isEarlyClobber = false;
-  hasMatchingInput = false;
+  MatchingInput = -1;
   isCommutative = false;
   isIndirect = false;
   
@@ -125,8 +127,13 @@ bool InlineAsm::ConstraintInfo::Parse(const std::string &Str,
           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));
@@ -181,15 +188,18 @@ bool InlineAsm::Verify(const FunctionType *Ty, const std::string &ConstStr) {
   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 ((NumInputs-NumIndirect) != 0 || NumClobbers != 0)
+        return false;  // outputs before inputs and clobbers.
       if (!Constraints[i].isIndirect) {
-        if (NumInputs || NumClobbers) return false;  // outputs come first.
         ++NumOutputs;
         break;
       }
+      ++NumIndirect;
       // FALLTHROUGH for Indirect Outputs.
     case InlineAsm::isInput:
       if (NumClobbers) return false;               // inputs before clobbers.
@@ -200,14 +210,22 @@ bool InlineAsm::Verify(const FunctionType *Ty, const std::string &ConstStr) {
       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;
 }
 
-DEFINING_FILE_FOR(InlineAsm)