llvm-project/llvm/lib/Transforms/Scalar/LoopAccessAnalysisPrinter.cpp
Ramkumar Ramachandra 4c01a58008
update_analyze_test_checks: support output from LAA (#67584)
update_analyze_test_checks.py is an invaluable tool in updating tests.
Unfortunately, it only supports output from the CostModel,
ScalarEvolution, and LoopVectorize analyses. Many LoopAccessAnalysis
tests use hand-crafted CHECK lines, and it is moreover tedious to
generate these CHECK lines, as the output fom the analysis is not
stable, and requires the test-writer to hand-craft FileCheck matches.
Alleviate this pain, and support output from:

  $ opt -passes='print<loop-accesses>'

This patch includes several non-trivial changes including:
- Preserving whitespace at the beginning of the line, so that the LAA
output can be properly indented.
- Regexes matching the unstable output, which is basically a pointer
address hex.
- Separating is_analyze from preserve_names clearly, as the former was
formerly used as an overload for the latter.

To demonstate the utility of this patch, several tests in
LoopAccessAnalysis have been auto-generated by
update_analyze_test_checks.py.
2023-10-31 14:33:53 +00:00

35 lines
1.2 KiB
C++

//===- LoopAccessAnalysisPrinter.cpp - Loop Access Analysis Printer --------==//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "llvm/Transforms/Scalar/LoopAccessAnalysisPrinter.h"
#include "llvm/ADT/PriorityWorklist.h"
#include "llvm/Analysis/LoopAccessAnalysis.h"
#include "llvm/Analysis/LoopInfo.h"
#include "llvm/Transforms/Utils/LoopUtils.h"
using namespace llvm;
#define DEBUG_TYPE "loop-accesses"
PreservedAnalyses LoopAccessInfoPrinterPass::run(Function &F,
FunctionAnalysisManager &AM) {
auto &LAIs = AM.getResult<LoopAccessAnalysis>(F);
auto &LI = AM.getResult<LoopAnalysis>(F);
OS << "Printing analysis 'Loop Access Analysis' for function '" << F.getName()
<< "':\n";
SmallPriorityWorklist<Loop *, 4> Worklist;
appendLoopsToWorklist(LI, Worklist);
while (!Worklist.empty()) {
Loop *L = Worklist.pop_back_val();
OS.indent(2) << L->getHeader()->getName() << ":\n";
LAIs.getInfo(*L).print(OS, 4);
}
return PreservedAnalyses::all();
}