]> granicus.if.org Git - clang/commitdiff
[ms-inline asm] Add support for clobbers in CodeGen.
authorChad Rosier <mcrosier@apple.com>
Wed, 15 Aug 2012 18:12:36 +0000 (18:12 +0000)
committerChad Rosier <mcrosier@apple.com>
Wed, 15 Aug 2012 18:12:36 +0000 (18:12 +0000)
This is a reapplication of r161914 now that the scoping issue has been resolved
in r161966.

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

lib/CodeGen/CGStmt.cpp
test/CodeGen/ms-inline-asm.c

index 467c77945e6035743746233ee1279157f3b9b9d2..d78908dee8768414c4ba7b29531f1a0800b2e742 100644 (file)
@@ -1691,14 +1691,36 @@ void CodeGenFunction::EmitMSAsmStmt(const MSAsmStmt &S) {
 
   std::vector<llvm::Value*> Args;
   std::vector<llvm::Type *> ArgTypes;
+  std::string Constraints;
+
+  // Clobbers
+  for (unsigned i = 0, e = S.getNumClobbers(); i != e; ++i) {
+    StringRef Clobber = S.getClobber(i);
+
+    if (Clobber != "memory" && Clobber != "cc")
+      Clobber = Target.getNormalizedGCCRegisterName(Clobber);
+
+    if (i != 0)
+      Constraints += ',';
+
+    Constraints += "~{";
+    Constraints += Clobber;
+    Constraints += '}';
+  }
 
+  // Add machine specific clobbers
   std::string MachineClobbers = Target.getClobbers();
+  if (!MachineClobbers.empty()) {
+    if (!Constraints.empty())
+      Constraints += ',';
+    Constraints += MachineClobbers;
+  }
 
   llvm::FunctionType *FTy =
     llvm::FunctionType::get(VoidTy, ArgTypes, false);
 
   llvm::InlineAsm *IA =
-    llvm::InlineAsm::get(FTy, *S.getAsmString(), MachineClobbers, true);
+    llvm::InlineAsm::get(FTy, *S.getAsmString(), Constraints, true);
   llvm::CallInst *Result = Builder.CreateCall(IA, Args);
   Result->addAttribute(~0, llvm::Attribute::NoUnwind);
   Result->addAttribute(~0, llvm::Attribute::IANSDialect);
index c08e53b64e1793a83c30c435251685af80819f2c..fe0d3a5826659b3dd6675fe936ab1c0008e2b422 100644 (file)
@@ -29,8 +29,8 @@ void t3() {
 
 void t4(void) {
 // CHECK: @t4
-// CHECK: call void asm sideeffect "mov ebx, eax", "~{dirflag},~{fpsr},~{flags}"() nounwind ia_nsdialect
-// CHECK: call void asm sideeffect "mov ecx, ebx", "~{dirflag},~{fpsr},~{flags}"() nounwind ia_nsdialect
+// CHECK: call void asm sideeffect "mov ebx, eax", "~{ebx},~{dirflag},~{fpsr},~{flags}"() nounwind ia_nsdialect
+// CHECK: call void asm sideeffect "mov ecx, ebx", "~{ecx},~{dirflag},~{fpsr},~{flags}"() nounwind ia_nsdialect
 // CHECK: ret void
   __asm mov ebx, eax
   __asm mov ecx, ebx
@@ -38,8 +38,8 @@ void t4(void) {
 
 void t5(void) {
 // CHECK: @t5
-// CHECK: call void asm sideeffect "mov ebx, eax", "~{dirflag},~{fpsr},~{flags}"() nounwind ia_nsdialect
-// CHECK: call void asm sideeffect "mov ecx, ebx", "~{dirflag},~{fpsr},~{flags}"() nounwind ia_nsdialect
+// CHECK: call void asm sideeffect "mov ebx, eax", "~{ebx},~{dirflag},~{fpsr},~{flags}"() nounwind ia_nsdialect
+// CHECK: call void asm sideeffect "mov ecx, ebx", "~{ecx},~{dirflag},~{fpsr},~{flags}"() nounwind ia_nsdialect
 // CHECK: ret void
   __asm mov ebx, eax __asm mov ecx, ebx
 }
@@ -83,5 +83,5 @@ void t10() {
     pop ebx
   }
 // CHECK: t10
-// CHECK: call void asm sideeffect "push ebx\0Amov ebx, 0x07\0Apop ebx", "~{dirflag},~{fpsr},~{flags}"() nounwind ia_nsdialect
+// CHECK: call void asm sideeffect "push ebx\0Amov ebx, 0x07\0Apop ebx", "~{ebx},~{ebx},~{dirflag},~{fpsr},~{flags}"() nounwind ia_nsdialect
 }