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

[Cherry-pick][CINN] Add IntrinsicOps into ir_codes_collector (#60556) #62245

Merged
merged 1 commit into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 8 additions & 1 deletion paddle/cinn/ir/ir_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,23 @@ class Dim;
macro__(Product) \
macro__(Sum) \
macro__(PrimitiveNode) \
macro__(IntrinsicOp) \
macro__(_BufferRange_) \
macro__(ScheduleBlock) \
macro__(ScheduleBlockRealize) \
macro__(_Dim_) \

#define NODETY_CONTROL_OP_FOR_INTRINSIC(macro__) \
macro__(IntrinsicOp) \

#define NODETY_FORALL(__m) \
NODETY_PRIMITIVE_TYPE_FOR_EACH(__m) \
NODETY_OP_FOR_EACH(__m) \
NODETY_CONTROL_OP_FOR_INTRINSIC(__m) \
NODETY_CONTROL_OP_FOR_EACH(__m)

#define NODETY_FORALL_EXCEPT_INTRINSIC(__m) \
NODETY_PRIMITIVE_TYPE_FOR_EACH(__m) \
NODETY_OP_FOR_EACH(__m) \
NODETY_CONTROL_OP_FOR_EACH(__m)
// clang-format on

Expand Down
67 changes: 66 additions & 1 deletion paddle/cinn/ir/utils/ir_nodes_collector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include "paddle/cinn/ir/utils/ir_nodes_collector.h"
#include <glog/logging.h>

#include "paddle/cinn/ir/intrinsic_ops.h"
#include "paddle/cinn/ir/ir.h"
#include "paddle/cinn/ir/ir_mutator.h"
#include "paddle/cinn/ir/ir_printer.h"

Expand Down Expand Up @@ -71,8 +73,71 @@ struct IrNodesCollector : public IRVisitorRequireReImpl<void> {
} \
}

NODETY_FORALL(__m)
NODETY_FORALL_EXCEPT_INTRINSIC(__m)
#undef __m

void Visit(const ir::IntrinsicOp* op) {
switch (op->getKind()) {
#define __(x) \
case ir::IntrinsicKind::k##x: \
Visit(llvm::dyn_cast<ir::intrinsics::x>(op)); \
break;

INTRINSIC_KIND_FOR_EACH(__)
#undef __
}
}

void Visit(const ir::intrinsics::GetAddr* x) {
if (x->data.defined()) {
Visit(&(x->data));
}
}

void Visit(const ir::intrinsics::BufferGetDataHandle* x) {
if (x->buffer.defined()) {
Visit(&(x->buffer));
}
}

void Visit(const ir::intrinsics::BufferGetDataConstHandle* x) {
if (x->buffer.defined()) {
Visit(&(x->buffer));
}
}

void Visit(const ir::intrinsics::PodValueToX* x) {
if (x->pod_value_ptr.defined()) {
Visit(&(x->pod_value_ptr));
}
}

void Visit(const ir::intrinsics::BufferCreate* x) {
if (x->buffer.defined()) {
Visit(&(x->buffer));
}
}

void Visit(const ir::intrinsics::ArgsConstruct* x) {
if (x->var.defined()) {
Expr convert = Expr(x->var);
Visit(&convert);
}
for (int i = 0; i < x->args.size(); ++i) {
if (x->args[i].defined()) {
Visit(&(x->args[i]));
}
}
}

void Visit(const ir::intrinsics::BuiltinIntrin* x) {
for (int i = 0; i < x->args.size(); ++i) {
if (x->args[i].defined()) {
Visit(&(x->args[i]));
}
}
}

std::set<void*> visited_;
};

Expand Down