[PATCH] D36450: [X86][Ms-InlineAsm] Extend MS Dot operator to accept "this" + struct/class pointers aliases

2017-08-09 Thread coby via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL310472: [X86][Ms-InlineAsm] Extend MS Dot operator to accept 
"this" + struct/class… (authored by coby).

Changed prior to commit:
  https://reviews.llvm.org/D36450?vs=110145=110377#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D36450

Files:
  cfe/trunk/lib/Sema/SemaStmtAsm.cpp
  cfe/trunk/test/CodeGen/ms-inline-asm.c
  cfe/trunk/test/CodeGen/ms-inline-asm.cpp

Index: cfe/trunk/test/CodeGen/ms-inline-asm.cpp
===
--- cfe/trunk/test/CodeGen/ms-inline-asm.cpp
+++ cfe/trunk/test/CodeGen/ms-inline-asm.cpp
@@ -180,3 +180,19 @@
   A::g();
 }
 
+void t9() {
+  // CHECK-LABEL: define void @_Z2t9v()
+  struct A {
+int a;
+int b;
+void g() {
+  __asm mov eax, dword ptr [eax]this.b
+  // CHECK: call void asm sideeffect inteldialect
+  // CHECK-SAME: mov eax, dword ptr [eax].4
+  // CHECK-SAME: "~{eax},~{dirflag},~{fpsr},~{flags}"()
+}
+  };
+  A AA;
+  AA.g();
+}
+
Index: cfe/trunk/test/CodeGen/ms-inline-asm.c
===
--- cfe/trunk/test/CodeGen/ms-inline-asm.c
+++ cfe/trunk/test/CodeGen/ms-inline-asm.c
@@ -527,7 +527,7 @@
 typedef struct {
   int a;
   int b;
-} A;
+} A, *pA;
 
 typedef struct {
   int b1;
@@ -539,14 +539,16 @@
   A   c2;
   int c3;
   B   c4;
-} C;
+} C, *pC;
 
 void t39() {
 // CHECK-LABEL: define void @t39
   __asm mov eax, [eax].A.b
 // CHECK: mov eax, [eax].4
   __asm mov eax, [eax] A.b
 // CHECK: mov eax, [eax] .4
+  __asm mov eax, [eax] pA.b
+// CHECK: mov eax, [eax] .4
   __asm mov eax, fs:[0] A.b
 // CHECK: mov eax, fs:[$$0] .4
   __asm mov eax, [eax].B.b2.a
@@ -557,6 +559,8 @@
 // CHECK: mov eax, fs:[$$0] .8
   __asm mov eax, [eax]C.c4.b2.b
 // CHECK: mov eax, [eax].24
+  __asm mov eax, [eax]pC.c4.b2.b
+// CHECK: mov eax, [eax].24
 // CHECK: "~{eax},~{dirflag},~{fpsr},~{flags}"()
 }
 
Index: cfe/trunk/lib/Sema/SemaStmtAsm.cpp
===
--- cfe/trunk/lib/Sema/SemaStmtAsm.cpp
+++ cfe/trunk/lib/Sema/SemaStmtAsm.cpp
@@ -677,22 +677,33 @@
   SmallVector Members;
   Member.split(Members, ".");
 
-  LookupResult BaseResult(*this, (Base), SourceLocation(),
-  LookupOrdinaryName);
+  NamedDecl *FoundDecl = nullptr;
 
-  if (!LookupName(BaseResult, getCurScope()))
-return true;
-  
-  if(!BaseResult.isSingleResult())
+  // MS InlineAsm uses 'this' as a base
+  if (getLangOpts().CPlusPlus && Base.equals("this")) {
+if (const Type *PT = getCurrentThisType().getTypePtrOrNull())
+  FoundDecl = PT->getPointeeType()->getAsTagDecl();
+  } else {
+LookupResult BaseResult(*this, (Base), SourceLocation(),
+LookupOrdinaryName);
+if (LookupName(BaseResult, getCurScope()) && BaseResult.isSingleResult())
+  FoundDecl = BaseResult.getFoundDecl();
+  }
+
+  if (!FoundDecl)
 return true;
-  NamedDecl *FoundDecl = BaseResult.getFoundDecl();
+
   for (StringRef NextMember : Members) {
 const RecordType *RT = nullptr;
 if (VarDecl *VD = dyn_cast(FoundDecl))
   RT = VD->getType()->getAs();
 else if (TypedefNameDecl *TD = dyn_cast(FoundDecl)) {
   MarkAnyDeclReferenced(TD->getLocation(), TD, /*OdrUse=*/false);
-  RT = TD->getUnderlyingType()->getAs();
+  // MS InlineAsm often uses struct pointer aliases as a base
+  QualType QT = TD->getUnderlyingType();
+  if (const auto *PT = QT->getAs())
+QT = PT->getPointeeType();
+  RT = QT->getAs();
 } else if (TypeDecl *TD = dyn_cast(FoundDecl))
   RT = TD->getTypeForDecl()->getAs();
 else if (FieldDecl *TD = dyn_cast(FoundDecl))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36450: [X86][Ms-InlineAsm] Extend MS Dot operator to accept "this" + struct/class pointers aliases

2017-08-09 Thread coby via Phabricator via cfe-commits
coby added inline comments.



Comment at: lib/Sema/SemaStmtAsm.cpp:702-705
+  // MS InlineAsm often uses struct pointer aliases as a base
+  const QualType QT = TD->getUnderlyingType();
+  RT = isa(QT) ? QT->getPointeeType()->getAs() :
+  QT->getAs();

rnk wrote:
> This would probably be simpler as:
>   QualType Ty = TD->getUnderlyingType();
>   if (const auto *PT = Ty->getAs())
> Ty = PT->getPointeeType();
>   RT = Ty->getAsRecordType();
> ... to avoid repeating getAs().
Indeed. thx for pointing it out!


Repository:
  rL LLVM

https://reviews.llvm.org/D36450



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36450: [X86][Ms-InlineAsm] Extend MS Dot operator to accept "this" + struct/class pointers aliases

2017-08-08 Thread Reid Kleckner via Phabricator via cfe-commits
rnk accepted this revision.
rnk added a comment.
This revision is now accepted and ready to land.

lgtm




Comment at: lib/Sema/SemaStmtAsm.cpp:702-705
+  // MS InlineAsm often uses struct pointer aliases as a base
+  const QualType QT = TD->getUnderlyingType();
+  RT = isa(QT) ? QT->getPointeeType()->getAs() :
+  QT->getAs();

This would probably be simpler as:
  QualType Ty = TD->getUnderlyingType();
  if (const auto *PT = Ty->getAs())
Ty = PT->getPointeeType();
  RT = Ty->getAsRecordType();
... to avoid repeating getAs().


Repository:
  rL LLVM

https://reviews.llvm.org/D36450



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36450: [X86][Ms-InlineAsm] Extend MS Dot operator to accept "this" + struct/class pointers aliases

2017-08-08 Thread coby via Phabricator via cfe-commits
coby created this revision.
Herald added a subscriber: eraman.

MS InlineAsm Dot operator accepts "Bases" such as "this" (cpp) and class/struct 
pointer typedef.
This patch enhance its implementation with this behavior.


Repository:
  rL LLVM

https://reviews.llvm.org/D36450

Files:
  lib/Sema/SemaStmtAsm.cpp
  test/CodeGen/ms-inline-asm.c
  test/CodeGen/ms-inline-asm.cpp

Index: lib/Sema/SemaStmtAsm.cpp
===
--- lib/Sema/SemaStmtAsm.cpp
+++ lib/Sema/SemaStmtAsm.cpp
@@ -677,22 +677,32 @@
   SmallVector Members;
   Member.split(Members, ".");
 
-  LookupResult BaseResult(*this, (Base), SourceLocation(),
-  LookupOrdinaryName);
+  NamedDecl *FoundDecl = nullptr;
 
-  if (!LookupName(BaseResult, getCurScope()))
-return true;
-  
-  if(!BaseResult.isSingleResult())
+  // MS InlineAsm uses 'this' as a base
+  if (getLangOpts().CPlusPlus && Base.equals("this")) {
+if (const Type *PT = getCurrentThisType().getTypePtrOrNull())
+  FoundDecl = PT->getPointeeType()->getAsTagDecl();
+  } else {
+LookupResult BaseResult(*this, (Base), SourceLocation(),
+LookupOrdinaryName);
+if (LookupName(BaseResult, getCurScope()) && BaseResult.isSingleResult())
+  FoundDecl = BaseResult.getFoundDecl();
+  }
+
+  if (!FoundDecl)
 return true;
-  NamedDecl *FoundDecl = BaseResult.getFoundDecl();
+
   for (StringRef NextMember : Members) {
 const RecordType *RT = nullptr;
 if (VarDecl *VD = dyn_cast(FoundDecl))
   RT = VD->getType()->getAs();
 else if (TypedefNameDecl *TD = dyn_cast(FoundDecl)) {
   MarkAnyDeclReferenced(TD->getLocation(), TD, /*OdrUse=*/false);
-  RT = TD->getUnderlyingType()->getAs();
+  // MS InlineAsm often uses struct pointer aliases as a base
+  const QualType QT = TD->getUnderlyingType();
+  RT = isa(QT) ? QT->getPointeeType()->getAs() :
+  QT->getAs();
 } else if (TypeDecl *TD = dyn_cast(FoundDecl))
   RT = TD->getTypeForDecl()->getAs();
 else if (FieldDecl *TD = dyn_cast(FoundDecl))
Index: test/CodeGen/ms-inline-asm.c
===
--- test/CodeGen/ms-inline-asm.c
+++ test/CodeGen/ms-inline-asm.c
@@ -527,7 +527,7 @@
 typedef struct {
   int a;
   int b;
-} A;
+} A, *pA;
 
 typedef struct {
   int b1;
@@ -539,14 +539,16 @@
   A   c2;
   int c3;
   B   c4;
-} C;
+} C, *pC;
 
 void t39() {
 // CHECK-LABEL: define void @t39
   __asm mov eax, [eax].A.b
 // CHECK: mov eax, [eax].4
   __asm mov eax, [eax] A.b
 // CHECK: mov eax, [eax] .4
+  __asm mov eax, [eax] pA.b
+// CHECK: mov eax, [eax] .4
   __asm mov eax, fs:[0] A.b
 // CHECK: mov eax, fs:[$$0] .4
   __asm mov eax, [eax].B.b2.a
@@ -557,6 +559,8 @@
 // CHECK: mov eax, fs:[$$0] .8
   __asm mov eax, [eax]C.c4.b2.b
 // CHECK: mov eax, [eax].24
+  __asm mov eax, [eax]pC.c4.b2.b
+// CHECK: mov eax, [eax].24
 // CHECK: "~{eax},~{dirflag},~{fpsr},~{flags}"()
 }
 
Index: test/CodeGen/ms-inline-asm.cpp
===
--- test/CodeGen/ms-inline-asm.cpp
+++ test/CodeGen/ms-inline-asm.cpp
@@ -180,3 +180,19 @@
   A::g();
 }
 
+void t9() {
+  // CHECK-LABEL: define void @_Z2t9v()
+  struct A {
+int a;
+int b;
+void g() {
+  __asm mov eax, dword ptr [eax]this.b
+  // CHECK: call void asm sideeffect inteldialect
+  // CHECK-SAME: mov eax, dword ptr [eax].4
+  // CHECK-SAME: "~{eax},~{dirflag},~{fpsr},~{flags}"()
+}
+  };
+  A AA;
+  AA.g();
+}
+
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits