[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
This commit is contained in:
Eugene Zelenko 2016-11-23 22:25:16 +00:00
parent 3ac1d4dc10
commit 1aa40f46ee
12 changed files with 241 additions and 78 deletions

View File

@ -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 <cassert>
#include <cstddef>
#include <iterator>
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<BasicBlock, Value::user_iterator> pred_iterator;
typedef PredIterator<const BasicBlock,
Value::const_user_iterator> const_pred_iterator;
typedef llvm::iterator_range<pred_iterator> pred_range;
typedef llvm::iterator_range<const_pred_iterator> pred_const_range;
typedef iterator_range<pred_iterator> pred_range;
typedef iterator_range<const_pred_iterator> 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<TerminatorInst *, BasicBlock>
succ_iterator;
typedef TerminatorInst::SuccIterator<const TerminatorInst *, const BasicBlock>
succ_const_iterator;
typedef llvm::iterator_range<succ_iterator> succ_range;
typedef llvm::iterator_range<succ_const_iterator> succ_const_range;
typedef iterator_range<succ_iterator> succ_range;
typedef iterator_range<succ_const_iterator> succ_const_range;
inline succ_iterator succ_begin(BasicBlock *BB) {
return succ_iterator(BB->getTerminator());
@ -144,8 +152,6 @@ struct isPodLike<TerminatorInst::SuccIterator<T, U>> {
static const bool value = isPodLike<T>::value;
};
//===--------------------------------------------------------------------===//
// GraphTraits specializations for basic block graphs (CFGs)
//===--------------------------------------------------------------------===//
@ -177,7 +183,7 @@ template <> struct GraphTraits<const BasicBlock*> {
// a function is considered to be when traversing the predecessor edges of a BB
// instead of the successor edges.
//
template <> struct GraphTraits<Inverse<BasicBlock*> > {
template <> struct GraphTraits<Inverse<BasicBlock*>> {
typedef BasicBlock *NodeRef;
typedef pred_iterator ChildIteratorType;
static NodeRef getEntryNode(Inverse<BasicBlock *> G) { return G.Graph; }
@ -185,7 +191,7 @@ template <> struct GraphTraits<Inverse<BasicBlock*> > {
static ChildIteratorType child_end(NodeRef N) { return pred_end(N); }
};
template <> struct GraphTraits<Inverse<const BasicBlock*> > {
template <> struct GraphTraits<Inverse<const BasicBlock*>> {
typedef const BasicBlock *NodeRef;
typedef const_pred_iterator ChildIteratorType;
static NodeRef getEntryNode(Inverse<const BasicBlock *> G) { return G.Graph; }
@ -193,8 +199,6 @@ template <> struct GraphTraits<Inverse<const BasicBlock*> > {
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<Function*> : public GraphTraits<BasicBlock*> {
// nodes_iterator/begin/end - Allow iteration over all nodes in the graph
typedef pointer_iterator<Function::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<const Function*> :
public GraphTraits<const BasicBlock*> {
@ -222,34 +229,36 @@ template <> struct GraphTraits<const Function*> :
// nodes_iterator/begin/end - Allow iteration over all nodes in the graph
typedef pointer_iterator<Function::const_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<Inverse<Function*> > :
public GraphTraits<Inverse<BasicBlock*> > {
template <> struct GraphTraits<Inverse<Function*>> :
public GraphTraits<Inverse<BasicBlock*>> {
static NodeRef getEntryNode(Inverse<Function *> G) {
return &G.Graph->getEntryBlock();
}
};
template <> struct GraphTraits<Inverse<const Function*> > :
public GraphTraits<Inverse<const BasicBlock*> > {
template <> struct GraphTraits<Inverse<const Function*>> :
public GraphTraits<Inverse<const BasicBlock*>> {
static NodeRef getEntryNode(Inverse<const Function *> G) {
return &G.Graph->getEntryBlock();
}
};
} // End llvm namespace
} // end namespace llvm
#endif
#endif // LLVM_IR_CFG_H

View File

@ -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 <cassert>
#include <cstdint>
#include <iterator>
namespace llvm {
class CallInst;
class InvokeInst;
template <typename FunTy = const Function,
typename BBTy = const BasicBlock,
typename ValTy = const Value,
@ -609,7 +618,7 @@ class CallSite : public CallSiteBase<Function, BasicBlock, Value, User, Use,
Instruction, CallInst, InvokeInst,
User::op_iterator> {
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<CallSite>;
User::op_iterator getCallee() const;
};
template <> struct DenseMapInfo<CallSite> {
using BaseInfo = llvm::DenseMapInfo<decltype(CallSite::I)>;
using BaseInfo = DenseMapInfo<decltype(CallSite::I)>;
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<CallSite> {
/// 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

View File

@ -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<Constant *> 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<Constant *> or
// ArrayRef<Value *>.
return ConstantExpr::getGetElementPtr(Ty, C, Idx);
}
Constant *CreateGetElementPtr(Type *Ty, Constant *C,
ArrayRef<Value *> IdxList) const {
return ConstantExpr::getGetElementPtr(Ty, C, IdxList);
@ -137,6 +160,7 @@ public:
ArrayRef<Constant *> 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<Value *>.
return ConstantExpr::getInBoundsGetElementPtr(Ty, C, Idx);
}
Constant *CreateInBoundsGetElementPtr(Type *Ty, Constant *C,
ArrayRef<Value *> 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

View File

@ -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 <cassert>
#include <climits>
#include <cstddef>
#include <cstdint>
#include <iterator>
#include <type_traits>
#include <vector>
// 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<DebugEmissionKind> 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<Metadata *> 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

View File

@ -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 <functional>
#include <algorithm>
#include <cstdint>
#include <iterator>
#include <string>
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:

View File

@ -19,6 +19,7 @@
#include <string>
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

View File

@ -21,15 +21,14 @@
#include <vector>
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<StructType *> getIdentifiedStructTypes() const = 0;
};
} // End llvm namespace
} // end namespace llvm
#endif
#endif // LLVM_IR_GVMATERIALIZER_H

View File

@ -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 <cstddef>
#include <iterator>
namespace llvm {
template<typename ItTy = User::const_op_iterator>
class generic_gep_type_iterator
: public std::iterator<std::forward_iterator_tag, Type *, ptrdiff_t> {
@ -30,9 +35,10 @@ namespace llvm {
ItTy OpIt;
PointerIntPair<Type *, 1> 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<GEPOperator>(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<T> A) {
return generic_gep_type_iterator<const T *>::end(A.end());
}
} // end namespace llvm
#endif
#endif // LLVM_IR_GETELEMENTPTRTYPEITERATOR_H

View File

@ -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 <iterator>
namespace llvm {
@ -35,6 +38,7 @@ template <class BB_t, class BB_i_t, class BI_t, class II_t> 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<typename A, typename B, typename C, typename D>
@ -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

View File

@ -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 <algorithm>
#include <cassert>
#include <cstddef>
#include <cstdint>
#include <iterator>
#include <string>
#include <vector>
namespace llvm {
class LLVMContext;
//===----------------------------------------------------------------------===//
// TerminatorInst Class
//===----------------------------------------------------------------------===//
@ -249,8 +263,8 @@ public:
typedef SuccIterator<TerminatorInst *, BasicBlock> succ_iterator;
typedef SuccIterator<const TerminatorInst *, const BasicBlock>
succ_const_iterator;
typedef llvm::iterator_range<succ_iterator> succ_range;
typedef llvm::iterator_range<succ_const_iterator> succ_const_range;
typedef iterator_range<succ_iterator> succ_range;
typedef iterator_range<succ_const_iterator> 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<Use> Inputs;
OperandBundleUse() {}
OperandBundleUse() = default;
explicit OperandBundleUse(StringMapEntry<uint32_t> *Tag, ArrayRef<Use> Inputs)
: Inputs(Inputs), Tag(Tag) {}

View File

@ -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<Constant *> 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<Constant *> or
// ArrayRef<Value *>.
return ConstantExpr::getGetElementPtr(Ty, C, Idx);
}
Instruction *CreateGetElementPtr(Type *Ty, Constant *C,
ArrayRef<Value *> IdxList) const {
return GetElementPtrInst::Create(Ty, C, IdxList);
@ -196,6 +229,7 @@ public:
ArrayRef<Constant *> 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<Value *>.
return ConstantExpr::getInBoundsGetElementPtr(Ty, C, Idx);
}
Instruction *CreateInBoundsGetElementPtr(Type *Ty, Constant *C,
ArrayRef<Value *> 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

View File

@ -20,6 +20,8 @@
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringRef.h"
#include <memory>
#include <utility>
namespace llvm {
@ -34,7 +36,7 @@ namespace detail {
template <typename IRUnitT, typename AnalysisManagerT, typename... ExtraArgTs>
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<IRUnitT, AnalysisManagerT, ExtraArgTs...> {
// 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<IRUnitT, AnalysisManagerT, ExtraArgTs...> {
ExtraArgTs... ExtraArgs) override {
return Pass.run(IR, AM, ExtraArgs...);
}
StringRef name() override { return PassT::name(); }
PassT Pass;
};
@ -83,7 +89,7 @@ struct PassModel : PassConcept<IRUnitT, AnalysisManagerT, ExtraArgTs...> {
/// This concept is parameterized over the IR unit that this result pertains
/// to.
template <typename IRUnitT> struct AnalysisResultConcept {
virtual ~AnalysisResultConcept() {}
virtual ~AnalysisResultConcept() = default;
/// \brief Method to try and mark a result as invalid.
///
@ -158,10 +164,12 @@ struct AnalysisResultModel<IRUnitT, PassT, ResultT, PreservedAnalysesT, false>
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<IRUnitT, PassT, ResultT, PreservedAnalysesT, true>
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<IRUnitT, PassT, ResultT, PreservedAnalysesT, true>
/// This concept is parameterized over the IR unit that it can run over and
/// produce an analysis result.
template <typename IRUnitT, typename... ExtraArgTs> 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<IRUnitT, ExtraArgTs...> {
// 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<IRUnitT, ExtraArgTs...> {
PassT Pass;
};
} // End namespace detail
}
} // end namespace detail
#endif
} // end namespace llvm
#endif // LLVM_IR_PASSMANAGERINTERNAL_H