Skip to content
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

[PIR] Reconstruct the Verify system #58052

Merged
merged 9 commits into from
Oct 13, 2023
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion paddle/fluid/pir/dialect/operator/ir/control_flow_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,45 @@ void IfOp::Print(pir::IrPrinter &printer) {
}
os << "\n }";
}
void IfOp::Verify() {}
void IfOp::Verify() {
if ((*this)->region(0).empty() && (*this)->region(1).empty()) {
LOG(WARNING)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

现在operation::create里面是调用了verify函数的。而create的时候,region都是空的。也就是说这个warning是一定会进入的。

<< "The true and false block of IfOp has not been initialized yet. "
"Please manually call Verify after completion the above content for "
"verification: op->dyn_cast<padding::dialect:IfOp>().Verify()";
return;
}

PADDLE_ENFORCE_EQ(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true_region和false_region的size可以不相等。
true_region的size一定等于1。 如果输入为空,false_region的size可以为0, 否则,一定为1;

(*this)->region(0).size(),
(*this)->region(1).size(),
phi::errors::PreconditionNotMet("The size %d of true_region must be "
"equal to the size %d of false_region.",
(*this)->region(0).size(),
(*this)->region(1).size()));
if ((*this)->num_results() != 0) {
auto *true_last_op = (*this)->region(0).front()->back();
auto *false_last_op = (*this)->region(1).front()->back();
PADDLE_ENFORCE_EQ(true_last_op->isa<pir::YieldOp>(),
true,
phi::errors::PreconditionNotMet(
"The last of true block must be YieldOp"));
PADDLE_ENFORCE_EQ(true_last_op->num_operands(),
(*this)->num_results(),
phi::errors::PreconditionNotMet(
"The size of last of true block op's input must be "
"equal to IfOp's outputs num."));
PADDLE_ENFORCE_EQ(false_last_op->isa<pir::YieldOp>(),
true,
phi::errors::PreconditionNotMet(
"The last of false block must be YieldOp"));
PADDLE_ENFORCE_EQ(false_last_op->num_operands(),
(*this)->num_results(),
phi::errors::PreconditionNotMet(
"The size of last of false block op's input must be "
"equal to IfOp's outputs num."));
}
}

void WhileOp::Build(pir::Builder &builder, // NOLINT
pir::OperationArgument &argument, // NOLINT
Expand Down