kaz7 created this revision.
kaz7 added reviewers: simoll, efocht.
kaz7 added a project: clang.
Herald added a subscriber: mgorny.
Herald added a project: All.
kaz7 requested review of this revision.
Herald added a subscriber: cfe-commits.

Add vector load intrinsic instructions for VE.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D121049

Files:
  clang/include/clang/Basic/BuiltinsVE.def
  clang/include/clang/Basic/BuiltinsVEVL.gen.def
  clang/include/clang/Basic/TargetBuiltins.h
  clang/include/clang/module.modulemap
  clang/lib/Basic/Targets/VE.cpp
  clang/lib/Headers/CMakeLists.txt
  clang/lib/Headers/velintrin.h
  clang/lib/Headers/velintrin_gen.h
  clang/test/CodeGen/VE/ve-velintrin.c

Index: clang/test/CodeGen/VE/ve-velintrin.c
===================================================================
--- /dev/null
+++ clang/test/CodeGen/VE/ve-velintrin.c
@@ -0,0 +1,120 @@
+// REQUIRES: ve-registered-target
+
+// RUN: %clang_cc1 -S -emit-llvm -triple ve-unknown-linux-gnu \
+// RUN:   -ffreestanding %s -o - | FileCheck %s
+
+#include <velintrin.h>
+
+__vr vr1;
+
+void __attribute__((noinline))
+test_vld_vssl(char* p, long idx) {
+  // CHECK-LABEL: @test_vld_vssl
+  // CHECK: call <256 x double> @llvm.ve.vl.vld.vssl(i64 %{{.*}}, i8* %{{.*}}, i32 256)
+  vr1 = _vel_vld_vssl(idx, p, 256);
+}
+
+void __attribute__((noinline))
+test_vld_vssvl(char* p, long idx) {
+  // CHECK-LABEL: @test_vld_vssvl
+  // CHECK: call <256 x double> @llvm.ve.vl.vld.vssvl(i64 %{{.*}}, i8* %{{.*}}, <256 x double> %{{.*}}, i32 256)
+  vr1 = _vel_vld_vssvl(idx, p, vr1, 256);
+}
+
+void __attribute__((noinline))
+test_vldnc_vssl(char* p, long idx) {
+  // CHECK-LABEL: @test_vldnc_vssl
+  // CHECK: call <256 x double> @llvm.ve.vl.vldnc.vssl(i64 %{{.*}}, i8* %{{.*}}, i32 256)
+  vr1 = _vel_vldnc_vssl(idx, p, 256);
+}
+
+void __attribute__((noinline))
+test_vldnc_vssvl(char* p, long idx) {
+  // CHECK-LABEL: @test_vldnc_vssvl
+  // CHECK: call <256 x double> @llvm.ve.vl.vldnc.vssvl(i64 %{{.*}}, i8* %{{.*}}, <256 x double> %{{.*}}, i32 256)
+  vr1 = _vel_vldnc_vssvl(idx, p, vr1, 256);
+}
+
+void __attribute__((noinline))
+test_vldu_vssl(char* p, long idx) {
+  // CHECK-LABEL: @test_vldu_vssl
+  // CHECK: call <256 x double> @llvm.ve.vl.vldu.vssl(i64 %{{.*}}, i8* %{{.*}}, i32 256)
+  vr1 = _vel_vldu_vssl(idx, p, 256);
+}
+
+void __attribute__((noinline))
+test_vldu_vssvl(char* p, long idx) {
+  // CHECK-LABEL: @test_vldu_vssvl
+  // CHECK: call <256 x double> @llvm.ve.vl.vldu.vssvl(i64 %{{.*}}, i8* %{{.*}}, <256 x double> %{{.*}}, i32 256)
+  vr1 = _vel_vldu_vssvl(idx, p, vr1, 256);
+}
+
+void __attribute__((noinline))
+test_vldunc_vssl(char* p, long idx) {
+  // CHECK-LABEL: @test_vldunc_vssl
+  // CHECK: call <256 x double> @llvm.ve.vl.vldunc.vssl(i64 %{{.*}}, i8* %{{.*}}, i32 256)
+  vr1 = _vel_vldunc_vssl(idx, p, 256);
+}
+
+void __attribute__((noinline))
+test_vldunc_vssvl(char* p, long idx) {
+  // CHECK-LABEL: @test_vldunc_vssvl
+  // CHECK: call <256 x double> @llvm.ve.vl.vldunc.vssvl(i64 %{{.*}}, i8* %{{.*}}, <256 x double> %{{.*}}, i32 256)
+  vr1 = _vel_vldunc_vssvl(idx, p, vr1, 256);
+}
+
+void __attribute__((noinline))
+test_vldlsx_vssl(char* p, long idx) {
+  // CHECK-LABEL: @test_vldlsx_vssl
+  // CHECK: call <256 x double> @llvm.ve.vl.vldlsx.vssl(i64 %{{.*}}, i8* %{{.*}}, i32 256)
+  vr1 = _vel_vldlsx_vssl(idx, p, 256);
+}
+
+void __attribute__((noinline))
+test_vldlsx_vssvl(char* p, long idx) {
+  // CHECK-LABEL: @test_vldlsx_vssvl
+  // CHECK: call <256 x double> @llvm.ve.vl.vldlsx.vssvl(i64 %{{.*}}, i8* %{{.*}}, <256 x double> %{{.*}}, i32 256)
+  vr1 = _vel_vldlsx_vssvl(idx, p, vr1, 256);
+}
+
+void __attribute__((noinline))
+test_vldlsxnc_vssl(char* p, long idx) {
+  // CHECK-LABEL: @test_vldlsxnc_vssl
+  // CHECK: call <256 x double> @llvm.ve.vl.vldlsxnc.vssl(i64 %{{.*}}, i8* %{{.*}}, i32 256)
+  vr1 = _vel_vldlsxnc_vssl(idx, p, 256);
+}
+
+void __attribute__((noinline))
+test_vldlsxnc_vssvl(char* p, long idx) {
+  // CHECK-LABEL: @test_vldlsxnc_vssvl
+  // CHECK: call <256 x double> @llvm.ve.vl.vldlsxnc.vssvl(i64 %{{.*}}, i8* %{{.*}}, <256 x double> %{{.*}}, i32 256)
+  vr1 = _vel_vldlsxnc_vssvl(idx, p, vr1, 256);
+}
+
+void __attribute__((noinline))
+test_vldlzx_vssl(char* p, long idx) {
+  // CHECK-LABEL: @test_vldlzx_vssl
+  // CHECK: call <256 x double> @llvm.ve.vl.vldlzx.vssl(i64 %{{.*}}, i8* %{{.*}}, i32 256)
+  vr1 = _vel_vldlzx_vssl(idx, p, 256);
+}
+
+void __attribute__((noinline))
+test_vldlzx_vssvl(char* p, long idx) {
+  // CHECK-LABEL: @test_vldlzx_vssvl
+  // CHECK: call <256 x double> @llvm.ve.vl.vldlzx.vssvl(i64 %{{.*}}, i8* %{{.*}}, <256 x double> %{{.*}}, i32 256)
+  vr1 = _vel_vldlzx_vssvl(idx, p, vr1, 256);
+}
+
+void __attribute__((noinline))
+test_vldlzxnc_vssl(char* p, long idx) {
+  // CHECK-LABEL: @test_vldlzxnc_vssl
+  // CHECK: call <256 x double> @llvm.ve.vl.vldlzxnc.vssl(i64 %{{.*}}, i8* %{{.*}}, i32 256)
+  vr1 = _vel_vldlzxnc_vssl(idx, p, 256);
+}
+
+void __attribute__((noinline))
+test_vldlzxnc_vssvl(char* p, long idx) {
+  // CHECK-LABEL: @test_vldlzxnc_vssvl
+  // CHECK: call <256 x double> @llvm.ve.vl.vldlzxnc.vssvl(i64 %{{.*}}, i8* %{{.*}}, <256 x double> %{{.*}}, i32 256)
+  vr1 = _vel_vldlzxnc_vssvl(idx, p, vr1, 256);
+}
Index: clang/lib/Headers/velintrin_gen.h
===================================================================
--- /dev/null
+++ clang/lib/Headers/velintrin_gen.h
@@ -0,0 +1,16 @@
+#define _vel_vld_vssl __builtin_ve_vl_vld_vssl
+#define _vel_vld_vssvl __builtin_ve_vl_vld_vssvl
+#define _vel_vldnc_vssl __builtin_ve_vl_vldnc_vssl
+#define _vel_vldnc_vssvl __builtin_ve_vl_vldnc_vssvl
+#define _vel_vldu_vssl __builtin_ve_vl_vldu_vssl
+#define _vel_vldu_vssvl __builtin_ve_vl_vldu_vssvl
+#define _vel_vldunc_vssl __builtin_ve_vl_vldunc_vssl
+#define _vel_vldunc_vssvl __builtin_ve_vl_vldunc_vssvl
+#define _vel_vldlsx_vssl __builtin_ve_vl_vldlsx_vssl
+#define _vel_vldlsx_vssvl __builtin_ve_vl_vldlsx_vssvl
+#define _vel_vldlsxnc_vssl __builtin_ve_vl_vldlsxnc_vssl
+#define _vel_vldlsxnc_vssvl __builtin_ve_vl_vldlsxnc_vssvl
+#define _vel_vldlzx_vssl __builtin_ve_vl_vldlzx_vssl
+#define _vel_vldlzx_vssvl __builtin_ve_vl_vldlzx_vssvl
+#define _vel_vldlzxnc_vssl __builtin_ve_vl_vldlzxnc_vssl
+#define _vel_vldlzxnc_vssvl __builtin_ve_vl_vldlzxnc_vssvl
Index: clang/lib/Headers/velintrin.h
===================================================================
--- /dev/null
+++ clang/lib/Headers/velintrin.h
@@ -0,0 +1,38 @@
+/*===---- velintrin.h - VEL intrinsics for VE ------------------------------===
+ *
+ * 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
+ *
+ *===-----------------------------------------------------------------------===
+ */
+#ifndef __VEL_INTRIN_H__
+#define __VEL_INTRIN_H__
+
+// Vector registers
+typedef double __vr __attribute__((__vector_size__(2048)));
+
+// TODO: Vector mask registers
+// Depend on https://reviews.llvm.org/D88905
+#if 0
+#if __STDC_VERSION__ >= 199901L
+// For C99
+typedef _Bool __vm    __attribute__((ext_vector_type(256)));
+typedef _Bool __vm256 __attribute__((ext_vector_type(256)));
+typedef _Bool __vm512 __attribute__((ext_vector_type(512)));
+#else
+#ifdef __cplusplus
+// For C++
+typedef bool __vm    __attribute__((ext_vector_type(256)));
+typedef bool __vm256 __attribute__((ext_vector_type(256)));
+typedef bool __vm512 __attribute__((ext_vector_type(512)));
+#else
+#error need C++ or C99 to use vector intrinsics for VE
+#endif
+#endif
+#endif
+
+// Use generated intrinsic name definitions
+#include <velintrin_gen.h>
+
+#endif
Index: clang/lib/Headers/CMakeLists.txt
===================================================================
--- clang/lib/Headers/CMakeLists.txt
+++ clang/lib/Headers/CMakeLists.txt
@@ -145,6 +145,8 @@
   xsaveoptintrin.h
   xsavesintrin.h
   xtestintrin.h
+  velintrin.h
+  velintrin_gen.h
   )
 
 set(cuda_wrapper_files
Index: clang/lib/Basic/Targets/VE.cpp
===================================================================
--- clang/lib/Basic/Targets/VE.cpp
+++ clang/lib/Basic/Targets/VE.cpp
@@ -18,6 +18,14 @@
 using namespace clang;
 using namespace clang::targets;
 
+const Builtin::Info VETargetInfo::BuiltinInfo[] = {
+#define BUILTIN(ID, TYPE, ATTRS)                                               \
+  {#ID, TYPE, ATTRS, nullptr, ALL_LANGUAGES, nullptr},
+#define LIBBUILTIN(ID, TYPE, ATTRS, HEADER)                                    \
+  {#ID, TYPE, ATTRS, HEADER, ALL_LANGUAGES, nullptr},
+#include "clang/Basic/BuiltinsVE.def"
+};
+
 void VETargetInfo::getTargetDefines(const LangOptions &Opts,
                                     MacroBuilder &Builder) const {
   Builder.defineMacro("_LP64", "1");
@@ -35,5 +43,6 @@
 }
 
 ArrayRef<Builtin::Info> VETargetInfo::getTargetBuiltins() const {
-  return ArrayRef<Builtin::Info>();
+  return llvm::makeArrayRef(BuiltinInfo,
+                            clang::VE::LastTSBuiltin - Builtin::FirstTSBuiltin);
 }
Index: clang/include/clang/module.modulemap
===================================================================
--- clang/include/clang/module.modulemap
+++ clang/include/clang/module.modulemap
@@ -50,6 +50,7 @@
   textual header "Basic/BuiltinsRISCVVector.def"
   textual header "Basic/BuiltinsSVE.def"
   textual header "Basic/BuiltinsSystemZ.def"
+  textual header "Basic/BuiltinsVE.def"
   textual header "Basic/BuiltinsWebAssembly.def"
   textual header "Basic/BuiltinsX86.def"
   textual header "Basic/BuiltinsX86_64.def"
Index: clang/include/clang/Basic/TargetBuiltins.h
===================================================================
--- clang/include/clang/Basic/TargetBuiltins.h
+++ clang/include/clang/Basic/TargetBuiltins.h
@@ -121,7 +121,12 @@
 
   /// VE builtins
   namespace VE {
-  enum { LastTIBuiltin = clang::Builtin::FirstTSBuiltin - 1, LastTSBuiltin };
+  enum {
+    LastTIBuiltin = clang::Builtin::FirstTSBuiltin - 1,
+#define BUILTIN(ID, TYPE, ATTRS) BI##ID,
+#include "clang/Basic/BuiltinsVE.def"
+    LastTSBuiltin
+  };
   }
 
   namespace RISCVVector {
Index: clang/include/clang/Basic/BuiltinsVEVL.gen.def
===================================================================
--- /dev/null
+++ clang/include/clang/Basic/BuiltinsVEVL.gen.def
@@ -0,0 +1,16 @@
+BUILTIN(__builtin_ve_vl_vld_vssl, "V256dLUivC*Ui", "n")
+BUILTIN(__builtin_ve_vl_vld_vssvl, "V256dLUivC*V256dUi", "n")
+BUILTIN(__builtin_ve_vl_vldnc_vssl, "V256dLUivC*Ui", "n")
+BUILTIN(__builtin_ve_vl_vldnc_vssvl, "V256dLUivC*V256dUi", "n")
+BUILTIN(__builtin_ve_vl_vldu_vssl, "V256dLUivC*Ui", "n")
+BUILTIN(__builtin_ve_vl_vldu_vssvl, "V256dLUivC*V256dUi", "n")
+BUILTIN(__builtin_ve_vl_vldunc_vssl, "V256dLUivC*Ui", "n")
+BUILTIN(__builtin_ve_vl_vldunc_vssvl, "V256dLUivC*V256dUi", "n")
+BUILTIN(__builtin_ve_vl_vldlsx_vssl, "V256dLUivC*Ui", "n")
+BUILTIN(__builtin_ve_vl_vldlsx_vssvl, "V256dLUivC*V256dUi", "n")
+BUILTIN(__builtin_ve_vl_vldlsxnc_vssl, "V256dLUivC*Ui", "n")
+BUILTIN(__builtin_ve_vl_vldlsxnc_vssvl, "V256dLUivC*V256dUi", "n")
+BUILTIN(__builtin_ve_vl_vldlzx_vssl, "V256dLUivC*Ui", "n")
+BUILTIN(__builtin_ve_vl_vldlzx_vssvl, "V256dLUivC*V256dUi", "n")
+BUILTIN(__builtin_ve_vl_vldlzxnc_vssl, "V256dLUivC*Ui", "n")
+BUILTIN(__builtin_ve_vl_vldlzxnc_vssvl, "V256dLUivC*V256dUi", "n")
Index: clang/include/clang/Basic/BuiltinsVE.def
===================================================================
--- /dev/null
+++ clang/include/clang/Basic/BuiltinsVE.def
@@ -0,0 +1,17 @@
+//===--- BuiltinsVE.def - VE Builtin function database ----------*- 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 defines the VE-specific builtin function database.  Users of
+// this file must define the BUILTIN macro to make use of this information.
+//
+//===----------------------------------------------------------------------===//
+
+// Use generated BUILTIN definitions
+#include "clang/Basic/BuiltinsVEVL.gen.def"
+
+#undef BUILTIN
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to