Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[X86] Add regcall4 attribute to make a specific function respect regcall ABIv4 #69628

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

yubingex007-a11y
Copy link
Contributor

@yubingex007-a11y yubingex007-a11y commented Oct 19, 2023

TODO: 1. add a testcase in cg side
2. add more testcase in CFE to check such combination {has regcall attr or not , has regcall4 attr or not, has regcall4 option or not}

@github-actions
Copy link

github-actions bot commented Oct 19, 2023

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

You can test this locally with the following command:
git-clang-format --diff 94123d164b910e0e9cca59438a00e619615e5776 83e01839777757e9afbcfdfaa57608bdb162d6f6 -- clang/test/CodeGen/regcall4-attr.c clang/lib/AST/ItaniumMangle.cpp clang/lib/AST/Mangle.cpp clang/lib/AST/TypePrinter.cpp clang/lib/CodeGen/CGCall.cpp clang/lib/CodeGen/CodeGenModule.cpp clang/lib/Sema/SemaDeclAttr.cpp clang/lib/Sema/SemaType.cpp
View the diff from clang-format here.
diff --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index 1d456d2b9ddf..f6b504c68ad7 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -524,7 +524,7 @@ private:
   void mangleUnscopedTemplateName(GlobalDecl GD, const DeclContext *DC,
                                   const AbiTagList *AdditionalAbiTags);
   void mangleSourceName(const IdentifierInfo *II);
-  void mangleRegCallName(const IdentifierInfo *II, const FunctionDecl* FD);
+  void mangleRegCallName(const IdentifierInfo *II, const FunctionDecl *FD);
   void mangleDeviceStubName(const IdentifierInfo *II);
   void mangleSourceNameWithAbiTags(
       const NamedDecl *ND, const AbiTagList *AdditionalAbiTags = nullptr);
@@ -1739,7 +1739,8 @@ void CXXNameMangler::mangleUnqualifiedName(
   }
 }
 
-void CXXNameMangler::mangleRegCallName(const IdentifierInfo *II, const FunctionDecl* FD) {
+void CXXNameMangler::mangleRegCallName(const IdentifierInfo *II,
+                                       const FunctionDecl *FD) {
   // <source-name> ::= <positive length number> __regcall3__ <identifier>
   // <number> ::= [n] <non-negative decimal integer>
   // <identifier> ::= <unqualified source code identifier>
diff --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp
index 6ca95eefe4b0..a4cfd5d168ce 100644
--- a/clang/lib/AST/TypePrinter.cpp
+++ b/clang/lib/AST/TypePrinter.cpp
@@ -1861,7 +1861,9 @@ void TypePrinter::printAttributedAfter(const AttributedType *T,
   case attr::MSABI: OS << "ms_abi"; break;
   case attr::SysVABI: OS << "sysv_abi"; break;
   case attr::RegCall: OS << "regcall"; break;
-  case attr::RegCall4: OS << "regcall4"; break;
+  case attr::RegCall4:
+    OS << "regcall4";
+    break;
   case attr::Pcs: {
     OS << "pcs(";
    QualType t = T->getEquivalentType();
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index f29513f6b6e9..c6d3cd89d725 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -2316,7 +2316,7 @@ void CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D,
     F->addFnAttrs(B);
     return;
   }
-  
+
   if (D->hasAttr<RegCall4Attr>())
     B.addAttribute("regcall4");
 
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 2c1bfb8d9115..5f829c1141fc 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -9352,7 +9352,7 @@ ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D, const ParsedAttr &AL,
   case ParsedAttr::AT_ThisCall:
   case ParsedAttr::AT_Pascal:
   case ParsedAttr::AT_RegCall:
-  //case ParsedAttr::AT_RegCall4:
+  // case ParsedAttr::AT_RegCall4:
   case ParsedAttr::AT_SwiftCall:
   case ParsedAttr::AT_SwiftAsyncCall:
   case ParsedAttr::AT_VectorCall:
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index d164944c3bde..86d472e33248 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -124,7 +124,7 @@ static void diagnoseBadTypeAttribute(Sema &S, const ParsedAttr &attr,
   case ParsedAttr::AT_StdCall:                                                 \
   case ParsedAttr::AT_ThisCall:                                                \
   case ParsedAttr::AT_RegCall:                                                 \
-  case ParsedAttr::AT_RegCall4:                                                 \
+  case ParsedAttr::AT_RegCall4:                                                \
   case ParsedAttr::AT_Pascal:                                                  \
   case ParsedAttr::AT_SwiftCall:                                               \
   case ParsedAttr::AT_SwiftAsyncCall:                                          \

@@ -9347,6 +9352,7 @@ ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D, const ParsedAttr &AL,
case ParsedAttr::AT_ThisCall:
case ParsedAttr::AT_Pascal:
case ParsedAttr::AT_RegCall:
//case ParsedAttr::AT_RegCall4:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mikerice1969 hi, if i uncomment here, and delete L9648-9650, regcall4 won't be added into Decl because hasDeclarator(D) is true:

static void handleCallConvAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
  if (hasDeclarator(D)) return;

do you know why this happened?

@yubingex007-a11y yubingex007-a11y changed the title [X86] Add regcall4 attribute to make a specific function respect regc… [X86] Add regcall4 attribute to make a specific function respect regcall ABIv4 Oct 20, 2023
@yubingex007-a11y
Copy link
Contributor Author

yubingex007-a11y commented Oct 20, 2023

there is question here: should we really add a new calling conv CC_X86RegCall4 in CFE?
currently i let regcall4 attr reuse CC_X86RegCall instead of creating CC_X86RegCall4 .

@mikerice1969

@yubingex007-a11y yubingex007-a11y requested review from AaronBallman and removed request for AaronBallman October 20, 2023 09:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant