[Support] Fix some Clang-tidy modernize and Include What You Use warnings; other minor fixes (NFC).

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@296714 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Eugene Zelenko 2017-03-01 23:59:26 +00:00
parent 73db97244c
commit f3b992a333
6 changed files with 157 additions and 143 deletions

View File

@ -16,17 +16,21 @@
#define LLVM_IR_DOMINATORS_H #define LLVM_IR_DOMINATORS_H
#include "llvm/ADT/DenseMapInfo.h" #include "llvm/ADT/DenseMapInfo.h"
#include "llvm/ADT/DepthFirstIterator.h"
#include "llvm/ADT/GraphTraits.h" #include "llvm/ADT/GraphTraits.h"
#include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/Hashing.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/CFG.h" #include "llvm/IR/CFG.h"
#include "llvm/IR/PassManager.h" #include "llvm/IR/PassManager.h"
#include "llvm/Pass.h" #include "llvm/Pass.h"
#include "llvm/Support/GenericDomTree.h" #include "llvm/Support/GenericDomTree.h"
#include <utility>
namespace llvm { namespace llvm {
class Function; class Function;
class BasicBlock; class Instruction;
class Module;
class raw_ostream; class raw_ostream;
extern template class DomTreeNodeBase<BasicBlock>; extern template class DomTreeNodeBase<BasicBlock>;
@ -43,28 +47,37 @@ typedef DomTreeNodeBase<BasicBlock> DomTreeNode;
class BasicBlockEdge { class BasicBlockEdge {
const BasicBlock *Start; const BasicBlock *Start;
const BasicBlock *End; const BasicBlock *End;
public: public:
BasicBlockEdge(const BasicBlock *Start_, const BasicBlock *End_) : BasicBlockEdge(const BasicBlock *Start_, const BasicBlock *End_) :
Start(Start_), End(End_) { } Start(Start_), End(End_) {}
BasicBlockEdge(const std::pair<BasicBlock *, BasicBlock *> &Pair) BasicBlockEdge(const std::pair<BasicBlock *, BasicBlock *> &Pair)
: Start(Pair.first), End(Pair.second) {} : Start(Pair.first), End(Pair.second) {}
BasicBlockEdge(const std::pair<const BasicBlock *, const BasicBlock *> &Pair) BasicBlockEdge(const std::pair<const BasicBlock *, const BasicBlock *> &Pair)
: Start(Pair.first), End(Pair.second) {} : Start(Pair.first), End(Pair.second) {}
const BasicBlock *getStart() const { const BasicBlock *getStart() const {
return Start; return Start;
} }
const BasicBlock *getEnd() const { const BasicBlock *getEnd() const {
return End; return End;
} }
bool isSingleEdge() const; bool isSingleEdge() const;
}; };
template <> struct DenseMapInfo<BasicBlockEdge> { template <> struct DenseMapInfo<BasicBlockEdge> {
static unsigned getHashValue(const BasicBlockEdge *V);
typedef DenseMapInfo<const BasicBlock *> BBInfo; typedef DenseMapInfo<const BasicBlock *> BBInfo;
static unsigned getHashValue(const BasicBlockEdge *V);
static inline BasicBlockEdge getEmptyKey() { static inline BasicBlockEdge getEmptyKey() {
return BasicBlockEdge(BBInfo::getEmptyKey(), BBInfo::getEmptyKey()); return BasicBlockEdge(BBInfo::getEmptyKey(), BBInfo::getEmptyKey());
} }
static inline BasicBlockEdge getTombstoneKey() { static inline BasicBlockEdge getTombstoneKey() {
return BasicBlockEdge(BBInfo::getTombstoneKey(), BBInfo::getTombstoneKey()); return BasicBlockEdge(BBInfo::getTombstoneKey(), BBInfo::getTombstoneKey());
} }
@ -73,6 +86,7 @@ template <> struct DenseMapInfo<BasicBlockEdge> {
return hash_combine(BBInfo::getHashValue(Edge.getStart()), return hash_combine(BBInfo::getHashValue(Edge.getStart()),
BBInfo::getHashValue(Edge.getEnd())); BBInfo::getHashValue(Edge.getEnd()));
} }
static bool isEqual(const BasicBlockEdge &LHS, const BasicBlockEdge &RHS) { static bool isEqual(const BasicBlockEdge &LHS, const BasicBlockEdge &RHS) {
return BBInfo::isEqual(LHS.getStart(), RHS.getStart()) && return BBInfo::isEqual(LHS.getStart(), RHS.getStart()) &&
BBInfo::isEqual(LHS.getEnd(), RHS.getEnd()); BBInfo::isEqual(LHS.getEnd(), RHS.getEnd());
@ -213,6 +227,7 @@ class DominatorTreePrinterPass
public: public:
explicit DominatorTreePrinterPass(raw_ostream &OS); explicit DominatorTreePrinterPass(raw_ostream &OS);
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM); PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
}; };
@ -248,6 +263,6 @@ public:
void print(raw_ostream &OS, const Module *M = nullptr) const override; void print(raw_ostream &OS, const Module *M = nullptr) const override;
}; };
} // End llvm namespace } // end namespace llvm
#endif #endif // LLVM_IR_DOMINATORS_H

View File

@ -1,4 +1,4 @@
//===--- Allocator.h - Simple memory allocation abstraction -----*- C++ -*-===// //===- Allocator.h - Simple memory allocation abstraction -------*- C++ -*-===//
// //
// The LLVM Compiler Infrastructure // The LLVM Compiler Infrastructure
// //
@ -144,12 +144,11 @@ public:
"that objects larger than a slab go into their own memory " "that objects larger than a slab go into their own memory "
"allocation."); "allocation.");
BumpPtrAllocatorImpl() BumpPtrAllocatorImpl() = default;
: CurPtr(nullptr), End(nullptr), BytesAllocated(0), Allocator() {}
template <typename T> template <typename T>
BumpPtrAllocatorImpl(T &&Allocator) BumpPtrAllocatorImpl(T &&Allocator)
: CurPtr(nullptr), End(nullptr), BytesAllocated(0), : Allocator(std::forward<T &&>(Allocator)) {}
Allocator(std::forward<T &&>(Allocator)) {}
// Manually implement a move constructor as we must clear the old allocator's // Manually implement a move constructor as we must clear the old allocator's
// slabs as a matter of correctness. // slabs as a matter of correctness.
@ -292,10 +291,10 @@ private:
/// \brief The current pointer into the current slab. /// \brief The current pointer into the current slab.
/// ///
/// This points to the next free byte in the slab. /// This points to the next free byte in the slab.
char *CurPtr; char *CurPtr = nullptr;
/// \brief The end of the current slab. /// \brief The end of the current slab.
char *End; char *End = nullptr;
/// \brief The slabs allocated so far. /// \brief The slabs allocated so far.
SmallVector<void *, 4> Slabs; SmallVector<void *, 4> Slabs;
@ -306,7 +305,7 @@ private:
/// \brief How many bytes we've allocated. /// \brief How many bytes we've allocated.
/// ///
/// Used so that we can compute how much space was wasted. /// Used so that we can compute how much space was wasted.
size_t BytesAllocated; size_t BytesAllocated = 0;
/// \brief The allocator instance we use to get slabs of memory. /// \brief The allocator instance we use to get slabs of memory.
AllocatorT Allocator; AllocatorT Allocator;

View File

@ -141,40 +141,35 @@ public:
/// a platform-specific member to store the result. /// a platform-specific member to store the result.
class file_status class file_status
{ {
#if defined(LLVM_ON_UNIX)
dev_t fs_st_dev;
ino_t fs_st_ino;
time_t fs_st_atime;
time_t fs_st_mtime;
uid_t fs_st_uid;
gid_t fs_st_gid;
off_t fs_st_size;
#elif defined (LLVM_ON_WIN32)
uint32_t LastAccessedTimeHigh;
uint32_t LastAccessedTimeLow;
uint32_t LastWriteTimeHigh;
uint32_t LastWriteTimeLow;
uint32_t VolumeSerialNumber;
uint32_t FileSizeHigh;
uint32_t FileSizeLow;
uint32_t FileIndexHigh;
uint32_t FileIndexLow;
#endif
friend bool equivalent(file_status A, file_status B); friend bool equivalent(file_status A, file_status B);
file_type Type;
perms Perms; #if defined(LLVM_ON_UNIX)
dev_t fs_st_dev = 0;
ino_t fs_st_ino = 0;
time_t fs_st_atime = 0;
time_t fs_st_mtime = 0;
uid_t fs_st_uid = 0;
gid_t fs_st_gid = 0;
off_t fs_st_size = 0;
#elif defined (LLVM_ON_WIN32)
uint32_t LastAccessedTimeHigh = 0;
uint32_t LastAccessedTimeLow = 0;
uint32_t LastWriteTimeHigh = 0;
uint32_t LastWriteTimeLow = 0;
uint32_t VolumeSerialNumber = 0;
uint32_t FileSizeHigh = 0;
uint32_t FileSizeLow = 0;
uint32_t FileIndexHigh = 0;
uint32_t FileIndexLow = 0;
#endif
file_type Type = file_type::status_error;
perms Perms = perms_not_known;
public: public:
#if defined(LLVM_ON_UNIX) #if defined(LLVM_ON_UNIX)
file_status() file_status() = default;
: fs_st_dev(0), fs_st_ino(0), fs_st_atime(0), fs_st_mtime(0),
fs_st_uid(0), fs_st_gid(0), fs_st_size(0),
Type(file_type::status_error), Perms(perms_not_known) {}
file_status(file_type Type) file_status(file_type Type) : Type(Type) {}
: fs_st_dev(0), fs_st_ino(0), fs_st_atime(0), fs_st_mtime(0),
fs_st_uid(0), fs_st_gid(0), fs_st_size(0), Type(Type),
Perms(perms_not_known) {}
file_status(file_type Type, perms Perms, dev_t Dev, ino_t Ino, time_t ATime, file_status(file_type Type, perms Perms, dev_t Dev, ino_t Ino, time_t ATime,
time_t MTime, uid_t UID, gid_t GID, off_t Size) time_t MTime, uid_t UID, gid_t GID, off_t Size)
@ -182,17 +177,9 @@ public:
fs_st_uid(UID), fs_st_gid(GID), fs_st_size(Size), Type(Type), fs_st_uid(UID), fs_st_gid(GID), fs_st_size(Size), Type(Type),
Perms(Perms) {} Perms(Perms) {}
#elif defined(LLVM_ON_WIN32) #elif defined(LLVM_ON_WIN32)
file_status() file_status() = default;
: LastAccessedTimeHigh(0), LastAccessedTimeLow(0), LastWriteTimeHigh(0),
LastWriteTimeLow(0), VolumeSerialNumber(0), FileSizeHigh(0),
FileSizeLow(0), FileIndexHigh(0), FileIndexLow(0),
Type(file_type::status_error), Perms(perms_not_known) {}
file_status(file_type Type) file_status(file_type Type) : Type(Type) {}
: LastAccessedTimeHigh(0), LastAccessedTimeLow(0), LastWriteTimeHigh(0),
LastWriteTimeLow(0), VolumeSerialNumber(0), FileSizeHigh(0),
FileSizeLow(0), FileIndexHigh(0), FileIndexLow(0), Type(Type),
Perms(perms_not_known) {}
file_status(file_type Type, uint32_t LastAccessTimeHigh, file_status(file_type Type, uint32_t LastAccessTimeHigh,
uint32_t LastAccessTimeLow, uint32_t LastWriteTimeHigh, uint32_t LastAccessTimeLow, uint32_t LastWriteTimeHigh,
@ -204,7 +191,7 @@ public:
LastWriteTimeLow(LastWriteTimeLow), LastWriteTimeLow(LastWriteTimeLow),
VolumeSerialNumber(VolumeSerialNumber), FileSizeHigh(FileSizeHigh), VolumeSerialNumber(VolumeSerialNumber), FileSizeHigh(FileSizeHigh),
FileSizeLow(FileSizeLow), FileIndexHigh(FileIndexHigh), FileSizeLow(FileSizeLow), FileIndexHigh(FileIndexHigh),
FileIndexLow(FileIndexLow), Type(Type), Perms(perms_not_known) {} FileIndexLow(FileIndexLow), Type(Type) {}
#endif #endif
// getters // getters
@ -222,9 +209,11 @@ public:
uint32_t getUser() const { uint32_t getUser() const {
return 9999; // Not applicable to Windows, so... return 9999; // Not applicable to Windows, so...
} }
uint32_t getGroup() const { uint32_t getGroup() const {
return 9999; // Not applicable to Windows, so... return 9999; // Not applicable to Windows, so...
} }
uint64_t getSize() const { uint64_t getSize() const {
return (uint64_t(FileSizeHigh) << 32) + FileSizeLow; return (uint64_t(FileSizeHigh) << 32) + FileSizeLow;
} }
@ -271,12 +260,12 @@ struct file_magic {
return V != unknown; return V != unknown;
} }
file_magic() : V(unknown) {} file_magic() = default;
file_magic(Impl V) : V(V) {} file_magic(Impl V) : V(V) {}
operator Impl() const { return V; } operator Impl() const { return V; }
private: private:
Impl V; Impl V = unknown;
}; };
/// @} /// @}
@ -796,6 +785,7 @@ public:
}; };
namespace detail { namespace detail {
struct DirIterState; struct DirIterState;
std::error_code directory_iterator_construct(DirIterState &, StringRef); std::error_code directory_iterator_construct(DirIterState &, StringRef);
@ -811,6 +801,7 @@ namespace detail {
intptr_t IterationHandle = 0; intptr_t IterationHandle = 0;
directory_entry CurrentEntry; directory_entry CurrentEntry;
}; };
} // end namespace detail } // end namespace detail
/// directory_iterator - Iterates through the entries in path. There is no /// directory_iterator - Iterates through the entries in path. There is no
@ -862,12 +853,14 @@ public:
}; };
namespace detail { namespace detail {
/// Keeps state for the recursive_directory_iterator. /// Keeps state for the recursive_directory_iterator.
struct RecDirIterState { struct RecDirIterState {
std::stack<directory_iterator, std::vector<directory_iterator>> Stack; std::stack<directory_iterator, std::vector<directory_iterator>> Stack;
uint16_t Level = 0; uint16_t Level = 0;
bool HasNoPushRequest = false; bool HasNoPushRequest = false;
}; };
} // end namespace detail } // end namespace detail
/// recursive_directory_iterator - Same as directory_iterator except for it /// recursive_directory_iterator - Same as directory_iterator except for it

View File

@ -63,7 +63,7 @@ struct Options {
/// read operations. /// read operations.
class GCOVBuffer { class GCOVBuffer {
public: public:
GCOVBuffer(MemoryBuffer *B) : Buffer(B), Cursor(0) {} GCOVBuffer(MemoryBuffer *B) : Buffer(B) {}
/// readGCNOFormat - Check GCNO signature is valid at the beginning of buffer. /// readGCNOFormat - Check GCNO signature is valid at the beginning of buffer.
bool readGCNOFormat() { bool readGCNOFormat() {
@ -234,16 +234,14 @@ public:
private: private:
MemoryBuffer *Buffer; MemoryBuffer *Buffer;
uint64_t Cursor; uint64_t Cursor = 0;
}; };
/// GCOVFile - Collects coverage information for one pair of coverage file /// GCOVFile - Collects coverage information for one pair of coverage file
/// (.gcno and .gcda). /// (.gcno and .gcda).
class GCOVFile { class GCOVFile {
public: public:
GCOVFile() GCOVFile() = default;
: GCNOInitialized(false), Checksum(0), RunCount(0),
ProgramCount(0) {}
bool readGCNO(GCOVBuffer &Buffer); bool readGCNO(GCOVBuffer &Buffer);
bool readGCDA(GCOVBuffer &Buffer); bool readGCDA(GCOVBuffer &Buffer);
@ -253,21 +251,21 @@ public:
void collectLineCounts(FileInfo &FI); void collectLineCounts(FileInfo &FI);
private: private:
bool GCNOInitialized; bool GCNOInitialized = false;
GCOV::GCOVVersion Version; GCOV::GCOVVersion Version;
uint32_t Checksum; uint32_t Checksum = 0;
SmallVector<std::unique_ptr<GCOVFunction>, 16> Functions; SmallVector<std::unique_ptr<GCOVFunction>, 16> Functions;
uint32_t RunCount; uint32_t RunCount = 0;
uint32_t ProgramCount; uint32_t ProgramCount = 0;
}; };
/// GCOVEdge - Collects edge information. /// GCOVEdge - Collects edge information.
struct GCOVEdge { struct GCOVEdge {
GCOVEdge(GCOVBlock &S, GCOVBlock &D) : Src(S), Dst(D), Count(0) {} GCOVEdge(GCOVBlock &S, GCOVBlock &D) : Src(S), Dst(D) {}
GCOVBlock &Src; GCOVBlock &Src;
GCOVBlock &Dst; GCOVBlock &Dst;
uint64_t Count; uint64_t Count = 0;
}; };
/// GCOVFunction - Collects function information. /// GCOVFunction - Collects function information.
@ -276,7 +274,8 @@ public:
typedef pointee_iterator<SmallVectorImpl< typedef pointee_iterator<SmallVectorImpl<
std::unique_ptr<GCOVBlock>>::const_iterator> BlockIterator; std::unique_ptr<GCOVBlock>>::const_iterator> BlockIterator;
GCOVFunction(GCOVFile &P) : Parent(P), Ident(0), LineNumber(0) {} GCOVFunction(GCOVFile &P) : Parent(P) {}
bool readGCNO(GCOVBuffer &Buffer, GCOV::GCOVVersion Version); bool readGCNO(GCOVBuffer &Buffer, GCOV::GCOVVersion Version);
bool readGCDA(GCOVBuffer &Buffer, GCOV::GCOVVersion Version); bool readGCDA(GCOVBuffer &Buffer, GCOV::GCOVVersion Version);
StringRef getName() const { return Name; } StringRef getName() const { return Name; }
@ -297,9 +296,9 @@ public:
private: private:
GCOVFile &Parent; GCOVFile &Parent;
uint32_t Ident; uint32_t Ident = 0;
uint32_t Checksum; uint32_t Checksum;
uint32_t LineNumber; uint32_t LineNumber = 0;
StringRef Name; StringRef Name;
StringRef Filename; StringRef Filename;
SmallVector<std::unique_ptr<GCOVBlock>, 16> Blocks; SmallVector<std::unique_ptr<GCOVBlock>, 16> Blocks;
@ -309,10 +308,10 @@ private:
/// GCOVBlock - Collects block information. /// GCOVBlock - Collects block information.
class GCOVBlock { class GCOVBlock {
struct EdgeWeight { struct EdgeWeight {
EdgeWeight(GCOVBlock *D) : Dst(D), Count(0) {} EdgeWeight(GCOVBlock *D) : Dst(D) {}
GCOVBlock *Dst; GCOVBlock *Dst;
uint64_t Count; uint64_t Count = 0;
}; };
struct SortDstEdgesFunctor { struct SortDstEdgesFunctor {
@ -324,8 +323,7 @@ class GCOVBlock {
public: public:
typedef SmallVectorImpl<GCOVEdge *>::const_iterator EdgeIterator; typedef SmallVectorImpl<GCOVEdge *>::const_iterator EdgeIterator;
GCOVBlock(GCOVFunction &P, uint32_t N) GCOVBlock(GCOVFunction &P, uint32_t N) : Parent(P), Number(N) {}
: Parent(P), Number(N), Counter(0), DstEdgesAreSorted(true) {}
~GCOVBlock(); ~GCOVBlock();
const GCOVFunction &getParent() const { return Parent; } const GCOVFunction &getParent() const { return Parent; }
@ -370,8 +368,8 @@ public:
private: private:
GCOVFunction &Parent; GCOVFunction &Parent;
uint32_t Number; uint32_t Number;
uint64_t Counter; uint64_t Counter = 0;
bool DstEdgesAreSorted; bool DstEdgesAreSorted = true;
SmallVector<GCOVEdge *, 16> SrcEdges; SmallVector<GCOVEdge *, 16> SrcEdges;
SmallVector<GCOVEdge *, 16> DstEdges; SmallVector<GCOVEdge *, 16> DstEdges;
SmallVector<uint32_t, 16> Lines; SmallVector<uint32_t, 16> Lines;
@ -389,30 +387,28 @@ class FileInfo {
typedef DenseMap<uint32_t, BlockVector> BlockLines; typedef DenseMap<uint32_t, BlockVector> BlockLines;
struct LineData { struct LineData {
LineData() : LastLine(0) {} LineData() = default;
BlockLines Blocks; BlockLines Blocks;
FunctionLines Functions; FunctionLines Functions;
uint32_t LastLine; uint32_t LastLine = 0;
}; };
struct GCOVCoverage { struct GCOVCoverage {
GCOVCoverage(StringRef Name) GCOVCoverage(StringRef Name) : Name(Name) {}
: Name(Name), LogicalLines(0), LinesExec(0), Branches(0),
BranchesExec(0), BranchesTaken(0) {}
StringRef Name; StringRef Name;
uint32_t LogicalLines; uint32_t LogicalLines = 0;
uint32_t LinesExec; uint32_t LinesExec = 0;
uint32_t Branches; uint32_t Branches = 0;
uint32_t BranchesExec; uint32_t BranchesExec = 0;
uint32_t BranchesTaken; uint32_t BranchesTaken = 0;
}; };
public: public:
FileInfo(const GCOV::Options &Options) FileInfo(const GCOV::Options &Options) : Options(Options) {}
: Options(Options), RunCount(0), ProgramCount(0) {}
void addBlockLine(StringRef Filename, uint32_t Line, const GCOVBlock *Block) { void addBlockLine(StringRef Filename, uint32_t Line, const GCOVBlock *Block) {
if (Line > LineInfo[Filename].LastLine) if (Line > LineInfo[Filename].LastLine)
@ -449,8 +445,8 @@ private:
const GCOV::Options &Options; const GCOV::Options &Options;
StringMap<LineData> LineInfo; StringMap<LineData> LineInfo;
uint32_t RunCount; uint32_t RunCount = 0;
uint32_t ProgramCount; uint32_t ProgramCount = 0;
typedef SmallVector<std::pair<std::string, GCOVCoverage>, 4> FileCoverageList; typedef SmallVector<std::pair<std::string, GCOVCoverage>, 4> FileCoverageList;
typedef MapVector<const GCOVFunction *, GCOVCoverage> FuncCoverageMap; typedef MapVector<const GCOVFunction *, GCOVCoverage> FuncCoverageMap;

View File

@ -25,14 +25,19 @@
#define LLVM_SUPPORT_GENERICDOMTREE_H #define LLVM_SUPPORT_GENERICDOMTREE_H
#include "llvm/ADT/DenseMap.h" #include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/DepthFirstIterator.h"
#include "llvm/ADT/GraphTraits.h" #include "llvm/ADT/GraphTraits.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/SmallVector.h"
#include "llvm/Support/Compiler.h" #include "llvm/ADT/STLExtras.h"
#include "llvm/Support/raw_ostream.h" #include "llvm/Support/raw_ostream.h"
#include <algorithm> #include <algorithm>
#include <cassert>
#include <cstddef>
#include <iterator>
#include <memory>
#include <type_traits>
#include <utility>
#include <vector>
namespace llvm { namespace llvm {
@ -47,7 +52,7 @@ template <typename GT> struct DominatorTreeBaseTraits {
typename std::remove_pointer<typename GT::NodeRef>::type>; typename std::remove_pointer<typename GT::NodeRef>::type>;
}; };
} // End namespace detail } // end namespace detail
template <typename GT> template <typename GT>
using DominatorTreeBaseByGraphTraits = using DominatorTreeBaseByGraphTraits =
@ -59,13 +64,16 @@ template <class NodeT> class DominatorBase {
protected: protected:
std::vector<NodeT *> Roots; std::vector<NodeT *> Roots;
bool IsPostDominators; bool IsPostDominators;
explicit DominatorBase(bool isPostDom) explicit DominatorBase(bool isPostDom)
: Roots(), IsPostDominators(isPostDom) {} : Roots(), IsPostDominators(isPostDom) {}
DominatorBase(DominatorBase &&Arg) DominatorBase(DominatorBase &&Arg)
: Roots(std::move(Arg.Roots)), : Roots(std::move(Arg.Roots)),
IsPostDominators(std::move(Arg.IsPostDominators)) { IsPostDominators(std::move(Arg.IsPostDominators)) {
Arg.Roots.clear(); Arg.Roots.clear();
} }
DominatorBase &operator=(DominatorBase &&RHS) { DominatorBase &operator=(DominatorBase &&RHS) {
Roots = std::move(RHS.Roots); Roots = std::move(RHS.Roots);
IsPostDominators = std::move(RHS.IsPostDominators); IsPostDominators = std::move(RHS.IsPostDominators);
@ -85,19 +93,21 @@ public:
bool isPostDominator() const { return IsPostDominators; } bool isPostDominator() const { return IsPostDominators; }
}; };
struct PostDominatorTree;
/// \brief Base class for the actual dominator tree node. /// \brief Base class for the actual dominator tree node.
template <class NodeT> class DomTreeNodeBase { template <class NodeT> class DomTreeNodeBase {
friend struct PostDominatorTree;
template <class N> friend class DominatorTreeBase;
NodeT *TheBB; NodeT *TheBB;
DomTreeNodeBase<NodeT> *IDom; DomTreeNodeBase<NodeT> *IDom;
std::vector<DomTreeNodeBase<NodeT> *> Children; std::vector<DomTreeNodeBase<NodeT> *> Children;
mutable int DFSNumIn, DFSNumOut; mutable int DFSNumIn = -1;
mutable int DFSNumOut = -1;
template <class N> friend class DominatorTreeBase;
friend struct PostDominatorTree;
public: public:
DomTreeNodeBase(NodeT *BB, DomTreeNodeBase<NodeT> *iDom)
: TheBB(BB), IDom(iDom) {}
typedef typename std::vector<DomTreeNodeBase<NodeT> *>::iterator iterator; typedef typename std::vector<DomTreeNodeBase<NodeT> *>::iterator iterator;
typedef typename std::vector<DomTreeNodeBase<NodeT> *>::const_iterator typedef typename std::vector<DomTreeNodeBase<NodeT> *>::const_iterator
const_iterator; const_iterator;
@ -109,13 +119,11 @@ public:
NodeT *getBlock() const { return TheBB; } NodeT *getBlock() const { return TheBB; }
DomTreeNodeBase<NodeT> *getIDom() const { return IDom; } DomTreeNodeBase<NodeT> *getIDom() const { return IDom; }
const std::vector<DomTreeNodeBase<NodeT> *> &getChildren() const { const std::vector<DomTreeNodeBase<NodeT> *> &getChildren() const {
return Children; return Children;
} }
DomTreeNodeBase(NodeT *BB, DomTreeNodeBase<NodeT> *iDom)
: TheBB(BB), IDom(iDom), DFSNumIn(-1), DFSNumOut(-1) {}
std::unique_ptr<DomTreeNodeBase<NodeT>> std::unique_ptr<DomTreeNodeBase<NodeT>>
addChild(std::unique_ptr<DomTreeNodeBase<NodeT>> C) { addChild(std::unique_ptr<DomTreeNodeBase<NodeT>> C) {
Children.push_back(C.get()); Children.push_back(C.get());
@ -206,9 +214,6 @@ void Calculate(DominatorTreeBaseByGraphTraits<GraphTraits<N>> &DT, FuncT &F);
/// This class is a generic template over graph nodes. It is instantiated for /// This class is a generic template over graph nodes. It is instantiated for
/// various graphs in the LLVM IR or in the code generator. /// various graphs in the LLVM IR or in the code generator.
template <class NodeT> class DominatorTreeBase : public DominatorBase<NodeT> { template <class NodeT> class DominatorTreeBase : public DominatorBase<NodeT> {
DominatorTreeBase(const DominatorTreeBase &) = delete;
DominatorTreeBase &operator=(const DominatorTreeBase &) = delete;
bool dominatedBySlowTreeWalk(const DomTreeNodeBase<NodeT> *A, bool dominatedBySlowTreeWalk(const DomTreeNodeBase<NodeT> *A,
const DomTreeNodeBase<NodeT> *B) const { const DomTreeNodeBase<NodeT> *B) const {
assert(A != B); assert(A != B);
@ -239,16 +244,16 @@ protected:
DomTreeNodeMapType DomTreeNodes; DomTreeNodeMapType DomTreeNodes;
DomTreeNodeBase<NodeT> *RootNode; DomTreeNodeBase<NodeT> *RootNode;
mutable bool DFSInfoValid; mutable bool DFSInfoValid = false;
mutable unsigned int SlowQueries; mutable unsigned int SlowQueries = 0;
// Information record used during immediate dominators computation. // Information record used during immediate dominators computation.
struct InfoRec { struct InfoRec {
unsigned DFSNum; unsigned DFSNum = 0;
unsigned Parent; unsigned Parent = 0;
unsigned Semi; unsigned Semi = 0;
NodeT *Label; NodeT *Label = nullptr;
InfoRec() : DFSNum(0), Parent(0), Semi(0), Label(nullptr) {} InfoRec() = default;
}; };
DenseMap<NodeT *, NodeT *> IDoms; DenseMap<NodeT *, NodeT *> IDoms;
@ -336,7 +341,7 @@ protected:
public: public:
explicit DominatorTreeBase(bool isPostDom) explicit DominatorTreeBase(bool isPostDom)
: DominatorBase<NodeT>(isPostDom), DFSInfoValid(false), SlowQueries(0) {} : DominatorBase<NodeT>(isPostDom) {}
DominatorTreeBase(DominatorTreeBase &&Arg) DominatorTreeBase(DominatorTreeBase &&Arg)
: DominatorBase<NodeT>( : DominatorBase<NodeT>(
@ -348,6 +353,7 @@ public:
Vertex(std::move(Arg.Vertex)), Info(std::move(Arg.Info)) { Vertex(std::move(Arg.Vertex)), Info(std::move(Arg.Info)) {
Arg.wipe(); Arg.wipe();
} }
DominatorTreeBase &operator=(DominatorTreeBase &&RHS) { DominatorTreeBase &operator=(DominatorTreeBase &&RHS) {
DominatorBase<NodeT>::operator=( DominatorBase<NodeT>::operator=(
std::move(static_cast<DominatorBase<NodeT> &>(RHS))); std::move(static_cast<DominatorBase<NodeT> &>(RHS)));
@ -362,6 +368,9 @@ public:
return *this; return *this;
} }
DominatorTreeBase(const DominatorTreeBase &) = delete;
DominatorTreeBase &operator=(const DominatorTreeBase &) = delete;
/// compare - Return false if the other dominator tree base matches this /// compare - Return false if the other dominator tree base matches this
/// dominator tree base. Otherwise return true. /// dominator tree base. Otherwise return true.
bool compare(const DominatorTreeBase &Other) const { bool compare(const DominatorTreeBase &Other) const {
@ -720,7 +729,6 @@ public:
/// updateDFSNumbers - Assign In and Out numbers to the nodes while walking /// updateDFSNumbers - Assign In and Out numbers to the nodes while walking
/// dominator tree in dfs order. /// dominator tree in dfs order.
void updateDFSNumbers() const { void updateDFSNumbers() const {
if (DFSInfoValid) { if (DFSInfoValid) {
SlowQueries = 0; SlowQueries = 0;
return; return;
@ -807,6 +815,6 @@ bool DominatorTreeBase<NodeT>::properlyDominates(const NodeT *A,
getNode(const_cast<NodeT *>(B))); getNode(const_cast<NodeT *>(B)));
} }
} } // end namespace llvm
#endif #endif // LLVM_SUPPORT_GENERICDOMTREE_H

View File

@ -1,4 +1,4 @@
//===-- Support/TargetRegistry.h - Target Registration ----------*- C++ -*-===// //===- Support/TargetRegistry.h - Target Registration -----------*- C++ -*-===//
// //
// The LLVM Compiler Infrastructure // The LLVM Compiler Infrastructure
// //
@ -20,15 +20,22 @@
#define LLVM_SUPPORT_TARGETREGISTRY_H #define LLVM_SUPPORT_TARGETREGISTRY_H
#include "llvm-c/Disassembler.h" #include "llvm-c/Disassembler.h"
#include "llvm/ADT/iterator_range.h"
#include "llvm/ADT/Optional.h" #include "llvm/ADT/Optional.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Triple.h" #include "llvm/ADT/Triple.h"
#include "llvm/Support/CodeGen.h" #include "llvm/Support/CodeGen.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/FormattedStream.h" #include "llvm/Support/FormattedStream.h"
#include <algorithm>
#include <cassert> #include <cassert>
#include <cstddef>
#include <iterator>
#include <memory> #include <memory>
#include <string> #include <string>
namespace llvm { namespace llvm {
class AsmPrinter; class AsmPrinter;
class MCAsmBackend; class MCAsmBackend;
class MCAsmInfo; class MCAsmInfo;
@ -36,22 +43,20 @@ class MCAsmParser;
class MCCodeEmitter; class MCCodeEmitter;
class MCContext; class MCContext;
class MCDisassembler; class MCDisassembler;
class MCInstrAnalysis;
class MCInstPrinter; class MCInstPrinter;
class MCInstrAnalysis;
class MCInstrInfo; class MCInstrInfo;
class MCRegisterInfo; class MCRegisterInfo;
class MCRelocationInfo;
class MCStreamer; class MCStreamer;
class MCSubtargetInfo; class MCSubtargetInfo;
class MCSymbolizer; class MCSymbolizer;
class MCRelocationInfo;
class MCTargetAsmParser; class MCTargetAsmParser;
class MCTargetOptions; class MCTargetOptions;
class MCTargetStreamer; class MCTargetStreamer;
class raw_pwrite_stream;
class TargetMachine; class TargetMachine;
class TargetOptions; class TargetOptions;
class raw_ostream;
class raw_pwrite_stream;
class formatted_raw_ostream;
MCStreamer *createNullStreamer(MCContext &Ctx); MCStreamer *createNullStreamer(MCContext &Ctx);
MCStreamer *createAsmStreamer(MCContext &Ctx, MCStreamer *createAsmStreamer(MCContext &Ctx,
@ -232,38 +237,33 @@ private:
MCCodeEmitterCtorTy MCCodeEmitterCtorFn; MCCodeEmitterCtorTy MCCodeEmitterCtorFn;
// Construction functions for the various object formats, if registered. // Construction functions for the various object formats, if registered.
COFFStreamerCtorTy COFFStreamerCtorFn; COFFStreamerCtorTy COFFStreamerCtorFn = nullptr;
MachOStreamerCtorTy MachOStreamerCtorFn; MachOStreamerCtorTy MachOStreamerCtorFn = nullptr;
ELFStreamerCtorTy ELFStreamerCtorFn; ELFStreamerCtorTy ELFStreamerCtorFn = nullptr;
WasmStreamerCtorTy WasmStreamerCtorFn; WasmStreamerCtorTy WasmStreamerCtorFn = nullptr;
/// Construction function for this target's null TargetStreamer, if /// Construction function for this target's null TargetStreamer, if
/// registered (default = nullptr). /// registered (default = nullptr).
NullTargetStreamerCtorTy NullTargetStreamerCtorFn; NullTargetStreamerCtorTy NullTargetStreamerCtorFn = nullptr;
/// Construction function for this target's asm TargetStreamer, if /// Construction function for this target's asm TargetStreamer, if
/// registered (default = nullptr). /// registered (default = nullptr).
AsmTargetStreamerCtorTy AsmTargetStreamerCtorFn; AsmTargetStreamerCtorTy AsmTargetStreamerCtorFn = nullptr;
/// Construction function for this target's obj TargetStreamer, if /// Construction function for this target's obj TargetStreamer, if
/// registered (default = nullptr). /// registered (default = nullptr).
ObjectTargetStreamerCtorTy ObjectTargetStreamerCtorFn; ObjectTargetStreamerCtorTy ObjectTargetStreamerCtorFn = nullptr;
/// MCRelocationInfoCtorFn - Construction function for this target's /// MCRelocationInfoCtorFn - Construction function for this target's
/// MCRelocationInfo, if registered (default = llvm::createMCRelocationInfo) /// MCRelocationInfo, if registered (default = llvm::createMCRelocationInfo)
MCRelocationInfoCtorTy MCRelocationInfoCtorFn; MCRelocationInfoCtorTy MCRelocationInfoCtorFn = nullptr;
/// MCSymbolizerCtorFn - Construction function for this target's /// MCSymbolizerCtorFn - Construction function for this target's
/// MCSymbolizer, if registered (default = llvm::createMCSymbolizer) /// MCSymbolizer, if registered (default = llvm::createMCSymbolizer)
MCSymbolizerCtorTy MCSymbolizerCtorFn; MCSymbolizerCtorTy MCSymbolizerCtorFn = nullptr;
public: public:
Target() Target() = default;
: COFFStreamerCtorFn(nullptr), MachOStreamerCtorFn(nullptr),
ELFStreamerCtorFn(nullptr), WasmStreamerCtorFn(nullptr),
NullTargetStreamerCtorFn(nullptr),
AsmTargetStreamerCtorFn(nullptr), ObjectTargetStreamerCtorFn(nullptr),
MCRelocationInfoCtorFn(nullptr), MCSymbolizerCtorFn(nullptr) {}
/// @name Target Information /// @name Target Information
/// @{ /// @{
@ -564,12 +564,14 @@ struct TargetRegistry {
class iterator class iterator
: public std::iterator<std::forward_iterator_tag, Target, ptrdiff_t> { : public std::iterator<std::forward_iterator_tag, Target, ptrdiff_t> {
const Target *Current;
explicit iterator(Target *T) : Current(T) {}
friend struct TargetRegistry; friend struct TargetRegistry;
const Target *Current = nullptr;
explicit iterator(Target *T) : Current(T) {}
public: public:
iterator() : Current(nullptr) {} iterator() = default;
bool operator==(const iterator &x) const { return Current == x.Current; } bool operator==(const iterator &x) const { return Current == x.Current; }
bool operator!=(const iterator &x) const { return !operator==(x); } bool operator!=(const iterator &x) const { return !operator==(x); }
@ -1167,6 +1169,7 @@ private:
return new MCCodeEmitterImpl(); return new MCCodeEmitterImpl();
} }
}; };
}
#endif } // end namespace llvm
#endif // LLVM_SUPPORT_TARGETREGISTRY_H