2021-09-29 05:17:27 +08:00
|
|
|
//===-- examples/flang-omp-report-plugin/flang-omp-report.cpp -------------===//
|
|
|
|
//
|
|
|
|
// 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
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2022-03-04 21:05:21 +08:00
|
|
|
// This plugin parses a Fortran source file and generates a YAML report with
|
|
|
|
// all the OpenMP constructs and clauses and which line they're located on.
|
2021-09-29 05:17:27 +08:00
|
|
|
//
|
|
|
|
// The plugin may be invoked as:
|
2022-03-04 21:05:21 +08:00
|
|
|
// ./bin/flang-new -fc1 -load lib/flangOmpReport.so -plugin flang-omp-report
|
|
|
|
// -fopenmp
|
2021-09-29 05:17:27 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2022-01-11 21:16:03 +08:00
|
|
|
#include "FlangOmpReportVisitor.h"
|
2021-09-29 05:17:27 +08:00
|
|
|
|
|
|
|
#include "flang/Frontend/FrontendActions.h"
|
|
|
|
#include "flang/Frontend/FrontendPluginRegistry.h"
|
|
|
|
#include "flang/Parser/dump-parse-tree.h"
|
|
|
|
#include "llvm/Support/YAMLParser.h"
|
|
|
|
#include "llvm/Support/YAMLTraits.h"
|
|
|
|
|
|
|
|
using namespace Fortran::frontend;
|
|
|
|
using namespace Fortran::parser;
|
|
|
|
|
|
|
|
LLVM_YAML_IS_SEQUENCE_VECTOR(LogRecord)
|
|
|
|
LLVM_YAML_IS_SEQUENCE_VECTOR(ClauseInfo)
|
|
|
|
namespace llvm {
|
|
|
|
namespace yaml {
|
|
|
|
using llvm::yaml::IO;
|
|
|
|
using llvm::yaml::MappingTraits;
|
|
|
|
template <> struct MappingTraits<ClauseInfo> {
|
|
|
|
static void mapping(IO &io, ClauseInfo &info) {
|
|
|
|
io.mapRequired("clause", info.clause);
|
|
|
|
io.mapRequired("details", info.clauseDetails);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
template <> struct MappingTraits<LogRecord> {
|
|
|
|
static void mapping(IO &io, LogRecord &info) {
|
|
|
|
io.mapRequired("file", info.file);
|
|
|
|
io.mapRequired("line", info.line);
|
|
|
|
io.mapRequired("construct", info.construct);
|
|
|
|
io.mapRequired("clauses", info.clauses);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
} // namespace yaml
|
|
|
|
} // namespace llvm
|
|
|
|
|
|
|
|
class FlangOmpReport : public PluginParseTreeAction {
|
2022-05-16 01:53:09 +08:00
|
|
|
void executeAction() override {
|
2021-09-29 05:17:27 +08:00
|
|
|
// Prepare the parse tree and the visitor
|
2022-03-04 21:05:21 +08:00
|
|
|
Parsing &parsing = getParsing();
|
2021-09-29 05:17:27 +08:00
|
|
|
OpenMPCounterVisitor visitor;
|
|
|
|
visitor.parsing = &parsing;
|
|
|
|
|
|
|
|
// Walk the parse tree
|
2022-03-04 21:05:21 +08:00
|
|
|
Walk(parsing.parseTree(), visitor);
|
2021-09-29 05:17:27 +08:00
|
|
|
|
|
|
|
// Dump the output
|
2022-03-04 21:05:21 +08:00
|
|
|
std::unique_ptr<llvm::raw_pwrite_stream> OS{
|
|
|
|
createOutputFile(/*extension=*/"yaml")};
|
2021-09-29 05:17:27 +08:00
|
|
|
llvm::yaml::Output yout(*OS);
|
2022-03-04 21:05:21 +08:00
|
|
|
|
2021-09-29 05:17:27 +08:00
|
|
|
yout << visitor.constructClauses;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static FrontendPluginRegistry::Add<FlangOmpReport> X("flang-omp-report",
|
|
|
|
"Generate a YAML summary of OpenMP constructs and clauses");
|