[PATCH] D112020: [RISCV] Use clang_builtin_alias for all RISCV vector intrinsics.

2021-10-20 Thread Craig Topper 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 rGa29dfc089d18: [RISCV] Use clang_builtin_alias for all RISCV 
vector intrinsics. (authored by craig.topper).

Changed prior to commit:
  https://reviews.llvm.org/D112020?vs=380474&id=380976#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112020

Files:
  clang/utils/TableGen/RISCVVEmitter.cpp


Index: clang/utils/TableGen/RISCVVEmitter.cpp
===
--- clang/utils/TableGen/RISCVVEmitter.cpp
+++ clang/utils/TableGen/RISCVVEmitter.cpp
@@ -198,7 +198,7 @@
   void emitCodeGenSwitchBody(raw_ostream &o) const;
 
   // Emit the macros for mapping C/C++ intrinsic function to builtin functions.
-  void emitIntrinsicMacro(raw_ostream &o) const;
+  void emitIntrinsicFuncDef(raw_ostream &o) const;
 
   // Emit the mangled function definition.
   void emitMangledFuncDef(raw_ostream &o) const;
@@ -855,34 +855,30 @@
   OS << "  break;\n";
 }
 
-void RVVIntrinsic::emitIntrinsicMacro(raw_ostream &OS) const {
-  OS << "#define " << getName() << "(";
-  if (!InputTypes.empty()) {
-ListSeparator LS;
-for (unsigned i = 0, e = InputTypes.size(); i != e; ++i)
-  OS << LS << "op" << i;
-  }
-  OS << ") \\\n";
-  OS << "__builtin_rvv_" << getName() << "(";
+void RVVIntrinsic::emitIntrinsicFuncDef(raw_ostream &OS) const {
+  OS << "__attribute__((__clang_builtin_alias__(";
+  OS << "__builtin_rvv_" << getName() << ")))\n";
+  OS << OutputType->getTypeStr() << " " << getName() << "(";
+  // Emit function arguments
   if (!InputTypes.empty()) {
 ListSeparator LS;
-for (unsigned i = 0, e = InputTypes.size(); i != e; ++i)
-  OS << LS << "(" << InputTypes[i]->getTypeStr() << ")(op" << i << ")";
+for (unsigned i = 0; i < InputTypes.size(); ++i)
+  OS << LS << InputTypes[i]->getTypeStr();
   }
-  OS << ")\n";
+  OS << ");\n";
 }
 
 void RVVIntrinsic::emitMangledFuncDef(raw_ostream &OS) const {
-  OS << "__attribute__((clang_builtin_alias(";
+  OS << "__attribute__((__clang_builtin_alias__(";
   OS << "__builtin_rvv_" << getName() << ")))\n";
   OS << OutputType->getTypeStr() << " " << getMangledName() << "(";
   // Emit function arguments
   if (!InputTypes.empty()) {
 ListSeparator LS;
 for (unsigned i = 0; i < InputTypes.size(); ++i)
-  OS << LS << InputTypes[i]->getTypeStr() << " op" << i;
+  OS << LS << InputTypes[i]->getTypeStr();
   }
-  OS << ");\n\n";
+  OS << ");\n";
 }
 
 
//===--===//
@@ -980,24 +976,32 @@
 return A->getRISCVExtensions() < B->getRISCVExtensions();
   });
 
+  OS << "#define __rvv_ai static __inline__ "
+"__attribute__((__always_inline__, __nodebug__))\n";
+
   // Print intrinsic functions with macro
   emitArchMacroAndBody(Defs, OS, [](raw_ostream &OS, const RVVIntrinsic &Inst) 
{
-Inst.emitIntrinsicMacro(OS);
+OS << "__rvv_ai ";
+Inst.emitIntrinsicFuncDef(OS);
   });
 
+  OS << "#undef __rvv_ai\n\n";
+
   OS << "#define __riscv_v_intrinsic_overloading 1\n";
 
   // Print Overloaded APIs
-  OS << "#define __rvv_overloaded static inline "
+  OS << "#define __rvv_aio static __inline__ "
 "__attribute__((__always_inline__, __nodebug__, __overloadable__))\n";
 
   emitArchMacroAndBody(Defs, OS, [](raw_ostream &OS, const RVVIntrinsic &Inst) 
{
 if (!Inst.isMask() && !Inst.hasNoMaskedOverloaded())
   return;
-OS << "__rvv_overloaded ";
+OS << "__rvv_aio ";
 Inst.emitMangledFuncDef(OS);
   });
 
+  OS << "#undef __rvv_aio\n";
+
   OS << "\n#ifdef __cplusplus\n";
   OS << "}\n";
   OS << "#endif // __cplusplus\n";


Index: clang/utils/TableGen/RISCVVEmitter.cpp
===
--- clang/utils/TableGen/RISCVVEmitter.cpp
+++ clang/utils/TableGen/RISCVVEmitter.cpp
@@ -198,7 +198,7 @@
   void emitCodeGenSwitchBody(raw_ostream &o) const;
 
   // Emit the macros for mapping C/C++ intrinsic function to builtin functions.
-  void emitIntrinsicMacro(raw_ostream &o) const;
+  void emitIntrinsicFuncDef(raw_ostream &o) const;
 
   // Emit the mangled function definition.
   void emitMangledFuncDef(raw_ostream &o) const;
@@ -855,34 +855,30 @@
   OS << "  break;\n";
 }
 
-void RVVIntrinsic::emitIntrinsicMacro(raw_ostream &OS) const {
-  OS << "#define " << getName() << "(";
-  if (!InputTypes.empty()) {
-ListSeparator LS;
-for (unsigned i = 0, e = InputTypes.size(); i != e; ++i)
-  OS << LS << "op" << i;
-  }
-  OS << ") \\\n";
-  OS << "__builtin_rvv_" << getName() << "(";
+void RVVIntrinsic::emitIntrinsicFuncDef(raw_ostream &OS) const {
+  OS << "__attribute__((__clang_builtin_alias__(";
+  OS << "__builtin_rvv_" << getName() << ")))\n";
+  OS << OutputType->getTypeStr() << " " << getName() << "(";
+  // Emit fun

[PATCH] D112020: [RISCV] Use clang_builtin_alias for all RISCV vector intrinsics.

2021-10-20 Thread Zakk Chen via Phabricator via cfe-commits
khchen accepted this revision.
khchen added a comment.

LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112020

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


[PATCH] D112020: [RISCV] Use clang_builtin_alias for all RISCV vector intrinsics.

2021-10-20 Thread Hsiangkai Wang via Phabricator via cfe-commits
HsiangKai accepted this revision.
HsiangKai added a comment.
This revision is now accepted and ready to land.

I ran tests under `clang/test/CodeGen/RISCV/rvv-intrinsics/`. It spent a little 
more time to run the tests. (previous: 84.01s; apply this patch: 96.43s in my 
local environment.) We could apply some technic similar to D111617 
 to reduce the header size. I think to reduce 
the number of RVV builtins is important in the long run.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112020

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


[PATCH] D112020: [RISCV] Use clang_builtin_alias for all RISCV vector intrinsics.

2021-10-20 Thread Hsiangkai Wang via Phabricator via cfe-commits
HsiangKai added a comment.

In D112020#3074557 , @HsiangKai wrote:

> After preprocessing, macro definitions will disappear, but function 
> declarations will not. This is the benefit of using macro.
>
> After applying D112102 , we could still use
>
>   #define vadd_vv_i8m1(op0, op1, op2) \
>   __builtin_rvv_vadd_vv((vint8m1_t)(op0), (vint8m1_t)(op1), (size_t)(op2))

Sorry for the disturbing. After removing type string in the builtin 
definitions, we need a function declaration in the header. Macro doesn't work.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112020

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


[PATCH] D112020: [RISCV] Use clang_builtin_alias for all RISCV vector intrinsics.

2021-10-20 Thread Hsiangkai Wang via Phabricator via cfe-commits
HsiangKai added a comment.

After preprocessing, macro definitions will disappear, but function 
declarations will not. This is the benefit of using macro.

After applying D112102 , we could still use

  #define vadd_vv_i8m1(op0, op1, op2) \
  __builtin_rvv_vadd_vv((vint8m1_t)(op0), (vint8m1_t)(op1), (size_t)(op2))


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112020

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


[PATCH] D112020: [RISCV] Use clang_builtin_alias for all RISCV vector intrinsics.

2021-10-18 Thread Craig Topper via Phabricator via cfe-commits
craig.topper created this revision.
craig.topper added reviewers: khchen, arcbbb, kito-cheng, HsiangKai, evandro.
Herald added subscribers: achieveartificialintelligence, jeroen.dobbelaere, 
StephenFan, vkmr, frasercrmck, luismarques, apazos, sameer.abuasal, s.egerton, 
Jim, benna, psnobl, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, 
edward-jones, zzheng, jrtc27, shiva0217, niosHD, sabuasal, simoncook, 
johnrusso, rbar, asb.
craig.topper requested review of this revision.
Herald added a subscriber: MaskRay.
Herald added a project: clang.

Previously we used builtin_alias for overloaded intrinsics, but
macros for the non-overloaded version. This patch changes the
non-overloaded versions to also use builtin_alias, but without
the overloadable attribute.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D112020

Files:
  clang/utils/TableGen/RISCVVEmitter.cpp


Index: clang/utils/TableGen/RISCVVEmitter.cpp
===
--- clang/utils/TableGen/RISCVVEmitter.cpp
+++ clang/utils/TableGen/RISCVVEmitter.cpp
@@ -202,7 +202,7 @@
   void emitCodeGenSwitchBody(raw_ostream &o) const;
 
   // Emit the macros for mapping C/C++ intrinsic function to builtin functions.
-  void emitIntrinsicMacro(raw_ostream &o) const;
+  void emitIntrinsicFuncDef(raw_ostream &o) const;
 
   // Emit the mangled function definition.
   void emitMangledFuncDef(raw_ostream &o) const;
@@ -860,21 +860,17 @@
   OS << "  break;\n";
 }
 
-void RVVIntrinsic::emitIntrinsicMacro(raw_ostream &OS) const {
-  OS << "#define " << getName() << "(";
-  if (!InputTypes.empty()) {
-ListSeparator LS;
-for (unsigned i = 0, e = InputTypes.size(); i != e; ++i)
-  OS << LS << "op" << i;
-  }
-  OS << ") \\\n";
-  OS << "__builtin_rvv_" << getName() << "(";
+void RVVIntrinsic::emitIntrinsicFuncDef(raw_ostream &OS) const {
+  OS << "__attribute__((clang_builtin_alias(";
+  OS << "__builtin_rvv_" << getName() << ")))\n";
+  OS << OutputType->getTypeStr() << " " << getName() << "(";
+  // Emit function arguments
   if (!InputTypes.empty()) {
 ListSeparator LS;
-for (unsigned i = 0, e = InputTypes.size(); i != e; ++i)
-  OS << LS << "(" << InputTypes[i]->getTypeStr() << ")(op" << i << ")";
+for (unsigned i = 0; i < InputTypes.size(); ++i)
+  OS << LS << InputTypes[i]->getTypeStr() << " op" << i;
   }
-  OS << ")\n";
+  OS << ");\n\n";
 }
 
 void RVVIntrinsic::emitMangledFuncDef(raw_ostream &OS) const {
@@ -986,11 +982,17 @@
  return A->getRISCVExtensions() < B->getRISCVExtensions();
});
 
+  OS << "#define __rvv_ai static inline "
+"__attribute__((__always_inline__, __nodebug__))\n";
+
   // Print intrinsic functions with macro
   emitArchMacroAndBody(Defs, OS, [](raw_ostream &OS, const RVVIntrinsic &Inst) 
{
-Inst.emitIntrinsicMacro(OS);
+OS << "__rvv_ai ";
+Inst.emitIntrinsicFuncDef(OS);
   });
 
+  OS << "#undef __rvv_ai\n";
+
   OS << "#define __riscv_v_intrinsic_overloading 1\n";
 
   // Print Overloaded APIs
@@ -1004,6 +1006,8 @@
 Inst.emitMangledFuncDef(OS);
   });
 
+  OS << "#undef __rvv_overloaded\n";
+
   OS << "\n#ifdef __cplusplus\n";
   OS << "}\n";
   OS << "#endif // __cplusplus\n";


Index: clang/utils/TableGen/RISCVVEmitter.cpp
===
--- clang/utils/TableGen/RISCVVEmitter.cpp
+++ clang/utils/TableGen/RISCVVEmitter.cpp
@@ -202,7 +202,7 @@
   void emitCodeGenSwitchBody(raw_ostream &o) const;
 
   // Emit the macros for mapping C/C++ intrinsic function to builtin functions.
-  void emitIntrinsicMacro(raw_ostream &o) const;
+  void emitIntrinsicFuncDef(raw_ostream &o) const;
 
   // Emit the mangled function definition.
   void emitMangledFuncDef(raw_ostream &o) const;
@@ -860,21 +860,17 @@
   OS << "  break;\n";
 }
 
-void RVVIntrinsic::emitIntrinsicMacro(raw_ostream &OS) const {
-  OS << "#define " << getName() << "(";
-  if (!InputTypes.empty()) {
-ListSeparator LS;
-for (unsigned i = 0, e = InputTypes.size(); i != e; ++i)
-  OS << LS << "op" << i;
-  }
-  OS << ") \\\n";
-  OS << "__builtin_rvv_" << getName() << "(";
+void RVVIntrinsic::emitIntrinsicFuncDef(raw_ostream &OS) const {
+  OS << "__attribute__((clang_builtin_alias(";
+  OS << "__builtin_rvv_" << getName() << ")))\n";
+  OS << OutputType->getTypeStr() << " " << getName() << "(";
+  // Emit function arguments
   if (!InputTypes.empty()) {
 ListSeparator LS;
-for (unsigned i = 0, e = InputTypes.size(); i != e; ++i)
-  OS << LS << "(" << InputTypes[i]->getTypeStr() << ")(op" << i << ")";
+for (unsigned i = 0; i < InputTypes.size(); ++i)
+  OS << LS << InputTypes[i]->getTypeStr() << " op" << i;
   }
-  OS << ")\n";
+  OS << ");\n\n";
 }
 
 void RVVIntrinsic::emitMangledFuncDef(raw_ostream &OS) const {
@@ -986,11 +982,17 @@
  return A->getRISCVExtensions() < B->getRISCVExtensions();
}