[cfe-commits] r66531 - in /cfe/trunk: include/clang/AST/Stmt.h lib/AST/Stmt.cpp lib/CodeGen/CGStmt.cpp test/CodeGen/asm.c

Chris Lattner sabre at nondot.org
Mon Mar 9 23:33:24 PDT 2009


Author: lattner
Date: Tue Mar 10 01:33:24 2009
New Revision: 66531

URL: http://llvm.org/viewvc/llvm-project?rev=66531&view=rev
Log:
move matching of named operands into AsmStmt class.  At the same
time handle + operands in operand counting, fixing asm.c:t7 to
expand into $2 instead of $1.

Modified:
    cfe/trunk/include/clang/AST/Stmt.h
    cfe/trunk/lib/AST/Stmt.cpp
    cfe/trunk/lib/CodeGen/CGStmt.cpp
    cfe/trunk/test/CodeGen/asm.c

Modified: cfe/trunk/include/clang/AST/Stmt.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Stmt.h?rev=66531&r1=66530&r2=66531&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Stmt.h (original)
+++ cfe/trunk/include/clang/AST/Stmt.h Tue Mar 10 01:33:24 2009
@@ -982,6 +982,15 @@
   const Expr *getInputExpr(unsigned i) const {
     return const_cast<AsmStmt*>(this)->getInputExpr(i);
   }
+  
+  //===--- Other ---===//
+  
+  /// getNamedOperand - Given a symbolic operand reference like %[foo],
+  /// translate this into a numeric value needed to reference the same operand.
+  /// This returns -1 if the operand name is invalid.
+  int getNamedOperand(const std::string &SymbolicName) const;
+
+  
 
   const StringLiteral *getAsmString() const { return AsmStr; }
   StringLiteral *getAsmString() { return AsmStr; }

Modified: cfe/trunk/lib/AST/Stmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Stmt.cpp?rev=66531&r1=66530&r2=66531&view=diff

==============================================================================
--- cfe/trunk/lib/AST/Stmt.cpp (original)
+++ cfe/trunk/lib/AST/Stmt.cpp Tue Mar 10 01:33:24 2009
@@ -154,6 +154,31 @@
                      Constraints[i + NumOutputs]->getByteLength());
 }
 
+
+/// getNamedOperand - Given a symbolic operand reference like %[foo],
+/// translate this into a numeric value needed to reference the same operand.
+/// This returns -1 if the operand name is invalid.
+int AsmStmt::getNamedOperand(const std::string &SymbolicName) const {
+  unsigned NumPlusOperands = 0;
+  
+  // Check if this is an output operand.
+  for (unsigned i = 0, e = getNumOutputs(); i != e; ++i) {
+    if (getOutputName(i) == SymbolicName)
+      return i;
+    
+    // Keep track of the number of '+' operands.
+    if (isOutputPlusConstraint(i)) ++NumPlusOperands;
+  }
+  
+  for (unsigned i = 0, e = getNumInputs(); i != e; ++i)
+    if (getInputName(i) == SymbolicName)
+      return getNumOutputs() + NumPlusOperands + i;
+
+  // Not found.
+  return -1;
+}
+
+
 //===----------------------------------------------------------------------===//
 // Constructors
 //===----------------------------------------------------------------------===//

Modified: cfe/trunk/lib/CodeGen/CGStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGStmt.cpp?rev=66531&r1=66530&r2=66531&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGStmt.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGStmt.cpp Tue Mar 10 01:33:24 2009
@@ -771,34 +771,15 @@
     if (EscapedChar == '[') {
       const char *NameEnd = (const char*)memchr(StrStart, ']', StrEnd-StrStart);
       // FIXME: Should be caught by sema.
+      // FIXME: Does sema catch multiple operands with the same name?
       assert(NameEnd != 0 && "Could not parse symbolic name");
-      
       std::string SymbolicName(StrStart, NameEnd);
-      
       StrStart = NameEnd+1;
       
-      int Index = -1;
-      
-      // Check if this is an output operand.
-      for (unsigned i = 0; i != S.getNumOutputs(); ++i) {
-        if (S.getOutputName(i) == SymbolicName) {
-          Index = i;
-          break;
-        }
-      }
-      
-      if (Index == -1) {
-        for (unsigned i = 0; i != S.getNumInputs(); ++i) {
-          if (S.getInputName(i) == SymbolicName) {
-            Index = S.getNumOutputs() + i;
-            break;
-          }
-        }
-      }
-      
-      assert(Index != -1 && "Did not find right operand!");
-     
-      Result += '$' + llvm::utostr(Index);
+      int OperandIndex = S.getNamedOperand(SymbolicName);
+      assert(OperandIndex != -1 && "FIXME: Catch in Sema.");
+
+      Result += '$' + llvm::utostr(unsigned(OperandIndex));
       continue;
     }
      

Modified: cfe/trunk/test/CodeGen/asm.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/asm.c?rev=66531&r1=66530&r2=66531&view=diff

==============================================================================
--- cfe/trunk/test/CodeGen/asm.c (original)
+++ cfe/trunk/test/CodeGen/asm.c Tue Mar 10 01:33:24 2009
@@ -1,21 +1,17 @@
-// RUN: clang -emit-llvm %s -o %t -arch=i386 
-void t1(int len)
-{
+// RUN: clang -emit-llvm %s -o %t -arch=i386 &&
+void t1(int len) {
   __asm__ volatile("" : "=&r"(len), "+&r"(len));
 }
 
-void t2(unsigned long long t) 
-{
+void t2(unsigned long long t)  {
   __asm__ volatile("" : "+m"(t));
 }
 
-void t3(unsigned char *src, unsigned long long temp)
-{
+void t3(unsigned char *src, unsigned long long temp) {
   __asm__ volatile("" : "+m"(temp), "+r"(src));
 }
 
-void t4()
-{
+void t4() {
   unsigned long long a;
   struct reg { unsigned long long a, b; } b;
 
@@ -23,13 +19,16 @@
 }
 
 // PR3417
-void t5(int i)
-{
+void t5(int i) {
   asm("nop" : "=r"(i) : "0"(t5));
 }
 
 // PR3641
-void t6(void)
-{
+void t6(void) {
   __asm__ volatile("" : : "i" (t6));
 }
+
+// RUN: grep "T7 NAMED: \$2" %t
+void t7(int a) {
+  __asm__ volatile("T7 NAMED: %[input]" : "+r"(a): [input] "i" (4));
+}
\ No newline at end of file





More information about the cfe-commits mailing list