simoll updated this revision to Diff 233328.
simoll added a comment.

Trimmed down to library changes only.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71340

Files:
  compiler-rt/cmake/Modules/CompilerRTUtils.cmake
  compiler-rt/cmake/base-config-ix.cmake
  compiler-rt/cmake/builtin-config-ix.cmake
  compiler-rt/cmake/config-ix.cmake
  compiler-rt/lib/builtins/CMakeLists.txt
  compiler-rt/lib/builtins/ve/llvm_grow_stack.S
  libcxx/src/filesystem/operations.cpp
  libcxxabi/cmake/config-ix.cmake
  libunwind/include/__libunwind_config.h
  libunwind/include/libunwind.h
  libunwind/src/Registers.hpp
  libunwind/src/Unwind-sjlj.c
  libunwind/src/libunwind.cpp
  openmp/CMakeLists.txt
  openmp/libomptarget/cmake/Modules/LibomptargetGetDependencies.cmake
  openmp/runtime/CMakeLists.txt
  openmp/runtime/cmake/LibompUtils.cmake
  openmp/runtime/src/kmp.h
  openmp/runtime/src/kmp_affinity.h
  openmp/runtime/src/kmp_csupport.cpp
  openmp/runtime/src/kmp_os.h
  openmp/runtime/src/kmp_platform.h
  openmp/runtime/src/kmp_runtime.cpp
  openmp/runtime/src/thirdparty/ittnotify/ittnotify_config.h
  openmp/runtime/src/z_Linux_asm.S

Index: openmp/runtime/src/z_Linux_asm.S
===================================================================
--- openmp/runtime/src/z_Linux_asm.S
+++ openmp/runtime/src/z_Linux_asm.S
@@ -1741,7 +1741,7 @@
     .size __kmp_unnamed_critical_addr,4
 #endif /* KMP_ARCH_ARM */
 
-#if KMP_ARCH_PPC64 || KMP_ARCH_AARCH64 || KMP_ARCH_MIPS64 || KMP_ARCH_RISCV64
+#if KMP_ARCH_PPC64 || KMP_ARCH_AARCH64 || KMP_ARCH_MIPS64 || KMP_ARCH_RISCV64 || KMP_ARCH_VE
     .data
     .comm .gomp_critical_user_,32,8
     .data
Index: openmp/runtime/src/thirdparty/ittnotify/ittnotify_config.h
===================================================================
--- openmp/runtime/src/thirdparty/ittnotify/ittnotify_config.h
+++ openmp/runtime/src/thirdparty/ittnotify/ittnotify_config.h
@@ -165,6 +165,10 @@
 #  define ITT_ARCH_RISCV64  7
 #endif /* ITT_ARCH_RISCV64 */
 
+#ifndef ITT_ARCH_VE
+#  define ITT_ARCH_VE  8
+#endif /* ITT_ARCH_VE */
+
 #ifndef ITT_ARCH
 #  if defined _M_IX86 || defined __i386__
 #    define ITT_ARCH ITT_ARCH_IA32
@@ -184,6 +188,8 @@
 #    define ITT_ARCH ITT_ARCH_MIPS64
 #  elif defined __riscv && __riscv_xlen == 64
 #    define ITT_ARCH ITT_ARCH_RISCV64
+#  elif defined __ve__
+#    define ITT_ARCH ITT_ARCH_VE
 #  endif
 #endif
 
@@ -338,7 +344,8 @@
 }
 #elif ITT_ARCH == ITT_ARCH_ARM || ITT_ARCH == ITT_ARCH_PPC64 ||                \
     ITT_ARCH == ITT_ARCH_AARCH64 || ITT_ARCH == ITT_ARCH_MIPS ||               \
-    ITT_ARCH == ITT_ARCH_MIPS64 || ITT_ARCH == ITT_ARCH_RISCV64
+    ITT_ARCH == ITT_ARCH_MIPS64 || ITT_ARCH == ITT_ARCH_RISCV64 ||             \
+    ITT_ARCH == ITT_ARCH_VE
 #define __TBB_machine_fetchadd4(addr, val) __sync_fetch_and_add(addr, val)
 #endif /* ITT_ARCH==ITT_ARCH_IA64 */
 #ifndef ITT_SIMPLE_INIT
Index: openmp/runtime/src/kmp_runtime.cpp
===================================================================
--- openmp/runtime/src/kmp_runtime.cpp
+++ openmp/runtime/src/kmp_runtime.cpp
@@ -8105,7 +8105,7 @@
     int atomic_available = FAST_REDUCTION_ATOMIC_METHOD_GENERATED;
 
 #if KMP_ARCH_X86_64 || KMP_ARCH_PPC64 || KMP_ARCH_AARCH64 ||                   \
-    KMP_ARCH_MIPS64 || KMP_ARCH_RISCV64
+    KMP_ARCH_MIPS64 || KMP_ARCH_RISCV64 || KMP_ARCH_VE
 
 #if KMP_OS_LINUX || KMP_OS_DRAGONFLY || KMP_OS_FREEBSD || KMP_OS_NETBSD ||     \
     KMP_OS_OPENBSD || KMP_OS_WINDOWS || KMP_OS_DARWIN || KMP_OS_HURD
Index: openmp/runtime/src/kmp_platform.h
===================================================================
--- openmp/runtime/src/kmp_platform.h
+++ openmp/runtime/src/kmp_platform.h
@@ -99,6 +99,7 @@
 #define KMP_ARCH_MIPS 0
 #define KMP_ARCH_MIPS64 0
 #define KMP_ARCH_RISCV64 0
+#define KMP_ARCH_VE 0
 
 #if KMP_OS_WINDOWS
 #if defined(_M_AMD64) || defined(__x86_64)
@@ -139,6 +140,9 @@
 #elif defined __riscv && __riscv_xlen == 64
 #undef KMP_ARCH_RISCV64
 #define KMP_ARCH_RISCV64 1
+#elif defined __ve__
+#undef KMP_ARCH_VE
+#define KMP_ARCH_VE 1
 #endif
 #endif
 
@@ -203,7 +207,8 @@
 // TODO: Fixme - This is clever, but really fugly
 #if (1 !=                                                                      \
      KMP_ARCH_X86 + KMP_ARCH_X86_64 + KMP_ARCH_ARM + KMP_ARCH_PPC64 +          \
-     KMP_ARCH_AARCH64 + KMP_ARCH_MIPS + KMP_ARCH_MIPS64 + KMP_ARCH_RISCV64)
+     KMP_ARCH_AARCH64 + KMP_ARCH_MIPS + KMP_ARCH_MIPS64 + KMP_ARCH_RISCV64 +   \
+     KMP_ARCH_VE)
 #error Unknown or unsupported architecture
 #endif
 
Index: openmp/runtime/src/kmp_os.h
===================================================================
--- openmp/runtime/src/kmp_os.h
+++ openmp/runtime/src/kmp_os.h
@@ -166,7 +166,7 @@
 #if KMP_ARCH_X86 || KMP_ARCH_ARM || KMP_ARCH_MIPS
 #define KMP_SIZE_T_SPEC KMP_UINT32_SPEC
 #elif KMP_ARCH_X86_64 || KMP_ARCH_PPC64 || KMP_ARCH_AARCH64 ||                 \
-    KMP_ARCH_MIPS64 || KMP_ARCH_RISCV64
+    KMP_ARCH_MIPS64 || KMP_ARCH_RISCV64 || KMP_ARCH_VE
 #define KMP_SIZE_T_SPEC KMP_UINT64_SPEC
 #else
 #error "Can't determine size_t printf format specifier."
@@ -841,7 +841,7 @@
 #endif /* KMP_OS_WINDOWS */
 
 #if KMP_ARCH_PPC64 || KMP_ARCH_ARM || KMP_ARCH_AARCH64 || KMP_ARCH_MIPS ||     \
-    KMP_ARCH_MIPS64 || KMP_ARCH_RISCV64
+    KMP_ARCH_MIPS64 || KMP_ARCH_RISCV64 || KMP_ARCH_VE
 #define KMP_MB() __sync_synchronize()
 #endif
 
Index: openmp/runtime/src/kmp_csupport.cpp
===================================================================
--- openmp/runtime/src/kmp_csupport.cpp
+++ openmp/runtime/src/kmp_csupport.cpp
@@ -678,7 +678,7 @@
   }
 #endif // KMP_MIC
 #elif (KMP_ARCH_ARM || KMP_ARCH_AARCH64 || KMP_ARCH_MIPS || KMP_ARCH_MIPS64 || \
-       KMP_ARCH_RISCV64)
+       KMP_ARCH_RISCV64 || KMP_ARCH_VE)
 // Nothing to see here move along
 #elif KMP_ARCH_PPC64
 // Nothing needed here (we have a real MB above).
Index: openmp/runtime/src/kmp_affinity.h
===================================================================
--- openmp/runtime/src/kmp_affinity.h
+++ openmp/runtime/src/kmp_affinity.h
@@ -233,6 +233,18 @@
 #elif __NR_sched_getaffinity != 5196
 #error Wrong code for getaffinity system call.
 #endif /* __NR_sched_getaffinity */
+#elif KMP_ARCH_VE
+#ifndef __NR_sched_setaffinity
+#define __NR_sched_setaffinity 203
+#elif __NR_sched_setaffinity != 203
+#error Wrong code for setaffinity system call.
+#endif /* __NR_sched_setaffinity */
+#ifndef __NR_sched_getaffinity
+#define __NR_sched_getaffinity 204
+#elif __NR_sched_getaffinity != 204
+#error Wrong code for getaffinity system call.
+#endif /* __NR_sched_getaffinity */
+#else
 #error Unknown or unsupported architecture
 #endif /* KMP_ARCH_* */
 #elif KMP_OS_FREEBSD
Index: openmp/runtime/src/kmp.h
===================================================================
--- openmp/runtime/src/kmp.h
+++ openmp/runtime/src/kmp.h
@@ -987,6 +987,9 @@
 #elif KMP_ARCH_X86_64
 #define KMP_DEFAULT_STKSIZE ((size_t)(4 * 1024 * 1024))
 #define KMP_BACKUP_STKSIZE ((size_t)(2 * 1024 * 1024))
+#elif KMP_ARCH_VE
+// Minimum stack size for pthread for VE is 4MB.
+#define KMP_DEFAULT_STKSIZE ((size_t)(4 * 1024 * 1024))
 #else
 #define KMP_DEFAULT_STKSIZE ((size_t)(1024 * 1024))
 #endif
Index: openmp/runtime/cmake/LibompUtils.cmake
===================================================================
--- openmp/runtime/cmake/LibompUtils.cmake
+++ openmp/runtime/cmake/LibompUtils.cmake
@@ -107,6 +107,8 @@
     set(${return_arch_string} "MIPS64" PARENT_SCOPE)
   elseif(${RISCV64})
     set(${return_arch_string} "RISCV64" PARENT_SCOPE)
+  elseif(${VE})
+    set(${return_arch_string} "VE" PARENT_SCOPE)
   else()
     set(${return_arch_string} "${LIBOMP_ARCH}" PARENT_SCOPE)
     libomp_warning_say("libomp_get_legal_arch(): Warning: Unknown architecture: Using ${LIBOMP_ARCH}")
Index: openmp/runtime/CMakeLists.txt
===================================================================
--- openmp/runtime/CMakeLists.txt
+++ openmp/runtime/CMakeLists.txt
@@ -30,7 +30,7 @@
   # If adding a new architecture, take a look at cmake/LibompGetArchitecture.cmake
   libomp_get_architecture(LIBOMP_DETECTED_ARCH)
   set(LIBOMP_ARCH ${LIBOMP_DETECTED_ARCH} CACHE STRING
-    "The architecture to build for (x86_64/i386/arm/ppc64/ppc64le/aarch64/mic/mips/mips64/riscv64).")
+    "The architecture to build for (x86_64/i386/arm/ppc64/ppc64le/aarch64/mic/mips/mips64/riscv64/ve).")
   # Should assertions be enabled?  They are on by default.
   set(LIBOMP_ENABLE_ASSERTIONS TRUE CACHE BOOL
     "enable assertions?")
@@ -60,13 +60,15 @@
     set(LIBOMP_ARCH arm)
   elseif(LIBOMP_NATIVE_ARCH MATCHES "riscv64")
     set(LIBOMP_ARCH riscv64)
+  elseif(LIBOMP_NATIVE_ARCH MATCHES "ve")
+    set(LIBOMP_ARCH ve)
   else()
     # last ditch effort
     libomp_get_architecture(LIBOMP_ARCH)
   endif ()
   set(LIBOMP_ENABLE_ASSERTIONS ${LLVM_ENABLE_ASSERTIONS})
 endif()
-libomp_check_variable(LIBOMP_ARCH 32e x86_64 32 i386 arm ppc64 ppc64le aarch64 mic mips mips64 riscv64)
+libomp_check_variable(LIBOMP_ARCH 32e x86_64 32 i386 arm ppc64 ppc64le aarch64 mic mips mips64 riscv64 ve)
 
 set(LIBOMP_LIB_TYPE normal CACHE STRING
   "Performance,Profiling,Stubs library (normal/profile/stubs)")
@@ -143,6 +145,7 @@
 set(MIPS64 FALSE)
 set(MIPS FALSE)
 set(RISCV64 FALSE)
+set(VE FALSE)
 if("${LIBOMP_ARCH}" STREQUAL "i386" OR "${LIBOMP_ARCH}" STREQUAL "32")    # IA-32 architecture
   set(IA32 TRUE)
 elseif("${LIBOMP_ARCH}" STREQUAL "x86_64" OR "${LIBOMP_ARCH}" STREQUAL "32e") # Intel(R) 64 architecture
@@ -165,6 +168,8 @@
     set(MIPS64 TRUE)
   elseif("${LIBOMP_ARCH}" STREQUAL "riscv64") # RISCV64 architecture
     set(RISCV64 TRUE)
+elseif("${LIBOMP_ARCH}" STREQUAL "ve") # VE architecture
+    set(VE TRUE)
 endif()
 
 # Set some flags based on build_type
Index: openmp/libomptarget/cmake/Modules/LibomptargetGetDependencies.cmake
===================================================================
--- openmp/libomptarget/cmake/Modules/LibomptargetGetDependencies.cmake
+++ openmp/libomptarget/cmake/Modules/LibomptargetGetDependencies.cmake
@@ -116,7 +116,12 @@
 endif()
 find_package(CUDA QUIET)
 
-set(LIBOMPTARGET_DEP_CUDA_FOUND ${CUDA_FOUND})
+if(NOT "${LIBOMP_ARCH}" STREQUAL "ve")
+  set(LIBOMPTARGET_DEP_CUDA_FOUND ${CUDA_FOUND})
+else(NOT "${LIBOMP_ARCH}" STREQUAL "ve")
+  # force to not compile CUDA libomptarget while compiling native VE libomp
+  set(LIBOMPTARGET_DEP_CUDA_FOUND "FALSE")
+endif(NOT "${LIBOMP_ARCH}" STREQUAL "ve")
 set(LIBOMPTARGET_DEP_CUDA_INCLUDE_DIRS ${CUDA_INCLUDE_DIRS})
 
 mark_as_advanced(
Index: openmp/CMakeLists.txt
===================================================================
--- openmp/CMakeLists.txt
+++ openmp/CMakeLists.txt
@@ -62,7 +62,8 @@
 # Currently libomptarget cannot be compiled on Windows or MacOS X.
 # Since the device plugins are only supported on Linux anyway,
 # there is no point in trying to compile libomptarget on other OSes.
-if (APPLE OR WIN32 OR NOT OPENMP_HAVE_STD_CPP11_FLAG)
+# Disable libomptarget on VE also since it doesn't work at the moment.
+if (APPLE OR WIN32 OR ("${LIBOMP_ARCH}" STREQUAL "ve") OR NOT OPENMP_HAVE_STD_CPP11_FLAG)
   set(ENABLE_LIBOMPTARGET OFF)
 endif()
 
Index: libunwind/src/libunwind.cpp
===================================================================
--- libunwind/src/libunwind.cpp
+++ libunwind/src/libunwind.cpp
@@ -58,6 +58,9 @@
 # warning The MIPS architecture is not supported with this ABI and environment!
 #elif defined(__sparc__)
 # define REGISTER_KIND Registers_sparc
+#elif defined(__ve__)
+# warning The VE architecture is not supported with this ABI and environment!
+# define REGISTER_KIND Registers_ve
 #else
 # error Architecture not supported
 #endif
Index: libunwind/src/Unwind-sjlj.c
===================================================================
--- libunwind/src/Unwind-sjlj.c
+++ libunwind/src/Unwind-sjlj.c
@@ -32,11 +32,21 @@
   // next function in stack of handlers
   struct _Unwind_FunctionContext *prev;
 
+#if defined(__ve__)
+  // VE requires to store 64 bit pointers as a part of these data.
+
+  // set by calling function before registering to be the landing pad
+  uintptr_t                       resumeLocation;
+
+  // set by personality handler to be parameters passed to landing pad function
+  uintptr_t                       resumeParameters[4];
+#else
   // set by calling function before registering to be the landing pad
   uint32_t                        resumeLocation;
 
   // set by personality handler to be parameters passed to landing pad function
   uint32_t                        resumeParameters[4];
+#endif
 
   // set by calling function before registering
   __personality_routine           personality; // arm offset=24
Index: libunwind/src/Registers.hpp
===================================================================
--- libunwind/src/Registers.hpp
+++ libunwind/src/Registers.hpp
@@ -3517,6 +3517,290 @@
 }
 #endif // _LIBUNWIND_TARGET_SPARC
 
+#if defined(_LIBUNWIND_TARGET_VE)
+/// Registers_ve holds the register state of a thread in a VE process.
+class _LIBUNWIND_HIDDEN Registers_ve {
+public:
+  Registers_ve();
+  Registers_ve(const void *registers);
+
+  bool        validRegister(int num) const;
+  uint64_t    getRegister(int num) const;
+  void        setRegister(int num, uint64_t value);
+  bool        validFloatRegister(int num) const;
+  double      getFloatRegister(int num) const;
+  void        setFloatRegister(int num, double value);
+  bool        validVectorRegister(int num) const;
+  v128        getVectorRegister(int num) const;
+  void        setVectorRegister(int num, v128 value);
+  const char *getRegisterName(int num);
+  void        jumpto();
+  static int  lastDwarfRegNum() { return _LIBUNWIND_HIGHEST_DWARF_REGISTER_VE; }
+
+  uint64_t  getSP() const         { return _registers.__s[11]; }
+  void      setSP(uint64_t value) { _registers.__s[11] = value; }
+  uint64_t  getIP() const         { return _registers.__ic; }
+  void      setIP(uint64_t value) { _registers.__ic = value; }
+
+private:
+  struct ve_thread_state_t {
+    uint64_t __s[64];   // s0-s64
+    uint64_t __ic;      // Instruction counter (IC)
+    uint64_t __vixr;    // Vector Index Register
+    uint64_t __vl;      // Vector Length Register
+  };
+
+  ve_thread_state_t _registers; // total 67 registers
+
+  // Currently no vector registers is preserved since libunwind
+  // supports only 128-bit vector registers.
+
+  static int getScalarRegNum(int num);
+};
+
+inline Registers_ve::Registers_ve(const void *registers) {
+  static_assert((check_fit<Registers_ve, unw_context_t>::does_fit),
+                "ve registers do not fit into unw_context_t");
+  memcpy(&_registers, static_cast<const uint8_t *>(registers),
+         sizeof(_registers));
+  static_assert(sizeof(_registers) == 536,
+                "expected vector register offset to be 536");
+}
+
+inline Registers_ve::Registers_ve() {
+  memset(&_registers, 0, sizeof(_registers));
+}
+
+inline bool Registers_ve::validRegister(int regNum) const {
+  if (regNum >= UNW_VE_S0 && regNum <= UNW_VE_S63)
+    return true;
+
+  switch (regNum) {
+  case UNW_REG_IP:
+  case UNW_REG_SP:
+  case UNW_VE_VIXR:
+  case UNW_VE_VL:
+    return true;
+  default:
+    return false;
+  }
+}
+
+inline int Registers_ve::getScalarRegNum(int num)
+{
+  if (num >= UNW_VE_S0 && num <= UNW_VE_S63)
+    return num - UNW_VE_S0;
+  return 0;
+}
+
+inline uint64_t Registers_ve::getRegister(int regNum) const {
+  if (num >= UNW_VE_S0 && num <= UNW_VE_S63)
+    return _registers.__s[getScalarRegNum(regNum)];
+
+  switch (regNum) {
+  case UNW_REG_IP:
+    return _registers.__ic;
+  case UNW_REG_SP:
+    return _registers.__s[11];
+  case UNW_VE_VIXR:
+    return _registers.__vixr;
+  case UNW_VE_VL:
+    return _registers.__vl;
+  }
+  _LIBUNWIND_ABORT("unsupported ve register");
+}
+
+inline void Registers_ve::setRegister(int regNum, uint64_t value) {
+  if (num >= UNW_VE_S0 && num <= UNW_VE_S63) {
+    _registers.__s[getScalarRegNum(regNum)] = value;
+    return;
+  }
+
+  switch (regNum) {
+  case UNW_REG_IP:
+    _registers.__ic = value;
+    return;
+  case UNW_REG_SP:
+    _registers.__s[11] = value;
+    return;
+  case UNW_VE_VIXR:
+    _registers.__vixr = value;
+    return;
+  case UNW_VE_VL:
+    _registers.__vl = value;
+    return;
+  }
+  _LIBUNWIND_ABORT("unsupported ve register");
+}
+
+inline bool Registers_ve::validFloatRegister(int /* regNum */) const {
+  return false;
+}
+
+inline double Registers_ve::getFloatRegister(int /* regNum */) const {
+  _LIBUNWIND_ABORT("VE float support not implemented");
+}
+
+inline void Registers_ve::setFloatRegister(int /* regNum */,
+                                           double /* value */) {
+  _LIBUNWIND_ABORT("VE float support not implemented");
+}
+
+inline bool Registers_ve::validVectorRegister(int /* regNum */) const {
+  return false;
+}
+
+inline v128 Registers_ve::getVectorRegister(int /* regNum */) const {
+  _LIBUNWIND_ABORT("VE vector support not implemented");
+}
+
+inline void Registers_ve::setVectorRegister(int /* regNum */, v128 /* value */) {
+  _LIBUNWIND_ABORT("VE vector support not implemented");
+}
+
+inline const char *Registers_ve::getRegisterName(int regNum) {
+  switch (regNum) {
+  case UNW_REG_IP:
+    return "ip";
+  case UNW_REG_SP:
+    return "sp";
+  case UNW_VE_VIXR:
+    return "vixr";
+  case UNW_VE_VL:
+    return "vl";
+  case UNW_VE_S0:
+    return "s0";
+  case UNW_VE_S1:
+    return "s1";
+  case UNW_VE_S2:
+    return "s2";
+  case UNW_VE_S3:
+    return "s3";
+  case UNW_VE_S4:
+    return "s4";
+  case UNW_VE_S5:
+    return "s5";
+  case UNW_VE_S6:
+    return "s6";
+  case UNW_VE_S7:
+    return "s7";
+  case UNW_VE_S8:
+    return "s8";
+  case UNW_VE_S9:
+    return "s9";
+  case UNW_VE_S10:
+    return "s10";
+  case UNW_VE_S11:
+    return "s11";
+  case UNW_VE_S12:
+    return "s12";
+  case UNW_VE_S13:
+    return "s13";
+  case UNW_VE_S14:
+    return "s14";
+  case UNW_VE_S15:
+    return "s15";
+  case UNW_VE_S16:
+    return "s16";
+  case UNW_VE_S17:
+    return "s17";
+  case UNW_VE_S18:
+    return "s18";
+  case UNW_VE_S19:
+    return "s19";
+  case UNW_VE_S20:
+    return "s20";
+  case UNW_VE_S21:
+    return "s21";
+  case UNW_VE_S22:
+    return "s22";
+  case UNW_VE_S23:
+    return "s23";
+  case UNW_VE_S24:
+    return "s24";
+  case UNW_VE_S25:
+    return "s25";
+  case UNW_VE_S26:
+    return "s26";
+  case UNW_VE_S27:
+    return "s27";
+  case UNW_VE_S28:
+    return "s28";
+  case UNW_VE_S29:
+    return "s29";
+  case UNW_VE_S30:
+    return "s30";
+  case UNW_VE_S31:
+    return "s31";
+  case UNW_VE_S32:
+    return "s32";
+  case UNW_VE_S33:
+    return "s33";
+  case UNW_VE_S34:
+    return "s34";
+  case UNW_VE_S35:
+    return "s35";
+  case UNW_VE_S36:
+    return "s36";
+  case UNW_VE_S37:
+    return "s37";
+  case UNW_VE_S38:
+    return "s38";
+  case UNW_VE_S39:
+    return "s39";
+  case UNW_VE_S40:
+    return "s40";
+  case UNW_VE_S41:
+    return "s41";
+  case UNW_VE_S42:
+    return "s42";
+  case UNW_VE_S43:
+    return "s43";
+  case UNW_VE_S44:
+    return "s44";
+  case UNW_VE_S45:
+    return "s45";
+  case UNW_VE_S46:
+    return "s46";
+  case UNW_VE_S47:
+    return "s47";
+  case UNW_VE_S48:
+    return "s48";
+  case UNW_VE_S49:
+    return "s49";
+  case UNW_VE_S50:
+    return "s50";
+  case UNW_VE_S51:
+    return "s51";
+  case UNW_VE_S52:
+    return "s52";
+  case UNW_VE_S53:
+    return "s53";
+  case UNW_VE_S54:
+    return "s54";
+  case UNW_VE_S55:
+    return "s55";
+  case UNW_VE_S56:
+    return "s56";
+  case UNW_VE_S57:
+    return "s57";
+  case UNW_VE_S58:
+    return "s58";
+  case UNW_VE_S59:
+    return "s59";
+  case UNW_VE_S60:
+    return "s60";
+  case UNW_VE_S61:
+    return "s61";
+  case UNW_VE_S62:
+    return "s62";
+  case UNW_VE_S63:
+    return "s63";
+  }
+  return "unknown register";
+}
+#endif // _LIBUNWIND_TARGET_VE
+
 } // namespace libunwind
 
 #endif // __REGISTERS_HPP__
Index: libunwind/include/libunwind.h
===================================================================
--- libunwind/include/libunwind.h
+++ libunwind/include/libunwind.h
@@ -832,4 +832,75 @@
   UNW_SPARC_I7 = 31,
 };
 
+// VE register numbers
+enum {
+  UNW_VE_S0      = 0,
+  UNW_VE_S1      = 1,
+  UNW_VE_S2      = 2,
+  UNW_VE_S3      = 3,
+  UNW_VE_S4      = 4,
+  UNW_VE_S5      = 5,
+  UNW_VE_S6      = 6,
+  UNW_VE_S7      = 7,
+  UNW_VE_S8      = 8,
+  UNW_VE_S9      = 9,
+  UNW_VE_S10     = 10,
+  UNW_VE_S11     = 11,
+  UNW_VE_S12     = 12,
+  UNW_VE_S13     = 13,
+  UNW_VE_S14     = 14,
+  UNW_VE_S15     = 15,
+  UNW_VE_S16     = 16,
+  UNW_VE_S17     = 17,
+  UNW_VE_S18     = 18,
+  UNW_VE_S19     = 19,
+  UNW_VE_S20     = 20,
+  UNW_VE_S21     = 21,
+  UNW_VE_S22     = 22,
+  UNW_VE_S23     = 23,
+  UNW_VE_S24     = 24,
+  UNW_VE_S25     = 25,
+  UNW_VE_S26     = 26,
+  UNW_VE_S27     = 27,
+  UNW_VE_S28     = 28,
+  UNW_VE_S29     = 29,
+  UNW_VE_S30     = 30,
+  UNW_VE_S31     = 31,
+  UNW_VE_S32     = 32,
+  UNW_VE_S33     = 33,
+  UNW_VE_S34     = 34,
+  UNW_VE_S35     = 35,
+  UNW_VE_S36     = 36,
+  UNW_VE_S37     = 37,
+  UNW_VE_S38     = 38,
+  UNW_VE_S39     = 39,
+  UNW_VE_S40     = 40,
+  UNW_VE_S41     = 41,
+  UNW_VE_S42     = 42,
+  UNW_VE_S43     = 43,
+  UNW_VE_S44     = 44,
+  UNW_VE_S45     = 45,
+  UNW_VE_S46     = 46,
+  UNW_VE_S47     = 47,
+  UNW_VE_S48     = 48,
+  UNW_VE_S49     = 49,
+  UNW_VE_S50     = 50,
+  UNW_VE_S51     = 51,
+  UNW_VE_S52     = 52,
+  UNW_VE_S53     = 53,
+  UNW_VE_S54     = 54,
+  UNW_VE_S55     = 55,
+  UNW_VE_S56     = 56,
+  UNW_VE_S57     = 57,
+  UNW_VE_S58     = 58,
+  UNW_VE_S59     = 59,
+  UNW_VE_S60     = 60,
+  UNW_VE_S61     = 61,
+  UNW_VE_S62     = 62,
+  UNW_VE_S63     = 63,
+
+  UNW_VE_VIXR    = 144,
+  UNW_VE_VL      = 145,
+};
+
 #endif
Index: libunwind/include/__libunwind_config.h
===================================================================
--- libunwind/include/__libunwind_config.h
+++ libunwind/include/__libunwind_config.h
@@ -23,6 +23,7 @@
 #define _LIBUNWIND_HIGHEST_DWARF_REGISTER_OR1K      32
 #define _LIBUNWIND_HIGHEST_DWARF_REGISTER_MIPS      65
 #define _LIBUNWIND_HIGHEST_DWARF_REGISTER_SPARC     31
+#define _LIBUNWIND_HIGHEST_DWARF_REGISTER_VE        143
 
 #if defined(_LIBUNWIND_IS_NATIVE_ONLY)
 # if defined(__i386__)
@@ -118,6 +119,11 @@
   #define _LIBUNWIND_HIGHEST_DWARF_REGISTER _LIBUNWIND_HIGHEST_DWARF_REGISTER_SPARC
   #define _LIBUNWIND_CONTEXT_SIZE 16
   #define _LIBUNWIND_CURSOR_SIZE 23
+# elif defined(__ve__)
+#  define _LIBUNWIND_TARGET_VE
+#  define _LIBUNWIND_CONTEXT_SIZE 74
+#  define _LIBUNWIND_CURSOR_SIZE 15
+#  define _LIBUNWIND_HIGHEST_DWARF_REGISTER _LIBUNWIND_HIGHEST_DWARF_REGISTER_VE
 # else
 #  error "Unsupported architecture."
 # endif
Index: libcxxabi/cmake/config-ix.cmake
===================================================================
--- libcxxabi/cmake/config-ix.cmake
+++ libcxxabi/cmake/config-ix.cmake
@@ -27,6 +27,9 @@
     list(APPEND CMAKE_REQUIRED_FLAGS -rtlib=compiler-rt)
     find_compiler_rt_library(builtins LIBCXXABI_BUILTINS_LIBRARY)
     list(APPEND CMAKE_REQUIRED_LIBRARIES "${LIBCXXABI_BUILTINS_LIBRARY}")
+    # CMAKE_REQUIRED_LIBRARIES is not used to link libc++abi.so, so
+    # append builtins to LIBCXXABI_SHARED_LIBRARIES too
+    list(APPEND LIBCXXABI_SHARED_LIBRARIES "${LIBCXXABI_BUILTINS_LIBRARY}")
   else ()
     if (LIBCXXABI_HAS_GCC_S_LIB)
       list(APPEND CMAKE_REQUIRED_LIBRARIES gcc_s)
Index: libcxx/src/filesystem/operations.cpp
===================================================================
--- libcxx/src/filesystem/operations.cpp
+++ libcxx/src/filesystem/operations.cpp
@@ -26,11 +26,16 @@
 #include <fcntl.h> /* values for fchmodat */
 
 #if defined(__linux__)
+#if defined(__ve__)
+#include <sys/sendfile.h>
+#define _LIBCPP_USE_SENDFILE
+#else
 #include <linux/version.h>
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 33)
 #include <sys/sendfile.h>
 #define _LIBCPP_USE_SENDFILE
 #endif
+#endif
 #elif defined(__APPLE__) || __has_include(<copyfile.h>)
 #include <copyfile.h>
 #define _LIBCPP_USE_COPYFILE
Index: compiler-rt/lib/builtins/ve/llvm_grow_stack.S
===================================================================
--- /dev/null
+++ compiler-rt/lib/builtins/ve/llvm_grow_stack.S
@@ -0,0 +1,32 @@
+// 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
+
+#include "../assembly.h"
+
+// grow_stack routine
+// This routine is VE specific
+// https://www.nec.com/en/global/prod/hpc/aurora/document/VE-ABI_v1.1.pdf
+
+// destroy %s62 and %s63 only
+
+#ifdef __ve__
+
+.text
+.p2align        4
+DEFINE_COMPILERRT_FUNCTION(__llvm_grow_stack)
+        lea             %s62, 15(%s0)           # (s0 + 15) / 16 * 16
+        and             %s62, -16, %s62
+        subu.l          %sp, %sp, %s62          # sp -= alloca size
+        brge.l.t        %sp, %sl, 1f
+        ld              %s63, 0x18(,%tp)        # load param area
+        lea             %s62, 0x13b             # syscall # of grow
+        shm.l           %s62, 0x0(%s63)         # stored at addr:0
+        shm.l           %sl, 0x8(%s63)          # old limit at addr:8
+        shm.l           %sp, 0x10(%s63)         # new limit at addr:16
+        monc
+1:
+        b.l             (,%lr)
+END_COMPILERRT_FUNCTION(__llvm_grow_stack)
+
+#endif // __ve__
Index: compiler-rt/lib/builtins/CMakeLists.txt
===================================================================
--- compiler-rt/lib/builtins/CMakeLists.txt
+++ compiler-rt/lib/builtins/CMakeLists.txt
@@ -561,6 +561,11 @@
   ${GENERIC_SOURCES}
 )
 
+set(ve_SOURCES 
+  ve/llvm_grow_stack.S
+  ${GENERIC_TF_SOURCES}
+  ${GENERIC_SOURCES})
+
 add_custom_target(builtins)
 set_target_properties(builtins PROPERTIES FOLDER "Compiler-RT Misc")
 
Index: compiler-rt/cmake/config-ix.cmake
===================================================================
--- compiler-rt/cmake/config-ix.cmake
+++ compiler-rt/cmake/config-ix.cmake
@@ -250,6 +250,7 @@
 set(SPARCV9 sparcv9)
 set(WASM32 wasm32)
 set(WASM64 wasm64)
+set(VE ve)
 
 if(APPLE)
   set(ARM64 arm64)
@@ -261,7 +262,7 @@
     ${ARM32} ${ARM64} ${MIPS32} ${MIPS64} ${S390X} ${SPARC} ${SPARCV9})
 set(ALL_ASAN_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64}
     ${MIPS32} ${MIPS64} ${PPC64} ${S390X} ${SPARC} ${SPARCV9})
-set(ALL_CRT_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${RISCV32} ${RISCV64})
+set(ALL_CRT_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${RISCV32} ${RISCV64} ${VE})
 set(ALL_DFSAN_SUPPORTED_ARCH ${X86_64} ${MIPS64} ${ARM64})
 
 if(ANDROID)
Index: compiler-rt/cmake/builtin-config-ix.cmake
===================================================================
--- compiler-rt/cmake/builtin-config-ix.cmake
+++ compiler-rt/cmake/builtin-config-ix.cmake
@@ -37,6 +37,7 @@
 set(SPARCV9 sparcv9)
 set(WASM32 wasm32)
 set(WASM64 wasm64)
+set(VE ve)
 
 if(APPLE)
   set(ARM64 arm64)
@@ -45,7 +46,7 @@
 endif()
 
 set(ALL_BUILTIN_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64}
-    ${HEXAGON} ${MIPS32} ${MIPS64} ${PPC64} ${RISCV32} ${RISCV64} ${SPARC} ${SPARCV9} ${WASM32} ${WASM64})
+    ${HEXAGON} ${MIPS32} ${MIPS64} ${PPC64} ${RISCV32} ${RISCV64} ${SPARC} ${SPARCV9} ${WASM32} ${WASM64} ${VE})
 
 include(CompilerRTUtils)
 include(CompilerRTDarwinUtils)
Index: compiler-rt/cmake/base-config-ix.cmake
===================================================================
--- compiler-rt/cmake/base-config-ix.cmake
+++ compiler-rt/cmake/base-config-ix.cmake
@@ -236,6 +236,8 @@
       test_target_arch(wasm32 "" "--target=wasm32-unknown-unknown")
     elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "wasm64")
       test_target_arch(wasm64 "" "--target=wasm64-unknown-unknown")
+    elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "ve")
+      test_target_arch(ve "__ve__" "--target=ve-unknown-none")
     endif()
     set(COMPILER_RT_OS_SUFFIX "")
   endif()
Index: compiler-rt/cmake/Modules/CompilerRTUtils.cmake
===================================================================
--- compiler-rt/cmake/Modules/CompilerRTUtils.cmake
+++ compiler-rt/cmake/Modules/CompilerRTUtils.cmake
@@ -166,6 +166,7 @@
   check_symbol_exists(__sparcv9 "" __SPARCV9)
   check_symbol_exists(__wasm32__ "" __WEBASSEMBLY32)
   check_symbol_exists(__wasm64__ "" __WEBASSEMBLY64)
+  check_symbol_exists(__ve__ "" __VE)
   if(__ARM)
     add_default_target_arch(arm)
   elseif(__AARCH64)
@@ -200,6 +201,8 @@
     add_default_target_arch(wasm32)
   elseif(__WEBASSEMBLY64)
     add_default_target_arch(wasm64)
+  elseif(__VE)
+    add_default_target_arch(ve)
   endif()
 endmacro()
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to