[midend-LoopAnalysis]为项目添加别名分析遍,副作用分析遍,循环分析遍,循环特征分析遍

This commit is contained in:
rain2133
2025-08-08 00:56:50 +08:00
parent bd02f5f1eb
commit b1a46b7d58
12 changed files with 2166 additions and 53 deletions

View File

@@ -290,16 +290,14 @@ bool LoopAnalysisPass::runOnFunction(Function *F, AnalysisManager &AM) {
}
}
// 3. 计算循环层级 (Level) 并填充最外层/最内层循环列表
// 3. 计算循环层级 (Level)
std::queue<Loop *> q_level;
// 查找所有最外层循环没有父循环的设置其层级为0并加入队列
CurrentResult->clearOutermostLoops(); // 清空最外层循环列表
for (const auto &loop_ptr : allLoops) {
if (loop_ptr->isOutermost()) {
loop_ptr->setLoopLevel(0);
q_level.push(loop_ptr.get());
CurrentResult->addOutermostLoop(loop_ptr.get());
}
}
@@ -314,12 +312,24 @@ bool LoopAnalysisPass::runOnFunction(Function *F, AnalysisManager &AM) {
}
}
// 填充最内层循环列表
CurrentResult->clearInnermostLoops(); // 清空最内层循环列表
for (const auto &loop_ptr : allLoops) {
if (loop_ptr->isInnermost()) {
CurrentResult->addInnermostLoop(loop_ptr.get());
if (DEBUG) {
std::cout << "Loop Analysis completed for function: " << F->getName() << std::endl;
std::cout << "Total loops found: " << CurrentResult->getLoopCount() << std::endl;
std::cout << "Max loop depth: " << CurrentResult->getMaxLoopDepth() << std::endl;
std::cout << "Innermost loops: " << CurrentResult->getInnermostLoops().size() << std::endl;
std::cout << "Outermost loops: " << CurrentResult->getOutermostLoops().size() << std::endl;
// 打印各深度的循环分布
for (int depth = 1; depth <= CurrentResult->getMaxLoopDepth(); ++depth) {
int count = CurrentResult->getLoopCountAtDepth(depth);
if (count > 0) {
std::cout << "Loops at depth " << depth << ": " << count << std::endl;
}
}
// 输出缓存统计
auto cacheStats = CurrentResult->getCacheStats();
std::cout << "Cache statistics - Total cached queries: " << cacheStats.totalCachedQueries << std::endl;
}
return changed;