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(); }); + 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";
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits