Skip to content

[CIR][Transforms][NFC] Use unique_ptr to encapsulate LowerModule #752

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions clang/lib/CIR/Dialect/Transforms/CallConvLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,23 @@ struct CallConvLoweringPattern : public OpRewritePattern<FuncOp> {
return op.emitError("function has no AST information");

auto modOp = op->getParentOfType<ModuleOp>();
LowerModule lowerModule = createLowerModule(modOp, rewriter);
std::unique_ptr<LowerModule> lowerModule =
createLowerModule(modOp, rewriter);

// Rewrite function calls before definitions. This should be done before
// lowering the definition.
auto calls = op.getSymbolUses(module);
if (calls.has_value()) {
for (auto call : calls.value()) {
auto callOp = cast<CallOp>(call.getUser());
if (lowerModule.rewriteFunctionCall(callOp, op).failed())
if (lowerModule->rewriteFunctionCall(callOp, op).failed())
return failure();
}
}

// TODO(cir): Instead of re-emmiting every load and store, bitcast arguments
// and return values to their ABI-specific counterparts when possible.
if (lowerModule.rewriteFunctionDefinition(op).failed())
if (lowerModule->rewriteFunctionDefinition(op).failed())
return failure();

return success();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,8 @@ LogicalResult LowerModule::rewriteFunctionCall(CallOp callOp, FuncOp funcOp) {
}

// TODO: not to create it every time
LowerModule createLowerModule(ModuleOp module, PatternRewriter &rewriter) {
std::unique_ptr<LowerModule> createLowerModule(ModuleOp module,
PatternRewriter &rewriter) {
// Fetch the LLVM data layout string.
auto dataLayoutStr = cast<StringAttr>(
module->getAttr(LLVM::LLVMDialect::getDataLayoutAttrName()));
Expand All @@ -237,7 +238,8 @@ LowerModule createLowerModule(ModuleOp module, PatternRewriter &rewriter) {
auto context = CIRLowerContext(module, langOpts);
context.initBuiltinTypes(*targetInfo);

return LowerModule(context, module, dataLayoutStr, *targetInfo, rewriter);
return std::make_unique<LowerModule>(context, module, dataLayoutStr,
*targetInfo, rewriter);
}

} // namespace cir
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ class LowerModule {
LogicalResult rewriteFunctionCall(CallOp callOp, FuncOp funcOp);
};

LowerModule createLowerModule(ModuleOp module, PatternRewriter &rewriter);
std::unique_ptr<LowerModule> createLowerModule(ModuleOp module,
PatternRewriter &rewriter);

} // namespace cir
} // namespace mlir
Expand Down
Loading