[PATCH] D25204: Register Calling Convention, Clang changes

2016-11-02 Thread Erich Keane via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL285849: regcall: Implement regcall Calling Conv in clang 
(authored by erichkeane).

Changed prior to commit:
  https://reviews.llvm.org/D25204?vs=76717&id=76755#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D25204

Files:
  cfe/trunk/include/clang-c/Index.h
  cfe/trunk/include/clang/AST/Type.h
  cfe/trunk/include/clang/Basic/Attr.td
  cfe/trunk/include/clang/Basic/AttrDocs.td
  cfe/trunk/include/clang/Basic/Specifiers.h
  cfe/trunk/include/clang/Basic/TokenKinds.def
  cfe/trunk/lib/AST/Expr.cpp
  cfe/trunk/lib/AST/ItaniumMangle.cpp
  cfe/trunk/lib/AST/Mangle.cpp
  cfe/trunk/lib/AST/MicrosoftMangle.cpp
  cfe/trunk/lib/AST/Type.cpp
  cfe/trunk/lib/AST/TypePrinter.cpp
  cfe/trunk/lib/Basic/Targets.cpp
  cfe/trunk/lib/CodeGen/CGCall.cpp
  cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
  cfe/trunk/lib/CodeGen/CodeGenModule.cpp
  cfe/trunk/lib/CodeGen/TargetInfo.cpp
  cfe/trunk/lib/Parse/ParseDecl.cpp
  cfe/trunk/lib/Parse/ParseTentative.cpp
  cfe/trunk/lib/Sema/SemaDeclAttr.cpp
  cfe/trunk/lib/Sema/SemaType.cpp
  cfe/trunk/test/CodeGen/regcall.c
  cfe/trunk/test/CodeGenCXX/regcall.cpp
  cfe/trunk/tools/libclang/CXType.cpp

Index: cfe/trunk/lib/Parse/ParseDecl.cpp
===
--- cfe/trunk/lib/Parse/ParseDecl.cpp
+++ cfe/trunk/lib/Parse/ParseDecl.cpp
@@ -605,6 +605,7 @@
 case tok::kw___fastcall:
 case tok::kw___stdcall:
 case tok::kw___thiscall:
+case tok::kw___regcall:
 case tok::kw___cdecl:
 case tok::kw___vectorcall:
 case tok::kw___ptr64:
@@ -3137,6 +3138,7 @@
 case tok::kw___stdcall:
 case tok::kw___fastcall:
 case tok::kw___thiscall:
+case tok::kw___regcall:
 case tok::kw___vectorcall:
   ParseMicrosoftTypeAttributes(DS.getAttributes());
   continue;
@@ -4454,6 +4456,7 @@
   case tok::kw___stdcall:
   case tok::kw___fastcall:
   case tok::kw___thiscall:
+  case tok::kw___regcall:
   case tok::kw___vectorcall:
   case tok::kw___w64:
   case tok::kw___ptr64:
@@ -4638,6 +4641,7 @@
   case tok::kw___stdcall:
   case tok::kw___fastcall:
   case tok::kw___thiscall:
+  case tok::kw___regcall:
   case tok::kw___vectorcall:
   case tok::kw___w64:
   case tok::kw___sptr:
@@ -4876,6 +4880,7 @@
 case tok::kw___stdcall:
 case tok::kw___fastcall:
 case tok::kw___thiscall:
+case tok::kw___regcall:
 case tok::kw___vectorcall:
   if (AttrReqs & AR_DeclspecAttributesParsed) {
 ParseMicrosoftTypeAttributes(DS.getAttributes());
Index: cfe/trunk/lib/Parse/ParseTentative.cpp
===
--- cfe/trunk/lib/Parse/ParseTentative.cpp
+++ cfe/trunk/lib/Parse/ParseTentative.cpp
@@ -909,7 +909,7 @@
   // '(' abstract-declarator ')'
   if (Tok.isOneOf(tok::kw___attribute, tok::kw___declspec, tok::kw___cdecl,
   tok::kw___stdcall, tok::kw___fastcall, tok::kw___thiscall,
-  tok::kw___vectorcall))
+  tok::kw___regcall, tok::kw___vectorcall))
 return TPResult::True; // attributes indicate declaration
   TPResult TPR = TryParseDeclarator(mayBeAbstract, mayHaveIdentifier);
   if (TPR != TPResult::Ambiguous)
@@ -1058,6 +1058,7 @@
   case tok::kw___stdcall:
   case tok::kw___fastcall:
   case tok::kw___thiscall:
+  case tok::kw___regcall:
   case tok::kw___vectorcall:
   case tok::kw___unaligned:
   case tok::kw___vector:
@@ -1351,6 +1352,7 @@
   case tok::kw___stdcall:
   case tok::kw___fastcall:
   case tok::kw___thiscall:
+  case tok::kw___regcall:
   case tok::kw___vectorcall:
   case tok::kw___w64:
   case tok::kw___sptr:
Index: cfe/trunk/lib/CodeGen/CGCall.cpp
===
--- cfe/trunk/lib/CodeGen/CGCall.cpp
+++ cfe/trunk/lib/CodeGen/CGCall.cpp
@@ -48,6 +48,7 @@
   default: return llvm::CallingConv::C;
   case CC_X86StdCall: return llvm::CallingConv::X86_StdCall;
   case CC_X86FastCall: return llvm::CallingConv::X86_FastCall;
+  case CC_X86RegCall: return llvm::CallingConv::X86_RegCall;
   case CC_X86ThisCall: return llvm::CallingConv::X86_ThisCall;
   case CC_X86_64Win64: return llvm::CallingConv::X86_64_Win64;
   case CC_X86_64SysV: return llvm::CallingConv::X86_64_SysV;
@@ -173,6 +174,9 @@
   if (D->hasAttr())
 return CC_X86FastCall;
 
+  if (D->hasAttr())
+return CC_X86RegCall;
+
   if (D->hasAttr())
 return CC_X86ThisCall;
 
Index: cfe/trunk/lib/CodeGen/TargetInfo.cpp
===
--- cfe/trunk/lib/CodeGen/TargetInfo.cpp
+++ cfe/trunk/lib/CodeGen/TargetInfo.cpp
@@ -1229,7 +1229,8 @@
 
   const Type *Base = nullptr;
   uint64_t NumElts = 0;
-  if (State.CC == llvm::CallingConv::X86_VectorCall &&
+  if ((State.CC == llvm::CallingConv::X86_VectorCall ||
+   State.CC == llvm::CallingConv::X86_RegCall) &&
   isHomogeneousAggregate(RetTy, Bas

[PATCH] D25204: Register Calling Convention, Clang changes

2016-11-02 Thread Reid Kleckner via cfe-commits
rnk accepted this revision.
rnk added a reviewer: rnk.
rnk added a comment.
This revision is now accepted and ready to land.

Looks good to me.


https://reviews.llvm.org/D25204



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


[PATCH] D25204: Register Calling Convention, Clang changes

2016-11-02 Thread Erich Keane via cfe-commits
erichkeane updated this revision to Diff 76717.
erichkeane added a comment.

It was brought to my attention that regcall isn't a calling convention that 
should cause MSVC to switch to C++ mangling.  Switched that and updated the 
tests.


https://reviews.llvm.org/D25204

Files:
  include/clang-c/Index.h
  include/clang/AST/Type.h
  include/clang/Basic/Attr.td
  include/clang/Basic/AttrDocs.td
  include/clang/Basic/Specifiers.h
  include/clang/Basic/TokenKinds.def
  lib/AST/Expr.cpp
  lib/AST/ItaniumMangle.cpp
  lib/AST/Mangle.cpp
  lib/AST/MicrosoftMangle.cpp
  lib/AST/Type.cpp
  lib/AST/TypePrinter.cpp
  lib/Basic/Targets.cpp
  lib/CodeGen/CGCall.cpp
  lib/CodeGen/CGDebugInfo.cpp
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/TargetInfo.cpp
  lib/Parse/ParseDecl.cpp
  lib/Parse/ParseTentative.cpp
  lib/Sema/SemaDeclAttr.cpp
  lib/Sema/SemaType.cpp
  test/CodeGen/regcall.c
  test/CodeGenCXX/regcall.cpp
  tools/libclang/CXType.cpp

Index: lib/Parse/ParseDecl.cpp
===
--- lib/Parse/ParseDecl.cpp
+++ lib/Parse/ParseDecl.cpp
@@ -605,6 +605,7 @@
 case tok::kw___fastcall:
 case tok::kw___stdcall:
 case tok::kw___thiscall:
+case tok::kw___regcall:
 case tok::kw___cdecl:
 case tok::kw___vectorcall:
 case tok::kw___ptr64:
@@ -3137,6 +3138,7 @@
 case tok::kw___stdcall:
 case tok::kw___fastcall:
 case tok::kw___thiscall:
+case tok::kw___regcall:
 case tok::kw___vectorcall:
   ParseMicrosoftTypeAttributes(DS.getAttributes());
   continue;
@@ -4454,6 +4456,7 @@
   case tok::kw___stdcall:
   case tok::kw___fastcall:
   case tok::kw___thiscall:
+  case tok::kw___regcall:
   case tok::kw___vectorcall:
   case tok::kw___w64:
   case tok::kw___ptr64:
@@ -4638,6 +4641,7 @@
   case tok::kw___stdcall:
   case tok::kw___fastcall:
   case tok::kw___thiscall:
+  case tok::kw___regcall:
   case tok::kw___vectorcall:
   case tok::kw___w64:
   case tok::kw___sptr:
@@ -4876,6 +4880,7 @@
 case tok::kw___stdcall:
 case tok::kw___fastcall:
 case tok::kw___thiscall:
+case tok::kw___regcall:
 case tok::kw___vectorcall:
   if (AttrReqs & AR_DeclspecAttributesParsed) {
 ParseMicrosoftTypeAttributes(DS.getAttributes());
Index: lib/Parse/ParseTentative.cpp
===
--- lib/Parse/ParseTentative.cpp
+++ lib/Parse/ParseTentative.cpp
@@ -909,7 +909,7 @@
   // '(' abstract-declarator ')'
   if (Tok.isOneOf(tok::kw___attribute, tok::kw___declspec, tok::kw___cdecl,
   tok::kw___stdcall, tok::kw___fastcall, tok::kw___thiscall,
-  tok::kw___vectorcall))
+  tok::kw___regcall, tok::kw___vectorcall))
 return TPResult::True; // attributes indicate declaration
   TPResult TPR = TryParseDeclarator(mayBeAbstract, mayHaveIdentifier);
   if (TPR != TPResult::Ambiguous)
@@ -1058,6 +1058,7 @@
   case tok::kw___stdcall:
   case tok::kw___fastcall:
   case tok::kw___thiscall:
+  case tok::kw___regcall:
   case tok::kw___vectorcall:
   case tok::kw___unaligned:
   case tok::kw___vector:
@@ -1351,6 +1352,7 @@
   case tok::kw___stdcall:
   case tok::kw___fastcall:
   case tok::kw___thiscall:
+  case tok::kw___regcall:
   case tok::kw___vectorcall:
   case tok::kw___w64:
   case tok::kw___sptr:
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -673,7 +673,16 @@
   } else {
 IdentifierInfo *II = ND->getIdentifier();
 assert(II && "Attempt to mangle unnamed decl.");
-Str = II->getName();
+const auto *FD = dyn_cast(ND);
+
+if (FD &&
+FD->getType()->castAs()->getCallConv() == CC_X86RegCall) {
+  llvm::raw_svector_ostream Out(Buffer);
+  Out << "__regcall3__" << II->getName();
+  Str = Out.str();
+} else {
+  Str = II->getName();
+}
   }
 
   // Keep the first result in the case of a mangling collision.
Index: lib/CodeGen/CGCall.cpp
===
--- lib/CodeGen/CGCall.cpp
+++ lib/CodeGen/CGCall.cpp
@@ -48,6 +48,7 @@
   default: return llvm::CallingConv::C;
   case CC_X86StdCall: return llvm::CallingConv::X86_StdCall;
   case CC_X86FastCall: return llvm::CallingConv::X86_FastCall;
+  case CC_X86RegCall: return llvm::CallingConv::X86_RegCall;
   case CC_X86ThisCall: return llvm::CallingConv::X86_ThisCall;
   case CC_X86_64Win64: return llvm::CallingConv::X86_64_Win64;
   case CC_X86_64SysV: return llvm::CallingConv::X86_64_SysV;
@@ -173,6 +174,9 @@
   if (D->hasAttr())
 return CC_X86FastCall;
 
+  if (D->hasAttr())
+return CC_X86RegCall;
+
   if (D->hasAttr())
 return CC_X86ThisCall;
 
Index: lib/CodeGen/CGDebugInfo.cpp
===
--- lib/CodeGen/CGDebugInfo.cpp
+++ lib/CodeGen/CGDebugInfo.

[PATCH] D25204: Register Calling Convention, Clang changes

2016-11-01 Thread Erich Keane via cfe-commits
erichkeane added a comment.

@rnk, @majnemer and @ABataev :  I believe that I've done everything that has 
come up in review, and this passes all tests for the convention I can find.  Do 
you guys see anything that is holding this patch up?  What is otherwise the 
'next step' in getting this into master?


https://reviews.llvm.org/D25204



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


[PATCH] D25204: Register Calling Convention, Clang changes

2016-10-27 Thread Erich Keane via cfe-commits
erichkeane updated this revision to Diff 76117.
erichkeane added a comment.

Remove single-underscore version of _regcall kw.


https://reviews.llvm.org/D25204

Files:
  include/clang-c/Index.h
  include/clang/AST/Type.h
  include/clang/Basic/Attr.td
  include/clang/Basic/AttrDocs.td
  include/clang/Basic/Specifiers.h
  include/clang/Basic/TokenKinds.def
  lib/AST/Expr.cpp
  lib/AST/ItaniumMangle.cpp
  lib/AST/Mangle.cpp
  lib/AST/MicrosoftMangle.cpp
  lib/AST/Type.cpp
  lib/AST/TypePrinter.cpp
  lib/Basic/Targets.cpp
  lib/CodeGen/CGCall.cpp
  lib/CodeGen/CGDebugInfo.cpp
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/TargetInfo.cpp
  lib/Parse/ParseDecl.cpp
  lib/Parse/ParseTentative.cpp
  lib/Sema/SemaDeclAttr.cpp
  lib/Sema/SemaType.cpp
  test/CodeGen/regcall.c
  test/CodeGenCXX/regcall.cpp
  tools/libclang/CXType.cpp

Index: lib/Parse/ParseDecl.cpp
===
--- lib/Parse/ParseDecl.cpp
+++ lib/Parse/ParseDecl.cpp
@@ -605,6 +605,7 @@
 case tok::kw___fastcall:
 case tok::kw___stdcall:
 case tok::kw___thiscall:
+case tok::kw___regcall:
 case tok::kw___cdecl:
 case tok::kw___vectorcall:
 case tok::kw___ptr64:
@@ -3137,6 +3138,7 @@
 case tok::kw___stdcall:
 case tok::kw___fastcall:
 case tok::kw___thiscall:
+case tok::kw___regcall:
 case tok::kw___vectorcall:
   ParseMicrosoftTypeAttributes(DS.getAttributes());
   continue;
@@ -4454,6 +4456,7 @@
   case tok::kw___stdcall:
   case tok::kw___fastcall:
   case tok::kw___thiscall:
+  case tok::kw___regcall:
   case tok::kw___vectorcall:
   case tok::kw___w64:
   case tok::kw___ptr64:
@@ -4638,6 +4641,7 @@
   case tok::kw___stdcall:
   case tok::kw___fastcall:
   case tok::kw___thiscall:
+  case tok::kw___regcall:
   case tok::kw___vectorcall:
   case tok::kw___w64:
   case tok::kw___sptr:
@@ -4876,6 +4880,7 @@
 case tok::kw___stdcall:
 case tok::kw___fastcall:
 case tok::kw___thiscall:
+case tok::kw___regcall:
 case tok::kw___vectorcall:
   if (AttrReqs & AR_DeclspecAttributesParsed) {
 ParseMicrosoftTypeAttributes(DS.getAttributes());
Index: lib/Parse/ParseTentative.cpp
===
--- lib/Parse/ParseTentative.cpp
+++ lib/Parse/ParseTentative.cpp
@@ -909,7 +909,7 @@
   // '(' abstract-declarator ')'
   if (Tok.isOneOf(tok::kw___attribute, tok::kw___declspec, tok::kw___cdecl,
   tok::kw___stdcall, tok::kw___fastcall, tok::kw___thiscall,
-  tok::kw___vectorcall))
+  tok::kw___regcall, tok::kw___vectorcall))
 return TPResult::True; // attributes indicate declaration
   TPResult TPR = TryParseDeclarator(mayBeAbstract, mayHaveIdentifier);
   if (TPR != TPResult::Ambiguous)
@@ -1058,6 +1058,7 @@
   case tok::kw___stdcall:
   case tok::kw___fastcall:
   case tok::kw___thiscall:
+  case tok::kw___regcall:
   case tok::kw___vectorcall:
   case tok::kw___unaligned:
   case tok::kw___vector:
@@ -1351,6 +1352,7 @@
   case tok::kw___stdcall:
   case tok::kw___fastcall:
   case tok::kw___thiscall:
+  case tok::kw___regcall:
   case tok::kw___vectorcall:
   case tok::kw___w64:
   case tok::kw___sptr:
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -673,7 +673,16 @@
   } else {
 IdentifierInfo *II = ND->getIdentifier();
 assert(II && "Attempt to mangle unnamed decl.");
-Str = II->getName();
+const auto *FD = dyn_cast(ND);
+
+if (FD &&
+FD->getType()->castAs()->getCallConv() == CC_X86RegCall) {
+  llvm::raw_svector_ostream Out(Buffer);
+  Out << "__regcall3__" << II->getName();
+  Str = Out.str();
+} else {
+  Str = II->getName();
+}
   }
 
   // Keep the first result in the case of a mangling collision.
Index: lib/CodeGen/CGCall.cpp
===
--- lib/CodeGen/CGCall.cpp
+++ lib/CodeGen/CGCall.cpp
@@ -48,6 +48,7 @@
   default: return llvm::CallingConv::C;
   case CC_X86StdCall: return llvm::CallingConv::X86_StdCall;
   case CC_X86FastCall: return llvm::CallingConv::X86_FastCall;
+  case CC_X86RegCall: return llvm::CallingConv::X86_RegCall;
   case CC_X86ThisCall: return llvm::CallingConv::X86_ThisCall;
   case CC_X86_64Win64: return llvm::CallingConv::X86_64_Win64;
   case CC_X86_64SysV: return llvm::CallingConv::X86_64_SysV;
@@ -173,6 +174,9 @@
   if (D->hasAttr())
 return CC_X86FastCall;
 
+  if (D->hasAttr())
+return CC_X86RegCall;
+
   if (D->hasAttr())
 return CC_X86ThisCall;
 
Index: lib/CodeGen/CGDebugInfo.cpp
===
--- lib/CodeGen/CGDebugInfo.cpp
+++ lib/CodeGen/CGDebugInfo.cpp
@@ -904,6 +904,7 @@
   case CC_Swift:
   case CC_PreserveMost:
   case CC_PreserveAll:
+  case CC_X86RegCall

[PATCH] D25204: Register Calling Convention, Clang changes

2016-10-27 Thread Reid Kleckner via cfe-commits
rnk added a comment.

In https://reviews.llvm.org/D25204#581477, @erichkeane wrote:

> In general, I can see the benefit of this rule, however in the case of 
> calling conventions, I would think that keeping them all orthogonal is 
> important.  Having "most" calling conventions work one way, and a couple a 
> different way seems like a bigger problem.


I agree. I don't think introducing a __regcall keyword is going to cause much 
real world breakage.




Comment at: include/clang/Basic/Attr.td:815
+  let Spellings = [GCC<"regcall">, Keyword<"__regcall">,
+   Keyword<"_regcall">];
+  let Documentation = [RegCallDocs];

Can we not add the single underscore keyword version? That's outside the 
implementer's namespace.


https://reviews.llvm.org/D25204



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


[PATCH] D25204: Register Calling Convention, Clang changes

2016-10-27 Thread Erich Keane via cfe-commits
erichkeane added a comment.

In https://reviews.llvm.org/D25204#581469, @rnk wrote:

> Remember the fight over _Atomic with MSVC's STL? The fallacy of the 
> implementer's namespace is that there is only one implementer.
>  https://llvm.org/bugs/show_bug.cgi?id=19043
>
> We should prefer adding `__attribute__`s and `__declspec`s instead of 
> keywords when possible.


In general, I can see the benefit of this rule, however in the case of calling 
conventions, I would think that keeping them all orthogonal is important.  
Having "most" calling conventions work one way, and a couple a different way 
seems like a bigger problem.


https://reviews.llvm.org/D25204



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


[PATCH] D25204: Register Calling Convention, Clang changes

2016-10-27 Thread Reid Kleckner via cfe-commits
rnk added a comment.

Remember the fight over _Atomic with MSVC's STL? The fallacy of the 
implementer's namespace is that there is only one implementer.
https://llvm.org/bugs/show_bug.cgi?id=19043

We should prefer adding `__attribute__`s and `__declspec`s instead of keywords 
when possible.


https://reviews.llvm.org/D25204



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


[PATCH] D25204: Register Calling Convention, Clang changes

2016-10-27 Thread Joerg Sonnenberger via cfe-commits
joerg added a comment.

The __ namespace is shared between all parts of the implementation, not just 
the compiler. The convention in the past was that compiler keywords will end in 
a __ as well, but calling conventions and Objective C broke that convention. I 
still think it is something that should be avoided when possible.


https://reviews.llvm.org/D25204



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


[PATCH] D25204: Register Calling Convention, Clang changes

2016-10-27 Thread David Majnemer via cfe-commits
majnemer added a comment.

The __ namespace is reserved for us and I can't imagine how __regcall would 
upset any existing code out there.


https://reviews.llvm.org/D25204



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


[PATCH] D25204: Register Calling Convention, Clang changes

2016-10-27 Thread Erich Keane via cfe-commits
erichkeane added a comment.

I guess I'm not sure how to respond to that... Calling conventions 
traditionally use double underscore to prevent from stomping on user keywords.  
Additionally, this is in a specification that has an existing implementation 
available, so I'm not sure what could be done.


https://reviews.llvm.org/D25204



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


[PATCH] D25204: Register Calling Convention, Clang changes

2016-10-26 Thread Joerg Sonnenberger via cfe-commits
joerg added a comment.

Can we please avoid adding more (pseudo) keywords in the double-underscore name 
space? Those tend to be used a lot by existing libc implementations and 
existing attribute cases like __strong and __weak have created enough trouble.


https://reviews.llvm.org/D25204



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


[PATCH] D25204: Register Calling Convention, Clang changes

2016-10-26 Thread Erich Keane via cfe-commits
erichkeane updated this revision to Diff 75919.

https://reviews.llvm.org/D25204

Files:
  include/clang-c/Index.h
  include/clang/AST/Type.h
  include/clang/Basic/Attr.td
  include/clang/Basic/AttrDocs.td
  include/clang/Basic/Specifiers.h
  include/clang/Basic/TokenKinds.def
  lib/AST/Expr.cpp
  lib/AST/ItaniumMangle.cpp
  lib/AST/Mangle.cpp
  lib/AST/MicrosoftMangle.cpp
  lib/AST/Type.cpp
  lib/AST/TypePrinter.cpp
  lib/Basic/Targets.cpp
  lib/CodeGen/CGCall.cpp
  lib/CodeGen/CGDebugInfo.cpp
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/TargetInfo.cpp
  lib/Parse/ParseDecl.cpp
  lib/Parse/ParseTentative.cpp
  lib/Sema/SemaDeclAttr.cpp
  lib/Sema/SemaType.cpp
  test/CodeGen/regcall.c
  test/CodeGenCXX/regcall.cpp
  tools/libclang/CXType.cpp

Index: lib/Parse/ParseDecl.cpp
===
--- lib/Parse/ParseDecl.cpp
+++ lib/Parse/ParseDecl.cpp
@@ -605,6 +605,7 @@
 case tok::kw___fastcall:
 case tok::kw___stdcall:
 case tok::kw___thiscall:
+case tok::kw___regcall:
 case tok::kw___cdecl:
 case tok::kw___vectorcall:
 case tok::kw___ptr64:
@@ -3137,6 +3138,7 @@
 case tok::kw___stdcall:
 case tok::kw___fastcall:
 case tok::kw___thiscall:
+case tok::kw___regcall:
 case tok::kw___vectorcall:
   ParseMicrosoftTypeAttributes(DS.getAttributes());
   continue;
@@ -4454,6 +4456,7 @@
   case tok::kw___stdcall:
   case tok::kw___fastcall:
   case tok::kw___thiscall:
+  case tok::kw___regcall:
   case tok::kw___vectorcall:
   case tok::kw___w64:
   case tok::kw___ptr64:
@@ -4638,6 +4641,7 @@
   case tok::kw___stdcall:
   case tok::kw___fastcall:
   case tok::kw___thiscall:
+  case tok::kw___regcall:
   case tok::kw___vectorcall:
   case tok::kw___w64:
   case tok::kw___sptr:
@@ -4876,6 +4880,7 @@
 case tok::kw___stdcall:
 case tok::kw___fastcall:
 case tok::kw___thiscall:
+case tok::kw___regcall:
 case tok::kw___vectorcall:
   if (AttrReqs & AR_DeclspecAttributesParsed) {
 ParseMicrosoftTypeAttributes(DS.getAttributes());
Index: lib/Parse/ParseTentative.cpp
===
--- lib/Parse/ParseTentative.cpp
+++ lib/Parse/ParseTentative.cpp
@@ -909,7 +909,7 @@
   // '(' abstract-declarator ')'
   if (Tok.isOneOf(tok::kw___attribute, tok::kw___declspec, tok::kw___cdecl,
   tok::kw___stdcall, tok::kw___fastcall, tok::kw___thiscall,
-  tok::kw___vectorcall))
+  tok::kw___regcall, tok::kw___vectorcall))
 return TPResult::True; // attributes indicate declaration
   TPResult TPR = TryParseDeclarator(mayBeAbstract, mayHaveIdentifier);
   if (TPR != TPResult::Ambiguous)
@@ -1058,6 +1058,7 @@
   case tok::kw___stdcall:
   case tok::kw___fastcall:
   case tok::kw___thiscall:
+  case tok::kw___regcall:
   case tok::kw___vectorcall:
   case tok::kw___unaligned:
   case tok::kw___vector:
@@ -1351,6 +1352,7 @@
   case tok::kw___stdcall:
   case tok::kw___fastcall:
   case tok::kw___thiscall:
+  case tok::kw___regcall:
   case tok::kw___vectorcall:
   case tok::kw___w64:
   case tok::kw___sptr:
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -673,7 +673,16 @@
   } else {
 IdentifierInfo *II = ND->getIdentifier();
 assert(II && "Attempt to mangle unnamed decl.");
-Str = II->getName();
+const auto *FD = dyn_cast(ND);
+
+if (FD &&
+FD->getType()->castAs()->getCallConv() == CC_X86RegCall) {
+  llvm::raw_svector_ostream Out(Buffer);
+  Out << "__regcall3__" << II->getName();
+  Str = Out.str();
+} else {
+  Str = II->getName();
+}
   }
 
   // Keep the first result in the case of a mangling collision.
Index: lib/CodeGen/CGCall.cpp
===
--- lib/CodeGen/CGCall.cpp
+++ lib/CodeGen/CGCall.cpp
@@ -48,6 +48,7 @@
   default: return llvm::CallingConv::C;
   case CC_X86StdCall: return llvm::CallingConv::X86_StdCall;
   case CC_X86FastCall: return llvm::CallingConv::X86_FastCall;
+  case CC_X86RegCall: return llvm::CallingConv::X86_RegCall;
   case CC_X86ThisCall: return llvm::CallingConv::X86_ThisCall;
   case CC_X86_64Win64: return llvm::CallingConv::X86_64_Win64;
   case CC_X86_64SysV: return llvm::CallingConv::X86_64_SysV;
@@ -173,6 +174,9 @@
   if (D->hasAttr())
 return CC_X86FastCall;
 
+  if (D->hasAttr())
+return CC_X86RegCall;
+
   if (D->hasAttr())
 return CC_X86ThisCall;
 
Index: lib/CodeGen/CGDebugInfo.cpp
===
--- lib/CodeGen/CGDebugInfo.cpp
+++ lib/CodeGen/CGDebugInfo.cpp
@@ -904,6 +904,7 @@
   case CC_Swift:
   case CC_PreserveMost:
   case CC_PreserveAll:
+  case CC_X86RegCall:
 return 0;
   }
   return 0;
Index: lib/CodeGen/TargetInfo.cpp
==

[PATCH] D25204: Register Calling Convention, Clang changes

2016-10-26 Thread Erich Keane via cfe-commits
erichkeane marked 8 inline comments as done.
erichkeane added a comment.

New diff coming that fixes Reid & David's comments


https://reviews.llvm.org/D25204



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


[PATCH] D25204: Register Calling Convention, Clang changes

2016-10-26 Thread David Majnemer via cfe-commits
majnemer added inline comments.



Comment at: lib/AST/MicrosoftMangle.cpp:433
   Out << Prefix;
+
   mangleName(D);

Please remove this stray newline.



Comment at: lib/CodeGen/TargetInfo.cpp:
+  if (classifyArgumentType(FD->getType(),
+   std::numeric_limits::max(),
+   LocalNeededInt, LocalNeededSSE, true)

I think UINT_MAX is more popular than using `std::numeric_limits` for this 
purpose in LLVM/Clang.



Comment at: lib/CodeGen/TargetInfo.cpp:3337-3338
+NeededInt = NeededSSE = 0;
+return getIndirectReturnResult(Ty);
+  } else {
+NeededInt += LocalNeededInt;

Please avoid else after return: 
http://llvm.org/docs/CodingStandards.html#don-t-use-else-after-a-return


https://reviews.llvm.org/D25204



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


[PATCH] D25204: Register Calling Convention, Clang changes

2016-10-26 Thread Reid Kleckner via cfe-commits
rnk added inline comments.



Comment at: include/clang/Basic/AttrDocs.td:1263
+On x86 targets, this attribute changes the calling convention to
+__regcall convention. This convention aims to pass as many arguments
+as possible in registers. It also tries to utilize registers for the

If you want `__regcall` to appear as a link, you want to put backticks and 
around it and underscore after it, like is done for __fastcall above:
  `__regcall`_



Comment at: include/clang/Basic/AttrDocs.td:1265
+as possible in registers. It also tries to utilize registers for the
+return value whenever it is possible.'
+

I don't think you need this trailing single quote.



Comment at: lib/AST/MicrosoftMangle.cpp:2006
   //  ::= J # __export __fastcall
   //  ::= Q # __vectorcall
   // The 'export' calling conventions are from a bygone era

Update the EBNF comment



Comment at: lib/CodeGen/TargetInfo.cpp:3324
+  for (const auto *FD : RT->getDecl()->fields()) {
+if (FD->getType()->isStructureType()) {
+  if (classifyRegCallStructTypeImpl(FD->getType(), NeededInt, NeededSSE)

This will return false for class fields, which I don't think you want. You 
probably want to do this for record types that aren't unions.



Comment at: lib/CodeGen/TargetInfo.cpp:3396
 
-unsigned neededInt, neededSSE;
-it->info = classifyArgumentType(it->type, freeIntRegs, neededInt,
-neededSSE, IsNamedArg);
+if (IsRegCall && it->type->isStructureType())
+  it->info = classifyRegCallStructType(it->type, NeededInt, NeededSSE);

You probably wanted isRecordType().


https://reviews.llvm.org/D25204



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


[PATCH] D25204: Register Calling Convention, Clang changes

2016-10-26 Thread Erich Keane via cfe-commits
erichkeane added a comment.

After much debate, the architects have agreed to change the "Decoration" 
section to the following.

The next patch does these, so I'm ready for continued review.  Thanks for your 
patience!
-Erich

__regcall Decoration
Names of functions that use __regcall are decorated. This helps avoid improper 
linking with a function using a different calling convention.
The name of a C function is prefixed with __regcalln__. For example, the name 
foo would be decorated as follows: __regcall3__foo. The n part of the 
decoration specifies the version of the __regcall convention in effect (the 
current convention revision number is 3). In a GCC compatibility environment, 
this decoration is also done for a C++ function or template function whose 
function or template name is an identifier (excluding constructors and operator 
functions, for example); this happens before C++ name mangling.
In a Microsoft compatibility environment, C++ name mangling uses the (lower 
case) letter w to encode revision 3 of the __regcall calling convention.


https://reviews.llvm.org/D25204



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


[PATCH] D25204: Register Calling Convention, Clang changes

2016-10-26 Thread Erich Keane via cfe-commits
erichkeane updated this revision to Diff 75903.
erichkeane added a comment.

Corrected Decoration settings to match the soon-to-be-updated spec.


https://reviews.llvm.org/D25204

Files:
  include/clang-c/Index.h
  include/clang/AST/Type.h
  include/clang/Basic/Attr.td
  include/clang/Basic/AttrDocs.td
  include/clang/Basic/Specifiers.h
  include/clang/Basic/TokenKinds.def
  lib/AST/Expr.cpp
  lib/AST/ItaniumMangle.cpp
  lib/AST/Mangle.cpp
  lib/AST/MicrosoftMangle.cpp
  lib/AST/Type.cpp
  lib/AST/TypePrinter.cpp
  lib/Basic/Targets.cpp
  lib/CodeGen/CGCall.cpp
  lib/CodeGen/CGDebugInfo.cpp
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/TargetInfo.cpp
  lib/Parse/ParseDecl.cpp
  lib/Parse/ParseTentative.cpp
  lib/Sema/SemaDeclAttr.cpp
  lib/Sema/SemaType.cpp
  test/CodeGen/regcall.c
  test/CodeGenCXX/regcall.cpp
  tools/libclang/CXType.cpp

Index: lib/Parse/ParseDecl.cpp
===
--- lib/Parse/ParseDecl.cpp
+++ lib/Parse/ParseDecl.cpp
@@ -605,6 +605,7 @@
 case tok::kw___fastcall:
 case tok::kw___stdcall:
 case tok::kw___thiscall:
+case tok::kw___regcall:
 case tok::kw___cdecl:
 case tok::kw___vectorcall:
 case tok::kw___ptr64:
@@ -3137,6 +3138,7 @@
 case tok::kw___stdcall:
 case tok::kw___fastcall:
 case tok::kw___thiscall:
+case tok::kw___regcall:
 case tok::kw___vectorcall:
   ParseMicrosoftTypeAttributes(DS.getAttributes());
   continue;
@@ -4454,6 +4456,7 @@
   case tok::kw___stdcall:
   case tok::kw___fastcall:
   case tok::kw___thiscall:
+  case tok::kw___regcall:
   case tok::kw___vectorcall:
   case tok::kw___w64:
   case tok::kw___ptr64:
@@ -4638,6 +4641,7 @@
   case tok::kw___stdcall:
   case tok::kw___fastcall:
   case tok::kw___thiscall:
+  case tok::kw___regcall:
   case tok::kw___vectorcall:
   case tok::kw___w64:
   case tok::kw___sptr:
@@ -4876,6 +4880,7 @@
 case tok::kw___stdcall:
 case tok::kw___fastcall:
 case tok::kw___thiscall:
+case tok::kw___regcall:
 case tok::kw___vectorcall:
   if (AttrReqs & AR_DeclspecAttributesParsed) {
 ParseMicrosoftTypeAttributes(DS.getAttributes());
Index: lib/Parse/ParseTentative.cpp
===
--- lib/Parse/ParseTentative.cpp
+++ lib/Parse/ParseTentative.cpp
@@ -909,7 +909,7 @@
   // '(' abstract-declarator ')'
   if (Tok.isOneOf(tok::kw___attribute, tok::kw___declspec, tok::kw___cdecl,
   tok::kw___stdcall, tok::kw___fastcall, tok::kw___thiscall,
-  tok::kw___vectorcall))
+  tok::kw___regcall, tok::kw___vectorcall))
 return TPResult::True; // attributes indicate declaration
   TPResult TPR = TryParseDeclarator(mayBeAbstract, mayHaveIdentifier);
   if (TPR != TPResult::Ambiguous)
@@ -1058,6 +1058,7 @@
   case tok::kw___stdcall:
   case tok::kw___fastcall:
   case tok::kw___thiscall:
+  case tok::kw___regcall:
   case tok::kw___vectorcall:
   case tok::kw___unaligned:
   case tok::kw___vector:
@@ -1351,6 +1352,7 @@
   case tok::kw___stdcall:
   case tok::kw___fastcall:
   case tok::kw___thiscall:
+  case tok::kw___regcall:
   case tok::kw___vectorcall:
   case tok::kw___w64:
   case tok::kw___sptr:
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -673,7 +673,16 @@
   } else {
 IdentifierInfo *II = ND->getIdentifier();
 assert(II && "Attempt to mangle unnamed decl.");
-Str = II->getName();
+const auto *FD = dyn_cast(ND);
+
+if (FD &&
+FD->getType()->castAs()->getCallConv() == CC_X86RegCall) {
+  llvm::raw_svector_ostream Out(Buffer);
+  Out << "__regcall3__" << II->getName();
+  Str = Out.str();
+} else {
+  Str = II->getName();
+}
   }
 
   // Keep the first result in the case of a mangling collision.
Index: lib/CodeGen/CGCall.cpp
===
--- lib/CodeGen/CGCall.cpp
+++ lib/CodeGen/CGCall.cpp
@@ -48,6 +48,7 @@
   default: return llvm::CallingConv::C;
   case CC_X86StdCall: return llvm::CallingConv::X86_StdCall;
   case CC_X86FastCall: return llvm::CallingConv::X86_FastCall;
+  case CC_X86RegCall: return llvm::CallingConv::X86_RegCall;
   case CC_X86ThisCall: return llvm::CallingConv::X86_ThisCall;
   case CC_X86_64Win64: return llvm::CallingConv::X86_64_Win64;
   case CC_X86_64SysV: return llvm::CallingConv::X86_64_SysV;
@@ -173,6 +174,9 @@
   if (D->hasAttr())
 return CC_X86FastCall;
 
+  if (D->hasAttr())
+return CC_X86RegCall;
+
   if (D->hasAttr())
 return CC_X86ThisCall;
 
Index: lib/CodeGen/CGDebugInfo.cpp
===
--- lib/CodeGen/CGDebugInfo.cpp
+++ lib/CodeGen/CGDebugInfo.cpp
@@ -904,6 +904,7 @@
   case CC_Swift:
   case CC_PreserveMost:
   case CC_PreserveAll:
+ 

[PATCH] D25204: Register Calling Convention, Clang changes

2016-10-10 Thread Erich Keane via cfe-commits
erichkeane added a comment.

I'm going to need to pump-the-brakes on this for a little bit.  The 
name-decoration work I did here highlighted a number of issues with that 
section of the spec.  We're currently considering rev'ing the spec to properly 
name mangle/decorate when C++ and Microsoft is ready.

In the meantime, the LLVM changes are unaffected.


https://reviews.llvm.org/D25204



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


[PATCH] D25204: Register Calling Convention, Clang changes

2016-10-08 Thread Erich Keane via cfe-commits
erichkeane added a comment.

Quick point i meant to post earlier  Couldn't change ExtInfo size.




Comment at: include/clang/AST/Type.h:1381
 /// regparm and the calling convention.
-unsigned ExtInfo : 9;
+unsigned ExtInfo : 10;
 

ABataev wrote:
> Erich, do you really need this? You don't increase number of required bits 
> anymore, so this code must be restored
After much debugging, I realized that this does NOT store the enum from above, 
it stores the CallingConv from include/clang/Basic/Specifiers.h, which we 
actually HAVE put over 16.  I didn't see anything that we could lose from that 
enum to replace it however.


https://reviews.llvm.org/D25204



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


[PATCH] D25204: Register Calling Convention, Clang changes

2016-10-06 Thread Oren Ben Simhon via cfe-commits
oren_ben_simhon added inline comments.


> erichkeane wrote in AttrDocs.td:1267
> This has changed 2x since I started this project.  Is there a way to get a 
> STABLE link?  I imagine that much of this documentation is filled with broken 
> links (since MSDN breaks them constantly), but don't really want to add to it.

I am not sure if there is a constant link to the latest and greatest. When i 
contacted the documentation team they pointed me to the latest published 
compiler documention version 16

https://reviews.llvm.org/D25204



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


[PATCH] D25204: Register Calling Convention, Clang changes

2016-10-05 Thread Erich Keane via cfe-commits
erichkeane updated this revision to Diff 73716.
erichkeane marked 6 inline comments as done.
erichkeane added a comment.

Updated tests to properly show mangling for C++ types.  Required some fixes.  
Note that the decorating of names doesn't match ICC in non-named functions due 
to a bug in ICC, and the spec is silent about it, so this patch decorates them 
in the way that best fits the spec.


https://reviews.llvm.org/D25204

Files:
  include/clang-c/Index.h
  include/clang/AST/Type.h
  include/clang/Basic/Attr.td
  include/clang/Basic/AttrDocs.td
  include/clang/Basic/Specifiers.h
  include/clang/Basic/TokenKinds.def
  lib/AST/Expr.cpp
  lib/AST/ItaniumMangle.cpp
  lib/AST/Mangle.cpp
  lib/AST/MicrosoftMangle.cpp
  lib/AST/Type.cpp
  lib/AST/TypePrinter.cpp
  lib/Basic/Targets.cpp
  lib/CodeGen/CGCall.cpp
  lib/CodeGen/CGDebugInfo.cpp
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/TargetInfo.cpp
  lib/Parse/ParseDecl.cpp
  lib/Parse/ParseTentative.cpp
  lib/Sema/SemaDeclAttr.cpp
  lib/Sema/SemaType.cpp
  test/CodeGen/regcall.c
  test/CodeGenCXX/regcall.cpp
  tools/libclang/CXType.cpp

Index: lib/Parse/ParseDecl.cpp
===
--- lib/Parse/ParseDecl.cpp
+++ lib/Parse/ParseDecl.cpp
@@ -605,6 +605,7 @@
 case tok::kw___fastcall:
 case tok::kw___stdcall:
 case tok::kw___thiscall:
+case tok::kw___regcall:
 case tok::kw___cdecl:
 case tok::kw___vectorcall:
 case tok::kw___ptr64:
@@ -3137,6 +3138,7 @@
 case tok::kw___stdcall:
 case tok::kw___fastcall:
 case tok::kw___thiscall:
+case tok::kw___regcall:
 case tok::kw___vectorcall:
   ParseMicrosoftTypeAttributes(DS.getAttributes());
   continue;
@@ -4454,6 +4456,7 @@
   case tok::kw___stdcall:
   case tok::kw___fastcall:
   case tok::kw___thiscall:
+  case tok::kw___regcall:
   case tok::kw___vectorcall:
   case tok::kw___w64:
   case tok::kw___ptr64:
@@ -4638,6 +4641,7 @@
   case tok::kw___stdcall:
   case tok::kw___fastcall:
   case tok::kw___thiscall:
+  case tok::kw___regcall:
   case tok::kw___vectorcall:
   case tok::kw___w64:
   case tok::kw___sptr:
@@ -4876,6 +4880,7 @@
 case tok::kw___stdcall:
 case tok::kw___fastcall:
 case tok::kw___thiscall:
+case tok::kw___regcall:
 case tok::kw___vectorcall:
   if (AttrReqs & AR_DeclspecAttributesParsed) {
 ParseMicrosoftTypeAttributes(DS.getAttributes());
Index: lib/Parse/ParseTentative.cpp
===
--- lib/Parse/ParseTentative.cpp
+++ lib/Parse/ParseTentative.cpp
@@ -909,7 +909,7 @@
   // '(' abstract-declarator ')'
   if (Tok.isOneOf(tok::kw___attribute, tok::kw___declspec, tok::kw___cdecl,
   tok::kw___stdcall, tok::kw___fastcall, tok::kw___thiscall,
-  tok::kw___vectorcall))
+  tok::kw___regcall, tok::kw___vectorcall))
 return TPResult::True; // attributes indicate declaration
   TPResult TPR = TryParseDeclarator(mayBeAbstract, mayHaveIdentifier);
   if (TPR != TPResult::Ambiguous)
@@ -1058,6 +1058,7 @@
   case tok::kw___stdcall:
   case tok::kw___fastcall:
   case tok::kw___thiscall:
+  case tok::kw___regcall:
   case tok::kw___vectorcall:
   case tok::kw___unaligned:
   case tok::kw___vector:
@@ -1351,6 +1352,7 @@
   case tok::kw___stdcall:
   case tok::kw___fastcall:
   case tok::kw___thiscall:
+  case tok::kw___regcall:
   case tok::kw___vectorcall:
   case tok::kw___w64:
   case tok::kw___sptr:
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -683,7 +683,16 @@
   } else {
 IdentifierInfo *II = ND->getIdentifier();
 assert(II && "Attempt to mangle unnamed decl.");
-Str = II->getName();
+const auto *FD = dyn_cast(ND);
+
+if (FD &&
+FD->getType()->castAs()->getCallConv() == CC_X86RegCall) {
+  llvm::raw_svector_ostream Out(Buffer);
+  Out << "__regcall3__" << II->getName();
+  Str = Out.str();
+} else {
+  Str = II->getName();
+}
   }
 
   // Keep the first result in the case of a mangling collision.
Index: lib/CodeGen/CGCall.cpp
===
--- lib/CodeGen/CGCall.cpp
+++ lib/CodeGen/CGCall.cpp
@@ -48,6 +48,7 @@
   default: return llvm::CallingConv::C;
   case CC_X86StdCall: return llvm::CallingConv::X86_StdCall;
   case CC_X86FastCall: return llvm::CallingConv::X86_FastCall;
+  case CC_X86RegCall: return llvm::CallingConv::X86_RegCall;
   case CC_X86ThisCall: return llvm::CallingConv::X86_ThisCall;
   case CC_X86_64Win64: return llvm::CallingConv::X86_64_Win64;
   case CC_X86_64SysV: return llvm::CallingConv::X86_64_SysV;
@@ -173,6 +174,9 @@
   if (D->hasAttr())
 return CC_X86FastCall;
 
+  if (D->hasAttr())
+return CC_X86RegCall;
+
   if (D->hasAttr())
 return CC_X86ThisCall;
 
Inde

[PATCH] D25204: Register Calling Convention, Clang changes

2016-10-05 Thread Erich Keane via cfe-commits
erichkeane marked 9 inline comments as done.
erichkeane added inline comments.


> oren_ben_simhon wrote in AttrDocs.td:1267
> You might want to use the following link instead because it is most updated: 
> https://software.intel.com/en-us/node/693069

This has changed 2x since I started this project.  Is there a way to get a 
STABLE link?  I imagine that much of this documentation is filled with broken 
links (since MSDN breaks them constantly), but don't really want to add to it.

> oren_ben_simhon wrote in TargetInfo.cpp:3352
> According to the ABI, there are 12 free int regs for windows and 11 free int 
> regs for non-windows (linux, OSX, etc). Is that taken into account somewhere?

Yes.  There are separate ABIInfo types for windows.

> oren_ben_simhon wrote in TargetInfo.cpp:3732
> Maybe i misinterpret the comment, but AFAIK, RegCall gives us 16 SSE 
> registers for each (return values and passed arguments)

I'd misread that in the spec and Ried corrected my implementation below.  
Updating the comment.

> oren_ben_simhon wrote in regcall.c:26
> I see that expended structures don't get InReg attribute. IMHO, If you know 
> that the value should be saved in register then you InReg attribute should be 
> added.

I am not sure that is the case.  That behavior doesn't happen in vectorcall 
seemingly.

https://reviews.llvm.org/D25204



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


[PATCH] D25204: Register Calling Convention, Clang changes

2016-10-05 Thread Alexey Bataev via cfe-commits
ABataev added inline comments.


> Type.h:1381
>  /// regparm and the calling convention.
> -unsigned ExtInfo : 9;
> +unsigned ExtInfo : 10;
>  

Erich, do you really need this? You don't increase number of required bits 
anymore, so this code must be restored

> Type.h:2909-2921
> +// Feel free to rearrange or add bits, but if you go over 10,
>  // you'll need to adjust both the Bits field below and
>  // Type::FunctionTypeBitfields.
>  
>  //   |  CC  |noreturn|produces|regparm|
> -//   |0 .. 3|   4|5   | 6 .. 8|
> +//   |0 .. 4|   5|6   | 7 .. 9|
>  //

Also, you don't need these changes anymore

> MicrosoftMangle.cpp:434
> +
> +  if (auto FD = dyn_cast(D))
> +if (FD->getType()->castAs()->getCallConv() ==

`auto*`

> CodeGenModule.cpp:686
>  assert(II && "Attempt to mangle unnamed decl.");
> -Str = II->getName();
> +const FunctionDecl *FD = dyn_cast(ND);
> +

`const auto *FD`

> ABataev wrote in TargetInfo.cpp:1546-1548
> Seems to me this code is clang-formatted

I mean, did you try to reformat the whole `return` statement? It looks ugly

> rnk wrote in TargetInfo.cpp:3321
> variable naming

I believe the whole patch must be `clang-tide`d

https://reviews.llvm.org/D25204



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


[PATCH] D25204: Register Calling Convention, Clang changes

2016-10-05 Thread Oren Ben Simhon via cfe-commits
oren_ben_simhon added inline comments.


> AttrDocs.td:1267
> +
> +.. _`__regcall`: https://software.intel.com/en-us/node/512847
> +  }];

You might want to use the following link instead because it is most updated: 
https://software.intel.com/en-us/node/693069

> TargetInfo.cpp:3352
>// Keep track of the number of assigned registers.
> -  unsigned freeIntRegs = 6, freeSSERegs = 8;
> +  unsigned freeIntRegs = IsRegCall ? 11 : 6;
> +  unsigned freeSSERegs = IsRegCall ? 16 : 8;

According to the ABI, there are 12 free int regs for windows and 11 free int 
regs for non-windows (linux, OSX, etc). Is that taken into account somewhere?

> TargetInfo.cpp:3732
> +  } else if (IsRegCall) {
> +// RegCall gives us 16 SSE registers total, return or otherwise.
> +FreeSSERegs = 16;

Maybe i misinterpret the comment, but AFAIK, RegCall gives us 16 SSE registers 
for each (return values and passed arguments)

> regcall.c:26
> +void __regcall v3(int a, struct Small b, int c) {}
> +// Win32: define x86_regcallcc void @"\01__regcall3__v3@12"(i32 inreg %a, 
> i32 %b.0, i32 inreg %c)
> +// Win64: define x86_regcallcc void @"\01__regcall3__v3@24"(i32 %a, i32 
> %b.coerce, i32 %c)

I see that expended structures don't get InReg attribute. IMHO, If you know 
that the value should be saved in register then you InReg attribute should be 
added.

https://reviews.llvm.org/D25204



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


[PATCH] D25204: Register Calling Convention, Clang changes

2016-10-04 Thread Erich Keane via cfe-commits
erichkeane marked 16 inline comments as done.
erichkeane added a comment.

Commenting to save my comments (don't seem to survive a refresh).  Still 
working on non-function mangling.



> rnk wrote in ItaniumMangle.cpp:1203
> What mangling should happen for operator overloads and all other kinds of 
> DeclarationName? Please add tests for these cases

Test cases show that I need to implement these.  Going to quit for the evening, 
but will continue working on this tomorrow.

> majnemer wrote in ItaniumMangle.cpp:1413-1414
> I'd add an overload of `mangleSourceName` which takes a `Twine`. Then the one 
> caller which passes `isRegCall` would merely concat the identifier with 
> __regcall3__. The existing implementation using `IdentifierInfo` would merely 
> pass in `II->getName` for the `Twine`.

I really like this idea, and had most of an implementation, however it seems 
that Twine has no real good way to get its 'length', so it required a temporary 
for the sake of getting the length.  Instead I ended up with Ried's suggestion 
of separate functions for each.

> rnk wrote in TargetInfo.cpp:3742-3743
> 'classify' takes FreeSSERegs by reference and modifies it, so are you sure 
> this is correct? It means if I have this kind of prototype, we won't pass 'd' 
> in registers because we'll consume four registers for the return value:
> 
>   struct HFA { __m128 f[4]; };
>   HFA __regcall f(HFA a, HFA b, HFA c, HFA d) {
> ...
>   }

I added it to the C test, and was convinced that you're right.  Fixed, thanks!

https://reviews.llvm.org/D25204



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


[PATCH] D25204: Register Calling Convention, Clang changes

2016-10-04 Thread David Majnemer via cfe-commits
majnemer added inline comments.


> ItaniumMangle.cpp:1234
>  
> -  mangleSourceName(II);
> +  auto FD = dyn_cast(ND);
> +  bool isRegCall = (FD != nullptr) &&

`auto *`

> ItaniumMangle.cpp:1235
> +  auto FD = dyn_cast(ND);
> +  bool isRegCall = (FD != nullptr) &&
> +FD->getType()->castAs()->getCallConv() ==

The convention is to just do `FD` instead of `(FD != nullptr)`

https://reviews.llvm.org/D25204



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


[PATCH] D25204: Register Calling Convention, Clang changes

2016-10-04 Thread David Majnemer via cfe-commits
majnemer added inline comments.


> ItaniumMangle.cpp:1413-1414
>  
> -void CXXNameMangler::mangleSourceName(const IdentifierInfo *II) {
> -  //  ::=  
> +void CXXNameMangler::mangleSourceName(const IdentifierInfo *II,
> +  bool isRegCall) {
> +  //  ::=  [__regcall3__] 

I'd add an overload of `mangleSourceName` which takes a `Twine`. Then the one 
caller which passes `isRegCall` would merely concat the identifier with 
__regcall3__. The existing implementation using `IdentifierInfo` would merely 
pass in `II->getName` for the `Twine`.

https://reviews.llvm.org/D25204



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


[PATCH] D25204: Register Calling Convention, Clang changes

2016-10-04 Thread Reid Kleckner via cfe-commits
rnk added inline comments.


> erichkeane wrote in ItaniumMangle.cpp:1236-1237
> Right, good catch.  I looked at Mangle.cpp which does something very similar, 
> and assumes that FunctionType is a valid cast here, so I've switched this 
> here too, please let me know if that is a wrong assumption.

IMO this would be simpler if we did:

  if (IsRegCall)
mangleRegCallName(II); // implement this elsewhere
  else
mangleSourceName(II);

I don't like that the standard mangleSourceName as you have it has to be 
concerned with IsRegCall. Without your change, it is a simple function that 
clearly expresses that the basic unit of Itanium name mangling is decimal 
length prefixed strings.

> ItaniumMangle.cpp:1203
>switch (Name.getNameKind()) {
>case DeclarationName::Identifier: {
>  const IdentifierInfo *II = Name.getAsIdentifierInfo();

What mangling should happen for operator overloads and all other kinds of 
DeclarationName? Please add tests for these cases

> TargetInfo.cpp:1954
> +  ABIArgInfo classifyRegCallStructTypeImpl(QualType Ty, 
> +   unsigned &neededInt, 
> +   unsigned &neededSSE) const;

format

> TargetInfo.cpp:3297
> +ABIArgInfo X86_64ABIInfo::classifyRegCallStructTypeImpl(
> +  QualType Ty, unsigned &neededInt, unsigned &neededSSE) const {
> +  auto RT = Ty->getAs();

Please name variables in LLVM style

> TargetInfo.cpp:3321
> +} else {
> +  unsigned localNeededInt, localNeededSSE;
> +  if (classifyArgumentType(FD->getType(), 
> std::numeric_limits::max(),

variable naming

> TargetInfo.cpp:3352-3354
> +  unsigned freeIntRegs = IsRegCall ? 11 : 6;
> +  unsigned freeSSERegs = IsRegCall ? 16 : 8;
> +  unsigned neededInt, neededSSE;

Since you're touching most of this, can you make this code standardize on 
LLVM's variable naming convention: 
http://llvm.org/docs/CodingStandards.html#name-types-functions-variables-and-enumerators-properly

> erichkeane wrote in TargetInfo.cpp:3306
> Hmmm... I'm not sure what behavior would be expected in that case.  Also, I 
> just looked at a bunch of similar 'for' loops for various other reasons, and 
> I don't really see where that is tested elsewhere (so I don't really see how 
> to, besides I.isVirtual?).  In that case, I would suspect that the class is 
> not put into a register?

You don't need to check if each base is dynamic, just check 
CXXRD->isDynamicClass() and make it return indirectly if so.

https://reviews.llvm.org/D25204



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


[PATCH] D25204: Register Calling Convention, Clang changes

2016-10-04 Thread Erich Keane via cfe-commits
erichkeane added inline comments.


> rnk wrote in TargetInfo.cpp:3742-3743
> But, if the return value is returned directly, it doesn't conflict with the 
> free parameter registers. In my example, the return value can use XMM0-3 and 
> the parameters can use XMM0-15. Can you add this test case and validate that 
> it does what you want?

Ah, I see what you mean now.  That definitely sounds like the right way to go 
about it.  I'll add a test and validate my assumptions.  Thanks for putting up 
with my misunderstanding.

https://reviews.llvm.org/D25204



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


[PATCH] D25204: Register Calling Convention, Clang changes

2016-10-04 Thread Reid Kleckner via cfe-commits
rnk added inline comments.


> erichkeane wrote in TargetInfo.cpp:3742-3743
> That was my intent, this should allow return values to be in registers as 
> well if I'm reading the spec correctly.  The idea is that register use is 
> 'greedy'.

But, if the return value is returned directly, it doesn't conflict with the 
free parameter registers. In my example, the return value can use XMM0-3 and 
the parameters can use XMM0-15. Can you add this test case and validate that it 
does what you want?

https://reviews.llvm.org/D25204



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


[PATCH] D25204: Register Calling Convention, Clang changes

2016-10-04 Thread Erich Keane via cfe-commits
erichkeane updated this revision to Diff 73507.
erichkeane marked an inline comment as done.
erichkeane added a comment.
Herald added a subscriber: dschuff.

Fixes based on Alexey/Ried's feedback


https://reviews.llvm.org/D25204

Files:
  include/clang-c/Index.h
  include/clang/AST/Type.h
  include/clang/Basic/Attr.td
  include/clang/Basic/AttrDocs.td
  include/clang/Basic/Specifiers.h
  include/clang/Basic/TokenKinds.def
  lib/AST/Expr.cpp
  lib/AST/ItaniumMangle.cpp
  lib/AST/Mangle.cpp
  lib/AST/MicrosoftMangle.cpp
  lib/AST/Type.cpp
  lib/AST/TypePrinter.cpp
  lib/Basic/Targets.cpp
  lib/CodeGen/CGCall.cpp
  lib/CodeGen/CGDebugInfo.cpp
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/TargetInfo.cpp
  lib/Parse/ParseDecl.cpp
  lib/Parse/ParseTentative.cpp
  lib/Sema/SemaDeclAttr.cpp
  lib/Sema/SemaType.cpp
  test/CodeGen/regcall.c
  test/CodeGenCXX/regcall.cpp
  tools/libclang/CXType.cpp

Index: lib/Parse/ParseDecl.cpp
===
--- lib/Parse/ParseDecl.cpp
+++ lib/Parse/ParseDecl.cpp
@@ -605,6 +605,7 @@
 case tok::kw___fastcall:
 case tok::kw___stdcall:
 case tok::kw___thiscall:
+case tok::kw___regcall:
 case tok::kw___cdecl:
 case tok::kw___vectorcall:
 case tok::kw___ptr64:
@@ -3137,6 +3138,7 @@
 case tok::kw___stdcall:
 case tok::kw___fastcall:
 case tok::kw___thiscall:
+case tok::kw___regcall:
 case tok::kw___vectorcall:
   ParseMicrosoftTypeAttributes(DS.getAttributes());
   continue;
@@ -4454,6 +4456,7 @@
   case tok::kw___stdcall:
   case tok::kw___fastcall:
   case tok::kw___thiscall:
+  case tok::kw___regcall:
   case tok::kw___vectorcall:
   case tok::kw___w64:
   case tok::kw___ptr64:
@@ -4638,6 +4641,7 @@
   case tok::kw___stdcall:
   case tok::kw___fastcall:
   case tok::kw___thiscall:
+  case tok::kw___regcall:
   case tok::kw___vectorcall:
   case tok::kw___w64:
   case tok::kw___sptr:
@@ -4876,6 +4880,7 @@
 case tok::kw___stdcall:
 case tok::kw___fastcall:
 case tok::kw___thiscall:
+case tok::kw___regcall:
 case tok::kw___vectorcall:
   if (AttrReqs & AR_DeclspecAttributesParsed) {
 ParseMicrosoftTypeAttributes(DS.getAttributes());
Index: lib/Parse/ParseTentative.cpp
===
--- lib/Parse/ParseTentative.cpp
+++ lib/Parse/ParseTentative.cpp
@@ -909,7 +909,7 @@
   // '(' abstract-declarator ')'
   if (Tok.isOneOf(tok::kw___attribute, tok::kw___declspec, tok::kw___cdecl,
   tok::kw___stdcall, tok::kw___fastcall, tok::kw___thiscall,
-  tok::kw___vectorcall))
+  tok::kw___regcall, tok::kw___vectorcall))
 return TPResult::True; // attributes indicate declaration
   TPResult TPR = TryParseDeclarator(mayBeAbstract, mayHaveIdentifier);
   if (TPR != TPResult::Ambiguous)
@@ -1058,6 +1058,7 @@
   case tok::kw___stdcall:
   case tok::kw___fastcall:
   case tok::kw___thiscall:
+  case tok::kw___regcall:
   case tok::kw___vectorcall:
   case tok::kw___unaligned:
   case tok::kw___vector:
@@ -1351,6 +1352,7 @@
   case tok::kw___stdcall:
   case tok::kw___fastcall:
   case tok::kw___thiscall:
+  case tok::kw___regcall:
   case tok::kw___vectorcall:
   case tok::kw___w64:
   case tok::kw___sptr:
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -683,7 +683,15 @@
   } else {
 IdentifierInfo *II = ND->getIdentifier();
 assert(II && "Attempt to mangle unnamed decl.");
-Str = II->getName();
+const FunctionDecl *FD = dyn_cast(ND);
+
+if (FD && FD->getType()->castAs()->getCallConv() == CC_X86RegCall) {
+  llvm::raw_svector_ostream Out(Buffer);
+  Out << "__regcall3__" << II->getName();
+  Str = Out.str();
+} else {
+  Str = II->getName();
+}
   }
 
   // Keep the first result in the case of a mangling collision.
Index: lib/CodeGen/CGCall.cpp
===
--- lib/CodeGen/CGCall.cpp
+++ lib/CodeGen/CGCall.cpp
@@ -48,6 +48,7 @@
   default: return llvm::CallingConv::C;
   case CC_X86StdCall: return llvm::CallingConv::X86_StdCall;
   case CC_X86FastCall: return llvm::CallingConv::X86_FastCall;
+  case CC_X86RegCall: return llvm::CallingConv::X86_RegCall;
   case CC_X86ThisCall: return llvm::CallingConv::X86_ThisCall;
   case CC_X86_64Win64: return llvm::CallingConv::X86_64_Win64;
   case CC_X86_64SysV: return llvm::CallingConv::X86_64_SysV;
@@ -173,6 +174,9 @@
   if (D->hasAttr())
 return CC_X86FastCall;
 
+  if (D->hasAttr())
+return CC_X86RegCall;
+
   if (D->hasAttr())
 return CC_X86ThisCall;
 
Index: lib/CodeGen/CGDebugInfo.cpp
===
--- lib/CodeGen/CGDebugInfo.cpp
+++ lib/CodeGen/CGDebugInfo.cpp
@@ -893,6 +893,7 @@
   case CC_Swift:
 

[PATCH] D25204: Register Calling Convention, Clang changes

2016-10-04 Thread Erich Keane via cfe-commits
erichkeane marked 11 inline comments as done.
erichkeane added a comment.

New patch incoming.



> ABataev wrote in ItaniumMangle.cpp:1236-1237
> What if function type is not a FunctionProtoType?

Right, good catch.  I looked at Mangle.cpp which does something very similar, 
and assumes that FunctionType is a valid cast here, so I've switched this here 
too, please let me know if that is a wrong assumption.

> rnk wrote in TargetInfo.cpp:3306
> You might want to defend against dynamic C++ records which will have vtable 
> fields.

Hmmm... I'm not sure what behavior would be expected in that case.  Also, I 
just looked at a bunch of similar 'for' loops for various other reasons, and I 
don't really see where that is tested elsewhere (so I don't really see how to, 
besides I.isVirtual?).  In that case, I would suspect that the class is not put 
into a register?

> rnk wrote in TargetInfo.cpp:3742-3743
> 'classify' takes FreeSSERegs by reference and modifies it, so are you sure 
> this is correct? It means if I have this kind of prototype, we won't pass 'd' 
> in registers because we'll consume four registers for the return value:
> 
>   struct HFA { __m128 f[4]; };
>   HFA __regcall f(HFA a, HFA b, HFA c, HFA d) {
> ...
>   }

That was my intent, this should allow return values to be in registers as well 
if I'm reading the spec correctly.  The idea is that register use is 'greedy'.

> rnk wrote in SemaDecl.cpp:8288
> The comment doesn't apply here. Are you sure you don't want some other 
> behavior, like unprototyped functions are actually implicitly void when 
> regcall is used, as in C++?

I suspect you're right.  I am not sure what behavior would be expected, so I 
think that reverting to the error case is likely the correct "safe" behavior if 
the spec doesn't say otherwise?

https://reviews.llvm.org/D25204



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


[PATCH] D25204: Register Calling Convention, Clang changes

2016-10-04 Thread Reid Kleckner via cfe-commits
rnk added inline comments.


> AttrDocs.td:1263
> +On x86 targets, this attribute changes the calling convention to
> +__regcall convention. This convention aimes to pass as many arguments
> +as possible in registers. It also tries to utilize registers for the

"aims"

> TargetInfo.cpp:3306
> +  // Sum up bases
> +  if (auto CXXRD = dyn_cast(RT->getDecl()))
> +for (const auto &I : CXXRD->bases())

You might want to defend against dynamic C++ records which will have vtable 
fields.

> TargetInfo.cpp:3323
> +  unsigned localNeededInt, localNeededSSE;
> +  if (classifyArgumentType(FD->getType(), 
> (std::numeric_limits::max)(),
> +localNeededInt, localNeededSSE, 
> true).isIndirect()) {

This code doesn't need to worry about windows.h defining max.

> TargetInfo.cpp:3388-3389
>  
> -unsigned neededInt, neededSSE;
> -it->info = classifyArgumentType(it->type, freeIntRegs, neededInt,
> +if (IsRegCall && it->type->isStructureType())
> +{
> +  it->info = classifyRegCallStructType(it->type, neededInt, neededSSE);

not llvm style

> TargetInfo.cpp:3742-3743
>  
> -  // We can use up to 6 SSE register parameters with vectorcall.
> -  FreeSSERegs = IsVectorCall ? 6 : 0;
> +  // Regcall doesn't differentiate between return and parameter registers,
> +  // and non Reg/Vector call was 0 anyway.
> +  if (IsVectorCall) {

'classify' takes FreeSSERegs by reference and modifies it, so are you sure this 
is correct? It means if I have this kind of prototype, we won't pass 'd' in 
registers because we'll consume four registers for the return value:

  struct HFA { __m128 f[4]; };
  HFA __regcall f(HFA a, HFA b, HFA c, HFA d) {
...
  }

> SemaDecl.cpp:8288
>  int DiagID =
> -CC == CC_X86StdCall ? diag::warn_cconv_knr : diag::err_cconv_knr;
> +(CC == CC_X86StdCall || CC == CC_X86RegCall) ? 
> diag::warn_cconv_knr : diag::err_cconv_knr;
>  Diag(NewFD->getLocation(), DiagID)

The comment doesn't apply here. Are you sure you don't want some other 
behavior, like unprototyped functions are actually implicitly void when regcall 
is used, as in C++?

https://reviews.llvm.org/D25204



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


[PATCH] D25204: Register Calling Convention, Clang changes

2016-10-04 Thread Alexey Bataev via cfe-commits
ABataev added inline comments.


> Index.h:3029
>CXCallingConv_PreserveAll = 15,
> +  CXCallingConv_X86RegCall = 16,
>  

Maybe it is better to use 8, as the previous comment allows it?

  /* Value 8 was PnaclCall, but it was never used, so it could safely be 
re-used. */

In this case you don't need to increase number of bits used for calling 
conventions

> ItaniumMangle.cpp:1236-1237
> +  bool isRegCall = (FD != nullptr) &&
> +FD->getType()->castAs()->getCallConv() ==
> +  clang::CC_X86RegCall;
> +

What if function type is not a FunctionProtoType?

> MicrosoftMangle.cpp:435-436
> +  if (auto FD = dyn_cast(D))
> +if (FD->getType()->castAs()->getCallConv() ==
> +clang::CC_X86RegCall)
> +  Out << "__regcall3__";

Again, what if type is not FunctionProtoType?

> TargetInfo.cpp:1546-1548
>State.CC == llvm::CallingConv::X86_FastCall ||
> -  State.CC == llvm::CallingConv::X86_VectorCall,
> +  State.CC == llvm::CallingConv::X86_VectorCall || 
> +  State.CC == llvm::CallingConv::X86_RegCall,

Seems to me this code is clang-formatted

> TargetInfo.cpp:3301-3303
> +  if (RT->getDecl()->hasFlexibleArrayMember()) {
> +return getIndirectReturnResult(Ty);
> +  }

No braces

> TargetInfo.cpp:3388-3392
> +if (IsRegCall && it->type->isStructureType())
> +{
> +  it->info = classifyRegCallStructType(it->type, neededInt, neededSSE);
> +}
> +else

Not clang-formatted and extra braces

> SemaDecl.cpp:8288
>  int DiagID =
> -CC == CC_X86StdCall ? diag::warn_cconv_knr : diag::err_cconv_knr;
> +(CC == CC_X86StdCall || CC == CC_X86RegCall) ? 
> diag::warn_cconv_knr : diag::err_cconv_knr;
>  Diag(NewFD->getLocation(), DiagID)

Is this formatted?

> SemaDeclAttr.cpp:3833-3837
> +  case AttributeList::AT_RegCall:
> +D->addAttr(::new (S.Context)
> +  RegCallAttr(Attr.getRange(), S.Context,
> +  Attr.getAttributeSpellingListIndex()));
> +return;

Not formatted

https://reviews.llvm.org/D25204



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


[PATCH] D25204: Register Calling Convention, Clang changes

2016-10-04 Thread Erich Keane via cfe-commits
erichkeane updated this revision to Diff 73490.
erichkeane added a comment.

Did a full context diff, as requested.


https://reviews.llvm.org/D25204

Files:
  include/clang-c/Index.h
  include/clang/AST/Type.h
  include/clang/Basic/Attr.td
  include/clang/Basic/AttrDocs.td
  include/clang/Basic/Specifiers.h
  include/clang/Basic/TokenKinds.def
  lib/AST/Expr.cpp
  lib/AST/ItaniumMangle.cpp
  lib/AST/Mangle.cpp
  lib/AST/MicrosoftMangle.cpp
  lib/AST/Type.cpp
  lib/AST/TypePrinter.cpp
  lib/Basic/Targets.cpp
  lib/CodeGen/CGCall.cpp
  lib/CodeGen/CGDebugInfo.cpp
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/TargetInfo.cpp
  lib/Parse/ParseDecl.cpp
  lib/Parse/ParseTentative.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaDeclAttr.cpp
  lib/Sema/SemaType.cpp
  test/CodeGen/regcall.c
  test/CodeGenCXX/regcall.cpp
  tools/libclang/CXType.cpp

Index: lib/Parse/ParseDecl.cpp
===
--- lib/Parse/ParseDecl.cpp
+++ lib/Parse/ParseDecl.cpp
@@ -605,6 +605,7 @@
 case tok::kw___fastcall:
 case tok::kw___stdcall:
 case tok::kw___thiscall:
+case tok::kw___regcall:
 case tok::kw___cdecl:
 case tok::kw___vectorcall:
 case tok::kw___ptr64:
@@ -3137,6 +3138,7 @@
 case tok::kw___stdcall:
 case tok::kw___fastcall:
 case tok::kw___thiscall:
+case tok::kw___regcall:
 case tok::kw___vectorcall:
   ParseMicrosoftTypeAttributes(DS.getAttributes());
   continue;
@@ -4454,6 +4456,7 @@
   case tok::kw___stdcall:
   case tok::kw___fastcall:
   case tok::kw___thiscall:
+  case tok::kw___regcall:
   case tok::kw___vectorcall:
   case tok::kw___w64:
   case tok::kw___ptr64:
@@ -4638,6 +4641,7 @@
   case tok::kw___stdcall:
   case tok::kw___fastcall:
   case tok::kw___thiscall:
+  case tok::kw___regcall:
   case tok::kw___vectorcall:
   case tok::kw___w64:
   case tok::kw___sptr:
@@ -4876,6 +4880,7 @@
 case tok::kw___stdcall:
 case tok::kw___fastcall:
 case tok::kw___thiscall:
+case tok::kw___regcall:
 case tok::kw___vectorcall:
   if (AttrReqs & AR_DeclspecAttributesParsed) {
 ParseMicrosoftTypeAttributes(DS.getAttributes());
Index: lib/Parse/ParseTentative.cpp
===
--- lib/Parse/ParseTentative.cpp
+++ lib/Parse/ParseTentative.cpp
@@ -909,7 +909,7 @@
   // '(' abstract-declarator ')'
   if (Tok.isOneOf(tok::kw___attribute, tok::kw___declspec, tok::kw___cdecl,
   tok::kw___stdcall, tok::kw___fastcall, tok::kw___thiscall,
-  tok::kw___vectorcall))
+  tok::kw___regcall, tok::kw___vectorcall))
 return TPResult::True; // attributes indicate declaration
   TPResult TPR = TryParseDeclarator(mayBeAbstract, mayHaveIdentifier);
   if (TPR != TPResult::Ambiguous)
@@ -1058,6 +1058,7 @@
   case tok::kw___stdcall:
   case tok::kw___fastcall:
   case tok::kw___thiscall:
+  case tok::kw___regcall:
   case tok::kw___vectorcall:
   case tok::kw___unaligned:
   case tok::kw___vector:
@@ -1351,6 +1352,7 @@
   case tok::kw___stdcall:
   case tok::kw___fastcall:
   case tok::kw___thiscall:
+  case tok::kw___regcall:
   case tok::kw___vectorcall:
   case tok::kw___w64:
   case tok::kw___sptr:
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -683,7 +683,15 @@
   } else {
 IdentifierInfo *II = ND->getIdentifier();
 assert(II && "Attempt to mangle unnamed decl.");
-Str = II->getName();
+const FunctionDecl *FD = dyn_cast(ND);
+
+if (FD && FD->getType()->castAs()->getCallConv() == CC_X86RegCall) {
+  llvm::raw_svector_ostream Out(Buffer);
+  Out << "__regcall3__" << II->getName();
+  Str = Out.str();
+} else {
+  Str = II->getName();
+}
   }
 
   // Keep the first result in the case of a mangling collision.
Index: lib/CodeGen/CGCall.cpp
===
--- lib/CodeGen/CGCall.cpp
+++ lib/CodeGen/CGCall.cpp
@@ -48,6 +48,7 @@
   default: return llvm::CallingConv::C;
   case CC_X86StdCall: return llvm::CallingConv::X86_StdCall;
   case CC_X86FastCall: return llvm::CallingConv::X86_FastCall;
+  case CC_X86RegCall: return llvm::CallingConv::X86_RegCall;
   case CC_X86ThisCall: return llvm::CallingConv::X86_ThisCall;
   case CC_X86_64Win64: return llvm::CallingConv::X86_64_Win64;
   case CC_X86_64SysV: return llvm::CallingConv::X86_64_SysV;
@@ -173,6 +174,9 @@
   if (D->hasAttr())
 return CC_X86FastCall;
 
+  if (D->hasAttr())
+return CC_X86RegCall;
+
   if (D->hasAttr())
 return CC_X86ThisCall;
 
Index: lib/CodeGen/CGDebugInfo.cpp
===
--- lib/CodeGen/CGDebugInfo.cpp
+++ lib/CodeGen/CGDebugInfo.cpp
@@ -893,6 +893,7 @@
   case CC_Swift:
   case CC_PreserveMost:
   case CC_PreserveAll:
+  case 

[PATCH] D25204: Register Calling Convention, Clang changes

2016-10-04 Thread Alexey Bataev via cfe-commits
ABataev added a comment.

In https://reviews.llvm.org/D25204#560894, @erichkeane wrote:

> Hi Alexey-
>  Can you let me know what you mean by "Full Context Review"?  I'm unfamiliar 
> with that process.  The other fixes I'll look at today.


Check this page http://llvm.org/docs/Phabricator.html
use

  git diff -U99 other-branch

or

  svn diff --diff-cmd=diff -x -U99


https://reviews.llvm.org/D25204



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


[PATCH] D25204: Register Calling Convention, Clang changes

2016-10-04 Thread Erich Keane via cfe-commits
erichkeane marked 4 inline comments as done.
erichkeane added a comment.

Updated the code, fixed Alexey's concerns.  Thanks again for the comments!


https://reviews.llvm.org/D25204



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


[PATCH] D25204: Register Calling Convention, Clang changes

2016-10-04 Thread Erich Keane via cfe-commits
erichkeane removed rL LLVM as the repository for this revision.
erichkeane updated this revision to Diff 73489.

https://reviews.llvm.org/D25204

Files:
  include/clang-c/Index.h
  include/clang/AST/Type.h
  include/clang/Basic/Attr.td
  include/clang/Basic/AttrDocs.td
  include/clang/Basic/Specifiers.h
  include/clang/Basic/TokenKinds.def
  lib/AST/Expr.cpp
  lib/AST/ItaniumMangle.cpp
  lib/AST/Mangle.cpp
  lib/AST/MicrosoftMangle.cpp
  lib/AST/Type.cpp
  lib/AST/TypePrinter.cpp
  lib/Basic/Targets.cpp
  lib/CodeGen/CGCall.cpp
  lib/CodeGen/CGDebugInfo.cpp
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/TargetInfo.cpp
  lib/Parse/ParseDecl.cpp
  lib/Parse/ParseTentative.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaDeclAttr.cpp
  lib/Sema/SemaType.cpp
  test/CodeGen/regcall.c
  test/CodeGenCXX/regcall.cpp
  tools/libclang/CXType.cpp

Index: lib/Parse/ParseDecl.cpp
===
--- lib/Parse/ParseDecl.cpp
+++ lib/Parse/ParseDecl.cpp
@@ -605,6 +605,7 @@
 case tok::kw___fastcall:
 case tok::kw___stdcall:
 case tok::kw___thiscall:
+case tok::kw___regcall:
 case tok::kw___cdecl:
 case tok::kw___vectorcall:
 case tok::kw___ptr64:
@@ -3137,6 +3138,7 @@
 case tok::kw___stdcall:
 case tok::kw___fastcall:
 case tok::kw___thiscall:
+case tok::kw___regcall:
 case tok::kw___vectorcall:
   ParseMicrosoftTypeAttributes(DS.getAttributes());
   continue;
@@ -4454,6 +4456,7 @@
   case tok::kw___stdcall:
   case tok::kw___fastcall:
   case tok::kw___thiscall:
+  case tok::kw___regcall:
   case tok::kw___vectorcall:
   case tok::kw___w64:
   case tok::kw___ptr64:
@@ -4638,6 +4641,7 @@
   case tok::kw___stdcall:
   case tok::kw___fastcall:
   case tok::kw___thiscall:
+  case tok::kw___regcall:
   case tok::kw___vectorcall:
   case tok::kw___w64:
   case tok::kw___sptr:
@@ -4876,6 +4880,7 @@
 case tok::kw___stdcall:
 case tok::kw___fastcall:
 case tok::kw___thiscall:
+case tok::kw___regcall:
 case tok::kw___vectorcall:
   if (AttrReqs & AR_DeclspecAttributesParsed) {
 ParseMicrosoftTypeAttributes(DS.getAttributes());
Index: lib/Parse/ParseTentative.cpp
===
--- lib/Parse/ParseTentative.cpp
+++ lib/Parse/ParseTentative.cpp
@@ -909,7 +909,7 @@
   // '(' abstract-declarator ')'
   if (Tok.isOneOf(tok::kw___attribute, tok::kw___declspec, tok::kw___cdecl,
   tok::kw___stdcall, tok::kw___fastcall, tok::kw___thiscall,
-  tok::kw___vectorcall))
+  tok::kw___regcall, tok::kw___vectorcall))
 return TPResult::True; // attributes indicate declaration
   TPResult TPR = TryParseDeclarator(mayBeAbstract, mayHaveIdentifier);
   if (TPR != TPResult::Ambiguous)
@@ -1058,6 +1058,7 @@
   case tok::kw___stdcall:
   case tok::kw___fastcall:
   case tok::kw___thiscall:
+  case tok::kw___regcall:
   case tok::kw___vectorcall:
   case tok::kw___unaligned:
   case tok::kw___vector:
@@ -1351,6 +1352,7 @@
   case tok::kw___stdcall:
   case tok::kw___fastcall:
   case tok::kw___thiscall:
+  case tok::kw___regcall:
   case tok::kw___vectorcall:
   case tok::kw___w64:
   case tok::kw___sptr:
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -683,7 +683,15 @@
   } else {
 IdentifierInfo *II = ND->getIdentifier();
 assert(II && "Attempt to mangle unnamed decl.");
-Str = II->getName();
+const FunctionDecl *FD = dyn_cast(ND);
+
+if (FD && FD->getType()->castAs()->getCallConv() == CC_X86RegCall) {
+  llvm::raw_svector_ostream Out(Buffer);
+  Out << "__regcall3__" << II->getName();
+  Str = Out.str();
+} else {
+  Str = II->getName();
+}
   }
 
   // Keep the first result in the case of a mangling collision.
Index: lib/CodeGen/CGCall.cpp
===
--- lib/CodeGen/CGCall.cpp
+++ lib/CodeGen/CGCall.cpp
@@ -48,6 +48,7 @@
   default: return llvm::CallingConv::C;
   case CC_X86StdCall: return llvm::CallingConv::X86_StdCall;
   case CC_X86FastCall: return llvm::CallingConv::X86_FastCall;
+  case CC_X86RegCall: return llvm::CallingConv::X86_RegCall;
   case CC_X86ThisCall: return llvm::CallingConv::X86_ThisCall;
   case CC_X86_64Win64: return llvm::CallingConv::X86_64_Win64;
   case CC_X86_64SysV: return llvm::CallingConv::X86_64_SysV;
@@ -173,6 +174,9 @@
   if (D->hasAttr())
 return CC_X86FastCall;
 
+  if (D->hasAttr())
+return CC_X86RegCall;
+
   if (D->hasAttr())
 return CC_X86ThisCall;
 
Index: lib/CodeGen/CGDebugInfo.cpp
===
--- lib/CodeGen/CGDebugInfo.cpp
+++ lib/CodeGen/CGDebugInfo.cpp
@@ -893,6 +893,7 @@
   case CC_Swift:
   case CC_PreserveMost:
   case CC_PreserveAll:
+  case CC_X8

[PATCH] D25204: Register Calling Convention, Clang changes

2016-10-04 Thread Erich Keane via cfe-commits
erichkeane added a comment.

Hi Alexey-
Can you let me know what you mean by "Full Context Review"?  I'm unfamiliar 
with that process.  The other fixes I'll look at today.


Repository:
  rL LLVM

https://reviews.llvm.org/D25204



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


[PATCH] D25204: Register Calling Convention, Clang changes

2016-10-04 Thread Alexey Bataev via cfe-commits
ABataev added a comment.

Eric, please, prepare a full context review!



> ItaniumMangle.cpp:1417-1421
> +  if (isRegCall) {
> +Out << II->getLength() + sizeof("__regcall3__") - 1<< "__regcall3__";
> +  } else {
> +Out << II->getLength();
> +  }

Single-line substatements must not be enclosed into braces

> ItaniumMangle.cpp:1418
> +  if (isRegCall) {
> +Out << II->getLength() + sizeof("__regcall3__") - 1<< "__regcall3__";
> +  } else {

Line is not clang-formatted

> Mangle.cpp:70
>const llvm::Triple &Triple = TI.getTriple();
> +
>if (!Triple.isOSWindows() ||

Seems to me this change is not required

> MicrosoftMangle.cpp:440
>mangleName(D);
> -  if (const FunctionDecl *FD = dyn_cast(D))
> +  if (const FunctionDecl *FD = dyn_cast(D)) 
>  mangleFunctionEncoding(FD, Context.shouldMangleDeclName(FD));

No changes here, restore original line

Repository:
  rL LLVM

https://reviews.llvm.org/D25204



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


[PATCH] D25204: Register Calling Convention, Clang changes

2016-10-03 Thread Erich Keane via cfe-commits
erichkeane created this revision.
erichkeane added reviewers: oren_ben_simhon, cfe-commits.
erichkeane set the repository for this revision to rL LLVM.

The Register Calling Convention (RegCall) was introduced by Intel to optimize 
parameter transfer on function call.
This calling convention ensures that as many values as possible are passed or 
returned in registers.

The following review presents the basic additions to the Clang Front-end in 
order to support RegCall in X86.

See https://reviews.llvm.org/D25022 for CodeGen changes


Repository:
  rL LLVM

https://reviews.llvm.org/D25204

Files:
  include/clang-c/Index.h
  include/clang/AST/Type.h
  include/clang/Basic/Attr.td
  include/clang/Basic/AttrDocs.td
  include/clang/Basic/Specifiers.h
  include/clang/Basic/TokenKinds.def
  lib/AST/Expr.cpp
  lib/AST/ItaniumMangle.cpp
  lib/AST/Mangle.cpp
  lib/AST/MicrosoftMangle.cpp
  lib/AST/Type.cpp
  lib/AST/TypePrinter.cpp
  lib/Basic/Targets.cpp
  lib/CodeGen/CGCall.cpp
  lib/CodeGen/CGDebugInfo.cpp
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/TargetInfo.cpp
  lib/Parse/ParseDecl.cpp
  lib/Parse/ParseTentative.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaDeclAttr.cpp
  lib/Sema/SemaType.cpp
  test/CodeGen/regcall.c
  test/CodeGenCXX/regcall.cpp
  tools/libclang/CXType.cpp

Index: lib/Parse/ParseDecl.cpp
===
--- lib/Parse/ParseDecl.cpp
+++ lib/Parse/ParseDecl.cpp
@@ -605,6 +605,7 @@
 case tok::kw___fastcall:
 case tok::kw___stdcall:
 case tok::kw___thiscall:
+case tok::kw___regcall:
 case tok::kw___cdecl:
 case tok::kw___vectorcall:
 case tok::kw___ptr64:
@@ -3137,6 +3138,7 @@
 case tok::kw___stdcall:
 case tok::kw___fastcall:
 case tok::kw___thiscall:
+case tok::kw___regcall:
 case tok::kw___vectorcall:
   ParseMicrosoftTypeAttributes(DS.getAttributes());
   continue;
@@ -4454,6 +4456,7 @@
   case tok::kw___stdcall:
   case tok::kw___fastcall:
   case tok::kw___thiscall:
+  case tok::kw___regcall:
   case tok::kw___vectorcall:
   case tok::kw___w64:
   case tok::kw___ptr64:
@@ -4638,6 +4641,7 @@
   case tok::kw___stdcall:
   case tok::kw___fastcall:
   case tok::kw___thiscall:
+  case tok::kw___regcall:
   case tok::kw___vectorcall:
   case tok::kw___w64:
   case tok::kw___sptr:
@@ -4876,6 +4880,7 @@
 case tok::kw___stdcall:
 case tok::kw___fastcall:
 case tok::kw___thiscall:
+case tok::kw___regcall:
 case tok::kw___vectorcall:
   if (AttrReqs & AR_DeclspecAttributesParsed) {
 ParseMicrosoftTypeAttributes(DS.getAttributes());
Index: lib/Parse/ParseTentative.cpp
===
--- lib/Parse/ParseTentative.cpp
+++ lib/Parse/ParseTentative.cpp
@@ -909,7 +909,7 @@
   // '(' abstract-declarator ')'
   if (Tok.isOneOf(tok::kw___attribute, tok::kw___declspec, tok::kw___cdecl,
   tok::kw___stdcall, tok::kw___fastcall, tok::kw___thiscall,
-  tok::kw___vectorcall))
+  tok::kw___regcall, tok::kw___vectorcall))
 return TPResult::True; // attributes indicate declaration
   TPResult TPR = TryParseDeclarator(mayBeAbstract, mayHaveIdentifier);
   if (TPR != TPResult::Ambiguous)
@@ -1058,6 +1058,7 @@
   case tok::kw___stdcall:
   case tok::kw___fastcall:
   case tok::kw___thiscall:
+  case tok::kw___regcall:
   case tok::kw___vectorcall:
   case tok::kw___unaligned:
   case tok::kw___vector:
@@ -1351,6 +1352,7 @@
   case tok::kw___stdcall:
   case tok::kw___fastcall:
   case tok::kw___thiscall:
+  case tok::kw___regcall:
   case tok::kw___vectorcall:
   case tok::kw___w64:
   case tok::kw___sptr:
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -683,7 +683,15 @@
   } else {
 IdentifierInfo *II = ND->getIdentifier();
 assert(II && "Attempt to mangle unnamed decl.");
-Str = II->getName();
+const FunctionDecl *FD = dyn_cast(ND);
+
+if (FD && FD->getType()->castAs()->getCallConv() == CC_X86RegCall) {
+  llvm::raw_svector_ostream Out(Buffer);
+  Out << "__regcall3__" << II->getName();
+  Str = Out.str();
+} else {
+  Str = II->getName();
+}
   }
 
   // Keep the first result in the case of a mangling collision.
Index: lib/CodeGen/CGCall.cpp
===
--- lib/CodeGen/CGCall.cpp
+++ lib/CodeGen/CGCall.cpp
@@ -48,6 +48,7 @@
   default: return llvm::CallingConv::C;
   case CC_X86StdCall: return llvm::CallingConv::X86_StdCall;
   case CC_X86FastCall: return llvm::CallingConv::X86_FastCall;
+  case CC_X86RegCall: return llvm::CallingConv::X86_RegCall;
   case CC_X86ThisCall: return llvm::CallingConv::X86_ThisCall;
   case CC_X86_64Win64: return llvm::CallingConv::X86_64_Win64;
   case CC_X86_64SysV: return llvm::CallingConv::X