2020using namespace llvm ;
2121using namespace offload ::tblgen;
2222
23- static void EmitEntryPointFunc (const FunctionRec &F, raw_ostream &OS) {
23+ static void EmitValidationFunc (const FunctionRec &F, raw_ostream &OS) {
2424 OS << CommentsHeader;
2525 // Emit preamble
26- OS << formatv (" {1}_APIEXPORT {0}_result_t {1}_APICALL {2}(\n " , PrefixLower,
27- PrefixUpper, F.getName ());
26+ OS << formatv (" {0}_result_t {1}_val(\n " , PrefixLower, F.getName ());
2827 // Emit arguments
2928 std::string ParamNameList = " " ;
3029 for (auto &Param : F.getParams ()) {
@@ -37,7 +36,6 @@ static void EmitEntryPointFunc(const FunctionRec &F, raw_ostream &OS) {
3736 OS << " ) {\n " ;
3837
3938 OS << TAB_1 " if (true /*enableParameterValidation*/) {\n " ;
40-
4139 // Emit validation checks
4240 for (const auto &Return : F.getReturns ()) {
4341 for (auto &Condition : Return.getConditions ()) {
@@ -49,16 +47,37 @@ static void EmitEntryPointFunc(const FunctionRec &F, raw_ostream &OS) {
4947 }
5048 }
5149 }
52- OS << " }\n\n " ;
50+ OS << TAB_1 " }\n\n " ;
51+
52+ // Perform actual function call to the implementation
53+ ParamNameList = ParamNameList.substr (0 , ParamNameList.size () - 2 );
54+ OS << formatv (TAB_1 " return {0}_impl({1});\n\n " , F.getName (), ParamNameList);
55+ OS << " }\n " ;
56+ }
57+
58+ static void EmitEntryPointFunc (const FunctionRec &F, raw_ostream &OS) {
59+ // Emit preamble
60+ OS << formatv (" {1}_APIEXPORT {0}_result_t {1}_APICALL {2}(\n " , PrefixLower,
61+ PrefixUpper, F.getName ());
62+ // Emit arguments
63+ std::string ParamNameList = " " ;
64+ for (auto &Param : F.getParams ()) {
65+ OS << Param.getType () << " " << Param.getName ();
66+ if (Param != F.getParams ().back ()) {
67+ OS << " , " ;
68+ }
69+ ParamNameList += Param.getName ().str () + " , " ;
70+ }
71+ OS << " ) {\n " ;
5372
5473 // Emit pre-call prints
5574 OS << TAB_1 " if (std::getenv(\" OFFLOAD_TRACE\" )) {\n " ;
5675 OS << formatv (TAB_2 " std::cout << \" ---> {0}\" ;\n " , F.getName ());
5776 OS << TAB_1 " }\n\n " ;
5877
59- // Perform actual function call
78+ // Perform actual function call to the validation wrapper
6079 ParamNameList = ParamNameList.substr (0 , ParamNameList.size () - 2 );
61- OS << formatv (TAB_1 " {0}_result_t result = {1}_impl ({2});\n\n " , PrefixLower,
80+ OS << formatv (TAB_1 " {0}_result_t result = {1}_val ({2});\n\n " , PrefixLower,
6281 F.getName (), ParamNameList);
6382
6483 // Emit post-call prints
@@ -81,6 +100,7 @@ static void EmitEntryPointFunc(const FunctionRec &F, raw_ostream &OS) {
81100
82101void EmitOffloadEntryPoints (RecordKeeper &Records, raw_ostream &OS) {
83102 for (auto *R : Records.getAllDerivedDefinitions (" Function" )) {
103+ EmitValidationFunc (FunctionRec{R}, OS);
84104 EmitEntryPointFunc (FunctionRec{R}, OS);
85105 }
86106}
0 commit comments