llvm.org GIT mirror llvm / 4679522
[IR] Fix some Clang-tidy modernize-use-using warnings; other minor fixes (NFC). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@303119 91177308-0d34-0410-b5e6-96231b3b80d8 Eugene Zelenko 2 years ago
8 changed file(s) with 189 addition(s) and 110 deletion(s). Raw diff Collapse all Expand all
1515
1616 #include "llvm/ADT/ArrayRef.h"
1717 #include "llvm/ADT/BitmaskEnum.h"
18 #include "llvm/ADT/iterator_range.h"
1819 #include "llvm/ADT/None.h"
20 #include "llvm/ADT/Optional.h"
1921 #include "llvm/ADT/SmallVector.h"
22 #include "llvm/ADT/STLExtras.h"
2023 #include "llvm/ADT/StringRef.h"
2124 #include "llvm/IR/Metadata.h"
2225 #include "llvm/Support/Casting.h"
5558
5659 namespace llvm {
5760
58 class DIBuilder;
59
60 template class Optional;
61
6261 /// Holds a subclass of DINode.
6362 ///
6463 /// FIXME: This class doesn't currently make much sense. Previously it was a
9392 bool operator!=(const TypedDINodeRef &X) const { return MD != X.MD; }
9493 };
9594
96 typedef TypedDINodeRef DINodeRef;
97 typedef TypedDINodeRef DIScopeRef;
98 typedef TypedDINodeRef DITypeRef;
95 using DINodeRef = TypedDINodeRef;
96 using DIScopeRef = TypedDINodeRef;
97 using DITypeRef = TypedDINodeRef;
9998
10099 class DITypeRefArray {
101100 const MDTuple *N = nullptr;
239238 };
240239
241240 template struct simplify_type> {
242 typedef Metadata *SimpleType;
241 using SimpleType = Metadata *;
242
243243 static SimpleType getSimplifiedValue(const TypedDINodeRef &MD) {
244244 return MD;
245245 }
798798 assert(getTag() == dwarf::DW_TAG_ptr_to_member_type);
799799 return DITypeRef(getExtraData());
800800 }
801
801802 DIObjCProperty *getObjCProperty() const {
802803 return dyn_cast_or_null(getExtraData());
803804 }
805
804806 Constant *getStorageOffsetInBits() const {
805807 assert(getTag() == dwarf::DW_TAG_member && isBitField());
806808 if (auto *C = cast_or_null(getExtraData()))
807809 return C->getValue();
808810 return nullptr;
809811 }
812
810813 Constant *getConstant() const {
811814 assert(getTag() == dwarf::DW_TAG_member && isStaticMember());
812815 if (auto *C = cast_or_null(getExtraData()))
969972 #endif
970973 replaceOperandWith(4, Elements.get());
971974 }
975
972976 void replaceVTableHolder(DITypeRef VTableHolder) {
973977 replaceOperandWith(5, VTableHolder);
974978 }
979
975980 void replaceTemplateParams(DITemplateParameterArray TemplateParams) {
976981 replaceOperandWith(6, TemplateParams.get());
977982 }
10301035 DITypeRefArray getTypeArray() const {
10311036 return cast_or_null(getRawTypeArray());
10321037 }
1038
10331039 Metadata *getRawTypeArray() const { return getOperand(3); }
10341040
10351041 static bool classof(const Metadata *MD) {
13181324 unsigned getLine() const { return SubclassData32; }
13191325 unsigned getColumn() const { return SubclassData16; }
13201326 DILocalScope *getScope() const { return cast(getRawScope()); }
1327
13211328 DILocation *getInlinedAt() const {
13221329 return cast_or_null(getRawInlinedAt());
13231330 }
14511458 static bool classof(const Metadata *MD) {
14521459 return MD->getMetadataID() == DILocationKind;
14531460 }
1454
14551461 };
14561462
14571463 /// Subprogram description.
20862092 return F->getFilename();
20872093 return "";
20882094 }
2095
20892096 StringRef getDirectory() const {
20902097 if (auto *F = getFile())
20912098 return F->getDirectory();
21422149 ArrayRef getElements() const { return Elements; }
21432150
21442151 unsigned getNumElements() const { return Elements.size(); }
2152
21452153 uint64_t getElement(unsigned I) const {
21462154 assert(I < Elements.size() && "Index out of range");
21472155 return Elements[I];
21502158 /// Determine whether this represents a standalone constant value.
21512159 bool isConstant() const;
21522160
2153 typedef ArrayRef::iterator element_iterator;
2161 using element_iterator = ArrayRef::iterator;
2162
21542163 element_iterator elements_begin() const { return getElements().begin(); }
21552164 element_iterator elements_end() const { return getElements().end(); }
21562165
25122521 return F->getFilename();
25132522 return "";
25142523 }
2524
25152525 StringRef getDirectory() const {
25162526 if (auto *F = getFile())
25172527 return F->getDirectory();
26122622 TempDIGlobalVariableExpression clone() const { return cloneImpl(); }
26132623
26142624 Metadata *getRawVariable() const { return getOperand(0); }
2625
26152626 DIGlobalVariable *getVariable() const {
26162627 return cast_or_null(getRawVariable());
26172628 }
2629
26182630 Metadata *getRawExpression() const { return getOperand(1); }
2631
26192632 DIExpression *getExpression() const {
26202633 return cast_or_null(getRawExpression());
26212634 }
1414 #ifndef LLVM_IR_DIAGNOSTICINFO_H
1515 #define LLVM_IR_DIAGNOSTICINFO_H
1616
17 #include "llvm/ADT/None.h"
1817 #include "llvm/ADT/Optional.h"
1918 #include "llvm/ADT/SmallVector.h"
2019 #include "llvm/ADT/StringRef.h"
119118 virtual void print(DiagnosticPrinter &DP) const = 0;
120119 };
121120
122 typedef std::function DiagnosticHandlerFunction;
121 using DiagnosticHandlerFunction = std::function;
123122
124123 /// Diagnostic information for inline asm reporting.
125124 /// This is basically a message and an optional location.
126125 class DiagnosticInfoInlineAsm : public DiagnosticInfo {
127126 private:
128127 /// Optional line information. 0 if not set.
129 unsigned LocCookie;
128 unsigned LocCookie = 0;
130129 /// Message to be reported.
131130 const Twine &MsgStr;
132131 /// Optional origin of the problem.
133 const Instruction *Instr;
132 const Instruction *Instr = nullptr;
134133
135134 public:
136135 /// \p MsgStr is the message to be reported to the frontend.
138137 /// for the whole life time of the Diagnostic.
139138 DiagnosticInfoInlineAsm(const Twine &MsgStr,
140139 DiagnosticSeverity Severity = DS_Error)
141 : DiagnosticInfo(DK_InlineAsm, Severity), LocCookie(0), MsgStr(MsgStr),
142 Instr(nullptr) {}
140 : DiagnosticInfo(DK_InlineAsm, Severity), MsgStr(MsgStr) {}
143141
144142 /// \p LocCookie if non-zero gives the line number for this report.
145143 /// \p MsgStr gives the message.
148146 DiagnosticInfoInlineAsm(unsigned LocCookie, const Twine &MsgStr,
149147 DiagnosticSeverity Severity = DS_Error)
150148 : DiagnosticInfo(DK_InlineAsm, Severity), LocCookie(LocCookie),
151 MsgStr(MsgStr), Instr(nullptr) {}
149 MsgStr(MsgStr) {}
152150
153151 /// \p Instr gives the original instruction that triggered the diagnostic.
154152 /// \p MsgStr gives the message.
293291 DiagnosticInfoSampleProfile(StringRef FileName, const Twine &Msg,
294292 DiagnosticSeverity Severity = DS_Error)
295293 : DiagnosticInfo(DK_SampleProfile, Severity), FileName(FileName),
296 LineNum(0), Msg(Msg) {}
294 Msg(Msg) {}
297295 DiagnosticInfoSampleProfile(const Twine &Msg,
298296 DiagnosticSeverity Severity = DS_Error)
299 : DiagnosticInfo(DK_SampleProfile, Severity), LineNum(0), Msg(Msg) {}
297 : DiagnosticInfo(DK_SampleProfile, Severity), Msg(Msg) {}
300298
301299 /// \see DiagnosticInfo::print.
302300 void print(DiagnosticPrinter &DP) const override;
315313
316314 /// Line number where the diagnostic occurred. If 0, no line number will
317315 /// be emitted in the message.
318 unsigned LineNum;
316 unsigned LineNum = 0;
319317
320318 /// Message to report.
321319 const Twine &Msg;
350348 StringRef Filename;
351349 unsigned Line = 0;
352350 unsigned Column = 0;
353 public:
354 DiagnosticLocation() {}
351
352 public:
353 DiagnosticLocation() = default;
355354 DiagnosticLocation(const DebugLoc &DL);
356355 DiagnosticLocation(const DISubprogram *SP);
357356
795794 const Twine &Msg)
796795 : OptimizationRemarkAnalysis(DK_OptimizationRemarkAnalysisFPCommute,
797796 PassName, Fn, Loc, Msg) {}
797
798798 friend void emitOptimizationRemarkAnalysisFPCommute(
799799 LLVMContext &Ctx, const char *PassName, const Function &Fn,
800800 const DiagnosticLocation &Loc, const Twine &Msg);
10111011
10121012 void print(DiagnosticPrinter &DP) const override;
10131013 };
1014
10141015 } // end namespace llvm
10151016
10161017 #endif // LLVM_IR_DIAGNOSTICINFO_H
None //===-- llvm/Instructions.h - Instruction subclass definitions --*- C++ -*-===//
0 //===- llvm/Instructions.h - Instruction subclass definitions ---*- C++ -*-===//
11 //
22 // The LLVM Compiler Infrastructure
33 //
1616 #define LLVM_IR_INSTRUCTIONS_H
1717
1818 #include "llvm/ADT/ArrayRef.h"
19 #include "llvm/ADT/iterator.h"
1920 #include "llvm/ADT/iterator_range.h"
2021 #include "llvm/ADT/None.h"
2122 #include "llvm/ADT/SmallVector.h"
2324 #include "llvm/ADT/StringRef.h"
2425 #include "llvm/ADT/Twine.h"
2526 #include "llvm/IR/Attributes.h"
27 #include "llvm/IR/BasicBlock.h"
2628 #include "llvm/IR/CallingConv.h"
2729 #include "llvm/IR/Constant.h"
2830 #include "llvm/IR/DerivedTypes.h"
2931 #include "llvm/IR/Function.h"
3032 #include "llvm/IR/InstrTypes.h"
33 #include "llvm/IR/Instruction.h"
3134 #include "llvm/IR/OperandTraits.h"
3235 #include "llvm/IR/Type.h"
3336 #include "llvm/IR/Use.h"
3437 #include "llvm/IR/User.h"
38 #include "llvm/IR/Value.h"
3539 #include "llvm/Support/AtomicOrdering.h"
3640 #include "llvm/Support/Casting.h"
3741 #include "llvm/Support/ErrorHandling.h"
3842 #include
3943 #include
4044 #include
45 #include
4146
4247 namespace llvm {
4348
263268 }
264269
265270 bool isSimple() const { return !isAtomic() && !isVolatile(); }
271
266272 bool isUnordered() const {
267273 return (getOrdering() == AtomicOrdering::NotAtomic ||
268274 getOrdering() == AtomicOrdering::Unordered) &&
385391 }
386392
387393 bool isSimple() const { return !isAtomic() && !isVolatile(); }
394
388395 bool isUnordered() const {
389396 return (getOrdering() == AtomicOrdering::NotAtomic ||
390397 getOrdering() == AtomicOrdering::Unordered) &&
835842 Type *SourceElementType;
836843 Type *ResultElementType;
837844
838 void anchor() override;
839
840845 GetElementPtrInst(const GetElementPtrInst &GEPI);
841 void init(Value *Ptr, ArrayRef IdxList, const Twine &NameStr);
842846
843847 /// Constructors - Create a getelementptr instruction with a base pointer an
844848 /// list of indices. The first ctor can optionally insert before an existing
850854 inline GetElementPtrInst(Type *PointeeType, Value *Ptr,
851855 ArrayRef IdxList, unsigned Values,
852856 const Twine &NameStr, BasicBlock *InsertAtEnd);
857
858 void anchor() override;
859 void init(Value *Ptr, ArrayRef IdxList, const Twine &NameStr);
853860
854861 protected:
855862 // Note: Instruction needs to be a friend here to call cloneImpl.
23002307 SmallVector Indices;
23012308
23022309 ExtractValueInst(const ExtractValueInst &EVI);
2310
23032311 /// Constructors - Create a extractvalue instruction with a base aggregate
23042312 /// value and a list of indices. The first ctor can optionally insert before
23052313 /// an existing instruction, the second appends the new instruction to the
23452353 /// Null is returned if the indices are invalid for the specified type.
23462354 static Type *getIndexedType(Type *Agg, ArrayRef Idxs);
23472355
2348 typedef const unsigned* idx_iterator;
2356 using idx_iterator = const unsigned*;
2357
23492358 inline idx_iterator idx_begin() const { return Indices.begin(); }
23502359 inline idx_iterator idx_end() const { return Indices.end(); }
23512360 inline iterator_range indices() const {
24672476 /// Transparently provide more efficient getOperand methods.
24682477 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
24692478
2470 typedef const unsigned* idx_iterator;
2479 using idx_iterator = const unsigned*;
2480
24712481 inline idx_iterator idx_begin() const { return Indices.begin(); }
24722482 inline idx_iterator idx_end() const { return Indices.end(); }
24732483 inline iterator_range indices() const {
26182628 // Block iterator interface. This provides access to the list of incoming
26192629 // basic blocks, which parallels the list of incoming values.
26202630
2621 typedef BasicBlock **block_iterator;
2622 typedef BasicBlock * const *const_block_iterator;
2631 using block_iterator = BasicBlock **;
2632 using const_block_iterator = BasicBlock * const *;
26232633
26242634 block_iterator block_begin() {
26252635 Use::UserRef *ref =
26682678 "All operands to PHI node must be the same type as the PHI node!");
26692679 setOperand(i, V);
26702680 }
2681
26712682 static unsigned getOperandNumForIncomingValue(unsigned i) {
26722683 return i;
26732684 }
2685
26742686 static unsigned getIncomingValueNumForOperand(unsigned i) {
26752687 return i;
26762688 }
29502962
29512963 private:
29522964 friend TerminatorInst;
2965
29532966 BasicBlock *getSuccessorV(unsigned idx) const;
29542967 unsigned getNumSuccessorsV() const;
29552968 void setSuccessorV(unsigned idx, BasicBlock *B);
30613074
30623075 private:
30633076 friend TerminatorInst;
3077
30643078 BasicBlock *getSuccessorV(unsigned idx) const;
30653079 unsigned getNumSuccessorsV() const;
30663080 void setSuccessorV(unsigned idx, BasicBlock *B);
31373151
31383152 protected:
31393153 // Expose the switch type we're parameterized with to the iterator.
3140 typedef SwitchInstT SwitchInstType;
3154 using SwitchInstType = SwitchInstT;
31413155
31423156 SwitchInstT *SI;
31433157 ptrdiff_t Index;
31783192 }
31793193 };
31803194
3181 typedef CaseHandleImpl
3182 ConstCaseHandle;
3195 using ConstCaseHandle =
3196 CaseHandleImpl;
31833197
31843198 class CaseHandle
31853199 : public CaseHandleImpl {
32063220 : public iterator_facade_base,
32073221 std::random_access_iterator_tag,
32083222 CaseHandleT> {
3209 typedef typename CaseHandleT::SwitchInstType SwitchInstT;
3223 using SwitchInstT = typename CaseHandleT::SwitchInstType;
32103224
32113225 CaseHandleT Case;
32123226
32683282 const CaseHandleT &operator*() const { return Case; }
32693283 };
32703284
3271 typedef CaseIteratorImpl CaseIt;
3272 typedef CaseIteratorImpl ConstCaseIt;
3285 using CaseIt = CaseIteratorImpl;
3286 using ConstCaseIt = CaseIteratorImpl;
32733287
32743288 static SwitchInst *Create(Value *Value, BasicBlock *Default,
32753289 unsigned NumCases,
34263440
34273441 private:
34283442 friend TerminatorInst;
3443
34293444 BasicBlock *getSuccessorV(unsigned idx) const;
34303445 unsigned getNumSuccessorsV() const;
34313446 void setSuccessorV(unsigned idx, BasicBlock *B);
35323547
35333548 private:
35343549 friend TerminatorInst;
3550
35353551 BasicBlock *getSuccessorV(unsigned idx) const;
35363552 unsigned getNumSuccessorsV() const;
35373553 void setSuccessorV(unsigned idx, BasicBlock *B);
36553671 return new (Values) InvokeInst(Func, IfNormal, IfException, Args, None,
36563672 Values, NameStr, InsertAtEnd);
36573673 }
3674
36583675 static InvokeInst *Create(Value *Func, BasicBlock *IfNormal,
36593676 BasicBlock *IfException, ArrayRef Args,
36603677 ArrayRef Bundles,
40134030
40144031 private:
40154032 friend TerminatorInst;
4033
40164034 BasicBlock *getSuccessorV(unsigned idx) const;
40174035 unsigned getNumSuccessorsV() const;
40184036 void setSuccessorV(unsigned idx, BasicBlock *B);
41134131
41144132 private:
41154133 friend TerminatorInst;
4134
41164135 BasicBlock *getSuccessorV(unsigned idx) const;
41174136 unsigned getNumSuccessorsV() const;
41184137 void setSuccessorV(unsigned idx, BasicBlock *B);
42204239 }
42214240
42224241 public:
4223 typedef std::pointer_to_unary_function DerefFnTy;
4224 typedef mapped_iterator handler_iterator;
4225 typedef iterator_range handler_range;
4226 typedef std::pointer_to_unary_function
4227 ConstDerefFnTy;
4228 typedef mapped_iterator const_handler_iterator;
4229 typedef iterator_range const_handler_range;
4242 using DerefFnTy = std::pointer_to_unary_function;
4243 using handler_iterator = mapped_iterator;
4244 using handler_range = iterator_range;
4245 using ConstDerefFnTy =
4246 std::pointer_to_unary_function;
4247 using const_handler_iterator =
4248 mapped_iterator;
4249 using const_handler_range = iterator_range;
42304250
42314251 /// Returns an iterator that points to the first handler in CatchSwitchInst.
42324252 handler_iterator handler_begin() {
42974317
42984318 private:
42994319 friend TerminatorInst;
4320
43004321 BasicBlock *getSuccessorV(unsigned Idx) const;
43014322 unsigned getNumSuccessorsV() const;
43024323 void setSuccessorV(unsigned Idx, BasicBlock *B);
44634484
44644485 private:
44654486 friend TerminatorInst;
4487
44664488 BasicBlock *getSuccessorV(unsigned Idx) const;
44674489 unsigned getNumSuccessorsV() const;
44684490 void setSuccessorV(unsigned Idx, BasicBlock *B);
45524574
45534575 private:
45544576 friend TerminatorInst;
4577
45554578 BasicBlock *getSuccessorV(unsigned Idx) const;
45564579 unsigned getNumSuccessorsV() const;
45574580 void setSuccessorV(unsigned Idx, BasicBlock *B);
46084631
46094632 private:
46104633 friend TerminatorInst;
4634
46114635 BasicBlock *getSuccessorV(unsigned idx) const;
46124636 unsigned getNumSuccessorsV() const;
46134637 void setSuccessorV(unsigned idx, BasicBlock *B);
None //===-- AttributeImpl.h - Attribute Internals -------------------*- C++ -*-===//
0 //===- AttributeImpl.h - Attribute Internals --------------------*- C++ -*-===//
11 //
22 // The LLVM Compiler Infrastructure
33 //
2020 #include "llvm/ADT/StringRef.h"
2121 #include "llvm/IR/Attributes.h"
2222 #include "llvm/Support/TrailingObjects.h"
23 #include
2423 #include
25 #include
2624 #include
2725 #include
2826 #include
7977 else
8078 Profile(ID, getKindAsString(), getValueAsString());
8179 }
80
8281 static void Profile(FoldingSetNodeID &ID, Attribute::AttrKind Kind,
8382 uint64_t Val) {
8483 ID.AddInteger(Kind);
8584 if (Val) ID.AddInteger(Val);
8685 }
86
8787 static void Profile(FoldingSetNodeID &ID, StringRef Kind, StringRef Values) {
8888 ID.AddString(Kind);
8989 if (!Values.empty()) ID.AddString(Values);
113113 };
114114
115115 class IntAttributeImpl : public EnumAttributeImpl {
116 uint64_t Val;
117
116118 void anchor() override;
117 uint64_t Val;
118119
119120 public:
120121 IntAttributeImpl(Attribute::AttrKind Kind, uint64_t Val)
187188 std::pair> getAllocSizeArgs() const;
188189 std::string getAsString(bool InAttrGrp) const;
189190
190 typedef const Attribute *iterator;
191 using iterator = const Attribute *;
192
191193 iterator begin() const { return getTrailingObjects(); }
192194 iterator end() const { return begin() + NumAttrs; }
193195
194196 void Profile(FoldingSetNodeID &ID) const {
195197 Profile(ID, makeArrayRef(begin(), end()));
196198 }
199
197200 static void Profile(FoldingSetNodeID &ID, ArrayRef AttrList) {
198201 for (const auto &Attr : AttrList)
199202 Attr.Profile(ID);
200203 }
201204 };
202205
203 typedef std::pair IndexAttrPair;
206 using IndexAttrPair = std::pair;
204207
205208 //===----------------------------------------------------------------------===//
206209 /// \class
264267 return AvailableFunctionAttrs & ((uint64_t)1) << Kind;
265268 }
266269
267 typedef AttributeSet::iterator iterator;
270 using iterator = AttributeSet::iterator;
271
268272 iterator begin(unsigned Slot) const {
269273 return getSlotAttributes(Slot).begin();
270274 }
3333 #include "llvm/Support/raw_ostream.h"
3434 #include
3535 #include
36 #include
37 #include
3638 #include
3739 #include
3840 #include
566568 }
567569
568570 bool AttributeSet::hasAttribute(Attribute::AttrKind Kind) const {
569 return SetNode ? SetNode->hasAttribute(Kind) : 0;
571 return SetNode ? SetNode->hasAttribute(Kind) : false;
570572 }
571573
572574 bool AttributeSet::hasAttribute(StringRef Kind) const {
573 return SetNode ? SetNode->hasAttribute(Kind) : 0;
575 return SetNode ? SetNode->hasAttribute(Kind) : false;
574576 }
575577
576578 Attribute AttributeSet::getAttribute(Attribute::AttrKind Kind) const {
2121 #include "llvm/ADT/None.h"
2222 #include "llvm/ADT/SmallVector.h"
2323 #include "llvm/ADT/StringRef.h"
24 #include "llvm/IR/Constant.h"
2425 #include "llvm/IR/Constants.h"
2526 #include "llvm/IR/DerivedTypes.h"
2627 #include "llvm/IR/InlineAsm.h"
386387
387388 template struct ConstantInfo;
388389 template <> struct ConstantInfo {
389 typedef ConstantExprKeyType ValType;
390 typedef Type TypeClass;
390 using ValType = ConstantExprKeyType;
391 using TypeClass = Type;
391392 };
392393 template <> struct ConstantInfo {
393 typedef InlineAsmKeyType ValType;
394 typedef PointerType TypeClass;
394 using ValType = InlineAsmKeyType;
395 using TypeClass = PointerType;
395396 };
396397 template <> struct ConstantInfo {
397 typedef ConstantAggrKeyType ValType;
398 typedef ArrayType TypeClass;
398 using ValType = ConstantAggrKeyType;
399 using TypeClass = ArrayType;
399400 };
400401 template <> struct ConstantInfo {
401 typedef ConstantAggrKeyType ValType;
402 typedef StructType TypeClass;
402 using ValType = ConstantAggrKeyType;
403 using TypeClass = StructType;
403404 };
404405 template <> struct ConstantInfo {
405 typedef ConstantAggrKeyType ValType;
406 typedef VectorType TypeClass;
406 using ValType = ConstantAggrKeyType;
407 using TypeClass = VectorType;
407408 };
408409
409410 template struct ConstantAggrKeyType {
410411 ArrayRef Operands;
412
411413 ConstantAggrKeyType(ArrayRef Operands) : Operands(Operands) {}
414
412415 ConstantAggrKeyType(ArrayRef Operands, const ConstantClass *)
413416 : Operands(Operands) {}
417
414418 ConstantAggrKeyType(const ConstantClass *C,
415419 SmallVectorImpl &Storage) {
416420 assert(Storage.empty() && "Expected empty storage");
436440 return hash_combine_range(Operands.begin(), Operands.end());
437441 }
438442
439 typedef typename ConstantInfo::TypeClass TypeClass;
443 using TypeClass = typename ConstantInfo::TypeClass;
444
440445 ConstantClass *create(TypeClass *Ty) const {
441446 return new (Operands.size()) ConstantClass(Ty, Operands);
442447 }
456461 : AsmString(AsmString), Constraints(Constraints), FTy(FTy),
457462 HasSideEffects(HasSideEffects), IsAlignStack(IsAlignStack),
458463 AsmDialect(AsmDialect) {}
464
459465 InlineAsmKeyType(const InlineAsm *Asm, SmallVectorImpl &)
460466 : AsmString(Asm->getAsmString()), Constraints(Asm->getConstraintString()),
461467 FTy(Asm->getFunctionType()), HasSideEffects(Asm->hasSideEffects()),
482488 AsmDialect, FTy);
483489 }
484490
485 typedef ConstantInfo::TypeClass TypeClass;
491 using TypeClass = ConstantInfo::TypeClass;
492
486493 InlineAsm *create(TypeClass *Ty) const {
487494 assert(PointerType::getUnqual(FTy) == Ty);
488495 return new InlineAsm(FTy, AsmString, Constraints, HasSideEffects,
506513 : Opcode(Opcode), SubclassOptionalData(SubclassOptionalData),
507514 SubclassData(SubclassData), Ops(Ops), Indexes(Indexes),
508515 ExplicitTy(ExplicitTy) {}
516
509517 ConstantExprKeyType(ArrayRef Operands, const ConstantExpr *CE)
510518 : Opcode(CE->getOpcode()),
511519 SubclassOptionalData(CE->getRawSubclassOptionalData()),
512520 SubclassData(CE->isCompare() ? CE->getPredicate() : 0), Ops(Operands),
513521 Indexes(CE->hasIndices() ? CE->getIndices() : ArrayRef()) {}
522
514523 ConstantExprKeyType(const ConstantExpr *CE,
515524 SmallVectorImpl &Storage)
516525 : Opcode(CE->getOpcode()),
552561 hash_combine_range(Indexes.begin(), Indexes.end()));
553562 }
554563
555 typedef ConstantInfo::TypeClass TypeClass;
564 using TypeClass = ConstantInfo::TypeClass;
565
556566 ConstantExpr *create(TypeClass *Ty) const {
557567 switch (Opcode) {
558568 default:
593603
594604 template class ConstantUniqueMap {
595605 public:
596 typedef typename ConstantInfo::ValType ValType;
597 typedef typename ConstantInfo::TypeClass TypeClass;
598 typedef std::pair LookupKey;
606 using ValType = typename ConstantInfo::ValType;
607 using TypeClass = typename ConstantInfo::TypeClass;
608 using LookupKey = std::pair;
599609
600610 /// Key and hash together, so that we compute the hash only once and reuse it.
601 typedef std::pair LookupKeyHashed;
611 using LookupKeyHashed = std::pair;
602612
603613 private:
604614 struct MapInfo {
605 typedef DenseMapInfo ConstantClassInfo;
615 using ConstantClassInfo = DenseMapInfo;
616
606617 static inline ConstantClass *getEmptyKey() {
607618 return ConstantClassInfo::getEmptyKey();
608619 }
642653 };
643654
644655 public:
645 typedef DenseSet MapTy;
656 using MapTy = DenseSet;
646657
647658 private:
648659 MapTy Map;
1111 // Diagnostics reporting is still done as part of the LLVMContext.
1212 //===----------------------------------------------------------------------===//
1313
14 #include "llvm/IR/DiagnosticInfo.h"
15 #include "LLVMContextImpl.h"
14 #include "llvm/ADT/iterator_range.h"
1615 #include "llvm/ADT/StringExtras.h"
1716 #include "llvm/ADT/Twine.h"
17 #include "llvm/IR/BasicBlock.h"
1818 #include "llvm/IR/Constants.h"
19 #include "llvm/IR/DebugInfo.h"
19 #include "llvm/IR/DebugInfoMetadata.h"
20 #include "llvm/IR/DerivedTypes.h"
21 #include "llvm/IR/DiagnosticInfo.h"
2022 #include "llvm/IR/DiagnosticPrinter.h"
2123 #include "llvm/IR/Function.h"
24 #include "llvm/IR/GlobalValue.h"
2225 #include "llvm/IR/Instruction.h"
26 #include "llvm/IR/LLVMContext.h"
2327 #include "llvm/IR/Metadata.h"
2428 #include "llvm/IR/Module.h"
29 #include "llvm/IR/Type.h"
30 #include "llvm/IR/Value.h"
31 #include "llvm/Support/Casting.h"
2532 #include "llvm/Support/CommandLine.h"
33 #include "llvm/Support/ErrorHandling.h"
34 #include "llvm/Support/raw_ostream.h"
2635 #include "llvm/Support/Regex.h"
2736 #include
37 #include
38 #include
2839 #include
2940
3041 using namespace llvm;
5263 }
5364 };
5465
66 } // end anonymous namespace
67
5568 static PassRemarksOpt PassRemarksOptLoc;
5669 static PassRemarksOpt PassRemarksMissedOptLoc;
5770 static PassRemarksOpt PassRemarksAnalysisOptLoc;
8497 "the given regular expression"),
8598 cl::Hidden, cl::location(PassRemarksAnalysisOptLoc), cl::ValueRequired,
8699 cl::ZeroOrMore);
87 }
88100
89101 int llvm::getNextAvailablePluginDiagnosticKind() {
90102 static std::atomic PluginKindID(DK_FirstPluginKind);
96108 DiagnosticInfoInlineAsm::DiagnosticInfoInlineAsm(const Instruction &I,
97109 const Twine &MsgStr,
98110 DiagnosticSeverity Severity)
99 : DiagnosticInfo(DK_InlineAsm, Severity), LocCookie(0), MsgStr(MsgStr),
100 Instr(&I) {
111 : DiagnosticInfo(DK_InlineAsm, Severity), MsgStr(MsgStr), Instr(&I) {
101112 if (const MDNode *SrcLoc = I.getMetadata("srcloc")) {
102113 if (SrcLoc->getNumOperands() != 0)
103114 if (const auto *CI =
None //===-- Instructions.cpp - Implement the LLVM instructions ----------------===//
0 //===- Instructions.cpp - Implement the LLVM instructions -----------------===//
11 //
22 // The LLVM Compiler Infrastructure
33 //
1111 //
1212 //===----------------------------------------------------------------------===//
1313
14 #include "llvm/IR/Instructions.h"
1514 #include "LLVMContextImpl.h"
15 #include "llvm/ADT/None.h"
16 #include "llvm/ADT/SmallVector.h"
17 #include "llvm/ADT/Twine.h"
18 #include "llvm/IR/Attributes.h"
19 #include "llvm/IR/BasicBlock.h"
1620 #include "llvm/IR/CallSite.h"
17 #include "llvm/IR/ConstantRange.h"
21 #include "llvm/IR/Constant.h"
1822 #include "llvm/IR/Constants.h"
1923 #include "llvm/IR/DataLayout.h"
2024 #include "llvm/IR/DerivedTypes.h"
2125 #include "llvm/IR/Function.h"
26 #include "llvm/IR/InstrTypes.h"
27 #include "llvm/IR/Instruction.h"
28 #include "llvm/IR/Instructions.h"
29 #include "llvm/IR/LLVMContext.h"
30 #include "llvm/IR/Metadata.h"
2231 #include "llvm/IR/Module.h"
2332 #include "llvm/IR/Operator.h"
33 #include "llvm/IR/Type.h"
34 #include "llvm/IR/Value.h"
35 #include "llvm/Support/AtomicOrdering.h"
36 #include "llvm/Support/Casting.h"
2437 #include "llvm/Support/ErrorHandling.h"
2538 #include "llvm/Support/MathExtras.h"
39 #include
40 #include
41 #include
42 #include
43
2644 using namespace llvm;
2745
2846 //===----------------------------------------------------------------------===//
4159 //===----------------------------------------------------------------------===//
4260
4361 // Out of line virtual method, so the vtable, etc has a home.
44 TerminatorInst::~TerminatorInst() {
45 }
62 TerminatorInst::~TerminatorInst() = default;
4663
4764 unsigned TerminatorInst::getNumSuccessors() const {
4865 switch (getOpcode()) {
85102 //===----------------------------------------------------------------------===//
86103
87104 // Out of line virtual method, so the vtable, etc has a home.
88 UnaryInstruction::~UnaryInstruction() {
89 }
105 UnaryInstruction::~UnaryInstruction() = default;
90106
91107 //===----------------------------------------------------------------------===//
92108 // SelectInst Class
116132 }
117133 return nullptr;
118134 }
119
120135
121136 //===----------------------------------------------------------------------===//
122137 // PHINode Class
277292 // CallInst Implementation
278293 //===----------------------------------------------------------------------===//
279294
280 CallInst::~CallInst() {
281 }
295 CallInst::~CallInst() = default;
282296
283297 void CallInst::init(FunctionType *FTy, Value *Func, ArrayRef Args,
284298 ArrayRef Bundles, const Twine &NameStr) {
576590 ArraySize, OpB, MallocF, Name);
577591 }
578592
579
580593 /// CreateMalloc - Generate the IR for a call to malloc:
581594 /// 1. Compute the malloc call's argument as the specified type's size,
582595 /// possibly multiplied by the array size if the array size is not
727740 BasicBlock *InvokeInst::getSuccessorV(unsigned idx) const {
728741 return getSuccessor(idx);
729742 }
743
730744 unsigned InvokeInst::getNumSuccessorsV() const {
731745 return getNumSuccessors();
732746 }
747
733748 void InvokeInst::setSuccessorV(unsigned idx, BasicBlock *B) {
734749 return setSuccessor(idx, B);
735750 }
856871 if (retVal)
857872 Op<0>() = retVal;
858873 }
874
859875 ReturnInst::ReturnInst(LLVMContext &C, Value *retVal, BasicBlock *InsertAtEnd)
860876 : TerminatorInst(Type::getVoidTy(C), Instruction::Ret,
861877 OperandTraits::op_end(this) - !!retVal, !!retVal,
863879 if (retVal)
864880 Op<0>() = retVal;
865881 }
882
866883 ReturnInst::ReturnInst(LLVMContext &Context, BasicBlock *InsertAtEnd)
867884 : TerminatorInst(Type::getVoidTy(Context), Instruction::Ret,
868885 OperandTraits::op_end(this), 0, InsertAtEnd) {
882899 llvm_unreachable("ReturnInst has no successors!");
883900 }
884901
885 ReturnInst::~ReturnInst() {
886 }
902 ReturnInst::~ReturnInst() = default;
887903
888904 //===----------------------------------------------------------------------===//
889905 // ResumeInst Implementation
965981 assert(Idx == 0);
966982 return getUnwindDest();
967983 }
984
968985 unsigned CleanupReturnInst::getNumSuccessorsV() const {
969986 return getNumSuccessors();
970987 }
988
971989 void CleanupReturnInst::setSuccessorV(unsigned Idx, BasicBlock *B) {
972990 assert(Idx == 0);
973991 setUnwindDest(B);
10081026 assert(Idx < getNumSuccessors() && "Successor # out of range for catchret!");
10091027 return getSuccessor();
10101028 }
1029
10111030 unsigned CatchReturnInst::getNumSuccessorsV() const {
10121031 return getNumSuccessors();
10131032 }
1033
10141034 void CatchReturnInst::setSuccessorV(unsigned Idx, BasicBlock *B) {
10151035 assert(Idx < getNumSuccessors() && "Successor # out of range for catchret!");
10161036 setSuccessor(B);
11021122 BasicBlock *CatchSwitchInst::getSuccessorV(unsigned idx) const {
11031123 return getSuccessor(idx);
11041124 }
1125
11051126 unsigned CatchSwitchInst::getNumSuccessorsV() const {
11061127 return getNumSuccessors();
11071128 }
1129
11081130 void CatchSwitchInst::setSuccessorV(unsigned idx, BasicBlock *B) {
11091131 setSuccessor(idx, B);
11101132 }
11901212 assert(IfTrue && "Branch destination may not be null!");
11911213 Op<-1>() = IfTrue;
11921214 }
1215
11931216 BranchInst::BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
11941217 Instruction *InsertBefore)
11951218 : TerminatorInst(Type::getVoidTy(IfTrue->getContext()), Instruction::Br,
12241247 #endif
12251248 }
12261249
1227
12281250 BranchInst::BranchInst(const BranchInst &BI) :
12291251 TerminatorInst(Type::getVoidTy(BI.getContext()), Instruction::Br,
12301252 OperandTraits::op_end(this) - BI.getNumOperands(),
12511273 BasicBlock *BranchInst::getSuccessorV(unsigned idx) const {
12521274 return getSuccessor(idx);
12531275 }
1276
12541277 unsigned BranchInst::getNumSuccessorsV() const {
12551278 return getNumSuccessors();
12561279 }
1280
12571281 void BranchInst::setSuccessorV(unsigned idx, BasicBlock *B) {
12581282 setSuccessor(idx, B);
12591283 }
1260
12611284
12621285 //===----------------------------------------------------------------------===//
12631286 // AllocaInst Implementation
13141337 }
13151338
13161339 // Out of line virtual method, so the vtable, etc has a home.
1317 AllocaInst::~AllocaInst() {
1318 }
1340 AllocaInst::~AllocaInst() = default;
13191341
13201342 void AllocaInst::setAlignment(unsigned Align) {
13211343 assert((Align & (Align-1)) == 0 && "Alignment is not a power of 2!");
18041826 setName(Name);
18051827 }
18061828
1807
18081829 bool ExtractElementInst::isValidOperands(const Value *Val, const Value *Index) {
18091830 if (!Val->getType()->isVectorTy() || !Index->getType()->isIntegerTy())
18101831 return false;
18111832 return true;
18121833 }
1813
18141834
18151835 //===----------------------------------------------------------------------===//
18161836 // InsertElementInst Implementation
18571877 return false; // Third operand of insertelement must be i32.
18581878 return true;
18591879 }
1860
18611880
18621881 //===----------------------------------------------------------------------===//
18631882 // ShuffleVectorInst Implementation
19711990 }
19721991 }
19731992
1974
19751993 //===----------------------------------------------------------------------===//
19761994 // InsertValueInst Class
19771995 //===----------------------------------------------------------------------===//
19842002 // (other than weirdness with &*IdxBegin being invalid; see
19852003 // getelementptr's init routine for example). But there's no
19862004 // present need to support it.
1987 assert(Idxs.size() > 0 && "InsertValueInst must have at least one index");
2005 assert(!Idxs.empty() && "InsertValueInst must have at least one index");
19882006
19892007 assert(ExtractValueInst::getIndexedType(Agg->getType(), Idxs) ==
19902008 Val->getType() && "Inserted value must match indexed type!");
20132031
20142032 // There's no fundamental reason why we require at least one index.
20152033 // But there's no present need to support it.
2016 assert(Idxs.size() > 0 && "ExtractValueInst must have at least one index");
2034 assert(!Idxs.empty() && "ExtractValueInst must have at least one index");
20172035
20182036 Indices.append(Idxs.begin(), Idxs.end());
20192037 setName(Name);
20852103 init(iType);
20862104 setName(Name);
20872105 }
2088
20892106
20902107 void BinaryOperator::init(BinaryOps iType) {
20912108 Value *LHS = getOperand(0), *RHS = getOperand(1);
22462263 Op->getType(), Name, InsertAtEnd);
22472264 }
22482265
2249
22502266 // isConstantAllOnes - Helper function for several functions below
22512267 static inline bool isConstantAllOnes(const Value *V) {
22522268 if (const Constant *C = dyn_cast(V))
23122328 return getNotArgument(const_cast(BinOp));
23132329 }
23142330
2315
23162331 // Exchange the two operands to this instruction. This instruction is safe to
23172332 // use on any binary instruction and does not modify the semantics of the
23182333 // instruction. If the instruction is order-dependent (SetLT f.e.), the opcode
23242339 return false;
23252340 }
23262341
2327
23282342 //===----------------------------------------------------------------------===//
23292343 // FPMathOperator Class
23302344 //===----------------------------------------------------------------------===//
23372351 ConstantFP *Accuracy = mdconst::extract(MD->getOperand(0));
23382352 return Accuracy->getValueAPF().convertToFloat();
23392353 }
2340
23412354
23422355 //===----------------------------------------------------------------------===//
23432356 // CastInst Class
26002613 return Instruction::BitCast;
26012614 return 0;
26022615 }
2603 case 12: {
2616 case 12:
26042617 // addrspacecast, addrspacecast -> bitcast, if SrcAS == DstAS
26052618 // addrspacecast, addrspacecast -> addrspacecast, if SrcAS != DstAS
26062619 if (SrcTy->getPointerAddressSpace() != DstTy->getPointerAddressSpace())
26072620 return Instruction::AddrSpaceCast;
26082621 return Instruction::BitCast;
2609 }
26102622 case 13:
26112623 // FIXME: this state can be merged with (1), but the following assert
26122624 // is useful to check the correcteness of the sequence due to semantic
26272639 DstTy->getScalarType()->getPointerElementType())
26282640 return Instruction::AddrSpaceCast;
26292641 return 0;
2630
26312642 case 15:
26322643 // FIXME: this state can be merged with (1), but the following assert
26332644 // is useful to check the correcteness of the sequence due to semantic
31033114 /// of the types involved.
31043115 bool
31053116 CastInst::castIsValid(Instruction::CastOps op, Value *S, Type *DstTy) {
3106
31073117 // Check for type sanity on the arguments
31083118 Type *SrcTy = S->getType();
31093119
34523462 return cast(this)->isEquality();
34533463 }
34543464
3455
34563465 CmpInst::Predicate CmpInst::getInversePredicate(Predicate pred) {
34573466 switch (pred) {
34583467 default: llvm_unreachable("Unknown cmp predicate!");
37763785 BasicBlock *SwitchInst::getSuccessorV(unsigned idx) const {
37773786 return getSuccessor(idx);
37783787 }
3788
37793789 unsigned SwitchInst::getNumSuccessorsV() const {
37803790 return getNumSuccessors();
37813791 }
3792
37823793 void SwitchInst::setSuccessorV(unsigned idx, BasicBlock *B) {
37833794 setSuccessor(idx, B);
37843795 }
38653876 BasicBlock *IndirectBrInst::getSuccessorV(unsigned idx) const {
38663877 return getSuccessor(idx);
38673878 }
3879
38683880 unsigned IndirectBrInst::getNumSuccessorsV() const {
38693881 return getNumSuccessors();
38703882 }
3883
38713884 void IndirectBrInst::setSuccessorV(unsigned idx, BasicBlock *B) {
38723885 setSuccessor(idx, B);
38733886 }