This is an archive of the discontinued LLVM Phabricator instance.

Add a helper function to convert LogicalResult to int for return from main
ClosedPublic

Authored by tkoeppe on May 17 2021, 10:59 AM.

Details

Summary

At present, a lot of code contains main function bodies like "return failed(mlir::MlirOptMain(...);". This is unfortunate for two reasons: a) it uses ADL, which is maybe not what the free "failed" function was designed for; and b) it is a bit awkward to read, requring the reader to both understand the boolean nature of the value and the semantics of main's return value. (And it's also not portable, since 1 is not a portable success value.)

The replacement code, return mlir::AsMainReturnCode(mlir::MlirOptMain(...)) is a bit more self-explanatory.

The change applies the new function to a few internal uses of MlirOptMain, too.

Diff Detail

Event Timeline

tkoeppe created this revision.May 17 2021, 10:59 AM
tkoeppe requested review of this revision.May 17 2021, 10:59 AM

Can you also introduce uses for this in the in-tree tools?

mlir/include/mlir/Support/MlirOptMain.h
75

Please fix :)

tkoeppe updated this revision to Diff 346105.May 18 2021, 3:43 AM
tkoeppe edited the summary of this revision. (Show Details)

Addressed both comments; function renamed to lowerSnakeCase.

tkoeppe marked an inline comment as done.May 18 2021, 4:19 AM
tkoeppe updated this revision to Diff 346110.May 18 2021, 4:22 AM
mehdi_amini accepted this revision.May 18 2021, 4:43 PM
This revision is now accepted and ready to land.May 18 2021, 4:43 PM