[PATCH] D80574: [ExtVector] Support ExtVectorType conditional operator

2020-05-26 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu created this revision.
myhsu added reviewers: Anastasia, bader, hfinkel, erichkeane.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Extension vectors now can be used in element-wise conditional selector.
For example:

  R[i] = C[i]? A[i] : B[i]

This feature was previously only enabled in OpenCL C. Now it's also
available in C. Not that it has different behaviors than GNU vectors
(i.e. __vector_size__). Extension vectors selects on signdness of the
vector. GNU vectors on the other hand do normal bool conversions. Also,
this feature is not available in C++.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D80574

Files:
  clang/docs/LanguageExtensions.rst
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Sema/ext_vector_comparisons.c

Index: clang/test/Sema/ext_vector_comparisons.c
===
--- clang/test/Sema/ext_vector_comparisons.c
+++ clang/test/Sema/ext_vector_comparisons.c
@@ -28,3 +28,19 @@
   return vec > vec;  // no-warning
   return vec >= vec; // no-warning
 }
+
+static int4 test3() {
+  int4 i0, i1;
+
+  return i0 > i1 ? i0 : i1; // no-error
+  return i0 ? i0 : i1;  // no-error
+}
+
+static float4 test4() {
+  float4 f0, f1;
+
+  // This would actually generate implicit casting warning
+  // under Weverything flag but we don't really care here
+  return f0 > f1 ? f0 : f1; // no-error
+  return f0 ? f0 : f1;  // expected-error {{arithmetic or pointer type is required}}
+}
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -7480,6 +7480,13 @@
   // C99 6.5.15p2
   if (CondTy->isScalarType()) return false;
 
+  // Only ext vector is allowed
+  if (const auto *VecCondTy = Cond->getType()->getAs()) {
+QualType EleTy = VecCondTy->getElementType();
+if (EleTy->isIntegerType())
+  return false;
+  }
+
   S.Diag(QuestionLoc, diag::err_typecheck_cond_expect_scalar)
 << CondTy << Cond->getSourceRange();
   return true;
@@ -7958,10 +7965,21 @@
 
   // Now check the two expressions.
   if (LHS.get()->getType()->isVectorType() ||
-  RHS.get()->getType()->isVectorType())
-return CheckVectorOperands(LHS, RHS, QuestionLoc, /*isCompAssign*/false,
-   /*AllowBothBool*/true,
-   /*AllowBoolConversions*/false);
+  RHS.get()->getType()->isVectorType()) {
+QualType VecResTy = CheckVectorOperands(LHS, RHS, QuestionLoc,
+/*isCompAssign*/ false,
+/*AllowBothBool*/ true,
+/*AllowBoolConversions*/ false);
+// If the condition is ext vector, we're imposing OpenCL's rule wrt
+// condition and result type.
+QualType CondTy = Cond.get()->getType();
+if (CondTy->isExtVectorType()) {
+  if (VecResTy.isNull() ||
+  checkVectorResult(*this, CondTy, VecResTy, QuestionLoc))
+return QualType();
+}
+return VecResTy;
+  }
 
   QualType ResTy =
   UsualArithmeticConversions(LHS, RHS, QuestionLoc, ACK_Conditional);
Index: clang/lib/CodeGen/CGExprScalar.cpp
===
--- clang/lib/CodeGen/CGExprScalar.cpp
+++ clang/lib/CodeGen/CGExprScalar.cpp
@@ -4431,8 +4431,8 @@
 
   // OpenCL: If the condition is a vector, we can treat this condition like
   // the select function.
-  if (CGF.getLangOpts().OpenCL
-  && condExpr->getType()->isVectorType()) {
+  if ((CGF.getLangOpts().OpenCL && condExpr->getType()->isVectorType()) ||
+  condExpr->getType()->isExtVectorType()) {
 CGF.incrementProfileCounter(E);
 
 llvm::Value *CondV = CGF.EmitScalarExpr(condExpr);
Index: clang/docs/LanguageExtensions.rst
===
--- clang/docs/LanguageExtensions.rst
+++ clang/docs/LanguageExtensions.rst
@@ -478,7 +478,7 @@
 !, &&, ||yes --yes [#]_--
 ==, !=, >, <, >=, <= yes yes   yes --
 =yes yes   yes yes
-:? [#]_  yes --yes --
+?:   yes --yes --
 sizeof   yes yes   yes yes
 C-style cast yes yes   yes no
 reinterpret_cast yes noyes no
@@ -486,12 +486,15 @@
 const_cast   no  nono  no
 == === === = ===
 
+Note that ternary operator(?:) has different behaviors depends on the vector type of
+the condition operands. If the condition is a GNU vector (i.e. __vector_size__),
+it's only available in C++ and uses normal b

[PATCH] D80574: [ExtVector] Support ExtVectorType conditional operator

2020-05-28 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu marked 2 inline comments as done.
myhsu added inline comments.



Comment at: clang/lib/Sema/SemaExpr.cpp:7484
+  // Only ext vector is allowed
+  if (const auto *VecCondTy = Cond->getType()->getAs()) {
+QualType EleTy = VecCondTy->getElementType();

Anastasia wrote:
> Why do you need this change? I believe OpenCL makes the same restriction.
I'm not quite sure what restriction you're referring here. If you're saying 
OpenCL only allow ext_vector_type on condition operand, I don't think that's 
the case since on line 7956 ~ 7957 of Sema/SemaExpr.cpp :

```
if (getLangOpts().OpenCL && Cond.get()->getType()->isVectorType())
return OpenCLCheckVectorConditional(*this, Cond, LHS, RHS, QuestionLoc);
```
`isVectorType()` will be true for both GNU vector and ext_vector_type.

Regarding why i add the change here rather than merging with OpenCL's flow 
(which is related to another comments below), OpenCL's flow diverge into line 
7957, as shown above, pretty early in the entire checking flow. And 
`OpenCLCheckVectorConditional` do other additional works. Most notably, 
promoting all scalar operands into vector if condition is a vector. I'm not 
sure if we should bring this feature to ext_vector



Comment at: clang/lib/Sema/SemaExpr.cpp:7975
+// condition and result type.
+QualType CondTy = Cond.get()->getType();
+if (CondTy->isExtVectorType()) {

Anastasia wrote:
> Do you know where it is done for OpenCL? I think we should try to share the 
> same code...
It's inside `OpenCLCheckVectorConditional` function. As I mentioned in earlier 
comment, as long as we agree to bring every OpenCL features/rules regarding 
conditional vectors to ext_vector_type, I'm happy to reuse 
`OpenCLCheckVectorConditional`


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

https://reviews.llvm.org/D80574



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


[PATCH] D80574: [ExtVector] Support ExtVectorType conditional operator

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

Fix document section


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

https://reviews.llvm.org/D80574

Files:
  clang/docs/LanguageExtensions.rst
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Sema/ext_vector_comparisons.c

Index: clang/test/Sema/ext_vector_comparisons.c
===
--- clang/test/Sema/ext_vector_comparisons.c
+++ clang/test/Sema/ext_vector_comparisons.c
@@ -28,3 +28,19 @@
   return vec > vec;  // no-warning
   return vec >= vec; // no-warning
 }
+
+static int4 test3() {
+  int4 i0, i1;
+
+  return i0 > i1 ? i0 : i1; // no-error
+  return i0 ? i0 : i1;  // no-error
+}
+
+static float4 test4() {
+  float4 f0, f1;
+
+  // This would actually generate implicit casting warning
+  // under Weverything flag but we don't really care here
+  return f0 > f1 ? f0 : f1; // no-error
+  return f0 ? f0 : f1;  // expected-error {{arithmetic or pointer type is required}}
+}
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -7480,6 +7480,13 @@
   // C99 6.5.15p2
   if (CondTy->isScalarType()) return false;
 
+  // Only ext vector is allowed
+  if (const auto *VecCondTy = Cond->getType()->getAs()) {
+QualType EleTy = VecCondTy->getElementType();
+if (EleTy->isIntegerType())
+  return false;
+  }
+
   S.Diag(QuestionLoc, diag::err_typecheck_cond_expect_scalar)
 << CondTy << Cond->getSourceRange();
   return true;
@@ -7958,10 +7965,21 @@
 
   // Now check the two expressions.
   if (LHS.get()->getType()->isVectorType() ||
-  RHS.get()->getType()->isVectorType())
-return CheckVectorOperands(LHS, RHS, QuestionLoc, /*isCompAssign*/false,
-   /*AllowBothBool*/true,
-   /*AllowBoolConversions*/false);
+  RHS.get()->getType()->isVectorType()) {
+QualType VecResTy = CheckVectorOperands(LHS, RHS, QuestionLoc,
+/*isCompAssign*/ false,
+/*AllowBothBool*/ true,
+/*AllowBoolConversions*/ false);
+// If the condition is ext vector, we're imposing OpenCL's rule wrt
+// condition and result type.
+QualType CondTy = Cond.get()->getType();
+if (CondTy->isExtVectorType()) {
+  if (VecResTy.isNull() ||
+  checkVectorResult(*this, CondTy, VecResTy, QuestionLoc))
+return QualType();
+}
+return VecResTy;
+  }
 
   QualType ResTy =
   UsualArithmeticConversions(LHS, RHS, QuestionLoc, ACK_Conditional);
Index: clang/lib/CodeGen/CGExprScalar.cpp
===
--- clang/lib/CodeGen/CGExprScalar.cpp
+++ clang/lib/CodeGen/CGExprScalar.cpp
@@ -4431,8 +4431,8 @@
 
   // OpenCL: If the condition is a vector, we can treat this condition like
   // the select function.
-  if (CGF.getLangOpts().OpenCL
-  && condExpr->getType()->isVectorType()) {
+  if ((CGF.getLangOpts().OpenCL && condExpr->getType()->isVectorType()) ||
+  condExpr->getType()->isExtVectorType()) {
 CGF.incrementProfileCounter(E);
 
 llvm::Value *CondV = CGF.EmitScalarExpr(condExpr);
Index: clang/docs/LanguageExtensions.rst
===
--- clang/docs/LanguageExtensions.rst
+++ clang/docs/LanguageExtensions.rst
@@ -478,7 +478,7 @@
 !, &&, ||yes --yes [#]_--
 ==, !=, >, <, >=, <= yes yes   yes --
 =yes yes   yes yes
-:? [#]_  yes --yes --
+?: [#]_  yes --yes --
 sizeof   yes yes   yes yes
 C-style cast yes yes   yes no
 reinterpret_cast yes noyes no
@@ -489,9 +489,11 @@
 See also :ref:`langext-__builtin_shufflevector`, :ref:`langext-__builtin_convertvector`.
 
 .. [#] unary operator ! is not implemented, however && and || are.
-.. [#] While OpenCL and GCC vectors both implement the comparison operator(?:) as a
-  'select', they operate somewhat differently. OpenCL selects based on signedness of
-  the condition operands, but GCC vectors use normal bool conversions (that is, != 0).
+.. [#] ternary operator(?:) has different behaviors depending on condition
+  operand's vector type. If the condition is a GNU vector (i.e. __vector_size__),
+  it's only available in C++ and uses normal bool conversions (that is, != 0).
+  If it's an extension (OpenCL) vector, it's only available in C and OpenCL C.
+  And it selects base on signedness of the condition operands.
 
 Matrix Types
 

[PATCH] D80574: [ExtVector] Support ExtVectorType conditional operator

2020-05-28 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu updated this revision to Diff 267027.

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

https://reviews.llvm.org/D80574

Files:
  clang/docs/LanguageExtensions.rst
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Sema/ext_vector_comparisons.c

Index: clang/test/Sema/ext_vector_comparisons.c
===
--- clang/test/Sema/ext_vector_comparisons.c
+++ clang/test/Sema/ext_vector_comparisons.c
@@ -28,3 +28,19 @@
   return vec > vec;  // no-warning
   return vec >= vec; // no-warning
 }
+
+static int4 test3() {
+  int4 i0, i1;
+
+  return i0 > i1 ? i0 : i1; // no-error
+  return i0 ? i0 : i1;  // no-error
+}
+
+static float4 test4() {
+  float4 f0, f1;
+
+  // This would actually generate implicit casting warning
+  // under Weverything flag but we don't really care here
+  return f0 > f1 ? f0 : f1; // no-error
+  return f0 ? f0 : f1;  // expected-error {{arithmetic or pointer type is required}}
+}
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -7480,6 +7480,13 @@
   // C99 6.5.15p2
   if (CondTy->isScalarType()) return false;
 
+  // Only ext vector is allowed
+  if (const auto *VecCondTy = Cond->getType()->getAs()) {
+QualType EleTy = VecCondTy->getElementType();
+if (EleTy->isIntegerType())
+  return false;
+  }
+
   S.Diag(QuestionLoc, diag::err_typecheck_cond_expect_scalar)
 << CondTy << Cond->getSourceRange();
   return true;
@@ -7958,10 +7965,21 @@
 
   // Now check the two expressions.
   if (LHS.get()->getType()->isVectorType() ||
-  RHS.get()->getType()->isVectorType())
-return CheckVectorOperands(LHS, RHS, QuestionLoc, /*isCompAssign*/false,
-   /*AllowBothBool*/true,
-   /*AllowBoolConversions*/false);
+  RHS.get()->getType()->isVectorType()) {
+QualType VecResTy = CheckVectorOperands(LHS, RHS, QuestionLoc,
+/*isCompAssign*/ false,
+/*AllowBothBool*/ true,
+/*AllowBoolConversions*/ false);
+// If the condition is ext vector, we're imposing OpenCL's rule wrt
+// condition and result type.
+QualType CondTy = Cond.get()->getType();
+if (CondTy->isExtVectorType()) {
+  if (VecResTy.isNull() ||
+  checkVectorResult(*this, CondTy, VecResTy, QuestionLoc))
+return QualType();
+}
+return VecResTy;
+  }
 
   QualType ResTy =
   UsualArithmeticConversions(LHS, RHS, QuestionLoc, ACK_Conditional);
Index: clang/lib/CodeGen/CGExprScalar.cpp
===
--- clang/lib/CodeGen/CGExprScalar.cpp
+++ clang/lib/CodeGen/CGExprScalar.cpp
@@ -4431,8 +4431,8 @@
 
   // OpenCL: If the condition is a vector, we can treat this condition like
   // the select function.
-  if (CGF.getLangOpts().OpenCL
-  && condExpr->getType()->isVectorType()) {
+  if ((CGF.getLangOpts().OpenCL && condExpr->getType()->isVectorType()) ||
+  condExpr->getType()->isExtVectorType()) {
 CGF.incrementProfileCounter(E);
 
 llvm::Value *CondV = CGF.EmitScalarExpr(condExpr);
Index: clang/docs/LanguageExtensions.rst
===
--- clang/docs/LanguageExtensions.rst
+++ clang/docs/LanguageExtensions.rst
@@ -478,7 +478,7 @@
 !, &&, ||yes --yes [#]_--
 ==, !=, >, <, >=, <= yes yes   yes --
 =yes yes   yes yes
-:? [#]_  yes --yes --
+?: [#]_  yes --yes --
 sizeof   yes yes   yes yes
 C-style cast yes yes   yes no
 reinterpret_cast yes noyes no
@@ -489,9 +489,11 @@
 See also :ref:`langext-__builtin_shufflevector`, :ref:`langext-__builtin_convertvector`.
 
 .. [#] unary operator ! is not implemented, however && and || are.
-.. [#] While OpenCL and GCC vectors both implement the comparison operator(?:) as a
-  'select', they operate somewhat differently. OpenCL selects based on signedness of
-  the condition operands, but GCC vectors use normal bool conversions (that is, != 0).
+.. [#] ternary operator(?:) has different behaviors depending on condition
+  operand's vector type. If the condition is a GNU vector (i.e. __vector_size__),
+  it's only available in C++ and uses normal bool conversions (that is, != 0).
+  If it's an extension (OpenCL) vector, it's only available in C and OpenCL C.
+  And it selects base on signedness of the condition operands (OpenCL v1.1 s6.3.i).
 
 Matrix Types
 

[PATCH] D80574: [ExtVector] Support ExtVectorType conditional operator

2020-05-29 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu marked 2 inline comments as done.
myhsu added inline comments.



Comment at: clang/lib/Sema/SemaExpr.cpp:7484
+  // Only ext vector is allowed
+  if (const auto *VecCondTy = Cond->getType()->getAs()) {
+QualType EleTy = VecCondTy->getElementType();

Anastasia wrote:
> myhsu wrote:
> > Anastasia wrote:
> > > Why do you need this change? I believe OpenCL makes the same restriction.
> > I'm not quite sure what restriction you're referring here. If you're saying 
> > OpenCL only allow ext_vector_type on condition operand, I don't think 
> > that's the case since on line 7956 ~ 7957 of Sema/SemaExpr.cpp :
> > 
> > ```
> > if (getLangOpts().OpenCL && Cond.get()->getType()->isVectorType())
> > return OpenCLCheckVectorConditional(*this, Cond, LHS, RHS, QuestionLoc);
> > ```
> > `isVectorType()` will be true for both GNU vector and ext_vector_type.
> > 
> > Regarding why i add the change here rather than merging with OpenCL's flow 
> > (which is related to another comments below), OpenCL's flow diverge into 
> > line 7957, as shown above, pretty early in the entire checking flow. And 
> > `OpenCLCheckVectorConditional` do other additional works. Most notably, 
> > promoting all scalar operands into vector if condition is a vector. I'm not 
> > sure if we should bring this feature to ext_vector
> > I'm not quite sure what restriction you're referring here. 
> 
> You are restricting the use non-integer vectors in condition, is it not?
> 
> 
> 
> > I'm not sure if we should bring this feature to ext_vector.
> 
> So what is it that you are trying to implement? My initial understanding was 
> that you are just enabling behavior from OpenCL vectors to work in non-OpenCL 
> mode. But you need to deviate from it?
> My initial understanding was that you are just enabling behavior from OpenCL 
> vectors to work in non-OpenCL mode

My initial thoughts was to bring, and only bring, OpenCL-style condition 
operands to ext_vector. Since that's the key to enable some hardware 
accelerations like the Intel AVX example I put in the original proposal.

But maybe I'm too cautious about introducing other OpenCL vector properties to 
ext_vector. After crafting some test cases, I found that there is little to no 
impact on simply using full set of OpenCL vector's semantic rules. So I'll 
update this patch to unify the checks between OpenCL vectors and ext_vector.


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

https://reviews.llvm.org/D80574



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


[PATCH] D80574: [ExtVector] Support ExtVectorType conditional operator

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

Use full set of OpenCL semantic rules for ext_vector_type


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

https://reviews.llvm.org/D80574

Files:
  clang/docs/LanguageExtensions.rst
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Sema/ext_vector_comparisons.c


Index: clang/test/Sema/ext_vector_comparisons.c
===
--- clang/test/Sema/ext_vector_comparisons.c
+++ clang/test/Sema/ext_vector_comparisons.c
@@ -28,3 +28,19 @@
   return vec > vec;  // no-warning
   return vec >= vec; // no-warning
 }
+
+static int4 test3() {
+  int4 i0, i1;
+
+  return i0 > i1 ? i0 : i1; // no-error
+  return i0 ? i0 : i1;  // no-error
+}
+
+static float4 test4() {
+  float4 f0, f1;
+
+  // This would actually generate implicit casting warning
+  // under Weverything flag but we don't really care here
+  return f0 > f1 ? f0 : f1; // no-error
+  return f0 ? f0 : f1;  // expected-error {{used type 'float4' (vector of 
4 'float' values) where floating point type is not allowed}}
+}
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -7946,7 +7946,8 @@
 
   // The OpenCL operator with a vector condition is sufficiently
   // different to merit its own checker.
-  if (getLangOpts().OpenCL && Cond.get()->getType()->isVectorType())
+  if ((getLangOpts().OpenCL && Cond.get()->getType()->isVectorType()) ||
+  Cond.get()->getType()->isExtVectorType())
 return OpenCLCheckVectorConditional(*this, Cond, LHS, RHS, QuestionLoc);
 
   // First, check the condition.
Index: clang/lib/CodeGen/CGExprScalar.cpp
===
--- clang/lib/CodeGen/CGExprScalar.cpp
+++ clang/lib/CodeGen/CGExprScalar.cpp
@@ -4431,8 +4431,8 @@
 
   // OpenCL: If the condition is a vector, we can treat this condition like
   // the select function.
-  if (CGF.getLangOpts().OpenCL
-  && condExpr->getType()->isVectorType()) {
+  if ((CGF.getLangOpts().OpenCL && condExpr->getType()->isVectorType()) ||
+  condExpr->getType()->isExtVectorType()) {
 CGF.incrementProfileCounter(E);
 
 llvm::Value *CondV = CGF.EmitScalarExpr(condExpr);
Index: clang/docs/LanguageExtensions.rst
===
--- clang/docs/LanguageExtensions.rst
+++ clang/docs/LanguageExtensions.rst
@@ -478,7 +478,7 @@
 !, &&, ||yes --yes [#]_--
 ==, !=, >, <, >=, <= yes yes   yes --
 =yes yes   yes yes
-:? [#]_  yes --yes --
+?: [#]_  yes --yes --
 sizeof   yes yes   yes yes
 C-style cast yes yes   yes no
 reinterpret_cast yes noyes no
@@ -489,9 +489,11 @@
 See also :ref:`langext-__builtin_shufflevector`, 
:ref:`langext-__builtin_convertvector`.
 
 .. [#] unary operator ! is not implemented, however && and || are.
-.. [#] While OpenCL and GCC vectors both implement the comparison operator(?:) 
as a
-  'select', they operate somewhat differently. OpenCL selects based on 
signedness of
-  the condition operands, but GCC vectors use normal bool conversions (that 
is, != 0).
+.. [#] ternary operator(?:) has different behaviors depending on condition
+  operand's vector type. If the condition is a GNU vector (i.e. 
__vector_size__),
+  it's only available in C++ and uses normal bool conversions (that is, != 0).
+  If it's an extension (OpenCL) vector, it's only available in C and OpenCL C.
+  And it selects base on signedness of the condition operands (OpenCL v1.1 
s6.3.i).
 
 Matrix Types
 


Index: clang/test/Sema/ext_vector_comparisons.c
===
--- clang/test/Sema/ext_vector_comparisons.c
+++ clang/test/Sema/ext_vector_comparisons.c
@@ -28,3 +28,19 @@
   return vec > vec;  // no-warning
   return vec >= vec; // no-warning
 }
+
+static int4 test3() {
+  int4 i0, i1;
+
+  return i0 > i1 ? i0 : i1; // no-error
+  return i0 ? i0 : i1;  // no-error
+}
+
+static float4 test4() {
+  float4 f0, f1;
+
+  // This would actually generate implicit casting warning
+  // under Weverything flag but we don't really care here
+  return f0 > f1 ? f0 : f1; // no-error
+  return f0 ? f0 : f1;  // expected-error {{used type 'float4' (vector of 4 'float' values) where floating point type is not allowed}}
+}
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -7946,7 +7946,8 @@
 
   // The OpenCL oper

[PATCH] D80574: [ExtVector] Support ExtVectorType conditional operator

2020-06-02 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu added a comment.

Thank you @Anastasia !


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

https://reviews.llvm.org/D80574



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


[PATCH] D80574: [ExtVector] Support ExtVectorType conditional operator

2020-06-02 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu added a comment.

> Btw does your change fix this bug:
>  https://bugs.llvm.org/show_bug.cgi?id=33103

As mentioned in the description, this patch only affect C code not C++ code. So 
strictly speaking this patch doesn't fix the bug, but if the same code attached 
in the bug report is compiled as C code it will pass.


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

https://reviews.llvm.org/D80574



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


[PATCH] D80574: [ExtVector] Support ExtVectorType conditional operator

2020-06-02 Thread Min-Yih Hsu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4431d64c10cb: Support ExtVectorType conditional operator 
(authored by myhsu).

Changed prior to commit:
  https://reviews.llvm.org/D80574?vs=267277&id=267913#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80574

Files:
  clang/docs/LanguageExtensions.rst
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Sema/ext_vector_comparisons.c


Index: clang/test/Sema/ext_vector_comparisons.c
===
--- clang/test/Sema/ext_vector_comparisons.c
+++ clang/test/Sema/ext_vector_comparisons.c
@@ -28,3 +28,19 @@
   return vec > vec;  // no-warning
   return vec >= vec; // no-warning
 }
+
+static int4 test3() {
+  int4 i0, i1;
+
+  return i0 > i1 ? i0 : i1; // no-error
+  return i0 ? i0 : i1;  // no-error
+}
+
+static float4 test4() {
+  float4 f0, f1;
+
+  // This would actually generate implicit casting warning
+  // under Weverything flag but we don't really care here
+  return f0 > f1 ? f0 : f1; // no-error
+  return f0 ? f0 : f1;  // expected-error {{used type 'float4' (vector of 
4 'float' values) where floating point type is not allowed}}
+}
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -8078,7 +8078,8 @@
 
   // The OpenCL operator with a vector condition is sufficiently
   // different to merit its own checker.
-  if (getLangOpts().OpenCL && Cond.get()->getType()->isVectorType())
+  if ((getLangOpts().OpenCL && Cond.get()->getType()->isVectorType()) ||
+  Cond.get()->getType()->isExtVectorType())
 return OpenCLCheckVectorConditional(*this, Cond, LHS, RHS, QuestionLoc);
 
   // First, check the condition.
Index: clang/lib/CodeGen/CGExprScalar.cpp
===
--- clang/lib/CodeGen/CGExprScalar.cpp
+++ clang/lib/CodeGen/CGExprScalar.cpp
@@ -4432,8 +4432,8 @@
 
   // OpenCL: If the condition is a vector, we can treat this condition like
   // the select function.
-  if (CGF.getLangOpts().OpenCL
-  && condExpr->getType()->isVectorType()) {
+  if ((CGF.getLangOpts().OpenCL && condExpr->getType()->isVectorType()) ||
+  condExpr->getType()->isExtVectorType()) {
 CGF.incrementProfileCounter(E);
 
 llvm::Value *CondV = CGF.EmitScalarExpr(condExpr);
Index: clang/docs/LanguageExtensions.rst
===
--- clang/docs/LanguageExtensions.rst
+++ clang/docs/LanguageExtensions.rst
@@ -478,7 +478,7 @@
 !, &&, ||yes --yes [#]_--
 ==, !=, >, <, >=, <= yes yes   yes --
 =yes yes   yes yes
-:? [#]_  yes --yes --
+?: [#]_  yes --yes --
 sizeof   yes yes   yes yes
 C-style cast yes yes   yes no
 reinterpret_cast yes noyes no
@@ -489,9 +489,11 @@
 See also :ref:`langext-__builtin_shufflevector`, 
:ref:`langext-__builtin_convertvector`.
 
 .. [#] unary operator ! is not implemented, however && and || are.
-.. [#] While OpenCL and GCC vectors both implement the comparison operator(?:) 
as a
-  'select', they operate somewhat differently. OpenCL selects based on 
signedness of
-  the condition operands, but GCC vectors use normal bool conversions (that 
is, != 0).
+.. [#] ternary operator(?:) has different behaviors depending on condition
+  operand's vector type. If the condition is a GNU vector (i.e. 
__vector_size__),
+  it's only available in C++ and uses normal bool conversions (that is, != 0).
+  If it's an extension (OpenCL) vector, it's only available in C and OpenCL C.
+  And it selects base on signedness of the condition operands (OpenCL v1.1 
s6.3.9).
 
 Matrix Types
 


Index: clang/test/Sema/ext_vector_comparisons.c
===
--- clang/test/Sema/ext_vector_comparisons.c
+++ clang/test/Sema/ext_vector_comparisons.c
@@ -28,3 +28,19 @@
   return vec > vec;  // no-warning
   return vec >= vec; // no-warning
 }
+
+static int4 test3() {
+  int4 i0, i1;
+
+  return i0 > i1 ? i0 : i1; // no-error
+  return i0 ? i0 : i1;  // no-error
+}
+
+static float4 test4() {
+  float4 f0, f1;
+
+  // This would actually generate implicit casting warning
+  // under Weverything flag but we don't really care here
+  return f0 > f1 ? f0 : f1; // no-error
+  return f0 ? f0 : f1;  // expected-error {{used type 'float4' (vector of 4 'float' values) where floating point type is not allowed}}
+}
Index: clang/lib/Sema/SemaExpr.cpp
=

[PATCH] D128157: [clang-tidy] cppcoreguidelines-virtual-class-destructor: Fix crash when "virtual" keyword is expanded from a macro

2022-06-27 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu added a comment.

> I pushed this change, but for some reason phabricator doesn't show it and 
> close the review... I wonder if it's because I rebased it?

You forgot to add 

 "Differential Revison: https://reviews.llvm.org/DXX";, which is how 
Phabricator identifies the differential to close. I don't think it has anything 
to do with rebasing.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128157

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


[PATCH] D104439: [analyzer][NFC] Demonstrate a move from the analyzer-configs `.def` file to a TableGen file

2022-05-01 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu added a comment.

Just curious: Have you considered using llvm::opt or even llvm::cl 
infrastructure? What are the pros & cons?




Comment at: clang/utils/TableGen/ClangSAConfigsEmitter.cpp:24
+
+using SortedRecords = llvm::StringMap;
+





Comment at: clang/utils/TableGen/ClangSAConfigsEmitter.cpp:32
+  OS.write_escaped(R->getValueAsString("HelpText")) << "\",";
+  StringRef DefaultVal = R->getValueAsString("DefaultVal");
+

I'm not an expert in clang-analyzer, but can `DefaultVal` be optional in an 
analyzer config? It you want it to be optional -- which, I think, also makes 
the TableGen file more concise -- you can use 
`Record::getValueasOptionalString` instead.



Comment at: clang/utils/TableGen/ClangSAConfigsEmitter.cpp:57
+
+  OS << "// This file is automatically generated. Do not edit this file by "
+"hand.\n";

Please use `llvm::emitSourceFileHeader` (in llvm/TableGen/TableGenBackend.h)



Comment at: clang/utils/TableGen/ClangSAConfigsEmitter.cpp:76
+OS << "BOOLEAN_OPTION(bool,";
+printOptionFields(R, OS, /*IsDefaultValString*/false);
+OS << ")\n";

IIRC usually we will also write /*IsDefaultValString=*/



Comment at: clang/utils/TableGen/ClangSAConfigsEmitter.cpp:140
+}
+OS << ")\n";
+  }

if `R->isValueUnset("Values")` returns true, the resulting code will have a 
trailing comma just right before the right brace:
```
ENUM_OPTION(Foo, Foo, "bar", "...",)
```
which I don't think is valid for C/C++ macro.
Please use `llvm::ListSeparator`(in StringExtras.h) to print commas instead.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104439

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


[PATCH] D88393: [cfe][M68K] (Patch 7/8) Basic Clang support

2020-09-27 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu created this revision.
Herald added subscribers: cfe-commits, mgorny.
Herald added a reviewer: aaron.ballman.
Herald added a project: clang.
myhsu requested review of this revision.

1. Add M68K as new Clang target
2. Add new attribute to support M68K's ISR (Interrupt Service Routine)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D88393

Files:
  clang/include/clang/Basic/Attr.td
  clang/lib/Basic/CMakeLists.txt
  clang/lib/Basic/Targets.cpp
  clang/lib/Basic/Targets/M680x0.cpp
  clang/lib/Basic/Targets/M680x0.h
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/Sema/SemaDeclAttr.cpp

Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -5797,6 +5797,39 @@
   D->addAttr(::new (S.Context) MipsInterruptAttr(S.Context, AL, Kind));
 }
 
+static void handleM680x0InterruptAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
+  if (!checkAttributeNumArgs(S, AL, 1))
+return;
+
+  if (!AL.isArgExpr(0)) {
+S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
+<< AL << AANT_ArgumentIntegerConstant;
+return;
+  }
+
+  // FIXME: Check for decl - it should be void ()(void).
+
+  Expr *NumParamsExpr = static_cast(AL.getArgAsExpr(0));
+  auto MaybeNumParams = NumParamsExpr->getIntegerConstantExpr(S.Context);
+  if (!MaybeNumParams) {
+S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
+<< AL << AANT_ArgumentIntegerConstant
+<< NumParamsExpr->getSourceRange();
+return;
+  }
+
+  unsigned Num = MaybeNumParams->getLimitedValue(255);
+  if ((Num & 1) || Num > 30) {
+S.Diag(AL.getLoc(), diag::err_attribute_argument_out_of_bounds)
+<< AL << (int)MaybeNumParams->getSExtValue()
+<< NumParamsExpr->getSourceRange();
+return;
+  }
+
+  D->addAttr(::new (S.Context) M680x0InterruptAttr(S.Context, AL, Num));
+  D->addAttr(UsedAttr::CreateImplicit(S.Context));
+}
+
 static void handleAnyX86InterruptAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
   // Semantic checks for a function with the 'interrupt' attribute.
   // a) Must be a function.
@@ -6069,6 +6102,9 @@
   case llvm::Triple::mips:
 handleMipsInterruptAttr(S, D, AL);
 break;
+  case llvm::Triple::m680x0:
+handleM680x0InterruptAttr(S, D, AL);
+break;
   case llvm::Triple::x86:
   case llvm::Triple::x86_64:
 handleAnyX86InterruptAttr(S, D, AL);
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -8064,6 +8064,46 @@
   return false;
 }
 
+//===--===//
+// M680x0 ABI Implementation
+//===--===//
+
+namespace {
+
+class M680x0TargetCodeGenInfo : public TargetCodeGenInfo {
+public:
+  M680x0TargetCodeGenInfo(CodeGenTypes &CGT)
+: TargetCodeGenInfo(std::make_unique(CGT)) {}
+  void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
+   CodeGen::CodeGenModule &M) const override;
+};
+
+}
+
+// TODO Does not actually work right now
+void M680x0TargetCodeGenInfo::
+setTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
+CodeGen::CodeGenModule &M) const {
+  if (const FunctionDecl *FD = dyn_cast_or_null(D)) {
+if (const M680x0InterruptAttr *attr = FD->getAttr()) {
+  // Handle 'interrupt' attribute:
+  llvm::Function *F = cast(GV);
+
+  // Step 1: Set ISR calling convention.
+  F->setCallingConv(llvm::CallingConv::M680x0_INTR);
+
+  // Step 2: Add attributes goodness.
+  F->addFnAttr(llvm::Attribute::NoInline);
+
+  // ??? is this right
+  // Step 3: Emit ISR vector alias.
+  unsigned Num = attr->getNumber() / 2;
+  llvm::GlobalAlias::create(llvm::Function::ExternalLinkage,
+"__isr_" + Twine(Num), F);
+}
+  }
+}
+
 //===--===//
 // AVR ABI Implementation.
 //===--===//
Index: clang/lib/Basic/Targets/M680x0.h
===
--- /dev/null
+++ clang/lib/Basic/Targets/M680x0.h
@@ -0,0 +1,58 @@
+//===--- M680x0.h - Declare M680x0 target feature support ---*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// This file declares M680x0 TargetInfo objects.
+//
+//===--===//
+
+#ifndef M680X0_H_LTNCIPAD
+#define M680X0_H_LTNCIPAD
+
+#include "OSTargets.h"
+#include "clang/Basi

[PATCH] D88394: [Driver][M68K] (Patch 8/8) Add driver support for M68K

2020-09-27 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu created this revision.
Herald added subscribers: cfe-commits, dang, mgorny.
Herald added a project: clang.
myhsu requested review of this revision.
Herald added a subscriber: ormris.

Add new toolchain and driver options for the M680x0 target


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D88394

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/CMakeLists.txt
  clang/lib/Driver/ToolChains/Arch/M680x0.cpp
  clang/lib/Driver/ToolChains/Arch/M680x0.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/lib/Driver/ToolChains/Linux.cpp
  clang/test/Driver/m680x0-features.cpp
  clang/test/Driver/m680x0-sub-archs.cpp

Index: clang/test/Driver/m680x0-sub-archs.cpp
===
--- /dev/null
+++ clang/test/Driver/m680x0-sub-archs.cpp
@@ -0,0 +1,23 @@
+// RUN: %clang -### -target m680x0-unknown-linux -mcpu=68000 %s 2>&1 | FileCheck --check-prefix=CHECK-MX00 %s
+// RUN: %clang -### -target m680x0-unknown-linux -m68000 %s 2>&1 | FileCheck --check-prefix=CHECK-MX00 %s
+// CHECK-MX00: "-target-cpu" "68000"
+
+// RUN: %clang -### -target m680x0-unknown-linux -mcpu=68010 %s 2>&1 | FileCheck --check-prefix=CHECK-MX10 %s
+// RUN: %clang -### -target m680x0-unknown-linux -m68010 %s 2>&1 | FileCheck --check-prefix=CHECK-MX10 %s
+// CHECK-MX10: "-target-cpu" "68010"
+
+// RUN: %clang -### -target m680x0-unknown-linux -mcpu=68020 %s 2>&1 | FileCheck --check-prefix=CHECK-MX20 %s
+// RUN: %clang -### -target m680x0-unknown-linux -m68020 %s 2>&1 | FileCheck --check-prefix=CHECK-MX20 %s
+// CHECK-MX20: "-target-cpu" "68020"
+
+// RUN: %clang -### -target m680x0-unknown-linux -mcpu=68030 %s 2>&1 | FileCheck --check-prefix=CHECK-MX30 %s
+// RUN: %clang -### -target m680x0-unknown-linux -m68030 %s 2>&1 | FileCheck --check-prefix=CHECK-MX30 %s
+// CHECK-MX30: "-target-cpu" "68030"
+
+// RUN: %clang -### -target m680x0-unknown-linux -mcpu=68040 %s 2>&1 | FileCheck --check-prefix=CHECK-MX40 %s
+// RUN: %clang -### -target m680x0-unknown-linux -m68040 %s 2>&1 | FileCheck --check-prefix=CHECK-MX40 %s
+// CHECK-MX40: "-target-cpu" "68040"
+
+// RUN: %clang -### -target m680x0-unknown-linux -mcpu=68060 %s 2>&1 | FileCheck --check-prefix=CHECK-MX60 %s
+// RUN: %clang -### -target m680x0-unknown-linux -m68060 %s 2>&1 | FileCheck --check-prefix=CHECK-MX60 %s
+// CHECK-MX60: "-target-cpu" "68060"
Index: clang/test/Driver/m680x0-features.cpp
===
--- /dev/null
+++ clang/test/Driver/m680x0-features.cpp
@@ -0,0 +1,45 @@
+// Check macro definitions
+// RUN: %clang -target m680x0-unknown-linux -m68000 -dM -E %s | FileCheck --check-prefix=CHECK-MX %s
+// CHECK-MX: #define __mc68000 1
+// CHECK-MX: #define __mc68000__ 1
+// CHECK-MX: #define mc68000 1
+
+// RUN: %clang -target m680x0-unknown-linux -m68010 -dM -E %s | FileCheck --check-prefix=CHECK-MX10 %s
+// CHECK-MX10: #define __mc68000 1
+// CHECK-MX10: #define __mc68000__ 1
+// CHECK-MX10: #define __mc68010 1
+// CHECK-MX10: #define __mc68010__ 1
+// CHECK-MX10: #define mc68000 1
+// CHECK-MX10: #define mc68010 1
+
+// RUN: %clang -target m680x0-unknown-linux -m68020 -dM -E %s | FileCheck --check-prefix=CHECK-MX20 %s
+// CHECK-MX20: #define __mc68000 1
+// CHECK-MX20: #define __mc68000__ 1
+// CHECK-MX20: #define __mc68020 1
+// CHECK-MX20: #define __mc68020__ 1
+// CHECK-MX20: #define mc68000 1
+// CHECK-MX20: #define mc68020 1
+
+// RUN: %clang -target m680x0-unknown-linux -m68030 -dM -E %s | FileCheck --check-prefix=CHECK-MX30 %s
+// CHECK-MX30: #define __mc68000 1
+// CHECK-MX30: #define __mc68000__ 1
+// CHECK-MX30: #define __mc68030 1
+// CHECK-MX30: #define __mc68030__ 1
+// CHECK-MX30: #define mc68000 1
+// CHECK-MX30: #define mc68030 1
+
+// RUN: %clang -target m680x0-unknown-linux -m68040 -dM -E %s | FileCheck --check-prefix=CHECK-MX40 %s
+// CHECK-MX40: #define __mc68000 1
+// CHECK-MX40: #define __mc68000__ 1
+// CHECK-MX40: #define __mc68040 1
+// CHECK-MX40: #define __mc68040__ 1
+// CHECK-MX40: #define mc68000 1
+// CHECK-MX40: #define mc68040 1
+
+// RUN: %clang -target m680x0-unknown-linux -m68060 -dM -E %s | FileCheck --check-prefix=CHECK-MX60 %s
+// CHECK-MX60: #define __mc68000 1
+// CHECK-MX60: #define __mc68000__ 1
+// CHECK-MX60: #define __mc68060 1
+// CHECK-MX60: #define __mc68060__ 1
+// CHECK-MX60: #define mc68000 1
+// CHECK-MX60: #define mc68060 1
Index: clang/lib/Driver/ToolChains/Linux.cpp
===
--- clang/lib/Driver/ToolChains/Linux.cpp
+++ clang/lib/Driver/ToolChains/Linux.cpp
@@ -102,6 +102,12 @@
 if (D.getVFS().exists(SysRoot + "/lib/aarch64_be-linux-gnu"))
   return "aarch64_be-linux-gnu";
 break;
+
+  case llvm::Triple::m680x0:
+if (D.getVFS().exists(SysRoot + "/lib/m68k-linux-gnu"))
+  return "m68k-linux-gnu";
+break;
+
   case llvm::Triple::mi

[PATCH] D87338: [Driver][PGO] Driver support for de-Optimizing cold functions (PATCH 2/2)

2020-09-08 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu created this revision.
myhsu added reviewers: rsmith, bogner, xur.
Herald added subscribers: cfe-commits, wenlei, dang, dexonsmith, steven_wu, 
hiraditya.
Herald added a project: clang.
myhsu requested review of this revision.

Following up https://reviews.llvm.org/D87337 . This patch add the driver 
support to propogate `-fprofile-deopt-cold` and 
`-fprofile-deopt-cold-percent=` flags to codegen and the LTO plugin.

authors: myhsu, probinson, and edd


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D87338

Files:
  clang/docs/ClangCommandLineReference.rst
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/Driver/deopt-cold-funcs.c
  clang/test/Driver/gold-lto-deopt-cold-funcs.c

Index: clang/test/Driver/gold-lto-deopt-cold-funcs.c
===
--- /dev/null
+++ clang/test/Driver/gold-lto-deopt-cold-funcs.c
@@ -0,0 +1,11 @@
+// RUN: touch %t.o
+//
+// RUN: %clang -### -fprofile-instr-use -fprofile-deopt-cold %t.o -flto 2>&1 \
+// RUN: | FileCheck --check-prefix=CHECK-BASE %s
+
+// RUN: %clang -### -fprofile-instr-use -fprofile-deopt-cold -fprofile-deopt-cold-percent=87 \
+// RUN: %t.o -flto 2>&1 \
+// RUN: | FileCheck --check-prefixes=CHECK-BASE,CHECK-PERCENT %s
+
+// CHECK-BASE: "-plugin-opt=-profile-deopt-cold=true"
+// CHECK-PERCENT: "-plugin-opt=-profile-deopt-cold-percent=87"
Index: clang/test/Driver/deopt-cold-funcs.c
===
--- /dev/null
+++ clang/test/Driver/deopt-cold-funcs.c
@@ -0,0 +1,15 @@
+// RUN: %clang -### -fprofile-instr-use -fprofile-deopt-cold -c %s 2>&1 \
+// RUN: | FileCheck --check-prefix=CHECK-BASE %s
+
+// RUN: %clang -### -fprofile-instr-use \
+// RUN: -fprofile-deopt-cold -fprofile-deopt-cold-percent=87 \
+// RUN: -c %s 2>&1 \
+// RUN: | FileCheck --check-prefixes=CHECK-BASE,CHECK-PERCENT %s
+
+// Shouldn't do anything if it's not using PGO profile
+// RUN: %clang -### -fprofile-deopt-cold -c %s 2>&1 \
+// RUN: | FileCheck --check-prefix=CHECK-NO-PGO %s
+
+// CHECK-BASE: "-mllvm" "-profile-deopt-cold=true"
+// CHECK-PERCENT: "-mllvm" "-profile-deopt-cold-percent=87"
+// CHECK-NO-PGO-NOT: "-profile-deopt-cold=true"
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -516,6 +516,16 @@
   llvm::sys::path::append(Path, "default.profdata");
 CmdArgs.push_back(Args.MakeArgString(Twine("-plugin-opt=cs-profile-path=") +
  Path));
+// Propagate -profile-deopt-cold options
+if (Args.hasFlag(options::OPT_fprofile_deopt_cold,
+ options::OPT_fno_profile_deopt_cold, false)) {
+  CmdArgs.push_back("-plugin-opt=-profile-deopt-cold=true");
+  Arg *A = Args.getLastArg(options::OPT_fprofile_deopt_cold_percent_EQ);
+  if (A) {
+CmdArgs.push_back(Args.MakeArgString(
+Twine("-plugin-opt=-profile-deopt-cold-percent=") + A->getValue()));
+  }
+}
   }
 
   // Need this flag to turn on new pass manager via Gold plugin.
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -824,6 +824,19 @@
   CmdArgs.push_back(
   Args.MakeArgString(Twine("-fprofile-instrument-use-path=") + Path));
 }
+// Tell profile passes to deopt cold functions.
+if (Args.hasFlag(options::OPT_fprofile_deopt_cold,
+ options::OPT_fno_profile_deopt_cold)) {
+  CmdArgs.push_back("-mllvm");
+  CmdArgs.push_back("-profile-deopt-cold=true");
+
+  if (Arg *A =
+  Args.getLastArg(options::OPT_fprofile_deopt_cold_percent_EQ)) {
+CmdArgs.push_back("-mllvm");
+CmdArgs.push_back(Args.MakeArgString(
+Twine("-profile-deopt-cold-percent=") + A->getValue()));
+  }
+}
   }
 
   bool EmitCovNotes = Args.hasFlag(options::OPT_ftest_coverage,
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -793,6 +793,17 @@
 Alias;
 defm debug_info_for_profiling : OptInFFlag<"debug-info-for-profiling",
   "Emit extra debug info to make sample profile more accurate">;
+
+// New option to deopt cold code.
+def fprofile_deopt_cold : Flag<["-"], "fprofile-deopt-cold">,
+Group, Flags<[CoreOption]>,
+HelpText<"Do not optimize functions that profiling indicates are cold">;
+def fno_profile_deopt_cold : Flag<["-"], "fno-profile-deopt-cold">,
+Group, Flags<[CoreOption]>;
+def fprofile_deopt_cold_percent_EQ : Joined<["-"], "fprofile-deopt-cold

[PATCH] D87338: [Driver][PGO] Driver support for de-Optimizing cold functions (PATCH 2/2)

2020-09-09 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu updated this revision to Diff 290769.
myhsu added a comment.

Fix a bug in driver that accidentally made this feature turn on by default


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

https://reviews.llvm.org/D87338

Files:
  clang/docs/ClangCommandLineReference.rst
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/Driver/deopt-cold-funcs.c
  clang/test/Driver/gold-lto-deopt-cold-funcs.c

Index: clang/test/Driver/gold-lto-deopt-cold-funcs.c
===
--- /dev/null
+++ clang/test/Driver/gold-lto-deopt-cold-funcs.c
@@ -0,0 +1,11 @@
+// RUN: touch %t.o
+//
+// RUN: %clang -### -fprofile-instr-use -fprofile-deopt-cold %t.o -flto 2>&1 \
+// RUN: | FileCheck --check-prefix=CHECK-BASE %s
+
+// RUN: %clang -### -fprofile-instr-use -fprofile-deopt-cold -fprofile-deopt-cold-percent=87 \
+// RUN: %t.o -flto 2>&1 \
+// RUN: | FileCheck --check-prefixes=CHECK-BASE,CHECK-PERCENT %s
+
+// CHECK-BASE: "-plugin-opt=-profile-deopt-cold=true"
+// CHECK-PERCENT: "-plugin-opt=-profile-deopt-cold-percent=87"
Index: clang/test/Driver/deopt-cold-funcs.c
===
--- /dev/null
+++ clang/test/Driver/deopt-cold-funcs.c
@@ -0,0 +1,15 @@
+// RUN: %clang -### -fprofile-instr-use -fprofile-deopt-cold -c %s 2>&1 \
+// RUN: | FileCheck --check-prefix=CHECK-BASE %s
+
+// RUN: %clang -### -fprofile-instr-use \
+// RUN: -fprofile-deopt-cold -fprofile-deopt-cold-percent=87 \
+// RUN: -c %s 2>&1 \
+// RUN: | FileCheck --check-prefixes=CHECK-BASE,CHECK-PERCENT %s
+
+// Shouldn't do anything if it's not using PGO profile
+// RUN: %clang -### -fprofile-deopt-cold -c %s 2>&1 \
+// RUN: | FileCheck --check-prefix=CHECK-NO-PGO %s
+
+// CHECK-BASE: "-mllvm" "-profile-deopt-cold=true"
+// CHECK-PERCENT: "-mllvm" "-profile-deopt-cold-percent=87"
+// CHECK-NO-PGO-NOT: "-profile-deopt-cold=true"
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -516,6 +516,16 @@
   llvm::sys::path::append(Path, "default.profdata");
 CmdArgs.push_back(Args.MakeArgString(Twine("-plugin-opt=cs-profile-path=") +
  Path));
+// Propagate -profile-deopt-cold options
+if (Args.hasFlag(options::OPT_fprofile_deopt_cold,
+ options::OPT_fno_profile_deopt_cold, false)) {
+  CmdArgs.push_back("-plugin-opt=-profile-deopt-cold=true");
+  Arg *A = Args.getLastArg(options::OPT_fprofile_deopt_cold_percent_EQ);
+  if (A) {
+CmdArgs.push_back(Args.MakeArgString(
+Twine("-plugin-opt=-profile-deopt-cold-percent=") + A->getValue()));
+  }
+}
   }
 
   // Need this flag to turn on new pass manager via Gold plugin.
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -824,6 +824,19 @@
   CmdArgs.push_back(
   Args.MakeArgString(Twine("-fprofile-instrument-use-path=") + Path));
 }
+// Tell profile passes to deopt cold functions.
+if (Args.hasFlag(options::OPT_fprofile_deopt_cold,
+ options::OPT_fno_profile_deopt_cold, false)) {
+  CmdArgs.push_back("-mllvm");
+  CmdArgs.push_back("-profile-deopt-cold=true");
+
+  if (Arg *A =
+  Args.getLastArg(options::OPT_fprofile_deopt_cold_percent_EQ)) {
+CmdArgs.push_back("-mllvm");
+CmdArgs.push_back(Args.MakeArgString(
+Twine("-profile-deopt-cold-percent=") + A->getValue()));
+  }
+}
   }
 
   bool EmitCovNotes = Args.hasFlag(options::OPT_ftest_coverage,
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -793,6 +793,17 @@
 Alias;
 defm debug_info_for_profiling : OptInFFlag<"debug-info-for-profiling",
   "Emit extra debug info to make sample profile more accurate">;
+
+// New option to deopt cold code.
+def fprofile_deopt_cold : Flag<["-"], "fprofile-deopt-cold">,
+Group, Flags<[CoreOption]>,
+HelpText<"Do not optimize functions that profiling indicates are cold">;
+def fno_profile_deopt_cold : Flag<["-"], "fno-profile-deopt-cold">,
+Group, Flags<[CoreOption]>;
+def fprofile_deopt_cold_percent_EQ : Joined<["-"], "fprofile-deopt-cold-percent=">,
+Group, Flags<[CoreOption]>,
+HelpText<"Do not optimize functions whose profiling count is lower than this percentage">;
+
 def fprofile_instr_generate : Flag<["-"], "fprofile-instr-generate">,
 Group, Flags<[CoreOption]>,
 HelpText<"Generate instrumented 

[PATCH] D87338: [Driver][PGO] Driver support for de-Optimizing cold functions (PATCH 2/2)

2020-09-09 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu updated this revision to Diff 290849.
myhsu edited the summary of this revision.
myhsu added a comment.

Unified driver options from "-fprofile-deopt-cold-*" into 
"-fprofile-omit-cold-opt" and "-fprofile-omit-cold-opt=". Where the 
former one is just a shorthand of "-fprofile-omit-cold-opt=0"


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

https://reviews.llvm.org/D87338

Files:
  clang/docs/ClangCommandLineReference.rst
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/Driver/gold-lto-omit-cold-opt.c
  clang/test/Driver/omit-cold-opt.c

Index: clang/test/Driver/omit-cold-opt.c
===
--- /dev/null
+++ clang/test/Driver/omit-cold-opt.c
@@ -0,0 +1,20 @@
+// RUN: %clang -### -fprofile-instr-use -fprofile-omit-cold-opt -c %s 2>&1 \
+// RUN: | FileCheck --check-prefix=CHECK-BASE %s
+
+// RUN: %clang -### -fprofile-instr-use \
+// RUN: -fprofile-omit-cold-opt=87 \
+// RUN: -c %s 2>&1 \
+// RUN: | FileCheck --check-prefixes=CHECK-BASE,CHECK-PERCENT %s
+
+// RUN: %clang -### -fprofile-instr-use \
+// RUN: -fprofile-omit-cold-opt -fno-profile-omit-cold-opt \
+// RUN: -c %s 2>&1 \
+// RUN: | FileCheck --check-prefix=CHECK-NEG %s
+
+// Shouldn't do anything if it's not using PGO profile
+// RUN: %clang -### -fprofile-omit-cold-opt -c %s 2>&1 \
+// RUN: | FileCheck --check-prefix=CHECK-NEG %s
+
+// CHECK-BASE: "-mllvm" "-profile-omit-cold-func-opt=true"
+// CHECK-PERCENT: "-mllvm" "-profile-omit-cold-func-opt-percent=87"
+// CHECK-NEG-NOT: "-profile-omit-cold-func-opt=true"
Index: clang/test/Driver/gold-lto-omit-cold-opt.c
===
--- /dev/null
+++ clang/test/Driver/gold-lto-omit-cold-opt.c
@@ -0,0 +1,11 @@
+// RUN: touch %t.o
+//
+// RUN: %clang -### -fprofile-instr-use -fprofile-omit-cold-opt %t.o -flto 2>&1 \
+// RUN: | FileCheck --check-prefix=CHECK-BASE %s
+
+// RUN: %clang -### -fprofile-instr-use -fprofile-omit-cold-opt=87 \
+// RUN: %t.o -flto 2>&1 \
+// RUN: | FileCheck --check-prefixes=CHECK-BASE,CHECK-PERCENT %s
+
+// CHECK-BASE: "-plugin-opt=-profile-omit-cold-func-opt=true"
+// CHECK-PERCENT: "-plugin-opt=-profile-omit-cold-func-opt-percent=87"
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -516,6 +516,18 @@
   llvm::sys::path::append(Path, "default.profdata");
 CmdArgs.push_back(Args.MakeArgString(Twine("-plugin-opt=cs-profile-path=") +
  Path));
+// Propagate -profile-omit-cold-func-opt options
+if (Args.hasFlag(options::OPT_fprofile_omit_cold_opt,
+ options::OPT_fprofile_omit_cold_opt_EQ,
+ options::OPT_fno_profile_omit_cold_opt, false)) {
+  CmdArgs.push_back("-plugin-opt=-profile-omit-cold-func-opt=true");
+  Arg *A = Args.getLastArg(options::OPT_fprofile_omit_cold_opt_EQ);
+  if (A) {
+CmdArgs.push_back(Args.MakeArgString(
+Twine("-plugin-opt=-profile-omit-cold-func-opt-percent=") +
+A->getValue()));
+  }
+}
   }
 
   // Need this flag to turn on new pass manager via Gold plugin.
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -824,6 +824,19 @@
   CmdArgs.push_back(
   Args.MakeArgString(Twine("-fprofile-instrument-use-path=") + Path));
 }
+// Tell profile passes to avoid optimizing cold functions.
+if (Args.hasFlag(options::OPT_fprofile_omit_cold_opt,
+ options::OPT_fprofile_omit_cold_opt_EQ,
+ options::OPT_fno_profile_omit_cold_opt, false)) {
+  CmdArgs.push_back("-mllvm");
+  CmdArgs.push_back("-profile-omit-cold-func-opt=true");
+
+  if (Arg *A = Args.getLastArg(options::OPT_fprofile_omit_cold_opt_EQ)) {
+CmdArgs.push_back("-mllvm");
+CmdArgs.push_back(Args.MakeArgString(
+Twine("-profile-omit-cold-func-opt-percent=") + A->getValue()));
+  }
+}
   }
 
   bool EmitCovNotes = Args.hasFlag(options::OPT_ftest_coverage,
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -793,6 +793,17 @@
 Alias;
 defm debug_info_for_profiling : OptInFFlag<"debug-info-for-profiling",
   "Emit extra debug info to make sample profile more accurate">;
+
+// Options to omit optimizations on cold code.
+def fprofile_omit_cold_opt : Flag<["-"], "fprofile-omit-cold-opt">,
+Group, Flags<[CoreOption]>,
+HelpT

[PATCH] D88394: [Driver][M68k] (Patch 8/8) Add driver support for M68k

2020-12-09 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu updated this revision to Diff 310755.
myhsu marked an inline comment as done.
myhsu added a comment.

- [NFC] Fix minor formatting


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

https://reviews.llvm.org/D88394

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/CMakeLists.txt
  clang/lib/Driver/ToolChains/Arch/M68k.cpp
  clang/lib/Driver/ToolChains/Arch/M68k.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/lib/Driver/ToolChains/Linux.cpp
  clang/test/Driver/m68k-features.cpp
  clang/test/Driver/m68k-sub-archs.cpp

Index: clang/test/Driver/m68k-sub-archs.cpp
===
--- /dev/null
+++ clang/test/Driver/m68k-sub-archs.cpp
@@ -0,0 +1,35 @@
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=68000 %s 2>&1 | FileCheck --check-prefix=CHECK-MX00 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=m68000 %s 2>&1 | FileCheck --check-prefix=CHECK-MX00 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=M68000 %s 2>&1 | FileCheck --check-prefix=CHECK-MX00 %s
+// RUN: %clang -### -target m68k-unknown-linux -m68000 %s 2>&1 | FileCheck --check-prefix=CHECK-MX00 %s
+// CHECK-MX00: "-target-cpu" "M68000"
+
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=68010 %s 2>&1 | FileCheck --check-prefix=CHECK-MX10 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=m68010 %s 2>&1 | FileCheck --check-prefix=CHECK-MX10 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=M68010 %s 2>&1 | FileCheck --check-prefix=CHECK-MX10 %s
+// RUN: %clang -### -target m68k-unknown-linux -m68010 %s 2>&1 | FileCheck --check-prefix=CHECK-MX10 %s
+// CHECK-MX10: "-target-cpu" "M68010"
+
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=68020 %s 2>&1 | FileCheck --check-prefix=CHECK-MX20 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=m68020 %s 2>&1 | FileCheck --check-prefix=CHECK-MX20 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=M68020 %s 2>&1 | FileCheck --check-prefix=CHECK-MX20 %s
+// RUN: %clang -### -target m68k-unknown-linux -m68020 %s 2>&1 | FileCheck --check-prefix=CHECK-MX20 %s
+// CHECK-MX20: "-target-cpu" "M68020"
+
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=68030 %s 2>&1 | FileCheck --check-prefix=CHECK-MX30 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=m68030 %s 2>&1 | FileCheck --check-prefix=CHECK-MX30 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=M68030 %s 2>&1 | FileCheck --check-prefix=CHECK-MX30 %s
+// RUN: %clang -### -target m68k-unknown-linux -m68030 %s 2>&1 | FileCheck --check-prefix=CHECK-MX30 %s
+// CHECK-MX30: "-target-cpu" "M68030"
+
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=68040 %s 2>&1 | FileCheck --check-prefix=CHECK-MX40 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=m68040 %s 2>&1 | FileCheck --check-prefix=CHECK-MX40 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=M68040 %s 2>&1 | FileCheck --check-prefix=CHECK-MX40 %s
+// RUN: %clang -### -target m68k-unknown-linux -m68040 %s 2>&1 | FileCheck --check-prefix=CHECK-MX40 %s
+// CHECK-MX40: "-target-cpu" "M68040"
+
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=68060 %s 2>&1 | FileCheck --check-prefix=CHECK-MX60 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=m68060 %s 2>&1 | FileCheck --check-prefix=CHECK-MX60 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=M68060 %s 2>&1 | FileCheck --check-prefix=CHECK-MX60 %s
+// RUN: %clang -### -target m68k-unknown-linux -m68060 %s 2>&1 | FileCheck --check-prefix=CHECK-MX60 %s
+// CHECK-MX60: "-target-cpu" "M68060"
Index: clang/test/Driver/m68k-features.cpp
===
--- /dev/null
+++ clang/test/Driver/m68k-features.cpp
@@ -0,0 +1,45 @@
+// Check macro definitions
+// RUN: %clang -target m68k-unknown-linux -m68000 -dM -E %s | FileCheck --check-prefix=CHECK-MX %s
+// CHECK-MX: #define __mc68000 1
+// CHECK-MX: #define __mc68000__ 1
+// CHECK-MX: #define mc68000 1
+
+// RUN: %clang -target m68k-unknown-linux -m68010 -dM -E %s | FileCheck --check-prefix=CHECK-MX10 %s
+// CHECK-MX10: #define __mc68000 1
+// CHECK-MX10: #define __mc68000__ 1
+// CHECK-MX10: #define __mc68010 1
+// CHECK-MX10: #define __mc68010__ 1
+// CHECK-MX10: #define mc68000 1
+// CHECK-MX10: #define mc68010 1
+
+// RUN: %clang -target m68k-unknown-linux -m68020 -dM -E %s | FileCheck --check-prefix=CHECK-MX20 %s
+// CHECK-MX20: #define __mc68000 1
+// CHECK-MX20: #define __mc68000__ 1
+// CHECK-MX20: #define __mc68020 1
+// CHECK-MX20: #define __mc68020__ 1
+// CHECK-MX20: #define mc68000 1
+// CHECK-MX20: #define mc68020 1
+
+// RUN: %clang -target m68k-unknown-linux -m68030 -dM -E %s | FileCheck --check-prefix=CHECK-MX30 %s
+// CHECK-MX30: #define __mc68000 1
+// CHECK-MX30: #define __mc68000__ 1
+// CHECK-MX30: #define __mc68030 1
+// CHECK-MX30: #define __mc68030__ 1
+// CHECK-MX30: #

[PATCH] D88393: [cfe][M68K] (Patch 7/8) Basic Clang support

2020-09-30 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu updated this revision to Diff 295468.
myhsu added a comment.

Fix formatting issues


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

https://reviews.llvm.org/D88393

Files:
  clang/include/clang/Basic/Attr.td
  clang/lib/Basic/CMakeLists.txt
  clang/lib/Basic/Targets.cpp
  clang/lib/Basic/Targets/M680x0.cpp
  clang/lib/Basic/Targets/M680x0.h
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/Sema/SemaDeclAttr.cpp

Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -5797,6 +5797,39 @@
   D->addAttr(::new (S.Context) MipsInterruptAttr(S.Context, AL, Kind));
 }
 
+static void handleM680x0InterruptAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
+  if (!checkAttributeNumArgs(S, AL, 1))
+return;
+
+  if (!AL.isArgExpr(0)) {
+S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
+<< AL << AANT_ArgumentIntegerConstant;
+return;
+  }
+
+  // FIXME: Check for decl - it should be void ()(void).
+
+  Expr *NumParamsExpr = static_cast(AL.getArgAsExpr(0));
+  auto MaybeNumParams = NumParamsExpr->getIntegerConstantExpr(S.Context);
+  if (!MaybeNumParams) {
+S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
+<< AL << AANT_ArgumentIntegerConstant
+<< NumParamsExpr->getSourceRange();
+return;
+  }
+
+  unsigned Num = MaybeNumParams->getLimitedValue(255);
+  if ((Num & 1) || Num > 30) {
+S.Diag(AL.getLoc(), diag::err_attribute_argument_out_of_bounds)
+<< AL << (int)MaybeNumParams->getSExtValue()
+<< NumParamsExpr->getSourceRange();
+return;
+  }
+
+  D->addAttr(::new (S.Context) M680x0InterruptAttr(S.Context, AL, Num));
+  D->addAttr(UsedAttr::CreateImplicit(S.Context));
+}
+
 static void handleAnyX86InterruptAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
   // Semantic checks for a function with the 'interrupt' attribute.
   // a) Must be a function.
@@ -6069,6 +6102,9 @@
   case llvm::Triple::mips:
 handleMipsInterruptAttr(S, D, AL);
 break;
+  case llvm::Triple::m680x0:
+handleM680x0InterruptAttr(S, D, AL);
+break;
   case llvm::Triple::x86:
   case llvm::Triple::x86_64:
 handleAnyX86InterruptAttr(S, D, AL);
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -8064,6 +8064,45 @@
   return false;
 }
 
+//===--===//
+// M680x0 ABI Implementation
+//===--===//
+
+namespace {
+
+class M680x0TargetCodeGenInfo : public TargetCodeGenInfo {
+public:
+  M680x0TargetCodeGenInfo(CodeGenTypes &CGT)
+  : TargetCodeGenInfo(std::make_unique(CGT)) {}
+  void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
+   CodeGen::CodeGenModule &M) const override;
+};
+
+} // namespace
+
+// TODO Does not actually work right now
+void M680x0TargetCodeGenInfo::setTargetAttributes(
+const Decl *D, llvm::GlobalValue *GV, CodeGen::CodeGenModule &M) const {
+  if (const FunctionDecl *FD = dyn_cast_or_null(D)) {
+if (const M680x0InterruptAttr *attr = FD->getAttr()) {
+  // Handle 'interrupt' attribute:
+  llvm::Function *F = cast(GV);
+
+  // Step 1: Set ISR calling convention.
+  F->setCallingConv(llvm::CallingConv::M680x0_INTR);
+
+  // Step 2: Add attributes goodness.
+  F->addFnAttr(llvm::Attribute::NoInline);
+
+  // ??? is this right
+  // Step 3: Emit ISR vector alias.
+  unsigned Num = attr->getNumber() / 2;
+  llvm::GlobalAlias::create(llvm::Function::ExternalLinkage,
+"__isr_" + Twine(Num), F);
+}
+  }
+}
+
 //===--===//
 // AVR ABI Implementation.
 //===--===//
Index: clang/lib/Basic/Targets/M680x0.h
===
--- /dev/null
+++ clang/lib/Basic/Targets/M680x0.h
@@ -0,0 +1,58 @@
+//===--- M680x0.h - Declare M680x0 target feature support ---*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// This file declares M680x0 TargetInfo objects.
+//
+//===--===//
+
+#ifndef M680X0_H_LTNCIPAD
+#define M680X0_H_LTNCIPAD
+
+#include "OSTargets.h"
+#include "clang/Basic/TargetInfo.h"
+#include "clang/Basic/TargetOptions.h"
+#include "llvm/ADT/Triple.h"
+#include "llvm/Support/Compiler.h"
+
+namespace clang {
+namespace targets {
+
+class LLVM

[PATCH] D88394: [Driver][M68K] (Patch 8/8) Add driver support for M68K

2020-09-30 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu updated this revision to Diff 295469.
myhsu added a reviewer: aaron.ballman.
myhsu added a comment.

Fix formatting issues


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

https://reviews.llvm.org/D88394

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/CMakeLists.txt
  clang/lib/Driver/ToolChains/Arch/M680x0.cpp
  clang/lib/Driver/ToolChains/Arch/M680x0.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/lib/Driver/ToolChains/Linux.cpp
  clang/test/Driver/m680x0-features.cpp
  clang/test/Driver/m680x0-sub-archs.cpp

Index: clang/test/Driver/m680x0-sub-archs.cpp
===
--- /dev/null
+++ clang/test/Driver/m680x0-sub-archs.cpp
@@ -0,0 +1,23 @@
+// RUN: %clang -### -target m680x0-unknown-linux -mcpu=68000 %s 2>&1 | FileCheck --check-prefix=CHECK-MX00 %s
+// RUN: %clang -### -target m680x0-unknown-linux -m68000 %s 2>&1 | FileCheck --check-prefix=CHECK-MX00 %s
+// CHECK-MX00: "-target-cpu" "68000"
+
+// RUN: %clang -### -target m680x0-unknown-linux -mcpu=68010 %s 2>&1 | FileCheck --check-prefix=CHECK-MX10 %s
+// RUN: %clang -### -target m680x0-unknown-linux -m68010 %s 2>&1 | FileCheck --check-prefix=CHECK-MX10 %s
+// CHECK-MX10: "-target-cpu" "68010"
+
+// RUN: %clang -### -target m680x0-unknown-linux -mcpu=68020 %s 2>&1 | FileCheck --check-prefix=CHECK-MX20 %s
+// RUN: %clang -### -target m680x0-unknown-linux -m68020 %s 2>&1 | FileCheck --check-prefix=CHECK-MX20 %s
+// CHECK-MX20: "-target-cpu" "68020"
+
+// RUN: %clang -### -target m680x0-unknown-linux -mcpu=68030 %s 2>&1 | FileCheck --check-prefix=CHECK-MX30 %s
+// RUN: %clang -### -target m680x0-unknown-linux -m68030 %s 2>&1 | FileCheck --check-prefix=CHECK-MX30 %s
+// CHECK-MX30: "-target-cpu" "68030"
+
+// RUN: %clang -### -target m680x0-unknown-linux -mcpu=68040 %s 2>&1 | FileCheck --check-prefix=CHECK-MX40 %s
+// RUN: %clang -### -target m680x0-unknown-linux -m68040 %s 2>&1 | FileCheck --check-prefix=CHECK-MX40 %s
+// CHECK-MX40: "-target-cpu" "68040"
+
+// RUN: %clang -### -target m680x0-unknown-linux -mcpu=68060 %s 2>&1 | FileCheck --check-prefix=CHECK-MX60 %s
+// RUN: %clang -### -target m680x0-unknown-linux -m68060 %s 2>&1 | FileCheck --check-prefix=CHECK-MX60 %s
+// CHECK-MX60: "-target-cpu" "68060"
Index: clang/test/Driver/m680x0-features.cpp
===
--- /dev/null
+++ clang/test/Driver/m680x0-features.cpp
@@ -0,0 +1,45 @@
+// Check macro definitions
+// RUN: %clang -target m680x0-unknown-linux -m68000 -dM -E %s | FileCheck --check-prefix=CHECK-MX %s
+// CHECK-MX: #define __mc68000 1
+// CHECK-MX: #define __mc68000__ 1
+// CHECK-MX: #define mc68000 1
+
+// RUN: %clang -target m680x0-unknown-linux -m68010 -dM -E %s | FileCheck --check-prefix=CHECK-MX10 %s
+// CHECK-MX10: #define __mc68000 1
+// CHECK-MX10: #define __mc68000__ 1
+// CHECK-MX10: #define __mc68010 1
+// CHECK-MX10: #define __mc68010__ 1
+// CHECK-MX10: #define mc68000 1
+// CHECK-MX10: #define mc68010 1
+
+// RUN: %clang -target m680x0-unknown-linux -m68020 -dM -E %s | FileCheck --check-prefix=CHECK-MX20 %s
+// CHECK-MX20: #define __mc68000 1
+// CHECK-MX20: #define __mc68000__ 1
+// CHECK-MX20: #define __mc68020 1
+// CHECK-MX20: #define __mc68020__ 1
+// CHECK-MX20: #define mc68000 1
+// CHECK-MX20: #define mc68020 1
+
+// RUN: %clang -target m680x0-unknown-linux -m68030 -dM -E %s | FileCheck --check-prefix=CHECK-MX30 %s
+// CHECK-MX30: #define __mc68000 1
+// CHECK-MX30: #define __mc68000__ 1
+// CHECK-MX30: #define __mc68030 1
+// CHECK-MX30: #define __mc68030__ 1
+// CHECK-MX30: #define mc68000 1
+// CHECK-MX30: #define mc68030 1
+
+// RUN: %clang -target m680x0-unknown-linux -m68040 -dM -E %s | FileCheck --check-prefix=CHECK-MX40 %s
+// CHECK-MX40: #define __mc68000 1
+// CHECK-MX40: #define __mc68000__ 1
+// CHECK-MX40: #define __mc68040 1
+// CHECK-MX40: #define __mc68040__ 1
+// CHECK-MX40: #define mc68000 1
+// CHECK-MX40: #define mc68040 1
+
+// RUN: %clang -target m680x0-unknown-linux -m68060 -dM -E %s | FileCheck --check-prefix=CHECK-MX60 %s
+// CHECK-MX60: #define __mc68000 1
+// CHECK-MX60: #define __mc68000__ 1
+// CHECK-MX60: #define __mc68060 1
+// CHECK-MX60: #define __mc68060__ 1
+// CHECK-MX60: #define mc68000 1
+// CHECK-MX60: #define mc68060 1
Index: clang/lib/Driver/ToolChains/Linux.cpp
===
--- clang/lib/Driver/ToolChains/Linux.cpp
+++ clang/lib/Driver/ToolChains/Linux.cpp
@@ -102,6 +102,12 @@
 if (D.getVFS().exists(SysRoot + "/lib/aarch64_be-linux-gnu"))
   return "aarch64_be-linux-gnu";
 break;
+
+  case llvm::Triple::m680x0:
+if (D.getVFS().exists(SysRoot + "/lib/m68k-linux-gnu"))
+  return "m68k-linux-gnu";
+break;
+
   case llvm::Triple::mips: {
 std::string MT = IsMipsR6 ? "mipsisa32r6-linux-gnu" : "mips-linux-gnu";
 if (D

[PATCH] D88393: [cfe][M68K] (Patch 7/8) Basic Clang support

2020-10-01 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu updated this revision to Diff 295706.
myhsu added a comment.

Update licenses


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

https://reviews.llvm.org/D88393

Files:
  clang/include/clang/Basic/Attr.td
  clang/lib/Basic/CMakeLists.txt
  clang/lib/Basic/Targets.cpp
  clang/lib/Basic/Targets/M680x0.cpp
  clang/lib/Basic/Targets/M680x0.h
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/Sema/SemaDeclAttr.cpp

Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -5797,6 +5797,39 @@
   D->addAttr(::new (S.Context) MipsInterruptAttr(S.Context, AL, Kind));
 }
 
+static void handleM680x0InterruptAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
+  if (!checkAttributeNumArgs(S, AL, 1))
+return;
+
+  if (!AL.isArgExpr(0)) {
+S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
+<< AL << AANT_ArgumentIntegerConstant;
+return;
+  }
+
+  // FIXME: Check for decl - it should be void ()(void).
+
+  Expr *NumParamsExpr = static_cast(AL.getArgAsExpr(0));
+  auto MaybeNumParams = NumParamsExpr->getIntegerConstantExpr(S.Context);
+  if (!MaybeNumParams) {
+S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
+<< AL << AANT_ArgumentIntegerConstant
+<< NumParamsExpr->getSourceRange();
+return;
+  }
+
+  unsigned Num = MaybeNumParams->getLimitedValue(255);
+  if ((Num & 1) || Num > 30) {
+S.Diag(AL.getLoc(), diag::err_attribute_argument_out_of_bounds)
+<< AL << (int)MaybeNumParams->getSExtValue()
+<< NumParamsExpr->getSourceRange();
+return;
+  }
+
+  D->addAttr(::new (S.Context) M680x0InterruptAttr(S.Context, AL, Num));
+  D->addAttr(UsedAttr::CreateImplicit(S.Context));
+}
+
 static void handleAnyX86InterruptAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
   // Semantic checks for a function with the 'interrupt' attribute.
   // a) Must be a function.
@@ -6069,6 +6102,9 @@
   case llvm::Triple::mips:
 handleMipsInterruptAttr(S, D, AL);
 break;
+  case llvm::Triple::m680x0:
+handleM680x0InterruptAttr(S, D, AL);
+break;
   case llvm::Triple::x86:
   case llvm::Triple::x86_64:
 handleAnyX86InterruptAttr(S, D, AL);
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -8064,6 +8064,45 @@
   return false;
 }
 
+//===--===//
+// M680x0 ABI Implementation
+//===--===//
+
+namespace {
+
+class M680x0TargetCodeGenInfo : public TargetCodeGenInfo {
+public:
+  M680x0TargetCodeGenInfo(CodeGenTypes &CGT)
+  : TargetCodeGenInfo(std::make_unique(CGT)) {}
+  void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
+   CodeGen::CodeGenModule &M) const override;
+};
+
+} // namespace
+
+// TODO Does not actually work right now
+void M680x0TargetCodeGenInfo::setTargetAttributes(
+const Decl *D, llvm::GlobalValue *GV, CodeGen::CodeGenModule &M) const {
+  if (const FunctionDecl *FD = dyn_cast_or_null(D)) {
+if (const M680x0InterruptAttr *attr = FD->getAttr()) {
+  // Handle 'interrupt' attribute:
+  llvm::Function *F = cast(GV);
+
+  // Step 1: Set ISR calling convention.
+  F->setCallingConv(llvm::CallingConv::M680x0_INTR);
+
+  // Step 2: Add attributes goodness.
+  F->addFnAttr(llvm::Attribute::NoInline);
+
+  // ??? is this right
+  // Step 3: Emit ISR vector alias.
+  unsigned Num = attr->getNumber() / 2;
+  llvm::GlobalAlias::create(llvm::Function::ExternalLinkage,
+"__isr_" + Twine(Num), F);
+}
+  }
+}
+
 //===--===//
 // AVR ABI Implementation.
 //===--===//
Index: clang/lib/Basic/Targets/M680x0.h
===
--- /dev/null
+++ clang/lib/Basic/Targets/M680x0.h
@@ -0,0 +1,57 @@
+//===--- M680x0.h - Declare M680x0 target feature support ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file declares M680x0 TargetInfo objects.
+//
+//===--===//
+
+#ifndef M680X0_H_LTNCIPAD
+#define M680X0_H_LTNCIPAD
+
+#include "OSTargets.h"
+#include "clang/Basic/TargetInfo.h"
+#include "clang/Basic/TargetOptions.h"
+#include "llvm/ADT/Triple.h"
+#include "llvm/Support/Compiler.h"
+
+namespace clang {
+namespace ta

[PATCH] D88393: [cfe][M68K] (Patch 7/8) Basic Clang support

2020-10-04 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu updated this revision to Diff 296064.
myhsu added a comment.

Fix the CPU name passing to the Backend


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

https://reviews.llvm.org/D88393

Files:
  clang/include/clang/Basic/Attr.td
  clang/lib/Basic/CMakeLists.txt
  clang/lib/Basic/Targets.cpp
  clang/lib/Basic/Targets/M680x0.cpp
  clang/lib/Basic/Targets/M680x0.h
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/Sema/SemaDeclAttr.cpp

Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -5797,6 +5797,39 @@
   D->addAttr(::new (S.Context) MipsInterruptAttr(S.Context, AL, Kind));
 }
 
+static void handleM680x0InterruptAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
+  if (!checkAttributeNumArgs(S, AL, 1))
+return;
+
+  if (!AL.isArgExpr(0)) {
+S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
+<< AL << AANT_ArgumentIntegerConstant;
+return;
+  }
+
+  // FIXME: Check for decl - it should be void ()(void).
+
+  Expr *NumParamsExpr = static_cast(AL.getArgAsExpr(0));
+  auto MaybeNumParams = NumParamsExpr->getIntegerConstantExpr(S.Context);
+  if (!MaybeNumParams) {
+S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
+<< AL << AANT_ArgumentIntegerConstant
+<< NumParamsExpr->getSourceRange();
+return;
+  }
+
+  unsigned Num = MaybeNumParams->getLimitedValue(255);
+  if ((Num & 1) || Num > 30) {
+S.Diag(AL.getLoc(), diag::err_attribute_argument_out_of_bounds)
+<< AL << (int)MaybeNumParams->getSExtValue()
+<< NumParamsExpr->getSourceRange();
+return;
+  }
+
+  D->addAttr(::new (S.Context) M680x0InterruptAttr(S.Context, AL, Num));
+  D->addAttr(UsedAttr::CreateImplicit(S.Context));
+}
+
 static void handleAnyX86InterruptAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
   // Semantic checks for a function with the 'interrupt' attribute.
   // a) Must be a function.
@@ -6069,6 +6102,9 @@
   case llvm::Triple::mips:
 handleMipsInterruptAttr(S, D, AL);
 break;
+  case llvm::Triple::m680x0:
+handleM680x0InterruptAttr(S, D, AL);
+break;
   case llvm::Triple::x86:
   case llvm::Triple::x86_64:
 handleAnyX86InterruptAttr(S, D, AL);
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -8064,6 +8064,45 @@
   return false;
 }
 
+//===--===//
+// M680x0 ABI Implementation
+//===--===//
+
+namespace {
+
+class M680x0TargetCodeGenInfo : public TargetCodeGenInfo {
+public:
+  M680x0TargetCodeGenInfo(CodeGenTypes &CGT)
+  : TargetCodeGenInfo(std::make_unique(CGT)) {}
+  void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
+   CodeGen::CodeGenModule &M) const override;
+};
+
+} // namespace
+
+// TODO Does not actually work right now
+void M680x0TargetCodeGenInfo::setTargetAttributes(
+const Decl *D, llvm::GlobalValue *GV, CodeGen::CodeGenModule &M) const {
+  if (const FunctionDecl *FD = dyn_cast_or_null(D)) {
+if (const M680x0InterruptAttr *attr = FD->getAttr()) {
+  // Handle 'interrupt' attribute:
+  llvm::Function *F = cast(GV);
+
+  // Step 1: Set ISR calling convention.
+  F->setCallingConv(llvm::CallingConv::M680x0_INTR);
+
+  // Step 2: Add attributes goodness.
+  F->addFnAttr(llvm::Attribute::NoInline);
+
+  // ??? is this right
+  // Step 3: Emit ISR vector alias.
+  unsigned Num = attr->getNumber() / 2;
+  llvm::GlobalAlias::create(llvm::Function::ExternalLinkage,
+"__isr_" + Twine(Num), F);
+}
+  }
+}
+
 //===--===//
 // AVR ABI Implementation.
 //===--===//
Index: clang/lib/Basic/Targets/M680x0.h
===
--- /dev/null
+++ clang/lib/Basic/Targets/M680x0.h
@@ -0,0 +1,57 @@
+//===--- M680x0.h - Declare M680x0 target feature support ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file declares M680x0 TargetInfo objects.
+//
+//===--===//
+
+#ifndef M680X0_H_LTNCIPAD
+#define M680X0_H_LTNCIPAD
+
+#include "OSTargets.h"
+#include "clang/Basic/TargetInfo.h"
+#include "clang/Basic/TargetOptions.h"
+#include "llvm/ADT/Triple.h"
+#include "llvm/Support/Compiler.h"
+
+namespa

[PATCH] D88394: [Driver][M68K] (Patch 8/8) Add driver support for M68K

2020-10-04 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu updated this revision to Diff 296065.
myhsu added a comment.

- Use the canonical CPU name (i.e. names started with upper case 'M')
- Tell the driver to use integrated assembler (i.e. MC) by default


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

https://reviews.llvm.org/D88394

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/CMakeLists.txt
  clang/lib/Driver/ToolChains/Arch/M680x0.cpp
  clang/lib/Driver/ToolChains/Arch/M680x0.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/lib/Driver/ToolChains/Linux.cpp
  clang/test/Driver/m680x0-features.cpp
  clang/test/Driver/m680x0-sub-archs.cpp

Index: clang/test/Driver/m680x0-sub-archs.cpp
===
--- /dev/null
+++ clang/test/Driver/m680x0-sub-archs.cpp
@@ -0,0 +1,29 @@
+// RUN: %clang -### -target m680x0-unknown-linux -mcpu=68000 %s 2>&1 | FileCheck --check-prefix=CHECK-MX00 %s
+// RUN: %clang -### -target m680x0-unknown-linux -mcpu=m68000 %s 2>&1 | FileCheck --check-prefix=CHECK-MX00 %s
+// RUN: %clang -### -target m680x0-unknown-linux -mcpu=M68000 %s 2>&1 | FileCheck --check-prefix=CHECK-MX00 %s
+// RUN: %clang -### -target m680x0-unknown-linux -m68000 %s 2>&1 | FileCheck --check-prefix=CHECK-MX00 %s
+// CHECK-MX00: "-target-cpu" "M68000"
+
+// RUN: %clang -### -target m680x0-unknown-linux -mcpu=68010 %s 2>&1 | FileCheck --check-prefix=CHECK-MX10 %s
+// RUN: %clang -### -target m680x0-unknown-linux -mcpu=m68010 %s 2>&1 | FileCheck --check-prefix=CHECK-MX10 %s
+// RUN: %clang -### -target m680x0-unknown-linux -mcpu=M68010 %s 2>&1 | FileCheck --check-prefix=CHECK-MX10 %s
+// RUN: %clang -### -target m680x0-unknown-linux -m68010 %s 2>&1 | FileCheck --check-prefix=CHECK-MX10 %s
+// CHECK-MX10: "-target-cpu" "M68010"
+
+// RUN: %clang -### -target m680x0-unknown-linux -mcpu=68020 %s 2>&1 | FileCheck --check-prefix=CHECK-MX20 %s
+// RUN: %clang -### -target m680x0-unknown-linux -mcpu=m68020 %s 2>&1 | FileCheck --check-prefix=CHECK-MX20 %s
+// RUN: %clang -### -target m680x0-unknown-linux -mcpu=M68020 %s 2>&1 | FileCheck --check-prefix=CHECK-MX20 %s
+// RUN: %clang -### -target m680x0-unknown-linux -m68020 %s 2>&1 | FileCheck --check-prefix=CHECK-MX20 %s
+// CHECK-MX20: "-target-cpu" "M68020"
+
+// RUN: %clang -### -target m680x0-unknown-linux -mcpu=68030 %s 2>&1 | FileCheck --check-prefix=CHECK-MX30 %s
+// RUN: %clang -### -target m680x0-unknown-linux -mcpu=m68030 %s 2>&1 | FileCheck --check-prefix=CHECK-MX30 %s
+// RUN: %clang -### -target m680x0-unknown-linux -mcpu=M68030 %s 2>&1 | FileCheck --check-prefix=CHECK-MX30 %s
+// RUN: %clang -### -target m680x0-unknown-linux -m68030 %s 2>&1 | FileCheck --check-prefix=CHECK-MX30 %s
+// CHECK-MX30: "-target-cpu" "M68030"
+
+// RUN: %clang -### -target m680x0-unknown-linux -mcpu=68040 %s 2>&1 | FileCheck --check-prefix=CHECK-MX40 %s
+// RUN: %clang -### -target m680x0-unknown-linux -mcpu=m68040 %s 2>&1 | FileCheck --check-prefix=CHECK-MX40 %s
+// RUN: %clang -### -target m680x0-unknown-linux -mcpu=M68040 %s 2>&1 | FileCheck --check-prefix=CHECK-MX40 %s
+// RUN: %clang -### -target m680x0-unknown-linux -m68040 %s 2>&1 | FileCheck --check-prefix=CHECK-MX40 %s
+// CHECK-MX40: "-target-cpu" "M68040"
Index: clang/test/Driver/m680x0-features.cpp
===
--- /dev/null
+++ clang/test/Driver/m680x0-features.cpp
@@ -0,0 +1,37 @@
+// Check macro definitions
+// RUN: %clang -target m680x0-unknown-linux -m68000 -dM -E %s | FileCheck --check-prefix=CHECK-MX %s
+// CHECK-MX: #define __mc68000 1
+// CHECK-MX: #define __mc68000__ 1
+// CHECK-MX: #define mc68000 1
+
+// RUN: %clang -target m680x0-unknown-linux -m68010 -dM -E %s | FileCheck --check-prefix=CHECK-MX10 %s
+// CHECK-MX10: #define __mc68000 1
+// CHECK-MX10: #define __mc68000__ 1
+// CHECK-MX10: #define __mc68010 1
+// CHECK-MX10: #define __mc68010__ 1
+// CHECK-MX10: #define mc68000 1
+// CHECK-MX10: #define mc68010 1
+
+// RUN: %clang -target m680x0-unknown-linux -m68020 -dM -E %s | FileCheck --check-prefix=CHECK-MX20 %s
+// CHECK-MX20: #define __mc68000 1
+// CHECK-MX20: #define __mc68000__ 1
+// CHECK-MX20: #define __mc68020 1
+// CHECK-MX20: #define __mc68020__ 1
+// CHECK-MX20: #define mc68000 1
+// CHECK-MX20: #define mc68020 1
+
+// RUN: %clang -target m680x0-unknown-linux -m68030 -dM -E %s | FileCheck --check-prefix=CHECK-MX30 %s
+// CHECK-MX30: #define __mc68000 1
+// CHECK-MX30: #define __mc68000__ 1
+// CHECK-MX30: #define __mc68030 1
+// CHECK-MX30: #define __mc68030__ 1
+// CHECK-MX30: #define mc68000 1
+// CHECK-MX30: #define mc68030 1
+
+// RUN: %clang -target m680x0-unknown-linux -m68040 -dM -E %s | FileCheck --check-prefix=CHECK-MX40 %s
+// CHECK-MX40: #define __mc68000 1
+// CHECK-MX40: #define __mc68000__ 1
+// CHECK-MX40: #define __mc68040 1
+// CHECK-MX40: #define __mc68040__ 1
+// CHECK-MX40: #define mc68000 1
+// 

[PATCH] D88393: [cfe][M68k] (Patch 7/8) Basic Clang support

2020-11-30 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu updated this revision to Diff 308550.
myhsu marked 5 inline comments as done.
myhsu added a comment.

- Rebased to latest changes
- Addressed some of the feedbacks


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

https://reviews.llvm.org/D88393

Files:
  clang/include/clang/Basic/Attr.td
  clang/lib/Basic/CMakeLists.txt
  clang/lib/Basic/Targets.cpp
  clang/lib/Basic/Targets/M68k.cpp
  clang/lib/Basic/Targets/M68k.h
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/Sema/SemaDeclAttr.cpp

Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -6306,6 +6306,39 @@
   D->addAttr(::new (S.Context) MipsInterruptAttr(S.Context, AL, Kind));
 }
 
+static void handleM68kInterruptAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
+  if (!checkAttributeNumArgs(S, AL, 1))
+return;
+
+  if (!AL.isArgExpr(0)) {
+S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
+<< AL << AANT_ArgumentIntegerConstant;
+return;
+  }
+
+  // FIXME: Check for decl - it should be void ()(void).
+
+  Expr *NumParamsExpr = static_cast(AL.getArgAsExpr(0));
+  auto MaybeNumParams = NumParamsExpr->getIntegerConstantExpr(S.Context);
+  if (!MaybeNumParams) {
+S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
+<< AL << AANT_ArgumentIntegerConstant
+<< NumParamsExpr->getSourceRange();
+return;
+  }
+
+  unsigned Num = MaybeNumParams->getLimitedValue(255);
+  if ((Num & 1) || Num > 30) {
+S.Diag(AL.getLoc(), diag::err_attribute_argument_out_of_bounds)
+<< AL << (int)MaybeNumParams->getSExtValue()
+<< NumParamsExpr->getSourceRange();
+return;
+  }
+
+  D->addAttr(::new (S.Context) M68kInterruptAttr(S.Context, AL, Num));
+  D->addAttr(UsedAttr::CreateImplicit(S.Context));
+}
+
 static void handleAnyX86InterruptAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
   // Semantic checks for a function with the 'interrupt' attribute.
   // a) Must be a function.
@@ -6578,6 +6611,9 @@
   case llvm::Triple::mips:
 handleMipsInterruptAttr(S, D, AL);
 break;
+  case llvm::Triple::m68k:
+handleM68kInterruptAttr(S, D, AL);
+break;
   case llvm::Triple::x86:
   case llvm::Triple::x86_64:
 handleAnyX86InterruptAttr(S, D, AL);
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -8066,6 +8066,45 @@
   return false;
 }
 
+//===--===//
+// M68k ABI Implementation
+//===--===//
+
+namespace {
+
+class M68kTargetCodeGenInfo : public TargetCodeGenInfo {
+public:
+  M68kTargetCodeGenInfo(CodeGenTypes &CGT)
+  : TargetCodeGenInfo(std::make_unique(CGT)) {}
+  void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
+   CodeGen::CodeGenModule &M) const override;
+};
+
+} // namespace
+
+// TODO Does not actually work right now
+void M68kTargetCodeGenInfo::setTargetAttributes(
+const Decl *D, llvm::GlobalValue *GV, CodeGen::CodeGenModule &M) const {
+  if (const auto *FD = dyn_cast_or_null(D)) {
+if (const auto *attr = FD->getAttr()) {
+  // Handle 'interrupt' attribute:
+  llvm::Function *F = cast(GV);
+
+  // Step 1: Set ISR calling convention.
+  F->setCallingConv(llvm::CallingConv::M68k_INTR);
+
+  // Step 2: Add attributes goodness.
+  F->addFnAttr(llvm::Attribute::NoInline);
+
+  // ??? is this right
+  // Step 3: Emit ISR vector alias.
+  unsigned Num = attr->getNumber() / 2;
+  llvm::GlobalAlias::create(llvm::Function::ExternalLinkage,
+"__isr_" + Twine(Num), F);
+}
+  }
+}
+
 //===--===//
 // AVR ABI Implementation.
 //===--===//
Index: clang/lib/Basic/Targets/M68k.h
===
--- /dev/null
+++ clang/lib/Basic/Targets/M68k.h
@@ -0,0 +1,56 @@
+//===--- M68k.h - Declare M68k target feature support ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file declares M68k TargetInfo objects.
+//
+//===--===//
+
+#ifndef M680X0_H_LTNCIPAD
+#define M680X0_H_LTNCIPAD
+
+#include "OSTargets.h"
+#include "clang/Basic/TargetInfo.h"
+#include "clang/Basic/TargetOptions.h"
+#include "llvm/ADT/Triple.h"
+#include "llvm/Support/Compiler.h"
+
+

[PATCH] D88394: [Driver][M68k] (Patch 8/8) Add driver support for M68k

2020-11-30 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu updated this revision to Diff 308551.
myhsu marked 11 inline comments as done.
myhsu added a comment.

- Rebased to latest changes
- Addressed some of the feedbacks


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

https://reviews.llvm.org/D88394

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/CMakeLists.txt
  clang/lib/Driver/ToolChains/Arch/M68k.cpp
  clang/lib/Driver/ToolChains/Arch/M68k.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/lib/Driver/ToolChains/Linux.cpp
  clang/test/Driver/m68k-features.cpp
  clang/test/Driver/m68k-sub-archs.cpp

Index: clang/test/Driver/m68k-sub-archs.cpp
===
--- /dev/null
+++ clang/test/Driver/m68k-sub-archs.cpp
@@ -0,0 +1,29 @@
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=68000 %s 2>&1 | FileCheck --check-prefix=CHECK-MX00 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=m68000 %s 2>&1 | FileCheck --check-prefix=CHECK-MX00 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=M68000 %s 2>&1 | FileCheck --check-prefix=CHECK-MX00 %s
+// RUN: %clang -### -target m68k-unknown-linux -m68000 %s 2>&1 | FileCheck --check-prefix=CHECK-MX00 %s
+// CHECK-MX00: "-target-cpu" "M68000"
+
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=68010 %s 2>&1 | FileCheck --check-prefix=CHECK-MX10 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=m68010 %s 2>&1 | FileCheck --check-prefix=CHECK-MX10 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=M68010 %s 2>&1 | FileCheck --check-prefix=CHECK-MX10 %s
+// RUN: %clang -### -target m68k-unknown-linux -m68010 %s 2>&1 | FileCheck --check-prefix=CHECK-MX10 %s
+// CHECK-MX10: "-target-cpu" "M68010"
+
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=68020 %s 2>&1 | FileCheck --check-prefix=CHECK-MX20 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=m68020 %s 2>&1 | FileCheck --check-prefix=CHECK-MX20 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=M68020 %s 2>&1 | FileCheck --check-prefix=CHECK-MX20 %s
+// RUN: %clang -### -target m68k-unknown-linux -m68020 %s 2>&1 | FileCheck --check-prefix=CHECK-MX20 %s
+// CHECK-MX20: "-target-cpu" "M68020"
+
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=68030 %s 2>&1 | FileCheck --check-prefix=CHECK-MX30 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=m68030 %s 2>&1 | FileCheck --check-prefix=CHECK-MX30 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=M68030 %s 2>&1 | FileCheck --check-prefix=CHECK-MX30 %s
+// RUN: %clang -### -target m68k-unknown-linux -m68030 %s 2>&1 | FileCheck --check-prefix=CHECK-MX30 %s
+// CHECK-MX30: "-target-cpu" "M68030"
+
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=68040 %s 2>&1 | FileCheck --check-prefix=CHECK-MX40 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=m68040 %s 2>&1 | FileCheck --check-prefix=CHECK-MX40 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=M68040 %s 2>&1 | FileCheck --check-prefix=CHECK-MX40 %s
+// RUN: %clang -### -target m68k-unknown-linux -m68040 %s 2>&1 | FileCheck --check-prefix=CHECK-MX40 %s
+// CHECK-MX40: "-target-cpu" "M68040"
Index: clang/test/Driver/m68k-features.cpp
===
--- /dev/null
+++ clang/test/Driver/m68k-features.cpp
@@ -0,0 +1,37 @@
+// Check macro definitions
+// RUN: %clang -target m68k-unknown-linux -m68000 -dM -E %s | FileCheck --check-prefix=CHECK-MX %s
+// CHECK-MX: #define __mc68000 1
+// CHECK-MX: #define __mc68000__ 1
+// CHECK-MX: #define mc68000 1
+
+// RUN: %clang -target m68k-unknown-linux -m68010 -dM -E %s | FileCheck --check-prefix=CHECK-MX10 %s
+// CHECK-MX10: #define __mc68000 1
+// CHECK-MX10: #define __mc68000__ 1
+// CHECK-MX10: #define __mc68010 1
+// CHECK-MX10: #define __mc68010__ 1
+// CHECK-MX10: #define mc68000 1
+// CHECK-MX10: #define mc68010 1
+
+// RUN: %clang -target m68k-unknown-linux -m68020 -dM -E %s | FileCheck --check-prefix=CHECK-MX20 %s
+// CHECK-MX20: #define __mc68000 1
+// CHECK-MX20: #define __mc68000__ 1
+// CHECK-MX20: #define __mc68020 1
+// CHECK-MX20: #define __mc68020__ 1
+// CHECK-MX20: #define mc68000 1
+// CHECK-MX20: #define mc68020 1
+
+// RUN: %clang -target m68k-unknown-linux -m68030 -dM -E %s | FileCheck --check-prefix=CHECK-MX30 %s
+// CHECK-MX30: #define __mc68000 1
+// CHECK-MX30: #define __mc68000__ 1
+// CHECK-MX30: #define __mc68030 1
+// CHECK-MX30: #define __mc68030__ 1
+// CHECK-MX30: #define mc68000 1
+// CHECK-MX30: #define mc68030 1
+
+// RUN: %clang -target m68k-unknown-linux -m68040 -dM -E %s | FileCheck --check-prefix=CHECK-MX40 %s
+// CHECK-MX40: #define __mc68000 1
+// CHECK-MX40: #define __mc68000__ 1
+// CHECK-MX40: #define __mc68040 1
+// CHECK-MX40: #define __mc68040__ 1
+// CHECK-MX40: #define mc68000 1
+// CHECK-MX40: #define mc68040 1
Index: clang/lib/Driver/ToolChains/Linux.cpp
=

[PATCH] D88394: [Driver][M68k] (Patch 8/8) Add driver support for M68k

2020-11-30 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu added inline comments.



Comment at: clang/include/clang/Driver/Options.td:3125
+foreach i = {0-4} in
+  def m680#i#0 : Flag<["-"], "m680"#i#"0">, Group;
 

bruno wrote:
> rengolin wrote:
> > Same question as @RKSimon had below: Shouldn't this cover all models the 
> > back-end recognises?
> Unless you are planning to add 100 or more target variations I'd prefer to 
> see these explicitly defined instead of a `foreach`. If I'm grepping for a 
> specific CPU variation in the code base it's nice to get that information 
> easily. 
@rengolin  I think the backend currently doesn't support M68060 either


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

https://reviews.llvm.org/D88394

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


[PATCH] D88393: [cfe][M68k] (Patch 7/8) Basic Clang support

2020-12-01 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu updated this revision to Diff 308866.
myhsu marked 3 inline comments as done.
myhsu added a comment.

- Addressed all the feedbacks
- Fixed minor issues that would retrieve the wrong TargetCodeGenInfo instance


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

https://reviews.llvm.org/D88393

Files:
  clang/include/clang/Basic/Attr.td
  clang/lib/Basic/CMakeLists.txt
  clang/lib/Basic/Targets.cpp
  clang/lib/Basic/Targets/M68k.cpp
  clang/lib/Basic/Targets/M68k.h
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/Sema/SemaDeclAttr.cpp

Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -6306,6 +6306,39 @@
   D->addAttr(::new (S.Context) MipsInterruptAttr(S.Context, AL, Kind));
 }
 
+static void handleM68kInterruptAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
+  if (!checkAttributeNumArgs(S, AL, 1))
+return;
+
+  if (!AL.isArgExpr(0)) {
+S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
+<< AL << AANT_ArgumentIntegerConstant;
+return;
+  }
+
+  // FIXME: Check for decl - it should be void ()(void).
+
+  Expr *NumParamsExpr = static_cast(AL.getArgAsExpr(0));
+  auto MaybeNumParams = NumParamsExpr->getIntegerConstantExpr(S.Context);
+  if (!MaybeNumParams) {
+S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
+<< AL << AANT_ArgumentIntegerConstant
+<< NumParamsExpr->getSourceRange();
+return;
+  }
+
+  unsigned Num = MaybeNumParams->getLimitedValue(255);
+  if ((Num & 1) || Num > 30) {
+S.Diag(AL.getLoc(), diag::err_attribute_argument_out_of_bounds)
+<< AL << (int)MaybeNumParams->getSExtValue()
+<< NumParamsExpr->getSourceRange();
+return;
+  }
+
+  D->addAttr(::new (S.Context) M68kInterruptAttr(S.Context, AL, Num));
+  D->addAttr(UsedAttr::CreateImplicit(S.Context));
+}
+
 static void handleAnyX86InterruptAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
   // Semantic checks for a function with the 'interrupt' attribute.
   // a) Must be a function.
@@ -6578,6 +6611,9 @@
   case llvm::Triple::mips:
 handleMipsInterruptAttr(S, D, AL);
 break;
+  case llvm::Triple::m68k:
+handleM68kInterruptAttr(S, D, AL);
+break;
   case llvm::Triple::x86:
   case llvm::Triple::x86_64:
 handleAnyX86InterruptAttr(S, D, AL);
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -8066,6 +8066,43 @@
   return false;
 }
 
+//===--===//
+// M68k ABI Implementation
+//===--===//
+
+namespace {
+
+class M68kTargetCodeGenInfo : public TargetCodeGenInfo {
+public:
+  M68kTargetCodeGenInfo(CodeGenTypes &CGT)
+  : TargetCodeGenInfo(std::make_unique(CGT)) {}
+  void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
+   CodeGen::CodeGenModule &M) const override;
+};
+
+} // namespace
+
+void M68kTargetCodeGenInfo::setTargetAttributes(
+const Decl *D, llvm::GlobalValue *GV, CodeGen::CodeGenModule &M) const {
+  if (const auto *FD = dyn_cast_or_null(D)) {
+if (const auto *attr = FD->getAttr()) {
+  // Handle 'interrupt' attribute:
+  llvm::Function *F = cast(GV);
+
+  // Step 1: Set ISR calling convention.
+  F->setCallingConv(llvm::CallingConv::M68k_INTR);
+
+  // Step 2: Add attributes goodness.
+  F->addFnAttr(llvm::Attribute::NoInline);
+
+  // Step 3: Emit ISR vector alias.
+  unsigned Num = attr->getNumber() / 2;
+  llvm::GlobalAlias::create(llvm::Function::ExternalLinkage,
+"__isr_" + Twine(Num), F);
+}
+  }
+}
+
 //===--===//
 // AVR ABI Implementation.
 //===--===//
@@ -10877,6 +10914,8 @@
 
   case llvm::Triple::le32:
 return SetCGInfo(new PNaClTargetCodeGenInfo(Types));
+  case llvm::Triple::m68k:
+return SetCGInfo(new M68kTargetCodeGenInfo(Types));
   case llvm::Triple::mips:
   case llvm::Triple::mipsel:
 if (Triple.getOS() == llvm::Triple::NaCl)
Index: clang/lib/Basic/Targets/M68k.h
===
--- /dev/null
+++ clang/lib/Basic/Targets/M68k.h
@@ -0,0 +1,56 @@
+//===--- M68k.h - Declare M68k target feature support ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file declares M68k TargetInfo objects.
+//
+//===--

[PATCH] D88393: [cfe][M68k] (Patch 7/8) Basic Clang support

2020-12-01 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu added inline comments.



Comment at: clang/lib/Basic/Targets.cpp:314
+default:
+  return new M68kTargetInfo(Triple, Opts);
+}

rengolin wrote:
> No support for bare-metal?
currently we don't have any plan for that



Comment at: clang/lib/Basic/Targets/M68k.cpp:123
+"d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7",
+"a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7"};
+

rengolin wrote:
> no "sp", "pc", etc? Or are all of them aliased to those?
stack pointer is aliased to `a7`, but I'll add `pc` into the list.



Comment at: clang/lib/CodeGen/TargetInfo.cpp:8083
+
+// TODO Does not actually work right now
+void M68kTargetCodeGenInfo::setTargetAttributes(

rengolin wrote:
> That's an odd comment... :)
> 
> What doesn't work right now? Something or everything?
Seems to work after I fixed a minor issue in getting the correct 
TargetCodeGenInfo. Will remove this comment.


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

https://reviews.llvm.org/D88393

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


[PATCH] D88393: [cfe][M68k] (Patch 7/8) Basic Clang support

2020-12-03 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu updated this revision to Diff 309461.
myhsu added a comment.

- Add support for M68060 sub-target


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

https://reviews.llvm.org/D88393

Files:
  clang/include/clang/Basic/Attr.td
  clang/lib/Basic/CMakeLists.txt
  clang/lib/Basic/Targets.cpp
  clang/lib/Basic/Targets/M68k.cpp
  clang/lib/Basic/Targets/M68k.h
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/Sema/SemaDeclAttr.cpp

Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -6306,6 +6306,39 @@
   D->addAttr(::new (S.Context) MipsInterruptAttr(S.Context, AL, Kind));
 }
 
+static void handleM68kInterruptAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
+  if (!checkAttributeNumArgs(S, AL, 1))
+return;
+
+  if (!AL.isArgExpr(0)) {
+S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
+<< AL << AANT_ArgumentIntegerConstant;
+return;
+  }
+
+  // FIXME: Check for decl - it should be void ()(void).
+
+  Expr *NumParamsExpr = static_cast(AL.getArgAsExpr(0));
+  auto MaybeNumParams = NumParamsExpr->getIntegerConstantExpr(S.Context);
+  if (!MaybeNumParams) {
+S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
+<< AL << AANT_ArgumentIntegerConstant
+<< NumParamsExpr->getSourceRange();
+return;
+  }
+
+  unsigned Num = MaybeNumParams->getLimitedValue(255);
+  if ((Num & 1) || Num > 30) {
+S.Diag(AL.getLoc(), diag::err_attribute_argument_out_of_bounds)
+<< AL << (int)MaybeNumParams->getSExtValue()
+<< NumParamsExpr->getSourceRange();
+return;
+  }
+
+  D->addAttr(::new (S.Context) M68kInterruptAttr(S.Context, AL, Num));
+  D->addAttr(UsedAttr::CreateImplicit(S.Context));
+}
+
 static void handleAnyX86InterruptAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
   // Semantic checks for a function with the 'interrupt' attribute.
   // a) Must be a function.
@@ -6578,6 +6611,9 @@
   case llvm::Triple::mips:
 handleMipsInterruptAttr(S, D, AL);
 break;
+  case llvm::Triple::m68k:
+handleM68kInterruptAttr(S, D, AL);
+break;
   case llvm::Triple::x86:
   case llvm::Triple::x86_64:
 handleAnyX86InterruptAttr(S, D, AL);
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -8066,6 +8066,43 @@
   return false;
 }
 
+//===--===//
+// M68k ABI Implementation
+//===--===//
+
+namespace {
+
+class M68kTargetCodeGenInfo : public TargetCodeGenInfo {
+public:
+  M68kTargetCodeGenInfo(CodeGenTypes &CGT)
+  : TargetCodeGenInfo(std::make_unique(CGT)) {}
+  void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
+   CodeGen::CodeGenModule &M) const override;
+};
+
+} // namespace
+
+void M68kTargetCodeGenInfo::setTargetAttributes(
+const Decl *D, llvm::GlobalValue *GV, CodeGen::CodeGenModule &M) const {
+  if (const auto *FD = dyn_cast_or_null(D)) {
+if (const auto *attr = FD->getAttr()) {
+  // Handle 'interrupt' attribute:
+  llvm::Function *F = cast(GV);
+
+  // Step 1: Set ISR calling convention.
+  F->setCallingConv(llvm::CallingConv::M68k_INTR);
+
+  // Step 2: Add attributes goodness.
+  F->addFnAttr(llvm::Attribute::NoInline);
+
+  // Step 3: Emit ISR vector alias.
+  unsigned Num = attr->getNumber() / 2;
+  llvm::GlobalAlias::create(llvm::Function::ExternalLinkage,
+"__isr_" + Twine(Num), F);
+}
+  }
+}
+
 //===--===//
 // AVR ABI Implementation.
 //===--===//
@@ -10877,6 +10914,8 @@
 
   case llvm::Triple::le32:
 return SetCGInfo(new PNaClTargetCodeGenInfo(Types));
+  case llvm::Triple::m68k:
+return SetCGInfo(new M68kTargetCodeGenInfo(Types));
   case llvm::Triple::mips:
   case llvm::Triple::mipsel:
 if (Triple.getOS() == llvm::Triple::NaCl)
Index: clang/lib/Basic/Targets/M68k.h
===
--- /dev/null
+++ clang/lib/Basic/Targets/M68k.h
@@ -0,0 +1,57 @@
+//===--- M68k.h - Declare M68k target feature support ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file declares M68k TargetInfo objects.
+//
+//===--===//
+
+#ifndef M680X0_H_LTNCIPAD
+#define M680X0_H_LTNCIPAD
+
+#in

[PATCH] D88394: [Driver][M68k] (Patch 8/8) Add driver support for M68k

2020-12-03 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu updated this revision to Diff 309462.
myhsu added a comment.

- Add support for M68060 sub-target


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

https://reviews.llvm.org/D88394

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/CMakeLists.txt
  clang/lib/Driver/ToolChains/Arch/M68k.cpp
  clang/lib/Driver/ToolChains/Arch/M68k.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/lib/Driver/ToolChains/Linux.cpp
  clang/test/Driver/m68k-features.cpp
  clang/test/Driver/m68k-sub-archs.cpp

Index: clang/test/Driver/m68k-sub-archs.cpp
===
--- /dev/null
+++ clang/test/Driver/m68k-sub-archs.cpp
@@ -0,0 +1,35 @@
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=68000 %s 2>&1 | FileCheck --check-prefix=CHECK-MX00 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=m68000 %s 2>&1 | FileCheck --check-prefix=CHECK-MX00 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=M68000 %s 2>&1 | FileCheck --check-prefix=CHECK-MX00 %s
+// RUN: %clang -### -target m68k-unknown-linux -m68000 %s 2>&1 | FileCheck --check-prefix=CHECK-MX00 %s
+// CHECK-MX00: "-target-cpu" "M68000"
+
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=68010 %s 2>&1 | FileCheck --check-prefix=CHECK-MX10 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=m68010 %s 2>&1 | FileCheck --check-prefix=CHECK-MX10 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=M68010 %s 2>&1 | FileCheck --check-prefix=CHECK-MX10 %s
+// RUN: %clang -### -target m68k-unknown-linux -m68010 %s 2>&1 | FileCheck --check-prefix=CHECK-MX10 %s
+// CHECK-MX10: "-target-cpu" "M68010"
+
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=68020 %s 2>&1 | FileCheck --check-prefix=CHECK-MX20 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=m68020 %s 2>&1 | FileCheck --check-prefix=CHECK-MX20 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=M68020 %s 2>&1 | FileCheck --check-prefix=CHECK-MX20 %s
+// RUN: %clang -### -target m68k-unknown-linux -m68020 %s 2>&1 | FileCheck --check-prefix=CHECK-MX20 %s
+// CHECK-MX20: "-target-cpu" "M68020"
+
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=68030 %s 2>&1 | FileCheck --check-prefix=CHECK-MX30 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=m68030 %s 2>&1 | FileCheck --check-prefix=CHECK-MX30 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=M68030 %s 2>&1 | FileCheck --check-prefix=CHECK-MX30 %s
+// RUN: %clang -### -target m68k-unknown-linux -m68030 %s 2>&1 | FileCheck --check-prefix=CHECK-MX30 %s
+// CHECK-MX30: "-target-cpu" "M68030"
+
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=68040 %s 2>&1 | FileCheck --check-prefix=CHECK-MX40 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=m68040 %s 2>&1 | FileCheck --check-prefix=CHECK-MX40 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=M68040 %s 2>&1 | FileCheck --check-prefix=CHECK-MX40 %s
+// RUN: %clang -### -target m68k-unknown-linux -m68040 %s 2>&1 | FileCheck --check-prefix=CHECK-MX40 %s
+// CHECK-MX40: "-target-cpu" "M68040"
+
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=68060 %s 2>&1 | FileCheck --check-prefix=CHECK-MX60 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=m68060 %s 2>&1 | FileCheck --check-prefix=CHECK-MX60 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=M68060 %s 2>&1 | FileCheck --check-prefix=CHECK-MX60 %s
+// RUN: %clang -### -target m68k-unknown-linux -m68060 %s 2>&1 | FileCheck --check-prefix=CHECK-MX60 %s
+// CHECK-MX60: "-target-cpu" "M68060"
Index: clang/test/Driver/m68k-features.cpp
===
--- /dev/null
+++ clang/test/Driver/m68k-features.cpp
@@ -0,0 +1,45 @@
+// Check macro definitions
+// RUN: %clang -target m68k-unknown-linux -m68000 -dM -E %s | FileCheck --check-prefix=CHECK-MX %s
+// CHECK-MX: #define __mc68000 1
+// CHECK-MX: #define __mc68000__ 1
+// CHECK-MX: #define mc68000 1
+
+// RUN: %clang -target m68k-unknown-linux -m68010 -dM -E %s | FileCheck --check-prefix=CHECK-MX10 %s
+// CHECK-MX10: #define __mc68000 1
+// CHECK-MX10: #define __mc68000__ 1
+// CHECK-MX10: #define __mc68010 1
+// CHECK-MX10: #define __mc68010__ 1
+// CHECK-MX10: #define mc68000 1
+// CHECK-MX10: #define mc68010 1
+
+// RUN: %clang -target m68k-unknown-linux -m68020 -dM -E %s | FileCheck --check-prefix=CHECK-MX20 %s
+// CHECK-MX20: #define __mc68000 1
+// CHECK-MX20: #define __mc68000__ 1
+// CHECK-MX20: #define __mc68020 1
+// CHECK-MX20: #define __mc68020__ 1
+// CHECK-MX20: #define mc68000 1
+// CHECK-MX20: #define mc68020 1
+
+// RUN: %clang -target m68k-unknown-linux -m68030 -dM -E %s | FileCheck --check-prefix=CHECK-MX30 %s
+// CHECK-MX30: #define __mc68000 1
+// CHECK-MX30: #define __mc68000__ 1
+// CHECK-MX30: #define __mc68030 1
+// CHECK-MX30: #define __mc68030__ 1
+// CHECK-MX30: #define mc68000 1
+// CHECK-MX30: 

[PATCH] D88394: [Driver][M68k] (Patch 8/8) Add driver support for M68k

2020-12-03 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu marked 2 inline comments as done.
myhsu added inline comments.



Comment at: clang/include/clang/Driver/Options.td:3125
+foreach i = {0-4} in
+  def m680#i#0 : Flag<["-"], "m680"#i#"0">, Group;
 

myhsu wrote:
> bruno wrote:
> > rengolin wrote:
> > > Same question as @RKSimon had below: Shouldn't this cover all models the 
> > > back-end recognises?
> > Unless you are planning to add 100 or more target variations I'd prefer to 
> > see these explicitly defined instead of a `foreach`. If I'm grepping for a 
> > specific CPU variation in the code base it's nice to get that information 
> > easily. 
> @rengolin  I think the backend currently doesn't support M68060 either
Update: I've just put the sub-target (skeleton) for M68060. So now you can 
specific M68060 :-)



Comment at: clang/lib/Driver/ToolChains/Arch/M68k.cpp:44
+
+llvm::Regex CPUPattern("m?680([01234]{1})0");
+llvm::SmallVector Matches;

RKSimon wrote:
> Why no 68060 ?
@RKSimon  Just added 060's support :-)
Currently I don't see any major ISA difference between 060 and 040 (correct me 
if I'm wrong). So I just put a sub-target skeleton and clang support for 060, 
and fill in the details in the future


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

https://reviews.llvm.org/D88394

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


[PATCH] D88393: [cfe][M68k] (Patch 7/8) Basic Clang support

2020-11-01 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu updated this revision to Diff 302187.
myhsu retitled this revision from "[cfe][M68K] (Patch 7/8) Basic Clang support" 
to "[cfe][M68k] (Patch 7/8) Basic Clang support".
myhsu edited the summary of this revision.
myhsu added a comment.
Herald added a subscriber: dexonsmith.

[NFC] Rename M680x0 to M68k


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

https://reviews.llvm.org/D88393

Files:
  clang/include/clang/Basic/Attr.td
  clang/lib/Basic/CMakeLists.txt
  clang/lib/Basic/Targets.cpp
  clang/lib/Basic/Targets/M68k.cpp
  clang/lib/Basic/Targets/M68k.h
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/Sema/SemaDeclAttr.cpp

Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -5797,6 +5797,39 @@
   D->addAttr(::new (S.Context) MipsInterruptAttr(S.Context, AL, Kind));
 }
 
+static void handleM68kInterruptAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
+  if (!checkAttributeNumArgs(S, AL, 1))
+return;
+
+  if (!AL.isArgExpr(0)) {
+S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
+<< AL << AANT_ArgumentIntegerConstant;
+return;
+  }
+
+  // FIXME: Check for decl - it should be void ()(void).
+
+  Expr *NumParamsExpr = static_cast(AL.getArgAsExpr(0));
+  auto MaybeNumParams = NumParamsExpr->getIntegerConstantExpr(S.Context);
+  if (!MaybeNumParams) {
+S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
+<< AL << AANT_ArgumentIntegerConstant
+<< NumParamsExpr->getSourceRange();
+return;
+  }
+
+  unsigned Num = MaybeNumParams->getLimitedValue(255);
+  if ((Num & 1) || Num > 30) {
+S.Diag(AL.getLoc(), diag::err_attribute_argument_out_of_bounds)
+<< AL << (int)MaybeNumParams->getSExtValue()
+<< NumParamsExpr->getSourceRange();
+return;
+  }
+
+  D->addAttr(::new (S.Context) M68kInterruptAttr(S.Context, AL, Num));
+  D->addAttr(UsedAttr::CreateImplicit(S.Context));
+}
+
 static void handleAnyX86InterruptAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
   // Semantic checks for a function with the 'interrupt' attribute.
   // a) Must be a function.
@@ -6069,6 +6102,9 @@
   case llvm::Triple::mips:
 handleMipsInterruptAttr(S, D, AL);
 break;
+  case llvm::Triple::m68k:
+handleM68kInterruptAttr(S, D, AL);
+break;
   case llvm::Triple::x86:
   case llvm::Triple::x86_64:
 handleAnyX86InterruptAttr(S, D, AL);
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -8064,6 +8064,45 @@
   return false;
 }
 
+//===--===//
+// M68k ABI Implementation
+//===--===//
+
+namespace {
+
+class M68kTargetCodeGenInfo : public TargetCodeGenInfo {
+public:
+  M68kTargetCodeGenInfo(CodeGenTypes &CGT)
+  : TargetCodeGenInfo(std::make_unique(CGT)) {}
+  void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
+   CodeGen::CodeGenModule &M) const override;
+};
+
+} // namespace
+
+// TODO Does not actually work right now
+void M68kTargetCodeGenInfo::setTargetAttributes(
+const Decl *D, llvm::GlobalValue *GV, CodeGen::CodeGenModule &M) const {
+  if (const FunctionDecl *FD = dyn_cast_or_null(D)) {
+if (const M68kInterruptAttr *attr = FD->getAttr()) {
+  // Handle 'interrupt' attribute:
+  llvm::Function *F = cast(GV);
+
+  // Step 1: Set ISR calling convention.
+  F->setCallingConv(llvm::CallingConv::M68k_INTR);
+
+  // Step 2: Add attributes goodness.
+  F->addFnAttr(llvm::Attribute::NoInline);
+
+  // ??? is this right
+  // Step 3: Emit ISR vector alias.
+  unsigned Num = attr->getNumber() / 2;
+  llvm::GlobalAlias::create(llvm::Function::ExternalLinkage,
+"__isr_" + Twine(Num), F);
+}
+  }
+}
+
 //===--===//
 // AVR ABI Implementation.
 //===--===//
Index: clang/lib/Basic/Targets/M68k.h
===
--- /dev/null
+++ clang/lib/Basic/Targets/M68k.h
@@ -0,0 +1,57 @@
+//===--- M68k.h - Declare M68k target feature support ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file declares M68k TargetInfo objects.
+//
+//===--===//
+
+#ifndef M680X0_H_LTNCIPAD
+#define M680X0_H_LTNCIPAD
+
+#include 

[PATCH] D88394: [Driver][M68k] (Patch 8/8) Add driver support for M68k

2020-11-01 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu updated this revision to Diff 302188.
myhsu retitled this revision from "[Driver][M68K] (Patch 8/8) Add driver 
support for M68K" to "[Driver][M68k] (Patch 8/8) Add driver support for M68k".
myhsu edited the summary of this revision.
myhsu added a comment.

[NFC] Rename M680x0 to M68k


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

https://reviews.llvm.org/D88394

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/CMakeLists.txt
  clang/lib/Driver/ToolChains/Arch/M68k.cpp
  clang/lib/Driver/ToolChains/Arch/M68k.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/lib/Driver/ToolChains/Linux.cpp
  clang/test/Driver/m68k-features.cpp
  clang/test/Driver/m68k-sub-archs.cpp

Index: clang/test/Driver/m68k-sub-archs.cpp
===
--- /dev/null
+++ clang/test/Driver/m68k-sub-archs.cpp
@@ -0,0 +1,29 @@
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=68000 %s 2>&1 | FileCheck --check-prefix=CHECK-MX00 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=m68000 %s 2>&1 | FileCheck --check-prefix=CHECK-MX00 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=M68000 %s 2>&1 | FileCheck --check-prefix=CHECK-MX00 %s
+// RUN: %clang -### -target m68k-unknown-linux -m68000 %s 2>&1 | FileCheck --check-prefix=CHECK-MX00 %s
+// CHECK-MX00: "-target-cpu" "M68000"
+
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=68010 %s 2>&1 | FileCheck --check-prefix=CHECK-MX10 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=m68010 %s 2>&1 | FileCheck --check-prefix=CHECK-MX10 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=M68010 %s 2>&1 | FileCheck --check-prefix=CHECK-MX10 %s
+// RUN: %clang -### -target m68k-unknown-linux -m68010 %s 2>&1 | FileCheck --check-prefix=CHECK-MX10 %s
+// CHECK-MX10: "-target-cpu" "M68010"
+
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=68020 %s 2>&1 | FileCheck --check-prefix=CHECK-MX20 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=m68020 %s 2>&1 | FileCheck --check-prefix=CHECK-MX20 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=M68020 %s 2>&1 | FileCheck --check-prefix=CHECK-MX20 %s
+// RUN: %clang -### -target m68k-unknown-linux -m68020 %s 2>&1 | FileCheck --check-prefix=CHECK-MX20 %s
+// CHECK-MX20: "-target-cpu" "M68020"
+
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=68030 %s 2>&1 | FileCheck --check-prefix=CHECK-MX30 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=m68030 %s 2>&1 | FileCheck --check-prefix=CHECK-MX30 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=M68030 %s 2>&1 | FileCheck --check-prefix=CHECK-MX30 %s
+// RUN: %clang -### -target m68k-unknown-linux -m68030 %s 2>&1 | FileCheck --check-prefix=CHECK-MX30 %s
+// CHECK-MX30: "-target-cpu" "M68030"
+
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=68040 %s 2>&1 | FileCheck --check-prefix=CHECK-MX40 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=m68040 %s 2>&1 | FileCheck --check-prefix=CHECK-MX40 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=M68040 %s 2>&1 | FileCheck --check-prefix=CHECK-MX40 %s
+// RUN: %clang -### -target m68k-unknown-linux -m68040 %s 2>&1 | FileCheck --check-prefix=CHECK-MX40 %s
+// CHECK-MX40: "-target-cpu" "M68040"
Index: clang/test/Driver/m68k-features.cpp
===
--- /dev/null
+++ clang/test/Driver/m68k-features.cpp
@@ -0,0 +1,37 @@
+// Check macro definitions
+// RUN: %clang -target m68k-unknown-linux -m68000 -dM -E %s | FileCheck --check-prefix=CHECK-MX %s
+// CHECK-MX: #define __mc68000 1
+// CHECK-MX: #define __mc68000__ 1
+// CHECK-MX: #define mc68000 1
+
+// RUN: %clang -target m68k-unknown-linux -m68010 -dM -E %s | FileCheck --check-prefix=CHECK-MX10 %s
+// CHECK-MX10: #define __mc68000 1
+// CHECK-MX10: #define __mc68000__ 1
+// CHECK-MX10: #define __mc68010 1
+// CHECK-MX10: #define __mc68010__ 1
+// CHECK-MX10: #define mc68000 1
+// CHECK-MX10: #define mc68010 1
+
+// RUN: %clang -target m68k-unknown-linux -m68020 -dM -E %s | FileCheck --check-prefix=CHECK-MX20 %s
+// CHECK-MX20: #define __mc68000 1
+// CHECK-MX20: #define __mc68000__ 1
+// CHECK-MX20: #define __mc68020 1
+// CHECK-MX20: #define __mc68020__ 1
+// CHECK-MX20: #define mc68000 1
+// CHECK-MX20: #define mc68020 1
+
+// RUN: %clang -target m68k-unknown-linux -m68030 -dM -E %s | FileCheck --check-prefix=CHECK-MX30 %s
+// CHECK-MX30: #define __mc68000 1
+// CHECK-MX30: #define __mc68000__ 1
+// CHECK-MX30: #define __mc68030 1
+// CHECK-MX30: #define __mc68030__ 1
+// CHECK-MX30: #define mc68000 1
+// CHECK-MX30: #define mc68030 1
+
+// RUN: %clang -target m68k-unknown-linux -m68040 -dM -E %s | FileCheck --check-prefix=CHECK-MX40 %s
+// CHECK-MX40: #define __mc68000 1
+// CHECK-MX40: #define __mc68000__ 1
+// CHECK-MX40: #define __mc68040 1
+// CHECK-MX40: #define __mc68040__ 1
+// CHECK-MX40: #

[PATCH] D102585: [M68k] Support inline asm operands w/ simple constraints

2021-05-16 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu created this revision.
myhsu added reviewers: echristo, craig.topper.
Herald added a subscriber: hiraditya.
myhsu requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

This patch adds supports for inline assembly operands and some simple
operand constraints, including register and constant operands.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D102585

Files:
  clang/lib/Basic/Targets/M68k.cpp
  clang/lib/Basic/Targets/M68k.h
  clang/test/Sema/inline-asm-validate-m68k.c
  llvm/lib/Target/M68k/M68kAsmPrinter.cpp
  llvm/lib/Target/M68k/M68kAsmPrinter.h
  llvm/lib/Target/M68k/M68kISelLowering.cpp
  llvm/lib/Target/M68k/M68kISelLowering.h
  llvm/test/CodeGen/M68k/inline-asm.ll

Index: llvm/test/CodeGen/M68k/inline-asm.ll
===
--- /dev/null
+++ llvm/test/CodeGen/M68k/inline-asm.ll
@@ -0,0 +1,70 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -mtriple=m68k < %s -o - | FileCheck %s
+
+; This function is verifying constant constraints that can NOT
+; be easily checked by Clang. For example, 'K' and 'M' are both
+; constraints for values that are outside certain numerical range.
+define void @constant_constraints() {
+; CHECK-LABEL: constant_constraints:
+; CHECK: .cfi_startproc
+; CHECK-NEXT:  ; %bb.0: ; %entry
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #-129, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #128, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #-257, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #256, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #-32769, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #32768, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:rts
+entry:
+  call void asm sideeffect "move.l $0, %d1", "K"(i32 -129)
+  call void asm sideeffect "move.l $0, %d1", "K"(i32 128)
+  call void asm sideeffect "move.l $0, %d1", "M"(i32 -257)
+  call void asm sideeffect "move.l $0, %d1", "M"(i32 256)
+  call void asm sideeffect "move.l $0, %d1", "^Cj"(i32 -32769)
+  call void asm sideeffect "move.l $0, %d1", "^Cj"(i32 32768)
+  ret void
+}
+
+define void @register_constraints() {
+; CHECK-LABEL: register_constraints:
+; CHECK: .cfi_startproc
+; CHECK-NEXT:  ; %bb.0: ; %entry
+; CHECK-NEXT:sub.l #4, %sp
+; CHECK-NEXT:.cfi_def_cfa_offset -8
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #94, %d0
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:move.l %d0, (0,%sp)
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #87, %d0
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:move.l %d0, (0,%sp)
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #66, %a0
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:move.l %a0, (0,%sp)
+; CHECK-NEXT:add.l #4, %sp
+; CHECK-NEXT:rts
+entry:
+  %out = alloca i32, align 4
+  %0 = call i32 asm sideeffect "move.l #94, $0", "=r"()
+  store i32 %0, i32* %out, align 4
+  %1 = call i32 asm sideeffect "move.l #87, $0", "=d"()
+  store i32 %1, i32* %out, align 4
+  %2 = call i32 asm sideeffect "move.l #66, $0", "=a"()
+  store i32 %2, i32* %out, align 4
+  ret void
+}
+
Index: llvm/lib/Target/M68k/M68kISelLowering.h
===
--- llvm/lib/Target/M68k/M68kISelLowering.h
+++ llvm/lib/Target/M68k/M68kISelLowering.h
@@ -156,6 +156,17 @@
  unsigned JTI,
  MCContext &Ctx) const override;
 
+  ConstraintType getConstraintType(StringRef ConstraintStr) const override;
+
+  std::pair
+  getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI,
+   StringRef Constraint, MVT VT) const override;
+
+  // Lower operand with C_Immediate and C_Other constraint type
+  void LowerAsmOperandForConstraint(SDValue Op, std::string &Constraint,
+std::vector &Ops,
+SelectionDAG &DAG) const override;
+
   MachineBasicBlock *
   EmitInstrWithCustomInserter(MachineInstr &MI,
   MachineBasicBlock *MBB) const override;
Index: llvm/lib/Target/M68k/M68kISelLowering.cpp
===
--- llvm/lib/Target/M68k/M68kISelLowering.cpp
+++ llvm/lib/Target/M68k/M68kISelLowering.cpp
@@ -2689,6 +2689,193 @@
   return MCSymbolRefExpr::create(MF->getJTISymbol(JTI, Ctx), Ctx);
 }
 
+M68kTargetLowering::ConstraintType
+M68kTargetLowering::getConstraintType(StringRef Constraint) const {
+  if (Constraint.size() > 0) {
+switch (Constraint[0]) {
+case 'a':
+case 'd':
+  return C_RegisterClass;
+case 'I':
+case 'J':
+case 'K':
+case 'L':
+case 'M':
+case 'N':
+case 'O':
+case 'P':
+ 

[PATCH] D102585: [M68k] Support inline asm operands w/ simple constraints

2021-05-18 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu updated this revision to Diff 346338.
myhsu marked 2 inline comments as done.
myhsu added a comment.

Fixed lint warning and added more test cases


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

https://reviews.llvm.org/D102585

Files:
  clang/lib/Basic/Targets/M68k.cpp
  clang/lib/Basic/Targets/M68k.h
  clang/test/Sema/inline-asm-validate-m68k.c
  llvm/lib/Target/M68k/M68kAsmPrinter.cpp
  llvm/lib/Target/M68k/M68kAsmPrinter.h
  llvm/lib/Target/M68k/M68kISelLowering.cpp
  llvm/lib/Target/M68k/M68kISelLowering.h
  llvm/test/CodeGen/M68k/inline-asm.ll

Index: llvm/test/CodeGen/M68k/inline-asm.ll
===
--- /dev/null
+++ llvm/test/CodeGen/M68k/inline-asm.ll
@@ -0,0 +1,122 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -mtriple=m68k < %s -o - | FileCheck %s
+
+; This function is primarily testing constant constraints that can NOT
+; be easily checked by Clang. For example, 'K' and 'M' are both
+; constraints for values that are outside certain numerical range.
+define void @constant_constraints() {
+; CHECK-LABEL: constant_constraints:
+; CHECK: .cfi_startproc
+; CHECK-NEXT:  ; %bb.0: ; %entry
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #1, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #8, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #-32768, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #32767, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #-129, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #128, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #-8, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #-1, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #-257, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #256, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #24, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #31, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #16, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #8, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #15, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #0, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #1, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #-32769, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #32768, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:rts
+entry:
+  call void asm sideeffect "move.l $0, %d1", "I"(i32 1)
+  call void asm sideeffect "move.l $0, %d1", "I"(i32 8)
+  call void asm sideeffect "move.l $0, %d1", "J"(i32 -32768)
+  call void asm sideeffect "move.l $0, %d1", "J"(i32 32767)
+  call void asm sideeffect "move.l $0, %d1", "K"(i32 -129)
+  call void asm sideeffect "move.l $0, %d1", "K"(i32 128)
+  call void asm sideeffect "move.l $0, %d1", "L"(i32 -8)
+  call void asm sideeffect "move.l $0, %d1", "L"(i32 -1)
+  call void asm sideeffect "move.l $0, %d1", "M"(i32 -257)
+  call void asm sideeffect "move.l $0, %d1", "M"(i32 256)
+  call void asm sideeffect "move.l $0, %d1", "N"(i32 24)
+  call void asm sideeffect "move.l $0, %d1", "N"(i32 31)
+  call void asm sideeffect "move.l $0, %d1", "O"(i32 16)
+  call void asm sideeffect "move.l $0, %d1", "P"(i32 8)
+  call void asm sideeffect "move.l $0, %d1", "P"(i32 15)
+  call void asm sideeffect "move.l $0, %d1", "^C0"(i32 0)
+  call void asm sideeffect "move.l $0, %d1", "^Ci"(i32 1)
+  call void asm sideeffect "move.l $0, %d1", "^Cj"(i32 -32769)
+  call void asm sideeffect "move.l $0, %d1", "^Cj"(i32 32768)
+  ret void
+}
+
+define void @register_constraints() {
+; CHECK-LABEL: register_constraints:
+; CHECK: .cfi_startproc
+; CHECK-NEXT:  ; %bb.0: ; %entry
+; CHECK-NEXT:sub.l #4, %sp
+; CHECK-NEXT:.cfi_def_cfa_offset -8
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #94, %d0
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:move.l %d0, (0,%sp)
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #87, %d0
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:move.l %d0, (0,%sp)
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #66, %a0
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:move.l %a0, (0,%sp)
+; CHECK-NEXT:add.l #4, %sp
+; CHECK-NEXT:rts
+entry:
+  %out = alloca i32, align 4
+  %0 = call i32 asm sideeffect "move.l #94, $0", "=r"()
+  store i32 %0, i32* %out, align 4
+  %1 = call i32 asm sideeffect "move.l #87, $0", "=d"()
+  store i32 %1, i32* %out, align 4
+  %2 = call i32 asm sideeffect "move.l #66, $0", "=a"()
+  store i32 %2, i32* %out, align 4
+  ret void
+}
+
Index: llvm/lib/T

[PATCH] D102585: [M68k] Support inline asm operands w/ simple constraints

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



Comment at: clang/lib/Basic/Targets/M68k.cpp:145
   case 'd': // data register
-  case 'f': // floating point register
 info.setAllowsRegister();

nickdesaulniers wrote:
> did you mean to drop support for `'f'`?
To drop it for now. I believe this constraint was added by mistake since we 
barely has any support for floating point in the backend. I think it's a good 
idea to remove this constraint from the frontend so that it will not be misused 
until floating point implementation got matured.


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

https://reviews.llvm.org/D102585

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


[PATCH] D102805: [M68k] Allow user to preserve certain registers

2021-05-19 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu created this revision.
myhsu added reviewers: nickdesaulniers, simoncook.
Herald added subscribers: dang, s.egerton, hiraditya.
myhsu requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

Add `-ffixed-a[0-6]` and `-ffixed-d[0-7]` driver flags and the corresponding 
subtarget features to prevent certain register from being allocated.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D102805

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Arch/M68k.cpp
  clang/test/Driver/m68k-fixed-register.c
  llvm/lib/Target/M68k/M68k.td
  llvm/lib/Target/M68k/M68kRegisterInfo.cpp
  llvm/lib/Target/M68k/M68kSubtarget.cpp
  llvm/lib/Target/M68k/M68kSubtarget.h
  llvm/test/CodeGen/M68k/reserved-regs.ll

Index: llvm/test/CodeGen/M68k/reserved-regs.ll
===
--- /dev/null
+++ llvm/test/CodeGen/M68k/reserved-regs.ll
@@ -0,0 +1,70 @@
+; RUN: llc -mtriple=m68k -mattr="+reserve-a0" < %s | FileCheck --check-prefix=A0 %s
+; RUN: llc -mtriple=m68k -mattr="+reserve-a1" < %s | FileCheck --check-prefix=A1 %s
+; RUN: llc -mtriple=m68k -mattr="+reserve-a2" < %s | FileCheck --check-prefix=A2 %s
+; RUN: llc -mtriple=m68k -mattr="+reserve-a3" < %s | FileCheck --check-prefix=A3 %s
+; RUN: llc -mtriple=m68k -mattr="+reserve-a4" < %s | FileCheck --check-prefix=A4 %s
+; RUN: llc -mtriple=m68k -mattr="+reserve-a5" < %s | FileCheck --check-prefix=A5 %s
+; RUN: llc -mtriple=m68k -mattr="+reserve-a6" < %s | FileCheck --check-prefix=A6 %s
+; RUN: llc -mtriple=m68k -mattr="+reserve-d0" < %s | FileCheck --check-prefix=D0 %s
+; RUN: llc -mtriple=m68k -mattr="+reserve-d1" < %s | FileCheck --check-prefix=D1 %s
+; RUN: llc -mtriple=m68k -mattr="+reserve-d2" < %s | FileCheck --check-prefix=D2 %s
+; RUN: llc -mtriple=m68k -mattr="+reserve-d3" < %s | FileCheck --check-prefix=D3 %s
+; RUN: llc -mtriple=m68k -mattr="+reserve-d4" < %s | FileCheck --check-prefix=D4 %s
+; RUN: llc -mtriple=m68k -mattr="+reserve-d5" < %s | FileCheck --check-prefix=D5 %s
+; RUN: llc -mtriple=m68k -mattr="+reserve-d6" < %s | FileCheck --check-prefix=D6 %s
+; RUN: llc -mtriple=m68k -mattr="+reserve-d7" < %s | FileCheck --check-prefix=D7 %s
+
+; Used to exhaust all registers
+;
+; A better way to do this might be:
+; ```
+; @var = global [16 x i32] zeroinitializer
+; ...
+; %tmp = load load volatile [16 x i32], [16 x i32]* @var
+; store volatile [16 x i32] %tmp, [16 x i32]* @var
+; ```
+; Which is copied from `test/CodeGen/RISCV/reserved-regs.ll`.
+; But currently we have problem doing codegen for the above snippet
+; (https://bugs.llvm.org/show_bug.cgi?id=50377).
+define void @foo(i32* nocapture readonly %a, i32* nocapture readonly %b, i32* nocapture readonly %c, i32* nocapture readonly %d,
+ i32* nocapture readonly %a1, i32* nocapture readonly %b1, i32* nocapture readonly %c1, i32* nocapture readonly %d1,
+ i32* nocapture readonly %a2, i32* nocapture readonly %b2, i32* nocapture readonly %c2, i32* nocapture readonly %d2,
+ i32* nocapture readonly %a3, i32* nocapture readonly %b3, i32* nocapture readonly %c3, i32* nocapture readonly %d3) {
+entry:
+  %0 = load i32, i32* %a, align 4
+  %1 = load i32, i32* %b, align 4
+  %2 = load i32, i32* %c, align 4
+  %3 = load i32, i32* %d, align 4
+  %4 = load i32, i32* %a1, align 4
+  %5 = load i32, i32* %b1, align 4
+  %6 = load i32, i32* %c1, align 4
+  %7 = load i32, i32* %d1, align 4
+  %8 = load i32, i32* %a2, align 4
+  %9 = load i32, i32* %b2, align 4
+  %10 = load i32, i32* %c2, align 4
+  %11 = load i32, i32* %d2, align 4
+  %12 = load i32, i32* %a3, align 4
+  %13 = load i32, i32* %b3, align 4
+  %14 = load i32, i32* %c3, align 4
+  %15 = load i32, i32* %d3, align 4
+  ; A0-NOT: %a0
+  ; A1-NOT: %a1
+  ; A2-NOT: %a2
+  ; A3-NOT: %a3
+  ; A4-NOT: %a4
+  ; A5-NOT: %a5
+  ; A6-NOT: %a6
+  ; D0-NOT: %d0
+  ; D1-NOT: %d1
+  ; D2-NOT: %d2
+  ; D3-NOT: %d3
+  ; D4-NOT: %d4
+  ; D5-NOT: %d5
+  ; D6-NOT: %d6
+  ; D7-NOT: %d7
+  tail call void @bar(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5, i32 %6, i32 %7, i32 %8, i32 %9, i32 %10, i32 %11, i32 %12, i32 %13, i32 %14, i32 %15)
+  ret void
+}
+
+declare void @bar(i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32)
+
Index: llvm/lib/Target/M68k/M68kSubtarget.h
===
--- llvm/lib/Target/M68k/M68kSubtarget.h
+++ llvm/lib/Target/M68k/M68kSubtarget.h
@@ -18,6 +18,7 @@
 #include "M68kISelLowering.h"
 #include "M68kInstrInfo.h"
 
+#include "llvm/ADT/BitVector.h"
 #include "llvm/CodeGen/SelectionDAGTargetInfo.h"
 #include "llvm/CodeGen/TargetSubtargetInfo.h"
 #include "llvm/IR/DataLayout.h"
@@ -47,6 +48,8 @@
   enum SubtargetEnum { M00, M10, M20, M30, M40, M60 };
   SubtargetEnum SubtargetKind = M00;
 
+  BitVector UserReservedRegister;
+
   InstrItineraryData InstrItins;
 
   /// Smal

[PATCH] D102805: [M68k] Allow user to preserve certain registers

2021-05-19 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu updated this revision to Diff 346627.
myhsu marked an inline comment as done.
myhsu added a comment.

Fix formatting


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

https://reviews.llvm.org/D102805

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Arch/M68k.cpp
  clang/test/Driver/m68k-fixed-register.c
  llvm/lib/Target/M68k/M68k.td
  llvm/lib/Target/M68k/M68kRegisterInfo.cpp
  llvm/lib/Target/M68k/M68kSubtarget.cpp
  llvm/lib/Target/M68k/M68kSubtarget.h
  llvm/test/CodeGen/M68k/reserved-regs.ll

Index: llvm/test/CodeGen/M68k/reserved-regs.ll
===
--- /dev/null
+++ llvm/test/CodeGen/M68k/reserved-regs.ll
@@ -0,0 +1,70 @@
+; RUN: llc -mtriple=m68k -mattr="+reserve-a0" < %s | FileCheck --check-prefix=A0 %s
+; RUN: llc -mtriple=m68k -mattr="+reserve-a1" < %s | FileCheck --check-prefix=A1 %s
+; RUN: llc -mtriple=m68k -mattr="+reserve-a2" < %s | FileCheck --check-prefix=A2 %s
+; RUN: llc -mtriple=m68k -mattr="+reserve-a3" < %s | FileCheck --check-prefix=A3 %s
+; RUN: llc -mtriple=m68k -mattr="+reserve-a4" < %s | FileCheck --check-prefix=A4 %s
+; RUN: llc -mtriple=m68k -mattr="+reserve-a5" < %s | FileCheck --check-prefix=A5 %s
+; RUN: llc -mtriple=m68k -mattr="+reserve-a6" < %s | FileCheck --check-prefix=A6 %s
+; RUN: llc -mtriple=m68k -mattr="+reserve-d0" < %s | FileCheck --check-prefix=D0 %s
+; RUN: llc -mtriple=m68k -mattr="+reserve-d1" < %s | FileCheck --check-prefix=D1 %s
+; RUN: llc -mtriple=m68k -mattr="+reserve-d2" < %s | FileCheck --check-prefix=D2 %s
+; RUN: llc -mtriple=m68k -mattr="+reserve-d3" < %s | FileCheck --check-prefix=D3 %s
+; RUN: llc -mtriple=m68k -mattr="+reserve-d4" < %s | FileCheck --check-prefix=D4 %s
+; RUN: llc -mtriple=m68k -mattr="+reserve-d5" < %s | FileCheck --check-prefix=D5 %s
+; RUN: llc -mtriple=m68k -mattr="+reserve-d6" < %s | FileCheck --check-prefix=D6 %s
+; RUN: llc -mtriple=m68k -mattr="+reserve-d7" < %s | FileCheck --check-prefix=D7 %s
+
+; Used to exhaust all registers
+;
+; A better way to do this might be:
+; ```
+; @var = global [16 x i32] zeroinitializer
+; ...
+; %tmp = load load volatile [16 x i32], [16 x i32]* @var
+; store volatile [16 x i32] %tmp, [16 x i32]* @var
+; ```
+; Which is copied from `test/CodeGen/RISCV/reserved-regs.ll`.
+; But currently we have problem doing codegen for the above snippet
+; (https://bugs.llvm.org/show_bug.cgi?id=50377).
+define void @foo(i32* nocapture readonly %a, i32* nocapture readonly %b, i32* nocapture readonly %c, i32* nocapture readonly %d,
+ i32* nocapture readonly %a1, i32* nocapture readonly %b1, i32* nocapture readonly %c1, i32* nocapture readonly %d1,
+ i32* nocapture readonly %a2, i32* nocapture readonly %b2, i32* nocapture readonly %c2, i32* nocapture readonly %d2,
+ i32* nocapture readonly %a3, i32* nocapture readonly %b3, i32* nocapture readonly %c3, i32* nocapture readonly %d3) {
+entry:
+  %0 = load i32, i32* %a, align 4
+  %1 = load i32, i32* %b, align 4
+  %2 = load i32, i32* %c, align 4
+  %3 = load i32, i32* %d, align 4
+  %4 = load i32, i32* %a1, align 4
+  %5 = load i32, i32* %b1, align 4
+  %6 = load i32, i32* %c1, align 4
+  %7 = load i32, i32* %d1, align 4
+  %8 = load i32, i32* %a2, align 4
+  %9 = load i32, i32* %b2, align 4
+  %10 = load i32, i32* %c2, align 4
+  %11 = load i32, i32* %d2, align 4
+  %12 = load i32, i32* %a3, align 4
+  %13 = load i32, i32* %b3, align 4
+  %14 = load i32, i32* %c3, align 4
+  %15 = load i32, i32* %d3, align 4
+  ; A0-NOT: %a0
+  ; A1-NOT: %a1
+  ; A2-NOT: %a2
+  ; A3-NOT: %a3
+  ; A4-NOT: %a4
+  ; A5-NOT: %a5
+  ; A6-NOT: %a6
+  ; D0-NOT: %d0
+  ; D1-NOT: %d1
+  ; D2-NOT: %d2
+  ; D3-NOT: %d3
+  ; D4-NOT: %d4
+  ; D5-NOT: %d5
+  ; D6-NOT: %d6
+  ; D7-NOT: %d7
+  tail call void @bar(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5, i32 %6, i32 %7, i32 %8, i32 %9, i32 %10, i32 %11, i32 %12, i32 %13, i32 %14, i32 %15)
+  ret void
+}
+
+declare void @bar(i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32)
+
Index: llvm/lib/Target/M68k/M68kSubtarget.h
===
--- llvm/lib/Target/M68k/M68kSubtarget.h
+++ llvm/lib/Target/M68k/M68kSubtarget.h
@@ -18,6 +18,7 @@
 #include "M68kISelLowering.h"
 #include "M68kInstrInfo.h"
 
+#include "llvm/ADT/BitVector.h"
 #include "llvm/CodeGen/SelectionDAGTargetInfo.h"
 #include "llvm/CodeGen/TargetSubtargetInfo.h"
 #include "llvm/IR/DataLayout.h"
@@ -47,6 +48,8 @@
   enum SubtargetEnum { M00, M10, M20, M30, M40, M60 };
   SubtargetEnum SubtargetKind = M00;
 
+  BitVector UserReservedRegister;
+
   InstrItineraryData InstrItins;
 
   /// Small section is used.
@@ -95,6 +98,11 @@
 
   bool isPositionIndependent() const;
 
+  bool isRegisterReservedByUser(Register R) const {
+assert(R < M68k::NUM_TARGET_REGS && "Register out of range");
+return UserReservedRegister[R];
+  }
+
   /// Classify 

[PATCH] D102585: [M68k] Support inline asm operands w/ simple constraints

2021-05-19 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu updated this revision to Diff 346638.
myhsu marked 4 inline comments as done.
myhsu added a comment.

- Add test cases for valid constraints
- Fix formatting


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

https://reviews.llvm.org/D102585

Files:
  clang/lib/Basic/Targets/M68k.cpp
  clang/lib/Basic/Targets/M68k.h
  clang/test/Sema/inline-asm-validate-m68k.c
  llvm/lib/Target/M68k/M68kAsmPrinter.cpp
  llvm/lib/Target/M68k/M68kAsmPrinter.h
  llvm/lib/Target/M68k/M68kISelLowering.cpp
  llvm/lib/Target/M68k/M68kISelLowering.h
  llvm/test/CodeGen/M68k/inline-asm.ll

Index: llvm/test/CodeGen/M68k/inline-asm.ll
===
--- /dev/null
+++ llvm/test/CodeGen/M68k/inline-asm.ll
@@ -0,0 +1,122 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -mtriple=m68k < %s -o - | FileCheck %s
+
+; This function is primarily testing constant constraints that can NOT
+; be easily checked by Clang. For example, 'K' and 'M' are both
+; constraints for values that are outside certain numerical range.
+define void @constant_constraints() {
+; CHECK-LABEL: constant_constraints:
+; CHECK: .cfi_startproc
+; CHECK-NEXT:  ; %bb.0: ; %entry
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #1, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #8, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #-32768, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #32767, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #-129, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #128, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #-8, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #-1, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #-257, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #256, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #24, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #31, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #16, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #8, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #15, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #0, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #1, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #-32769, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #32768, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:rts
+entry:
+  call void asm sideeffect "move.l $0, %d1", "I"(i32 1)
+  call void asm sideeffect "move.l $0, %d1", "I"(i32 8)
+  call void asm sideeffect "move.l $0, %d1", "J"(i32 -32768)
+  call void asm sideeffect "move.l $0, %d1", "J"(i32 32767)
+  call void asm sideeffect "move.l $0, %d1", "K"(i32 -129)
+  call void asm sideeffect "move.l $0, %d1", "K"(i32 128)
+  call void asm sideeffect "move.l $0, %d1", "L"(i32 -8)
+  call void asm sideeffect "move.l $0, %d1", "L"(i32 -1)
+  call void asm sideeffect "move.l $0, %d1", "M"(i32 -257)
+  call void asm sideeffect "move.l $0, %d1", "M"(i32 256)
+  call void asm sideeffect "move.l $0, %d1", "N"(i32 24)
+  call void asm sideeffect "move.l $0, %d1", "N"(i32 31)
+  call void asm sideeffect "move.l $0, %d1", "O"(i32 16)
+  call void asm sideeffect "move.l $0, %d1", "P"(i32 8)
+  call void asm sideeffect "move.l $0, %d1", "P"(i32 15)
+  call void asm sideeffect "move.l $0, %d1", "^C0"(i32 0)
+  call void asm sideeffect "move.l $0, %d1", "^Ci"(i32 1)
+  call void asm sideeffect "move.l $0, %d1", "^Cj"(i32 -32769)
+  call void asm sideeffect "move.l $0, %d1", "^Cj"(i32 32768)
+  ret void
+}
+
+define void @register_constraints() {
+; CHECK-LABEL: register_constraints:
+; CHECK: .cfi_startproc
+; CHECK-NEXT:  ; %bb.0: ; %entry
+; CHECK-NEXT:sub.l #4, %sp
+; CHECK-NEXT:.cfi_def_cfa_offset -8
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #94, %d0
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:move.l %d0, (0,%sp)
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #87, %d0
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:move.l %d0, (0,%sp)
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #66, %a0
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:move.l %a0, (0,%sp)
+; CHECK-NEXT:add.l #4, %sp
+; CHECK-NEXT:rts
+entry:
+  %out = alloca i32, align 4
+  %0 = call i32 asm sideeffect "move.l #94, $0", "=r"()
+  store i32 %0, i32* %out, align 4
+  %1 = call i32 asm sideeffect "move.l #87, $0", "=d"()
+  store i32 %1, i32* %out, align 4
+  %2 = call i32 asm sideeffect "move.l #66, $0", "=a"()
+  store i32 %2, i32* %out, align 4
+  ret void
+}
+
Index:

[PATCH] D102585: [M68k] Support inline asm operands w/ simple constraints

2021-05-19 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu added a comment.

In D102585#2769887 , @nickdesaulniers 
wrote:

> Looking good @myhsu .  Also, I got your LLVM book recently!  You'll need to 
> sign it for me at the next llvm conf in person.

Thank you :-) Hope you will like it.
I'll start to practice my autograph too.




Comment at: clang/test/Sema/inline-asm-validate-m68k.c:51
+  asm volatile ("" :: "C0"(IncorrectVal)); // expected-error{{value '1' out of 
range for constraint 'C0'}}
+}

nickdesaulniers wrote:
> do we need tests for lowercase `a`, `r`, or `d`?
Actually I think `r` is already a built-in constraint letter for register. I'm 
adding test cases for `a` and `d` though.


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

https://reviews.llvm.org/D102585

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


[PATCH] D102805: [M68k] Allow user to preserve certain registers

2021-05-20 Thread Min-Yih Hsu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe620bea21199: [M68k] Allow user to preserve certain 
registers (authored by myhsu).

Changed prior to commit:
  https://reviews.llvm.org/D102805?vs=346627&id=346848#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102805

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Arch/M68k.cpp
  clang/test/Driver/m68k-fixed-register.c
  llvm/lib/Target/M68k/M68k.td
  llvm/lib/Target/M68k/M68kRegisterInfo.cpp
  llvm/lib/Target/M68k/M68kSubtarget.cpp
  llvm/lib/Target/M68k/M68kSubtarget.h
  llvm/test/CodeGen/M68k/reserved-regs.ll

Index: llvm/test/CodeGen/M68k/reserved-regs.ll
===
--- /dev/null
+++ llvm/test/CodeGen/M68k/reserved-regs.ll
@@ -0,0 +1,70 @@
+; RUN: llc -mtriple=m68k -mattr="+reserve-a0" < %s | FileCheck --check-prefix=A0 %s
+; RUN: llc -mtriple=m68k -mattr="+reserve-a1" < %s | FileCheck --check-prefix=A1 %s
+; RUN: llc -mtriple=m68k -mattr="+reserve-a2" < %s | FileCheck --check-prefix=A2 %s
+; RUN: llc -mtriple=m68k -mattr="+reserve-a3" < %s | FileCheck --check-prefix=A3 %s
+; RUN: llc -mtriple=m68k -mattr="+reserve-a4" < %s | FileCheck --check-prefix=A4 %s
+; RUN: llc -mtriple=m68k -mattr="+reserve-a5" < %s | FileCheck --check-prefix=A5 %s
+; RUN: llc -mtriple=m68k -mattr="+reserve-a6" < %s | FileCheck --check-prefix=A6 %s
+; RUN: llc -mtriple=m68k -mattr="+reserve-d0" < %s | FileCheck --check-prefix=D0 %s
+; RUN: llc -mtriple=m68k -mattr="+reserve-d1" < %s | FileCheck --check-prefix=D1 %s
+; RUN: llc -mtriple=m68k -mattr="+reserve-d2" < %s | FileCheck --check-prefix=D2 %s
+; RUN: llc -mtriple=m68k -mattr="+reserve-d3" < %s | FileCheck --check-prefix=D3 %s
+; RUN: llc -mtriple=m68k -mattr="+reserve-d4" < %s | FileCheck --check-prefix=D4 %s
+; RUN: llc -mtriple=m68k -mattr="+reserve-d5" < %s | FileCheck --check-prefix=D5 %s
+; RUN: llc -mtriple=m68k -mattr="+reserve-d6" < %s | FileCheck --check-prefix=D6 %s
+; RUN: llc -mtriple=m68k -mattr="+reserve-d7" < %s | FileCheck --check-prefix=D7 %s
+
+; Used to exhaust all registers
+;
+; A better way to do this might be:
+; ```
+; @var = global [16 x i32] zeroinitializer
+; ...
+; %tmp = load load volatile [16 x i32], [16 x i32]* @var
+; store volatile [16 x i32] %tmp, [16 x i32]* @var
+; ```
+; Which is copied from `test/CodeGen/RISCV/reserved-regs.ll`.
+; But currently we have problem doing codegen for the above snippet
+; (https://bugs.llvm.org/show_bug.cgi?id=50377).
+define void @foo(i32* nocapture readonly %a, i32* nocapture readonly %b, i32* nocapture readonly %c, i32* nocapture readonly %d,
+ i32* nocapture readonly %a1, i32* nocapture readonly %b1, i32* nocapture readonly %c1, i32* nocapture readonly %d1,
+ i32* nocapture readonly %a2, i32* nocapture readonly %b2, i32* nocapture readonly %c2, i32* nocapture readonly %d2,
+ i32* nocapture readonly %a3, i32* nocapture readonly %b3, i32* nocapture readonly %c3, i32* nocapture readonly %d3) {
+entry:
+  %0 = load i32, i32* %a, align 4
+  %1 = load i32, i32* %b, align 4
+  %2 = load i32, i32* %c, align 4
+  %3 = load i32, i32* %d, align 4
+  %4 = load i32, i32* %a1, align 4
+  %5 = load i32, i32* %b1, align 4
+  %6 = load i32, i32* %c1, align 4
+  %7 = load i32, i32* %d1, align 4
+  %8 = load i32, i32* %a2, align 4
+  %9 = load i32, i32* %b2, align 4
+  %10 = load i32, i32* %c2, align 4
+  %11 = load i32, i32* %d2, align 4
+  %12 = load i32, i32* %a3, align 4
+  %13 = load i32, i32* %b3, align 4
+  %14 = load i32, i32* %c3, align 4
+  %15 = load i32, i32* %d3, align 4
+  ; A0-NOT: %a0
+  ; A1-NOT: %a1
+  ; A2-NOT: %a2
+  ; A3-NOT: %a3
+  ; A4-NOT: %a4
+  ; A5-NOT: %a5
+  ; A6-NOT: %a6
+  ; D0-NOT: %d0
+  ; D1-NOT: %d1
+  ; D2-NOT: %d2
+  ; D3-NOT: %d3
+  ; D4-NOT: %d4
+  ; D5-NOT: %d5
+  ; D6-NOT: %d6
+  ; D7-NOT: %d7
+  tail call void @bar(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5, i32 %6, i32 %7, i32 %8, i32 %9, i32 %10, i32 %11, i32 %12, i32 %13, i32 %14, i32 %15)
+  ret void
+}
+
+declare void @bar(i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32)
+
Index: llvm/lib/Target/M68k/M68kSubtarget.h
===
--- llvm/lib/Target/M68k/M68kSubtarget.h
+++ llvm/lib/Target/M68k/M68kSubtarget.h
@@ -18,6 +18,7 @@
 #include "M68kISelLowering.h"
 #include "M68kInstrInfo.h"
 
+#include "llvm/ADT/BitVector.h"
 #include "llvm/CodeGen/SelectionDAGTargetInfo.h"
 #include "llvm/CodeGen/TargetSubtargetInfo.h"
 #include "llvm/IR/DataLayout.h"
@@ -47,6 +48,8 @@
   enum SubtargetEnum { M00, M10, M20, M30, M40, M60 };
   SubtargetEnum SubtargetKind = M00;
 
+  BitVector UserReservedRegister;
+
   InstrItineraryData InstrItins;
 
   /// Small section is used.
@@ -95,6 

[PATCH] D102585: [M68k] Support inline asm operands w/ simple constraints

2021-05-20 Thread Min-Yih Hsu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGdccf5c7dfb9e: [M68k] Support for inline asm operands w/ 
simple constraints (authored by myhsu).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102585

Files:
  clang/lib/Basic/Targets/M68k.cpp
  clang/lib/Basic/Targets/M68k.h
  clang/test/Sema/inline-asm-validate-m68k.c
  llvm/lib/Target/M68k/M68kAsmPrinter.cpp
  llvm/lib/Target/M68k/M68kAsmPrinter.h
  llvm/lib/Target/M68k/M68kISelLowering.cpp
  llvm/lib/Target/M68k/M68kISelLowering.h
  llvm/test/CodeGen/M68k/inline-asm.ll

Index: llvm/test/CodeGen/M68k/inline-asm.ll
===
--- /dev/null
+++ llvm/test/CodeGen/M68k/inline-asm.ll
@@ -0,0 +1,122 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -mtriple=m68k < %s -o - | FileCheck %s
+
+; This function is primarily testing constant constraints that can NOT
+; be easily checked by Clang. For example, 'K' and 'M' are both
+; constraints for values that are outside certain numerical range.
+define void @constant_constraints() {
+; CHECK-LABEL: constant_constraints:
+; CHECK: .cfi_startproc
+; CHECK-NEXT:  ; %bb.0: ; %entry
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #1, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #8, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #-32768, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #32767, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #-129, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #128, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #-8, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #-1, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #-257, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #256, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #24, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #31, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #16, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #8, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #15, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #0, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #1, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #-32769, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #32768, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:rts
+entry:
+  call void asm sideeffect "move.l $0, %d1", "I"(i32 1)
+  call void asm sideeffect "move.l $0, %d1", "I"(i32 8)
+  call void asm sideeffect "move.l $0, %d1", "J"(i32 -32768)
+  call void asm sideeffect "move.l $0, %d1", "J"(i32 32767)
+  call void asm sideeffect "move.l $0, %d1", "K"(i32 -129)
+  call void asm sideeffect "move.l $0, %d1", "K"(i32 128)
+  call void asm sideeffect "move.l $0, %d1", "L"(i32 -8)
+  call void asm sideeffect "move.l $0, %d1", "L"(i32 -1)
+  call void asm sideeffect "move.l $0, %d1", "M"(i32 -257)
+  call void asm sideeffect "move.l $0, %d1", "M"(i32 256)
+  call void asm sideeffect "move.l $0, %d1", "N"(i32 24)
+  call void asm sideeffect "move.l $0, %d1", "N"(i32 31)
+  call void asm sideeffect "move.l $0, %d1", "O"(i32 16)
+  call void asm sideeffect "move.l $0, %d1", "P"(i32 8)
+  call void asm sideeffect "move.l $0, %d1", "P"(i32 15)
+  call void asm sideeffect "move.l $0, %d1", "^C0"(i32 0)
+  call void asm sideeffect "move.l $0, %d1", "^Ci"(i32 1)
+  call void asm sideeffect "move.l $0, %d1", "^Cj"(i32 -32769)
+  call void asm sideeffect "move.l $0, %d1", "^Cj"(i32 32768)
+  ret void
+}
+
+define void @register_constraints() {
+; CHECK-LABEL: register_constraints:
+; CHECK: .cfi_startproc
+; CHECK-NEXT:  ; %bb.0: ; %entry
+; CHECK-NEXT:sub.l #4, %sp
+; CHECK-NEXT:.cfi_def_cfa_offset -8
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #94, %d0
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:move.l %d0, (0,%sp)
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #87, %d0
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:move.l %d0, (0,%sp)
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #66, %a0
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:move.l %a0, (0,%sp)
+; CHECK-NEXT:add.l #4, %sp
+; CHECK-NEXT:rts
+entry:
+  %out = alloca i32, align 4
+  %0 = call i32 asm sideeffect "move.l #94, $0", "=r"()
+  store i32 %0, i32* %out, align 4
+  %1 = call i32 asm sideeffect "move.l #87, $0", "=d"()
+  store i32 %1, i32* %out, alig

[PATCH] D103036: [cfe][inline-asm] Support target-specific escaped character in inline asm

2021-05-24 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu created this revision.
myhsu added reviewers: nickdesaulniers, nathanchance, m_zuckerman, rnk.
myhsu requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

GCC allows each target to define a set of non-letter and non-digit escaped 
characters for inline assembly that will be replaced by another string (They 
call this "punctuation" characters. The existing "%%" and "%{" -- replaced by 
'%' and '{' at the end -- can be seen as special cases shared by all targets).
This patch implements this feature by adding a new hook in `TargetInfo`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D103036

Files:
  clang/include/clang/Basic/TargetInfo.h
  clang/lib/AST/Stmt.cpp
  clang/lib/Basic/Targets/M68k.cpp
  clang/lib/Basic/Targets/M68k.h
  clang/test/CodeGen/m68k-asm.c

Index: clang/test/CodeGen/m68k-asm.c
===
--- /dev/null
+++ clang/test/CodeGen/m68k-asm.c
@@ -0,0 +1,21 @@
+// REQUIRES: m68k-registered-target
+// RUN: %clang -target m68k -S %s -o - | FileCheck %s
+
+// Test special escaped character in inline assembly
+void escaped() {
+  // '.' -> '.'
+  // CHECK: move.l #66, %d1
+  __asm__ ("move%.l #66, %%d1" ::);
+  // '#' -> '#'
+  // CHECK: move.l #66, %d1
+  __asm__ ("move.l %#66, %%d1" ::);
+  // '/' -> '%'
+  // CHECK: move.l #66, %d1
+  __asm__ ("move.l #66, %/d1" ::);
+  // '$' -> 's'
+  // CHECK: muls %d0, %d1
+  __asm__ ("mul%$ %%d0, %%d1" ::);
+  // '&' -> 'd'
+  // CHECK: move.l %d0, %d1
+  __asm__ ("move.l %%%&0, %%d1" ::);
+}
Index: clang/lib/Basic/Targets/M68k.h
===
--- clang/lib/Basic/Targets/M68k.h
+++ clang/lib/Basic/Targets/M68k.h
@@ -47,6 +47,7 @@
   std::string convertConstraint(const char *&Constraint) const override;
   bool validateAsmConstraint(const char *&Name,
  TargetInfo::ConstraintInfo &info) const override;
+  llvm::Optional handleAsmEscapedChar(char EscChar) const override;
   const char *getClobbers() const override;
   BuiltinVaListKind getBuiltinVaListKind() const override;
   bool setCPU(const std::string &Name) override;
Index: clang/lib/Basic/Targets/M68k.cpp
===
--- clang/lib/Basic/Targets/M68k.cpp
+++ clang/lib/Basic/Targets/M68k.cpp
@@ -191,6 +191,30 @@
   return false;
 }
 
+llvm::Optional
+M68kTargetInfo::handleAsmEscapedChar(char EscChar) const {
+  char C;
+  switch (EscChar) {
+  case '.':
+  case '#':
+C = EscChar;
+break;
+  case '/':
+C = '%';
+break;
+  case '$':
+C = 's';
+break;
+  case '&':
+C = 'd';
+break;
+  default:
+return llvm::None;
+  }
+
+  return std::string(1, C);
+}
+
 std::string M68kTargetInfo::convertConstraint(const char *&Constraint) const {
   if (*Constraint == 'C')
 // Two-character constraint; add "^" hint for later parsing
Index: clang/lib/AST/Stmt.cpp
===
--- clang/lib/AST/Stmt.cpp
+++ clang/lib/AST/Stmt.cpp
@@ -646,6 +646,8 @@
   continue;
 }
 
+const TargetInfo &TI = C.getTargetInfo();
+
 // Escaped "%" character in asm string.
 if (CurPtr == StrEnd) {
   // % at end of string is invalid (no escape).
@@ -666,6 +668,11 @@
   CurStringPiece += "${:uid}";
   continue;
 }
+// Handle target-specific escaped characters
+if (auto MaybeReplaceStr = TI.handleAsmEscapedChar(EscapedChar)) {
+  CurStringPiece += *MaybeReplaceStr;
+  continue;
+}
 
 // Otherwise, we have an operand.  If we have accumulated a string so far,
 // add it to the Pieces list.
@@ -688,7 +695,6 @@
   EscapedChar = *CurPtr++;
 }
 
-const TargetInfo &TI = C.getTargetInfo();
 const SourceManager &SM = C.getSourceManager();
 const LangOptions &LO = C.getLangOpts();
 
Index: clang/include/clang/Basic/TargetInfo.h
===
--- clang/include/clang/Basic/TargetInfo.h
+++ clang/include/clang/Basic/TargetInfo.h
@@ -1091,6 +1091,12 @@
 return std::string(1, *Constraint);
   }
 
+  // Replace some escaped characters with another string based on
+  // target-specific rules
+  virtual llvm::Optional handleAsmEscapedChar(char C) const {
+return llvm::None;
+  }
+
   /// Returns a string of target-specific clobbers, in LLVM format.
   virtual const char *getClobbers() const = 0;
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D103036: [cfe][inline-asm] Support target-specific escaped character in inline asm

2021-05-24 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu updated this revision to Diff 347574.
myhsu marked 3 inline comments as done.
myhsu added a comment.

Fix formatting


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

https://reviews.llvm.org/D103036

Files:
  clang/include/clang/Basic/TargetInfo.h
  clang/lib/AST/Stmt.cpp
  clang/lib/Basic/Targets/M68k.cpp
  clang/lib/Basic/Targets/M68k.h
  clang/test/CodeGen/m68k-asm.c

Index: clang/test/CodeGen/m68k-asm.c
===
--- /dev/null
+++ clang/test/CodeGen/m68k-asm.c
@@ -0,0 +1,21 @@
+// REQUIRES: m68k-registered-target
+// RUN: %clang -target m68k -S %s -o - | FileCheck %s
+
+// Test special escaped character in inline assembly
+void escaped() {
+  // '.' -> '.'
+  // CHECK: move.l #66, %d1
+  __asm__ ("move%.l #66, %%d1" ::);
+  // '#' -> '#'
+  // CHECK: move.l #66, %d1
+  __asm__ ("move.l %#66, %%d1" ::);
+  // '/' -> '%'
+  // CHECK: move.l #66, %d1
+  __asm__ ("move.l #66, %/d1" ::);
+  // '$' -> 's'
+  // CHECK: muls %d0, %d1
+  __asm__ ("mul%$ %%d0, %%d1" ::);
+  // '&' -> 'd'
+  // CHECK: move.l %d0, %d1
+  __asm__ ("move.l %%%&0, %%d1" ::);
+}
Index: clang/lib/Basic/Targets/M68k.h
===
--- clang/lib/Basic/Targets/M68k.h
+++ clang/lib/Basic/Targets/M68k.h
@@ -47,6 +47,7 @@
   std::string convertConstraint(const char *&Constraint) const override;
   bool validateAsmConstraint(const char *&Name,
  TargetInfo::ConstraintInfo &info) const override;
+  llvm::Optional handleAsmEscapedChar(char EscChar) const override;
   const char *getClobbers() const override;
   BuiltinVaListKind getBuiltinVaListKind() const override;
   bool setCPU(const std::string &Name) override;
Index: clang/lib/Basic/Targets/M68k.cpp
===
--- clang/lib/Basic/Targets/M68k.cpp
+++ clang/lib/Basic/Targets/M68k.cpp
@@ -191,6 +191,30 @@
   return false;
 }
 
+llvm::Optional
+M68kTargetInfo::handleAsmEscapedChar(char EscChar) const {
+  char C;
+  switch (EscChar) {
+  case '.':
+  case '#':
+C = EscChar;
+break;
+  case '/':
+C = '%';
+break;
+  case '$':
+C = 's';
+break;
+  case '&':
+C = 'd';
+break;
+  default:
+return llvm::None;
+  }
+
+  return std::string(1, C);
+}
+
 std::string M68kTargetInfo::convertConstraint(const char *&Constraint) const {
   if (*Constraint == 'C')
 // Two-character constraint; add "^" hint for later parsing
Index: clang/lib/AST/Stmt.cpp
===
--- clang/lib/AST/Stmt.cpp
+++ clang/lib/AST/Stmt.cpp
@@ -646,6 +646,8 @@
   continue;
 }
 
+const TargetInfo &TI = C.getTargetInfo();
+
 // Escaped "%" character in asm string.
 if (CurPtr == StrEnd) {
   // % at end of string is invalid (no escape).
@@ -656,6 +658,11 @@
 char EscapedChar = *CurPtr++;
 switch (EscapedChar) {
 default:
+  // Handle target-specific escaped characters.
+  if (auto MaybeReplaceStr = TI.handleAsmEscapedChar(EscapedChar)) {
+CurStringPiece += *MaybeReplaceStr;
+continue;
+  }
   break;
 case '%': // %% -> %
 case '{': // %{ -> {
@@ -688,7 +695,6 @@
   EscapedChar = *CurPtr++;
 }
 
-const TargetInfo &TI = C.getTargetInfo();
 const SourceManager &SM = C.getSourceManager();
 const LangOptions &LO = C.getLangOpts();
 
Index: clang/include/clang/Basic/TargetInfo.h
===
--- clang/include/clang/Basic/TargetInfo.h
+++ clang/include/clang/Basic/TargetInfo.h
@@ -1091,6 +1091,12 @@
 return std::string(1, *Constraint);
   }
 
+  /// Replace some escaped characters with another string based on
+  /// target-specific rules
+  virtual llvm::Optional handleAsmEscapedChar(char C) const {
+return llvm::None;
+  }
+
   /// Returns a string of target-specific clobbers, in LLVM format.
   virtual const char *getClobbers() const = 0;
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D103036: [cfe][inline-asm] Support target-specific escaped character in inline asm

2021-05-24 Thread Min-Yih Hsu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG6685a3f3e4c4: [cfe] Support target-specific escaped 
character in inline asm (authored by myhsu).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103036

Files:
  clang/include/clang/Basic/TargetInfo.h
  clang/lib/AST/Stmt.cpp
  clang/lib/Basic/Targets/M68k.cpp
  clang/lib/Basic/Targets/M68k.h
  clang/test/CodeGen/m68k-asm.c

Index: clang/test/CodeGen/m68k-asm.c
===
--- /dev/null
+++ clang/test/CodeGen/m68k-asm.c
@@ -0,0 +1,21 @@
+// REQUIRES: m68k-registered-target
+// RUN: %clang -target m68k -S %s -o - | FileCheck %s
+
+// Test special escaped character in inline assembly
+void escaped() {
+  // '.' -> '.'
+  // CHECK: move.l #66, %d1
+  __asm__ ("move%.l #66, %%d1" ::);
+  // '#' -> '#'
+  // CHECK: move.l #66, %d1
+  __asm__ ("move.l %#66, %%d1" ::);
+  // '/' -> '%'
+  // CHECK: move.l #66, %d1
+  __asm__ ("move.l #66, %/d1" ::);
+  // '$' -> 's'
+  // CHECK: muls %d0, %d1
+  __asm__ ("mul%$ %%d0, %%d1" ::);
+  // '&' -> 'd'
+  // CHECK: move.l %d0, %d1
+  __asm__ ("move.l %%%&0, %%d1" ::);
+}
Index: clang/lib/Basic/Targets/M68k.h
===
--- clang/lib/Basic/Targets/M68k.h
+++ clang/lib/Basic/Targets/M68k.h
@@ -47,6 +47,7 @@
   std::string convertConstraint(const char *&Constraint) const override;
   bool validateAsmConstraint(const char *&Name,
  TargetInfo::ConstraintInfo &info) const override;
+  llvm::Optional handleAsmEscapedChar(char EscChar) const override;
   const char *getClobbers() const override;
   BuiltinVaListKind getBuiltinVaListKind() const override;
   bool setCPU(const std::string &Name) override;
Index: clang/lib/Basic/Targets/M68k.cpp
===
--- clang/lib/Basic/Targets/M68k.cpp
+++ clang/lib/Basic/Targets/M68k.cpp
@@ -191,6 +191,30 @@
   return false;
 }
 
+llvm::Optional
+M68kTargetInfo::handleAsmEscapedChar(char EscChar) const {
+  char C;
+  switch (EscChar) {
+  case '.':
+  case '#':
+C = EscChar;
+break;
+  case '/':
+C = '%';
+break;
+  case '$':
+C = 's';
+break;
+  case '&':
+C = 'd';
+break;
+  default:
+return llvm::None;
+  }
+
+  return std::string(1, C);
+}
+
 std::string M68kTargetInfo::convertConstraint(const char *&Constraint) const {
   if (*Constraint == 'C')
 // Two-character constraint; add "^" hint for later parsing
Index: clang/lib/AST/Stmt.cpp
===
--- clang/lib/AST/Stmt.cpp
+++ clang/lib/AST/Stmt.cpp
@@ -646,6 +646,8 @@
   continue;
 }
 
+const TargetInfo &TI = C.getTargetInfo();
+
 // Escaped "%" character in asm string.
 if (CurPtr == StrEnd) {
   // % at end of string is invalid (no escape).
@@ -656,6 +658,11 @@
 char EscapedChar = *CurPtr++;
 switch (EscapedChar) {
 default:
+  // Handle target-specific escaped characters.
+  if (auto MaybeReplaceStr = TI.handleAsmEscapedChar(EscapedChar)) {
+CurStringPiece += *MaybeReplaceStr;
+continue;
+  }
   break;
 case '%': // %% -> %
 case '{': // %{ -> {
@@ -688,7 +695,6 @@
   EscapedChar = *CurPtr++;
 }
 
-const TargetInfo &TI = C.getTargetInfo();
 const SourceManager &SM = C.getSourceManager();
 const LangOptions &LO = C.getLangOpts();
 
Index: clang/include/clang/Basic/TargetInfo.h
===
--- clang/include/clang/Basic/TargetInfo.h
+++ clang/include/clang/Basic/TargetInfo.h
@@ -1091,6 +1091,12 @@
 return std::string(1, *Constraint);
   }
 
+  /// Replace some escaped characters with another string based on
+  /// target-specific rules
+  virtual llvm::Optional handleAsmEscapedChar(char C) const {
+return llvm::None;
+  }
+
   /// Returns a string of target-specific clobbers, in LLVM format.
   virtual const char *getClobbers() const = 0;
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D88393: [cfe][M68k] (Patch 7/8) Basic Clang support

2021-02-01 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu updated this revision to Diff 320585.
myhsu marked 4 inline comments as done.
myhsu added a comment.

- Addressed feedbacks
  - Now M68k tries to use ABI that is compatible with GCC


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

https://reviews.llvm.org/D88393

Files:
  clang/include/clang/Basic/Attr.td
  clang/lib/Basic/CMakeLists.txt
  clang/lib/Basic/Targets.cpp
  clang/lib/Basic/Targets/M68k.cpp
  clang/lib/Basic/Targets/M68k.h
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/Sema/SemaDeclAttr.cpp

Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -6306,6 +6306,39 @@
   D->addAttr(::new (S.Context) MipsInterruptAttr(S.Context, AL, Kind));
 }
 
+static void handleM68kInterruptAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
+  if (!checkAttributeNumArgs(S, AL, 1))
+return;
+
+  if (!AL.isArgExpr(0)) {
+S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
+<< AL << AANT_ArgumentIntegerConstant;
+return;
+  }
+
+  // FIXME: Check for decl - it should be void ()(void).
+
+  Expr *NumParamsExpr = static_cast(AL.getArgAsExpr(0));
+  auto MaybeNumParams = NumParamsExpr->getIntegerConstantExpr(S.Context);
+  if (!MaybeNumParams) {
+S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
+<< AL << AANT_ArgumentIntegerConstant
+<< NumParamsExpr->getSourceRange();
+return;
+  }
+
+  unsigned Num = MaybeNumParams->getLimitedValue(255);
+  if ((Num & 1) || Num > 30) {
+S.Diag(AL.getLoc(), diag::err_attribute_argument_out_of_bounds)
+<< AL << (int)MaybeNumParams->getSExtValue()
+<< NumParamsExpr->getSourceRange();
+return;
+  }
+
+  D->addAttr(::new (S.Context) M68kInterruptAttr(S.Context, AL, Num));
+  D->addAttr(UsedAttr::CreateImplicit(S.Context));
+}
+
 static void handleAnyX86InterruptAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
   // Semantic checks for a function with the 'interrupt' attribute.
   // a) Must be a function.
@@ -6578,6 +6611,9 @@
   case llvm::Triple::mips:
 handleMipsInterruptAttr(S, D, AL);
 break;
+  case llvm::Triple::m68k:
+handleM68kInterruptAttr(S, D, AL);
+break;
   case llvm::Triple::x86:
   case llvm::Triple::x86_64:
 handleAnyX86InterruptAttr(S, D, AL);
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -8066,6 +8066,43 @@
   return false;
 }
 
+//===--===//
+// M68k ABI Implementation
+//===--===//
+
+namespace {
+
+class M68kTargetCodeGenInfo : public TargetCodeGenInfo {
+public:
+  M68kTargetCodeGenInfo(CodeGenTypes &CGT)
+  : TargetCodeGenInfo(std::make_unique(CGT)) {}
+  void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
+   CodeGen::CodeGenModule &M) const override;
+};
+
+} // namespace
+
+void M68kTargetCodeGenInfo::setTargetAttributes(
+const Decl *D, llvm::GlobalValue *GV, CodeGen::CodeGenModule &M) const {
+  if (const auto *FD = dyn_cast_or_null(D)) {
+if (const auto *attr = FD->getAttr()) {
+  // Handle 'interrupt' attribute:
+  llvm::Function *F = cast(GV);
+
+  // Step 1: Set ISR calling convention.
+  F->setCallingConv(llvm::CallingConv::M68k_INTR);
+
+  // Step 2: Add attributes goodness.
+  F->addFnAttr(llvm::Attribute::NoInline);
+
+  // Step 3: Emit ISR vector alias.
+  unsigned Num = attr->getNumber() / 2;
+  llvm::GlobalAlias::create(llvm::Function::ExternalLinkage,
+"__isr_" + Twine(Num), F);
+}
+  }
+}
+
 //===--===//
 // AVR ABI Implementation.
 //===--===//
@@ -10877,6 +10914,8 @@
 
   case llvm::Triple::le32:
 return SetCGInfo(new PNaClTargetCodeGenInfo(Types));
+  case llvm::Triple::m68k:
+return SetCGInfo(new M68kTargetCodeGenInfo(Types));
   case llvm::Triple::mips:
   case llvm::Triple::mipsel:
 if (Triple.getOS() == llvm::Triple::NaCl)
Index: clang/lib/Basic/Targets/M68k.h
===
--- /dev/null
+++ clang/lib/Basic/Targets/M68k.h
@@ -0,0 +1,57 @@
+//===--- M68k.h - Declare M68k target feature support ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file declares M68k TargetInfo objects.
+//
+//===--

[PATCH] D88393: [cfe][M68k] (Patch 7/8) Basic Clang support

2021-02-01 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu added inline comments.



Comment at: clang/lib/Basic/Targets/M68k.cpp:63
+.Case("generic", CK_68000)
+.Case("M68000", CK_68000)
+.Case("M68010", CK_68010)

jrtc27 wrote:
> GCC's -mcpu excludes any M prefix and is just the number.
we also support -mcpu with just number via `m68k::getM68kTargetCPU`



Comment at: clang/lib/Basic/Targets/M68k.cpp:77-79
+  Builder.defineMacro("M68k");
+  Builder.defineMacro("__M68k__");
+  Builder.defineMacro("__M68K__");

jrtc27 wrote:
> Where are these coming from? GCC only defines `__m68k__`.
I think GCC does: 
https://github.com/gcc-mirror/gcc/blob/b90d051ecbc1d8972ae1bf0cd7588fcc66df0722/gcc/config/m68k/m68k.h#L64

Also I found this page: https://sourceforge.net/p/predef/wiki/Architectures


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

https://reviews.llvm.org/D88393

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


[PATCH] D88394: [Driver][M68k] (Patch 8/8) Add driver support for M68k

2021-02-01 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu updated this revision to Diff 320586.
myhsu marked 5 inline comments as done.
myhsu added a comment.
Herald added a reviewer: jansvoboda11.

- Addressed feedbacks


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

https://reviews.llvm.org/D88394

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/CMakeLists.txt
  clang/lib/Driver/ToolChains/Arch/M68k.cpp
  clang/lib/Driver/ToolChains/Arch/M68k.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/lib/Driver/ToolChains/Linux.cpp
  clang/test/Driver/m68k-features.cpp
  clang/test/Driver/m68k-sub-archs.cpp

Index: clang/test/Driver/m68k-sub-archs.cpp
===
--- /dev/null
+++ clang/test/Driver/m68k-sub-archs.cpp
@@ -0,0 +1,35 @@
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=68000 %s 2>&1 | FileCheck --check-prefix=CHECK-MX00 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=m68000 %s 2>&1 | FileCheck --check-prefix=CHECK-MX00 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=M68000 %s 2>&1 | FileCheck --check-prefix=CHECK-MX00 %s
+// RUN: %clang -### -target m68k-unknown-linux -m68000 %s 2>&1 | FileCheck --check-prefix=CHECK-MX00 %s
+// CHECK-MX00: "-target-cpu" "M68000"
+
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=68010 %s 2>&1 | FileCheck --check-prefix=CHECK-MX10 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=m68010 %s 2>&1 | FileCheck --check-prefix=CHECK-MX10 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=M68010 %s 2>&1 | FileCheck --check-prefix=CHECK-MX10 %s
+// RUN: %clang -### -target m68k-unknown-linux -m68010 %s 2>&1 | FileCheck --check-prefix=CHECK-MX10 %s
+// CHECK-MX10: "-target-cpu" "M68010"
+
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=68020 %s 2>&1 | FileCheck --check-prefix=CHECK-MX20 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=m68020 %s 2>&1 | FileCheck --check-prefix=CHECK-MX20 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=M68020 %s 2>&1 | FileCheck --check-prefix=CHECK-MX20 %s
+// RUN: %clang -### -target m68k-unknown-linux -m68020 %s 2>&1 | FileCheck --check-prefix=CHECK-MX20 %s
+// CHECK-MX20: "-target-cpu" "M68020"
+
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=68030 %s 2>&1 | FileCheck --check-prefix=CHECK-MX30 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=m68030 %s 2>&1 | FileCheck --check-prefix=CHECK-MX30 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=M68030 %s 2>&1 | FileCheck --check-prefix=CHECK-MX30 %s
+// RUN: %clang -### -target m68k-unknown-linux -m68030 %s 2>&1 | FileCheck --check-prefix=CHECK-MX30 %s
+// CHECK-MX30: "-target-cpu" "M68030"
+
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=68040 %s 2>&1 | FileCheck --check-prefix=CHECK-MX40 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=m68040 %s 2>&1 | FileCheck --check-prefix=CHECK-MX40 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=M68040 %s 2>&1 | FileCheck --check-prefix=CHECK-MX40 %s
+// RUN: %clang -### -target m68k-unknown-linux -m68040 %s 2>&1 | FileCheck --check-prefix=CHECK-MX40 %s
+// CHECK-MX40: "-target-cpu" "M68040"
+
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=68060 %s 2>&1 | FileCheck --check-prefix=CHECK-MX60 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=m68060 %s 2>&1 | FileCheck --check-prefix=CHECK-MX60 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=M68060 %s 2>&1 | FileCheck --check-prefix=CHECK-MX60 %s
+// RUN: %clang -### -target m68k-unknown-linux -m68060 %s 2>&1 | FileCheck --check-prefix=CHECK-MX60 %s
+// CHECK-MX60: "-target-cpu" "M68060"
Index: clang/test/Driver/m68k-features.cpp
===
--- /dev/null
+++ clang/test/Driver/m68k-features.cpp
@@ -0,0 +1,45 @@
+// Check macro definitions
+// RUN: %clang -target m68k-unknown-linux -m68000 -dM -E %s | FileCheck --check-prefix=CHECK-MX %s
+// CHECK-MX: #define __mc68000 1
+// CHECK-MX: #define __mc68000__ 1
+// CHECK-MX: #define mc68000 1
+
+// RUN: %clang -target m68k-unknown-linux -m68010 -dM -E %s | FileCheck --check-prefix=CHECK-MX10 %s
+// CHECK-MX10: #define __mc68000 1
+// CHECK-MX10: #define __mc68000__ 1
+// CHECK-MX10: #define __mc68010 1
+// CHECK-MX10: #define __mc68010__ 1
+// CHECK-MX10: #define mc68000 1
+// CHECK-MX10: #define mc68010 1
+
+// RUN: %clang -target m68k-unknown-linux -m68020 -dM -E %s | FileCheck --check-prefix=CHECK-MX20 %s
+// CHECK-MX20: #define __mc68000 1
+// CHECK-MX20: #define __mc68000__ 1
+// CHECK-MX20: #define __mc68020 1
+// CHECK-MX20: #define __mc68020__ 1
+// CHECK-MX20: #define mc68000 1
+// CHECK-MX20: #define mc68020 1
+
+// RUN: %clang -target m68k-unknown-linux -m68030 -dM -E %s | FileCheck --check-prefix=CHECK-MX30 %s
+// CHECK-MX30: #define __mc68000 1
+// CHECK-MX30: #define __mc68000__ 1
+// CHECK-MX30: #define __mc68030 1
+// CHECK-MX30: #define

[PATCH] D88394: [Driver][M68k] (Patch 8/8) Add driver support for M68k

2021-02-01 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu added inline comments.



Comment at: clang/lib/Driver/ToolChains/Gnu.cpp:2101
 
+  static const char *const M68kLibDirs[] = {"/lib"};
+  static const char *const M68kTriples[] = {

MaskRay wrote:
> The second `const ` is redundant
I don't think so...first, `const char *const` means "a pointer points to const 
char, and you can't modify this pointer", which make sense in this context. 
Second, all the surrounding code here are using `const char *const`.


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

https://reviews.llvm.org/D88394

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


[PATCH] D88393: [cfe][M68k] (Patch 7/8) Basic Clang support

2021-02-01 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu updated this revision to Diff 320604.
myhsu added a comment.

- Addressed feedback
  - Remove redundant target macro definitions


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

https://reviews.llvm.org/D88393

Files:
  clang/include/clang/Basic/Attr.td
  clang/lib/Basic/CMakeLists.txt
  clang/lib/Basic/Targets.cpp
  clang/lib/Basic/Targets/M68k.cpp
  clang/lib/Basic/Targets/M68k.h
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/Sema/SemaDeclAttr.cpp

Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -6306,6 +6306,39 @@
   D->addAttr(::new (S.Context) MipsInterruptAttr(S.Context, AL, Kind));
 }
 
+static void handleM68kInterruptAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
+  if (!checkAttributeNumArgs(S, AL, 1))
+return;
+
+  if (!AL.isArgExpr(0)) {
+S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
+<< AL << AANT_ArgumentIntegerConstant;
+return;
+  }
+
+  // FIXME: Check for decl - it should be void ()(void).
+
+  Expr *NumParamsExpr = static_cast(AL.getArgAsExpr(0));
+  auto MaybeNumParams = NumParamsExpr->getIntegerConstantExpr(S.Context);
+  if (!MaybeNumParams) {
+S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
+<< AL << AANT_ArgumentIntegerConstant
+<< NumParamsExpr->getSourceRange();
+return;
+  }
+
+  unsigned Num = MaybeNumParams->getLimitedValue(255);
+  if ((Num & 1) || Num > 30) {
+S.Diag(AL.getLoc(), diag::err_attribute_argument_out_of_bounds)
+<< AL << (int)MaybeNumParams->getSExtValue()
+<< NumParamsExpr->getSourceRange();
+return;
+  }
+
+  D->addAttr(::new (S.Context) M68kInterruptAttr(S.Context, AL, Num));
+  D->addAttr(UsedAttr::CreateImplicit(S.Context));
+}
+
 static void handleAnyX86InterruptAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
   // Semantic checks for a function with the 'interrupt' attribute.
   // a) Must be a function.
@@ -6578,6 +6611,9 @@
   case llvm::Triple::mips:
 handleMipsInterruptAttr(S, D, AL);
 break;
+  case llvm::Triple::m68k:
+handleM68kInterruptAttr(S, D, AL);
+break;
   case llvm::Triple::x86:
   case llvm::Triple::x86_64:
 handleAnyX86InterruptAttr(S, D, AL);
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -8066,6 +8066,43 @@
   return false;
 }
 
+//===--===//
+// M68k ABI Implementation
+//===--===//
+
+namespace {
+
+class M68kTargetCodeGenInfo : public TargetCodeGenInfo {
+public:
+  M68kTargetCodeGenInfo(CodeGenTypes &CGT)
+  : TargetCodeGenInfo(std::make_unique(CGT)) {}
+  void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
+   CodeGen::CodeGenModule &M) const override;
+};
+
+} // namespace
+
+void M68kTargetCodeGenInfo::setTargetAttributes(
+const Decl *D, llvm::GlobalValue *GV, CodeGen::CodeGenModule &M) const {
+  if (const auto *FD = dyn_cast_or_null(D)) {
+if (const auto *attr = FD->getAttr()) {
+  // Handle 'interrupt' attribute:
+  llvm::Function *F = cast(GV);
+
+  // Step 1: Set ISR calling convention.
+  F->setCallingConv(llvm::CallingConv::M68k_INTR);
+
+  // Step 2: Add attributes goodness.
+  F->addFnAttr(llvm::Attribute::NoInline);
+
+  // Step 3: Emit ISR vector alias.
+  unsigned Num = attr->getNumber() / 2;
+  llvm::GlobalAlias::create(llvm::Function::ExternalLinkage,
+"__isr_" + Twine(Num), F);
+}
+  }
+}
+
 //===--===//
 // AVR ABI Implementation.
 //===--===//
@@ -10877,6 +10914,8 @@
 
   case llvm::Triple::le32:
 return SetCGInfo(new PNaClTargetCodeGenInfo(Types));
+  case llvm::Triple::m68k:
+return SetCGInfo(new M68kTargetCodeGenInfo(Types));
   case llvm::Triple::mips:
   case llvm::Triple::mipsel:
 if (Triple.getOS() == llvm::Triple::NaCl)
Index: clang/lib/Basic/Targets/M68k.h
===
--- /dev/null
+++ clang/lib/Basic/Targets/M68k.h
@@ -0,0 +1,57 @@
+//===--- M68k.h - Declare M68k target feature support ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file declares M68k TargetInfo objects.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_LIB_BASIC

[PATCH] D88393: [cfe][M68k] (Patch 7/8) Basic Clang support

2021-02-01 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu added inline comments.



Comment at: clang/lib/Basic/Targets/M68k.cpp:77-79
+  Builder.defineMacro("M68k");
+  Builder.defineMacro("__M68k__");
+  Builder.defineMacro("__M68K__");

jrtc27 wrote:
> myhsu wrote:
> > jrtc27 wrote:
> > > Where are these coming from? GCC only defines `__m68k__`.
> > I think GCC does: 
> > https://github.com/gcc-mirror/gcc/blob/b90d051ecbc1d8972ae1bf0cd7588fcc66df0722/gcc/config/m68k/m68k.h#L64
> > 
> > Also I found this page: https://sourceforge.net/p/predef/wiki/Architectures
> Yes, and as you can see none of those three are defined by GCC. Defining 
> `M68k` is particularly bad as it will collide with the C++ namespace used by 
> this very backend so you won't be able to build Clang with Clang on m68k! And 
> the others are just a waste of time. Defining fewer macros is best, that way 
> people don't come to rely on non-standard ones and instead use the single 
> option that exists everywhere (`__m68k__`).
> it will collide with the C++ namespace used by this very backend so you won't 
> be able to build Clang with Clang on m68k

good point :-)

> Defining fewer macros is best, that way people don't come to rely on 
> non-standard ones and instead use the single option that exists everywhere

fair enough


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

https://reviews.llvm.org/D88393

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


[PATCH] D88393: [cfe][M68k] (Patch 7/8) Basic Clang support

2021-02-25 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu updated this revision to Diff 326505.
myhsu marked 4 inline comments as done.
myhsu added a comment.

- [NFC] Addressed feedbacks


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

https://reviews.llvm.org/D88393

Files:
  clang/include/clang/Basic/Attr.td
  clang/lib/Basic/CMakeLists.txt
  clang/lib/Basic/Targets.cpp
  clang/lib/Basic/Targets/M68k.cpp
  clang/lib/Basic/Targets/M68k.h
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/Sema/SemaDeclAttr.cpp

Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -6306,6 +6306,39 @@
   D->addAttr(::new (S.Context) MipsInterruptAttr(S.Context, AL, Kind));
 }
 
+static void handleM68kInterruptAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
+  if (!checkAttributeNumArgs(S, AL, 1))
+return;
+
+  if (!AL.isArgExpr(0)) {
+S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
+<< AL << AANT_ArgumentIntegerConstant;
+return;
+  }
+
+  // FIXME: Check for decl - it should be void ()(void).
+
+  Expr *NumParamsExpr = static_cast(AL.getArgAsExpr(0));
+  auto MaybeNumParams = NumParamsExpr->getIntegerConstantExpr(S.Context);
+  if (!MaybeNumParams) {
+S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
+<< AL << AANT_ArgumentIntegerConstant
+<< NumParamsExpr->getSourceRange();
+return;
+  }
+
+  unsigned Num = MaybeNumParams->getLimitedValue(255);
+  if ((Num & 1) || Num > 30) {
+S.Diag(AL.getLoc(), diag::err_attribute_argument_out_of_bounds)
+<< AL << (int)MaybeNumParams->getSExtValue()
+<< NumParamsExpr->getSourceRange();
+return;
+  }
+
+  D->addAttr(::new (S.Context) M68kInterruptAttr(S.Context, AL, Num));
+  D->addAttr(UsedAttr::CreateImplicit(S.Context));
+}
+
 static void handleAnyX86InterruptAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
   // Semantic checks for a function with the 'interrupt' attribute.
   // a) Must be a function.
@@ -6578,6 +6611,9 @@
   case llvm::Triple::mips:
 handleMipsInterruptAttr(S, D, AL);
 break;
+  case llvm::Triple::m68k:
+handleM68kInterruptAttr(S, D, AL);
+break;
   case llvm::Triple::x86:
   case llvm::Triple::x86_64:
 handleAnyX86InterruptAttr(S, D, AL);
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -8066,6 +8066,43 @@
   return false;
 }
 
+//===--===//
+// M68k ABI Implementation
+//===--===//
+
+namespace {
+
+class M68kTargetCodeGenInfo : public TargetCodeGenInfo {
+public:
+  M68kTargetCodeGenInfo(CodeGenTypes &CGT)
+  : TargetCodeGenInfo(std::make_unique(CGT)) {}
+  void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
+   CodeGen::CodeGenModule &M) const override;
+};
+
+} // namespace
+
+void M68kTargetCodeGenInfo::setTargetAttributes(
+const Decl *D, llvm::GlobalValue *GV, CodeGen::CodeGenModule &M) const {
+  if (const auto *FD = dyn_cast_or_null(D)) {
+if (const auto *attr = FD->getAttr()) {
+  // Handle 'interrupt' attribute:
+  llvm::Function *F = cast(GV);
+
+  // Step 1: Set ISR calling convention.
+  F->setCallingConv(llvm::CallingConv::M68k_INTR);
+
+  // Step 2: Add attributes goodness.
+  F->addFnAttr(llvm::Attribute::NoInline);
+
+  // Step 3: Emit ISR vector alias.
+  unsigned Num = attr->getNumber() / 2;
+  llvm::GlobalAlias::create(llvm::Function::ExternalLinkage,
+"__isr_" + Twine(Num), F);
+}
+  }
+}
+
 //===--===//
 // AVR ABI Implementation.
 //===--===//
@@ -10877,6 +10914,8 @@
 
   case llvm::Triple::le32:
 return SetCGInfo(new PNaClTargetCodeGenInfo(Types));
+  case llvm::Triple::m68k:
+return SetCGInfo(new M68kTargetCodeGenInfo(Types));
   case llvm::Triple::mips:
   case llvm::Triple::mipsel:
 if (Triple.getOS() == llvm::Triple::NaCl)
Index: clang/lib/Basic/Targets/M68k.h
===
--- /dev/null
+++ clang/lib/Basic/Targets/M68k.h
@@ -0,0 +1,57 @@
+//===--- M68k.h - Declare M68k target feature support ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file declares M68k TargetInfo objects.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_LIB_BASI

[PATCH] D88393: [cfe][M68k] (Patch 7/8) Basic Clang support

2021-02-25 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu marked an inline comment as done.
myhsu added inline comments.



Comment at: clang/lib/Basic/Targets/M68k.cpp:142
+const char *&Name, TargetInfo::ConstraintInfo &info) const {
+  // FIXME: implement
+  switch (*Name) {

jrtc27 wrote:
> This is implemented?
only part of the constraints are implements for now. I edit the FIXME comment 
and move to the end of switch statement


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

https://reviews.llvm.org/D88393

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


[PATCH] D88394: [Driver][M68k] (Patch 8/8) Add driver support for M68k

2021-02-25 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu updated this revision to Diff 326506.
myhsu marked 3 inline comments as done.
myhsu added a comment.

- Addressed feedbacks


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

https://reviews.llvm.org/D88394

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/CMakeLists.txt
  clang/lib/Driver/ToolChains/Arch/M68k.cpp
  clang/lib/Driver/ToolChains/Arch/M68k.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/lib/Driver/ToolChains/Linux.cpp
  clang/test/Driver/m68k-features.cpp
  clang/test/Driver/m68k-sub-archs.cpp

Index: clang/test/Driver/m68k-sub-archs.cpp
===
--- /dev/null
+++ clang/test/Driver/m68k-sub-archs.cpp
@@ -0,0 +1,35 @@
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=68000 %s 2>&1 | FileCheck %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=m68000 %s 2>&1 | FileCheck %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=M68000 %s 2>&1 | FileCheck %s
+// RUN: %clang -### -target m68k-unknown-linux -m68000 %s 2>&1 | FileCheck %s
+// CHECK: "-target-cpu" "M68000"
+
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=68010 %s 2>&1 | FileCheck --check-prefix=CHECK-MX10 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=m68010 %s 2>&1 | FileCheck --check-prefix=CHECK-MX10 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=M68010 %s 2>&1 | FileCheck --check-prefix=CHECK-MX10 %s
+// RUN: %clang -### -target m68k-unknown-linux -m68010 %s 2>&1 | FileCheck --check-prefix=CHECK-MX10 %s
+// CHECK-MX10: "-target-cpu" "M68010"
+
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=68020 %s 2>&1 | FileCheck --check-prefix=CHECK-MX20 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=m68020 %s 2>&1 | FileCheck --check-prefix=CHECK-MX20 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=M68020 %s 2>&1 | FileCheck --check-prefix=CHECK-MX20 %s
+// RUN: %clang -### -target m68k-unknown-linux -m68020 %s 2>&1 | FileCheck --check-prefix=CHECK-MX20 %s
+// CHECK-MX20: "-target-cpu" "M68020"
+
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=68030 %s 2>&1 | FileCheck --check-prefix=CHECK-MX30 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=m68030 %s 2>&1 | FileCheck --check-prefix=CHECK-MX30 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=M68030 %s 2>&1 | FileCheck --check-prefix=CHECK-MX30 %s
+// RUN: %clang -### -target m68k-unknown-linux -m68030 %s 2>&1 | FileCheck --check-prefix=CHECK-MX30 %s
+// CHECK-MX30: "-target-cpu" "M68030"
+
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=68040 %s 2>&1 | FileCheck --check-prefix=CHECK-MX40 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=m68040 %s 2>&1 | FileCheck --check-prefix=CHECK-MX40 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=M68040 %s 2>&1 | FileCheck --check-prefix=CHECK-MX40 %s
+// RUN: %clang -### -target m68k-unknown-linux -m68040 %s 2>&1 | FileCheck --check-prefix=CHECK-MX40 %s
+// CHECK-MX40: "-target-cpu" "M68040"
+
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=68060 %s 2>&1 | FileCheck --check-prefix=CHECK-MX60 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=m68060 %s 2>&1 | FileCheck --check-prefix=CHECK-MX60 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=M68060 %s 2>&1 | FileCheck --check-prefix=CHECK-MX60 %s
+// RUN: %clang -### -target m68k-unknown-linux -m68060 %s 2>&1 | FileCheck --check-prefix=CHECK-MX60 %s
+// CHECK-MX60: "-target-cpu" "M68060"
Index: clang/test/Driver/m68k-features.cpp
===
--- /dev/null
+++ clang/test/Driver/m68k-features.cpp
@@ -0,0 +1,45 @@
+// Check macro definitions
+// RUN: %clang -target m68k-unknown-linux -m68000 -dM -E %s | FileCheck --check-prefix=CHECK-MX %s
+// CHECK-MX: #define __mc68000 1
+// CHECK-MX: #define __mc68000__ 1
+// CHECK-MX: #define mc68000 1
+
+// RUN: %clang -target m68k-unknown-linux -m68010 -dM -E %s | FileCheck --check-prefix=CHECK-MX10 %s
+// CHECK-MX10: #define __mc68000 1
+// CHECK-MX10: #define __mc68000__ 1
+// CHECK-MX10: #define __mc68010 1
+// CHECK-MX10: #define __mc68010__ 1
+// CHECK-MX10: #define mc68000 1
+// CHECK-MX10: #define mc68010 1
+
+// RUN: %clang -target m68k-unknown-linux -m68020 -dM -E %s | FileCheck --check-prefix=CHECK-MX20 %s
+// CHECK-MX20: #define __mc68000 1
+// CHECK-MX20: #define __mc68000__ 1
+// CHECK-MX20: #define __mc68020 1
+// CHECK-MX20: #define __mc68020__ 1
+// CHECK-MX20: #define mc68000 1
+// CHECK-MX20: #define mc68020 1
+
+// RUN: %clang -target m68k-unknown-linux -m68030 -dM -E %s | FileCheck --check-prefix=CHECK-MX30 %s
+// CHECK-MX30: #define __mc68000 1
+// CHECK-MX30: #define __mc68000__ 1
+// CHECK-MX30: #define __mc68030 1
+// CHECK-MX30: #define __mc68030__ 1
+// CHECK-MX30: #define mc68000 1
+// CHECK-MX30: #define mc68030 1
+
+// RUN: %clang -target m68k-unknown-linux -m68040 -dM -E %s | 

[PATCH] D88394: [Driver][M68k] (Patch 8/8) Add driver support for M68k

2021-02-25 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu marked an inline comment as done.
myhsu added inline comments.



Comment at: clang/lib/Driver/ToolChains/Clang.cpp:380
 ve::getVETargetFeatures(D, Args, Features);
+break;
   }

jrtc27 wrote:
> jrtc27 wrote:
> > Unrelated
> I committed this as 22215e492338, should disappear if you rebase (or you can 
> just drop the diff if you don't plan to rebase)
thanks, I'll drop the change for this line


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

https://reviews.llvm.org/D88394

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


[PATCH] D88394: [Driver][M68k] (Patch 8/8) Add driver support for M68k

2021-02-28 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu updated this revision to Diff 327029.
myhsu marked 4 inline comments as done.
myhsu added a comment.

[NFC] Update FileCheck prefix


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

https://reviews.llvm.org/D88394

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/CMakeLists.txt
  clang/lib/Driver/ToolChains/Arch/M68k.cpp
  clang/lib/Driver/ToolChains/Arch/M68k.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/lib/Driver/ToolChains/Linux.cpp
  clang/test/Driver/m68k-features.cpp
  clang/test/Driver/m68k-sub-archs.cpp

Index: clang/test/Driver/m68k-sub-archs.cpp
===
--- /dev/null
+++ clang/test/Driver/m68k-sub-archs.cpp
@@ -0,0 +1,35 @@
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=68000 %s 2>&1 | FileCheck --check-prefix=CHECK-M00 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=m68000 %s 2>&1 | FileCheck --check-prefix=CHECK-M00 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=M68000 %s 2>&1 | FileCheck --check-prefix=CHECK-M00 %s
+// RUN: %clang -### -target m68k-unknown-linux -m68000 %s 2>&1 | FileCheck --check-prefix=CHECK-M00 %s
+// CHECK-M00: "-target-cpu" "M68000"
+
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=68010 %s 2>&1 | FileCheck --check-prefix=CHECK-M10 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=m68010 %s 2>&1 | FileCheck --check-prefix=CHECK-M10 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=M68010 %s 2>&1 | FileCheck --check-prefix=CHECK-M10 %s
+// RUN: %clang -### -target m68k-unknown-linux -m68010 %s 2>&1 | FileCheck --check-prefix=CHECK-M10 %s
+// CHECK-M10: "-target-cpu" "M68010"
+
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=68020 %s 2>&1 | FileCheck --check-prefix=CHECK-M20 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=m68020 %s 2>&1 | FileCheck --check-prefix=CHECK-M20 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=M68020 %s 2>&1 | FileCheck --check-prefix=CHECK-M20 %s
+// RUN: %clang -### -target m68k-unknown-linux -m68020 %s 2>&1 | FileCheck --check-prefix=CHECK-M20 %s
+// CHECK-M20: "-target-cpu" "M68020"
+
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=68030 %s 2>&1 | FileCheck --check-prefix=CHECK-M30 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=m68030 %s 2>&1 | FileCheck --check-prefix=CHECK-M30 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=M68030 %s 2>&1 | FileCheck --check-prefix=CHECK-M30 %s
+// RUN: %clang -### -target m68k-unknown-linux -m68030 %s 2>&1 | FileCheck --check-prefix=CHECK-M30 %s
+// CHECK-M30: "-target-cpu" "M68030"
+
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=68040 %s 2>&1 | FileCheck --check-prefix=CHECK-M40 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=m68040 %s 2>&1 | FileCheck --check-prefix=CHECK-M40 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=M68040 %s 2>&1 | FileCheck --check-prefix=CHECK-M40 %s
+// RUN: %clang -### -target m68k-unknown-linux -m68040 %s 2>&1 | FileCheck --check-prefix=CHECK-M40 %s
+// CHECK-M40: "-target-cpu" "M68040"
+
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=68060 %s 2>&1 | FileCheck --check-prefix=CHECK-M60 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=m68060 %s 2>&1 | FileCheck --check-prefix=CHECK-M60 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=M68060 %s 2>&1 | FileCheck --check-prefix=CHECK-M60 %s
+// RUN: %clang -### -target m68k-unknown-linux -m68060 %s 2>&1 | FileCheck --check-prefix=CHECK-M60 %s
+// CHECK-M60: "-target-cpu" "M68060"
Index: clang/test/Driver/m68k-features.cpp
===
--- /dev/null
+++ clang/test/Driver/m68k-features.cpp
@@ -0,0 +1,45 @@
+// Check macro definitions
+// RUN: %clang -target m68k-unknown-linux -m68000 -dM -E %s | FileCheck --check-prefix=CHECK-MX %s
+// CHECK-MX: #define __mc68000 1
+// CHECK-MX: #define __mc68000__ 1
+// CHECK-MX: #define mc68000 1
+
+// RUN: %clang -target m68k-unknown-linux -m68010 -dM -E %s | FileCheck --check-prefix=CHECK-MX10 %s
+// CHECK-MX10: #define __mc68000 1
+// CHECK-MX10: #define __mc68000__ 1
+// CHECK-MX10: #define __mc68010 1
+// CHECK-MX10: #define __mc68010__ 1
+// CHECK-MX10: #define mc68000 1
+// CHECK-MX10: #define mc68010 1
+
+// RUN: %clang -target m68k-unknown-linux -m68020 -dM -E %s | FileCheck --check-prefix=CHECK-MX20 %s
+// CHECK-MX20: #define __mc68000 1
+// CHECK-MX20: #define __mc68000__ 1
+// CHECK-MX20: #define __mc68020 1
+// CHECK-MX20: #define __mc68020__ 1
+// CHECK-MX20: #define mc68000 1
+// CHECK-MX20: #define mc68020 1
+
+// RUN: %clang -target m68k-unknown-linux -m68030 -dM -E %s | FileCheck --check-prefix=CHECK-MX30 %s
+// CHECK-MX30: #define __mc68000 1
+// CHECK-MX30: #define __mc68000__ 1
+// CHECK-MX30: #define __mc68030 1
+// CHECK-MX30: #define __mc68030__ 1
+// CHECK-MX30: #define mc68000 1
+// CHECK-MX

[PATCH] D88393: [cfe][M68k] (Patch 7/8) Basic Clang support

2021-03-08 Thread Min-Yih Hsu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5eb7a5814a5c: [cfe][M68k](7/8) Clang basic support (authored 
by myhsu).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88393

Files:
  clang/include/clang/Basic/Attr.td
  clang/lib/Basic/CMakeLists.txt
  clang/lib/Basic/Targets.cpp
  clang/lib/Basic/Targets/M68k.cpp
  clang/lib/Basic/Targets/M68k.h
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/Sema/SemaDeclAttr.cpp

Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -6641,6 +6641,39 @@
   D->addAttr(::new (S.Context) MipsInterruptAttr(S.Context, AL, Kind));
 }
 
+static void handleM68kInterruptAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
+  if (!checkAttributeNumArgs(S, AL, 1))
+return;
+
+  if (!AL.isArgExpr(0)) {
+S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
+<< AL << AANT_ArgumentIntegerConstant;
+return;
+  }
+
+  // FIXME: Check for decl - it should be void ()(void).
+
+  Expr *NumParamsExpr = static_cast(AL.getArgAsExpr(0));
+  auto MaybeNumParams = NumParamsExpr->getIntegerConstantExpr(S.Context);
+  if (!MaybeNumParams) {
+S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
+<< AL << AANT_ArgumentIntegerConstant
+<< NumParamsExpr->getSourceRange();
+return;
+  }
+
+  unsigned Num = MaybeNumParams->getLimitedValue(255);
+  if ((Num & 1) || Num > 30) {
+S.Diag(AL.getLoc(), diag::err_attribute_argument_out_of_bounds)
+<< AL << (int)MaybeNumParams->getSExtValue()
+<< NumParamsExpr->getSourceRange();
+return;
+  }
+
+  D->addAttr(::new (S.Context) M68kInterruptAttr(S.Context, AL, Num));
+  D->addAttr(UsedAttr::CreateImplicit(S.Context));
+}
+
 static void handleAnyX86InterruptAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
   // Semantic checks for a function with the 'interrupt' attribute.
   // a) Must be a function.
@@ -6913,6 +6946,9 @@
   case llvm::Triple::mips:
 handleMipsInterruptAttr(S, D, AL);
 break;
+  case llvm::Triple::m68k:
+handleM68kInterruptAttr(S, D, AL);
+break;
   case llvm::Triple::x86:
   case llvm::Triple::x86_64:
 handleAnyX86InterruptAttr(S, D, AL);
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -8049,6 +8049,43 @@
   return false;
 }
 
+//===--===//
+// M68k ABI Implementation
+//===--===//
+
+namespace {
+
+class M68kTargetCodeGenInfo : public TargetCodeGenInfo {
+public:
+  M68kTargetCodeGenInfo(CodeGenTypes &CGT)
+  : TargetCodeGenInfo(std::make_unique(CGT)) {}
+  void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
+   CodeGen::CodeGenModule &M) const override;
+};
+
+} // namespace
+
+void M68kTargetCodeGenInfo::setTargetAttributes(
+const Decl *D, llvm::GlobalValue *GV, CodeGen::CodeGenModule &M) const {
+  if (const auto *FD = dyn_cast_or_null(D)) {
+if (const auto *attr = FD->getAttr()) {
+  // Handle 'interrupt' attribute:
+  llvm::Function *F = cast(GV);
+
+  // Step 1: Set ISR calling convention.
+  F->setCallingConv(llvm::CallingConv::M68k_INTR);
+
+  // Step 2: Add attributes goodness.
+  F->addFnAttr(llvm::Attribute::NoInline);
+
+  // Step 3: Emit ISR vector alias.
+  unsigned Num = attr->getNumber() / 2;
+  llvm::GlobalAlias::create(llvm::Function::ExternalLinkage,
+"__isr_" + Twine(Num), F);
+}
+  }
+}
+
 //===--===//
 // AVR ABI Implementation.
 //===--===//
@@ -10876,6 +10913,8 @@
 
   case llvm::Triple::le32:
 return SetCGInfo(new PNaClTargetCodeGenInfo(Types));
+  case llvm::Triple::m68k:
+return SetCGInfo(new M68kTargetCodeGenInfo(Types));
   case llvm::Triple::mips:
   case llvm::Triple::mipsel:
 if (Triple.getOS() == llvm::Triple::NaCl)
Index: clang/lib/Basic/Targets/M68k.h
===
--- /dev/null
+++ clang/lib/Basic/Targets/M68k.h
@@ -0,0 +1,57 @@
+//===--- M68k.h - Declare M68k target feature support ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file declares M68k TargetInfo o

[PATCH] D88394: [Driver][M68k] (Patch 8/8) Add driver support for M68k

2021-03-08 Thread Min-Yih Hsu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5509748f2ce5: [cfe][driver][M68k](8/8) Clang driver support 
(authored by myhsu).

Changed prior to commit:
  https://reviews.llvm.org/D88394?vs=327029&id=329111#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88394

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/CMakeLists.txt
  clang/lib/Driver/ToolChains/Arch/M68k.cpp
  clang/lib/Driver/ToolChains/Arch/M68k.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/lib/Driver/ToolChains/Linux.cpp
  clang/test/Driver/m68k-features.cpp
  clang/test/Driver/m68k-sub-archs.cpp

Index: clang/test/Driver/m68k-sub-archs.cpp
===
--- /dev/null
+++ clang/test/Driver/m68k-sub-archs.cpp
@@ -0,0 +1,35 @@
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=68000 %s 2>&1 | FileCheck --check-prefix=CHECK-M00 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=m68000 %s 2>&1 | FileCheck --check-prefix=CHECK-M00 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=M68000 %s 2>&1 | FileCheck --check-prefix=CHECK-M00 %s
+// RUN: %clang -### -target m68k-unknown-linux -m68000 %s 2>&1 | FileCheck --check-prefix=CHECK-M00 %s
+// CHECK-M00: "-target-cpu" "M68000"
+
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=68010 %s 2>&1 | FileCheck --check-prefix=CHECK-M10 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=m68010 %s 2>&1 | FileCheck --check-prefix=CHECK-M10 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=M68010 %s 2>&1 | FileCheck --check-prefix=CHECK-M10 %s
+// RUN: %clang -### -target m68k-unknown-linux -m68010 %s 2>&1 | FileCheck --check-prefix=CHECK-M10 %s
+// CHECK-M10: "-target-cpu" "M68010"
+
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=68020 %s 2>&1 | FileCheck --check-prefix=CHECK-M20 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=m68020 %s 2>&1 | FileCheck --check-prefix=CHECK-M20 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=M68020 %s 2>&1 | FileCheck --check-prefix=CHECK-M20 %s
+// RUN: %clang -### -target m68k-unknown-linux -m68020 %s 2>&1 | FileCheck --check-prefix=CHECK-M20 %s
+// CHECK-M20: "-target-cpu" "M68020"
+
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=68030 %s 2>&1 | FileCheck --check-prefix=CHECK-M30 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=m68030 %s 2>&1 | FileCheck --check-prefix=CHECK-M30 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=M68030 %s 2>&1 | FileCheck --check-prefix=CHECK-M30 %s
+// RUN: %clang -### -target m68k-unknown-linux -m68030 %s 2>&1 | FileCheck --check-prefix=CHECK-M30 %s
+// CHECK-M30: "-target-cpu" "M68030"
+
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=68040 %s 2>&1 | FileCheck --check-prefix=CHECK-M40 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=m68040 %s 2>&1 | FileCheck --check-prefix=CHECK-M40 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=M68040 %s 2>&1 | FileCheck --check-prefix=CHECK-M40 %s
+// RUN: %clang -### -target m68k-unknown-linux -m68040 %s 2>&1 | FileCheck --check-prefix=CHECK-M40 %s
+// CHECK-M40: "-target-cpu" "M68040"
+
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=68060 %s 2>&1 | FileCheck --check-prefix=CHECK-M60 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=m68060 %s 2>&1 | FileCheck --check-prefix=CHECK-M60 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=M68060 %s 2>&1 | FileCheck --check-prefix=CHECK-M60 %s
+// RUN: %clang -### -target m68k-unknown-linux -m68060 %s 2>&1 | FileCheck --check-prefix=CHECK-M60 %s
+// CHECK-M60: "-target-cpu" "M68060"
Index: clang/test/Driver/m68k-features.cpp
===
--- /dev/null
+++ clang/test/Driver/m68k-features.cpp
@@ -0,0 +1,45 @@
+// Check macro definitions
+// RUN: %clang -target m68k-unknown-linux -m68000 -dM -E %s | FileCheck --check-prefix=CHECK-MX %s
+// CHECK-MX: #define __mc68000 1
+// CHECK-MX: #define __mc68000__ 1
+// CHECK-MX: #define mc68000 1
+
+// RUN: %clang -target m68k-unknown-linux -m68010 -dM -E %s | FileCheck --check-prefix=CHECK-MX10 %s
+// CHECK-MX10: #define __mc68000 1
+// CHECK-MX10: #define __mc68000__ 1
+// CHECK-MX10: #define __mc68010 1
+// CHECK-MX10: #define __mc68010__ 1
+// CHECK-MX10: #define mc68000 1
+// CHECK-MX10: #define mc68010 1
+
+// RUN: %clang -target m68k-unknown-linux -m68020 -dM -E %s | FileCheck --check-prefix=CHECK-MX20 %s
+// CHECK-MX20: #define __mc68000 1
+// CHECK-MX20: #define __mc68000__ 1
+// CHECK-MX20: #define __mc68020 1
+// CHECK-MX20: #define __mc68020__ 1
+// CHECK-MX20: #define mc68000 1
+// CHECK-MX20: #define mc68020 1
+
+// RUN: %clang -target m68k-unknown-linux -m68030 -dM -E %s | FileCheck --check-

[PATCH] D135488: [codegen] Display stack layouts in console

2022-10-26 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu added a comment.

Just some drive-by comments




Comment at: llvm/lib/CodeGen/StackFramePrinterPass.cpp:79
+
+  void printBody(raw_ostream &OS, SlotData &D) const {
+OS << formatv("{0,-11} {1,-5} {2,-9} {3,-10}\n", genStackOffset(D.Offset),

const SlotData &? If this is true please also update the call site (e.g. line 
143)



Comment at: llvm/lib/CodeGen/StackFramePrinterPass.cpp:82
+  D.IsSpillSlot ? "Spill" : "", D.Align, D.Size)
+  .str();
+  };

IIRC there is no need to materialize to std::string, formatv works out-of-box 
with raw_ostream



Comment at: llvm/lib/CodeGen/StackFramePrinterPass.cpp:123
+  // This is a dead slot, so skip it
+  if (Size == ~0ULL) {
+continue;

format: remove curly braces for single-line body



Comment at: llvm/lib/CodeGen/StackFramePrinterPass.cpp:138
+// sort the ordering, to match the actual layout in memory
+std::sort(SlotInfo.begin(), SlotInfo.end(),
+  [](SlotData &A, SlotData &B) { return A.Offset > B.Offset; });

nit: use llvm::sort so that we can simply write `llvm::sort(SlotInfo, 
)`



Comment at: llvm/lib/CodeGen/StackFramePrinterPass.cpp:139
+std::sort(SlotInfo.begin(), SlotInfo.end(),
+  [](SlotData &A, SlotData &B) { return A.Offset > B.Offset; });
+

nit: using `const SlotData &` for both A and B



Comment at: llvm/lib/CodeGen/StackFramePrinterPass.cpp:145
+  printBody(OS, L);
+  for (const llvm::DILocalVariable *N : SlotMap[L.Slot])
+printSourceLoc(OS, N);

remove llvm



Comment at: llvm/lib/CodeGen/StackFramePrinterPass.cpp:159
+// add variables to the map
+for (MachineFunction::VariableDbgInfo &DI : MF.getVariableDbgInfo()) {
+  SlotDebugMap[DI.Slot].insert(DI.Var);

format: remove curly braces for single-line loop body



Comment at: llvm/lib/CodeGen/StackFramePrinterPass.cpp:179
+
+  for (llvm::MachineInstr *MI : Dbg)
+SlotDebugMap[FrameIdx].insert(MI->getDebugVariable());

remove llvm



Comment at: llvm/test/CodeGen/ARM/stack-frame-printer.ll:221
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: 
"Fuchsia clang version 16.0.0 (g...@github.com:llvm/llvm-project.git 
bb51a99e67747be81c9b523fd5ddcc8bf91a1ffb)", isOptimized: true, runtimeVersion: 
0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
+!1 = !DIFile(filename: "frame-diags.c", directory: 
"/usr/local/google/home/paulkirth/llvm-sysroot/clang/test/Frontend", 
checksumkind: CSK_MD5, checksum: "01b5d69ce5387b02de2d1191b28a0b7f")

nit: is it possible to clean up some of the irrelevant strings like the 
producer and directory fields?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135488

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


[PATCH] D140695: [M68k] Define __GCC_HAVE_SYNC_COMPARE_AND_SWAP macros

2022-12-27 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu accepted this revision.
myhsu added a comment.
This revision is now accepted and ready to land.

LGTM Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140695

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


[PATCH] D140695: [M68k] Define __GCC_HAVE_SYNC_COMPARE_AND_SWAP macros

2022-12-28 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu requested changes to this revision.
myhsu added a comment.
This revision now requires changes to proceed.

In D140695#4018127 , @0x59616e wrote:

> FYI the pre-merge checks seem to have some issues. Here is the output:
>
>   Command Output (stderr):
>   --
>   
> /var/lib/buildkite-agent/builds/llvm-project/clang/test/Preprocessor/predefined-arch-macros.c:4322:28:
>  error: CHECK_M68K_GCC_ATOMICS: expected string not found in input
>   // CHECK_M68K_GCC_ATOMICS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1
>  ^
>   :1:1: note: scanning from here
>   #define _ILP32 1
>   ^
>   :62:1: note: possible intended match here
>   #define __GCC_ATOMIC_CHAR_LOCK_FREE 1
>   ^
>
>   Input file: 
>   Check file: 
> /var/lib/buildkite-agent/builds/llvm-project/clang/test/Preprocessor/predefined-arch-macros.c
>
>   -dump-input=help explains the following input dump.
>
>   Input was:
>   <<
> 1: #define _ILP32 1
>   check:4322'0 X error: no match found
> 2: #define __ATOMIC_ACQUIRE 2
>   check:4322'0 ~~~
> 3: #define __ATOMIC_ACQ_REL 4
>   check:4322'0 ~~~
> 4: #define __ATOMIC_CONSUME 1
>   check:4322'0 ~~~
> 5: #define __ATOMIC_RELAXED 0
>   check:4322'0 ~~~
> 6: #define __ATOMIC_RELEASE 3
>   check:4322'0 ~~~
> .
> .
> .
>57: #define __FLT_MIN__ 1.17549435e-38F
>   check:4322'0 
>58: #define __FLT_RADIX__ 2
>   check:4322'0 
>59: #define __GCC_ATOMIC_BOOL_LOCK_FREE 1
>   check:4322'0 ~~
>60: #define __GCC_ATOMIC_CHAR16_T_LOCK_FREE 1
>   check:4322'0 ~~
>61: #define __GCC_ATOMIC_CHAR32_T_LOCK_FREE 1
>   check:4322'0 ~~
>62: #define __GCC_ATOMIC_CHAR_LOCK_FREE 1
>   check:4322'0 ~~
>   check:4322'1 ?  possible intended 
> match
>63: #define __GCC_ATOMIC_INT_LOCK_FREE 1
>   check:4322'0 ~
>64: #define __GCC_ATOMIC_LLONG_LOCK_FREE 1
>   check:4322'0 ~~~
>65: #define __GCC_ATOMIC_LONG_LOCK_FREE 1
>   check:4322'0 ~~
>66: #define __GCC_ATOMIC_POINTER_LOCK_FREE 1
>   check:4322'0 ~
>67: #define __GCC_ATOMIC_SHORT_LOCK_FREE 1
>   check:4322'0 ~~~
> .
> .
> .
>   >>
>
>   --

This is probably caused by the fact that you didn't use CPU later than 68020. 
Please update your test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140695

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


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

2023-08-19 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu updated this revision to Diff 551797.
myhsu marked 4 inline comments as done.
myhsu added a comment.

- Add more C++ tests for `m68k_rtd`, both Sema and CodeGen ones
- Addressed other comments


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

https://reviews.llvm.org/D149867

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang-c/Index.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/LangOptions.h
  clang/include/clang/Basic/Specifiers.h
  clang/include/clang/Driver/Options.td
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/Type.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Basic/Targets/M68k.cpp
  clang/lib/Basic/Targets/M68k.h
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CodeGen/mrtd.c
  clang/test/CodeGenCXX/default_calling_conv.cpp
  clang/test/CodeGenCXX/m68k-rtdcall.cpp
  clang/test/Sema/m68k-rtdcall.c
  clang/test/SemaCXX/m68k-rtdcall.cpp
  clang/tools/libclang/CXType.cpp

Index: clang/tools/libclang/CXType.cpp
===
--- clang/tools/libclang/CXType.cpp
+++ clang/tools/libclang/CXType.cpp
@@ -678,6 +678,7 @@
   TCALLINGCONV(SwiftAsync);
   TCALLINGCONV(PreserveMost);
   TCALLINGCONV(PreserveAll);
+  TCALLINGCONV(M68kRTD);
 case CC_SpirFunction: return CXCallingConv_Unexposed;
 case CC_AMDGPUKernelCall: return CXCallingConv_Unexposed;
 case CC_OpenCLKernel: return CXCallingConv_Unexposed;
Index: clang/test/SemaCXX/m68k-rtdcall.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/m68k-rtdcall.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -triple m68k-linux-gnu -fsyntax-only %s
+
+class A {
+public:
+  void __attribute__((m68k_rtd)) member() {}
+};
+
+void test() {
+  A a;
+  a.member();
+
+  auto f = [](int b) __attribute__((m68k_rtd)) {};
+  f(87);
+};
Index: clang/test/Sema/m68k-rtdcall.c
===
--- /dev/null
+++ clang/test/Sema/m68k-rtdcall.c
@@ -0,0 +1,46 @@
+// RUN: %clang_cc1 -triple m68k-unknown-unknown -mrtd -std=c89 -verify -verify=rtd %s
+// RUN: %clang_cc1 -triple m68k-unknown-unknown -std=c89 -verify -verify=nortd %s
+
+// rtd-error@+2 {{function with no prototype cannot use the m68k_rtd calling convention}}
+void foo(int arg) {
+  bar(arg);
+}
+
+// nortd-note@+4 {{previous declaration is here}}
+// nortd-error@+4 {{function declared 'm68k_rtd' here was previously declared without calling convention}}
+// nortd-note@+4 {{previous declaration is here}}
+// nortd-error@+4 {{function declared 'm68k_rtd' here was previously declared without calling convention}}
+void nonvariadic1(int a, int b, int c);
+void __attribute__((m68k_rtd)) nonvariadic1(int a, int b, int c);
+void nonvariadic2(int a, int b, int c);
+void __attribute__((m68k_rtd)) nonvariadic2(int a, int b, int c) { }
+
+// expected-error@+2 {{variadic function cannot use m68k_rtd calling convention}}
+void variadic(int a, ...);
+void __attribute__((m68k_rtd)) variadic(int a, ...);
+
+// rtd-note@+2 {{previous declaration is here}}
+// rtd-error@+2 {{redeclaration of 'a' with a different type: 'void ((*))(int, int) __attribute__((cdecl))' vs 'void (*)(int, int) __attribute__((m68k_rtd))'}}
+extern void (*a)(int, int);
+__attribute__((cdecl)) extern void (*a)(int, int);
+
+extern void (*b)(int, ...);
+__attribute__((cdecl)) extern void (*b)(int, ...);
+
+// nortd-note@+2 {{previous declaration is here}}
+// nortd-error@+2 {{redeclaration of 'c' with a different type: 'void ((*))(int, int) __attribute__((m68k_rtd))' vs 'void (*)(int, int)'}}
+extern void (*c)(int, int);
+__attribute__((m68k_rtd)) extern void (*c)(int, int);
+
+// expected-error@+2 {{variadic function cannot use m68k_rtd calling convention}}
+extern void (*d)(int, ...);
+__attribute__((m68k_rtd)) extern void (*d)(int, ...);
+
+// expected-warning@+1 {{'m68k_rtd' only applies to function types; type here is 'int'}}
+__attribute__((m68k_rtd)) static int g = 0;
+
+// expected-error@+1 {{'m68k_rtd' attribute takes no arguments}}
+void __attribute__((m68k_rtd("invalid"))) z(int a);
+
+// expected-error@+1 {{function with no prototype cannot use the m68k_rtd calling convention}}
+void __attribute__((m68k_rtd)) e();
Index: clang/test/CodeGenCXX/m68k-rtdcall.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/m68k-rtdcall.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -triple m68k-linux-gnu -emit-llvm -o - %s | FileCheck %s
+
+class A {
+public:
+// CHECK: define{{.*}} m68k_rtdcc void @_ZN1A6memberEv
+  void __attribute__((m68k_rtd)) member() {}
+};
+
+void test() {
+  A a;
+  a.member();
+
+// CHECK: define{{.*}} m68k_rtdcc voi

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

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



Comment at: clang/test/Sema/m68k-mrtd.c:4-9
+#ifdef MRTD
+// expected-error@+3 {{function with no prototype cannot use the m68k_rtd 
calling convention}}
+#endif
+void foo(int arg) {
+  bar(arg);
+}

aaron.ballman wrote:
> myhsu wrote:
> > aaron.ballman wrote:
> > > A better way to do this is to use `-verify=mrtd` on the line enabling 
> > > rtd, and using `// rtd-error {{whatever}}` on the line being diagnosed. 
> > > (Same comment applies throughout the file.)
> > > 
> > > Huh, I was unaware that implicit function declarations are using 
> > > something other than the default calling convention (which is C, not 
> > > m68k_rtd). Is this intentional?
> > > Huh, I was unaware that implicit function declarations are using 
> > > something other than the default calling convention (which is C, not 
> > > m68k_rtd). Is this intentional?
> > 
> > I'm not sure if I understand you correctly, but this diagnostic is emitted 
> > if the CC does not support variadic function call. 
> `bar` is not declared, in C89 this causes an implicit function declaration to 
> be generated with the signature: `extern int ident();` What surprised me is 
> that we seem to be generating something more like this instead: 
> `__attribute__((m68k_rtd)) int ident();` despite that not being valid.
I understand what you meant, but the standard only says that using implicit 
declared identifier is as if `extern int ident();` appears in the source code. 
My interpretation is that in this case since the very source code is compiled 
with `-mrtd`, every functions use m68k_rtd rather than C calling convention. 

Another example is stdcall: i386 Clang emits a similar warning ("function with 
no prototype cannot use the stdcall calling convention") when `-mrtd` is used 
(to set default CC to stdcall) on the same snippet. Should `bar` was not called 
with stdcall under the influence of `-mrtd`, the aforementioned message would 
not be emitted in the first place.
i386 GCC also calls `bar` with stdcall when `-mrtd` is given (though no warning 
message is emitted).



Comment at: clang/test/Sema/m68k-mrtd.c:45
+extern void (*d)(int, ...);
+__attribute__((m68k_rtd)) extern void (*d)(int, ...);

aaron.ballman wrote:
> myhsu wrote:
> > aaron.ballman wrote:
> > > Missing tests for:
> > > 
> > > * Function without a prototype
> > > * Applying the attribute to a non-function
> > > * Providing arguments to the attribute
> > > * What should happen for C++ and things like member functions?
> > > Function without a prototype
> > 
> > I thought the first check was testing function without a prototype.
> > 
> > > What should happen for C++ and things like member functions?
> > 
> > I believe we don't have any special handling for C++.
> > 
> > I addressed rest of the bullet items you mentioned, please take a look.
> >> Function without a prototype
> > I thought the first check was testing function without a prototype.
> 
> Nope, I meant something more like this:
> ```
> __attribute__((m68k_rtd)) void foo(); // Should error
> __attribute__((m68k_rtd)) void bar(a, b) int a, b; {} // Should error
> ```
> 
> >> What should happen for C++ and things like member functions?
> > I believe we don't have any special handling for C++.
> 
> Test coverage should still exist to ensure the behavior is what you'd expect 
> when adding the calling convention to a member function and a lambda, for 
> example. (Both Sema and CodeGen tests for this)
> 
> Also missing coverage for the changes to `-fdefault-calling-conv=`
> 
> I'm also still wondering whether there's a way to use m68k with a Windows ABI 
> triple (basically, do we need changes in MicrosoftMangle.cpp?)

> ```
> __attribute__((m68k_rtd)) void bar(a, b) int a, b; {} // Should error
> ```

Right now Clang only gives a warning about potential behavior change after C23, 
rather than an error for this kind of syntax. Because it seems like Clang 
doesn't check this situation against unsupported calling convention. I'm not 
sure if we should throw the same error as `__attribute__((m68k_rtd)) void 
foo()`.

> I'm also still wondering whether there's a way to use m68k with a Windows ABI 
> triple (basically, do we need changes in MicrosoftMangle.cpp?)

I don't think it's worth it to support m68k with Windows ABI as this 
combination never existed (and unlikely to happen in the future)


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: [Clang][M68k] Add Clang support for the new M68k_RTD CC

2023-08-22 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu updated this revision to Diff 552596.
myhsu marked 2 inline comments as done.
myhsu added a comment.

Addressed comments in `test/CodeGen/mrtd.c`


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

https://reviews.llvm.org/D149867

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang-c/Index.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/LangOptions.h
  clang/include/clang/Basic/Specifiers.h
  clang/include/clang/Driver/Options.td
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/Type.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Basic/Targets/M68k.cpp
  clang/lib/Basic/Targets/M68k.h
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CodeGen/mrtd.c
  clang/test/CodeGenCXX/default_calling_conv.cpp
  clang/test/CodeGenCXX/m68k-rtdcall.cpp
  clang/test/Sema/m68k-rtdcall.c
  clang/test/SemaCXX/m68k-rtdcall.cpp
  clang/tools/libclang/CXType.cpp

Index: clang/tools/libclang/CXType.cpp
===
--- clang/tools/libclang/CXType.cpp
+++ clang/tools/libclang/CXType.cpp
@@ -678,6 +678,7 @@
   TCALLINGCONV(SwiftAsync);
   TCALLINGCONV(PreserveMost);
   TCALLINGCONV(PreserveAll);
+  TCALLINGCONV(M68kRTD);
 case CC_SpirFunction: return CXCallingConv_Unexposed;
 case CC_AMDGPUKernelCall: return CXCallingConv_Unexposed;
 case CC_OpenCLKernel: return CXCallingConv_Unexposed;
Index: clang/test/SemaCXX/m68k-rtdcall.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/m68k-rtdcall.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -triple m68k-linux-gnu -fsyntax-only %s
+
+class A {
+public:
+  void __attribute__((m68k_rtd)) member() {}
+};
+
+void test() {
+  A a;
+  a.member();
+
+  auto f = [](int b) __attribute__((m68k_rtd)) {};
+  f(87);
+};
Index: clang/test/Sema/m68k-rtdcall.c
===
--- /dev/null
+++ clang/test/Sema/m68k-rtdcall.c
@@ -0,0 +1,46 @@
+// RUN: %clang_cc1 -triple m68k-unknown-unknown -mrtd -std=c89 -verify -verify=rtd %s
+// RUN: %clang_cc1 -triple m68k-unknown-unknown -std=c89 -verify -verify=nortd %s
+
+// rtd-error@+2 {{function with no prototype cannot use the m68k_rtd calling convention}}
+void foo(int arg) {
+  bar(arg);
+}
+
+// nortd-note@+4 {{previous declaration is here}}
+// nortd-error@+4 {{function declared 'm68k_rtd' here was previously declared without calling convention}}
+// nortd-note@+4 {{previous declaration is here}}
+// nortd-error@+4 {{function declared 'm68k_rtd' here was previously declared without calling convention}}
+void nonvariadic1(int a, int b, int c);
+void __attribute__((m68k_rtd)) nonvariadic1(int a, int b, int c);
+void nonvariadic2(int a, int b, int c);
+void __attribute__((m68k_rtd)) nonvariadic2(int a, int b, int c) { }
+
+// expected-error@+2 {{variadic function cannot use m68k_rtd calling convention}}
+void variadic(int a, ...);
+void __attribute__((m68k_rtd)) variadic(int a, ...);
+
+// rtd-note@+2 {{previous declaration is here}}
+// rtd-error@+2 {{redeclaration of 'a' with a different type: 'void ((*))(int, int) __attribute__((cdecl))' vs 'void (*)(int, int) __attribute__((m68k_rtd))'}}
+extern void (*a)(int, int);
+__attribute__((cdecl)) extern void (*a)(int, int);
+
+extern void (*b)(int, ...);
+__attribute__((cdecl)) extern void (*b)(int, ...);
+
+// nortd-note@+2 {{previous declaration is here}}
+// nortd-error@+2 {{redeclaration of 'c' with a different type: 'void ((*))(int, int) __attribute__((m68k_rtd))' vs 'void (*)(int, int)'}}
+extern void (*c)(int, int);
+__attribute__((m68k_rtd)) extern void (*c)(int, int);
+
+// expected-error@+2 {{variadic function cannot use m68k_rtd calling convention}}
+extern void (*d)(int, ...);
+__attribute__((m68k_rtd)) extern void (*d)(int, ...);
+
+// expected-warning@+1 {{'m68k_rtd' only applies to function types; type here is 'int'}}
+__attribute__((m68k_rtd)) static int g = 0;
+
+// expected-error@+1 {{'m68k_rtd' attribute takes no arguments}}
+void __attribute__((m68k_rtd("invalid"))) z(int a);
+
+// expected-error@+1 {{function with no prototype cannot use the m68k_rtd calling convention}}
+void __attribute__((m68k_rtd)) e();
Index: clang/test/CodeGenCXX/m68k-rtdcall.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/m68k-rtdcall.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -triple m68k-linux-gnu -emit-llvm -o - %s | FileCheck %s
+
+class A {
+public:
+// CHECK: define{{.*}} m68k_rtdcc void @_ZN1A6memberEv
+  void __attribute__((m68k_rtd)) member() {}
+};
+
+void test() {
+  A a;
+  a.member();
+
+// CHECK: define{{.*}} m68k_rtdcc void @"_ZZ4testvENK3$_0clEi"
+  auto f = [](int b)

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

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



Comment at: clang/test/CodeGen/mrtd.c:10
+// X86: call x86_stdcallcc i32 @bar(
+#ifndef mc68000
   bar(arg);

jrtc27 wrote:
> Uh, this shouldn't be defined in ISO C; GCC's using builtin_define_std, so 
> you should only get `__mc68000` and `__mc68000__` for ISO C, i.e. using 
> `DefineStd("mc68000")` in libClangBasic and let it add the underscored 
> variants needed
Thanks for pointing out. I'll put the changes to using `DefineStd` in a 
separate patch.


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: [Clang][M68k] Add Clang support for the new M68k_RTD CC

2023-10-15 Thread Min-Yih Hsu via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGfd4f96290ac9: [Clang][M68k] Add Clang support for the new 
M68k_RTD CC (authored by myhsu).

Changed prior to commit:
  https://reviews.llvm.org/D149867?vs=552596&id=557711#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149867

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang-c/Index.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/LangOptions.h
  clang/include/clang/Basic/Specifiers.h
  clang/include/clang/Driver/Options.td
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/Type.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Basic/Targets/M68k.cpp
  clang/lib/Basic/Targets/M68k.h
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CodeGen/mrtd.c
  clang/test/CodeGenCXX/default_calling_conv.cpp
  clang/test/CodeGenCXX/m68k-rtdcall.cpp
  clang/test/Sema/m68k-rtdcall.c
  clang/test/SemaCXX/m68k-rtdcall.cpp
  clang/tools/libclang/CXType.cpp

Index: clang/tools/libclang/CXType.cpp
===
--- clang/tools/libclang/CXType.cpp
+++ clang/tools/libclang/CXType.cpp
@@ -678,6 +678,7 @@
   TCALLINGCONV(SwiftAsync);
   TCALLINGCONV(PreserveMost);
   TCALLINGCONV(PreserveAll);
+  TCALLINGCONV(M68kRTD);
 case CC_SpirFunction: return CXCallingConv_Unexposed;
 case CC_AMDGPUKernelCall: return CXCallingConv_Unexposed;
 case CC_OpenCLKernel: return CXCallingConv_Unexposed;
Index: clang/test/SemaCXX/m68k-rtdcall.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/m68k-rtdcall.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -triple m68k-linux-gnu -fsyntax-only %s
+
+class A {
+public:
+  void __attribute__((m68k_rtd)) member() {}
+};
+
+void test() {
+  A a;
+  a.member();
+
+  auto f = [](int b) __attribute__((m68k_rtd)) {};
+  f(87);
+};
Index: clang/test/Sema/m68k-rtdcall.c
===
--- /dev/null
+++ clang/test/Sema/m68k-rtdcall.c
@@ -0,0 +1,46 @@
+// RUN: %clang_cc1 -triple m68k-unknown-unknown -mrtd -std=c89 -verify -verify=rtd %s
+// RUN: %clang_cc1 -triple m68k-unknown-unknown -std=c89 -verify -verify=nortd %s
+
+// rtd-error@+2 {{function with no prototype cannot use the m68k_rtd calling convention}}
+void foo(int arg) {
+  bar(arg);
+}
+
+// nortd-note@+4 {{previous declaration is here}}
+// nortd-error@+4 {{function declared 'm68k_rtd' here was previously declared without calling convention}}
+// nortd-note@+4 {{previous declaration is here}}
+// nortd-error@+4 {{function declared 'm68k_rtd' here was previously declared without calling convention}}
+void nonvariadic1(int a, int b, int c);
+void __attribute__((m68k_rtd)) nonvariadic1(int a, int b, int c);
+void nonvariadic2(int a, int b, int c);
+void __attribute__((m68k_rtd)) nonvariadic2(int a, int b, int c) { }
+
+// expected-error@+2 {{variadic function cannot use m68k_rtd calling convention}}
+void variadic(int a, ...);
+void __attribute__((m68k_rtd)) variadic(int a, ...);
+
+// rtd-note@+2 {{previous declaration is here}}
+// rtd-error@+2 {{redeclaration of 'a' with a different type: 'void ((*))(int, int) __attribute__((cdecl))' vs 'void (*)(int, int) __attribute__((m68k_rtd))'}}
+extern void (*a)(int, int);
+__attribute__((cdecl)) extern void (*a)(int, int);
+
+extern void (*b)(int, ...);
+__attribute__((cdecl)) extern void (*b)(int, ...);
+
+// nortd-note@+2 {{previous declaration is here}}
+// nortd-error@+2 {{redeclaration of 'c' with a different type: 'void ((*))(int, int) __attribute__((m68k_rtd))' vs 'void (*)(int, int)'}}
+extern void (*c)(int, int);
+__attribute__((m68k_rtd)) extern void (*c)(int, int);
+
+// expected-error@+2 {{variadic function cannot use m68k_rtd calling convention}}
+extern void (*d)(int, ...);
+__attribute__((m68k_rtd)) extern void (*d)(int, ...);
+
+// expected-warning@+1 {{'m68k_rtd' only applies to function types; type here is 'int'}}
+__attribute__((m68k_rtd)) static int g = 0;
+
+// expected-error@+1 {{'m68k_rtd' attribute takes no arguments}}
+void __attribute__((m68k_rtd("invalid"))) z(int a);
+
+// expected-error@+1 {{function with no prototype cannot use the m68k_rtd calling convention}}
+void __attribute__((m68k_rtd)) e();
Index: clang/test/CodeGenCXX/m68k-rtdcall.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/m68k-rtdcall.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -triple m68k-linu

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

2023-07-29 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu added a comment.

In D149867#4544281 , @glaubitz wrote:

> Any update on this?

Sorry I was busy on my phd defense (which I passed!) in the past month. I'll 
get back to this next week.


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] D158698: [Clang][M68k] Use `DefineStd` for target-specific macros

2023-08-23 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu created this revision.
myhsu added reviewers: jrtc27, 0x59616e.
Herald added a project: All.
myhsu requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

(From the comments of D149867 )
Use `DefineStd` for target-specific macros such that GNU-style definitions can 
be correctly toggled.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158698

Files:
  clang/lib/Basic/Targets/M68k.cpp
  clang/test/Driver/m68k-macros.cpp

Index: clang/test/Driver/m68k-macros.cpp
===
--- clang/test/Driver/m68k-macros.cpp
+++ clang/test/Driver/m68k-macros.cpp
@@ -4,55 +4,61 @@
 // CHECK-MX881: #define __HAVE_68881__ 1
 // CHECK-NOMX881-NOT: #define __HAVE_68881__ 1
 
-// RUN: %clang -target m68k-unknown-linux -m68000 -dM -E %s | FileCheck --check-prefixes=CHECK-MX,CHECK-NOMX881 %s
+// RUN: %clang -target m68k-unknown-linux -m68000 -std=c++11 -dM -E %s | FileCheck --check-prefixes=CHECK-MX,CHECK-NOMX881 %s
+// RUN: %clang -target m68k-unknown-linux -m68000 -std=gnu++11 -dM -E %s | FileCheck --check-prefixes=CHECK-MX,CHECK-MX-GNU,CHECK-NOMX881 %s
 // RUN: %clang -target m68k-unknown-linux -m68000 -mhard-float -dM -E %s | FileCheck --check-prefix=CHECK-MX881 %s
 // RUN: %clang -target m68k-unknown-linux -m68000 -m68881 -dM -E %s | FileCheck --check-prefix=CHECK-MX881 %s
 // CHECK-MX: #define __mc68000 1
 // CHECK-MX: #define __mc68000__ 1
-// CHECK-MX: #define mc68000 1
+// CHECK-MX-GNU: #define mc68000 1
 
-// RUN: %clang -target m68k-unknown-linux -m68010 -dM -E %s | FileCheck --check-prefixes=CHECK-MX10,CHECK-NOMX881 %s
+// RUN: %clang -target m68k-unknown-linux -m68010 -std=c++11 -dM -E %s | FileCheck --check-prefixes=CHECK-MX10,CHECK-NOMX881 %s
+// RUN: %clang -target m68k-unknown-linux -m68010 -std=gnu++11 -dM -E %s | FileCheck --check-prefixes=CHECK-MX10,CHECK-MX10-GNU,CHECK-NOMX881 %s
 // RUN: %clang -target m68k-unknown-linux -m68010 -mhard-float -dM -E %s | FileCheck --check-prefix=CHECK-MX881 %s
 // RUN: %clang -target m68k-unknown-linux -m68010 -m68881 -dM -E %s | FileCheck --check-prefix=CHECK-MX881 %s
 // CHECK-MX10: #define __mc68000 1
 // CHECK-MX10: #define __mc68000__ 1
 // CHECK-MX10: #define __mc68010 1
 // CHECK-MX10: #define __mc68010__ 1
-// CHECK-MX10: #define mc68000 1
-// CHECK-MX10: #define mc68010 1
+// CHECK-MX10-GNU: #define mc68000 1
+// CHECK-MX10-GNU: #define mc68010 1
 
-// RUN: %clang -target m68k-unknown-linux -m68020 -dM -E %s | FileCheck --check-prefixes=CHECK-MX20,CHECK-MX881 %s
+// RUN: %clang -target m68k-unknown-linux -m68020 -std=c++11 -dM -E %s | FileCheck --check-prefixes=CHECK-MX20,CHECK-MX881 %s
+// RUN: %clang -target m68k-unknown-linux -m68020 -std=gnu++11 -dM -E %s | FileCheck --check-prefixes=CHECK-MX20,CHECK-MX20-GNU,CHECK-MX881 %s
 // RUN: %clang -target m68k-unknown-linux -m68020 -msoft-float -dM -E %s | FileCheck --check-prefix=CHECK-NOMX881 %s
 // CHECK-MX20: #define __mc68000 1
 // CHECK-MX20: #define __mc68000__ 1
 // CHECK-MX20: #define __mc68020 1
 // CHECK-MX20: #define __mc68020__ 1
-// CHECK-MX20: #define mc68000 1
-// CHECK-MX20: #define mc68020 1
+// CHECK-MX20-GNU: #define mc68000 1
+// CHECK-MX20-GNU: #define mc68020 1
 
-// RUN: %clang -target m68k-unknown-linux -m68030 -dM -E %s | FileCheck --check-prefixes=CHECK-MX30,CHECK-MX881 %s
+// RUN: %clang -target m68k-unknown-linux -m68030 -std=c++11 -dM -E %s | FileCheck --check-prefixes=CHECK-MX30,CHECK-MX881 %s
+// RUN: %clang -target m68k-unknown-linux -m68030 -std=gnu++11 -dM -E %s | FileCheck --check-prefixes=CHECK-MX30,CHECK-MX30-GNU,CHECK-MX881 %s
 // RUN: %clang -target m68k-unknown-linux -m68030 -msoft-float -dM -E %s | FileCheck --check-prefix=CHECK-NOMX881 %s
 // CHECK-MX30: #define __mc68000 1
 // CHECK-MX30: #define __mc68000__ 1
 // CHECK-MX30: #define __mc68030 1
 // CHECK-MX30: #define __mc68030__ 1
-// CHECK-MX30: #define mc68000 1
-// CHECK-MX30: #define mc68030 1
+// CHECK-MX30-GNU: #define mc68000 1
+// CHECK-MX30-GNU: #define mc68030 1
 
-// RUN: %clang -target m68k-unknown-linux -m68040 -dM -E %s | FileCheck --check-prefixes=CHECK-MX40,CHECK-MX881 %s
+// RUN: %clang -target m68k-unknown-linux -m68040 -std=c++11 -dM -E %s | FileCheck --check-prefixes=CHECK-MX40,CHECK-MX881 %s
+// RUN: %clang -target m68k-unknown-linux -m68040 -std=gnu++11 -dM -E %s | FileCheck --check-prefixes=CHECK-MX40,CHECK-MX40-GNU,CHECK-MX881 %s
 // RUN: %clang -target m68k-unknown-linux -m68040 -msoft-float -dM -E %s | FileCheck --check-prefix=CHECK-NOMX881 %s
 // CHECK-MX40: #define __mc68000 1
 // CHECK-MX40: #define __mc68000__ 1
 // CHECK-MX40: #define __mc68040 1
 // CHECK-MX40: #define __mc68040__ 1
-// CHECK-MX40: #define mc68000 1
-// CHECK-MX40: #define mc68040 1
+// CHECK-MX40-GNU: #define mc68000 1
+// CHECK-MX40-GNU: #define mc68040 1
 
-// RUN: %clang -target m68k-unknown-linux -m68060 -dM -E %s | FileCheck --check-prefixes=CHECK-MX60,CHECK-

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

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

In D149867#4603853 , @aaron.ballman 
wrote:

> In D149867#4544489 , @myhsu wrote:
>
>> Sorry I was busy on my phd defense (which I passed!) in the past month. I'll 
>> get back to this next week.
>
> Congratulations!! 🎉

Thank you!


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] D158698: [Clang][M68k] Use `DefineStd` for target-specific macros

2023-09-01 Thread Min-Yih Hsu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG230558e444c2: [Clang][M68k] Use `DefineStd` for 
target-specific macros (authored by myhsu).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158698

Files:
  clang/lib/Basic/Targets/M68k.cpp
  clang/test/Driver/m68k-macros.cpp

Index: clang/test/Driver/m68k-macros.cpp
===
--- clang/test/Driver/m68k-macros.cpp
+++ clang/test/Driver/m68k-macros.cpp
@@ -4,55 +4,61 @@
 // CHECK-MX881: #define __HAVE_68881__ 1
 // CHECK-NOMX881-NOT: #define __HAVE_68881__ 1
 
-// RUN: %clang -target m68k-unknown-linux -m68000 -dM -E %s | FileCheck --check-prefixes=CHECK-MX,CHECK-NOMX881 %s
+// RUN: %clang -target m68k-unknown-linux -m68000 -std=c++11 -dM -E %s | FileCheck --check-prefixes=CHECK-MX,CHECK-NOMX881 %s
+// RUN: %clang -target m68k-unknown-linux -m68000 -std=gnu++11 -dM -E %s | FileCheck --check-prefixes=CHECK-MX,CHECK-MX-GNU,CHECK-NOMX881 %s
 // RUN: %clang -target m68k-unknown-linux -m68000 -mhard-float -dM -E %s | FileCheck --check-prefix=CHECK-MX881 %s
 // RUN: %clang -target m68k-unknown-linux -m68000 -m68881 -dM -E %s | FileCheck --check-prefix=CHECK-MX881 %s
 // CHECK-MX: #define __mc68000 1
 // CHECK-MX: #define __mc68000__ 1
-// CHECK-MX: #define mc68000 1
+// CHECK-MX-GNU: #define mc68000 1
 
-// RUN: %clang -target m68k-unknown-linux -m68010 -dM -E %s | FileCheck --check-prefixes=CHECK-MX10,CHECK-NOMX881 %s
+// RUN: %clang -target m68k-unknown-linux -m68010 -std=c++11 -dM -E %s | FileCheck --check-prefixes=CHECK-MX10,CHECK-NOMX881 %s
+// RUN: %clang -target m68k-unknown-linux -m68010 -std=gnu++11 -dM -E %s | FileCheck --check-prefixes=CHECK-MX10,CHECK-MX10-GNU,CHECK-NOMX881 %s
 // RUN: %clang -target m68k-unknown-linux -m68010 -mhard-float -dM -E %s | FileCheck --check-prefix=CHECK-MX881 %s
 // RUN: %clang -target m68k-unknown-linux -m68010 -m68881 -dM -E %s | FileCheck --check-prefix=CHECK-MX881 %s
 // CHECK-MX10: #define __mc68000 1
 // CHECK-MX10: #define __mc68000__ 1
 // CHECK-MX10: #define __mc68010 1
 // CHECK-MX10: #define __mc68010__ 1
-// CHECK-MX10: #define mc68000 1
-// CHECK-MX10: #define mc68010 1
+// CHECK-MX10-GNU: #define mc68000 1
+// CHECK-MX10-GNU: #define mc68010 1
 
-// RUN: %clang -target m68k-unknown-linux -m68020 -dM -E %s | FileCheck --check-prefixes=CHECK-MX20,CHECK-MX881 %s
+// RUN: %clang -target m68k-unknown-linux -m68020 -std=c++11 -dM -E %s | FileCheck --check-prefixes=CHECK-MX20,CHECK-MX881 %s
+// RUN: %clang -target m68k-unknown-linux -m68020 -std=gnu++11 -dM -E %s | FileCheck --check-prefixes=CHECK-MX20,CHECK-MX20-GNU,CHECK-MX881 %s
 // RUN: %clang -target m68k-unknown-linux -m68020 -msoft-float -dM -E %s | FileCheck --check-prefix=CHECK-NOMX881 %s
 // CHECK-MX20: #define __mc68000 1
 // CHECK-MX20: #define __mc68000__ 1
 // CHECK-MX20: #define __mc68020 1
 // CHECK-MX20: #define __mc68020__ 1
-// CHECK-MX20: #define mc68000 1
-// CHECK-MX20: #define mc68020 1
+// CHECK-MX20-GNU: #define mc68000 1
+// CHECK-MX20-GNU: #define mc68020 1
 
-// RUN: %clang -target m68k-unknown-linux -m68030 -dM -E %s | FileCheck --check-prefixes=CHECK-MX30,CHECK-MX881 %s
+// RUN: %clang -target m68k-unknown-linux -m68030 -std=c++11 -dM -E %s | FileCheck --check-prefixes=CHECK-MX30,CHECK-MX881 %s
+// RUN: %clang -target m68k-unknown-linux -m68030 -std=gnu++11 -dM -E %s | FileCheck --check-prefixes=CHECK-MX30,CHECK-MX30-GNU,CHECK-MX881 %s
 // RUN: %clang -target m68k-unknown-linux -m68030 -msoft-float -dM -E %s | FileCheck --check-prefix=CHECK-NOMX881 %s
 // CHECK-MX30: #define __mc68000 1
 // CHECK-MX30: #define __mc68000__ 1
 // CHECK-MX30: #define __mc68030 1
 // CHECK-MX30: #define __mc68030__ 1
-// CHECK-MX30: #define mc68000 1
-// CHECK-MX30: #define mc68030 1
+// CHECK-MX30-GNU: #define mc68000 1
+// CHECK-MX30-GNU: #define mc68030 1
 
-// RUN: %clang -target m68k-unknown-linux -m68040 -dM -E %s | FileCheck --check-prefixes=CHECK-MX40,CHECK-MX881 %s
+// RUN: %clang -target m68k-unknown-linux -m68040 -std=c++11 -dM -E %s | FileCheck --check-prefixes=CHECK-MX40,CHECK-MX881 %s
+// RUN: %clang -target m68k-unknown-linux -m68040 -std=gnu++11 -dM -E %s | FileCheck --check-prefixes=CHECK-MX40,CHECK-MX40-GNU,CHECK-MX881 %s
 // RUN: %clang -target m68k-unknown-linux -m68040 -msoft-float -dM -E %s | FileCheck --check-prefix=CHECK-NOMX881 %s
 // CHECK-MX40: #define __mc68000 1
 // CHECK-MX40: #define __mc68000__ 1
 // CHECK-MX40: #define __mc68040 1
 // CHECK-MX40: #define __mc68040__ 1
-// CHECK-MX40: #define mc68000 1
-// CHECK-MX40: #define mc68040 1
+// CHECK-MX40-GNU: #define mc68000 1
+// CHECK-MX40-GNU: #define mc68040 1
 
-// RUN: %clang -target m68k-unknown-linux -m68060 -dM -E %s | FileCheck --check-prefixes=CHECK-MX60,CHECK-MX881 %s
+// RUN: %clang -target m68k-unknown-linux -m68060 -std=c++11 -

[PATCH] D143529: [M68k] Add support for basic memory constraints in inline asm

2023-03-08 Thread Min-Yih Hsu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7335cd051370: [M68k] Add support for basic memory 
constraints in inline asm (authored by myhsu).

Changed prior to commit:
  https://reviews.llvm.org/D143529?vs=495647&id=503509#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143529

Files:
  clang/lib/Basic/Targets/M68k.cpp
  clang/test/Sema/inline-asm-validate-m68k.c
  llvm/lib/Target/M68k/M68kAsmPrinter.cpp
  llvm/lib/Target/M68k/M68kAsmPrinter.h
  llvm/lib/Target/M68k/M68kISelDAGToDAG.cpp
  llvm/lib/Target/M68k/M68kISelLowering.cpp
  llvm/lib/Target/M68k/M68kISelLowering.h
  llvm/lib/Target/M68k/MCTargetDesc/M68kBaseInfo.h
  llvm/test/CodeGen/M68k/inline-asm.ll

Index: llvm/test/CodeGen/M68k/inline-asm.ll
===
--- llvm/test/CodeGen/M68k/inline-asm.ll
+++ llvm/test/CodeGen/M68k/inline-asm.ll
@@ -1,6 +1,8 @@
 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
 ; RUN: llc -mtriple=m68k < %s -o - | FileCheck %s
 
+@g = internal global i32 10, align 4
+
 ; This function is primarily testing constant constraints that can NOT
 ; be easily checked by Clang. For example, 'K' and 'M' are both
 ; constraints for values that are outside certain numerical range.
@@ -120,3 +122,33 @@
   ret void
 }
 
+define void @memory_constraints() {
+; CHECK-LABEL: memory_constraints:
+; CHECK: .cfi_startproc
+; CHECK-NEXT:  ; %bb.0: ; %entry
+; CHECK-NEXT:suba.l #4, %sp
+; CHECK-NEXT:.cfi_def_cfa_offset -8
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l (0,%sp), %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l (g,%pc), %d2
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:lea (0,%sp), %a0
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l (%a0), %d3
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l (0,%sp), %d4
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:adda.l #4, %sp
+; CHECK-NEXT:rts
+entry:
+  %x = alloca i32, align 4
+  call void asm sideeffect "move.l $0, %d1", "*m"(ptr elementtype(i32) %x)
+  call void asm sideeffect "move.l $0, %d2", "*m"(ptr elementtype(i32) @g)
+  call void asm sideeffect "move.l $0, %d3", "*Q"(ptr elementtype(i32) %x)
+  call void asm sideeffect "move.l $0, %d4", "*U"(ptr elementtype(i32) %x)
+  ret void
+}
+
Index: llvm/lib/Target/M68k/MCTargetDesc/M68kBaseInfo.h
===
--- llvm/lib/Target/M68k/MCTargetDesc/M68kBaseInfo.h
+++ llvm/lib/Target/M68k/MCTargetDesc/M68kBaseInfo.h
@@ -48,6 +48,32 @@
 /// ([bd,PC,Xn],od)
 enum { PCRelDisp = 0, PCRelIndex = 1, PCRelOuter = 2 };
 
+enum class MemAddrModeKind : unsigned {
+  j = 1, // (An)
+  o, // (An)+
+  e, // -(An)
+  p, // (d,An)
+  f, // (d,An,Xn.L)
+  F, // (d,An,Xn.W)
+  g, // (d,An,Xn.L,SCALE)
+  G, // (d,An,Xn.W,SCALE)
+  u, // ([bd,An],Xn.L,SCALE,od)
+  U, // ([bd,An],Xn.W,SCALE,od)
+  v, // ([bd,An,Xn.L,SCALE],od)
+  V, // ([bd,An,Xn.W,SCALE],od)
+  b, // abs.L
+  B, // abs.W
+  q, // (d,PC)
+  k, // (d,PC,Xn.L)
+  K, // (d,PC,Xn.W)
+  l, // (d,PC,Xn.L,SCALE)
+  L, // (d,PC,Xn.W,SCALE)
+  x, // ([bd,PC],Xn.L,SCALE,od)
+  X, // ([bd,PC],Xn.W,SCALE,od)
+  y, // ([bd,PC,Xn.L,SCALE],od)
+  Y  // ([bd,PC,Xn.W,SCALE],od)
+};
+
 // On a LE host:
 // MSB   LSBMSB   LSB
 // | 0x12 0x34 | 0xAB 0xCD | -> | 0xAB 0xCD | 0x12 0x34 |
Index: llvm/lib/Target/M68k/M68kISelLowering.h
===
--- llvm/lib/Target/M68k/M68kISelLowering.h
+++ llvm/lib/Target/M68k/M68kISelLowering.h
@@ -187,6 +187,8 @@
   Register
   getExceptionSelectorRegister(const Constant *PersonalityFn) const override;
 
+  unsigned getInlineAsmMemConstraint(StringRef ConstraintCode) const override;
+
 private:
   unsigned GetAlignedArgumentStackSize(unsigned StackSize,
SelectionDAG &DAG) const;
Index: llvm/lib/Target/M68k/M68kISelLowering.cpp
===
--- llvm/lib/Target/M68k/M68kISelLowering.cpp
+++ llvm/lib/Target/M68k/M68kISelLowering.cpp
@@ -201,6 +201,14 @@
   return M68k::D1;
 }
 
+unsigned
+M68kTargetLowering::getInlineAsmMemConstraint(StringRef ConstraintCode) const {
+  return StringSwitch(ConstraintCode)
+  .Case("Q", InlineAsm::Constraint_Q)
+  .Case("U", InlineAsm::Constraint_Um) // We borrow Constraint_Um for 'U'.
+  .Default(TargetLowering::getInlineAsmMemConstraint(ConstraintCode));
+}
+
 EVT M68kTargetLowering::getSetCCResultType(const DataLayout &DL,
LLVMContext &Context, EVT VT) const {
   // M68k SETcc producess either 0x00 or 0xFF
@@ -2764,6 +2772,9 @@
   break;
 }
   break;
+case '

[PATCH] D87338: [Driver][PGO] Driver support for de-Optimizing cold functions (PATCH 2/2)

2023-04-03 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu abandoned this revision.
myhsu added a comment.
Herald added subscribers: wlei, ormris, MaskRay.
Herald added a project: All.

just realized I haven't updated this patch for years. I'll come up with an 
up-to-date version when I have time.


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

https://reviews.llvm.org/D87338

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


[PATCH] D147481: [M68k] Add basic Clang supports for M68881/2

2023-04-03 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu created this revision.
myhsu added reviewers: 0x59616e, RKSimon.
Herald added a project: All.
myhsu requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang.

- Add the `-m68881` flag
- Add floating point feature detection
- Macro definitions


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147481

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Basic/Targets/M68k.cpp
  clang/lib/Basic/Targets/M68k.h
  clang/lib/Driver/ToolChains/Arch/M68k.cpp
  clang/lib/Driver/ToolChains/Arch/M68k.h
  clang/test/Driver/m68k-features.cpp
  clang/test/Driver/m68k-macros.cpp

Index: clang/test/Driver/m68k-macros.cpp
===
--- clang/test/Driver/m68k-macros.cpp
+++ clang/test/Driver/m68k-macros.cpp
@@ -1,10 +1,16 @@
 // Check macro definitions
 // RUN: %clang -target m68k-unknown-linux -m68000 -dM -E %s | FileCheck --check-prefix=CHECK-MX %s
+// RUN: %clang -target m68k-unknown-linux -m68000 -mhard-float -dM -E %s | FileCheck --check-prefix=CHECK-MX881 %s
+// RUN: %clang -target m68k-unknown-linux -m68000 -m68881 -dM -E %s | FileCheck --check-prefix=CHECK-MX881 %s
+// CHECK-MX-NOT: #define __HAVE_68881__ 1
 // CHECK-MX: #define __mc68000 1
 // CHECK-MX: #define __mc68000__ 1
 // CHECK-MX: #define mc68000 1
 
 // RUN: %clang -target m68k-unknown-linux -m68010 -dM -E %s | FileCheck --check-prefix=CHECK-MX10 %s
+// RUN: %clang -target m68k-unknown-linux -m68010 -mhard-float -dM -E %s | FileCheck --check-prefix=CHECK-MX881 %s
+// RUN: %clang -target m68k-unknown-linux -m68010 -m68881 -dM -E %s | FileCheck --check-prefix=CHECK-MX881 %s
+// CHECK-MX10-NOT: #define __HAVE_68881__ 1
 // CHECK-MX10: #define __mc68000 1
 // CHECK-MX10: #define __mc68000__ 1
 // CHECK-MX10: #define __mc68010 1
@@ -12,7 +18,10 @@
 // CHECK-MX10: #define mc68000 1
 // CHECK-MX10: #define mc68010 1
 
-// RUN: %clang -target m68k-unknown-linux -m68020 -dM -E %s | FileCheck --check-prefix=CHECK-MX20 %s
+// Since '__HAVE_68881__' sorted before most of the 'mc680x0' macros, we need to put it here.
+// CHECK-MX881: #define __HAVE_68881__ 1
+
+// RUN: %clang -target m68k-unknown-linux -m68020 -dM -E %s | FileCheck --check-prefixes=CHECK-MX20,CHECK-MX881 %s
 // CHECK-MX20: #define __mc68000 1
 // CHECK-MX20: #define __mc68000__ 1
 // CHECK-MX20: #define __mc68020 1
@@ -20,7 +29,7 @@
 // CHECK-MX20: #define mc68000 1
 // CHECK-MX20: #define mc68020 1
 
-// RUN: %clang -target m68k-unknown-linux -m68030 -dM -E %s | FileCheck --check-prefix=CHECK-MX30 %s
+// RUN: %clang -target m68k-unknown-linux -m68030 -dM -E %s | FileCheck --check-prefixes=CHECK-MX30,CHECK-MX881 %s
 // CHECK-MX30: #define __mc68000 1
 // CHECK-MX30: #define __mc68000__ 1
 // CHECK-MX30: #define __mc68030 1
@@ -28,7 +37,7 @@
 // CHECK-MX30: #define mc68000 1
 // CHECK-MX30: #define mc68030 1
 
-// RUN: %clang -target m68k-unknown-linux -m68040 -dM -E %s | FileCheck --check-prefix=CHECK-MX40 %s
+// RUN: %clang -target m68k-unknown-linux -m68040 -dM -E %s | FileCheck --check-prefixes=CHECK-MX40,CHECK-MX881 %s
 // CHECK-MX40: #define __mc68000 1
 // CHECK-MX40: #define __mc68000__ 1
 // CHECK-MX40: #define __mc68040 1
@@ -36,7 +45,7 @@
 // CHECK-MX40: #define mc68000 1
 // CHECK-MX40: #define mc68040 1
 
-// RUN: %clang -target m68k-unknown-linux -m68060 -dM -E %s | FileCheck --check-prefix=CHECK-MX60 %s
+// RUN: %clang -target m68k-unknown-linux -m68060 -dM -E %s | FileCheck --check-prefixes=CHECK-MX60,CHECK-MX881 %s
 // CHECK-MX60: #define __mc68000 1
 // CHECK-MX60: #define __mc68000__ 1
 // CHECK-MX60: #define __mc68060 1
Index: clang/test/Driver/m68k-features.cpp
===
--- clang/test/Driver/m68k-features.cpp
+++ clang/test/Driver/m68k-features.cpp
@@ -59,3 +59,23 @@
 // RUN: FileCheck --check-prefix=CHECK-FIXED-D7 < %t %s
 // CHECK-FIXED-D7: "-target-feature" "+reserve-d7"
 
+//  Floating point 
+// RUN: %clang -target m68k -m68000 -mhard-float -### %s 2> %t
+// RUN: FileCheck --check-prefix=CHECK-MX881 < %t %s
+// RUN: %clang -target m68k -m68000 -m68881 -### %s 2> %t
+// RUN: FileCheck --check-prefix=CHECK-MX881 < %t %s
+
+// RUN: %clang -target m68k -m68010 -mhard-float -### %s 2> %t
+// RUN: FileCheck --check-prefix=CHECK-MX881 < %t %s
+// RUN: %clang -target m68k -m68010 -m68881 -### %s 2> %t
+// RUN: FileCheck --check-prefix=CHECK-MX881 < %t %s
+
+// RUN: %clang -target m68k -m68020 -### %s 2> %t
+// RUN: FileCheck --check-prefix=CHECK-MX881 < %t %s
+
+// RUN: %clang -target m68k -m68030 -### %s 2> %t
+// RUN: FileCheck --check-prefix=CHECK-MX882 < %t %s
+
+// CHECK-MX881: "-target-feature" "+isa-68881"
+// CHECK-MX882: "-target-feature" "+isa-68882"
+
Index: clang/lib/Driver/ToolChains/Arch/M68k.h
===
--- clang/lib/Driver/ToolChains/Arch/M68k.h
+++ clang/lib/Driver/ToolChains/Arch/M68k.h
@@ -20,14 +20,6 @@

[PATCH] D147481: [M68k] Add basic Clang supports for M68881/2

2023-04-06 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu updated this revision to Diff 511477.
myhsu marked 2 inline comments as done.
myhsu added a comment.

- Explicit add `isa-68882` even for newer (>=68040) CPUs. Such that's it's a 
lot easier to conditionally add related macro definitions with 
TargetOptions::FeatureMap
- Add cases to test the absent of HAVE_68881 macro definitions


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

https://reviews.llvm.org/D147481

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Basic/Targets/M68k.cpp
  clang/lib/Basic/Targets/M68k.h
  clang/lib/Driver/ToolChains/Arch/M68k.cpp
  clang/lib/Driver/ToolChains/Arch/M68k.h
  clang/test/Driver/m68k-features.cpp
  clang/test/Driver/m68k-macros.cpp

Index: clang/test/Driver/m68k-macros.cpp
===
--- clang/test/Driver/m68k-macros.cpp
+++ clang/test/Driver/m68k-macros.cpp
@@ -1,10 +1,19 @@
 // Check macro definitions
-// RUN: %clang -target m68k-unknown-linux -m68000 -dM -E %s | FileCheck --check-prefix=CHECK-MX %s
+
+// Since '__HAVE_68881__' sorted before most of the 'mc680x0' macros, we need to put it here.
+// CHECK-MX881: #define __HAVE_68881__ 1
+// CHECK-NOMX881-NOT: #define __HAVE_68881__ 1
+
+// RUN: %clang -target m68k-unknown-linux -m68000 -dM -E %s | FileCheck --check-prefixes=CHECK-MX,CHECK-NOMX881 %s
+// RUN: %clang -target m68k-unknown-linux -m68000 -mhard-float -dM -E %s | FileCheck --check-prefix=CHECK-MX881 %s
+// RUN: %clang -target m68k-unknown-linux -m68000 -m68881 -dM -E %s | FileCheck --check-prefix=CHECK-MX881 %s
 // CHECK-MX: #define __mc68000 1
 // CHECK-MX: #define __mc68000__ 1
 // CHECK-MX: #define mc68000 1
 
-// RUN: %clang -target m68k-unknown-linux -m68010 -dM -E %s | FileCheck --check-prefix=CHECK-MX10 %s
+// RUN: %clang -target m68k-unknown-linux -m68010 -dM -E %s | FileCheck --check-prefixes=CHECK-MX10,CHECK-NOMX881 %s
+// RUN: %clang -target m68k-unknown-linux -m68010 -mhard-float -dM -E %s | FileCheck --check-prefix=CHECK-MX881 %s
+// RUN: %clang -target m68k-unknown-linux -m68010 -m68881 -dM -E %s | FileCheck --check-prefix=CHECK-MX881 %s
 // CHECK-MX10: #define __mc68000 1
 // CHECK-MX10: #define __mc68000__ 1
 // CHECK-MX10: #define __mc68010 1
@@ -12,7 +21,8 @@
 // CHECK-MX10: #define mc68000 1
 // CHECK-MX10: #define mc68010 1
 
-// RUN: %clang -target m68k-unknown-linux -m68020 -dM -E %s | FileCheck --check-prefix=CHECK-MX20 %s
+// RUN: %clang -target m68k-unknown-linux -m68020 -dM -E %s | FileCheck --check-prefixes=CHECK-MX20,CHECK-MX881 %s
+// RUN: %clang -target m68k-unknown-linux -m68020 -msoft-float -dM -E %s | FileCheck --check-prefix=CHECK-NOMX881 %s
 // CHECK-MX20: #define __mc68000 1
 // CHECK-MX20: #define __mc68000__ 1
 // CHECK-MX20: #define __mc68020 1
@@ -20,7 +30,8 @@
 // CHECK-MX20: #define mc68000 1
 // CHECK-MX20: #define mc68020 1
 
-// RUN: %clang -target m68k-unknown-linux -m68030 -dM -E %s | FileCheck --check-prefix=CHECK-MX30 %s
+// RUN: %clang -target m68k-unknown-linux -m68030 -dM -E %s | FileCheck --check-prefixes=CHECK-MX30,CHECK-MX881 %s
+// RUN: %clang -target m68k-unknown-linux -m68030 -msoft-float -dM -E %s | FileCheck --check-prefix=CHECK-NOMX881 %s
 // CHECK-MX30: #define __mc68000 1
 // CHECK-MX30: #define __mc68000__ 1
 // CHECK-MX30: #define __mc68030 1
@@ -28,7 +39,8 @@
 // CHECK-MX30: #define mc68000 1
 // CHECK-MX30: #define mc68030 1
 
-// RUN: %clang -target m68k-unknown-linux -m68040 -dM -E %s | FileCheck --check-prefix=CHECK-MX40 %s
+// RUN: %clang -target m68k-unknown-linux -m68040 -dM -E %s | FileCheck --check-prefixes=CHECK-MX40,CHECK-MX881 %s
+// RUN: %clang -target m68k-unknown-linux -m68040 -msoft-float -dM -E %s | FileCheck --check-prefix=CHECK-NOMX881 %s
 // CHECK-MX40: #define __mc68000 1
 // CHECK-MX40: #define __mc68000__ 1
 // CHECK-MX40: #define __mc68040 1
@@ -36,7 +48,8 @@
 // CHECK-MX40: #define mc68000 1
 // CHECK-MX40: #define mc68040 1
 
-// RUN: %clang -target m68k-unknown-linux -m68060 -dM -E %s | FileCheck --check-prefix=CHECK-MX60 %s
+// RUN: %clang -target m68k-unknown-linux -m68060 -dM -E %s | FileCheck --check-prefixes=CHECK-MX60,CHECK-MX881 %s
+// RUN: %clang -target m68k-unknown-linux -m68060 -msoft-float -dM -E %s | FileCheck --check-prefix=CHECK-NOMX881 %s
 // CHECK-MX60: #define __mc68000 1
 // CHECK-MX60: #define __mc68000__ 1
 // CHECK-MX60: #define __mc68060 1
Index: clang/test/Driver/m68k-features.cpp
===
--- clang/test/Driver/m68k-features.cpp
+++ clang/test/Driver/m68k-features.cpp
@@ -59,3 +59,23 @@
 // RUN: FileCheck --check-prefix=CHECK-FIXED-D7 < %t %s
 // CHECK-FIXED-D7: "-target-feature" "+reserve-d7"
 
+//  Floating point 
+// RUN: %clang -target m68k -m68000 -mhard-float -### %s 2> %t
+// RUN: FileCheck --check-prefix=CHECK-MX881 < %t %s
+// RUN: %clang -target m68k -m68000 -m68881 -### %s 2> %t
+// RUN: FileCheck --check-prefix=CHECK-MX881 < %t %s
+
+// RUN: %clang -target m68k -m68010 -

[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] D143529: [M68k] Add support for basic memory constraints in inline asm

2023-02-07 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu created this revision.
myhsu added reviewers: 0x59616e, RKSimon, nickdesaulniers.
Herald added a subscriber: hiraditya.
Herald added a project: All.
myhsu requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

This patch adds support for 'm', 'Q', and 'U' memory constraints.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D143529

Files:
  clang/lib/Basic/Targets/M68k.cpp
  clang/test/Sema/inline-asm-validate-m68k.c
  llvm/lib/Target/M68k/M68kAsmPrinter.cpp
  llvm/lib/Target/M68k/M68kAsmPrinter.h
  llvm/lib/Target/M68k/M68kISelDAGToDAG.cpp
  llvm/lib/Target/M68k/M68kISelLowering.cpp
  llvm/lib/Target/M68k/M68kISelLowering.h
  llvm/lib/Target/M68k/MCTargetDesc/M68kBaseInfo.h
  llvm/test/CodeGen/M68k/inline-asm.ll

Index: llvm/test/CodeGen/M68k/inline-asm.ll
===
--- llvm/test/CodeGen/M68k/inline-asm.ll
+++ llvm/test/CodeGen/M68k/inline-asm.ll
@@ -1,6 +1,8 @@
 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
 ; RUN: llc -mtriple=m68k < %s -o - | FileCheck %s
 
+@g = internal global i32 10, align 4
+
 ; This function is primarily testing constant constraints that can NOT
 ; be easily checked by Clang. For example, 'K' and 'M' are both
 ; constraints for values that are outside certain numerical range.
@@ -120,3 +122,33 @@
   ret void
 }
 
+define void @memory_constraints() {
+; CHECK-LABEL: memory_constraints:
+; CHECK: .cfi_startproc
+; CHECK-NEXT:  ; %bb.0: ; %entry
+; CHECK-NEXT:suba.l #4, %sp
+; CHECK-NEXT:.cfi_def_cfa_offset -8
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l (0,%sp), %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l (g,%pc), %d2
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:lea (0,%sp), %a0
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l (%a0), %d3
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l (0,%sp), %d4
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:adda.l #4, %sp
+; CHECK-NEXT:rts
+entry:
+  %x = alloca i32, align 4
+  call void asm sideeffect "move.l $0, %d1", "*m"(ptr elementtype(i32) %x)
+  call void asm sideeffect "move.l $0, %d2", "*m"(ptr elementtype(i32) @g)
+  call void asm sideeffect "move.l $0, %d3", "*Q"(ptr elementtype(i32) %x)
+  call void asm sideeffect "move.l $0, %d4", "*U"(ptr elementtype(i32) %x)
+  ret void
+}
+
Index: llvm/lib/Target/M68k/MCTargetDesc/M68kBaseInfo.h
===
--- llvm/lib/Target/M68k/MCTargetDesc/M68kBaseInfo.h
+++ llvm/lib/Target/M68k/MCTargetDesc/M68kBaseInfo.h
@@ -48,6 +48,32 @@
 /// ([bd,PC,Xn],od)
 enum { PCRelDisp = 0, PCRelIndex = 1, PCRelOuter = 2 };
 
+enum class MemAddrModeKind : unsigned {
+  j = 1, // (An)
+  o, // (An)+
+  e, // -(An)
+  p, // (d,An)
+  f, // (d,An,Xn.L)
+  F, // (d,An,Xn.W)
+  g, // (d,An,Xn.L,SCALE)
+  G, // (d,An,Xn.W,SCALE)
+  u, // ([bd,An],Xn.L,SCALE,od)
+  U, // ([bd,An],Xn.W,SCALE,od)
+  v, // ([bd,An,Xn.L,SCALE],od)
+  V, // ([bd,An,Xn.W,SCALE],od)
+  b, // abs.L
+  B, // abs.W
+  q, // (d,PC)
+  k, // (d,PC,Xn.L)
+  K, // (d,PC,Xn.W)
+  l, // (d,PC,Xn.L,SCALE)
+  L, // (d,PC,Xn.W,SCALE)
+  x, // ([bd,PC],Xn.L,SCALE,od)
+  X, // ([bd,PC],Xn.W,SCALE,od)
+  y, // ([bd,PC,Xn.L,SCALE],od)
+  Y  // ([bd,PC,Xn.W,SCALE],od)
+};
+
 // On a LE host:
 // MSB   LSBMSB   LSB
 // | 0x12 0x34 | 0xAB 0xCD | -> | 0xAB 0xCD | 0x12 0x34 |
Index: llvm/lib/Target/M68k/M68kISelLowering.h
===
--- llvm/lib/Target/M68k/M68kISelLowering.h
+++ llvm/lib/Target/M68k/M68kISelLowering.h
@@ -177,6 +177,8 @@
   AtomicExpansionKind
   shouldExpandAtomicRMWInIR(AtomicRMWInst *RMW) const override;
 
+  unsigned getInlineAsmMemConstraint(StringRef ConstraintCode) const override;
+
 private:
   unsigned GetAlignedArgumentStackSize(unsigned StackSize,
SelectionDAG &DAG) const;
Index: llvm/lib/Target/M68k/M68kISelLowering.cpp
===
--- llvm/lib/Target/M68k/M68kISelLowering.cpp
+++ llvm/lib/Target/M68k/M68kISelLowering.cpp
@@ -191,6 +191,14 @@
  : TargetLoweringBase::AtomicExpansionKind::None;
 }
 
+unsigned
+M68kTargetLowering::getInlineAsmMemConstraint(StringRef ConstraintCode) const {
+  return StringSwitch(ConstraintCode)
+  .Case("Q", InlineAsm::Constraint_Q)
+  .Case("U", InlineAsm::Constraint_Um) // We borrow Constraint_Um for 'U'.
+  .Default(TargetLowering::getInlineAsmMemConstraint(ConstraintCode));
+}
+
 EVT M68kTargetLowering::getSetCCResultType(const DataLayout &DL,
LLVMContext &Context, EVT VT) const {
   // M68k SETcc producess either 0x00 or 0xFF
@@ -2754,6 +2762,9 @@

[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 llvm::CallingConv::X8

[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-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 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 CC_X86ThisC

[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] D147481: [M68k] Add basic Clang supports for M68881/2

2023-04-22 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu added a comment.

ping


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

https://reviews.llvm.org/D147481

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


[PATCH] D147481: [M68k] Add basic Clang supports for M68881/2

2023-04-24 Thread Min-Yih Hsu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9b617081420d: [M68k] Add basic Clang support for M68881/2 
(authored by myhsu).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147481

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Basic/Targets/M68k.cpp
  clang/lib/Basic/Targets/M68k.h
  clang/lib/Driver/ToolChains/Arch/M68k.cpp
  clang/lib/Driver/ToolChains/Arch/M68k.h
  clang/test/Driver/m68k-features.cpp
  clang/test/Driver/m68k-macros.cpp

Index: clang/test/Driver/m68k-macros.cpp
===
--- clang/test/Driver/m68k-macros.cpp
+++ clang/test/Driver/m68k-macros.cpp
@@ -1,10 +1,19 @@
 // Check macro definitions
-// RUN: %clang -target m68k-unknown-linux -m68000 -dM -E %s | FileCheck --check-prefix=CHECK-MX %s
+
+// Since '__HAVE_68881__' sorted before most of the 'mc680x0' macros, we need to put it here.
+// CHECK-MX881: #define __HAVE_68881__ 1
+// CHECK-NOMX881-NOT: #define __HAVE_68881__ 1
+
+// RUN: %clang -target m68k-unknown-linux -m68000 -dM -E %s | FileCheck --check-prefixes=CHECK-MX,CHECK-NOMX881 %s
+// RUN: %clang -target m68k-unknown-linux -m68000 -mhard-float -dM -E %s | FileCheck --check-prefix=CHECK-MX881 %s
+// RUN: %clang -target m68k-unknown-linux -m68000 -m68881 -dM -E %s | FileCheck --check-prefix=CHECK-MX881 %s
 // CHECK-MX: #define __mc68000 1
 // CHECK-MX: #define __mc68000__ 1
 // CHECK-MX: #define mc68000 1
 
-// RUN: %clang -target m68k-unknown-linux -m68010 -dM -E %s | FileCheck --check-prefix=CHECK-MX10 %s
+// RUN: %clang -target m68k-unknown-linux -m68010 -dM -E %s | FileCheck --check-prefixes=CHECK-MX10,CHECK-NOMX881 %s
+// RUN: %clang -target m68k-unknown-linux -m68010 -mhard-float -dM -E %s | FileCheck --check-prefix=CHECK-MX881 %s
+// RUN: %clang -target m68k-unknown-linux -m68010 -m68881 -dM -E %s | FileCheck --check-prefix=CHECK-MX881 %s
 // CHECK-MX10: #define __mc68000 1
 // CHECK-MX10: #define __mc68000__ 1
 // CHECK-MX10: #define __mc68010 1
@@ -12,7 +21,8 @@
 // CHECK-MX10: #define mc68000 1
 // CHECK-MX10: #define mc68010 1
 
-// RUN: %clang -target m68k-unknown-linux -m68020 -dM -E %s | FileCheck --check-prefix=CHECK-MX20 %s
+// RUN: %clang -target m68k-unknown-linux -m68020 -dM -E %s | FileCheck --check-prefixes=CHECK-MX20,CHECK-MX881 %s
+// RUN: %clang -target m68k-unknown-linux -m68020 -msoft-float -dM -E %s | FileCheck --check-prefix=CHECK-NOMX881 %s
 // CHECK-MX20: #define __mc68000 1
 // CHECK-MX20: #define __mc68000__ 1
 // CHECK-MX20: #define __mc68020 1
@@ -20,7 +30,8 @@
 // CHECK-MX20: #define mc68000 1
 // CHECK-MX20: #define mc68020 1
 
-// RUN: %clang -target m68k-unknown-linux -m68030 -dM -E %s | FileCheck --check-prefix=CHECK-MX30 %s
+// RUN: %clang -target m68k-unknown-linux -m68030 -dM -E %s | FileCheck --check-prefixes=CHECK-MX30,CHECK-MX881 %s
+// RUN: %clang -target m68k-unknown-linux -m68030 -msoft-float -dM -E %s | FileCheck --check-prefix=CHECK-NOMX881 %s
 // CHECK-MX30: #define __mc68000 1
 // CHECK-MX30: #define __mc68000__ 1
 // CHECK-MX30: #define __mc68030 1
@@ -28,7 +39,8 @@
 // CHECK-MX30: #define mc68000 1
 // CHECK-MX30: #define mc68030 1
 
-// RUN: %clang -target m68k-unknown-linux -m68040 -dM -E %s | FileCheck --check-prefix=CHECK-MX40 %s
+// RUN: %clang -target m68k-unknown-linux -m68040 -dM -E %s | FileCheck --check-prefixes=CHECK-MX40,CHECK-MX881 %s
+// RUN: %clang -target m68k-unknown-linux -m68040 -msoft-float -dM -E %s | FileCheck --check-prefix=CHECK-NOMX881 %s
 // CHECK-MX40: #define __mc68000 1
 // CHECK-MX40: #define __mc68000__ 1
 // CHECK-MX40: #define __mc68040 1
@@ -36,7 +48,8 @@
 // CHECK-MX40: #define mc68000 1
 // CHECK-MX40: #define mc68040 1
 
-// RUN: %clang -target m68k-unknown-linux -m68060 -dM -E %s | FileCheck --check-prefix=CHECK-MX60 %s
+// RUN: %clang -target m68k-unknown-linux -m68060 -dM -E %s | FileCheck --check-prefixes=CHECK-MX60,CHECK-MX881 %s
+// RUN: %clang -target m68k-unknown-linux -m68060 -msoft-float -dM -E %s | FileCheck --check-prefix=CHECK-NOMX881 %s
 // CHECK-MX60: #define __mc68000 1
 // CHECK-MX60: #define __mc68000__ 1
 // CHECK-MX60: #define __mc68060 1
Index: clang/test/Driver/m68k-features.cpp
===
--- clang/test/Driver/m68k-features.cpp
+++ clang/test/Driver/m68k-features.cpp
@@ -59,3 +59,23 @@
 // RUN: FileCheck --check-prefix=CHECK-FIXED-D7 < %t %s
 // CHECK-FIXED-D7: "-target-feature" "+reserve-d7"
 
+//  Floating point 
+// RUN: %clang -target m68k -m68000 -mhard-float -### %s 2> %t
+// RUN: FileCheck --check-prefix=CHECK-MX881 < %t %s
+// RUN: %clang -target m68k -m68000 -m68881 -### %s 2> %t
+// RUN: FileCheck --check-prefix=CHECK-MX881 < %t %s
+
+// RUN: %clang -target m68k -m68010 -mhard-float -### %s 2> %t
+// RUN: FileCheck --check-prefix=CHECK-MX881 < %t %s
+// RUN: %clang -target m68k -m68010 -m68881 -##

[PATCH] D148094: [DRAFT][clang][CodeGen] Break up TargetInfo.cpp [6/6]

2023-04-26 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu added a comment.

In D148094#4284316 , @barannikov88 
wrote:

> ping
> Does the approach look right?

This definitely improves the readability and potentially the compilation time.

> Would it be better to put everything into cpp files and only expose a factory 
> method e.g. createMyTargetCodeGenInfo?

I'm fine with either approach. Also, the 68k part looks good.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148094

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


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

2023-06-09 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu updated this revision to Diff 530089.
myhsu retitled this revision from "[M68k] Add Clang support for the new 
M68k_RTD CC" to "[Clang][M68k] Add Clang support for the new M68k_RTD CC".
myhsu edited the summary of this revision.
myhsu set the repository for this revision to rG LLVM Github Monorepo.
myhsu added a comment.
Herald added a subscriber: arphaman.
Herald added a reviewer: aaron.ballman.

Use a new CC, `CC_M68kRTD`, to model `llvm::CallingConv::M68k_RTD` instead of 
using X86StdCall


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149867

Files:
  clang/include/clang-c/Index.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/Specifiers.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/Type.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Basic/Targets/M68k.cpp
  clang/lib/Basic/Targets/M68k.h
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CodeGen/mrtd.c
  clang/test/Sema/m68k-mrtd.c
  clang/tools/libclang/CXType.cpp

Index: clang/tools/libclang/CXType.cpp
===
--- clang/tools/libclang/CXType.cpp
+++ clang/tools/libclang/CXType.cpp
@@ -678,6 +678,7 @@
   TCALLINGCONV(SwiftAsync);
   TCALLINGCONV(PreserveMost);
   TCALLINGCONV(PreserveAll);
+  TCALLINGCONV(M68kRTD);
 case CC_SpirFunction: return CXCallingConv_Unexposed;
 case CC_AMDGPUKernelCall: return CXCallingConv_Unexposed;
 case CC_OpenCLKernel: return CXCallingConv_Unexposed;
Index: clang/test/Sema/m68k-mrtd.c
===
--- /dev/null
+++ clang/test/Sema/m68k-mrtd.c
@@ -0,0 +1,45 @@
+// RUN: %clang_cc1 -DMRTD -mrtd -triple m68k-unknown-unknown -std=c89 -verify %s
+// RUN: %clang_cc1 -triple m68k-unknown-unknown -std=c89 -verify %s
+
+#ifdef MRTD
+// expected-error@+3 {{function with no prototype cannot use the m68k_rtd calling convention}}
+#endif
+void foo(int arg) {
+  bar(arg);
+}
+
+#ifndef MRTD
+// expected-note@+5 {{previous declaration is here}}
+// expected-error@+5 {{function declared 'm68k_rtd' here was previously declared without calling convention}}
+// expected-note@+5 {{previous declaration is here}}
+// expected-error@+5 {{function declared 'm68k_rtd' here was previously declared without calling convention}}
+#endif
+void nonvariadic1(int a, int b, int c);
+void __attribute__((m68k_rtd)) nonvariadic1(int a, int b, int c);
+void nonvariadic2(int a, int b, int c);
+void __attribute__((m68k_rtd)) nonvariadic2(int a, int b, int c) { }
+
+// expected-warning@+2 {{m68k_rtd calling convention is not supported on variadic function}}
+void variadic(int a, ...);
+void __attribute__((m68k_rtd)) variadic(int a, ...);
+
+#ifdef MRTD
+// expected-note@+3 {{previous declaration is here}}
+// expected-error@+3 {{redeclaration of 'a' with a different type: 'void ((*))(int, int) __attribute__((cdecl))' vs 'void (*)(int, int) __attribute__((m68k_rtd))'}}
+#endif
+extern void (*a)(int, int);
+__attribute__((cdecl)) extern void (*a)(int, int);
+
+extern void (*b)(int, ...);
+__attribute__((cdecl)) extern void (*b)(int, ...);
+
+#ifndef MRTD
+// expected-note@+3 {{previous declaration is here}}
+// expected-error@+3 {{redeclaration of 'c' with a different type: 'void ((*))(int, int) __attribute__((m68k_rtd))' vs 'void (*)(int, int)'}}
+#endif
+extern void (*c)(int, int);
+__attribute__((m68k_rtd)) extern void (*c)(int, int);
+
+// expected-warning@+2 {{m68k_rtd calling convention is not supported on variadic function}}
+extern void (*d)(int, ...);
+__attribute__((m68k_rtd)) extern void (*d)(int, ...);
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
+// X86: 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(
+#ifndef mc68000
 

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

2023-06-09 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu marked 3 inline comments as done.
myhsu added inline comments.



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
 

jrtc27 wrote:
> 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.
Now this check is moved to `test/Sema/m68k-mrtd.c`


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: [Clang][M68k] Add Clang support for the new M68k_RTD CC

2023-06-17 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu updated this revision to Diff 532423.
myhsu marked 5 inline comments as done.
myhsu edited the summary of this revision.
myhsu added a comment.
Herald added a subscriber: MaskRay.

- Add a new default calling convention `-fdefault-calling-conv=rtdcall` to 
model using `m68k_rtdcc` globally
- Add documents for `rtdcall`
- Add more tests on `__attribute__((m68k_rtd))`


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

https://reviews.llvm.org/D149867

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang-c/Index.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/LangOptions.h
  clang/include/clang/Basic/Specifiers.h
  clang/include/clang/Driver/Options.td
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/Type.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Basic/Targets/M68k.cpp
  clang/lib/Basic/Targets/M68k.h
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CodeGen/mrtd.c
  clang/test/Sema/m68k-mrtd.c
  clang/tools/libclang/CXType.cpp

Index: clang/tools/libclang/CXType.cpp
===
--- clang/tools/libclang/CXType.cpp
+++ clang/tools/libclang/CXType.cpp
@@ -678,6 +678,7 @@
   TCALLINGCONV(SwiftAsync);
   TCALLINGCONV(PreserveMost);
   TCALLINGCONV(PreserveAll);
+  TCALLINGCONV(M68kRTD);
 case CC_SpirFunction: return CXCallingConv_Unexposed;
 case CC_AMDGPUKernelCall: return CXCallingConv_Unexposed;
 case CC_OpenCLKernel: return CXCallingConv_Unexposed;
Index: clang/test/Sema/m68k-mrtd.c
===
--- /dev/null
+++ clang/test/Sema/m68k-mrtd.c
@@ -0,0 +1,43 @@
+// RUN: %clang_cc1 -triple m68k-unknown-unknown -mrtd -std=c89 -verify -verify=rtd %s
+// RUN: %clang_cc1 -triple m68k-unknown-unknown -std=c89 -verify -verify=nortd %s
+
+// rtd-error@+2 {{function with no prototype cannot use the m68k_rtd calling convention}}
+void foo(int arg) {
+  bar(arg);
+}
+
+// nortd-note@+4 {{previous declaration is here}}
+// nortd-error@+4 {{function declared 'm68k_rtd' here was previously declared without calling convention}}
+// nortd-note@+4 {{previous declaration is here}}
+// nortd-error@+4 {{function declared 'm68k_rtd' here was previously declared without calling convention}}
+void nonvariadic1(int a, int b, int c);
+void __attribute__((m68k_rtd)) nonvariadic1(int a, int b, int c);
+void nonvariadic2(int a, int b, int c);
+void __attribute__((m68k_rtd)) nonvariadic2(int a, int b, int c) { }
+
+// expected-error@+2 {{variadic function cannot use m68k_rtd calling convention}}
+void variadic(int a, ...);
+void __attribute__((m68k_rtd)) variadic(int a, ...);
+
+// rtd-note@+2 {{previous declaration is here}}
+// rtd-error@+2 {{redeclaration of 'a' with a different type: 'void ((*))(int, int) __attribute__((cdecl))' vs 'void (*)(int, int) __attribute__((m68k_rtd))'}}
+extern void (*a)(int, int);
+__attribute__((cdecl)) extern void (*a)(int, int);
+
+extern void (*b)(int, ...);
+__attribute__((cdecl)) extern void (*b)(int, ...);
+
+// nortd-note@+2 {{previous declaration is here}}
+// nortd-error@+2 {{redeclaration of 'c' with a different type: 'void ((*))(int, int) __attribute__((m68k_rtd))' vs 'void (*)(int, int)'}}
+extern void (*c)(int, int);
+__attribute__((m68k_rtd)) extern void (*c)(int, int);
+
+// expected-error@+2 {{variadic function cannot use m68k_rtd calling convention}}
+extern void (*d)(int, ...);
+__attribute__((m68k_rtd)) extern void (*d)(int, ...);
+
+// expected-warning@+1 {{'m68k_rtd' only applies to function types; type here is 'int'}}
+__attribute__((m68k_rtd)) static int g = 0;
+
+// expected-error@+1 {{'m68k_rtd' attribute takes no arguments}}
+void __attribute__((m68k_rtd("invalid"))) z(int a);
Index: clang/test/CodeGen/mrtd.c
===
--- clang/test/CodeGen/mrtd.c
+++ clang/test/CodeGen/mrtd.c
@@ -1,20 +1,24 @@
-// RUN: %clang_cc1 -mrtd -triple i386-unknown-unknown -std=c89 -emit-llvm -o - %s 2>&1 | FileCheck %s
-
-// CHECK: mrtd.c:10:3: warning: function with no prototype cannot use the stdcall calling convention
+// 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
 
 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 @ba

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

2023-06-17 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu 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 ||

aaron.ballman wrote:
> Maybe it's too early in the morning for me to be thinking clearly, but this 
> is wrong for m68k, isn't it? If the default calling convention is stdcall and 
> the architecture is m68k, we want to emit the error, don't we?
> 
> I don't see test coverage for the change.
The idea was to use our new RTD CC whenever `-mrtd` is given to either the 
driver or the frontend. Due to some historical reasons `-mrtd` has been taken 
by i386 to specify stdcall. Specifically, DefaultCallingConvention will be set 
to `DCC_StdCall` when `-mrtd` is present. My original approach was to reuse 
this workflow and the `DCC_StdCall`, then translate to either `CC_X86StdCall` 
or `CC_M68kRTD` later in ASTContext.

Since there are many concerns on reusing DCC_StdCall, I will create another DCC 
enum value instead.



Comment at: clang/test/Sema/m68k-mrtd.c:4-9
+#ifdef MRTD
+// expected-error@+3 {{function with no prototype cannot use the m68k_rtd 
calling convention}}
+#endif
+void foo(int arg) {
+  bar(arg);
+}

aaron.ballman wrote:
> A better way to do this is to use `-verify=mrtd` on the line enabling rtd, 
> and using `// rtd-error {{whatever}}` on the line being diagnosed. (Same 
> comment applies throughout the file.)
> 
> Huh, I was unaware that implicit function declarations are using something 
> other than the default calling convention (which is C, not m68k_rtd). Is this 
> intentional?
> Huh, I was unaware that implicit function declarations are using something 
> other than the default calling convention (which is C, not m68k_rtd). Is this 
> intentional?

I'm not sure if I understand you correctly, but this diagnostic is emitted if 
the CC does not support variadic function call. 



Comment at: clang/test/Sema/m68k-mrtd.c:45
+extern void (*d)(int, ...);
+__attribute__((m68k_rtd)) extern void (*d)(int, ...);

aaron.ballman wrote:
> Missing tests for:
> 
> * Function without a prototype
> * Applying the attribute to a non-function
> * Providing arguments to the attribute
> * What should happen for C++ and things like member functions?
> Function without a prototype

I thought the first check was testing function without a prototype.

> What should happen for C++ and things like member functions?

I believe we don't have any special handling for C++.

I addressed rest of the bullet items you mentioned, please take a look.


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] D117605: [time-trace] Add optimizer and codegen regions to NPM

2022-01-21 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu accepted this revision.
myhsu added a comment.
This revision is now accepted and ready to land.

LGTM I think this is neat. Thank you!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117605

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


[PATCH] D119876: [nfc][codegen] Move RegisterBank[Info].h under CodeGen

2022-03-01 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu accepted this revision.
myhsu added a comment.
This revision is now accepted and ready to land.

since D119053  was accepted, I don't see any 
reason why this patch shouldn't be :-)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119876

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


[PATCH] D119876: [nfc][codegen] Move RegisterBank[Info].h under CodeGen

2022-03-01 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu added inline comments.



Comment at: llvm/lib/Target/ARM/ARMTargetMachine.cpp:43
 #include "llvm/Pass.h"
+#include "llvm/Support/ARMTargetParser.h"
 #include "llvm/Support/CodeGen.h"

Hmm...did you use clang-format-diff.py? I wonder why this was changed (although 
it's a legit one)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119876

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