diff options
author | Eugene Zelenko <eugene.zelenko@gmail.com> | 2017-09-07 23:28:24 +0000 |
---|---|---|
committer | Eugene Zelenko <eugene.zelenko@gmail.com> | 2017-09-07 23:28:24 +0000 |
commit | 975293f0e593761a5d2d4446463fecd14b425aff (patch) | |
tree | 6c76aa6c5c88ff1c26a0a1607ffe66522ca4eb20 /llvm/lib/Bitcode/Writer | |
parent | 0e8c4bb05542ee035aae1732f0e5c434ecd20336 (diff) | |
download | bcm5719-llvm-975293f0e593761a5d2d4446463fecd14b425aff.tar.gz bcm5719-llvm-975293f0e593761a5d2d4446463fecd14b425aff.zip |
[Bitcode] Fix some Clang-tidy modernize-use-using and Include What You Use warnings; other minor fixes (NFC).
llvm-svn: 312760
Diffstat (limited to 'llvm/lib/Bitcode/Writer')
-rw-r--r-- | llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 75 | ||||
-rw-r--r-- | llvm/lib/Bitcode/Writer/ValueEnumerator.cpp | 52 | ||||
-rw-r--r-- | llvm/lib/Bitcode/Writer/ValueEnumerator.h | 61 |
3 files changed, 131 insertions, 57 deletions
diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp index 7fcec9c7a8d..317a5db2bc5 100644 --- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -1,4 +1,4 @@ -//===--- Bitcode/Writer/BitcodeWriter.cpp - Bitcode Writer ----------------===// +//===- Bitcode/Writer/BitcodeWriter.cpp - Bitcode Writer ------------------===// // // The LLVM Compiler Infrastructure // @@ -13,39 +13,81 @@ #include "llvm/Bitcode/BitcodeWriter.h" #include "ValueEnumerator.h" -#include "llvm/ADT/StringExtras.h" +#include "llvm/ADT/APFloat.h" +#include "llvm/ADT/APInt.h" +#include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/None.h" +#include "llvm/ADT/Optional.h" +#include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/SmallString.h" +#include "llvm/ADT/SmallVector.h" +#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/Bitcode/LLVMBitCodes.h" +#include "llvm/IR/Attributes.h" +#include "llvm/IR/BasicBlock.h" #include "llvm/IR/CallSite.h" +#include "llvm/IR/Comdat.h" +#include "llvm/IR/Constant.h" #include "llvm/IR/Constants.h" #include "llvm/IR/DebugInfoMetadata.h" +#include "llvm/IR/DebugLoc.h" #include "llvm/IR/DerivedTypes.h" +#include "llvm/IR/Function.h" +#include "llvm/IR/GlobalAlias.h" +#include "llvm/IR/GlobalIFunc.h" +#include "llvm/IR/GlobalObject.h" +#include "llvm/IR/GlobalValue.h" +#include "llvm/IR/GlobalVariable.h" #include "llvm/IR/InlineAsm.h" +#include "llvm/IR/InstrTypes.h" +#include "llvm/IR/Instruction.h" #include "llvm/IR/Instructions.h" #include "llvm/IR/LLVMContext.h" +#include "llvm/IR/Metadata.h" #include "llvm/IR/Module.h" +#include "llvm/IR/ModuleSummaryIndex.h" #include "llvm/IR/Operator.h" +#include "llvm/IR/Type.h" #include "llvm/IR/UseListOrder.h" +#include "llvm/IR/Value.h" #include "llvm/IR/ValueSymbolTable.h" #include "llvm/MC/StringTableBuilder.h" #include "llvm/Object/IRSymtab.h" +#include "llvm/Support/AtomicOrdering.h" +#include "llvm/Support/Casting.h" +#include "llvm/Support/CommandLine.h" +#include "llvm/Support/Endian.h" +#include "llvm/Support/Error.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/MathExtras.h" -#include "llvm/Support/Program.h" #include "llvm/Support/SHA1.h" #include "llvm/Support/TargetRegistry.h" #include "llvm/Support/raw_ostream.h" -#include <cctype> +#include <algorithm> +#include <cassert> +#include <cstddef> +#include <cstdint> +#include <iterator> #include <map> -using namespace llvm; +#include <memory> +#include <string> +#include <utility> +#include <vector> -namespace { +using namespace llvm; -cl::opt<unsigned> +static cl::opt<unsigned> IndexThreshold("bitcode-mdindex-threshold", cl::Hidden, cl::init(25), cl::desc("Number of metadatas above which we emit an index " "to enable lazy-loading")); + +namespace { + /// These are manifest constants used by the bitcode writer. They do not need to /// be kept in sync with the reader, but need to be consistent within this file. enum { @@ -169,6 +211,7 @@ private: void assignValueId(GlobalValue::GUID ValGUID) { GUIDToValueIdMap[ValGUID] = ++GlobalValueId; } + unsigned getValueId(GlobalValue::GUID ValGUID) { const auto &VMI = GUIDToValueIdMap.find(ValGUID); // Expect that any GUID value had a value Id assigned by an @@ -177,12 +220,14 @@ private: "GUID does not have assigned value Id"); return VMI->second; } + // Helper to get the valueId for the type of value recorded in VI. unsigned getValueId(ValueInfo VI) { if (!VI.getValue()) return getValueId(VI.getGUID()); return VE.getValueID(VI.getValue()); } + std::map<GlobalValue::GUID, unsigned> &valueIds() { return GUIDToValueIdMap; } }; @@ -374,7 +419,7 @@ public: } /// The below iterator returns the GUID and associated summary. - typedef std::pair<GlobalValue::GUID, GlobalValueSummary *> GVInfo; + using GVInfo = std::pair<GlobalValue::GUID, GlobalValueSummary *>; /// Calls the callback for each value GUID and summary to be written to /// bitcode. This hides the details of whether they are being pulled from the @@ -428,8 +473,10 @@ private: return None; return VMI->second; } + std::map<GlobalValue::GUID, unsigned> &valueIds() { return GUIDToValueIdMap; } }; + } // end anonymous namespace static unsigned getEncodedCastOpcode(unsigned Opcode) { @@ -726,7 +773,6 @@ void ModuleBitcodeWriter::writeTypeTable() { Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isvararg Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, NumBits)); - unsigned FunctionAbbrev = Stream.EmitAbbrev(std::move(Abbv)); // Abbrev for TYPE_CODE_STRUCT_ANON. @@ -735,7 +781,6 @@ void ModuleBitcodeWriter::writeTypeTable() { Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ispacked Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, NumBits)); - unsigned StructAnonAbbrev = Stream.EmitAbbrev(std::move(Abbv)); // Abbrev for TYPE_CODE_STRUCT_NAME. @@ -751,7 +796,6 @@ void ModuleBitcodeWriter::writeTypeTable() { Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ispacked Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, NumBits)); - unsigned StructNamedAbbrev = Stream.EmitAbbrev(std::move(Abbv)); // Abbrev for TYPE_CODE_ARRAY. @@ -759,7 +803,6 @@ void ModuleBitcodeWriter::writeTypeTable() { Abbv->Add(BitCodeAbbrevOp(bitc::TYPE_CODE_ARRAY)); Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // size Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, NumBits)); - unsigned ArrayAbbrev = Stream.EmitAbbrev(std::move(Abbv)); // Emit an entry count so the reader can reserve space. @@ -2206,7 +2249,7 @@ void ModuleBitcodeWriter::writeConstants(unsigned FirstVal, unsigned LastVal, Record.push_back(p[0]); Record.push_back(p[1]); } else { - assert (0 && "Unknown FP type!"); + assert(0 && "Unknown FP type!"); } } else if (isa<ConstantDataSequential>(C) && cast<ConstantDataSequential>(C)->isString()) { @@ -3051,8 +3094,6 @@ void ModuleBitcodeWriter::writeBlockInfo() { llvm_unreachable("Unexpected abbrev ordering!"); } - - { // SETTYPE abbrev for CONSTANTS_BLOCK. auto Abbv = std::make_shared<BitCodeAbbrev>(); Abbv->Add(BitCodeAbbrevOp(bitc::CST_CODE_SETTYPE)); @@ -4032,6 +4073,7 @@ void llvm::WriteIndexToFile( } namespace { + /// Class to manage the bitcode writing for a thin link bitcode file. class ThinLinkBitcodeWriter : public ModuleBitcodeWriterBase { /// ModHash is for use in ThinLTO incremental build, generated while writing @@ -4052,7 +4094,8 @@ public: private: void writeSimplifiedModuleInfo(); }; -} // namespace + +} // end anonymous namespace // This function writes a simpilified module info for thin link bitcode file. // It only contains the source file name along with the name(the offset and diff --git a/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp b/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp index bb626baabd1..d99befcdaea 100644 --- a/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp +++ b/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp @@ -1,4 +1,4 @@ -//===-- ValueEnumerator.cpp - Number values and types for bitcode writer --===// +//===- ValueEnumerator.cpp - Number values and types for bitcode writer ---===// // // The LLVM Compiler Infrastructure // @@ -12,47 +12,77 @@ //===----------------------------------------------------------------------===// #include "ValueEnumerator.h" -#include "llvm/ADT/STLExtras.h" -#include "llvm/ADT/SmallPtrSet.h" -#include "llvm/IR/Constants.h" +#include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/IR/Argument.h" +#include "llvm/IR/Attributes.h" +#include "llvm/IR/BasicBlock.h" +#include "llvm/IR/Constant.h" #include "llvm/IR/DebugInfoMetadata.h" #include "llvm/IR/DerivedTypes.h" +#include "llvm/IR/Function.h" +#include "llvm/IR/GlobalAlias.h" +#include "llvm/IR/GlobalIFunc.h" +#include "llvm/IR/GlobalObject.h" +#include "llvm/IR/GlobalValue.h" +#include "llvm/IR/GlobalVariable.h" +#include "llvm/IR/Instruction.h" #include "llvm/IR/Instructions.h" +#include "llvm/IR/Metadata.h" #include "llvm/IR/Module.h" +#include "llvm/IR/Type.h" +#include "llvm/IR/Use.h" #include "llvm/IR/UseListOrder.h" +#include "llvm/IR/User.h" +#include "llvm/IR/Value.h" #include "llvm/IR/ValueSymbolTable.h" +#include "llvm/Support/Casting.h" +#include "llvm/Support/Compiler.h" #include "llvm/Support/Debug.h" +#include "llvm/Support/MathExtras.h" #include "llvm/Support/raw_ostream.h" #include <algorithm> +#include <cassert> +#include <cstddef> +#include <iterator> +#include <tuple> +#include <utility> +#include <vector> + using namespace llvm; namespace { + struct OrderMap { DenseMap<const Value *, std::pair<unsigned, bool>> IDs; - unsigned LastGlobalConstantID; - unsigned LastGlobalValueID; + unsigned LastGlobalConstantID = 0; + unsigned LastGlobalValueID = 0; - OrderMap() : LastGlobalConstantID(0), LastGlobalValueID(0) {} + OrderMap() = default; bool isGlobalConstant(unsigned ID) const { return ID <= LastGlobalConstantID; } + bool isGlobalValue(unsigned ID) const { return ID <= LastGlobalValueID && !isGlobalConstant(ID); } unsigned size() const { return IDs.size(); } std::pair<unsigned, bool> &operator[](const Value *V) { return IDs[V]; } + std::pair<unsigned, bool> lookup(const Value *V) const { return IDs.lookup(V); } + void index(const Value *V) { // Explicitly sequence get-size and insert-value operations to avoid UB. unsigned ID = IDs.size() + 1; IDs[V].first = ID; } }; -} + +} // end anonymous namespace static void orderValue(const Value *V, OrderMap &OM) { if (OM.lookup(V).first) @@ -141,7 +171,7 @@ static void predictValueUseListOrderImpl(const Value *V, const Function *F, unsigned ID, const OrderMap &OM, UseListOrderStack &Stack) { // Predict use-list order for this one. - typedef std::pair<const Use *, unsigned> Entry; + using Entry = std::pair<const Use *, unsigned>; SmallVector<Entry, 64> List; for (const Use &U : V->uses()) // Check if this user will be serialized. @@ -446,12 +476,10 @@ LLVM_DUMP_METHOD void ValueEnumerator::dump() const { void ValueEnumerator::print(raw_ostream &OS, const ValueMapType &Map, const char *Name) const { - OS << "Map Name: " << Name << "\n"; OS << "Size: " << Map.size() << "\n"; for (ValueMapType::const_iterator I = Map.begin(), E = Map.end(); I != E; ++I) { - const Value *V = I->first; if (V->hasName()) OS << "Value: " << V->getName(); @@ -476,7 +504,6 @@ void ValueEnumerator::print(raw_ostream &OS, const ValueMapType &Map, void ValueEnumerator::print(raw_ostream &OS, const MetadataMapType &Map, const char *Name) const { - OS << "Map Name: " << Name << "\n"; OS << "Size: " << Map.size() << "\n"; for (auto I = Map.begin(), E = Map.end(); I != E; ++I) { @@ -518,7 +545,6 @@ void ValueEnumerator::OptimizeConstants(unsigned CstStart, unsigned CstEnd) { ValueMap[Values[CstStart].first] = CstStart+1; } - /// EnumerateValueSymbolTable - Insert all of the values in the specified symbol /// table into the values table. void ValueEnumerator::EnumerateValueSymbolTable(const ValueSymbolTable &VST) { diff --git a/llvm/lib/Bitcode/Writer/ValueEnumerator.h b/llvm/lib/Bitcode/Writer/ValueEnumerator.h index e7ccc8df1e5..730187087dc 100644 --- a/llvm/lib/Bitcode/Writer/ValueEnumerator.h +++ b/llvm/lib/Bitcode/Writer/ValueEnumerator.h @@ -1,4 +1,4 @@ -//===-- Bitcode/Writer/ValueEnumerator.h - Number values --------*- C++ -*-===// +//===- Bitcode/Writer/ValueEnumerator.h - Number values ---------*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -14,56 +14,55 @@ #ifndef LLVM_LIB_BITCODE_WRITER_VALUEENUMERATOR_H #define LLVM_LIB_BITCODE_WRITER_VALUEENUMERATOR_H +#include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/UniqueVector.h" #include "llvm/IR/Attributes.h" -#include "llvm/IR/Metadata.h" -#include "llvm/IR/Type.h" #include "llvm/IR/UseListOrder.h" +#include <cassert> +#include <cstdint> +#include <utility> #include <vector> namespace llvm { -class Type; -class Value; -class Instruction; class BasicBlock; class Comdat; class Function; -class Module; -class Metadata; +class Instruction; class LocalAsMetadata; class MDNode; -class MDOperand; +class Metadata; +class Module; class NamedMDNode; -class AttributeList; -class ValueSymbolTable; -class MDSymbolTable; class raw_ostream; +class Type; +class Value; +class ValueSymbolTable; class ValueEnumerator { public: - typedef std::vector<Type*> TypeList; + using TypeList = std::vector<Type *>; // For each value, we remember its Value* and occurrence frequency. - typedef std::vector<std::pair<const Value*, unsigned> > ValueList; + using ValueList = std::vector<std::pair<const Value *, unsigned>>; /// Attribute groups as encoded in bitcode are almost AttributeSets, but they /// include the AttributeList index, so we have to track that in our map. - typedef std::pair<unsigned, AttributeSet> IndexAndAttrSet; + using IndexAndAttrSet = std::pair<unsigned, AttributeSet>; UseListOrderStack UseListOrders; private: - typedef DenseMap<Type*, unsigned> TypeMapType; + using TypeMapType = DenseMap<Type *, unsigned>; TypeMapType TypeMap; TypeList Types; - typedef DenseMap<const Value*, unsigned> ValueMapType; + using ValueMapType = DenseMap<const Value *, unsigned>; ValueMapType ValueMap; ValueList Values; - typedef UniqueVector<const Comdat *> ComdatSetType; + using ComdatSetType = UniqueVector<const Comdat *>; ComdatSetType Comdats; std::vector<const Metadata *> MDs; @@ -88,7 +87,7 @@ private: } }; - typedef DenseMap<const Metadata *, MDIndex> MetadataMapType; + using MetadataMapType = DenseMap<const Metadata *, MDIndex>; MetadataMapType MetadataMap; /// Range of metadata IDs, as a half-open range. @@ -99,18 +98,18 @@ private: /// Number of strings in the prefix of the metadata range. unsigned NumStrings = 0; - MDRange() {} + MDRange() = default; explicit MDRange(unsigned First) : First(First) {} }; SmallDenseMap<unsigned, MDRange, 1> FunctionMDInfo; bool ShouldPreserveUseListOrder; - typedef DenseMap<IndexAndAttrSet, unsigned> AttributeGroupMapType; + using AttributeGroupMapType = DenseMap<IndexAndAttrSet, unsigned>; AttributeGroupMapType AttributeGroupMap; std::vector<IndexAndAttrSet> AttributeGroups; - typedef DenseMap<AttributeList, unsigned> AttributeListMapType; + using AttributeListMapType = DenseMap<AttributeList, unsigned>; AttributeListMapType AttributeListMap; std::vector<AttributeList> AttributeLists; @@ -118,7 +117,7 @@ private: /// the "getGlobalBasicBlockID" method. mutable DenseMap<const BasicBlock*, unsigned> GlobalBasicBlockIDs; - typedef DenseMap<const Instruction*, unsigned> InstructionMapType; + using InstructionMapType = DenseMap<const Instruction *, unsigned>; InstructionMapType InstructionMap; unsigned InstructionCount; @@ -138,10 +137,10 @@ private: unsigned FirstFuncConstantID; unsigned FirstInstID; - ValueEnumerator(const ValueEnumerator &) = delete; - void operator=(const ValueEnumerator &) = delete; public: ValueEnumerator(const Module &M, bool ShouldPreserveUseListOrder); + ValueEnumerator(const ValueEnumerator &) = delete; + ValueEnumerator &operator=(const ValueEnumerator &) = delete; void dump() const; void print(raw_ostream &OS, const ValueMapType &Map, const char *Name) const; @@ -149,14 +148,17 @@ public: const char *Name) const; unsigned getValueID(const Value *V) const; + unsigned getMetadataID(const Metadata *MD) const { auto ID = getMetadataOrNullID(MD); assert(ID != 0 && "Metadata not in slotcalculator!"); return ID - 1; } + unsigned getMetadataOrNullID(const Metadata *MD) const { return MetadataMap.lookup(MD).ID; } + unsigned numMDs() const { return MDs.size(); } bool shouldPreserveUseListOrder() const { return ShouldPreserveUseListOrder; } @@ -208,10 +210,13 @@ public: } const TypeList &getTypes() const { return Types; } + const std::vector<const BasicBlock*> &getBasicBlocks() const { return BasicBlocks; } + const std::vector<AttributeList> &getAttributeLists() const { return AttributeLists; } + const std::vector<IndexAndAttrSet> &getAttributeGroups() const { return AttributeGroups; } @@ -226,8 +231,8 @@ public: /// incorporateFunction/purgeFunction - If you'd like to deal with a function, /// use these two methods to get its data into the ValueEnumerator! - /// void incorporateFunction(const Function &F); + void purgeFunction(); uint64_t computeBitsRequiredForTypeIndicies() const; @@ -292,6 +297,6 @@ private: void EnumerateNamedMetadata(const Module &M); }; -} // End llvm namespace +} // end namespace llvm -#endif +#endif // LLVM_LIB_BITCODE_WRITER_VALUEENUMERATOR_H |