Skip to content

Commit c0e5149

Browse files
committed
[offload] defer "---> olInit" trace message
Tracing requires liboffload to be initialized, so calling isTracingEnabled() before olInit always returns false. This caused the first trace log to look like: -> OL_SUCCESS instead of: ---> olInit() -> OL_SUCCESS This patch moves the pre-call trace print for olInit so it is emitted only after initialization. It would be possible to add extra logic to detect whether liboffload is already initialized and only postpone the first pre-call print, but this would add unnecessary complexity, especially since this is tablegen code. The difference would matter only in the unlikely case of a crash during a second olInit call.
1 parent 09fd430 commit c0e5149

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

offload/tools/offload-tblgen/EntryPointGen.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,15 @@ static void EmitEntryPointFunc(const FunctionRec &F, raw_ostream &OS) {
8383
OS << ") {\n";
8484

8585
// Check offload is initialized
86-
if (F.getName() != "olInit")
86+
if (F.getName() != "olInit") {
8787
OS << "if (!llvm::offload::isOffloadInitialized()) return &UninitError;";
8888

89-
// Emit pre-call prints
90-
OS << TAB_1 "if (llvm::offload::isTracingEnabled()) {\n";
91-
OS << formatv(TAB_2 "llvm::errs() << \"---> {0}\";\n", F.getName());
92-
OS << TAB_1 "}\n\n";
89+
// Emit pre-call prints
90+
// Postpone pre-calls for olInit as tracing requires liboffload to be initialized
91+
OS << TAB_1 "if (llvm::offload::isTracingEnabled()) {\n";
92+
OS << formatv(TAB_2 "llvm::errs() << \"---> {0}\";\n", F.getName());
93+
OS << TAB_1 "}\n\n";
94+
}
9395

9496
// Perform actual function call to the validation wrapper
9597
ParamNameList = ParamNameList.substr(0, ParamNameList.size() - 2);
@@ -99,6 +101,11 @@ static void EmitEntryPointFunc(const FunctionRec &F, raw_ostream &OS) {
99101

100102
// Emit post-call prints
101103
OS << TAB_1 "if (llvm::offload::isTracingEnabled()) {\n";
104+
// postponed pre-call print for olInit
105+
if (F.getName() == "olInit") {
106+
OS << formatv(TAB_2 "llvm::errs() << \"---> {0}\";\n", F.getName());
107+
}
108+
102109
if (F.getParams().size() > 0) {
103110
OS << formatv(TAB_2 "{0} Params = {{", F.getParamStructName());
104111
for (const auto &Param : F.getParams()) {

0 commit comments

Comments
 (0)