This is an archive of the discontinued LLVM Phabricator instance.

[libomptarget][amdgpu][nfc] Expand errorcheck macros
ClosedPublic

Authored by JonChesterfield on May 11 2021, 4:51 AM.

Details

Summary

[libomptarget][amdgpu][nfc] Expand errorcheck macros

These macros expand to continue, which is confusing, or exit,
which is incompatible with continuing execution on offloading fail.

Expanding the macros in place makes the code look untidy but the
control flow obvious and amenable to improving. In particular, exit
becomes easier to eliminate.

Diff Detail

Event Timeline

JonChesterfield requested review of this revision.May 11 2021, 4:51 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 11 2021, 4:51 AM
  • remove else {}; noise
  • remove else {}; noise
pdhaliwal added inline comments.May 11 2021, 11:55 PM
openmp/libomptarget/plugins/amdgpu/impl/data.cpp
52–54

Will it be better to use assert's here?

This patch doesn't fix any of the control flow, just expands macros and deletes else{}; clauses

openmp/libomptarget/plugins/amdgpu/impl/data.cpp
52–54

No, malloc can fail, and its failure can be handled. Assert might be better than exit, but what we actually need is return some-error-code

This revision is now accepted and ready to land.May 12 2021, 3:44 AM
protze.joachim added inline comments.
openmp/libomptarget/plugins/amdgpu/impl/data.cpp
52–54

Isn't that was the lines below do?

61

This line cannot be reached with your change.

openmp/libomptarget/plugins/amdgpu/impl/data.cpp
52–54

Yep. Nice example of something that is obvious once the macro is expanded, and was missed by repeated reading with the macro in use.

61

Then it was unreachable before. Not great, kind of why I don't like control flow escaping macros.

All this change does is macroexpand ErrorCheck et al and s_else {};__g then clang format. Quite literally, I write this with regex replace / run preprocessor / regex replace.

Functional changes / stuff that requires thought intentionally left for the next round. See also D102228 for the previous incremental change which made that scripting simple.

openmp/libomptarget/plugins/amdgpu/impl/data.cpp
61

I.e. before we had

#define ErrorCheck(msg, status)            \
  if (status != HSA_STATUS_SUCCESS) {                       \
    printf("[%s:%d] %s failed: %s\n", __FILE__, __LINE__, msg, \
           get_error_string(status));         \
    exit(1);  }

ErrorCheck("atmi_malloc", err);

which expands to
if (err != HSA_STATUS_SUCCESS) {printf(); exit(1); }

JonChesterfield added a comment.EditedMay 12 2021, 9:29 AM

I'm going to land this so I can follow up with fixing the above points and simplify system.cpp. In D102346

This revision was landed with ongoing or failed builds.May 12 2021, 9:31 AM
This revision was automatically updated to reflect the committed changes.