24#define GEN_PASS_DEF_FUNCTIONFILTERINGPASS
25#include "mlir/Dialect/OpenMP/Transforms/Passes.h.inc"
34class FunctionFilteringPass
35 :
public omp::impl::FunctionFilteringPassBase<FunctionFilteringPass> {
37 void runOnOperation()
override {
38 auto op = dyn_cast<omp::OffloadModuleInterface>(getOperation());
39 if (!op || !op.getIsTargetDevice())
43 op->walk<WalkOrder::PreOrder>([&](FunctionOpInterface funcOp) {
47 bool hasTargetRegion =
49 ->walk<WalkOrder::PreOrder>([&](omp::TargetOp targetOp) {
54 omp::DeclareTargetDeviceType declareType =
55 omp::DeclareTargetDeviceType::host;
56 auto declareTargetOp =
57 dyn_cast<omp::DeclareTargetInterface>(funcOp.getOperation());
58 if (declareTargetOp && declareTargetOp.isDeclareTarget())
59 declareType = declareTargetOp.getDeclareTargetDeviceType();
63 if (declareType != omp::DeclareTargetDeviceType::host)
66 SymbolTable::UseRange funcUses = *funcOp.getSymbolUses(op);
67 for (SymbolTable::SymbolUse use : funcUses) {
68 Operation *callOp = use.getUser();
73 if (isa<FunctionOpInterface>(callOp))
80 SmallVector<Value> poisonResults;
83 poisonResults.emplace_back(
84 LLVM::PoisonOp::create(opBuilder, res.getLoc(), res.
getType()));
92 if (!hasTargetRegion) {
101 if (declareTargetOp && !declareTargetOp.isDeclareTarget())
102 declareTargetOp.setDeclareTarget(omp::DeclareTargetDeviceType::host,
103 omp::DeclareTargetCaptureClause::to,
Ty getType(Args &&...args)
Get or construct an instance of the type Ty with provided arguments.
void setInsertionPoint(Block *block, Block::iterator insertPoint)
Set the insertion point to the specified location.
bool use_empty()
Returns true if this operation has no uses.
void replaceAllUsesWith(ValuesT &&values)
Replace all uses of results of this operation with the provided 'values'.
result_range getResults()
void erase()
Remove this operation from its parent block and delete it.
static WalkResult advance()
static WalkResult interrupt()
Include the generated interface declarations.