NFC: Remove Function::getModule.

There is already a more general 'getParentOfType' method, and 'getModule' is likely to be misused as functions get placed within different regions than ModuleOp.

PiperOrigin-RevId: 257442243
This commit is contained in:
River Riddle 2019-07-10 11:12:27 -07:00 committed by jpienaar
parent 68edb3ba75
commit b3e28fca53
9 changed files with 12 additions and 24 deletions

View File

@ -93,8 +93,8 @@ inline void cleanupAndPrintFunction(mlir::FuncOp f) {
}
};
auto pm = cleanupPassManager();
check(mlir::verify(f.getModule()));
check(pm->run(f.getModule()));
check(mlir::verify(f.getParentOfType<mlir::ModuleOp>()));
check(pm->run(f.getParentOfType<mlir::ModuleOp>()));
if (printToOuts)
f.print(llvm::outs());
}

View File

@ -173,7 +173,7 @@ TEST_FUNC(matmul_as_matvec_as_affine) {
lowerToLoops(f);
PassManager pm;
pm.addPass(createLowerLinalgLoadStorePass());
if (succeeded(pm.run(f.getModule())))
if (succeeded(pm.run(f.getParentOfType<mlir::ModuleOp>())))
cleanupAndPrintFunction(f);
// clang-format off

View File

@ -69,7 +69,7 @@ TEST_FUNC(matmul_tiled_loops) {
lowerToTiledLoops(f, {8, 9});
PassManager pm;
pm.addPass(createLowerLinalgLoadStorePass());
if (succeeded(pm.run(f.getModule())))
if (succeeded(pm.run(f.getParentOfType<mlir::ModuleOp>())))
cleanupAndPrintFunction(f);
// clang-format off

View File

@ -27,8 +27,6 @@
#include "llvm/ADT/SmallString.h"
namespace mlir {
class ModuleOp;
//===--------------------------------------------------------------------===//
// Function Operation.
//===--------------------------------------------------------------------===//
@ -60,9 +58,6 @@ public:
FunctionType type, ArrayRef<NamedAttribute> attrs,
ArrayRef<NamedAttributeList> argAttrs);
/// Get the parent module.
ModuleOp getModule();
/// Operation hooks.
static ParseResult parse(OpAsmParser *parser, OperationState *result);
void print(OpAsmPrinter *p);

View File

@ -441,14 +441,14 @@ struct AllocOpLowering : public LLVMLegalizationPattern<AllocOp> {
createIndexConstant(rewriter, op->getLoc(), elementSize)});
// Insert the `malloc` declaration if it is not already present.
FuncOp mallocFunc =
op->getParentOfType<FuncOp>().getModule().getNamedFunction("malloc");
auto module = op->getParentOfType<ModuleOp>();
FuncOp mallocFunc = module.getNamedFunction("malloc");
if (!mallocFunc) {
auto mallocType =
rewriter.getFunctionType(getIndexType(), getVoidPtrType());
mallocFunc =
FuncOp::create(rewriter.getUnknownLoc(), "malloc", mallocType);
op->getParentOfType<FuncOp>().getModule().push_back(mallocFunc);
module.push_back(mallocFunc);
}
// Allocate the underlying buffer and store a pointer to it in the MemRef
@ -503,12 +503,11 @@ struct DeallocOpLowering : public LLVMLegalizationPattern<DeallocOp> {
OperandAdaptor<DeallocOp> transformed(operands);
// Insert the `free` declaration if it is not already present.
FuncOp freeFunc =
op->getParentOfType<FuncOp>().getModule().getNamedFunction("free");
FuncOp freeFunc = op->getParentOfType<ModuleOp>().getNamedFunction("free");
if (!freeFunc) {
auto freeType = rewriter.getFunctionType(getVoidPtrType(), {});
freeFunc = FuncOp::create(rewriter.getUnknownLoc(), "free", freeType);
op->getParentOfType<FuncOp>().getModule().push_back(freeFunc);
op->getParentOfType<ModuleOp>().push_back(freeFunc);
}
auto type = transformed.memref()->getType().cast<LLVM::LLVMType>();

View File

@ -73,12 +73,6 @@ void FuncOp::build(Builder *builder, OperationState *result, StringRef name,
result->addAttribute(getArgAttrName(i, argAttrName), argDict);
}
/// Get the parent module.
ModuleOp FuncOp::getModule() {
auto *parent = getOperation()->getContainingRegion();
return parent ? parent->getParentOfType<ModuleOp>() : nullptr;
}
/// Parsing/Printing methods.
static ParseResult
parseArgumentList(OpAsmParser *parser, SmallVectorImpl<Type> &argTypes,

View File

@ -575,7 +575,7 @@ public:
// types and returns pointers to the output types.
static FuncOp getLLVMLibraryCallImplDefinition(FuncOp libFn) {
auto implFnName = (libFn.getName().str() + "_impl");
auto module = libFn.getModule();
auto module = libFn.getParentOfType<ModuleOp>();
if (auto f = module.getNamedFunction(implFnName)) {
return f;
}

View File

@ -66,7 +66,7 @@ static void printIR(const llvm::Any &ir, bool printModuleScope,
// Print the function name and a newline before the Module.
out << " (function: " << function.getName() << ")\n";
function.getModule().print(out);
function.getParentOfType<ModuleOp>().print(out);
return;
}

View File

@ -340,7 +340,7 @@ PassInstrumentor *FunctionAnalysisManager::getPassInstrumentor() const {
/// Create an analysis slice for the given child function.
FunctionAnalysisManager ModuleAnalysisManager::slice(FuncOp func) {
assert(func.getModule() == moduleAnalyses.getIRUnit() &&
assert(func.getOperation()->getParentOp() == moduleAnalyses.getIRUnit() &&
"function has a different parent module");
auto it = functionAnalyses.find(func);
if (it == functionAnalyses.end()) {