mirror of
https://github.com/intel/llvm.git
synced 2026-02-08 17:28:30 +08:00
NFC: Refactor Module to be value typed.
As with Functions, Module will soon become an operation, which are value-typed. This eases the transition from Module to ModuleOp. A new class, OwningModuleRef is provided to allow for owning a reference to a Module, and will auto-delete the held module on destruction. PiperOrigin-RevId: 256196193
This commit is contained in:
committed by
Mehdi Amini
parent
b4a2dbc8b6
commit
206e55cc16
@@ -442,13 +442,13 @@ struct AllocOpLowering : public LLVMLegalizationPattern<AllocOp> {
|
||||
|
||||
// Insert the `malloc` declaration if it is not already present.
|
||||
Function mallocFunc =
|
||||
op->getFunction().getModule()->getNamedFunction("malloc");
|
||||
op->getFunction().getModule().getNamedFunction("malloc");
|
||||
if (!mallocFunc) {
|
||||
auto mallocType =
|
||||
rewriter.getFunctionType(getIndexType(), getVoidPtrType());
|
||||
mallocFunc =
|
||||
Function::create(rewriter.getUnknownLoc(), "malloc", mallocType);
|
||||
op->getFunction().getModule()->push_back(mallocFunc);
|
||||
op->getFunction().getModule().push_back(mallocFunc);
|
||||
}
|
||||
|
||||
// Allocate the underlying buffer and store a pointer to it in the MemRef
|
||||
@@ -503,11 +503,11 @@ struct DeallocOpLowering : public LLVMLegalizationPattern<DeallocOp> {
|
||||
OperandAdaptor<DeallocOp> transformed(operands);
|
||||
|
||||
// Insert the `free` declaration if it is not already present.
|
||||
Function freeFunc = op->getFunction().getModule()->getNamedFunction("free");
|
||||
Function freeFunc = op->getFunction().getModule().getNamedFunction("free");
|
||||
if (!freeFunc) {
|
||||
auto freeType = rewriter.getFunctionType(getVoidPtrType(), {});
|
||||
freeFunc = Function::create(rewriter.getUnknownLoc(), "free", freeType);
|
||||
op->getFunction().getModule()->push_back(freeFunc);
|
||||
op->getFunction().getModule().push_back(freeFunc);
|
||||
}
|
||||
|
||||
auto type = transformed.memref()->getType().cast<LLVM::LLVMType>();
|
||||
@@ -936,8 +936,8 @@ static void ensureDistinctSuccessors(Block &bb) {
|
||||
}
|
||||
}
|
||||
|
||||
void mlir::LLVM::ensureDistinctSuccessors(Module *m) {
|
||||
for (auto f : *m) {
|
||||
void mlir::LLVM::ensureDistinctSuccessors(Module m) {
|
||||
for (auto f : m) {
|
||||
for (auto &bb : f.getBlocks()) {
|
||||
::ensureDistinctSuccessors(bb);
|
||||
}
|
||||
@@ -1010,8 +1010,8 @@ namespace {
|
||||
struct LLVMLoweringPass : public ModulePass<LLVMLoweringPass> {
|
||||
// Run the dialect converter on the module.
|
||||
void runOnModule() override {
|
||||
Module &m = getModule();
|
||||
LLVM::ensureDistinctSuccessors(&m);
|
||||
Module m = getModule();
|
||||
LLVM::ensureDistinctSuccessors(m);
|
||||
|
||||
LLVMTypeConverter converter(&getContext());
|
||||
OwningRewritePatternList patterns;
|
||||
|
||||
Reference in New Issue
Block a user