r346471 - [PowerPC] [Clang] [AltiVec] The second parameter of vec_sr function should be modulo the number of bits in the element

2018-11-08 Thread Zi Xuan Wu via cfe-commits
Author: wuzish
Date: Thu Nov  8 19:35:32 2018
New Revision: 346471

URL: http://llvm.org/viewvc/llvm-project?rev=346471&view=rev
Log:
[PowerPC] [Clang] [AltiVec] The second parameter of vec_sr function should be 
modulo the number of bits in the element

The second parameter of vec_sr function is representing shift bits and it 
should be modulo the number of bits in the element like what vec_sl does now. 
This is actually required by the ABI:

Each element of the result vector is the result of logically right shifting the 
corresponding
element of ARG1 by the number of bits specified by the value of the 
corresponding
element of ARG2, modulo the number of bits in the element. The bits that are 
shifted out
are replaced by zeros.

Differential Revision: https://reviews.llvm.org/D54087


Modified:
cfe/trunk/lib/Headers/altivec.h
cfe/trunk/test/CodeGen/builtins-ppc-altivec.c
cfe/trunk/test/CodeGen/builtins-ppc-p8vector.c

Modified: cfe/trunk/lib/Headers/altivec.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/altivec.h?rev=346471&r1=346470&r2=346471&view=diff
==
--- cfe/trunk/lib/Headers/altivec.h (original)
+++ cfe/trunk/lib/Headers/altivec.h Thu Nov  8 19:35:32 2018
@@ -9492,49 +9492,51 @@ vec_splat_u32(signed char __a) {
 
 /* vec_sr */
 
-static __inline__ vector signed char __ATTRS_o_ai
-vec_sr(vector signed char __a, vector unsigned char __b) {
-  vector unsigned char __res = (vector unsigned char)__a >> __b;
-  return (vector signed char)__res;
-}
-
+// vec_sr does modulo arithmetic on __b first, so __b is allowed to be more
+// than the length of __a.
 static __inline__ vector unsigned char __ATTRS_o_ai
 vec_sr(vector unsigned char __a, vector unsigned char __b) {
-  return __a >> __b;
+  return __a >>
+ (__b % (vector unsigned char)(sizeof(unsigned char) * __CHAR_BIT__));
 }
 
-static __inline__ vector signed short __ATTRS_o_ai
-vec_sr(vector signed short __a, vector unsigned short __b) {
-  vector unsigned short __res = (vector unsigned short)__a >> __b;
-  return (vector signed short)__res;
+static __inline__ vector signed char __ATTRS_o_ai
+vec_sr(vector signed char __a, vector unsigned char __b) {
+  return (vector signed char)vec_sr((vector unsigned char)__a, __b);
 }
 
 static __inline__ vector unsigned short __ATTRS_o_ai
 vec_sr(vector unsigned short __a, vector unsigned short __b) {
-  return __a >> __b;
+  return __a >>
+ (__b % (vector unsigned short)(sizeof(unsigned short) * 
__CHAR_BIT__));
 }
 
-static __inline__ vector signed int __ATTRS_o_ai
-vec_sr(vector signed int __a, vector unsigned int __b) {
-  vector unsigned int __res = (vector unsigned int)__a >> __b;
-  return (vector signed int)__res;
+static __inline__ vector short __ATTRS_o_ai vec_sr(vector short __a,
+   vector unsigned short __b) {
+  return (vector short)vec_sr((vector unsigned short)__a, __b);
 }
 
 static __inline__ vector unsigned int __ATTRS_o_ai
 vec_sr(vector unsigned int __a, vector unsigned int __b) {
-  return __a >> __b;
+  return __a >>
+ (__b % (vector unsigned int)(sizeof(unsigned int) * __CHAR_BIT__));
 }
 
-#ifdef __POWER8_VECTOR__
-static __inline__ vector signed long long __ATTRS_o_ai
-vec_sr(vector signed long long __a, vector unsigned long long __b) {
-  vector unsigned long long __res = (vector unsigned long long)__a >> __b;
-  return (vector signed long long)__res;
+static __inline__ vector int __ATTRS_o_ai vec_sr(vector int __a,
+ vector unsigned int __b) {
+  return (vector int)vec_sr((vector unsigned int)__a, __b);
 }
 
+#ifdef __POWER8_VECTOR__
 static __inline__ vector unsigned long long __ATTRS_o_ai
 vec_sr(vector unsigned long long __a, vector unsigned long long __b) {
-  return __a >> __b;
+  return __a >> (__b % (vector unsigned long long)(sizeof(unsigned long long) *
+   __CHAR_BIT__));
+}
+
+static __inline__ vector long long __ATTRS_o_ai
+vec_sr(vector long long __a, vector unsigned long long __b) {
+  return (vector long long)vec_sr((vector unsigned long long)__a, __b);
 }
 #endif
 
@@ -9544,12 +9546,12 @@ vec_sr(vector unsigned long long __a, ve
 
 static __inline__ vector signed char __ATTRS_o_ai
 vec_vsrb(vector signed char __a, vector unsigned char __b) {
-  return __a >> (vector signed char)__b;
+  return vec_sr(__a, __b);
 }
 
 static __inline__ vector unsigned char __ATTRS_o_ai
 vec_vsrb(vector unsigned char __a, vector unsigned char __b) {
-  return __a >> __b;
+  return vec_sr(__a, __b);
 }
 
 /* vec_vsrh */
@@ -9558,12 +9560,12 @@ vec_vsrb(vector unsigned char __a, vecto
 
 static __inline__ vector short __ATTRS_o_ai
 vec_vsrh(vector short __a, vector unsigned short __b) {
-  return __a >> (vector short)__b;
+  return vec_sr(__a, __b);
 }
 
 static __inline__ vector unsigned short __ATTRS_o_ai
 vec_vsrh(vect

r347019 - [Clang][Sema]Choose a better candidate in overload function call if there is a compatible vector conversion instead of ambiguous call error

2018-11-15 Thread Zi Xuan Wu via cfe-commits
Author: wuzish
Date: Thu Nov 15 19:00:00 2018
New Revision: 347019

URL: http://llvm.org/viewvc/llvm-project?rev=347019&view=rev
Log:
[Clang][Sema]Choose a better candidate in overload function call if there is a 
compatible vector conversion instead of ambiguous call error

There are 2 function variations with vector type parameter. When we call them 
with argument of different vector type we would prefer to 
choose the variation with implicit argument conversion of compatible vector 
type instead of incompatible vector type. For example,

typedef float __v4sf __attribute__((__vector_size__(16)));
void f(vector float);
void f(vector signed int);

int main {
   __v4sf a;
   f(a);
}

Here, we'd like to choose f(vector float) but not report an ambiguous call 
error.

Differential revision: https://reviews.llvm.org/D53417


Added:
cfe/trunk/test/Sema/altivec-generic-overload.c
Modified:
cfe/trunk/lib/Sema/SemaOverload.cpp
cfe/trunk/test/SemaCXX/vector.cpp

Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=347019&r1=347018&r2=347019&view=diff
==
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Thu Nov 15 19:00:00 2018
@@ -3900,6 +3900,31 @@ CompareStandardConversionSequences(Sema
   S.Context.getTypeSize(SCS1.getToType(2)))
 return ImplicitConversionSequence::Better;
 
+  // Prefer a compatible vector conversion over a lax vector conversion
+  // For example:
+  //
+  // typedef float __v4sf __attribute__((__vector_size__(16)));
+  // void f(vector float);
+  // void f(vector signed int);
+  // int main() {
+  //   __v4sf a;
+  //   f(a);
+  // }
+  // Here, we'd like to choose f(vector float) and not
+  // report an ambiguous call error
+  if (SCS1.Second == ICK_Vector_Conversion &&
+  SCS2.Second == ICK_Vector_Conversion) {
+bool SCS1IsCompatibleVectorConversion = S.Context.areCompatibleVectorTypes(
+SCS1.getFromType(), SCS1.getToType(2));
+bool SCS2IsCompatibleVectorConversion = S.Context.areCompatibleVectorTypes(
+SCS2.getFromType(), SCS2.getToType(2));
+
+if (SCS1IsCompatibleVectorConversion != SCS2IsCompatibleVectorConversion)
+  return SCS1IsCompatibleVectorConversion
+ ? ImplicitConversionSequence::Better
+ : ImplicitConversionSequence::Worse;
+  }
+
   return ImplicitConversionSequence::Indistinguishable;
 }
 

Added: cfe/trunk/test/Sema/altivec-generic-overload.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/altivec-generic-overload.c?rev=347019&view=auto
==
--- cfe/trunk/test/Sema/altivec-generic-overload.c (added)
+++ cfe/trunk/test/Sema/altivec-generic-overload.c Thu Nov 15 19:00:00 2018
@@ -0,0 +1,100 @@
+// RUN: %clang_cc1 %s -triple=powerpc64le-unknown-linux -target-feature 
+altivec -target-feature +vsx -verify -verify-ignore-unexpected=note -pedantic 
-fsyntax-only
+
+typedef signed char __v16sc __attribute__((__vector_size__(16)));
+typedef unsigned char __v16uc __attribute__((__vector_size__(16)));
+typedef signed short __v8ss __attribute__((__vector_size__(16)));
+typedef unsigned short __v8us __attribute__((__vector_size__(16)));
+typedef signed int __v4si __attribute__((__vector_size__(16)));
+typedef unsigned int __v4ui __attribute__((__vector_size__(16)));
+typedef signed long long __v2sll __attribute__((__vector_size__(16)));
+typedef unsigned long long __v2ull __attribute__((__vector_size__(16)));
+typedef signed __int128 __v1slll __attribute__((__vector_size__(16)));
+typedef unsigned __int128 __v1ulll __attribute__((__vector_size__(16)));
+typedef float __v4f __attribute__((__vector_size__(16)));
+typedef double __v2d __attribute__((__vector_size__(16)));
+
+__v16sc *__attribute__((__overloadable__)) convert1(vector signed char);
+__v16uc *__attribute__((__overloadable__)) convert1(vector unsigned char);
+__v8ss *__attribute__((__overloadable__)) convert1(vector signed short);
+__v8us *__attribute__((__overloadable__)) convert1(vector unsigned short);
+__v4si *__attribute__((__overloadable__)) convert1(vector signed int);
+__v4ui *__attribute__((__overloadable__)) convert1(vector unsigned int);
+__v2sll *__attribute__((__overloadable__)) convert1(vector signed long long);
+__v2ull *__attribute__((__overloadable__)) convert1(vector unsigned long long);
+__v1slll *__attribute__((__overloadable__)) convert1(vector signed __int128);
+__v1ulll *__attribute__((__overloadable__)) convert1(vector unsigned __int128);
+__v4f *__attribute__((__overloadable__)) convert1(vector float);
+__v2d *__attribute__((__overloadable__)) convert1(vector double);
+void __attribute__((__overloadable__)) convert1(vector bool int);
+void __attribute__((__overloadable__)) convert1(vector pixel short);
+
+vector signed char *__attribute__

[clang] 97e4960 - [Clang][CSKY] Add the CSKY target and compiler driver

2022-04-05 Thread Zi Xuan Wu via cfe-commits

Author: Zi Xuan Wu
Date: 2022-04-06T11:37:37+08:00
New Revision: 97e496054a378131227262109c856f89b288c309

URL: 
https://github.com/llvm/llvm-project/commit/97e496054a378131227262109c856f89b288c309
DIFF: 
https://github.com/llvm/llvm-project/commit/97e496054a378131227262109c856f89b288c309.diff

LOG: [Clang][CSKY] Add the CSKY target and compiler driver

Add CSKY target toolchains to support csky in linux and elf environment.

It can leverage the basic universal Linux toolchain for linux environment, and 
only add some compile or link parameters.
For elf environment, add a CSKYToolChain to support compile and link.

Also add some parameters into basic codebase of clang driver.

Differential Revision: https://reviews.llvm.org/D121445

Added: 
clang/lib/Basic/Targets/CSKY.cpp
clang/lib/Basic/Targets/CSKY.h
clang/lib/Driver/ToolChains/Arch/CSKY.cpp
clang/lib/Driver/ToolChains/Arch/CSKY.h
clang/lib/Driver/ToolChains/CSKYToolChain.cpp
clang/lib/Driver/ToolChains/CSKYToolChain.h
clang/test/Driver/Inputs/multilib_csky_linux_sdk/csky-linux-gnuabiv2/bin/ld

clang/test/Driver/Inputs/multilib_csky_linux_sdk/csky-linux-gnuabiv2/libc/ck860v/lib/.keep

clang/test/Driver/Inputs/multilib_csky_linux_sdk/csky-linux-gnuabiv2/libc/ck860v/usr/lib/crt1.o

clang/test/Driver/Inputs/multilib_csky_linux_sdk/csky-linux-gnuabiv2/libc/lib/.keep

clang/test/Driver/Inputs/multilib_csky_linux_sdk/csky-linux-gnuabiv2/libc/usr/lib/crt1.o

clang/test/Driver/Inputs/multilib_csky_linux_sdk/lib/gcc/csky-linux-gnuabiv2/6.3.0/ck860v/crtbegin.o

clang/test/Driver/Inputs/multilib_csky_linux_sdk/lib/gcc/csky-linux-gnuabiv2/6.3.0/ck860v/crtend.o

clang/test/Driver/Inputs/multilib_csky_linux_sdk/lib/gcc/csky-linux-gnuabiv2/6.3.0/ck860v/crti.o

clang/test/Driver/Inputs/multilib_csky_linux_sdk/lib/gcc/csky-linux-gnuabiv2/6.3.0/ck860v/crtn.o

clang/test/Driver/Inputs/multilib_csky_linux_sdk/lib/gcc/csky-linux-gnuabiv2/6.3.0/crtbegin.o

clang/test/Driver/Inputs/multilib_csky_linux_sdk/lib/gcc/csky-linux-gnuabiv2/6.3.0/crtend.o

clang/test/Driver/Inputs/multilib_csky_linux_sdk/lib/gcc/csky-linux-gnuabiv2/6.3.0/crti.o

clang/test/Driver/Inputs/multilib_csky_linux_sdk/lib/gcc/csky-linux-gnuabiv2/6.3.0/crtn.o
clang/test/Driver/csky-arch-error.c
clang/test/Driver/csky-arch.c
clang/test/Driver/csky-cpus-error.c
clang/test/Driver/csky-cpus.c
clang/test/Driver/csky-toolchain.c
clang/test/Preprocessor/csky-target-features.c
clang/test/Preprocessor/init-csky.c

Modified: 
clang/lib/Basic/CMakeLists.txt
clang/lib/Basic/Targets.cpp
clang/lib/Driver/CMakeLists.txt
clang/lib/Driver/Driver.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Driver/ToolChains/CommonArgs.cpp
clang/lib/Driver/ToolChains/Gnu.cpp
clang/lib/Driver/ToolChains/Linux.cpp
llvm/lib/Support/CSKYTargetParser.cpp
llvm/unittests/Support/CSKYTargetParserTest.cpp

Removed: 




diff  --git a/clang/lib/Basic/CMakeLists.txt b/clang/lib/Basic/CMakeLists.txt
index 12ed97b99b45f..c815b571bc9c0 100644
--- a/clang/lib/Basic/CMakeLists.txt
+++ b/clang/lib/Basic/CMakeLists.txt
@@ -75,6 +75,7 @@ add_clang_library(clangBasic
   Targets/ARM.cpp
   Targets/AVR.cpp
   Targets/BPF.cpp
+  Targets/CSKY.cpp
   Targets/DirectX.cpp
   Targets/Hexagon.cpp
   Targets/Lanai.cpp

diff  --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp
index 641345452cfe3..85c73abde1826 100644
--- a/clang/lib/Basic/Targets.cpp
+++ b/clang/lib/Basic/Targets.cpp
@@ -19,6 +19,7 @@
 #include "Targets/ARM.h"
 #include "Targets/AVR.h"
 #include "Targets/BPF.h"
+#include "Targets/CSKY.h"
 #include "Targets/DirectX.h"
 #include "Targets/Hexagon.h"
 #include "Targets/Lanai.h"
@@ -659,6 +660,14 @@ TargetInfo *AllocateTarget(const llvm::Triple &Triple,
 
   case llvm::Triple::ve:
 return new LinuxTargetInfo(Triple, Opts);
+
+  case llvm::Triple::csky:
+switch (os) {
+case llvm::Triple::Linux:
+  return new LinuxTargetInfo(Triple, Opts);
+default:
+  return new CSKYTargetInfo(Triple, Opts);
+}
   }
 }
 } // namespace targets

diff  --git a/clang/lib/Basic/Targets/CSKY.cpp 
b/clang/lib/Basic/Targets/CSKY.cpp
new file mode 100644
index 0..40004da982594
--- /dev/null
+++ b/clang/lib/Basic/Targets/CSKY.cpp
@@ -0,0 +1,295 @@
+//===--- CSKY.cpp - Implement CSKY target feature support 
-===//
+//
+// 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 implements CSKY TargetInfo objects.
+//
+//===--===//
+
+#include "CSKY.h"
+
+using namespace clang;
+u

[clang] 9906d38 - [NFC][CSKY] Fix the test error in toolchain case in windows by add UNSUPPORTED: system-windows

2022-04-05 Thread Zi Xuan Wu via cfe-commits

Author: Zi Xuan Wu
Date: 2022-04-06T12:18:54+08:00
New Revision: 9906d38252d112894f304ba1b4fbdcd2cc93ab19

URL: 
https://github.com/llvm/llvm-project/commit/9906d38252d112894f304ba1b4fbdcd2cc93ab19
DIFF: 
https://github.com/llvm/llvm-project/commit/9906d38252d112894f304ba1b4fbdcd2cc93ab19.diff

LOG: [NFC][CSKY] Fix the test error in toolchain case in windows by add 
UNSUPPORTED: system-windows

Added: 


Modified: 
clang/test/Driver/csky-toolchain.c

Removed: 




diff  --git a/clang/test/Driver/csky-toolchain.c 
b/clang/test/Driver/csky-toolchain.c
index 3f8069da4735d..6f120cf452cb7 100644
--- a/clang/test/Driver/csky-toolchain.c
+++ b/clang/test/Driver/csky-toolchain.c
@@ -1,3 +1,4 @@
+// UNSUPPORTED: system-windows
 // A basic clang -cc1 command-line, and simple environment check.
 
 // RUN: %clang %s -### -no-canonical-prefixes -target csky 2>&1 | FileCheck 
-check-prefix=CC1 %s



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


[clang] dca37af - [NFC][Clang] Modify expect of fail test or XFAIL because CSKY align is different

2022-05-17 Thread Zi Xuan Wu via cfe-commits

Author: Zi Xuan Wu (Zeson)
Date: 2022-05-18T10:53:30+08:00
New Revision: dca37af061fbe6590399dfb4e3fd3dda16d63144

URL: 
https://github.com/llvm/llvm-project/commit/dca37af061fbe6590399dfb4e3fd3dda16d63144
DIFF: 
https://github.com/llvm/llvm-project/commit/dca37af061fbe6590399dfb4e3fd3dda16d63144.diff

LOG: [NFC][Clang] Modify expect of fail test or XFAIL because CSKY align is 
different

CSKY is always in 4-byte align, no matter it's long long type.
For global aggregate variable, it's 4-byte align if its size is bigger than or 
equal to 4 bytes.

Differential Revision: https://reviews.llvm.org/D124977

Added: 


Modified: 
clang/test/CodeGen/c-strings.c
clang/test/Sema/builtin-alloca-with-align.c

Removed: 




diff  --git a/clang/test/CodeGen/c-strings.c b/clang/test/CodeGen/c-strings.c
index 085380101554..e783b6cb6ad0 100644
--- a/clang/test/CodeGen/c-strings.c
+++ b/clang/test/CodeGen/c-strings.c
@@ -20,6 +20,11 @@
 // fails the check for "@f3.x = ... align [ALIGN]", since ALIGN is derived
 // from the alignment of a single i8, which is still 1.
 
+// XFAIL: csky
+// CSKY aligns arrays of size 4+ bytes to a 32-bit boundary, which
+// fails the check for "@f2.x = ... align [ALIGN]", since ALIGN is derived
+// from the alignment of a single i8, which is still 1.
+
 #if defined(__s390x__)
 unsigned char align = 2;
 #else
@@ -69,4 +74,3 @@ void f4(void) {
 }
 
 char x[3] = "ola";
-

diff  --git a/clang/test/Sema/builtin-alloca-with-align.c 
b/clang/test/Sema/builtin-alloca-with-align.c
index cac171f0e7ea..0a3e0f6a2022 100644
--- a/clang/test/Sema/builtin-alloca-with-align.c
+++ b/clang/test/Sema/builtin-alloca-with-align.c
@@ -30,4 +30,8 @@ void test7(int a) {
 
 void test8(void) {
   __builtin_alloca_with_align(sizeof(__INT64_TYPE__), 
__alignof__(__INT64_TYPE__)); // expected-warning {{second argument to 
__builtin_alloca_with_align is supposed to be in bits}}
+#if defined(__csky__)
+  // expected-error@-1 {{requested alignment must be 8 or greater}}
+  // Because the alignment of long long is 4 in CSKY target
+#endif
 }



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


[clang] 632cfbc - [NFC][test] Fix the line num of expected-error for CSKY at builtin-alloca-with-align.c

2022-05-20 Thread Zi Xuan Wu via cfe-commits

Author: Zi Xuan Wu
Date: 2022-05-20T16:54:23+08:00
New Revision: 632cfbc9f933afc9956f7e0b26086fb1cb7294b5

URL: 
https://github.com/llvm/llvm-project/commit/632cfbc9f933afc9956f7e0b26086fb1cb7294b5
DIFF: 
https://github.com/llvm/llvm-project/commit/632cfbc9f933afc9956f7e0b26086fb1cb7294b5.diff

LOG: [NFC][test] Fix the line num of expected-error for CSKY at 
builtin-alloca-with-align.c

Added: 


Modified: 
clang/test/Sema/builtin-alloca-with-align.c

Removed: 




diff  --git a/clang/test/Sema/builtin-alloca-with-align.c 
b/clang/test/Sema/builtin-alloca-with-align.c
index 0a3e0f6a20220..5f55c070fa333 100644
--- a/clang/test/Sema/builtin-alloca-with-align.c
+++ b/clang/test/Sema/builtin-alloca-with-align.c
@@ -31,7 +31,7 @@ void test7(int a) {
 void test8(void) {
   __builtin_alloca_with_align(sizeof(__INT64_TYPE__), 
__alignof__(__INT64_TYPE__)); // expected-warning {{second argument to 
__builtin_alloca_with_align is supposed to be in bits}}
 #if defined(__csky__)
-  // expected-error@-1 {{requested alignment must be 8 or greater}}
+  // expected-error@-2 {{requested alignment must be 8 or greater}}
   // Because the alignment of long long is 4 in CSKY target
 #endif
 }



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


[clang] b86440e - [CSKY] Fix the conflict of default fpu features and -mfpu option

2022-05-22 Thread Zi Xuan Wu via cfe-commits

Author: Zi Xuan Wu (Zeson)
Date: 2022-05-23T10:44:55+08:00
New Revision: b86440ecde5c1dec5b898a3f1bc08ab9853d5ed9

URL: 
https://github.com/llvm/llvm-project/commit/b86440ecde5c1dec5b898a3f1bc08ab9853d5ed9
DIFF: 
https://github.com/llvm/llvm-project/commit/b86440ecde5c1dec5b898a3f1bc08ab9853d5ed9.diff

LOG: [CSKY] Fix the conflict of default fpu features and -mfpu option

The arch or cpu has its default fpu features and versions such as 
fpuv2_sf/fpuv3_sf.
And there is also -mfpu option to specify and override fpu version and features.
For example, C860 has fpuv3_sf/fpuv3_df feature as default, when
-mfpu=fpv2 is given, fpuv3_sf/fpuv3_df is replaced with fpuv2_sf/fpuv2_df.

Added: 
clang/test/Driver/csky-mfpu.c

Modified: 
clang/lib/Basic/Targets/CSKY.cpp
clang/lib/Basic/Targets/CSKY.h
clang/lib/Driver/ToolChains/Arch/CSKY.cpp
llvm/lib/Support/CSKYTargetParser.cpp

Removed: 




diff  --git a/clang/lib/Basic/Targets/CSKY.cpp 
b/clang/lib/Basic/Targets/CSKY.cpp
index 40004da982594..adcffd90ae780 100644
--- a/clang/lib/Basic/Targets/CSKY.cpp
+++ b/clang/lib/Basic/Targets/CSKY.cpp
@@ -95,17 +95,36 @@ void CSKYTargetInfo::getTargetDefines(const LangOptions 
&Opts,
   }
 }
 
+bool CSKYTargetInfo::hasFeature(StringRef Feature) const {
+  return llvm::StringSwitch(Feature)
+  .Case("hard-float", HardFloat)
+  .Case("hard-float-abi", HardFloatABI)
+  .Case("fpuv2_sf", FPUV2_SF)
+  .Case("fpuv2_df", FPUV2_DF)
+  .Case("fpuv3_sf", FPUV3_SF)
+  .Case("fpuv3_df", FPUV3_DF)
+  .Case("vdspv2", VDSPV2)
+  .Case("dspv2", DSPV2)
+  .Case("vdspv1", VDSPV1)
+  .Case("3e3r1", is3E3R1)
+  .Default(false);
+}
+
 bool CSKYTargetInfo::handleTargetFeatures(std::vector &Features,
   DiagnosticsEngine &Diags) {
-  HardFloat = false;
-  VDSPV2 = false;
-  VDSPV1 = false;
-  DSPV2 = false;
-  is3E3R1 = false;
-
   for (const auto &Feature : Features) {
 if (Feature == "+hard-float")
   HardFloat = true;
+if (Feature == "+hard-float-abi")
+  HardFloatABI = true;
+if (Feature == "+fpuv2_sf")
+  FPUV2_SF = true;
+if (Feature == "+fpuv2_df")
+  FPUV2_DF = true;
+if (Feature == "+fpuv3_sf")
+  FPUV3_SF = true;
+if (Feature == "+fpuv3_df")
+  FPUV3_DF = true;
 if (Feature == "+vdspv2")
   VDSPV2 = true;
 if (Feature == "+dspv2")

diff  --git a/clang/lib/Basic/Targets/CSKY.h b/clang/lib/Basic/Targets/CSKY.h
index 17e5f30d3cd87..7e932e7c86b1c 100644
--- a/clang/lib/Basic/Targets/CSKY.h
+++ b/clang/lib/Basic/Targets/CSKY.h
@@ -26,11 +26,16 @@ class LLVM_LIBRARY_VISIBILITY CSKYTargetInfo : public 
TargetInfo {
   llvm::CSKY::ArchKind Arch = llvm::CSKY::ArchKind::INVALID;
   std::string CPU;
 
-  bool HardFloat;
-  bool VDSPV2;
-  bool VDSPV1;
-  bool DSPV2;
-  bool is3E3R1;
+  bool HardFloat = false;
+  bool HardFloatABI = false;
+  bool FPUV2_SF = false;
+  bool FPUV2_DF = false;
+  bool FPUV3_SF = false;
+  bool FPUV3_DF = false;
+  bool VDSPV2 = false;
+  bool VDSPV1 = false;
+  bool DSPV2 = false;
+  bool is3E3R1 = false;
 
 public:
   CSKYTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
@@ -81,6 +86,7 @@ class LLVM_LIBRARY_VISIBILITY CSKYTargetInfo : public 
TargetInfo {
 
   void getTargetDefines(const LangOptions &Opts,
 MacroBuilder &Builder) const override;
+  bool hasFeature(StringRef Feature) const override;
   bool handleTargetFeatures(std::vector &Features,
 DiagnosticsEngine &Diags) override;
 

diff  --git a/clang/lib/Driver/ToolChains/Arch/CSKY.cpp 
b/clang/lib/Driver/ToolChains/Arch/CSKY.cpp
index fb809956afa80..3a8f927856092 100644
--- a/clang/lib/Driver/ToolChains/Arch/CSKY.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/CSKY.cpp
@@ -91,6 +91,22 @@ getCSKYFPUFeatures(const Driver &D, const Arg *A, const 
ArgList &Args,
   .Case("fpv3_hsf", llvm::CSKY::FK_FPV3_HSF)
   .Case("fpv3_sdf", llvm::CSKY::FK_FPV3_SDF)
   .Default(llvm::CSKY::FK_INVALID);
+  if (FPUID == llvm::CSKY::FK_INVALID) {
+D.Diag(clang::diag::err_drv_clang_unsupported) << A->getAsString(Args);
+return llvm::CSKY::FK_INVALID;
+  }
+
+  auto RemoveTargetFPUFeature =
+  [&Features](ArrayRef FPUFeatures) {
+for (auto FPUFeature : FPUFeatures) {
+  auto it = std::find(Features.begin(), Features.end(), FPUFeature);
+  if (it != Features.end())
+Features.erase(it);
+}
+  };
+
+  RemoveTargetFPUFeature({"+fpuv2_sf", "+fpuv2_df", "+fdivdu", "+fpuv3_hi",
+  "+fpuv3_hf", "+fpuv3_sf", "+fpuv3_df"});
 
   if (!llvm::CSKY::getFPUFeatures(FPUID, Features)) {
 D.Diag(clang::diag::err_drv_clang_unsupported) << A->getAsString(Args);
@@ -126,6 +142,8 @@ void csky::getCSKYTargetFeatures(const Driver &D, const 
llvm::Triple &Triple,
   return;
 }
 cpuNa

[clang] 55c2137 - [testcase][OpenMP] Fix the testcase error of check-all when DCLANG_DEFAULT_OPENMP_RUNTIME is not libomp

2022-10-19 Thread Zi Xuan Wu via cfe-commits

Author: Zi Xuan Wu (Zeson)
Date: 2022-10-20T10:19:37+08:00
New Revision: 55c2137939d8e12c064cedcda21108c239dddf8e

URL: 
https://github.com/llvm/llvm-project/commit/55c2137939d8e12c064cedcda21108c239dddf8e
DIFF: 
https://github.com/llvm/llvm-project/commit/55c2137939d8e12c064cedcda21108c239dddf8e.diff

LOG: [testcase][OpenMP] Fix the testcase error of check-all when 
DCLANG_DEFAULT_OPENMP_RUNTIME is not libomp

When DCLANG_DEFAULT_OPENMP_RUNTIME is set to libgomp, there is some check-all 
error.
The expected CHECK result only displays when fopenmp=libomp is specified 
explicitly.

Differential Revision: https://reviews.llvm.org/D136239

Added: 


Modified: 
clang/test/Driver/fopenmp.c
clang/test/Index/openmp-tile.c

Removed: 




diff  --git a/clang/test/Driver/fopenmp.c b/clang/test/Driver/fopenmp.c
index aadade101125e..6e31de109912b 100644
--- a/clang/test/Driver/fopenmp.c
+++ b/clang/test/Driver/fopenmp.c
@@ -140,7 +140,7 @@
 // CHECK-LD-STATIC-IOMP5-NO-BDYNAMIC: "-{{B?}}static" {{.*}} "-liomp5"
 // CHECK-LD-STATIC-IOMP5-NO-BDYNAMIC-NOT: "-Bdynamic"
 //
-// RUN: %clang -target x86_64-linux-gnu -fopenmp -fopenmp-enable-irbuilder -c 
%s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CC1-OPENMPIRBUILDER
+// RUN: %clang -target x86_64-linux-gnu -fopenmp=libomp 
-fopenmp-enable-irbuilder -c %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-CC1-OPENMPIRBUILDER
 //
 // CHECK-CC1-OPENMPIRBUILDER: "-cc1"
 // CHECK-CC1-OPENMPIRBUILDER-SAME: "-fopenmp"

diff  --git a/clang/test/Index/openmp-tile.c b/clang/test/Index/openmp-tile.c
index a51bc82c228b1..a9e379e0a4b6c 100644
--- a/clang/test/Index/openmp-tile.c
+++ b/clang/test/Index/openmp-tile.c
@@ -1,4 +1,4 @@
-// RUN: c-index-test -test-load-source local %s -fopenmp -fopenmp-version=51 | 
FileCheck %s
+// RUN: c-index-test -test-load-source local %s -fopenmp=libomp 
-fopenmp-version=51 | FileCheck %s
 
 void test() {
 #pragma omp tile sizes(5)



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


[clang] 563cc3f - [Clang][CSKY] Add support about CSKYABIInfo

2022-05-30 Thread Zi Xuan Wu via cfe-commits

Author: Zi Xuan Wu (Zeson)
Date: 2022-05-31T10:53:30+08:00
New Revision: 563cc3fda9a2a35582d274e1d2d66687ecf2fc77

URL: 
https://github.com/llvm/llvm-project/commit/563cc3fda9a2a35582d274e1d2d66687ecf2fc77
DIFF: 
https://github.com/llvm/llvm-project/commit/563cc3fda9a2a35582d274e1d2d66687ecf2fc77.diff

LOG: [Clang][CSKY] Add support about CSKYABIInfo

According to the CSKY ABIv2 document, 
https://github.com/c-sky/csky-doc/blob/master/C-SKY_V2_CPU_Applications_Binary_Interface_Standards_Manual.pdf
construct the ABIInfo to handle argument passing and return of clang data type. 
It also includes how to emit and expand VAArg intrinsic.

Differential Revision: https://reviews.llvm.org/D126451

Added: 
clang/test/CodeGen/CSKY/csky-abi.c
clang/test/CodeGen/CSKY/csky-hard-abi.c
clang/test/CodeGen/CSKY/csky-soft-abi.c

Modified: 
clang/lib/CodeGen/TargetInfo.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/TargetInfo.cpp 
b/clang/lib/CodeGen/TargetInfo.cpp
index ecbb3505bb91c..4b7b301594d77 100644
--- a/clang/lib/CodeGen/TargetInfo.cpp
+++ b/clang/lib/CodeGen/TargetInfo.cpp
@@ -11325,6 +11325,165 @@ class VETargetCodeGenInfo : public TargetCodeGenInfo {
 };
 } // end anonymous namespace
 
+//===--===//
+// CSKY ABI Implementation
+//===--===//
+namespace {
+class CSKYABIInfo : public DefaultABIInfo {
+  static const int NumArgGPRs = 4;
+  static const int NumArgFPRs = 4;
+
+  static const unsigned XLen = 32;
+  unsigned FLen;
+
+public:
+  CSKYABIInfo(CodeGen::CodeGenTypes &CGT, unsigned FLen)
+  : DefaultABIInfo(CGT), FLen(FLen) {}
+
+  void computeInfo(CGFunctionInfo &FI) const override;
+  ABIArgInfo classifyArgumentType(QualType Ty, int &ArgGPRsLeft,
+  int &ArgFPRsLeft,
+  bool isReturnType = false) const;
+  ABIArgInfo classifyReturnType(QualType RetTy) const;
+
+  Address EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
+QualType Ty) const override;
+};
+
+} // end anonymous namespace
+
+void CSKYABIInfo::computeInfo(CGFunctionInfo &FI) const {
+  QualType RetTy = FI.getReturnType();
+  if (!getCXXABI().classifyReturnType(FI))
+FI.getReturnInfo() = classifyReturnType(RetTy);
+
+  bool IsRetIndirect = FI.getReturnInfo().getKind() == ABIArgInfo::Indirect;
+
+  // We must track the number of GPRs used in order to conform to the CSKY
+  // ABI, as integer scalars passed in registers should have signext/zeroext
+  // when promoted.
+  int ArgGPRsLeft = IsRetIndirect ? NumArgGPRs - 1 : NumArgGPRs;
+  int ArgFPRsLeft = FLen ? NumArgFPRs : 0;
+
+  for (auto &ArgInfo : FI.arguments()) {
+ArgInfo.info = classifyArgumentType(ArgInfo.type, ArgGPRsLeft, 
ArgFPRsLeft);
+  }
+}
+
+Address CSKYABIInfo::EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
+   QualType Ty) const {
+  CharUnits SlotSize = CharUnits::fromQuantity(XLen / 8);
+
+  // Empty records are ignored for parameter passing purposes.
+  if (isEmptyRecord(getContext(), Ty, true)) {
+Address Addr = Address(CGF.Builder.CreateLoad(VAListAddr),
+   getVAListElementType(CGF), SlotSize);
+Addr = CGF.Builder.CreateElementBitCast(Addr, CGF.ConvertTypeForMem(Ty));
+return Addr;
+  }
+
+  auto TInfo = getContext().getTypeInfoInChars(Ty);
+
+  return emitVoidPtrVAArg(CGF, VAListAddr, Ty, false, TInfo, SlotSize,
+  /*AllowHigherAlign=*/true);
+}
+
+ABIArgInfo CSKYABIInfo::classifyArgumentType(QualType Ty, int &ArgGPRsLeft,
+ int &ArgFPRsLeft,
+ bool isReturnType) const {
+  assert(ArgGPRsLeft <= NumArgGPRs && "Arg GPR tracking underflow");
+  Ty = useFirstFieldIfTransparentUnion(Ty);
+
+  // Structures with either a non-trivial destructor or a non-trivial
+  // copy constructor are always passed indirectly.
+  if (CGCXXABI::RecordArgABI RAA = getRecordArgABI(Ty, getCXXABI())) {
+if (ArgGPRsLeft)
+  ArgGPRsLeft -= 1;
+return getNaturalAlignIndirect(Ty, /*ByVal=*/RAA ==
+   CGCXXABI::RAA_DirectInMemory);
+  }
+
+  // Ignore empty structs/unions.
+  if (isEmptyRecord(getContext(), Ty, true))
+return ABIArgInfo::getIgnore();
+
+  if (!Ty->getAsUnionType())
+if (const Type *SeltTy = isSingleElementStruct(Ty, getContext()))
+  return ABIArgInfo::getDirect(CGT.ConvertType(QualType(SeltTy, 0)));
+
+  uint64_t Size = getContext().getTypeSize(Ty);
+  // Pass floating point values via FPRs if possible.
+  if (Ty->isFloatingType() && !Ty->isComplexType() && FLen >= Size &&
+  ArgFPRsLeft) {
+ArgFPRsLeft--;
+return ABIArgInfo::getDirect();
+  }
+
+  // Complex types for the hard float ABI must be passed

[clang] [CSKY] Default to unsigned char (PR #115961)

2025-02-07 Thread Zi Xuan Wu via cfe-commits

https://github.com/zixuan-wu approved this pull request.

LGTM. But I think commit msg should be refined(this PR is not for upstreaming?)

https://github.com/llvm/llvm-project/pull/115961
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [CSKY] Default to unsigned char (PR #115961)

2025-02-07 Thread Zi Xuan Wu via cfe-commits

zixuan-wu wrote:

LGTM.  But I think commit msg should be refined(this PR is not for upstreaming?)

https://github.com/llvm/llvm-project/pull/115961
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits