-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[flang-rt] Add the ability to have user supplied callback functions to further customize the runtime environment. #155646
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[flang-rt] Add the ability to have user supplied callback functions to further customize the runtime environment. #155646
Conversation
…o further customize the runtime environment. modified: flang-rt/include/flang-rt/runtime/environment.h modified: flang-rt/lib/runtime/environment.cpp
|
||
// Optional callback routines to be invoked pre and post | ||
// execution environment setup. | ||
void (*PreConfigureEnv)(int, const char *[], const char *[], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, Dave!
It looks good to me, except maybe we should typedef the type of the callback functions (probably within ExecutionEnvironment
struct), so that we can reduce text here and in the declaration of RegisterConfigureEnv
.
Should there be support for multiple callbacks? |
modified: ../../include/flang-rt/runtime/environment.h modified: environment.cpp
modified: ../../include/flang-rt/runtime/environment.h
…he order they are registered. modified: environment.cpp
flang-rt/lib/runtime/environment.cpp
Outdated
// The pre and post callback functions are called upon entry and exit | ||
// of ExecutionEnvironment::Configure() respectively. | ||
|
||
void RTNAME(RegisterConfigureEnv)( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Who's able to call this early enough to take effect?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the example above, the constructor will be called before _QQmain
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Where from?
// for either pre or post functions. | ||
|
||
static constexpr int nConfigEnvCallback{8}; | ||
int nPreConfigEnvCallback{0}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that you want to define a variable like this in a header file.
flang-rt/lib/runtime/environment.cpp
Outdated
if (0 != nPreConfigEnvCallback) { | ||
// Run an optional callback function after the core of the | ||
// ExecutionEnvironment() logic. | ||
for (auto i = 0; i != nPreConfigEnvCallback; ++i) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
int i{0};
please in the runtime
flang-rt/lib/runtime/environment.cpp
Outdated
if (0 != nPostConfigEnvCallback) { | ||
// Run an optional callback function in reverse order of registration | ||
// after the core of the ExecutionEnvironment() logic. | ||
for (auto i = 0; i != nPostConfigEnvCallback; ++i) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
int i{0};
modified: ../../include/flang-rt/runtime/environment.h modified: environment.cpp
modified: environment.cpp
Add the ability to have pre and post call back functions to ExecutionEnvironment::Configure() to allow further customization of the flang runtime environment (called from _FortranAStartProgam) in situations where either the desired features/functionality are proprietary or are too specific to be accepted by the flang community.
Example:
Custom constructor object linked with flang objects: