Skip to content
This repository was archived by the owner on Feb 21, 2026. It is now read-only.

Commit 1282ab8

Browse files
bcardosolopesTommy McMichen
andcommitted
[CIR] Add live object analysis pass
Add a backward dataflow analysis that computes object liveness at each program point using points-to information. The analysis determines when objects are last used, supporting control flow constructs including loops, gotos, and region-based operations. Includes diagnostic pass for emitting last-use remarks and cir-opt integration. Co-authored-by: Tommy McMichen <tommymcmichen@fb.com>
1 parent 2a4fc44 commit 1282ab8

10 files changed

Lines changed: 784 additions & 0 deletions

File tree

clang/include/clang/CIR/Dialect/Passes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ std::unique_ptr<Pass> createLoweringPreparePass(clang::ASTContext *astCtx);
3535
std::unique_ptr<Pass> createIdiomRecognizerPass();
3636
std::unique_ptr<Pass> createIdiomRecognizerPass(clang::ASTContext *astCtx);
3737
std::unique_ptr<Pass> createPointsToDiagnosticPass();
38+
std::unique_ptr<Pass> createLiveObjectDiagnosticPass();
3839
std::unique_ptr<Pass> createLibOptPass();
3940
std::unique_ptr<Pass> createLibOptPass(clang::ASTContext *astCtx);
4041
std::unique_ptr<Pass> createFlattenCFGPass();

clang/include/clang/CIR/Dialect/Passes.td

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,15 @@ def PointsToDiagnostic : Pass<"cir-points-to-diagnostics"> {
156156
let dependentDialects = ["cir::CIRDialect"];
157157
}
158158

159+
def LiveObjectDiagnostic : Pass<"cir-live-object-diagnostics"> {
160+
let summary = "Dump live-object information";
161+
let description = [{
162+
Dump live-object information for all reads/writes in the function.
163+
}];
164+
let constructor = "mlir::createLiveObjectDiagnosticPass()";
165+
let dependentDialects = ["cir::CIRDialect"];
166+
}
167+
159168
def IdiomRecognizer : Pass<"cir-idiom-recognizer"> {
160169
let summary = "Raise calls to C/C++ libraries to CIR operations";
161170
let description = [{

clang/lib/CIR/Dialect/Transforms/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ add_clang_library(MLIRCIRTransforms
1616
CallConvLowering.cpp
1717
HoistAllocas.cpp
1818
PointsToAnalysis.cpp
19+
LiveObjectAnalysis.cpp
1920
StdLibStatistics.cpp
2021

2122
DEPENDS

0 commit comments

Comments
 (0)