zackcquic commented on a change in pull request #7952:
URL: https://github.com/apache/tvm/pull/7952#discussion_r639032543
##########
File path: src/ir/transform.cc
##########
@@ -164,34 +167,57 @@ void PassContext::RegisterConfigOption(const char* key,
uint32_t value_type_inde
PassContext PassContext::Create() { return
PassContext(make_object<PassContextNode>()); }
-void PassContext::InstrumentSetUp() const {
+void PassContext::InstrumentEnterPassContext() {
auto pass_ctx_node = this->operator->();
if (pass_ctx_node->instruments.defined()) {
- for (instrument::PassInstrument pi : pass_ctx_node->instruments) {
- pi->SetUp();
+ try {
+ for (instrument::PassInstrument pi : pass_ctx_node->instruments) {
+ pi->EnterPassContext();
+ }
+ } catch (const Error& e) {
+ LOG(INFO) << "Pass instrumentation entering pass context failed.";
+ LOG(INFO) << "Disable pass instrumentation.";
+ pass_ctx_node->instruments.clear();
+ throw e;
}
}
}
-void PassContext::InstrumentTearDown() const {
+void PassContext::InstrumentExitPassContext() {
auto pass_ctx_node = this->operator->();
if (pass_ctx_node->instruments.defined()) {
- for (instrument::PassInstrument pi : pass_ctx_node->instruments) {
- pi->TearDown();
+ try {
+ for (instrument::PassInstrument pi : pass_ctx_node->instruments) {
+ pi->ExitPassContext();
+ }
+ } catch (const Error& e) {
+ LOG(INFO) << "Pass instrumentation exiting pass context failed.";
+ pass_ctx_node->instruments.clear();
+ throw e;
}
}
}
bool PassContext::InstrumentBeforePass(const IRModule& ir_module, const
PassInfo& pass_info) const {
auto pass_ctx_node = this->operator->();
- if (pass_ctx_node->instruments.defined()) {
+ if (!pass_ctx_node->instruments.defined()) {
+ return true;
+ }
+
+ const bool pass_required = PassArrayContains(pass_ctx_node->required_pass,
pass_info->name);
+ bool should_run = true;
+ if (!pass_required) {
+ const Array<instrument::PassInstrument>& instruments =
pass_ctx_node->instruments;
+ should_run &= std::all_of(instruments.begin(), instruments.end(),
Review comment:
Removed all_of (much like llvm's code above now).
For the second question, personally, I prefer to be consistent with llvm's
API and its logics like above.
If there are strong desire to do that in the future, I will change it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]