]> granicus.if.org Git - clang/commitdiff
Generate bitcasts going in and out of MMX parameters
authorDale Johannesen <dalej@apple.com>
Fri, 29 Oct 2010 23:12:32 +0000 (23:12 +0000)
committerDale Johannesen <dalej@apple.com>
Fri, 29 Oct 2010 23:12:32 +0000 (23:12 +0000)
in asm's.  PR 8501, 8602988.
I don't like including Type.h where it is; the idea was
to get references to X86_MMXTy out of the common code.
Maybe there's a better way?

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@117736 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/TargetInfo.h
lib/Basic/Targets.cpp
lib/CodeGen/CGStmt.cpp

index a00cc0d07c1284003edf92414cc1b783b47a5e8b..2912bc92aa39af9be66ab996a90cea70683e0ae6 100644 (file)
@@ -19,6 +19,7 @@
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/ADT/Triple.h"
 #include "llvm/System/DataTypes.h"
+#include "llvm/Type.h"
 #include <cassert>
 #include <vector>
 #include <string>
@@ -26,6 +27,7 @@
 namespace llvm {
 struct fltSemantics;
 class StringRef;
+class LLVMContext;
 }
 
 namespace clang {
@@ -524,6 +526,11 @@ public:
     return 0;
   }
 
+  virtual const llvm::Type* adjustInlineAsmType(std::string& Constraint, 
+                                     const llvm::Type* Ty,
+                                     llvm::LLVMContext& Context) const {
+    return Ty;
+  }
 protected:
   virtual uint64_t getPointerWidthV(unsigned AddrSpace) const {
     return PointerWidth;
index 5ed285dcd74c576904f3958a8d6b64f5ace922ea..631aa1f33d9f61e6f2a493986dd3897644726c31 100644 (file)
@@ -985,6 +985,9 @@ public:
   }
   virtual bool validateAsmConstraint(const char *&Name,
                                      TargetInfo::ConstraintInfo &info) const;
+  virtual const llvm::Type* adjustInlineAsmType(std::string& Constraint,
+                                     const llvm::Type* Ty,
+                                     llvm::LLVMContext& Context) const;
   virtual std::string convertConstraint(const char Constraint) const;
   virtual const char *getClobbers() const {
     return "~{dirflag},~{fpsr},~{flags}";
@@ -1306,6 +1309,16 @@ X86TargetInfo::validateAsmConstraint(const char *&Name,
   return false;
 }
 
+const llvm::Type*
+X86TargetInfo::adjustInlineAsmType(std::string& Constraint,
+                                   const llvm::Type* Ty,
+                                   llvm::LLVMContext &Context) const {
+  if (Constraint=="y" && Ty->isVectorTy())
+    return llvm::Type::getX86_MMXTy(Context);
+  return Ty;
+}
+
+
 std::string
 X86TargetInfo::convertConstraint(const char Constraint) const {
   switch (Constraint) {
index 4de505abdf6e6b02a0f3ef8e044aa7e7c72d623d..282541bd02cc59f69e32fd09066f01453daf1807 100644 (file)
@@ -1046,6 +1046,10 @@ void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) {
           ResultRegTypes.back() = ConvertType(InputTy);
         }
       }
+      if (const llvm::Type* AdjTy = 
+            Target.adjustInlineAsmType(OutputConstraint, ResultRegTypes.back(),
+                                       VMContext))
+        ResultRegTypes.back() = AdjTy;
     } else {
       ArgTypes.push_back(Dest.getAddress()->getType());
       Args.push_back(Dest.getAddress());
@@ -1109,7 +1113,10 @@ void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) {
           Arg = Builder.CreateFPExt(Arg, OutputTy);
       }
     }
-
+    if (const llvm::Type* AdjTy = 
+              Target.adjustInlineAsmType(InputConstraint, Arg->getType(),
+                                         VMContext))
+      Arg = Builder.CreateBitCast(Arg, AdjTy);
 
     ArgTypes.push_back(Arg->getType());
     Args.push_back(Arg);
@@ -1204,6 +1211,8 @@ void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) {
         Tmp = Builder.CreateTrunc(Tmp, TruncTy);
       } else if (TruncTy->isIntegerTy()) {
         Tmp = Builder.CreateTrunc(Tmp, TruncTy);
+      } else if (TruncTy->isVectorTy()) {
+        Tmp = Builder.CreateBitCast(Tmp, TruncTy);
       }
     }