From 972459e6ed229456d011c93773bcc16de7f85ded Mon Sep 17 00:00:00 2001 From: Francis Visoiu Mistrih Date: Wed, 3 Jul 2019 22:40:07 +0000 Subject: [PATCH] [Bitcode] Move Bitstream to a separate library This moves Bitcode/Bitstream*, Bitcode/BitCodes.h to Bitstream/. This is needed to avoid a circular dependency when using the bitstream code for parsing optimization remarks. Since Bitcode uses Core for the IR part: libLLVMRemarks -> Bitcode -> Core and Core uses libLLVMRemarks to generate remarks (see IR/RemarkStreamer.cpp): Core -> libLLVMRemarks we need to separate the Bitstream and Bitcode part. For clang-doc, it seems that it doesn't need the whole bitcode layer, so I updated the CMake to only use the bitstream part. Differential Revision: https://reviews.llvm.org/D63899 llvm-svn: 365091 --- include/llvm/Bitcode/BitcodeReader.h | 2 +- include/llvm/Bitcode/LLVMBitCodes.h | 2 +- .../llvm/{Bitcode => Bitstream}/BitCodes.h | 10 ++++---- .../{Bitcode => Bitstream}/BitstreamReader.h | 8 +++---- .../{Bitcode => Bitstream}/BitstreamWriter.h | 6 ++--- include/llvm/Support/JSON.h | 2 +- lib/Bitcode/Reader/BitcodeReader.cpp | 2 +- lib/Bitcode/Reader/CMakeLists.txt | 1 - lib/Bitcode/Reader/LLVMBuild.txt | 2 +- lib/Bitcode/Reader/MetadataLoader.cpp | 2 +- lib/Bitcode/Writer/BitcodeWriter.cpp | 4 ++-- lib/Bitstream/CMakeLists.txt | 2 ++ lib/Bitstream/LLVMBuild.txt | 23 +++++++++++++++++++ .../Reader/BitstreamReader.cpp | 2 +- lib/Bitstream/Reader/CMakeLists.txt | 7 ++++++ lib/Bitstream/Reader/LLVMBuild.txt | 21 +++++++++++++++++ lib/CMakeLists.txt | 1 + lib/LLVMBuild.txt | 1 + tools/llvm-bcanalyzer/CMakeLists.txt | 1 + tools/llvm-bcanalyzer/LLVMBuild.txt | 2 +- tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp | 2 +- unittests/Bitcode/CMakeLists.txt | 2 -- .../BitstreamReaderTest.cpp | 4 ++-- .../BitstreamWriterTest.cpp | 2 +- unittests/Bitstream/CMakeLists.txt | 8 +++++++ unittests/CMakeLists.txt | 1 + utils/GenLibDeps.pl | 4 ++++ 27 files changed, 95 insertions(+), 29 deletions(-) rename include/llvm/{Bitcode => Bitstream}/BitCodes.h (96%) rename include/llvm/{Bitcode => Bitstream}/BitstreamReader.h (99%) rename include/llvm/{Bitcode => Bitstream}/BitstreamWriter.h (99%) create mode 100644 lib/Bitstream/CMakeLists.txt create mode 100644 lib/Bitstream/LLVMBuild.txt rename lib/{Bitcode => Bitstream}/Reader/BitstreamReader.cpp (99%) create mode 100644 lib/Bitstream/Reader/CMakeLists.txt create mode 100644 lib/Bitstream/Reader/LLVMBuild.txt rename unittests/{Bitcode => Bitstream}/BitstreamReaderTest.cpp (98%) rename unittests/{Bitcode => Bitstream}/BitstreamWriterTest.cpp (97%) create mode 100644 unittests/Bitstream/CMakeLists.txt diff --git a/include/llvm/Bitcode/BitcodeReader.h b/include/llvm/Bitcode/BitcodeReader.h index 3e8e7edf79c..ba61da733be 100644 --- a/include/llvm/Bitcode/BitcodeReader.h +++ b/include/llvm/Bitcode/BitcodeReader.h @@ -15,7 +15,7 @@ #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/StringRef.h" -#include "llvm/Bitcode/BitCodes.h" +#include "llvm/Bitstream/BitCodes.h" #include "llvm/IR/ModuleSummaryIndex.h" #include "llvm/Support/Endian.h" #include "llvm/Support/Error.h" diff --git a/include/llvm/Bitcode/LLVMBitCodes.h b/include/llvm/Bitcode/LLVMBitCodes.h index 3a0e1cc2b2c..5f3f7b1bd37 100644 --- a/include/llvm/Bitcode/LLVMBitCodes.h +++ b/include/llvm/Bitcode/LLVMBitCodes.h @@ -17,7 +17,7 @@ #ifndef LLVM_BITCODE_LLVMBITCODES_H #define LLVM_BITCODE_LLVMBITCODES_H -#include "llvm/Bitcode/BitCodes.h" +#include "llvm/Bitstream/BitCodes.h" namespace llvm { namespace bitc { diff --git a/include/llvm/Bitcode/BitCodes.h b/include/llvm/Bitstream/BitCodes.h similarity index 96% rename from include/llvm/Bitcode/BitCodes.h rename to include/llvm/Bitstream/BitCodes.h index a0d8dfd68bf..60de9622947 100644 --- a/include/llvm/Bitcode/BitCodes.h +++ b/include/llvm/Bitstream/BitCodes.h @@ -1,4 +1,4 @@ -//===- BitCodes.h - Enum values for the bitcode format ----------*- C++ -*-===// +//===- BitCodes.h - Enum values for the bitstream format --------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// // -// This header Bitcode enum values. +// This header defines bitstream enum values. // // The enum values defined in this file should be considered permanent. If // new features are added, they should have values added at the end of the @@ -14,8 +14,8 @@ // //===----------------------------------------------------------------------===// -#ifndef LLVM_BITCODE_BITCODES_H -#define LLVM_BITCODE_BITCODES_H +#ifndef LLVM_BITSTREAM_BITCODES_H +#define LLVM_BITSTREAM_BITCODES_H #include "llvm/ADT/SmallVector.h" #include "llvm/Support/DataTypes.h" @@ -23,7 +23,7 @@ #include namespace llvm { -/// Offsets of the 32-bit fields of bitcode wrapper header. +/// Offsets of the 32-bit fields of bitstream wrapper header. static const unsigned BWH_MagicField = 0 * 4; static const unsigned BWH_VersionField = 1 * 4; static const unsigned BWH_OffsetField = 2 * 4; diff --git a/include/llvm/Bitcode/BitstreamReader.h b/include/llvm/Bitstream/BitstreamReader.h similarity index 99% rename from include/llvm/Bitcode/BitstreamReader.h rename to include/llvm/Bitstream/BitstreamReader.h index c8ed77fded8..ccb4a492b9d 100644 --- a/include/llvm/Bitcode/BitstreamReader.h +++ b/include/llvm/Bitstream/BitstreamReader.h @@ -11,12 +11,12 @@ // //===----------------------------------------------------------------------===// -#ifndef LLVM_BITCODE_BITSTREAMREADER_H -#define LLVM_BITCODE_BITSTREAMREADER_H +#ifndef LLVM_BITSTREAM_BITSTREAMREADER_H +#define LLVM_BITSTREAM_BITSTREAMREADER_H #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/SmallVector.h" -#include "llvm/Bitcode/BitCodes.h" +#include "llvm/Bitstream/BitCodes.h" #include "llvm/Support/Endian.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/MathExtras.h" @@ -550,4 +550,4 @@ public: } // end llvm namespace -#endif // LLVM_BITCODE_BITSTREAMREADER_H +#endif // LLVM_BITSTREAM_BITSTREAMREADER_H diff --git a/include/llvm/Bitcode/BitstreamWriter.h b/include/llvm/Bitstream/BitstreamWriter.h similarity index 99% rename from include/llvm/Bitcode/BitstreamWriter.h rename to include/llvm/Bitstream/BitstreamWriter.h index cd5b614d105..c0ead19dc71 100644 --- a/include/llvm/Bitcode/BitstreamWriter.h +++ b/include/llvm/Bitstream/BitstreamWriter.h @@ -11,14 +11,14 @@ // //===----------------------------------------------------------------------===// -#ifndef LLVM_BITCODE_BITSTREAMWRITER_H -#define LLVM_BITCODE_BITSTREAMWRITER_H +#ifndef LLVM_BITSTREAM_BITSTREAMWRITER_H +#define LLVM_BITSTREAM_BITSTREAMWRITER_H #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/Optional.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringRef.h" -#include "llvm/Bitcode/BitCodes.h" +#include "llvm/Bitstream/BitCodes.h" #include "llvm/Support/Endian.h" #include diff --git a/include/llvm/Support/JSON.h b/include/llvm/Support/JSON.h index fb6a6d4e19a..0ca41097ddd 100644 --- a/include/llvm/Support/JSON.h +++ b/include/llvm/Support/JSON.h @@ -39,7 +39,7 @@ /// /// - LLVM bitstream is a space- and CPU- efficient binary format. Typically it /// encodes LLVM IR ("bitcode"), but it can be a container for other data. -/// Low-level reader/writer libraries are in Bitcode/Bitstream*.h +/// Low-level reader/writer libraries are in Bitstream/Bitstream*.h /// //===---------------------------------------------------------------------===// diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp index fa4fbdcea5b..9e0c397d743 100644 --- a/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/lib/Bitcode/Reader/BitcodeReader.cpp @@ -20,7 +20,7 @@ #include "llvm/ADT/StringRef.h" #include "llvm/ADT/Triple.h" #include "llvm/ADT/Twine.h" -#include "llvm/Bitcode/BitstreamReader.h" +#include "llvm/Bitstream/BitstreamReader.h" #include "llvm/Bitcode/LLVMBitCodes.h" #include "llvm/Config/llvm-config.h" #include "llvm/IR/Argument.h" diff --git a/lib/Bitcode/Reader/CMakeLists.txt b/lib/Bitcode/Reader/CMakeLists.txt index c24216ffa70..c9e1c00d10e 100644 --- a/lib/Bitcode/Reader/CMakeLists.txt +++ b/lib/Bitcode/Reader/CMakeLists.txt @@ -1,7 +1,6 @@ add_llvm_library(LLVMBitReader BitReader.cpp BitcodeReader.cpp - BitstreamReader.cpp MetadataLoader.cpp ValueList.cpp diff --git a/lib/Bitcode/Reader/LLVMBuild.txt b/lib/Bitcode/Reader/LLVMBuild.txt index c43f819750c..2eafab53c58 100644 --- a/lib/Bitcode/Reader/LLVMBuild.txt +++ b/lib/Bitcode/Reader/LLVMBuild.txt @@ -18,4 +18,4 @@ type = Library name = BitReader parent = Bitcode -required_libraries = Core Support +required_libraries = BitstreamReader Core Support diff --git a/lib/Bitcode/Reader/MetadataLoader.cpp b/lib/Bitcode/Reader/MetadataLoader.cpp index 03f9c950ef0..24620ed10d7 100644 --- a/lib/Bitcode/Reader/MetadataLoader.cpp +++ b/lib/Bitcode/Reader/MetadataLoader.cpp @@ -22,7 +22,7 @@ #include "llvm/ADT/StringRef.h" #include "llvm/ADT/Twine.h" #include "llvm/Bitcode/BitcodeReader.h" -#include "llvm/Bitcode/BitstreamReader.h" +#include "llvm/Bitstream/BitstreamReader.h" #include "llvm/Bitcode/LLVMBitCodes.h" #include "llvm/IR/Argument.h" #include "llvm/IR/Attributes.h" diff --git a/lib/Bitcode/Writer/BitcodeWriter.cpp b/lib/Bitcode/Writer/BitcodeWriter.cpp index e8d9fb8f62e..90de4688c8c 100644 --- a/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -24,8 +24,8 @@ #include "llvm/ADT/StringMap.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/Triple.h" -#include "llvm/Bitcode/BitCodes.h" -#include "llvm/Bitcode/BitstreamWriter.h" +#include "llvm/Bitstream/BitCodes.h" +#include "llvm/Bitstream/BitstreamWriter.h" #include "llvm/Bitcode/LLVMBitCodes.h" #include "llvm/Config/llvm-config.h" #include "llvm/IR/Attributes.h" diff --git a/lib/Bitstream/CMakeLists.txt b/lib/Bitstream/CMakeLists.txt new file mode 100644 index 00000000000..49def158f69 --- /dev/null +++ b/lib/Bitstream/CMakeLists.txt @@ -0,0 +1,2 @@ +add_subdirectory(Reader) +# The writer is header-only. diff --git a/lib/Bitstream/LLVMBuild.txt b/lib/Bitstream/LLVMBuild.txt new file mode 100644 index 00000000000..1dfb6d2ed1e --- /dev/null +++ b/lib/Bitstream/LLVMBuild.txt @@ -0,0 +1,23 @@ +;===- ./lib/Bitstream/LLVMBuild.txt ----------------------------*- Conf -*--===; +; +; 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 +; +;===------------------------------------------------------------------------===; +; +; This is an LLVMBuild description file for the components in this subdirectory. +; +; For more information on the LLVMBuild system, please see: +; +; http://llvm.org/docs/LLVMBuild.html +; +;===------------------------------------------------------------------------===; + +[common] +subdirectories = Reader + +[component_0] +type = Group +name = Bitstream +parent = Libraries diff --git a/lib/Bitcode/Reader/BitstreamReader.cpp b/lib/Bitstream/Reader/BitstreamReader.cpp similarity index 99% rename from lib/Bitcode/Reader/BitstreamReader.cpp rename to lib/Bitstream/Reader/BitstreamReader.cpp index 2f29ce29db0..a4a97ced545 100644 --- a/lib/Bitcode/Reader/BitstreamReader.cpp +++ b/lib/Bitstream/Reader/BitstreamReader.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "llvm/Bitcode/BitstreamReader.h" +#include "llvm/Bitstream/BitstreamReader.h" #include "llvm/ADT/StringRef.h" #include #include diff --git a/lib/Bitstream/Reader/CMakeLists.txt b/lib/Bitstream/Reader/CMakeLists.txt new file mode 100644 index 00000000000..f91e450d888 --- /dev/null +++ b/lib/Bitstream/Reader/CMakeLists.txt @@ -0,0 +1,7 @@ +add_llvm_library(LLVMBitstreamReader + BitstreamReader.cpp + + ADDITIONAL_HEADER_DIRS + ${LLVM_MAIN_INCLUDE_DIR}/llvm/Bitcode + ${LLVM_MAIN_INCLUDE_DIR}/llvm/Bitstream + ) diff --git a/lib/Bitstream/Reader/LLVMBuild.txt b/lib/Bitstream/Reader/LLVMBuild.txt new file mode 100644 index 00000000000..8ef4276c90a --- /dev/null +++ b/lib/Bitstream/Reader/LLVMBuild.txt @@ -0,0 +1,21 @@ +;===- ./lib/Bitstream/Reader/LLVMBuild.txt ---------------------*- Conf -*--===; +; +; 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 +; +;===------------------------------------------------------------------------===; +; +; This is an LLVMBuild description file for the components in this subdirectory. +; +; For more information on the LLVMBuild system, please see: +; +; http://llvm.org/docs/LLVMBuild.html +; +;===------------------------------------------------------------------------===; + +[component_0] +type = Library +name = BitstreamReader +parent = Bitstream +required_libraries = Support diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index c458927e3cd..17313df0ecf 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -7,6 +7,7 @@ add_subdirectory(IRReader) add_subdirectory(CodeGen) add_subdirectory(BinaryFormat) add_subdirectory(Bitcode) +add_subdirectory(Bitstream) add_subdirectory(Transforms) add_subdirectory(Linker) add_subdirectory(Analysis) diff --git a/lib/LLVMBuild.txt b/lib/LLVMBuild.txt index 3b5e71d6ef1..4c039176267 100644 --- a/lib/LLVMBuild.txt +++ b/lib/LLVMBuild.txt @@ -19,6 +19,7 @@ subdirectories = Analysis AsmParser Bitcode + Bitstream CodeGen DebugInfo Demangle diff --git a/tools/llvm-bcanalyzer/CMakeLists.txt b/tools/llvm-bcanalyzer/CMakeLists.txt index 15d51ee7a9d..0d541e1fde3 100644 --- a/tools/llvm-bcanalyzer/CMakeLists.txt +++ b/tools/llvm-bcanalyzer/CMakeLists.txt @@ -1,5 +1,6 @@ set(LLVM_LINK_COMPONENTS BitReader + BitstreamReader Support ) diff --git a/tools/llvm-bcanalyzer/LLVMBuild.txt b/tools/llvm-bcanalyzer/LLVMBuild.txt index 281d60246e9..c3b69110747 100644 --- a/tools/llvm-bcanalyzer/LLVMBuild.txt +++ b/tools/llvm-bcanalyzer/LLVMBuild.txt @@ -18,4 +18,4 @@ type = Tool name = llvm-bcanalyzer parent = Tools -required_libraries = BitReader +required_libraries = BitReader BitstreamReader Support diff --git a/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp b/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp index 29f6778d331..774432a5921 100644 --- a/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp +++ b/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp @@ -28,7 +28,7 @@ #include "llvm/ADT/StringExtras.h" #include "llvm/Bitcode/BitcodeReader.h" -#include "llvm/Bitcode/BitstreamReader.h" +#include "llvm/Bitstream/BitstreamReader.h" #include "llvm/Bitcode/LLVMBitCodes.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/Format.h" diff --git a/unittests/Bitcode/CMakeLists.txt b/unittests/Bitcode/CMakeLists.txt index 4d06f8008d3..7e9d1bc43fe 100644 --- a/unittests/Bitcode/CMakeLists.txt +++ b/unittests/Bitcode/CMakeLists.txt @@ -8,6 +8,4 @@ set(LLVM_LINK_COMPONENTS add_llvm_unittest(BitcodeTests BitReaderTest.cpp - BitstreamReaderTest.cpp - BitstreamWriterTest.cpp ) diff --git a/unittests/Bitcode/BitstreamReaderTest.cpp b/unittests/Bitstream/BitstreamReaderTest.cpp similarity index 98% rename from unittests/Bitcode/BitstreamReaderTest.cpp rename to unittests/Bitstream/BitstreamReaderTest.cpp index 89657d9e992..f58af220f2d 100644 --- a/unittests/Bitcode/BitstreamReaderTest.cpp +++ b/unittests/Bitstream/BitstreamReaderTest.cpp @@ -6,9 +6,9 @@ // //===----------------------------------------------------------------------===// -#include "llvm/Bitcode/BitstreamReader.h" +#include "llvm/Bitstream/BitstreamReader.h" #include "llvm/ADT/STLExtras.h" -#include "llvm/Bitcode/BitstreamWriter.h" +#include "llvm/Bitstream/BitstreamWriter.h" #include "gtest/gtest.h" using namespace llvm; diff --git a/unittests/Bitcode/BitstreamWriterTest.cpp b/unittests/Bitstream/BitstreamWriterTest.cpp similarity index 97% rename from unittests/Bitcode/BitstreamWriterTest.cpp rename to unittests/Bitstream/BitstreamWriterTest.cpp index ef4696c8c17..993c5aadee2 100644 --- a/unittests/Bitcode/BitstreamWriterTest.cpp +++ b/unittests/Bitstream/BitstreamWriterTest.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "llvm/Bitcode/BitstreamWriter.h" +#include "llvm/Bitstream/BitstreamWriter.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallString.h" #include "gtest/gtest.h" diff --git a/unittests/Bitstream/CMakeLists.txt b/unittests/Bitstream/CMakeLists.txt new file mode 100644 index 00000000000..a62003417d4 --- /dev/null +++ b/unittests/Bitstream/CMakeLists.txt @@ -0,0 +1,8 @@ +set(LLVM_LINK_COMPONENTS + BitstreamReader + ) + +add_llvm_unittest(BitstreamTests + BitstreamReaderTest.cpp + BitstreamWriterTest.cpp + ) diff --git a/unittests/CMakeLists.txt b/unittests/CMakeLists.txt index 68fa8533baf..6bb2fb8eb92 100644 --- a/unittests/CMakeLists.txt +++ b/unittests/CMakeLists.txt @@ -13,6 +13,7 @@ add_subdirectory(Analysis) add_subdirectory(AsmParser) add_subdirectory(BinaryFormat) add_subdirectory(Bitcode) +add_subdirectory(Bitstream) add_subdirectory(CodeGen) add_subdirectory(DebugInfo) add_subdirectory(Demangle) diff --git a/utils/GenLibDeps.pl b/utils/GenLibDeps.pl index 9b65e900c53..42afa6a11fc 100755 --- a/utils/GenLibDeps.pl +++ b/utils/GenLibDeps.pl @@ -96,6 +96,8 @@ if ($PEROBJ) { $libpath =~ s/^AsmPrinter/CodeGen\/AsmPrinter/; $libpath =~ s/^BitReader/Bitcode\/Reader/; $libpath =~ s/^BitWriter/Bitcode\/Writer/; + $libpath =~ s/^BitstreamReader/Bitstream\/Reader/; + $libpath =~ s/^BitstreamWriter/Bitstream\/Writer/; $libpath =~ s/^MSIL/Target\/MSIL/; $libpath =~ s/^Core/IR/; $libpath =~ s/^Instrumentation/Transforms\/Instrumentation/; @@ -136,6 +138,8 @@ if ($PEROBJ) { $libpath =~ s/^AsmPrinter/CodeGen\/AsmPrinter/; $libpath =~ s/^BitReader/Bitcode\/Reader/; $libpath =~ s/^BitWriter/Bitcode\/Writer/; + $libpath =~ s/^BitstreamReader/Bitstream\/Reader/; + $libpath =~ s/^BitstreamWriter/Bitstream\/Writer/; $libpath =~ s/^MSIL/Target\/MSIL/; $libpath =~ s/^Core/VMCore/; $libpath =~ s/^Instrumentation/Transforms\/Instrumentation/;