]> granicus.if.org Git - clang/commitdiff
Handle multi-value inputs
authorAnders Carlsson <andersca@mac.com>
Mon, 12 Jan 2009 02:22:13 +0000 (02:22 +0000)
committerAnders Carlsson <andersca@mac.com>
Mon, 12 Jan 2009 02:22:13 +0000 (02:22 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62069 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGStmt.cpp
test/CodeGen/asm.c

index fd01905698a930c26ea88ef935bd4a921fb0d2b9..edccbe41bfd5f2b4e247ea1e6015bc7336cb8237 100644 (file)
@@ -19,6 +19,7 @@
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/InlineAsm.h"
 #include "llvm/Intrinsics.h"
+#include "llvm/Target/TargetData.h"
 using namespace clang;
 using namespace CodeGen;
 
@@ -867,12 +868,24 @@ llvm::Value* CodeGenFunction::EmitAsmInput(const AsmStmt &S,
 {
   llvm::Value *Arg;
   if ((Info & TargetInfo::CI_AllowsRegister) ||
-      !(Info & TargetInfo::CI_AllowsMemory)) {      
-    if (ConvertType(InputExpr->getType())->isSingleValueType()) {
+      !(Info & TargetInfo::CI_AllowsMemory)) { 
+    const llvm::Type *Ty = ConvertType(InputExpr->getType());
+    
+    if (Ty->isSingleValueType()) {
       Arg = EmitScalarExpr(InputExpr);
     } else {
-      ErrorUnsupported(&S,
-                       "asm statement passing multiple-value types as inputs");
+      LValue Dest = EmitLValue(InputExpr);
+
+      uint64_t Size = CGM.getTargetData().getTypeSizeInBits(Ty);
+      if (Size <= 64 && llvm::isPowerOf2_64(Size)) {
+        Ty = llvm::IntegerType::get(Size);
+        Ty = llvm::PointerType::getUnqual(Ty);
+        
+        Arg = Builder.CreateLoad(Builder.CreateBitCast(Dest.getAddress(), Ty));
+      } else {
+        Arg = Dest.getAddress();
+        ConstraintStr += '*';
+      }
     }
   } else {
     LValue Dest = EmitLValue(InputExpr);
@@ -964,7 +977,7 @@ void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) {
     
     TargetInfo::ConstraintInfo Info;
     bool result = Target.validateInputConstraint(InputConstraint.c_str(),
-                                                 NumConstraints,  Info);
+                                                 NumConstraints, Info);
     assert(result && "Failed to parse input constraint"); result=result;
     
     if (i != 0 || S.getNumOutputs() > 0)
index 0b6485ebfff9a1a2ecc8012865277ff19981ba06..4ef97bde2ad3d4e0d2cf10745ff79c5dabff81e4 100644 (file)
@@ -14,6 +14,13 @@ void t3(unsigned char *src, unsigned long long temp)
   __asm__ volatile("" : "+m"(temp), "+r"(src));
 }
 
+void t4()
+{
+  unsigned long long a;
+  struct reg { unsigned long long a, b; } b;
+
+       __asm__ volatile ("":: "m"(a), "m"(b));
+}