17#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
19#include "mlir/IR/Matchers.h"
20#include "mlir/IR/PatternMatch.h"
21#include "mlir/IR/SymbolTable.h"
26#define GEN_PASS_DEF_RAISELLVMEXTPASS
27#include "Passes/Passes.h.inc"
33using namespace enzyme;
35struct RaiseLLVMExtPass
36 :
public enzyme::impl::RaiseLLVMExtPassBase<RaiseLLVMExtPass> {
37 using RaiseLLVMExtPassBase::RaiseLLVMExtPassBase;
39 void runOnOperation()
override {
42 SymbolTable::walkSymbolTables(
44 true, [&](Operation *st,
bool allUsesVisible) {
45 SymbolTable symtable(st);
47 auto name = StringAttr::get(&getContext(),
"__enzyme_ptr_size_hint");
48 auto uses = SymbolTable::getSymbolUses(name, st);
53 auto fn = cast<FunctionOpInterface>(symtable.lookup(name));
54 if (!fn.isExternal()) {
56 fn.emitError() <<
"__enzyme_ptr_size_hint is not declared external";
60 for (
auto use : *uses) {
61 auto call = dyn_cast<LLVM::CallOp>(use.getUser());
64 use.getUser()->emitError()
65 <<
"user of __enzyme_ptr_size_hint is not a llvm.call";
69 OpBuilder builder(call);
70 llvm_ext::PtrSizeHintOp::create(
71 builder, call.getLoc(), call.getOperand(0), call.getOperand(1));