From 1aa40f46ee8b86bd1ded97cc108301e42506c8ab Mon Sep 17 00:00:00 2001 From: Eugene Zelenko Date: Wed, 23 Nov 2016 22:25:16 +0000 Subject: [PATCH] [IR] Fix some Clang-tidy modernize-use-default, modernize-use-equal-delete and Include What You Use warnings; other minor fixes (NFC). Per Zachary Turner and Mehdi Amini suggestion to make only post-commit reviews. llvm-svn: 287834 --- llvm/include/llvm/IR/CFG.h | 49 +++++++++++-------- llvm/include/llvm/IR/CallSite.h | 31 ++++++++---- llvm/include/llvm/IR/ConstantFolder.h | 38 ++++++++++++-- llvm/include/llvm/IR/DebugInfoMetadata.h | 26 ++++++++-- llvm/include/llvm/IR/DiagnosticInfo.h | 11 +++-- llvm/include/llvm/IR/DiagnosticPrinter.h | 8 +-- llvm/include/llvm/IR/GVMaterializer.h | 9 ++-- .../llvm/IR/GetElementPtrTypeIterator.h | 20 ++++++-- llvm/include/llvm/IR/InstIterator.h | 12 +++-- llvm/include/llvm/IR/InstrTypes.h | 41 +++++++++++----- llvm/include/llvm/IR/NoFolder.h | 49 +++++++++++++++++-- llvm/include/llvm/IR/PassManagerInternal.h | 25 +++++++--- 12 files changed, 241 insertions(+), 78 deletions(-) diff --git a/llvm/include/llvm/IR/CFG.h b/llvm/include/llvm/IR/CFG.h index efbf1098ae59..52de11a06baf 100644 --- a/llvm/include/llvm/IR/CFG.h +++ b/llvm/include/llvm/IR/CFG.h @@ -16,9 +16,17 @@ #define LLVM_IR_CFG_H #include "llvm/ADT/GraphTraits.h" +#include "llvm/ADT/iterator.h" #include "llvm/ADT/iterator_range.h" +#include "llvm/IR/BasicBlock.h" #include "llvm/IR/Function.h" #include "llvm/IR/InstrTypes.h" +#include "llvm/IR/Value.h" +#include "llvm/Support/Casting.h" +#include "llvm/Support/type_traits.h" +#include +#include +#include namespace llvm { @@ -44,7 +52,7 @@ public: typedef typename super::pointer pointer; typedef typename super::reference reference; - PredIterator() {} + PredIterator() = default; explicit inline PredIterator(Ptr *bb) : It(bb->user_begin()) { advancePastNonTerminators(); } @@ -85,8 +93,8 @@ public: typedef PredIterator pred_iterator; typedef PredIterator const_pred_iterator; -typedef llvm::iterator_range pred_range; -typedef llvm::iterator_range pred_const_range; +typedef iterator_range pred_range; +typedef iterator_range pred_const_range; inline pred_iterator pred_begin(BasicBlock *BB) { return pred_iterator(BB); } inline const_pred_iterator pred_begin(const BasicBlock *BB) { @@ -114,8 +122,8 @@ typedef TerminatorInst::SuccIterator succ_iterator; typedef TerminatorInst::SuccIterator succ_const_iterator; -typedef llvm::iterator_range succ_range; -typedef llvm::iterator_range succ_const_range; +typedef iterator_range succ_range; +typedef iterator_range succ_const_range; inline succ_iterator succ_begin(BasicBlock *BB) { return succ_iterator(BB->getTerminator()); @@ -144,8 +152,6 @@ struct isPodLike> { static const bool value = isPodLike::value; }; - - //===--------------------------------------------------------------------===// // GraphTraits specializations for basic block graphs (CFGs) //===--------------------------------------------------------------------===// @@ -177,7 +183,7 @@ template <> struct GraphTraits { // a function is considered to be when traversing the predecessor edges of a BB // instead of the successor edges. // -template <> struct GraphTraits > { +template <> struct GraphTraits> { typedef BasicBlock *NodeRef; typedef pred_iterator ChildIteratorType; static NodeRef getEntryNode(Inverse G) { return G.Graph; } @@ -185,7 +191,7 @@ template <> struct GraphTraits > { static ChildIteratorType child_end(NodeRef N) { return pred_end(N); } }; -template <> struct GraphTraits > { +template <> struct GraphTraits> { typedef const BasicBlock *NodeRef; typedef const_pred_iterator ChildIteratorType; static NodeRef getEntryNode(Inverse G) { return G.Graph; } @@ -193,8 +199,6 @@ template <> struct GraphTraits > { static ChildIteratorType child_end(NodeRef N) { return pred_end(N); } }; - - //===--------------------------------------------------------------------===// // GraphTraits specializations for function basic block graphs (CFGs) //===--------------------------------------------------------------------===// @@ -208,13 +212,16 @@ template <> struct GraphTraits : public GraphTraits { // nodes_iterator/begin/end - Allow iteration over all nodes in the graph typedef pointer_iterator nodes_iterator; + static nodes_iterator nodes_begin(Function *F) { return nodes_iterator(F->begin()); } + static nodes_iterator nodes_end(Function *F) { return nodes_iterator(F->end()); } - static size_t size (Function *F) { return F->size(); } + + static size_t size(Function *F) { return F->size(); } }; template <> struct GraphTraits : public GraphTraits { @@ -222,34 +229,36 @@ template <> struct GraphTraits : // nodes_iterator/begin/end - Allow iteration over all nodes in the graph typedef pointer_iterator nodes_iterator; + static nodes_iterator nodes_begin(const Function *F) { return nodes_iterator(F->begin()); } + static nodes_iterator nodes_end(const Function *F) { return nodes_iterator(F->end()); } - static size_t size (const Function *F) { return F->size(); } -}; + static size_t size(const Function *F) { return F->size(); } +}; // Provide specializations of GraphTraits to be able to treat a function as a // graph of basic blocks... and to walk it in inverse order. Inverse order for // a function is considered to be when traversing the predecessor edges of a BB // instead of the successor edges. // -template <> struct GraphTraits > : - public GraphTraits > { +template <> struct GraphTraits> : + public GraphTraits> { static NodeRef getEntryNode(Inverse G) { return &G.Graph->getEntryBlock(); } }; -template <> struct GraphTraits > : - public GraphTraits > { +template <> struct GraphTraits> : + public GraphTraits> { static NodeRef getEntryNode(Inverse G) { return &G.Graph->getEntryBlock(); } }; -} // End llvm namespace +} // end namespace llvm -#endif +#endif // LLVM_IR_CFG_H diff --git a/llvm/include/llvm/IR/CallSite.h b/llvm/include/llvm/IR/CallSite.h index 407849927431..b02c89474146 100644 --- a/llvm/include/llvm/IR/CallSite.h +++ b/llvm/include/llvm/IR/CallSite.h @@ -26,17 +26,26 @@ #ifndef LLVM_IR_CALLSITE_H #define LLVM_IR_CALLSITE_H -#include "llvm/ADT/PointerIntPair.h" #include "llvm/ADT/iterator_range.h" +#include "llvm/ADT/Optional.h" +#include "llvm/ADT/PointerIntPair.h" #include "llvm/IR/Attributes.h" #include "llvm/IR/CallingConv.h" +#include "llvm/IR/Function.h" +#include "llvm/IR/InstrTypes.h" +#include "llvm/IR/Instruction.h" #include "llvm/IR/Instructions.h" +#include "llvm/IR/Intrinsics.h" +#include "llvm/Support/Casting.h" +#include "llvm/IR/Use.h" +#include "llvm/IR/User.h" +#include "llvm/IR/Value.h" +#include +#include +#include namespace llvm { -class CallInst; -class InvokeInst; - template { public: - CallSite() {} + CallSite() = default; CallSite(CallSiteBase B) : CallSiteBase(B) {} CallSite(CallInst *CI) : CallSiteBase(CI) {} CallSite(InvokeInst *II) : CallSiteBase(II) {} @@ -624,25 +633,29 @@ public: private: friend struct DenseMapInfo; + User::op_iterator getCallee() const; }; template <> struct DenseMapInfo { - using BaseInfo = llvm::DenseMapInfo; + using BaseInfo = DenseMapInfo; static CallSite getEmptyKey() { CallSite CS; CS.I = BaseInfo::getEmptyKey(); return CS; } + static CallSite getTombstoneKey() { CallSite CS; CS.I = BaseInfo::getTombstoneKey(); return CS; } + static unsigned getHashValue(const CallSite &CS) { return BaseInfo::getHashValue(CS.I); } + static bool isEqual(const CallSite &LHS, const CallSite &RHS) { return LHS == RHS; } @@ -651,7 +664,7 @@ template <> struct DenseMapInfo { /// ImmutableCallSite - establish a view to a call site for examination class ImmutableCallSite : public CallSiteBase<> { public: - ImmutableCallSite() {} + ImmutableCallSite() = default; ImmutableCallSite(const CallInst *CI) : CallSiteBase(CI) {} ImmutableCallSite(const InvokeInst *II) : CallSiteBase(II) {} explicit ImmutableCallSite(const Instruction *II) : CallSiteBase(II) {} @@ -659,6 +672,6 @@ public: ImmutableCallSite(CallSite CS) : CallSiteBase(CS.getInstruction()) {} }; -} // End llvm namespace +} // end namespace llvm -#endif +#endif // LLVM_IR_CALLSITE_H diff --git a/llvm/include/llvm/IR/ConstantFolder.h b/llvm/include/llvm/IR/ConstantFolder.h index fb6ca3b3184c..da5bba7ba141 100644 --- a/llvm/include/llvm/IR/ConstantFolder.h +++ b/llvm/include/llvm/IR/ConstantFolder.h @@ -17,15 +17,17 @@ #ifndef LLVM_IR_CONSTANTFOLDER_H #define LLVM_IR_CONSTANTFOLDER_H +#include "llvm/ADT/ArrayRef.h" #include "llvm/IR/Constants.h" #include "llvm/IR/InstrTypes.h" +#include "llvm/IR/Instruction.h" namespace llvm { /// ConstantFolder - Create constants with minimum, target independent, folding. class ConstantFolder { public: - explicit ConstantFolder() {} + explicit ConstantFolder() = default; //===--------------------------------------------------------------------===// // Binary Operators @@ -35,61 +37,78 @@ public: bool HasNUW = false, bool HasNSW = false) const { return ConstantExpr::getAdd(LHS, RHS, HasNUW, HasNSW); } + Constant *CreateFAdd(Constant *LHS, Constant *RHS) const { return ConstantExpr::getFAdd(LHS, RHS); } + Constant *CreateSub(Constant *LHS, Constant *RHS, bool HasNUW = false, bool HasNSW = false) const { return ConstantExpr::getSub(LHS, RHS, HasNUW, HasNSW); } + Constant *CreateFSub(Constant *LHS, Constant *RHS) const { return ConstantExpr::getFSub(LHS, RHS); } + Constant *CreateMul(Constant *LHS, Constant *RHS, bool HasNUW = false, bool HasNSW = false) const { return ConstantExpr::getMul(LHS, RHS, HasNUW, HasNSW); } + Constant *CreateFMul(Constant *LHS, Constant *RHS) const { return ConstantExpr::getFMul(LHS, RHS); } + Constant *CreateUDiv(Constant *LHS, Constant *RHS, bool isExact = false) const { return ConstantExpr::getUDiv(LHS, RHS, isExact); } + Constant *CreateSDiv(Constant *LHS, Constant *RHS, bool isExact = false) const { return ConstantExpr::getSDiv(LHS, RHS, isExact); } + Constant *CreateFDiv(Constant *LHS, Constant *RHS) const { return ConstantExpr::getFDiv(LHS, RHS); } + Constant *CreateURem(Constant *LHS, Constant *RHS) const { return ConstantExpr::getURem(LHS, RHS); } + Constant *CreateSRem(Constant *LHS, Constant *RHS) const { return ConstantExpr::getSRem(LHS, RHS); } + Constant *CreateFRem(Constant *LHS, Constant *RHS) const { return ConstantExpr::getFRem(LHS, RHS); } + Constant *CreateShl(Constant *LHS, Constant *RHS, bool HasNUW = false, bool HasNSW = false) const { return ConstantExpr::getShl(LHS, RHS, HasNUW, HasNSW); } + Constant *CreateLShr(Constant *LHS, Constant *RHS, bool isExact = false) const { return ConstantExpr::getLShr(LHS, RHS, isExact); } + Constant *CreateAShr(Constant *LHS, Constant *RHS, bool isExact = false) const { return ConstantExpr::getAShr(LHS, RHS, isExact); } + Constant *CreateAnd(Constant *LHS, Constant *RHS) const { return ConstantExpr::getAnd(LHS, RHS); } + Constant *CreateOr(Constant *LHS, Constant *RHS) const { return ConstantExpr::getOr(LHS, RHS); } + Constant *CreateXor(Constant *LHS, Constant *RHS) const { return ConstantExpr::getXor(LHS, RHS); } @@ -107,9 +126,11 @@ public: bool HasNUW = false, bool HasNSW = false) const { return ConstantExpr::getNeg(C, HasNUW, HasNSW); } + Constant *CreateFNeg(Constant *C) const { return ConstantExpr::getFNeg(C); } + Constant *CreateNot(Constant *C) const { return ConstantExpr::getNot(C); } @@ -122,12 +143,14 @@ public: ArrayRef IdxList) const { return ConstantExpr::getGetElementPtr(Ty, C, IdxList); } + Constant *CreateGetElementPtr(Type *Ty, Constant *C, Constant *Idx) const { // This form of the function only exists to avoid ambiguous overload // warnings about whether to convert Idx to ArrayRef or // ArrayRef. return ConstantExpr::getGetElementPtr(Ty, C, Idx); } + Constant *CreateGetElementPtr(Type *Ty, Constant *C, ArrayRef IdxList) const { return ConstantExpr::getGetElementPtr(Ty, C, IdxList); @@ -137,6 +160,7 @@ public: ArrayRef IdxList) const { return ConstantExpr::getInBoundsGetElementPtr(Ty, C, IdxList); } + Constant *CreateInBoundsGetElementPtr(Type *Ty, Constant *C, Constant *Idx) const { // This form of the function only exists to avoid ambiguous overload @@ -144,6 +168,7 @@ public: // ArrayRef. return ConstantExpr::getInBoundsGetElementPtr(Ty, C, Idx); } + Constant *CreateInBoundsGetElementPtr(Type *Ty, Constant *C, ArrayRef IdxList) const { return ConstantExpr::getInBoundsGetElementPtr(Ty, C, IdxList); @@ -157,6 +182,7 @@ public: Type *DestTy) const { return ConstantExpr::getCast(Op, C, DestTy); } + Constant *CreatePointerCast(Constant *C, Type *DestTy) const { return ConstantExpr::getPointerCast(C, DestTy); } @@ -170,6 +196,7 @@ public: bool isSigned) const { return ConstantExpr::getIntegerCast(C, DestTy, isSigned); } + Constant *CreateFPCast(Constant *C, Type *DestTy) const { return ConstantExpr::getFPCast(C, DestTy); } @@ -177,15 +204,19 @@ public: Constant *CreateBitCast(Constant *C, Type *DestTy) const { return CreateCast(Instruction::BitCast, C, DestTy); } + Constant *CreateIntToPtr(Constant *C, Type *DestTy) const { return CreateCast(Instruction::IntToPtr, C, DestTy); } + Constant *CreatePtrToInt(Constant *C, Type *DestTy) const { return CreateCast(Instruction::PtrToInt, C, DestTy); } + Constant *CreateZExtOrBitCast(Constant *C, Type *DestTy) const { return ConstantExpr::getZExtOrBitCast(C, DestTy); } + Constant *CreateSExtOrBitCast(Constant *C, Type *DestTy) const { return ConstantExpr::getSExtOrBitCast(C, DestTy); } @@ -202,6 +233,7 @@ public: Constant *RHS) const { return ConstantExpr::getCompare(P, LHS, RHS); } + Constant *CreateFCmp(CmpInst::Predicate P, Constant *LHS, Constant *RHS) const { return ConstantExpr::getCompare(P, LHS, RHS); @@ -240,6 +272,6 @@ public: } }; -} +} // end namespace llvm -#endif +#endif // LLVM_IR_CONSTANTFOLDER_H diff --git a/llvm/include/llvm/IR/DebugInfoMetadata.h b/llvm/include/llvm/IR/DebugInfoMetadata.h index aaa0e0d49792..c434f40b0739 100644 --- a/llvm/include/llvm/IR/DebugInfoMetadata.h +++ b/llvm/include/llvm/IR/DebugInfoMetadata.h @@ -14,9 +14,21 @@ #ifndef LLVM_IR_DEBUGINFOMETADATA_H #define LLVM_IR_DEBUGINFOMETADATA_H +#include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/BitmaskEnum.h" +#include "llvm/ADT/None.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/StringRef.h" #include "llvm/IR/Metadata.h" +#include "llvm/Support/Casting.h" #include "llvm/Support/Dwarf.h" +#include +#include +#include +#include +#include +#include +#include // Helper macros for defining get() overrides. #define DEFINE_MDNODE_GET_UNPACK_IMPL(...) __VA_ARGS__ @@ -109,16 +121,20 @@ public: public: iterator() = default; explicit iterator(MDNode::op_iterator I) : I(I) {} + DITypeRef operator*() const { return DITypeRef(*I); } + iterator &operator++() { ++I; return *this; } + iterator operator++(int) { iterator Temp(*this); ++I; return Temp; } + bool operator==(const iterator &X) const { return I == X.I; } bool operator!=(const iterator &X) const { return I != X.I; } }; @@ -985,6 +1001,7 @@ public: class DICompileUnit : public DIScope { friend class LLVMContextImpl; friend class MDNode; + public: enum DebugEmissionKind : unsigned { NoDebug = 0, @@ -992,6 +1009,7 @@ public: LineTablesOnly, LastEmissionKind = LineTablesOnly }; + static Optional getEmissionKind(StringRef Str); static const char *EmissionKindString(DebugEmissionKind EK); @@ -1050,10 +1068,10 @@ private: getMacros(), DWOId, getSplitDebugInlining()); } +public: static void get() = delete; static void getIfExists() = delete; -public: DEFINE_MDNODE_GET_DISTINCT_TEMPORARY( DICompileUnit, (unsigned SourceLanguage, DIFile *File, StringRef Producer, @@ -1210,10 +1228,10 @@ class DILocation : public MDNode { getRawInlinedAt()); } +public: // Disallow replacing operands. void replaceOperandWith(unsigned I, Metadata *New) = delete; -public: DEFINE_MDNODE_GET(DILocation, (unsigned Line, unsigned Column, Metadata *Scope, Metadata *InlinedAt = nullptr), @@ -1694,7 +1712,7 @@ class DIModule : public DIScope { DIModule(LLVMContext &Context, StorageType Storage, ArrayRef Ops) : DIScope(Context, DIModuleKind, Storage, dwarf::DW_TAG_module, Ops) {} - ~DIModule() {} + ~DIModule() = default; static DIModule *getImpl(LLVMContext &Context, DIScope *Scope, StringRef Name, StringRef ConfigurationMacros, @@ -2519,4 +2537,4 @@ public: #undef DEFINE_MDNODE_GET_UNPACK #undef DEFINE_MDNODE_GET -#endif +#endif // LLVM_IR_DEBUGINFOMETADATA_H diff --git a/llvm/include/llvm/IR/DiagnosticInfo.h b/llvm/include/llvm/IR/DiagnosticInfo.h index 3a2e789257f9..62732abe0242 100644 --- a/llvm/include/llvm/IR/DiagnosticInfo.h +++ b/llvm/include/llvm/IR/DiagnosticInfo.h @@ -15,15 +15,19 @@ #ifndef LLVM_IR_DIAGNOSTICINFO_H #define LLVM_IR_DIAGNOSTICINFO_H -#include "llvm-c/Types.h" +#include "llvm/ADT/None.h" #include "llvm/ADT/Optional.h" -#include "llvm/ADT/SmallString.h" +#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/Twine.h" #include "llvm/IR/DebugLoc.h" #include "llvm/Support/CBindingWrapping.h" #include "llvm/Support/YAMLTraits.h" +#include "llvm-c/Types.h" #include +#include +#include +#include #include namespace llvm { @@ -97,7 +101,7 @@ public: DiagnosticInfo(/* DiagnosticKind */ int Kind, DiagnosticSeverity Severity) : Kind(Kind), Severity(Severity) {} - virtual ~DiagnosticInfo() {} + virtual ~DiagnosticInfo() = default; /* DiagnosticKind */ int getKind() const { return Kind; } DiagnosticSeverity getSeverity() const { return Severity; } @@ -274,7 +278,6 @@ public: } }; - /// Diagnostic information for the sample profiler. class DiagnosticInfoSampleProfile : public DiagnosticInfo { public: diff --git a/llvm/include/llvm/IR/DiagnosticPrinter.h b/llvm/include/llvm/IR/DiagnosticPrinter.h index 1bcd73738b66..59c83291affa 100644 --- a/llvm/include/llvm/IR/DiagnosticPrinter.h +++ b/llvm/include/llvm/IR/DiagnosticPrinter.h @@ -19,6 +19,7 @@ #include namespace llvm { + // Forward declarations. class Module; class raw_ostream; @@ -30,7 +31,7 @@ class Value; /// \brief Interface for custom diagnostic printing. class DiagnosticPrinter { public: - virtual ~DiagnosticPrinter() {} + virtual ~DiagnosticPrinter() = default; // Simple types. virtual DiagnosticPrinter &operator<<(char C) = 0; @@ -89,6 +90,7 @@ public: // Other types. DiagnosticPrinter &operator<<(const SMDiagnostic &Diag) override; }; -} // End namespace llvm -#endif +} // end namespace llvm + +#endif // LLVM_IR_DIAGNOSTICPRINTER_H diff --git a/llvm/include/llvm/IR/GVMaterializer.h b/llvm/include/llvm/IR/GVMaterializer.h index b02459e84e8b..675abeb6ec3a 100644 --- a/llvm/include/llvm/IR/GVMaterializer.h +++ b/llvm/include/llvm/IR/GVMaterializer.h @@ -21,15 +21,14 @@ #include namespace llvm { + class Error; -class Function; class GlobalValue; -class Module; class StructType; class GVMaterializer { protected: - GVMaterializer() {} + GVMaterializer() = default; public: virtual ~GVMaterializer(); @@ -48,6 +47,6 @@ public: virtual std::vector getIdentifiedStructTypes() const = 0; }; -} // End llvm namespace +} // end namespace llvm -#endif +#endif // LLVM_IR_GVMATERIALIZER_H diff --git a/llvm/include/llvm/IR/GetElementPtrTypeIterator.h b/llvm/include/llvm/IR/GetElementPtrTypeIterator.h index 4953aebbe8aa..1e896218f7fe 100644 --- a/llvm/include/llvm/IR/GetElementPtrTypeIterator.h +++ b/llvm/include/llvm/IR/GetElementPtrTypeIterator.h @@ -15,12 +15,17 @@ #ifndef LLVM_IR_GETELEMENTPTRTYPEITERATOR_H #define LLVM_IR_GETELEMENTPTRTYPEITERATOR_H +#include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/PointerIntPair.h" #include "llvm/IR/DerivedTypes.h" #include "llvm/IR/Operator.h" #include "llvm/IR/User.h" -#include "llvm/ADT/PointerIntPair.h" +#include "llvm/Support/Casting.h" +#include +#include namespace llvm { + template class generic_gep_type_iterator : public std::iterator { @@ -30,9 +35,10 @@ namespace llvm { ItTy OpIt; PointerIntPair CurTy; unsigned AddrSpace; - generic_gep_type_iterator() {} - public: + generic_gep_type_iterator() = default; + + public: static generic_gep_type_iterator begin(Type *Ty, unsigned AddrSpace, ItTy It) { generic_gep_type_iterator I; @@ -42,6 +48,7 @@ namespace llvm { I.OpIt = It; return I; } + static generic_gep_type_iterator end(ItTy It) { generic_gep_type_iterator I; I.OpIt = It; @@ -51,6 +58,7 @@ namespace llvm { bool operator==(const generic_gep_type_iterator& x) const { return OpIt == x.OpIt; } + bool operator!=(const generic_gep_type_iterator& x) const { return !operator==(x); } @@ -102,9 +110,11 @@ namespace llvm { ->getAddressSpace(), GEP->op_begin() + 1); } + inline gep_type_iterator gep_type_end(const User *GEP) { return gep_type_iterator::end(GEP->op_end()); } + inline gep_type_iterator gep_type_begin(const User &GEP) { auto &GEPOp = cast(GEP); return gep_type_iterator::begin( @@ -113,6 +123,7 @@ namespace llvm { ->getAddressSpace(), GEP.op_begin() + 1); } + inline gep_type_iterator gep_type_end(const User &GEP) { return gep_type_iterator::end(GEP.op_end()); } @@ -128,6 +139,7 @@ namespace llvm { gep_type_end(Type * /*Op0*/, unsigned /*AS*/, ArrayRef A) { return generic_gep_type_iterator::end(A.end()); } + } // end namespace llvm -#endif +#endif // LLVM_IR_GETELEMENTPTRTYPEITERATOR_H diff --git a/llvm/include/llvm/IR/InstIterator.h b/llvm/include/llvm/IR/InstIterator.h index 1baca21c73af..28fc473f1490 100644 --- a/llvm/include/llvm/IR/InstIterator.h +++ b/llvm/include/llvm/IR/InstIterator.h @@ -19,8 +19,11 @@ #ifndef LLVM_IR_INSTITERATOR_H #define LLVM_IR_INSTITERATOR_H +#include "llvm/ADT/iterator_range.h" #include "llvm/IR/BasicBlock.h" #include "llvm/IR/Function.h" +#include "llvm/IR/SymbolTableListTraits.h" +#include namespace llvm { @@ -35,6 +38,7 @@ template class InstIterator { BB_t *BBs; // BasicBlocksType BB_i_t BB; // BasicBlocksType::iterator BI_t BI; // BasicBlock::iterator + public: typedef std::bidirectional_iterator_tag iterator_category; typedef IIty value_type; @@ -43,7 +47,7 @@ public: typedef IIty& reference; // Default constructor - InstIterator() {} + InstIterator() = default; // Copy constructor... template @@ -97,7 +101,7 @@ public: --BI; return *this; } - inline InstIterator operator--(int) { + inline InstIterator operator--(int) { InstIterator tmp = *this; --*this; return tmp; } @@ -152,6 +156,6 @@ inline const_inst_range instructions(const Function &F) { return const_inst_range(inst_begin(F), inst_end(F)); } -} // End llvm namespace +} // end namespace llvm -#endif +#endif // LLVM_IR_INSTITERATOR_H diff --git a/llvm/include/llvm/IR/InstrTypes.h b/llvm/include/llvm/IR/InstrTypes.h index 282e0637f8a7..f2abbec64fe6 100644 --- a/llvm/include/llvm/IR/InstrTypes.h +++ b/llvm/include/llvm/IR/InstrTypes.h @@ -16,18 +16,32 @@ #ifndef LLVM_IR_INSTRTYPES_H #define LLVM_IR_INSTRTYPES_H +#include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/iterator_range.h" +#include "llvm/ADT/None.h" #include "llvm/ADT/Optional.h" +#include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/StringMap.h" +#include "llvm/ADT/StringRef.h" #include "llvm/ADT/Twine.h" #include "llvm/IR/Attributes.h" #include "llvm/IR/DerivedTypes.h" #include "llvm/IR/Instruction.h" #include "llvm/IR/LLVMContext.h" #include "llvm/IR/OperandTraits.h" +#include "llvm/IR/User.h" +#include "llvm/Support/Casting.h" +#include "llvm/Support/ErrorHandling.h" +#include +#include +#include +#include +#include +#include +#include namespace llvm { -class LLVMContext; - //===----------------------------------------------------------------------===// // TerminatorInst Class //===----------------------------------------------------------------------===// @@ -249,8 +263,8 @@ public: typedef SuccIterator succ_iterator; typedef SuccIterator succ_const_iterator; - typedef llvm::iterator_range succ_range; - typedef llvm::iterator_range succ_const_range; + typedef iterator_range succ_range; + typedef iterator_range succ_const_range; private: inline succ_iterator succ_begin() { return succ_iterator(this); } @@ -276,8 +290,6 @@ public: //===----------------------------------------------------------------------===// class UnaryInstruction : public Instruction { - void *operator new(size_t, unsigned) = delete; - protected: UnaryInstruction(Type *Ty, unsigned iType, Value *V, Instruction *IB = nullptr) @@ -295,6 +307,8 @@ public: return User::operator new(s, 1); } + void *operator new(size_t, unsigned) = delete; + // Out of line virtual method, so the vtable, etc has a home. ~UnaryInstruction() override; @@ -326,8 +340,6 @@ DEFINE_TRANSPARENT_OPERAND_ACCESSORS(UnaryInstruction, Value) //===----------------------------------------------------------------------===// class BinaryOperator : public Instruction { - void *operator new(size_t, unsigned) = delete; - protected: void init(BinaryOps iType); BinaryOperator(BinaryOps iType, Value *S1, Value *S2, Type *Ty, @@ -345,6 +357,8 @@ public: return User::operator new(s, 2); } + void *operator new(size_t, unsigned) = delete; + /// Transparently provide more efficient getOperand methods. DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); @@ -899,10 +913,6 @@ public: BAD_ICMP_PREDICATE = ICMP_SLE + 1 }; -private: - void *operator new(size_t, unsigned) = delete; - CmpInst() = delete; - protected: CmpInst(Type *ty, Instruction::OtherOps op, Predicate pred, Value *LHS, Value *RHS, const Twine &Name = "", @@ -915,10 +925,15 @@ protected: void anchor() override; // Out of line virtual method. public: + CmpInst() = delete; + // allocate space for exactly two operands void *operator new(size_t s) { return User::operator new(s, 2); } + + void *operator new(size_t, unsigned) = delete; + /// Construct a compare instruction, given the opcode, the predicate and /// the two operands. Optionally (if InstBefore is specified) insert the /// instruction into a BasicBlock right before the specified instruction. @@ -1191,7 +1206,7 @@ DEFINE_TRANSPARENT_OPERAND_ACCESSORS(FuncletPadInst, Value) struct OperandBundleUse { ArrayRef Inputs; - OperandBundleUse() {} + OperandBundleUse() = default; explicit OperandBundleUse(StringMapEntry *Tag, ArrayRef Inputs) : Inputs(Inputs), Tag(Tag) {} diff --git a/llvm/include/llvm/IR/NoFolder.h b/llvm/include/llvm/IR/NoFolder.h index 61f4817a9b62..def07ffe2ff6 100644 --- a/llvm/include/llvm/IR/NoFolder.h +++ b/llvm/include/llvm/IR/NoFolder.h @@ -24,6 +24,8 @@ #include "llvm/ADT/ArrayRef.h" #include "llvm/IR/Constants.h" +#include "llvm/IR/InstrTypes.h" +#include "llvm/IR/Instruction.h" #include "llvm/IR/Instructions.h" namespace llvm { @@ -31,7 +33,7 @@ namespace llvm { /// NoFolder - Create "constants" (actually, instructions) with no folding. class NoFolder { public: - explicit NoFolder() {} + explicit NoFolder() = default; //===--------------------------------------------------------------------===// // Binary Operators @@ -44,15 +46,19 @@ public: if (HasNSW) BO->setHasNoSignedWrap(); return BO; } + Instruction *CreateNSWAdd(Constant *LHS, Constant *RHS) const { return BinaryOperator::CreateNSWAdd(LHS, RHS); } + Instruction *CreateNUWAdd(Constant *LHS, Constant *RHS) const { return BinaryOperator::CreateNUWAdd(LHS, RHS); } + Instruction *CreateFAdd(Constant *LHS, Constant *RHS) const { return BinaryOperator::CreateFAdd(LHS, RHS); } + Instruction *CreateSub(Constant *LHS, Constant *RHS, bool HasNUW = false, bool HasNSW = false) const { BinaryOperator *BO = BinaryOperator::CreateSub(LHS, RHS); @@ -60,15 +66,19 @@ public: if (HasNSW) BO->setHasNoSignedWrap(); return BO; } + Instruction *CreateNSWSub(Constant *LHS, Constant *RHS) const { return BinaryOperator::CreateNSWSub(LHS, RHS); } + Instruction *CreateNUWSub(Constant *LHS, Constant *RHS) const { return BinaryOperator::CreateNUWSub(LHS, RHS); } + Instruction *CreateFSub(Constant *LHS, Constant *RHS) const { return BinaryOperator::CreateFSub(LHS, RHS); } + Instruction *CreateMul(Constant *LHS, Constant *RHS, bool HasNUW = false, bool HasNSW = false) const { BinaryOperator *BO = BinaryOperator::CreateMul(LHS, RHS); @@ -76,45 +86,57 @@ public: if (HasNSW) BO->setHasNoSignedWrap(); return BO; } + Instruction *CreateNSWMul(Constant *LHS, Constant *RHS) const { return BinaryOperator::CreateNSWMul(LHS, RHS); } + Instruction *CreateNUWMul(Constant *LHS, Constant *RHS) const { return BinaryOperator::CreateNUWMul(LHS, RHS); } + Instruction *CreateFMul(Constant *LHS, Constant *RHS) const { return BinaryOperator::CreateFMul(LHS, RHS); } + Instruction *CreateUDiv(Constant *LHS, Constant *RHS, bool isExact = false) const { if (!isExact) return BinaryOperator::CreateUDiv(LHS, RHS); return BinaryOperator::CreateExactUDiv(LHS, RHS); } + Instruction *CreateExactUDiv(Constant *LHS, Constant *RHS) const { return BinaryOperator::CreateExactUDiv(LHS, RHS); } + Instruction *CreateSDiv(Constant *LHS, Constant *RHS, bool isExact = false) const { if (!isExact) return BinaryOperator::CreateSDiv(LHS, RHS); return BinaryOperator::CreateExactSDiv(LHS, RHS); } + Instruction *CreateExactSDiv(Constant *LHS, Constant *RHS) const { return BinaryOperator::CreateExactSDiv(LHS, RHS); } + Instruction *CreateFDiv(Constant *LHS, Constant *RHS) const { return BinaryOperator::CreateFDiv(LHS, RHS); } + Instruction *CreateURem(Constant *LHS, Constant *RHS) const { return BinaryOperator::CreateURem(LHS, RHS); } + Instruction *CreateSRem(Constant *LHS, Constant *RHS) const { return BinaryOperator::CreateSRem(LHS, RHS); } + Instruction *CreateFRem(Constant *LHS, Constant *RHS) const { return BinaryOperator::CreateFRem(LHS, RHS); } + Instruction *CreateShl(Constant *LHS, Constant *RHS, bool HasNUW = false, bool HasNSW = false) const { BinaryOperator *BO = BinaryOperator::CreateShl(LHS, RHS); @@ -122,24 +144,29 @@ public: if (HasNSW) BO->setHasNoSignedWrap(); return BO; } + Instruction *CreateLShr(Constant *LHS, Constant *RHS, bool isExact = false) const { if (!isExact) return BinaryOperator::CreateLShr(LHS, RHS); return BinaryOperator::CreateExactLShr(LHS, RHS); } + Instruction *CreateAShr(Constant *LHS, Constant *RHS, bool isExact = false) const { if (!isExact) return BinaryOperator::CreateAShr(LHS, RHS); return BinaryOperator::CreateExactAShr(LHS, RHS); } + Instruction *CreateAnd(Constant *LHS, Constant *RHS) const { return BinaryOperator::CreateAnd(LHS, RHS); } + Instruction *CreateOr(Constant *LHS, Constant *RHS) const { return BinaryOperator::CreateOr(LHS, RHS); } + Instruction *CreateXor(Constant *LHS, Constant *RHS) const { return BinaryOperator::CreateXor(LHS, RHS); } @@ -160,15 +187,19 @@ public: if (HasNSW) BO->setHasNoSignedWrap(); return BO; } + Instruction *CreateNSWNeg(Constant *C) const { return BinaryOperator::CreateNSWNeg(C); } + Instruction *CreateNUWNeg(Constant *C) const { return BinaryOperator::CreateNUWNeg(C); } + Instruction *CreateFNeg(Constant *C) const { return BinaryOperator::CreateFNeg(C); } + Instruction *CreateNot(Constant *C) const { return BinaryOperator::CreateNot(C); } @@ -181,12 +212,14 @@ public: ArrayRef IdxList) const { return ConstantExpr::getGetElementPtr(Ty, C, IdxList); } + Constant *CreateGetElementPtr(Type *Ty, Constant *C, Constant *Idx) const { // This form of the function only exists to avoid ambiguous overload // warnings about whether to convert Idx to ArrayRef or // ArrayRef. return ConstantExpr::getGetElementPtr(Ty, C, Idx); } + Instruction *CreateGetElementPtr(Type *Ty, Constant *C, ArrayRef IdxList) const { return GetElementPtrInst::Create(Ty, C, IdxList); @@ -196,6 +229,7 @@ public: ArrayRef IdxList) const { return ConstantExpr::getInBoundsGetElementPtr(Ty, C, IdxList); } + Constant *CreateInBoundsGetElementPtr(Type *Ty, Constant *C, Constant *Idx) const { // This form of the function only exists to avoid ambiguous overload @@ -203,6 +237,7 @@ public: // ArrayRef. return ConstantExpr::getInBoundsGetElementPtr(Ty, C, Idx); } + Instruction *CreateInBoundsGetElementPtr(Type *Ty, Constant *C, ArrayRef IdxList) const { return GetElementPtrInst::CreateInBounds(Ty, C, IdxList); @@ -216,13 +251,16 @@ public: Type *DestTy) const { return CastInst::Create(Op, C, DestTy); } + Instruction *CreatePointerCast(Constant *C, Type *DestTy) const { return CastInst::CreatePointerCast(C, DestTy); } + Instruction *CreateIntCast(Constant *C, Type *DestTy, bool isSigned) const { return CastInst::CreateIntegerCast(C, DestTy, isSigned); } + Instruction *CreateFPCast(Constant *C, Type *DestTy) const { return CastInst::CreateFPCast(C, DestTy); } @@ -230,15 +268,19 @@ public: Instruction *CreateBitCast(Constant *C, Type *DestTy) const { return CreateCast(Instruction::BitCast, C, DestTy); } + Instruction *CreateIntToPtr(Constant *C, Type *DestTy) const { return CreateCast(Instruction::IntToPtr, C, DestTy); } + Instruction *CreatePtrToInt(Constant *C, Type *DestTy) const { return CreateCast(Instruction::PtrToInt, C, DestTy); } + Instruction *CreateZExtOrBitCast(Constant *C, Type *DestTy) const { return CastInst::CreateZExtOrBitCast(C, DestTy); } + Instruction *CreateSExtOrBitCast(Constant *C, Type *DestTy) const { return CastInst::CreateSExtOrBitCast(C, DestTy); } @@ -255,6 +297,7 @@ public: Constant *LHS, Constant *RHS) const { return new ICmpInst(P, LHS, RHS); } + Instruction *CreateFCmp(CmpInst::Predicate P, Constant *LHS, Constant *RHS) const { return new FCmpInst(P, LHS, RHS); @@ -294,6 +337,6 @@ public: } }; -} +} // end namespace llvm -#endif +#endif // LLVM_IR_NOFOLDER_H diff --git a/llvm/include/llvm/IR/PassManagerInternal.h b/llvm/include/llvm/IR/PassManagerInternal.h index dcc0a1cb2d97..890979f0c721 100644 --- a/llvm/include/llvm/IR/PassManagerInternal.h +++ b/llvm/include/llvm/IR/PassManagerInternal.h @@ -20,6 +20,8 @@ #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringRef.h" +#include +#include namespace llvm { @@ -34,7 +36,7 @@ namespace detail { template struct PassConcept { // Boiler plate necessary for the container of derived classes. - virtual ~PassConcept() {} + virtual ~PassConcept() = default; /// \brief The polymorphic API which runs the pass over a given IR entity. /// @@ -61,10 +63,12 @@ struct PassModel : PassConcept { // refuses to generate them. PassModel(const PassModel &Arg) : Pass(Arg.Pass) {} PassModel(PassModel &&Arg) : Pass(std::move(Arg.Pass)) {} + friend void swap(PassModel &LHS, PassModel &RHS) { using std::swap; swap(LHS.Pass, RHS.Pass); } + PassModel &operator=(PassModel RHS) { swap(*this, RHS); return *this; @@ -74,7 +78,9 @@ struct PassModel : PassConcept { ExtraArgTs... ExtraArgs) override { return Pass.run(IR, AM, ExtraArgs...); } + StringRef name() override { return PassT::name(); } + PassT Pass; }; @@ -83,7 +89,7 @@ struct PassModel : PassConcept { /// This concept is parameterized over the IR unit that this result pertains /// to. template struct AnalysisResultConcept { - virtual ~AnalysisResultConcept() {} + virtual ~AnalysisResultConcept() = default; /// \brief Method to try and mark a result as invalid. /// @@ -158,10 +164,12 @@ struct AnalysisResultModel AnalysisResultModel(const AnalysisResultModel &Arg) : Result(Arg.Result) {} AnalysisResultModel(AnalysisResultModel &&Arg) : Result(std::move(Arg.Result)) {} + friend void swap(AnalysisResultModel &LHS, AnalysisResultModel &RHS) { using std::swap; swap(LHS.Result, RHS.Result); } + AnalysisResultModel &operator=(AnalysisResultModel RHS) { swap(*this, RHS); return *this; @@ -191,10 +199,12 @@ struct AnalysisResultModel AnalysisResultModel(const AnalysisResultModel &Arg) : Result(Arg.Result) {} AnalysisResultModel(AnalysisResultModel &&Arg) : Result(std::move(Arg.Result)) {} + friend void swap(AnalysisResultModel &LHS, AnalysisResultModel &RHS) { using std::swap; swap(LHS.Result, RHS.Result); } + AnalysisResultModel &operator=(AnalysisResultModel RHS) { swap(*this, RHS); return *this; @@ -213,7 +223,7 @@ struct AnalysisResultModel /// This concept is parameterized over the IR unit that it can run over and /// produce an analysis result. template struct AnalysisPassConcept { - virtual ~AnalysisPassConcept() {} + virtual ~AnalysisPassConcept() = default; /// \brief Method to run this analysis over a unit of IR. /// \returns A unique_ptr to the analysis result object to be queried by @@ -238,10 +248,12 @@ struct AnalysisPassModel : AnalysisPassConcept { // refuses to generate them. AnalysisPassModel(const AnalysisPassModel &Arg) : Pass(Arg.Pass) {} AnalysisPassModel(AnalysisPassModel &&Arg) : Pass(std::move(Arg.Pass)) {} + friend void swap(AnalysisPassModel &LHS, AnalysisPassModel &RHS) { using std::swap; swap(LHS.Pass, RHS.Pass); } + AnalysisPassModel &operator=(AnalysisPassModel RHS) { swap(*this, RHS); return *this; @@ -268,7 +280,8 @@ struct AnalysisPassModel : AnalysisPassConcept { PassT Pass; }; -} // End namespace detail -} +} // end namespace detail -#endif +} // end namespace llvm + +#endif // LLVM_IR_PASSMANAGERINTERNAL_H