forked from OSchip/llvm-project
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:
parent
68edb3ba75
commit
b3e28fca53
|
@ -93,8 +93,8 @@ inline void cleanupAndPrintFunction(mlir::FuncOp f) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
auto pm = cleanupPassManager();
|
auto pm = cleanupPassManager();
|
||||||
check(mlir::verify(f.getModule()));
|
check(mlir::verify(f.getParentOfType<mlir::ModuleOp>()));
|
||||||
check(pm->run(f.getModule()));
|
check(pm->run(f.getParentOfType<mlir::ModuleOp>()));
|
||||||
if (printToOuts)
|
if (printToOuts)
|
||||||
f.print(llvm::outs());
|
f.print(llvm::outs());
|
||||||
}
|
}
|
||||||
|
|
|
@ -173,7 +173,7 @@ TEST_FUNC(matmul_as_matvec_as_affine) {
|
||||||
lowerToLoops(f);
|
lowerToLoops(f);
|
||||||
PassManager pm;
|
PassManager pm;
|
||||||
pm.addPass(createLowerLinalgLoadStorePass());
|
pm.addPass(createLowerLinalgLoadStorePass());
|
||||||
if (succeeded(pm.run(f.getModule())))
|
if (succeeded(pm.run(f.getParentOfType<mlir::ModuleOp>())))
|
||||||
cleanupAndPrintFunction(f);
|
cleanupAndPrintFunction(f);
|
||||||
|
|
||||||
// clang-format off
|
// clang-format off
|
||||||
|
|
|
@ -69,7 +69,7 @@ TEST_FUNC(matmul_tiled_loops) {
|
||||||
lowerToTiledLoops(f, {8, 9});
|
lowerToTiledLoops(f, {8, 9});
|
||||||
PassManager pm;
|
PassManager pm;
|
||||||
pm.addPass(createLowerLinalgLoadStorePass());
|
pm.addPass(createLowerLinalgLoadStorePass());
|
||||||
if (succeeded(pm.run(f.getModule())))
|
if (succeeded(pm.run(f.getParentOfType<mlir::ModuleOp>())))
|
||||||
cleanupAndPrintFunction(f);
|
cleanupAndPrintFunction(f);
|
||||||
|
|
||||||
// clang-format off
|
// clang-format off
|
||||||
|
|
|
@ -27,8 +27,6 @@
|
||||||
#include "llvm/ADT/SmallString.h"
|
#include "llvm/ADT/SmallString.h"
|
||||||
|
|
||||||
namespace mlir {
|
namespace mlir {
|
||||||
class ModuleOp;
|
|
||||||
|
|
||||||
//===--------------------------------------------------------------------===//
|
//===--------------------------------------------------------------------===//
|
||||||
// Function Operation.
|
// Function Operation.
|
||||||
//===--------------------------------------------------------------------===//
|
//===--------------------------------------------------------------------===//
|
||||||
|
@ -60,9 +58,6 @@ public:
|
||||||
FunctionType type, ArrayRef<NamedAttribute> attrs,
|
FunctionType type, ArrayRef<NamedAttribute> attrs,
|
||||||
ArrayRef<NamedAttributeList> argAttrs);
|
ArrayRef<NamedAttributeList> argAttrs);
|
||||||
|
|
||||||
/// Get the parent module.
|
|
||||||
ModuleOp getModule();
|
|
||||||
|
|
||||||
/// Operation hooks.
|
/// Operation hooks.
|
||||||
static ParseResult parse(OpAsmParser *parser, OperationState *result);
|
static ParseResult parse(OpAsmParser *parser, OperationState *result);
|
||||||
void print(OpAsmPrinter *p);
|
void print(OpAsmPrinter *p);
|
||||||
|
|
|
@ -441,14 +441,14 @@ struct AllocOpLowering : public LLVMLegalizationPattern<AllocOp> {
|
||||||
createIndexConstant(rewriter, op->getLoc(), elementSize)});
|
createIndexConstant(rewriter, op->getLoc(), elementSize)});
|
||||||
|
|
||||||
// Insert the `malloc` declaration if it is not already present.
|
// Insert the `malloc` declaration if it is not already present.
|
||||||
FuncOp mallocFunc =
|
auto module = op->getParentOfType<ModuleOp>();
|
||||||
op->getParentOfType<FuncOp>().getModule().getNamedFunction("malloc");
|
FuncOp mallocFunc = module.getNamedFunction("malloc");
|
||||||
if (!mallocFunc) {
|
if (!mallocFunc) {
|
||||||
auto mallocType =
|
auto mallocType =
|
||||||
rewriter.getFunctionType(getIndexType(), getVoidPtrType());
|
rewriter.getFunctionType(getIndexType(), getVoidPtrType());
|
||||||
mallocFunc =
|
mallocFunc =
|
||||||
FuncOp::create(rewriter.getUnknownLoc(), "malloc", mallocType);
|
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
|
// 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);
|
OperandAdaptor<DeallocOp> transformed(operands);
|
||||||
|
|
||||||
// Insert the `free` declaration if it is not already present.
|
// Insert the `free` declaration if it is not already present.
|
||||||
FuncOp freeFunc =
|
FuncOp freeFunc = op->getParentOfType<ModuleOp>().getNamedFunction("free");
|
||||||
op->getParentOfType<FuncOp>().getModule().getNamedFunction("free");
|
|
||||||
if (!freeFunc) {
|
if (!freeFunc) {
|
||||||
auto freeType = rewriter.getFunctionType(getVoidPtrType(), {});
|
auto freeType = rewriter.getFunctionType(getVoidPtrType(), {});
|
||||||
freeFunc = FuncOp::create(rewriter.getUnknownLoc(), "free", freeType);
|
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>();
|
auto type = transformed.memref()->getType().cast<LLVM::LLVMType>();
|
||||||
|
|
|
@ -73,12 +73,6 @@ void FuncOp::build(Builder *builder, OperationState *result, StringRef name,
|
||||||
result->addAttribute(getArgAttrName(i, argAttrName), argDict);
|
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.
|
/// Parsing/Printing methods.
|
||||||
static ParseResult
|
static ParseResult
|
||||||
parseArgumentList(OpAsmParser *parser, SmallVectorImpl<Type> &argTypes,
|
parseArgumentList(OpAsmParser *parser, SmallVectorImpl<Type> &argTypes,
|
||||||
|
|
|
@ -575,7 +575,7 @@ public:
|
||||||
// types and returns pointers to the output types.
|
// types and returns pointers to the output types.
|
||||||
static FuncOp getLLVMLibraryCallImplDefinition(FuncOp libFn) {
|
static FuncOp getLLVMLibraryCallImplDefinition(FuncOp libFn) {
|
||||||
auto implFnName = (libFn.getName().str() + "_impl");
|
auto implFnName = (libFn.getName().str() + "_impl");
|
||||||
auto module = libFn.getModule();
|
auto module = libFn.getParentOfType<ModuleOp>();
|
||||||
if (auto f = module.getNamedFunction(implFnName)) {
|
if (auto f = module.getNamedFunction(implFnName)) {
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,7 +66,7 @@ static void printIR(const llvm::Any &ir, bool printModuleScope,
|
||||||
|
|
||||||
// Print the function name and a newline before the Module.
|
// Print the function name and a newline before the Module.
|
||||||
out << " (function: " << function.getName() << ")\n";
|
out << " (function: " << function.getName() << ")\n";
|
||||||
function.getModule().print(out);
|
function.getParentOfType<ModuleOp>().print(out);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -340,7 +340,7 @@ PassInstrumentor *FunctionAnalysisManager::getPassInstrumentor() const {
|
||||||
|
|
||||||
/// Create an analysis slice for the given child function.
|
/// Create an analysis slice for the given child function.
|
||||||
FunctionAnalysisManager ModuleAnalysisManager::slice(FuncOp func) {
|
FunctionAnalysisManager ModuleAnalysisManager::slice(FuncOp func) {
|
||||||
assert(func.getModule() == moduleAnalyses.getIRUnit() &&
|
assert(func.getOperation()->getParentOp() == moduleAnalyses.getIRUnit() &&
|
||||||
"function has a different parent module");
|
"function has a different parent module");
|
||||||
auto it = functionAnalyses.find(func);
|
auto it = functionAnalyses.find(func);
|
||||||
if (it == functionAnalyses.end()) {
|
if (it == functionAnalyses.end()) {
|
||||||
|
|
Loading…
Reference in New Issue