#include "mlir/Transforms/Inliner.h"
#include "mlir/IR/Threading.h"
#include "mlir/Interfaces/CallInterfaces.h"
#include "mlir/Interfaces/SideEffectInterfaces.h"
#include "mlir/Pass/Pass.h"
#include "mlir/Support/DebugStringHelper.h"
#include "mlir/Transforms/InliningUtils.h"
#include "llvm/ADT/SCCIterator.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/Support/Debug.h"
#define DEBUG_TYPE …
usingnamespacemlir;
ResolvedCall;
static void walkReferencedSymbolNodes(
Operation *op, CallGraph &cg, SymbolTableCollection &symbolTable,
DenseMap<Attribute, CallGraphNode *> &resolvedRefs,
function_ref<void(CallGraphNode *, Operation *)> callback) { … }
namespace {
struct CGUseList { … };
}
CGUseList::CGUseList(Operation *op, CallGraph &cg,
SymbolTableCollection &symbolTable)
: … { … }
void CGUseList::dropCallUses(CallGraphNode *userNode, Operation *callOp,
CallGraph &cg) { … }
void CGUseList::eraseNode(CallGraphNode *node) { … }
bool CGUseList::isDead(CallGraphNode *node) const { … }
bool CGUseList::hasOneUseAndDiscardable(CallGraphNode *node) const { … }
void CGUseList::recomputeUses(CallGraphNode *node, CallGraph &cg) { … }
void CGUseList::mergeUsesAfterInlining(CallGraphNode *lhs, CallGraphNode *rhs) { … }
void CGUseList::decrementDiscardableUses(CGUser &uses) { … }
namespace {
class CallGraphSCC { … };
}
static LogicalResult runTransformOnCGSCCs(
const CallGraph &cg,
function_ref<LogicalResult(CallGraphSCC &)> sccTransformer) { … }
static void collectCallOps(iterator_range<Region::iterator> blocks,
CallGraphNode *sourceNode, CallGraph &cg,
SymbolTableCollection &symbolTable,
SmallVectorImpl<ResolvedCall> &calls,
bool traverseNestedCGNodes) { … }
#ifndef NDEBUG
static std::string getNodeName(CallOpInterface op) {
if (llvm::dyn_cast_if_present<SymbolRefAttr>(op.getCallableForCallee()))
return debugString(op);
return "_unnamed_callee_";
}
#endif
static bool inlineHistoryIncludes(
CallGraphNode *node, std::optional<size_t> inlineHistoryID,
MutableArrayRef<std::pair<CallGraphNode *, std::optional<size_t>>>
inlineHistory) { … }
namespace {
struct InlinerInterfaceImpl : public InlinerInterface { … };
}
namespace mlir {
class Inliner::Impl { … };
LogicalResult Inliner::Impl::inlineSCC(InlinerInterfaceImpl &inlinerIface,
CGUseList &useList,
CallGraphSCC ¤tSCC,
MLIRContext *context) { … }
LogicalResult Inliner::Impl::optimizeSCC(CallGraph &cg, CGUseList &useList,
CallGraphSCC ¤tSCC,
MLIRContext *context) { … }
LogicalResult
Inliner::Impl::optimizeSCCAsync(MutableArrayRef<CallGraphNode *> nodesToVisit,
MLIRContext *ctx) { … }
LogicalResult
Inliner::Impl::optimizeCallable(CallGraphNode *node,
llvm::StringMap<OpPassManager> &pipelines) { … }
LogicalResult
Inliner::Impl::inlineCallsInSCC(InlinerInterfaceImpl &inlinerIface,
CGUseList &useList, CallGraphSCC ¤tSCC) { … }
bool Inliner::Impl::shouldInline(ResolvedCall &resolvedCall) { … }
LogicalResult Inliner::doInlining() { … }
}