diff --git a/llvm/include/llvm/IR/TypeFinder.h b/llvm/include/llvm/IR/TypeFinder.h --- a/llvm/include/llvm/IR/TypeFinder.h +++ b/llvm/include/llvm/IR/TypeFinder.h @@ -23,6 +23,7 @@ class MDNode; class Module; class StructType; +class TargetExtType; class Type; class Value; @@ -37,6 +38,7 @@ DenseSet VisitedTypes; std::vector StructTypes; + std::vector TargetExtTypes; bool OnlyNamed = false; public: @@ -45,20 +47,43 @@ void run(const Module &M, bool onlyNamed); void clear(); - using iterator = std::vector::iterator; - using const_iterator = std::vector::const_iterator; + using struct_iterator = std::vector::iterator; + using const_struct_iterator = std::vector::const_iterator; - iterator begin() { return StructTypes.begin(); } - iterator end() { return StructTypes.end(); } + struct_iterator structs_begin() { return StructTypes.begin(); } + struct_iterator structs_end() { return StructTypes.end(); } - const_iterator begin() const { return StructTypes.begin(); } - const_iterator end() const { return StructTypes.end(); } + const_struct_iterator structs_begin() const { return StructTypes.begin(); } + const_struct_iterator structs_end() const { return StructTypes.end(); } - bool empty() const { return StructTypes.empty(); } - size_t size() const { return StructTypes.size(); } - iterator erase(iterator I, iterator E) { return StructTypes.erase(I, E); } + iterator_range structs() { + return make_range(structs_begin(), structs_end()); + } + iterator_range structs() const { + return make_range(structs_begin(), structs_end()); + } - StructType *&operator[](unsigned Idx) { return StructTypes[Idx]; } + bool structs_empty() const { return StructTypes.empty(); } + size_t structs_size() const { return StructTypes.size(); } + struct_iterator structs_erase(struct_iterator I, struct_iterator E) { + return StructTypes.erase(I, E); + } + + using const_target_ext_iterator = + std::vector::const_iterator; + + const_target_ext_iterator target_exts_begin() const { + return TargetExtTypes.begin(); + } + const_target_ext_iterator target_exts_end() const { + return TargetExtTypes.end(); + } + + iterator_range target_exts() const { + return make_range(target_exts_begin(), target_exts_end()); + } + + bool target_exts_empty() const { return TargetExtTypes.empty(); } DenseSet &getVisitedMetadata() { return VisitedMetadata; } diff --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp --- a/llvm/lib/IR/AsmWriter.cpp +++ b/llvm/lib/IR/AsmWriter.cpp @@ -453,8 +453,8 @@ TypePrinting(const TypePrinting &) = delete; TypePrinting &operator=(const TypePrinting &) = delete; - /// The named types that are used by the current module. - TypeFinder &getNamedTypes(); + /// The type finder for the current module. + TypeFinder &getTypeFinder(); /// The numbered types, number to type mapping. std::vector &getNumberedTypes(); @@ -471,7 +471,7 @@ /// A module to process lazily when needed. Set to nullptr as soon as used. const Module *DeferredM; - TypeFinder NamedTypes; + TypeFinder TF; // The numbered types, along with their value. DenseMap Type2Number; @@ -481,9 +481,9 @@ } // end anonymous namespace -TypeFinder &TypePrinting::getNamedTypes() { +TypeFinder &TypePrinting::getTypeFinder() { incorporateTypes(); - return NamedTypes; + return TF; } std::vector &TypePrinting::getNumberedTypes() { @@ -506,22 +506,22 @@ bool TypePrinting::empty() { incorporateTypes(); - return NamedTypes.empty() && Type2Number.empty(); + return TF.structs_empty() && Type2Number.empty(); } void TypePrinting::incorporateTypes() { if (!DeferredM) return; - NamedTypes.run(*DeferredM, false); + TF.run(*DeferredM, false); DeferredM = nullptr; // The list of struct types we got back includes all the struct types, split // the unnamed ones out to a numbering and remove the anonymous structs. unsigned NextNumber = 0; - std::vector::iterator NextToUse = NamedTypes.begin(); - for (StructType *STy : NamedTypes) { + std::vector::iterator NextToUse = TF.structs_begin(); + for (StructType *STy : TF.structs()) { // Ignore anonymous types. if (STy->isLiteral()) continue; @@ -532,7 +532,7 @@ *NextToUse++ = STy; } - NamedTypes.erase(NextToUse, NamedTypes.end()); + TF.structs_erase(NextToUse, TF.structs_end()); } /// Write the specified type to the specified raw_ostream, making use of type @@ -3753,8 +3753,8 @@ Out << '\n'; } - auto &NamedTypes = TypePrinter.getNamedTypes(); - for (StructType *NamedType : NamedTypes) { + auto &TF = TypePrinter.getTypeFinder(); + for (StructType *NamedType : TF.structs()) { PrintLLVMName(Out, NamedType->getName(), LocalPrefix); Out << " = type "; diff --git a/llvm/lib/IR/Module.cpp b/llvm/lib/IR/Module.cpp --- a/llvm/lib/IR/Module.cpp +++ b/llvm/lib/IR/Module.cpp @@ -470,7 +470,7 @@ std::vector Ret; TypeFinder SrcStructTypes; SrcStructTypes.run(*this, true); - Ret.assign(SrcStructTypes.begin(), SrcStructTypes.end()); + Ret.assign(SrcStructTypes.structs_begin(), SrcStructTypes.structs_end()); return Ret; } diff --git a/llvm/lib/IR/TypeFinder.cpp b/llvm/lib/IR/TypeFinder.cpp --- a/llvm/lib/IR/TypeFinder.cpp +++ b/llvm/lib/IR/TypeFinder.cpp @@ -115,9 +115,12 @@ Ty = TypeWorklist.pop_back_val(); // If this is a structure or opaque type, add a name for the type. - if (StructType *STy = dyn_cast(Ty)) + if (StructType *STy = dyn_cast(Ty)) { if (!OnlyNamed || STy->hasName()) StructTypes.push_back(STy); + } else if (TargetExtType *TTy = dyn_cast(Ty)) { + TargetExtTypes.push_back(TTy); + } // Add all unvisited subtypes to worklist for processing for (Type *SubTy : llvm::reverse(Ty->subtypes())) diff --git a/llvm/lib/Linker/IRMover.cpp b/llvm/lib/Linker/IRMover.cpp --- a/llvm/lib/Linker/IRMover.cpp +++ b/llvm/lib/Linker/IRMover.cpp @@ -1787,7 +1787,7 @@ IRMover::IRMover(Module &M) : Composite(M) { TypeFinder StructTypes; StructTypes.run(M, /* OnlyNamed */ false); - for (StructType *Ty : StructTypes) { + for (StructType *Ty : StructTypes.structs()) { if (Ty->isOpaque()) IdentifiedStructTypes.addOpaque(Ty); else diff --git a/llvm/lib/Transforms/IPO/StripSymbols.cpp b/llvm/lib/Transforms/IPO/StripSymbols.cpp --- a/llvm/lib/Transforms/IPO/StripSymbols.cpp +++ b/llvm/lib/Transforms/IPO/StripSymbols.cpp @@ -85,7 +85,7 @@ TypeFinder StructTypes; StructTypes.run(M, false); - for (StructType *STy : StructTypes) { + for (StructType *STy : StructTypes.structs()) { if (STy->isLiteral() || STy->getName().empty()) continue; if (PreserveDbgInfo && STy->getName().startswith("llvm.dbg")) diff --git a/llvm/lib/Transforms/Utils/MetaRenamer.cpp b/llvm/lib/Transforms/Utils/MetaRenamer.cpp --- a/llvm/lib/Transforms/Utils/MetaRenamer.cpp +++ b/llvm/lib/Transforms/Utils/MetaRenamer.cpp @@ -165,7 +165,7 @@ // Rename all struct types TypeFinder StructTypes; StructTypes.run(M, true); - for (StructType *STy : StructTypes) { + for (StructType *STy : StructTypes.structs()) { StringRef Name = STy->getName(); if (STy->isLiteral() || Name.empty() || IsNameExcluded(Name, ExcludedStructsPrefixes))