Files
swift-mirror/lib/SILOptimizer/UtilityPasses/CallerAnalysisPrinter.cpp
Michael Gottesman 3051cd3f60 [caller-analysis] Change the dumping format to be a yaml format and update tests to use that format.
The current dumping format consists of 1 row of information per function. This
will become unweildy to write patterns for when I add additional state to
FunctionInfo.

Instead, this commit converts the dumping format of the caller analysis into a
multi line yaml format. This yaml format looks as follows:

  ---
  calleeName:      closure1
  hasCaller:       false
  minPartialAppliedArgs: 1
  partialAppliers:
    - partial_apply_one_arg
    - partial_apply_two_args1
  fullAppliers:
  ...

This can easily expand over time as we expand the queries that caller analysis
can answer.

As an additional advantage, there are definitely yaml parsers that can handle
multiple yaml documents in sequence in a stream. This means that by running via
sil-opt the caller-analysis-printer pass, one now will get a yaml description of
the caller analysis state, perfect and ready for analysis.
2018-07-12 22:43:23 -07:00

46 lines
1.5 KiB
C++

//===--- CallerAnalysisPrinter.cpp - Caller Analysis test pass ------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
//
// This pass prints all the callsites of every function in the module.
//
//===----------------------------------------------------------------------===//
#include "swift/SIL/SILFunction.h"
#include "swift/SIL/SILModule.h"
#include "swift/SILOptimizer/Analysis/CallerAnalysis.h"
#include "swift/SILOptimizer/PassManager/Transforms.h"
#include "llvm/Support/YAMLTraits.h"
#include "llvm/Support/raw_ostream.h"
using namespace swift;
#define DEBUG_TYPE "caller-analysis-printer"
namespace {
/// A pass that dumps the caller analysis state in yaml form. Intended to allow
/// for visualizing of the caller analysis via external data visualization and
/// analysis programs.
class CallerAnalysisPrinterPass : public SILModuleTransform {
/// The entry point to the transformation.
void run() override {
auto *CA = getAnalysis<CallerAnalysis>();
CA->print(llvm::outs());
}
};
} // end anonymous namespace
SILTransform *swift::createCallerAnalysisPrinter() {
return new CallerAnalysisPrinterPass();
}