Skip to content

Commit 4fb0a4d

Browse files
committed
[CIR][Transforms][NFC] Use unique_ptr to capsule LowerModule
1 parent d047947 commit 4fb0a4d

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

clang/lib/CIR/Dialect/Transforms/CallConvLowering.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,22 @@ struct CallConvLoweringPattern : public OpRewritePattern<FuncOp> {
3636
return op.emitError("function has no AST information");
3737

3838
auto modOp = op->getParentOfType<ModuleOp>();
39-
LowerModule lowerModule = createLowerModule(modOp, rewriter);
39+
auto lowerModule = createLowerModule(modOp, rewriter);
4040

4141
// Rewrite function calls before definitions. This should be done before
4242
// lowering the definition.
4343
auto calls = op.getSymbolUses(module);
4444
if (calls.has_value()) {
4545
for (auto call : calls.value()) {
4646
auto callOp = cast<CallOp>(call.getUser());
47-
if (lowerModule.rewriteFunctionCall(callOp, op).failed())
47+
if (lowerModule->rewriteFunctionCall(callOp, op).failed())
4848
return failure();
4949
}
5050
}
5151

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

5757
return success();

clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerModule.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,8 @@ LogicalResult LowerModule::rewriteFunctionCall(CallOp callOp, FuncOp funcOp) {
217217
}
218218

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

240-
return LowerModule(context, module, dataLayoutStr, *targetInfo, rewriter);
241+
return std::make_unique<LowerModule>(context, module, dataLayoutStr,
242+
*targetInfo, rewriter);
241243
}
242244

243245
} // namespace cir

clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerModule.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ class LowerModule {
9191
LogicalResult rewriteFunctionCall(CallOp callOp, FuncOp funcOp);
9292
};
9393

94-
LowerModule createLowerModule(ModuleOp module, PatternRewriter &rewriter);
94+
std::unique_ptr<LowerModule> createLowerModule(ModuleOp module,
95+
PatternRewriter &rewriter);
9596

9697
} // namespace cir
9798
} // namespace mlir

0 commit comments

Comments
 (0)