点击查看代码
//遍历一个function
func.walk([&](Operation *op) {
size_t nUser =
llvm::count_if(op->getUsers(), [](auto *) { return true; });
unresolvedUsers[op] = nUser;
});
//返乡遍历operand
for (auto opr : llvm::reverse(op->getOperands())) {
if (auto def = opr.getDefiningOp<StcGoatInterface>()) {
if (--unresolvedUsers[def] == 0) {
todoList.push_front(def);
}
}
}
//OpBuilder使用Context初始化:
OpBuilder builder(op->getContext());
//tensor to memref
MemRefType::get(type.getShape(), type.getElementType());
//Value.cpp
//替换使用者
arg.replaceAllUsesExcept(load->getResult(0), load);
//获取op的参数个数
op.getNumOperands()
//带index遍历operand
for (auto opr : llvm::enumerate(adaptor.getOperands())) {
auto outputArg = func.getArgument(retArgIndex + opr.index());
rewriter.create<stc::StoreOp>(op.getLoc(), opr.value(), outputArg);
}
// debug a function
#include "mlir/Dialect/Func/IR/FuncOps.h"
if (auto op = llvm::dyn_cast<mlir::func::FuncOp>(*funcOp)) {
if (op.getName() == "forward"){
llvm::dbgs() << "funcOp:" << funcOp << "\n";
}
}