[PATCH] D149867: [M68k] Add Clang support for the new M68k_RTD CC

2023-06-01 Thread Jessica Clarke via Phabricator via cfe-commits
jrtc27 added a comment.

In D149867#4387189 , @glaubitz wrote:

> In D149867#4386271 , @jrtc27 wrote:
>
>> I disagree. Being experimental doesn't mean you should do the wrong thing. 
>> Reusing stdcall in the frontend is ugly, pollutes non-m68k code paths (doing 
>> your own thing _avoids_ that and makes the experimental backend get out of 
>> the way, even) and introduces a bug where you can write garbage code and 
>> have it compile rather than be rejected like it should be.
>
> Maybe we can get the TLS stuff merged first before dealing with this more 
> complex change?

They're totally independent, so nothing's blocking that being merged. Plus this 
isn't a complex change to make, just a bunch of copy pasta.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149867/new/

https://reviews.llvm.org/D149867

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


[PATCH] D149867: [M68k] Add Clang support for the new M68k_RTD CC

2023-06-01 Thread John Paul Adrian Glaubitz via Phabricator via cfe-commits
glaubitz added a comment.

In D149867#4386271 , @jrtc27 wrote:

> I disagree. Being experimental doesn't mean you should do the wrong thing. 
> Reusing stdcall in the frontend is ugly, pollutes non-m68k code paths (doing 
> your own thing _avoids_ that and makes the experimental backend get out of 
> the way, even) and introduces a bug where you can write garbage code and have 
> it compile rather than be rejected like it should be.

Maybe we can get the TLS stuff merged first before dealing with this more 
complex change?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149867/new/

https://reviews.llvm.org/D149867

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


[PATCH] D149867: [M68k] Add Clang support for the new M68k_RTD CC

2023-05-31 Thread Jessica Clarke via Phabricator via cfe-commits
jrtc27 requested changes to this revision.
jrtc27 added a comment.
This revision now requires changes to proceed.

I disagree. Being experimental doesn't mean you should do the wrong thing. 
Reusing std call in the frontend is ugly, pollutes non-m68k code paths (doing 
your own thing _avoids_ that and makes the experimental backend get out of the 
way, even) and introduces a bug where you can write garbage code and have it 
compile rather than be rejected like it should be.

Add your own calling convention like everyone else.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149867/new/

https://reviews.llvm.org/D149867

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


[PATCH] D149867: [M68k] Add Clang support for the new M68k_RTD CC

2023-05-31 Thread Sheng via Phabricator via cfe-commits
0x59616e accepted this revision.
0x59616e added a comment.
This revision is now accepted and ready to land.

Though creating our own calling convention is better, I think Min's path is 
correct at this moment given that m68k is still an experimental target. We can 
reignite this discussion once we're approaching to becoming a offiical target.

@myhsu could you open an issue to cite this problem ?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149867/new/

https://reviews.llvm.org/D149867

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


[PATCH] D149867: [M68k] Add Clang support for the new M68k_RTD CC

2023-05-25 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu added a comment.

ping


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149867/new/

https://reviews.llvm.org/D149867

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


[PATCH] D149867: [M68k] Add Clang support for the new M68k_RTD CC

2023-05-08 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu added a comment.

In D149867#4325040 , @jrtc27 wrote:

> So GCC gives me:
>
>   warning: ‘stdcall’ attribute directive ignored [-Wattributes]
>
> when trying to use `__attribute__((stdcall))` on m68k, which matches the fact 
> it's only mentioned in the manage for the x86 option.

In principal, I wanted to reuse as much existing code path as possible to 
handle `-mrtd`, primarily because these two calling conventions are basically 
identical and I didn't want to create too much churn. Reusing both 
`DCC_StdCall` and `CC_X86StdCall` serves that purpose. Making 
`__attribute__((stdcall))` available to m68k is just a side effect that I felt 
harmless.
I'm fine to create a separate `CC_M68kRTDCall` or even `DCC_RTDCall`. What do 
you think @jrtc27 ?

> Interestingly it seems to ICE during expand when I use -mrtd though...

I guess you're referring to GCC? I'm curious which snippet you used.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149867/new/

https://reviews.llvm.org/D149867

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


[PATCH] D149867: [M68k] Add Clang support for the new M68k_RTD CC

2023-05-07 Thread Jessica Clarke via Phabricator via cfe-commits
jrtc27 added a comment.

So GCC gives me:

  warning: ‘stdcall’ attribute directive ignored [-Wattributes]

when trying to use `__attribute__((stdcall))` on m68k, which matches the fact 
it's only mentioned in the manage for the x86 option.

Interestingly it seems to ICE during expand when I use -mrtd though...




Comment at: clang/lib/Basic/Targets/M68k.cpp:258
+  // The M68k_RTD calling convention.
+  case CC_X86StdCall:
+return CCCR_OK;

Uhh



Comment at: clang/lib/CodeGen/CGCall.cpp:51
   default: return llvm::CallingConv::C;
-  case CC_X86StdCall: return llvm::CallingConv::X86_StdCall;
+  case CC_X86StdCall:
+return CGM.getTriple().getArch() == llvm::Triple::m68k

Ditto...



Comment at: clang/test/CodeGen/mrtd.c:4
 
-// CHECK: mrtd.c:10:3: warning: function with no prototype cannot use the 
stdcall calling convention
+// CHECK: mrtd.c:13:3: warning: function with no prototype cannot use the 
stdcall calling convention
 

Ew... this should be using -verify and `// expected-warning {{...}}`, then the 
line number is relative to the comment's location. Or, really, it should be in 
the Sema test...

Plus is it correct to call this stdcall on m68k? The GCC manpage only mentions 
it in the x86 option description, not the m68k one.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149867/new/

https://reviews.llvm.org/D149867

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


[PATCH] D149867: [M68k] Add Clang support for the new M68k_RTD CC

2023-05-05 Thread Sheng via Phabricator via cfe-commits
0x59616e added a comment.

I didn't see any issue here. Let's wait for the approval from other (more 
senior) reviewers.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149867/new/

https://reviews.llvm.org/D149867

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


[PATCH] D149867: [M68k] Add Clang support for the new M68k_RTD CC

2023-05-05 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu updated this revision to Diff 519983.
myhsu added a comment.

Minor updates. NFC.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149867/new/

https://reviews.llvm.org/D149867

Files:
  clang/lib/Basic/Targets/M68k.cpp
  clang/lib/Basic/Targets/M68k.h
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CodeGen/mrtd.c
  clang/test/Sema/mrtd.c

Index: clang/test/Sema/mrtd.c
===
--- clang/test/Sema/mrtd.c
+++ clang/test/Sema/mrtd.c
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 -DMRTD -mrtd -triple i386-unknown-unknown -verify %s
+// RUN: %clang_cc1 -DMRTD -mrtd -triple m68k-unknown-unknown -verify %s
 // RUN: %clang_cc1 -triple i386-unknown-unknown -verify %s
+// RUN: %clang_cc1 -triple m68k-unknown-unknown -verify %s
 
 #ifndef MRTD
 // expected-note@+5 {{previous declaration is here}}
Index: clang/test/CodeGen/mrtd.c
===
--- clang/test/CodeGen/mrtd.c
+++ clang/test/CodeGen/mrtd.c
@@ -1,20 +1,26 @@
-// RUN: %clang_cc1 -mrtd -triple i386-unknown-unknown -std=c89 -emit-llvm -o - %s 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -mrtd -triple i386-unknown-unknown -std=c89 -emit-llvm -o - %s 2>&1 | FileCheck --check-prefixes=CHECK,X86 %s
+// RUN: %clang_cc1 -mrtd -triple m68k-unknown-unknown -std=c89 -emit-llvm -o - %s 2>&1 | FileCheck --check-prefixes=CHECK,M68k %s
 
-// CHECK: mrtd.c:10:3: warning: function with no prototype cannot use the stdcall calling convention
+// CHECK: mrtd.c:13:3: warning: function with no prototype cannot use the stdcall calling convention
 
 void baz(int arg);
 
-// CHECK: define{{.*}} x86_stdcallcc void @foo(i32 noundef %arg) [[NUW:#[0-9]+]]
+// X86: define{{.*}} x86_stdcallcc void @foo(i32 noundef %arg) [[NUW:#[0-9]+]]
+// M68k: define{{.*}} m68k_rtdcc void @foo(i32 noundef %arg)
 void foo(int arg) {
-// CHECK: call x86_stdcallcc i32 @bar(
+// X86: call x86_stdcallcc i32 @bar(
+// M68k: call m68k_rtdcc i32 @bar(
   bar(arg);
-// CHECK: call x86_stdcallcc void @baz(i32
+// X86: call x86_stdcallcc void @baz(i32
+// M68k: call m68k_rtdcc void @baz(i32
   baz(arg);
 }
 
-// CHECK: declare x86_stdcallcc i32 @bar(...)
+// X86: declare x86_stdcallcc i32 @bar(...)
+// M68k: declare m68k_rtdcc i32 @bar(...)
 
-// CHECK: declare x86_stdcallcc void @baz(i32 noundef)
+// X86: declare x86_stdcallcc void @baz(i32 noundef)
+// M68k: declare m68k_rtdcc void @baz(i32 noundef)
 
 void qux(int arg, ...) { }
 // CHECK: define{{.*}} void @qux(i32 noundef %arg, ...)
@@ -22,7 +28,8 @@
 void quux(int a1, int a2, int a3) {
   qux(a1, a2, a3);
 }
-// CHECK-LABEL: define{{.*}} x86_stdcallcc void @quux
+// X86-LABEL: define{{.*}} x86_stdcallcc void @quux
+// M68k-LABEL: define{{.*}} m68k_rtdcc void @quux
 // CHECK: call void (i32, ...) @qux
 
-// CHECK: attributes [[NUW]] = { noinline nounwind{{.*}} }
+// X86: attributes [[NUW]] = { noinline nounwind{{.*}} }
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -553,9 +553,10 @@
   if (Arg *A = Args.getLastArg(OPT_fdefault_calling_conv_EQ)) {
 auto DefaultCC = LangOpts.getDefaultCallingConv();
 
-bool emitError = (DefaultCC == LangOptions::DCC_FastCall ||
-  DefaultCC == LangOptions::DCC_StdCall) &&
- Arch != llvm::Triple::x86;
+bool emitError =
+DefaultCC == LangOptions::DCC_FastCall && Arch != llvm::Triple::x86;
+emitError |= DefaultCC == LangOptions::DCC_StdCall &&
+ Arch != llvm::Triple::m68k && Arch != llvm::Triple::x86;
 emitError |= (DefaultCC == LangOptions::DCC_VectorCall ||
   DefaultCC == LangOptions::DCC_RegCall) &&
  !T.isX86();
@@ -3747,7 +3748,7 @@
   Diags.Report(diag::err_drv_argument_not_allowed_with)
   << A->getSpelling() << "-fdefault-calling-conv";
 else {
-  if (T.getArch() != llvm::Triple::x86)
+  if (T.getArch() != llvm::Triple::x86 && T.getArch() != llvm::Triple::m68k)
 Diags.Report(diag::err_drv_argument_not_allowed_with)
 << A->getSpelling() << T.getTriple();
   else
Index: clang/lib/CodeGen/CGCall.cpp
===
--- clang/lib/CodeGen/CGCall.cpp
+++ clang/lib/CodeGen/CGCall.cpp
@@ -48,7 +48,10 @@
 unsigned CodeGenTypes::ClangCallConvToLLVMCallConv(CallingConv CC) {
   switch (CC) {
   default: return llvm::CallingConv::C;
-  case CC_X86StdCall: return llvm::CallingConv::X86_StdCall;
+  case CC_X86StdCall:
+return CGM.getTriple().getArch() == llvm::Triple::m68k
+   ? llvm::CallingConv::M68k_RTD
+   : llvm::CallingConv::X86_StdCall;
   case CC_X86FastCall: return llvm::CallingConv::X86_FastCall;
   case CC_X86RegCall: return llvm::CallingConv::X86_RegCall;
   case 

[PATCH] D149867: [M68k] Add Clang support for the new M68k_RTD CC

2023-05-05 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu updated this revision to Diff 519982.
myhsu added a comment.

Introduce `m68k_rtdcc` the textual LLVM IR designation for M68k_RTD


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149867/new/

https://reviews.llvm.org/D149867

Files:
  clang/lib/Basic/Targets/M68k.cpp
  clang/lib/Basic/Targets/M68k.h
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CodeGen/mrtd.c
  clang/test/Sema/mrtd.c

Index: clang/test/Sema/mrtd.c
===
--- clang/test/Sema/mrtd.c
+++ clang/test/Sema/mrtd.c
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 -DMRTD -mrtd -triple i386-unknown-unknown -verify %s
+// RUN: %clang_cc1 -DMRTD -mrtd -triple m68k-unknown-unknown -verify %s
 // RUN: %clang_cc1 -triple i386-unknown-unknown -verify %s
+// RUN: %clang_cc1 -triple m68k-unknown-unknown -verify %s
 
 #ifndef MRTD
 // expected-note@+5 {{previous declaration is here}}
Index: clang/test/CodeGen/mrtd.c
===
--- clang/test/CodeGen/mrtd.c
+++ clang/test/CodeGen/mrtd.c
@@ -1,20 +1,26 @@
-// RUN: %clang_cc1 -mrtd -triple i386-unknown-unknown -std=c89 -emit-llvm -o - %s 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -mrtd -triple i386-unknown-unknown -std=c89 -emit-llvm -o - %s 2>&1 | FileCheck --check-prefixes=CHECK,X86 %s
+// RUN: %clang_cc1 -mrtd -triple m68k-unknown-unknown -std=c89 -emit-llvm -o - %s 2>&1 | FileCheck --check-prefixes=CHECK,M68k %s
 
-// CHECK: mrtd.c:10:3: warning: function with no prototype cannot use the stdcall calling convention
+// CHECK: mrtd.c:13:3: warning: function with no prototype cannot use the stdcall calling convention
 
 void baz(int arg);
 
-// CHECK: define{{.*}} x86_stdcallcc void @foo(i32 noundef %arg) [[NUW:#[0-9]+]]
+// X86: define{{.*}} x86_stdcallcc void @foo(i32 noundef %arg) [[NUW:#[0-9]+]]
+// M68k: define{{.*}} m68k_rtdcc void @foo(i32 noundef %arg)
 void foo(int arg) {
-// CHECK: call x86_stdcallcc i32 @bar(
+// X86: call x86_stdcallcc i32 @bar(
+// M68k: call m68k_rtdcc i32 @bar(
   bar(arg);
-// CHECK: call x86_stdcallcc void @baz(i32
+// X86: call x86_stdcallcc void @baz(i32
+// M68k: call m68k_rtdcc void @baz(i32
   baz(arg);
 }
 
-// CHECK: declare x86_stdcallcc i32 @bar(...)
+// X86: declare x86_stdcallcc i32 @bar(...)
+// M68k: declare m68k_rtdcc i32 @bar(...)
 
-// CHECK: declare x86_stdcallcc void @baz(i32 noundef)
+// X86: declare x86_stdcallcc void @baz(i32 noundef)
+// M68k: declare m68k_rtdcc void @baz(i32 noundef)
 
 void qux(int arg, ...) { }
 // CHECK: define{{.*}} void @qux(i32 noundef %arg, ...)
@@ -22,7 +28,8 @@
 void quux(int a1, int a2, int a3) {
   qux(a1, a2, a3);
 }
-// CHECK-LABEL: define{{.*}} x86_stdcallcc void @quux
+// X86-LABEL: define{{.*}} x86_stdcallcc void @quux
+// M68k-LABEL: define{{.*}} m68k_rtdcc void @quux
 // CHECK: call void (i32, ...) @qux
 
-// CHECK: attributes [[NUW]] = { noinline nounwind{{.*}} }
+// X86: attributes [[NUW]] = { noinline nounwind{{.*}} }
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -553,9 +553,10 @@
   if (Arg *A = Args.getLastArg(OPT_fdefault_calling_conv_EQ)) {
 auto DefaultCC = LangOpts.getDefaultCallingConv();
 
-bool emitError = (DefaultCC == LangOptions::DCC_FastCall ||
-  DefaultCC == LangOptions::DCC_StdCall) &&
- Arch != llvm::Triple::x86;
+bool emitError =
+DefaultCC == LangOptions::DCC_FastCall && Arch != llvm::Triple::x86;
+emitError |= DefaultCC == LangOptions::DCC_StdCall &&
+ !(Arch == llvm::Triple::m68k || Arch == llvm::Triple::x86);
 emitError |= (DefaultCC == LangOptions::DCC_VectorCall ||
   DefaultCC == LangOptions::DCC_RegCall) &&
  !T.isX86();
@@ -3747,7 +3748,7 @@
   Diags.Report(diag::err_drv_argument_not_allowed_with)
   << A->getSpelling() << "-fdefault-calling-conv";
 else {
-  if (T.getArch() != llvm::Triple::x86)
+  if (T.getArch() != llvm::Triple::x86 && T.getArch() != llvm::Triple::m68k)
 Diags.Report(diag::err_drv_argument_not_allowed_with)
 << A->getSpelling() << T.getTriple();
   else
Index: clang/lib/CodeGen/CGCall.cpp
===
--- clang/lib/CodeGen/CGCall.cpp
+++ clang/lib/CodeGen/CGCall.cpp
@@ -48,7 +48,10 @@
 unsigned CodeGenTypes::ClangCallConvToLLVMCallConv(CallingConv CC) {
   switch (CC) {
   default: return llvm::CallingConv::C;
-  case CC_X86StdCall: return llvm::CallingConv::X86_StdCall;
+  case CC_X86StdCall:
+return CGM.getTriple().getArch() == llvm::Triple::m68k
+   ? llvm::CallingConv::M68k_RTD
+   : llvm::CallingConv::X86_StdCall;
   case CC_X86FastCall: return llvm::CallingConv::X86_FastCall;
   case CC_X86RegCall: return 

[PATCH] D149867: [M68k] Add Clang support for the new M68k_RTD CC

2023-05-05 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu added inline comments.



Comment at: clang/test/CodeGen/mrtd.c:9
+// X86: define{{.*}} x86_stdcallcc void @foo(i32 noundef %arg) [[NUW:#[0-9]+]]
+// M68k: define{{.*}} cc104 void @foo(i32 noundef %arg)
 void foo(int arg) {

0x59616e wrote:
> 0x59616e wrote:
> > Just curious, why do we have to use such an arcane name instead of a more 
> > lucid one , such as `m68k_rtdcc`.
> I guess this involves more work ?
> I guess this involves more work ?

Yes because it requires changes to (LLVM IR's) AsmReader/Writer. But it's not 
hard and I can do that. The reason I didn't do that was simply because this CC 
is rare so the arcane name's impact on (our) productivity will be low.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149867/new/

https://reviews.llvm.org/D149867

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


[PATCH] D149867: [M68k] Add Clang support for the new M68k_RTD CC

2023-05-04 Thread Sheng via Phabricator via cfe-commits
0x59616e added inline comments.



Comment at: clang/test/CodeGen/mrtd.c:9
+// X86: define{{.*}} x86_stdcallcc void @foo(i32 noundef %arg) [[NUW:#[0-9]+]]
+// M68k: define{{.*}} cc104 void @foo(i32 noundef %arg)
 void foo(int arg) {

0x59616e wrote:
> Just curious, why do we have to use such an arcane name instead of a more 
> lucid one , such as `m68k_rtdcc`.
I guess this involves more work ?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149867/new/

https://reviews.llvm.org/D149867

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


[PATCH] D149867: [M68k] Add Clang support for the new M68k_RTD CC

2023-05-04 Thread Sheng via Phabricator via cfe-commits
0x59616e added inline comments.



Comment at: clang/lib/Frontend/CompilerInvocation.cpp:559
+emitError |= DefaultCC == LangOptions::DCC_StdCall &&
+ !(Arch == llvm::Triple::m68k || Arch == llvm::Triple::x86);
 emitError |= (DefaultCC == LangOptions::DCC_VectorCall ||

nit: Is the expanded one better in terms of readability ?



Comment at: clang/test/CodeGen/mrtd.c:9
+// X86: define{{.*}} x86_stdcallcc void @foo(i32 noundef %arg) [[NUW:#[0-9]+]]
+// M68k: define{{.*}} cc104 void @foo(i32 noundef %arg)
 void foo(int arg) {

Just curious, why do we have to use such an arcane name instead of a more lucid 
one , such as `m68k_rtdcc`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149867/new/

https://reviews.llvm.org/D149867

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


[PATCH] D149867: [M68k] Add Clang support for the new M68k_RTD CC

2023-05-04 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu created this revision.
myhsu added reviewers: 0x59616e, RKSimon, craig.topper.
Herald added a subscriber: pengfei.
Herald added a project: All.
myhsu requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

We basically piggyback most of implementations on top of X86's stdcall due to 
their similarities, all the way until CodeGen where we use 
`llvm::CallingConv::M68k_RTD` rather than `llvm::CallingConv::X86_StdCall`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D149867

Files:
  clang/lib/Basic/Targets/M68k.cpp
  clang/lib/Basic/Targets/M68k.h
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CodeGen/mrtd.c
  clang/test/Sema/mrtd.c

Index: clang/test/Sema/mrtd.c
===
--- clang/test/Sema/mrtd.c
+++ clang/test/Sema/mrtd.c
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 -DMRTD -mrtd -triple i386-unknown-unknown -verify %s
+// RUN: %clang_cc1 -DMRTD -mrtd -triple m68k-unknown-unknown -verify %s
 // RUN: %clang_cc1 -triple i386-unknown-unknown -verify %s
+// RUN: %clang_cc1 -triple m68k-unknown-unknown -verify %s
 
 #ifndef MRTD
 // expected-note@+5 {{previous declaration is here}}
Index: clang/test/CodeGen/mrtd.c
===
--- clang/test/CodeGen/mrtd.c
+++ clang/test/CodeGen/mrtd.c
@@ -1,20 +1,26 @@
-// RUN: %clang_cc1 -mrtd -triple i386-unknown-unknown -std=c89 -emit-llvm -o - %s 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -mrtd -triple i386-unknown-unknown -std=c89 -emit-llvm -o - %s 2>&1 | FileCheck --check-prefixes=CHECK,X86 %s
+// RUN: %clang_cc1 -mrtd -triple m68k-unknown-unknown -std=c89 -emit-llvm -o - %s 2>&1 | FileCheck --check-prefixes=CHECK,M68k %s
 
-// CHECK: mrtd.c:10:3: warning: function with no prototype cannot use the stdcall calling convention
+// CHECK: mrtd.c:13:3: warning: function with no prototype cannot use the stdcall calling convention
 
 void baz(int arg);
 
-// CHECK: define{{.*}} x86_stdcallcc void @foo(i32 noundef %arg) [[NUW:#[0-9]+]]
+// X86: define{{.*}} x86_stdcallcc void @foo(i32 noundef %arg) [[NUW:#[0-9]+]]
+// M68k: define{{.*}} cc104 void @foo(i32 noundef %arg)
 void foo(int arg) {
-// CHECK: call x86_stdcallcc i32 @bar(
+// X86: call x86_stdcallcc i32 @bar(
+// M68k: call cc104 i32 @bar(
   bar(arg);
-// CHECK: call x86_stdcallcc void @baz(i32
+// X86: call x86_stdcallcc void @baz(i32
+// M68k: call cc104 void @baz(i32
   baz(arg);
 }
 
-// CHECK: declare x86_stdcallcc i32 @bar(...)
+// X86: declare x86_stdcallcc i32 @bar(...)
+// M68k: declare cc104 i32 @bar(...)
 
-// CHECK: declare x86_stdcallcc void @baz(i32 noundef)
+// X86: declare x86_stdcallcc void @baz(i32 noundef)
+// M68k: declare cc104 void @baz(i32 noundef)
 
 void qux(int arg, ...) { }
 // CHECK: define{{.*}} void @qux(i32 noundef %arg, ...)
@@ -22,7 +28,8 @@
 void quux(int a1, int a2, int a3) {
   qux(a1, a2, a3);
 }
-// CHECK-LABEL: define{{.*}} x86_stdcallcc void @quux
+// X86-LABEL: define{{.*}} x86_stdcallcc void @quux
+// M68k-LABEL: define{{.*}} cc104 void @quux
 // CHECK: call void (i32, ...) @qux
 
-// CHECK: attributes [[NUW]] = { noinline nounwind{{.*}} }
+// X86: attributes [[NUW]] = { noinline nounwind{{.*}} }
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -553,9 +553,10 @@
   if (Arg *A = Args.getLastArg(OPT_fdefault_calling_conv_EQ)) {
 auto DefaultCC = LangOpts.getDefaultCallingConv();
 
-bool emitError = (DefaultCC == LangOptions::DCC_FastCall ||
-  DefaultCC == LangOptions::DCC_StdCall) &&
- Arch != llvm::Triple::x86;
+bool emitError =
+DefaultCC == LangOptions::DCC_FastCall && Arch != llvm::Triple::x86;
+emitError |= DefaultCC == LangOptions::DCC_StdCall &&
+ !(Arch == llvm::Triple::m68k || Arch == llvm::Triple::x86);
 emitError |= (DefaultCC == LangOptions::DCC_VectorCall ||
   DefaultCC == LangOptions::DCC_RegCall) &&
  !T.isX86();
@@ -3747,7 +3748,7 @@
   Diags.Report(diag::err_drv_argument_not_allowed_with)
   << A->getSpelling() << "-fdefault-calling-conv";
 else {
-  if (T.getArch() != llvm::Triple::x86)
+  if (T.getArch() != llvm::Triple::x86 && T.getArch() != llvm::Triple::m68k)
 Diags.Report(diag::err_drv_argument_not_allowed_with)
 << A->getSpelling() << T.getTriple();
   else
Index: clang/lib/CodeGen/CGCall.cpp
===
--- clang/lib/CodeGen/CGCall.cpp
+++ clang/lib/CodeGen/CGCall.cpp
@@ -48,7 +48,10 @@
 unsigned CodeGenTypes::ClangCallConvToLLVMCallConv(CallingConv CC) {
   switch (CC) {
   default: return llvm::CallingConv::C;
-  case CC_X86StdCall: return