From 60b571e49a90d38697b3aca23020d9da42fc7d7f Mon Sep 17 00:00:00 2001 From: dim Date: Sun, 2 Apr 2017 17:24:58 +0000 Subject: Update clang, llvm, lld, lldb, compiler-rt and libc++ to 4.0.0 release: MFC r309142 (by emaste): Add WITH_LLD_AS_LD build knob If set it installs LLD as /usr/bin/ld. LLD (as of version 3.9) is not capable of linking the world and kernel, but can self-host and link many substantial applications. GNU ld continues to be used for the world and kernel build, regardless of how this knob is set. It is on by default for arm64, and off for all other CPU architectures. Sponsored by: The FreeBSD Foundation MFC r310840: Reapply 310775, now it also builds correctly if lldb is disabled: Move llvm-objdump from CLANG_EXTRAS to installed by default We currently install three tools from binutils 2.17.50: as, ld, and objdump. Work is underway to migrate to a permissively-licensed tool-chain, with one goal being the retirement of binutils 2.17.50. LLVM's llvm-objdump is intended to be compatible with GNU objdump although it is currently missing some options and may have formatting differences. Enable it by default for testing and further investigation. It may later be changed to install as /usr/bin/objdump, it becomes a fully viable replacement. Reviewed by: emaste Differential Revision: https://reviews.freebsd.org/D8879 MFC r312855 (by emaste): Rename LLD_AS_LD to LLD_IS_LD, for consistency with CLANG_IS_CC Reported by: Dan McGregor MFC r313559 | glebius | 2017-02-10 18:34:48 +0100 (Fri, 10 Feb 2017) | 5 lines Don't check struct rtentry on FreeBSD, it is an internal kernel structure. On other systems it may be API structure for SIOCADDRT/SIOCDELRT. Reviewed by: emaste, dim MFC r314152 (by jkim): Remove an assembler flag, which is redundant since r309124. The upstream took care of it by introducing a macro NO_EXEC_STACK_DIRECTIVE. http://llvm.org/viewvc/llvm-project?rev=273500&view=rev Reviewed by: dim MFC r314564: Upgrade our copies of clang, llvm, lld, lldb, compiler-rt and libc++ to 4.0.0 (branches/release_40 296509). The release will follow soon. Please note that from 3.5.0 onwards, clang, llvm and lldb require C++11 support to build; see UPDATING for more information. Also note that as of 4.0.0, lld should be able to link the base system on amd64 and aarch64. See the WITH_LLD_IS_LLD setting in src.conf(5). Though please be aware that this is work in progress. Release notes for llvm, clang and lld will be available here: Thanks to Ed Maste, Jan Beich, Antoine Brodin and Eric Fiselier for their help. Relnotes: yes Exp-run: antoine PR: 215969, 216008 MFC r314708: For now, revert r287232 from upstream llvm trunk (by Daniil Fukalov): [SCEV] limit recursion depth of CompareSCEVComplexity Summary: CompareSCEVComplexity goes too deep (50+ on a quite a big unrolled loop) and runs almost infinite time. Added cache of "equal" SCEV pairs to earlier cutoff of further estimation. Recursion depth limit was also introduced as a parameter. Reviewers: sanjoy Subscribers: mzolotukhin, tstellarAMD, llvm-commits Differential Revision: https://reviews.llvm.org/D26389 This commit is the cause of excessive compile times on skein_block.c (and possibly other files) during kernel builds on amd64. We never saw the problematic behavior described in this upstream commit, so for now it is better to revert it. An upstream bug has been filed here: https://bugs.llvm.org/show_bug.cgi?id=32142 Reported by: mjg MFC r314795: Reapply r287232 from upstream llvm trunk (by Daniil Fukalov): [SCEV] limit recursion depth of CompareSCEVComplexity Summary: CompareSCEVComplexity goes too deep (50+ on a quite a big unrolled loop) and runs almost infinite time. Added cache of "equal" SCEV pairs to earlier cutoff of further estimation. Recursion depth limit was also introduced as a parameter. Reviewers: sanjoy Subscribers: mzolotukhin, tstellarAMD, llvm-commits Differential Revision: https://reviews.llvm.org/D26389 Pull in r296992 from upstream llvm trunk (by Sanjoy Das): [SCEV] Decrease the recursion threshold for CompareValueComplexity Fixes PR32142. r287232 accidentally increased the recursion threshold for CompareValueComplexity from 2 to 32. This change reverses that change by introducing a separate flag for CompareValueComplexity's threshold. The latter revision fixes the excessive compile times for skein_block.c. MFC r314907 | mmel | 2017-03-08 12:40:27 +0100 (Wed, 08 Mar 2017) | 7 lines Unbreak ARMv6 world. The new compiler_rt library imported with clang 4.0.0 have several fatal issues (non-functional __udivsi3 for example) with ARM specific instrict functions. As temporary workaround, until upstream solve these problems, disable all thumb[1][2] related feature. MFC r315016: Update clang, llvm, lld, lldb, compiler-rt and libc++ to 4.0.0 release. We were already very close to the last release candidate, so this is a pretty minor update. Relnotes: yes MFC r316005: Revert r314907, and pull in r298713 from upstream compiler-rt trunk (by Weiming Zhao): builtins: Select correct code fragments when compiling for Thumb1/Thum2/ARM ISA. Summary: Value of __ARM_ARCH_ISA_THUMB isn't based on the actual compilation mode (-mthumb, -marm), it reflect's capability of given CPU. Due to this: - use __tbumb__ and __thumb2__ insteand of __ARM_ARCH_ISA_THUMB - use '.thumb' directive consistently in all affected files - decorate all thumb functions using DEFINE_COMPILERRT_THUMB_FUNCTION() --------- Note: This patch doesn't fix broken Thumb1 variant of __udivsi3 ! Reviewers: weimingz, rengolin, compnerd Subscribers: aemerson, dim Differential Revision: https://reviews.llvm.org/D30938 Discussed with: mmel --- .../llvm/tools/llvm-cov/CoverageExporterJson.cpp | 421 +++++++++++++++++++++ 1 file changed, 421 insertions(+) create mode 100644 contrib/llvm/tools/llvm-cov/CoverageExporterJson.cpp (limited to 'contrib/llvm/tools/llvm-cov/CoverageExporterJson.cpp') diff --git a/contrib/llvm/tools/llvm-cov/CoverageExporterJson.cpp b/contrib/llvm/tools/llvm-cov/CoverageExporterJson.cpp new file mode 100644 index 0000000..ef50bba --- /dev/null +++ b/contrib/llvm/tools/llvm-cov/CoverageExporterJson.cpp @@ -0,0 +1,421 @@ +//===- CoverageExporterJson.cpp - Code coverage export --------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file implements export of code coverage data to JSON. +// +//===----------------------------------------------------------------------===// + +//===----------------------------------------------------------------------===// +// +// The json code coverage export follows the following format +// Root: dict => Root Element containing metadata +// -- Data: array => Homogeneous array of one or more export objects +// ---- Export: dict => Json representation of one CoverageMapping +// ------ Files: array => List of objects describing coverage for files +// -------- File: dict => Coverage for a single file +// ---------- Segments: array => List of Segments contained in the file +// ------------ Segment: dict => Describes a segment of the file with a counter +// ---------- Expansions: array => List of expansion records +// ------------ Expansion: dict => Object that descibes a single expansion +// -------------- CountedRegion: dict => The region to be expanded +// -------------- TargetRegions: array => List of Regions in the expansion +// ---------------- CountedRegion: dict => Single Region in the expansion +// ---------- Summary: dict => Object summarizing the coverage for this file +// ------------ LineCoverage: dict => Object summarizing line coverage +// ------------ FunctionCoverage: dict => Object summarizing function coverage +// ------------ RegionCoverage: dict => Object summarizing region coverage +// ------ Functions: array => List of objects describing coverage for functions +// -------- Function: dict => Coverage info for a single function +// ---------- Filenames: array => List of filenames that the function relates to +// ---- Summary: dict => Object summarizing the coverage for the entire binary +// ------ LineCoverage: dict => Object summarizing line coverage +// ------ FunctionCoverage: dict => Object summarizing function coverage +// ------ InstantiationCoverage: dict => Object summarizing inst. coverage +// ------ RegionCoverage: dict => Object summarizing region coverage +// +//===----------------------------------------------------------------------===// + +#include "CoverageReport.h" +#include "CoverageSummaryInfo.h" +#include "CoverageViewOptions.h" +#include "llvm/ProfileData/Coverage/CoverageMapping.h" +#include + +/// \brief The semantic version combined as a string. +#define LLVM_COVERAGE_EXPORT_JSON_STR "2.0.0" + +/// \brief Unique type identifier for JSON coverage export. +#define LLVM_COVERAGE_EXPORT_JSON_TYPE_STR "llvm.coverage.json.export" + +using namespace llvm; +using namespace coverage; + +class CoverageExporterJson { + /// \brief Output stream to print JSON to. + raw_ostream &OS; + + /// \brief The full CoverageMapping object to export. + const CoverageMapping &Coverage; + + /// \brief States that the JSON rendering machine can be in. + enum JsonState { None, NonEmptyElement, EmptyElement }; + + /// \brief Tracks state of the JSON output. + std::stack State; + + /// \brief Emit a serialized scalar. + void emitSerialized(const int64_t Value) { OS << Value; } + + /// \brief Emit a serialized string. + void emitSerialized(const std::string &Value) { + OS << "\""; + for (char C : Value) { + if (C != '\\') + OS << C; + else + OS << "\\\\"; + } + OS << "\""; + } + + /// \brief Emit a comma if there is a previous element to delimit. + void emitComma() { + if (State.top() == JsonState::NonEmptyElement) { + OS << ","; + } else if (State.top() == JsonState::EmptyElement) { + State.pop(); + assert((State.size() >= 1) && "Closed too many JSON elements"); + State.push(JsonState::NonEmptyElement); + } + } + + /// \brief Emit a starting dictionary/object character. + void emitDictStart() { + emitComma(); + State.push(JsonState::EmptyElement); + OS << "{"; + } + + /// \brief Emit a dictionary/object key but no value. + void emitDictKey(const std::string &Key) { + emitComma(); + emitSerialized(Key); + OS << ":"; + State.pop(); + assert((State.size() >= 1) && "Closed too many JSON elements"); + + // We do not want to emit a comma after this key. + State.push(JsonState::EmptyElement); + } + + /// \brief Emit a dictionary/object key/value pair. + template + void emitDictElement(const std::string &Key, const V &Value) { + emitComma(); + emitSerialized(Key); + OS << ":"; + emitSerialized(Value); + } + + /// \brief Emit a closing dictionary/object character. + void emitDictEnd() { + State.pop(); + assert((State.size() >= 1) && "Closed too many JSON elements"); + OS << "}"; + } + + /// \brief Emit a starting array character. + void emitArrayStart() { + emitComma(); + State.push(JsonState::EmptyElement); + OS << "["; + } + + /// \brief Emit an array element. + template void emitArrayElement(const V &Value) { + emitComma(); + emitSerialized(Value); + } + + /// \brief emit a closing array character. + void emitArrayEnd() { + State.pop(); + assert((State.size() >= 1) && "Closed too many JSON elements"); + OS << "]"; + } + + /// \brief Render the CoverageMapping object. + void renderRoot() { + // Start Root of JSON object. + emitDictStart(); + + emitDictElement("version", LLVM_COVERAGE_EXPORT_JSON_STR); + emitDictElement("type", LLVM_COVERAGE_EXPORT_JSON_TYPE_STR); + emitDictKey("data"); + + // Start List of Exports. + emitArrayStart(); + + // Start Export. + emitDictStart(); + + emitDictKey("files"); + + FileCoverageSummary Totals = FileCoverageSummary("Totals"); + std::vector SourceFiles; + for (StringRef SF : Coverage.getUniqueSourceFiles()) + SourceFiles.emplace_back(SF); + auto FileReports = + CoverageReport::prepareFileReports(Coverage, Totals, SourceFiles); + renderFiles(SourceFiles, FileReports); + + emitDictKey("functions"); + renderFunctions(Coverage.getCoveredFunctions()); + + emitDictKey("totals"); + renderSummary(Totals); + + // End Export. + emitDictEnd(); + + // End List of Exports. + emitArrayEnd(); + + // End Root of JSON Object. + emitDictEnd(); + + assert((State.top() == JsonState::None) && + "All Elements In JSON were Closed"); + } + + /// \brief Render an array of all the given functions. + void + renderFunctions(const iterator_range &Functions) { + // Start List of Functions. + emitArrayStart(); + + for (const auto &Function : Functions) { + // Start Function. + emitDictStart(); + + emitDictElement("name", Function.Name); + emitDictElement("count", Function.ExecutionCount); + emitDictKey("regions"); + + renderRegions(Function.CountedRegions); + + emitDictKey("filenames"); + + // Start Filenames for Function. + emitArrayStart(); + + for (const auto &FileName : Function.Filenames) + emitArrayElement(FileName); + + // End Filenames for Function. + emitArrayEnd(); + + // End Function. + emitDictEnd(); + } + + // End List of Functions. + emitArrayEnd(); + } + + /// \brief Render an array of all the source files, also pass back a Summary. + void renderFiles(ArrayRef SourceFiles, + ArrayRef FileReports) { + // Start List of Files. + emitArrayStart(); + + for (unsigned I = 0, E = SourceFiles.size(); I < E; ++I) { + // Render the file. + auto FileCoverage = Coverage.getCoverageForFile(SourceFiles[I]); + renderFile(FileCoverage, FileReports[I]); + } + + // End List of Files. + emitArrayEnd(); + } + + /// \brief Render a single file. + void renderFile(const CoverageData &FileCoverage, + const FileCoverageSummary &FileReport) { + // Start File. + emitDictStart(); + + emitDictElement("filename", FileCoverage.getFilename()); + emitDictKey("segments"); + + // Start List of Segments. + emitArrayStart(); + + for (const auto &Segment : FileCoverage) + renderSegment(Segment); + + // End List of Segments. + emitArrayEnd(); + + emitDictKey("expansions"); + + // Start List of Expansions. + emitArrayStart(); + + for (const auto &Expansion : FileCoverage.getExpansions()) + renderExpansion(Expansion); + + // End List of Expansions. + emitArrayEnd(); + + emitDictKey("summary"); + renderSummary(FileReport); + + // End File. + emitDictEnd(); + } + + /// \brief Render a CoverageSegment. + void renderSegment(const CoverageSegment &Segment) { + // Start Segment. + emitArrayStart(); + + emitArrayElement(Segment.Line); + emitArrayElement(Segment.Col); + emitArrayElement(Segment.Count); + emitArrayElement(Segment.HasCount); + emitArrayElement(Segment.IsRegionEntry); + + // End Segment. + emitArrayEnd(); + } + + /// \brief Render an ExpansionRecord. + void renderExpansion(const ExpansionRecord &Expansion) { + // Start Expansion. + emitDictStart(); + + // Mark the beginning and end of this expansion in the source file. + emitDictKey("source_region"); + renderRegion(Expansion.Region); + + // Enumerate the coverage information for the expansion. + emitDictKey("target_regions"); + renderRegions(Expansion.Function.CountedRegions); + + emitDictKey("filenames"); + // Start List of Filenames to map the fileIDs. + emitArrayStart(); + for (const auto &Filename : Expansion.Function.Filenames) + emitArrayElement(Filename); + // End List of Filenames. + emitArrayEnd(); + + // End Expansion. + emitDictEnd(); + } + + /// \brief Render a list of CountedRegions. + void renderRegions(ArrayRef Regions) { + // Start List of Regions. + emitArrayStart(); + + for (const auto &Region : Regions) + renderRegion(Region); + + // End List of Regions. + emitArrayEnd(); + } + + /// \brief Render a single CountedRegion. + void renderRegion(const CountedRegion &Region) { + // Start CountedRegion. + emitArrayStart(); + + emitArrayElement(Region.LineStart); + emitArrayElement(Region.ColumnStart); + emitArrayElement(Region.LineEnd); + emitArrayElement(Region.ColumnEnd); + emitArrayElement(Region.ExecutionCount); + emitArrayElement(Region.FileID); + emitArrayElement(Region.ExpandedFileID); + emitArrayElement(Region.Kind); + + // End CountedRegion. + emitArrayEnd(); + } + + /// \brief Render a FileCoverageSummary. + void renderSummary(const FileCoverageSummary &Summary) { + // Start Summary for the file. + emitDictStart(); + + emitDictKey("lines"); + + // Start Line Coverage Summary. + emitDictStart(); + emitDictElement("count", Summary.LineCoverage.NumLines); + emitDictElement("covered", Summary.LineCoverage.Covered); + emitDictElement("percent", Summary.LineCoverage.getPercentCovered()); + // End Line Coverage Summary. + emitDictEnd(); + + emitDictKey("functions"); + + // Start Function Coverage Summary. + emitDictStart(); + emitDictElement("count", Summary.FunctionCoverage.NumFunctions); + emitDictElement("covered", Summary.FunctionCoverage.Executed); + emitDictElement("percent", Summary.FunctionCoverage.getPercentCovered()); + // End Function Coverage Summary. + emitDictEnd(); + + emitDictKey("instantiations"); + + // Start Instantiation Coverage Summary. + emitDictStart(); + emitDictElement("count", Summary.InstantiationCoverage.NumFunctions); + emitDictElement("covered", Summary.InstantiationCoverage.Executed); + emitDictElement("percent", + Summary.InstantiationCoverage.getPercentCovered()); + // End Function Coverage Summary. + emitDictEnd(); + + emitDictKey("regions"); + + // Start Region Coverage Summary. + emitDictStart(); + emitDictElement("count", Summary.RegionCoverage.NumRegions); + emitDictElement("covered", Summary.RegionCoverage.Covered); + emitDictElement("notcovered", Summary.RegionCoverage.NotCovered); + emitDictElement("percent", Summary.RegionCoverage.getPercentCovered()); + // End Region Coverage Summary. + emitDictEnd(); + + // End Summary for the file. + emitDictEnd(); + } + +public: + CoverageExporterJson(const CoverageMapping &CoverageMapping, raw_ostream &OS) + : OS(OS), Coverage(CoverageMapping) { + State.push(JsonState::None); + } + + /// \brief Print the CoverageMapping. + void print() { renderRoot(); } +}; + +/// \brief Export the given CoverageMapping to a JSON Format. +void exportCoverageDataToJson(const CoverageMapping &CoverageMapping, + raw_ostream &OS) { + auto Exporter = CoverageExporterJson(CoverageMapping, OS); + + Exporter.print(); +} -- cgit v1.1