Skip to content

Commit 1f8d9e8

Browse files
committed
Refactor entry point validation so failures are visible in tracing output
1 parent 41cc771 commit 1f8d9e8

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
lines changed

offload/tools/offload-tblgen/EntryPointGen.cpp

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,10 @@
2020
using namespace llvm;
2121
using 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

82101
void 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

Comments
 (0)