llvm.org GIT mirror llvm / 5067e6a
[CodeGen] Fix some Clang-tidy modernize-use-using and Include What You Use warnings; other minor fixes (NFC). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@304621 91177308-0d34-0410-b5e6-96231b3b80d8 Eugene Zelenko 3 years ago
6 changed file(s) with 218 addition(s) and 146 deletion(s). Raw diff Collapse all Expand all
None //===-- llvm/CodeGen/SelectionDAG.h - InstSelection DAG ---------*- C++ -*-===//
0 //===- llvm/CodeGen/SelectionDAG.h - InstSelection DAG ----------*- C++ -*-===//
11 //
22 // The LLVM Compiler Infrastructure
33 //
1414 #ifndef LLVM_CODEGEN_SELECTIONDAG_H
1515 #define LLVM_CODEGEN_SELECTIONDAG_H
1616
17 #include "llvm/ADT/APFloat.h"
18 #include "llvm/ADT/APInt.h"
19 #include "llvm/ADT/ArrayRef.h"
20 #include "llvm/ADT/DenseMap.h"
1721 #include "llvm/ADT/DenseSet.h"
22 #include "llvm/ADT/FoldingSet.h"
23 #include "llvm/ADT/ilist.h"
24 #include "llvm/ADT/iterator.h"
25 #include "llvm/ADT/iterator_range.h"
1826 #include "llvm/ADT/SetVector.h"
27 #include "llvm/ADT/SmallVector.h"
1928 #include "llvm/ADT/StringMap.h"
20 #include "llvm/ADT/ilist.h"
2129 #include "llvm/Analysis/AliasAnalysis.h"
2230 #include "llvm/CodeGen/DAGCombine.h"
31 #include "llvm/CodeGen/ISDOpcodes.h"
2332 #include "llvm/CodeGen/MachineFunction.h"
33 #include "llvm/CodeGen/MachineMemOperand.h"
34 #include "llvm/CodeGen/MachineValueType.h"
2435 #include "llvm/CodeGen/SelectionDAGNodes.h"
36 #include "llvm/CodeGen/ValueTypes.h"
37 #include "llvm/IR/DebugLoc.h"
38 #include "llvm/IR/Instructions.h"
39 #include "llvm/IR/Metadata.h"
40 #include "llvm/Support/Allocator.h"
2541 #include "llvm/Support/ArrayRecycler.h"
42 #include "llvm/Support/AtomicOrdering.h"
43 #include "llvm/Support/Casting.h"
44 #include "llvm/Support/CodeGen.h"
45 #include "llvm/Support/ErrorHandling.h"
2646 #include "llvm/Support/RecyclingAllocator.h"
27 #include "llvm/Target/TargetMachine.h"
47 #include
2848 #include
49 #include
50 #include
2951 #include
3052 #include
53 #include
54 #include
3155 #include
3256
3357 namespace llvm {
3458
59 class BlockAddress;
60 class Constant;
61 class ConstantFP;
62 class ConstantInt;
63 class DataLayout;
64 struct fltSemantics;
65 class GlobalValue;
3566 struct KnownBits;
67 class LLVMContext;
68 class MachineBasicBlock;
3669 class MachineConstantPoolValue;
37 class MachineFunction;
38 class MDNode;
70 class MCSymbol;
3971 class OptimizationRemarkEmitter;
4072 class SDDbgValue;
73 class SelectionDAG;
74 class SelectionDAGTargetInfo;
4175 class TargetLowering;
42 class SelectionDAGTargetInfo;
76 class TargetMachine;
77 class TargetSubtargetInfo;
78 class Value;
4379
4480 class SDVTListNode : public FoldingSetNode {
4581 friend struct FoldingSetTrait;
82
4683 /// A reference to an Interned FoldingSetNodeID for this node.
4784 /// The Allocator in SelectionDAG holds the data.
4885 /// SDVTList contains all types which are frequently accessed in SelectionDAG.
5491 /// The hash value for SDVTList is fixed, so cache it to avoid
5592 /// hash calculation.
5693 unsigned HashValue;
94
5795 public:
5896 SDVTListNode(const FoldingSetNodeIDRef ID, const EVT *VT, unsigned int Num) :
5997 FastID(ID), VTs(VT), NumVTs(Num) {
6098 HashValue = ID.ComputeHash();
6199 }
100
62101 SDVTList getSDVTList() {
63102 SDVTList result = {VTs, NumVTs};
64103 return result;
71110 static void Profile(const SDVTListNode &X, FoldingSetNodeID& ID) {
72111 ID = X.FastID;
73112 }
113
74114 static bool Equals(const SDVTListNode &X, const FoldingSetNodeID &ID,
75115 unsigned IDHash, FoldingSetNodeID &TempID) {
76116 if (X.HashValue != IDHash)
77117 return false;
78118 return ID == X.FastID;
79119 }
120
80121 static unsigned ComputeHash(const SDVTListNode &X, FoldingSetNodeID &TempID) {
81122 return X.HashValue;
82123 }
103144 BumpPtrAllocator Alloc;
104145 SmallVector DbgValues;
105146 SmallVector ByvalParmDbgValues;
106 typedef DenseMap > DbgValMapType;
147 using DbgValMapType = DenseMap>;
107148 DbgValMapType DbgValMap;
108149
109 void operator=(const SDDbgInfo&) = delete;
110 SDDbgInfo(const SDDbgInfo&) = delete;
111150 public:
112 SDDbgInfo() {}
151 SDDbgInfo() = default;
152 SDDbgInfo(const SDDbgInfo &) = delete;
153 SDDbgInfo &operator=(const SDDbgInfo &) = delete;
113154
114155 void add(SDDbgValue *V, const SDNode *Node, bool isParameter) {
115156 if (isParameter) {
143184 return ArrayRef();
144185 }
145186
146 typedef SmallVectorImpl::iterator DbgIterator;
187 using DbgIterator = SmallVectorImpl::iterator;
188
147189 DbgIterator DbgBegin() { return DbgValues.begin(); }
148190 DbgIterator DbgEnd() { return DbgValues.end(); }
149191 DbgIterator ByvalParmDbgBegin() { return ByvalParmDbgValues.begin(); }
150192 DbgIterator ByvalParmDbgEnd() { return ByvalParmDbgValues.end(); }
151193 };
152194
153 class SelectionDAG;
154195 void checkForCycles(const SelectionDAG *DAG, bool force = false);
155196
156197 /// This is used to represent a portion of an LLVM function in a low-level
166207 ///
167208 class SelectionDAG {
168209 const TargetMachine &TM;
169 const SelectionDAGTargetInfo *TSI;
170 const TargetLowering *TLI;
210 const SelectionDAGTargetInfo *TSI = nullptr;
211 const TargetLowering *TLI = nullptr;
171212 MachineFunction *MF;
172213 LLVMContext *Context;
173214 CodeGenOpt::Level OptLevel;
187228
188229 /// The AllocatorType for allocating SDNodes. We use
189230 /// pool allocation with recycling.
190 typedef RecyclingAllocator
191 alignof(MostAlignedSDNode)>
192 NodeAllocatorType;
231 using NodeAllocatorType = RecyclingAllocator
232 sizeof(LargestSDNode),
233 alignof(MostAlignedSDNode)>;
193234
194235 /// Pool allocation for nodes.
195236 NodeAllocatorType NodeAllocator;
242283
243284 struct DAGNodeDeletedListener : public DAGUpdateListener {
244285 std::function Callback;
286
245287 DAGNodeDeletedListener(SelectionDAG &DAG,
246288 std::function Callback)
247289 : DAGUpdateListener(DAG), Callback(std::move(Callback)) {}
290
248291 void NodeDeleted(SDNode *N, SDNode *E) override { Callback(N, E); }
249292 };
250293
253296 /// have legal types. This is important after type legalization since
254297 /// any illegally typed nodes generated after this point will not experience
255298 /// type legalization.
256 bool NewNodesMustHaveLegalTypes;
299 bool NewNodesMustHaveLegalTypes = false;
257300
258301 private:
259302 /// DAGUpdateListener is a friend so it can manipulate the listener stack.
261304
262305 /// Linked list of registered DAGUpdateListener instances.
263306 /// This stack is maintained by DAGUpdateListener RAII.
264 DAGUpdateListener *UpdateListeners;
307 DAGUpdateListener *UpdateListeners = nullptr;
265308
266309 /// Implementation of setSubgraphColor.
267310 /// Return whether we had to truncate the search.
315358 Node->OperandList = nullptr;
316359 }
317360
318 void operator=(const SelectionDAG&) = delete;
319 SelectionDAG(const SelectionDAG&) = delete;
320
321361 public:
322 explicit SelectionDAG(const TargetMachine &TM, llvm::CodeGenOpt::Level);
362 explicit SelectionDAG(const TargetMachine &TM, CodeGenOpt::Level);
363 SelectionDAG(const SelectionDAG &) = delete;
364 SelectionDAG &operator=(const SelectionDAG &) = delete;
323365 ~SelectionDAG();
324366
325367 /// Prepare this SelectionDAG to process code in the given MachineFunction.
363405 /// Convenience for setting subgraph color attribute.
364406 void setSubgraphColor(SDNode *N, const char *Color);
365407
366 typedef ilist::const_iterator allnodes_const_iterator;
408 using allnodes_const_iterator = ilist::const_iterator;
409
367410 allnodes_const_iterator allnodes_begin() const { return AllNodes.begin(); }
368411 allnodes_const_iterator allnodes_end() const { return AllNodes.end(); }
369 typedef ilist::iterator allnodes_iterator;
412
413 using allnodes_iterator = ilist::iterator;
414
370415 allnodes_iterator allnodes_begin() { return AllNodes.begin(); }
371416 allnodes_iterator allnodes_end() { return AllNodes.end(); }
417
372418 ilist::size_type allnodes_size() const {
373419 return AllNodes.size();
374420 }
474520
475521 //===--------------------------------------------------------------------===//
476522 // Node creation methods.
477 //
478523
479524 /// \brief Create a ConstantSDNode wrapping a constant value.
480525 /// If VT is a vector type, the constant is splatted into a BUILD_VECTOR.
12501295
12511296 SDDbgInfo::DbgIterator DbgBegin() { return DbgInfo->DbgBegin(); }
12521297 SDDbgInfo::DbgIterator DbgEnd() { return DbgInfo->DbgEnd(); }
1298
12531299 SDDbgInfo::DbgIterator ByvalParmDbgBegin() {
12541300 return DbgInfo->ByvalParmDbgBegin();
12551301 }
1302
12561303 SDDbgInfo::DbgIterator ByvalParmDbgEnd() {
12571304 return DbgInfo->ByvalParmDbgEnd();
12581305 }
14781525 };
14791526
14801527 template <> struct GraphTraits : public GraphTraits {
1481 typedef pointer_iterator nodes_iterator;
1528 using nodes_iterator = pointer_iterator;
1529
14821530 static nodes_iterator nodes_begin(SelectionDAG *G) {
14831531 return nodes_iterator(G->allnodes_begin());
14841532 }
1533
14851534 static nodes_iterator nodes_end(SelectionDAG *G) {
14861535 return nodes_iterator(G->allnodes_end());
14871536 }
14921541 ArrayRef Ops,
14931542 const SDLoc &dl, EVT MemVT,
14941543 MachineMemOperand *MMO) {
1495
14961544 /// Compose node ID and try to find an existing node.
14971545 FoldingSetNodeID ID;
14981546 unsigned Opcode =
15231571 return SDValue(N, 0);
15241572 }
15251573
1526 } // end namespace llvm
1527
1528 #endif
1574 } // end namespace llvm
1575
1576 #endif // LLVM_CODEGEN_SELECTIONDAG_H
3636 #include "llvm/IR/DebugLoc.h"
3737 #include "llvm/IR/Instruction.h"
3838 #include "llvm/IR/Instructions.h"
39 #include "llvm/IR/Metadata.h"
3940 #include "llvm/Support/AlignOf.h"
4041 #include "llvm/Support/AtomicOrdering.h"
4142 #include "llvm/Support/Casting.h"
5253
5354 namespace llvm {
5455
55 class SelectionDAG;
56 class APInt;
57 class Constant;
58 template struct DenseMapInfo;
5659 class GlobalValue;
5760 class MachineBasicBlock;
5861 class MachineConstantPoolValue;
62 class MCSymbol;
63 class raw_ostream;
5964 class SDNode;
65 class SelectionDAG;
66 class Type;
6067 class Value;
61 class MCSymbol;
62 template struct DenseMapInfo;
6368
6469 void checkForCycles(const SDNode *N, const SelectionDAG *DAG = nullptr,
6570 bool force = false);
228233 /// Allow casting operators to work directly on
229234 /// SDValues as if they were SDNode*'s.
230235 template<> struct simplify_type {
231 typedef SDNode* SimpleType;
236 using SimpleType = SDNode *;
237
232238 static SimpleType getSimplifiedValue(SDValue &Val) {
233239 return Val.getNode();
234240 }
235241 };
236242 template<> struct simplify_type {
237 typedef /*const*/ SDNode* SimpleType;
243 using SimpleType = /*const*/ SDNode *;
244
238245 static SimpleType getSimplifiedValue(const SDValue &Val) {
239246 return Val.getNode();
240247 }
329336 /// simplify_type specializations - Allow casting operators to work directly on
330337 /// SDValues as if they were SDNode*'s.
331338 template<> struct simplify_type {
332 typedef SDNode* SimpleType;
339 using SimpleType = SDNode *;
340
333341 static SimpleType getSimplifiedValue(SDUse &Val) {
334342 return Val.getNode();
335343 }
510518
511519 uint16_t : NumLSBaseSDNodeBits;
512520
513 uint16_t IsTruncating : 1;
514 uint16_t IsCompressing : 1;
521 bool IsTruncating : 1;
522 bool IsCompressing : 1;
515523 };
516524
517525 union {
694702 explicit use_iterator(SDUse *op) : Op(op) {}
695703
696704 public:
697 typedef std::iterator
698 SDUse, ptrdiff_t>::reference reference;
699 typedef std::iterator
700 SDUse, ptrdiff_t>::pointer pointer;
705 using reference = std::iterator
706 SDUse, ptrdiff_t>::reference;
707 using pointer = std::iterator
708 SDUse, ptrdiff_t>::pointer;
701709
702710 use_iterator() = default;
703711 use_iterator(const use_iterator &I) : Op(I.Op) {}
823831 return OperandList[Num];
824832 }
825833
826 typedef SDUse* op_iterator;
834 using op_iterator = SDUse *;
827835
828836 op_iterator op_begin() const { return OperandList; }
829837 op_iterator op_end() const { return OperandList+NumOperands; }
895903 return getValueType(ResNo).getSizeInBits();
896904 }
897905
898 typedef const EVT* value_iterator;
906 using value_iterator = const EVT *;
907
899908 value_iterator value_begin() const { return ValueList; }
900909 value_iterator value_end() const { return ValueList+NumValues; }
901910
18211830 BlockAddressSDNode(unsigned NodeTy, EVT VT, const BlockAddress *ba,
18221831 int64_t o, unsigned char Flags)
18231832 : SDNode(NodeTy, 0, DebugLoc(), getSDVTList(VT)),
1824 BA(ba), Offset(o), TargetFlags(Flags) {
1825 }
1833 BA(ba), Offset(o), TargetFlags(Flags) {}
18261834
18271835 public:
18281836 const BlockAddress *getBlockAddress() const { return BA; }
21532161 /// instruction selection proper phase.
21542162 class MachineSDNode : public SDNode {
21552163 public:
2156 typedef MachineMemOperand **mmo_iterator;
2164 using mmo_iterator = MachineMemOperand **;
21572165
21582166 private:
21592167 friend class SelectionDAG;
22252233 };
22262234
22272235 template <> struct GraphTraits {
2228 typedef SDNode *NodeRef;
2229 typedef SDNodeIterator ChildIteratorType;
2236 using NodeRef = SDNode *;
2237 using ChildIteratorType = SDNodeIterator;
22302238
22312239 static NodeRef getEntryNode(SDNode *N) { return N; }
22322240
22432251 ///
22442252 /// This needs to be a union because the largest node differs on 32 bit systems
22452253 /// with 4 and 8 byte pointer alignment, respectively.
2246 typedef AlignedCharArrayUnion
2247 BlockAddressSDNode, GlobalAddressSDNode>
2248 LargestSDNode;
2254 using LargestSDNode = AlignedCharArrayUnion
2255 BlockAddressSDNode,
2256 GlobalAddressSDNode>;
22492257
22502258 /// The SDNode class with the greatest alignment requirement.
2251 typedef GlobalAddressSDNode MostAlignedSDNode;
2259 using MostAlignedSDNode = GlobalAddressSDNode;
22522260
22532261 namespace ISD {
22542262
1919 #define LLVM_CODEGEN_SLOTINDEXES_H
2020
2121 #include "llvm/ADT/DenseMap.h"
22 #include "llvm/ADT/ilist.h"
2223 #include "llvm/ADT/IntervalMap.h"
2324 #include "llvm/ADT/PointerIntPair.h"
2425 #include "llvm/ADT/SmallVector.h"
25 #include "llvm/ADT/ilist.h"
26 #include "llvm/CodeGen/MachineBasicBlock.h"
2627 #include "llvm/CodeGen/MachineFunction.h"
2728 #include "llvm/CodeGen/MachineFunctionPass.h"
29 #include "llvm/CodeGen/MachineInstr.h"
2830 #include "llvm/CodeGen/MachineInstrBundle.h"
31 #include "llvm/Pass.h"
2932 #include "llvm/Support/Allocator.h"
33 #include
34 #include
35 #include
36 #include
3037
3138 namespace llvm {
39
40 class raw_ostream;
3241
3342 /// This class represents an entry in the slot index list held in the
3443 /// SlotIndexes pass. It should not be used directly. See the
3948 unsigned index;
4049
4150 public:
42
4351 IndexListEntry(MachineInstr *mi, unsigned index) : mi(mi), index(index) {}
4452
4553 MachineInstr* getInstr() const { return mi; }
300308 return os;
301309 }
302310
303 typedef std::pair IdxMBBPair;
311 using IdxMBBPair = std::pair;
304312
305313 inline bool operator<(SlotIndex V, const IdxMBBPair &IM) {
306314 return V < IM.first;
324332 // IndexListEntry allocator.
325333 BumpPtrAllocator ileAllocator;
326334
327 typedef ilist IndexList;
335 using IndexList = ilist;
328336 IndexList indexList;
329337
330338 #ifdef EXPENSIVE_CHECKS
333341
334342 MachineFunction *mf;
335343
336 typedef DenseMap Mi2IndexMap;
344 using Mi2IndexMap = DenseMap;
337345 Mi2IndexMap mi2iMap;
338346
339347 /// MBBRanges - Map MBB number to (start, stop) indexes.
435443 const MachineBasicBlock *MBB = MI.getParent();
436444 assert(MBB && "MI must be inserted inna basic block");
437445 MachineBasicBlock::const_iterator I = MI, B = MBB->begin();
438 for (;;) {
446 while (true) {
439447 if (I == B)
440448 return getMBBStartIdx(MBB);
441449 --I;
452460 const MachineBasicBlock *MBB = MI.getParent();
453461 assert(MBB && "MI must be inserted inna basic block");
454462 MachineBasicBlock::const_iterator I = MI, E = MBB->end();
455 for (;;) {
463 while (true) {
456464 ++I;
457465 if (I == E)
458466 return getMBBEndIdx(MBB);
496504
497505 /// Iterator over the idx2MBBMap (sorted pairs of slot index of basic block
498506 /// begin and basic block)
499 typedef SmallVectorImpl::const_iterator MBBIndexIterator;
507 using MBBIndexIterator = SmallVectorImpl::const_iterator;
508
500509 /// Move iterator to the next IdxMBBPair where the SlotIndex is greater or
501510 /// equal to \p To.
502511 MBBIndexIterator advanceMBBIndex(MBBIndexIterator I, SlotIndex To) const {
503512 return std::lower_bound(I, idx2MBBMap.end(), To);
504513 }
514
505515 /// Get an iterator pointing to the IdxMBBPair with the biggest SlotIndex
506516 /// that is greater or equal to \p Idx.
507517 MBBIndexIterator findMBBIndex(SlotIndex Idx) const {
508518 return advanceMBBIndex(idx2MBBMap.begin(), Idx);
509519 }
520
510521 /// Returns an iterator for the begin of the idx2MBBMap.
511522 MBBIndexIterator MBBIndexBegin() const {
512523 return idx2MBBMap.begin();
513524 }
525
514526 /// Return an iterator for the end of the idx2MBBMap.
515527 MBBIndexIterator MBBIndexEnd() const {
516528 return idx2MBBMap.end();
225225 // OpTypes are used to encode information about the following logical
226226 // operand (which may consist of several MachineOperands) for the
227227 // OpParser.
228 typedef enum { DirectMemRefOp, IndirectMemRefOp, ConstantOp } OpType;
228 using OpType = enum { DirectMemRefOp, IndirectMemRefOp, ConstantOp };
229229
230230 StackMaps(AsmPrinter &AP);
231231
253253
254254 private:
255255 static const char *WSMP;
256 typedef SmallVector LocationVec;
257 typedef SmallVector LiveOutVec;
258 typedef MapVector ConstantPool;
256
257 using LocationVec = SmallVector;
258 using LiveOutVec = SmallVector;
259 using ConstantPool = MapVector;
259260
260261 struct FunctionInfo {
261262 uint64_t StackSize = 0;
278279 LiveOuts(std::move(LiveOuts)) {}
279280 };
280281
281 typedef MapVector FnInfoMap;
282 typedef std::vector CallsiteInfoList;
282 using FnInfoMap = MapVector;
283 using CallsiteInfoList = std::vector;
283284
284285 AsmPrinter &AP;
285286 CallsiteInfoList CSInfos;
None //===-- llvm/CodeGen/WinEHFuncInfo.h ----------------------------*- C++ -*-===//
0 //===- llvm/CodeGen/WinEHFuncInfo.h -----------------------------*- C++ -*-===//
11 //
22 // The LLVM Compiler Infrastructure
33 //
1616 #include "llvm/ADT/DenseMap.h"
1717 #include "llvm/ADT/PointerUnion.h"
1818 #include "llvm/ADT/SmallVector.h"
19 #include "llvm/ADT/TinyPtrVector.h"
20 #include "llvm/IR/Instructions.h"
19 #include
20 #include
21 #include
2122
2223 namespace llvm {
24
2325 class AllocaInst;
2426 class BasicBlock;
25 class CatchReturnInst;
26 class Constant;
27 class FuncletPadInst;
2728 class Function;
2829 class GlobalVariable;
30 class Instruction;
2931 class InvokeInst;
30 class IntrinsicInst;
31 class LandingPadInst;
32 class MCExpr;
32 class MachineBasicBlock;
3333 class MCSymbol;
34 class MachineBasicBlock;
35 class Value;
3634
3735 // The following structs respresent the .xdata tables for various
3836 // Windows-related EH personalities.
3937
40 typedef PointerUnion MBBOrBasicBlock;
38 using MBBOrBasicBlock = PointerUnion;
4139
4240 struct CxxUnwindMapEntry {
4341 int ToState;
9896 SmallVector TryBlockMap;
9997 SmallVector SEHUnwindMap;
10098 SmallVector ClrEHUnwindMap;
101 int UnwindHelpFrameIdx = INT_MAX;
102 int PSPSymFrameIdx = INT_MAX;
99 int UnwindHelpFrameIdx = std::numeric_limits::max();
100 int PSPSymFrameIdx = std::numeric_limits::max();
103101
104102 int getLastStateNumber() const { return CxxUnwindMap.size() - 1; }
105103
106104 void addIPToStateRange(const InvokeInst *II, MCSymbol *InvokeBegin,
107105 MCSymbol *InvokeEnd);
108106
109 int EHRegNodeFrameIndex = INT_MAX;
110 int EHRegNodeEndOffset = INT_MAX;
111 int EHGuardFrameIndex = INT_MAX;
112 int SEHSetFrameOffset = INT_MAX;
107 int EHRegNodeFrameIndex = std::numeric_limits::max();
108 int EHRegNodeEndOffset = std::numeric_limits::max();
109 int EHGuardFrameIndex = std::numeric_limits::max();
110 int SEHSetFrameOffset = std::numeric_limits::max();
113111
114112 WinEHFuncInfo();
115113 };
124122 WinEHFuncInfo &FuncInfo);
125123
126124 void calculateClrEHStateNumbers(const Function *Fn, WinEHFuncInfo &FuncInfo);
127 }
125
126 } // end namespace llvm
127
128128 #endif // LLVM_CODEGEN_WINEHFUNCINFO_H
None //===-- SelectionDAG.cpp - Implement the SelectionDAG data structures -----===//
0 //===- SelectionDAG.cpp - Implement the SelectionDAG data structures ------===//
11 //
22 // The LLVM Compiler Infrastructure
33 //
1010 //
1111 //===----------------------------------------------------------------------===//
1212
13 #include "llvm/CodeGen/SelectionDAG.h"
1413 #include "SDNodeDbgValue.h"
14 #include "llvm/ADT/APFloat.h"
15 #include "llvm/ADT/APInt.h"
1516 #include "llvm/ADT/APSInt.h"
16 #include "llvm/ADT/SetVector.h"
17 #include "llvm/ADT/ArrayRef.h"
18 #include "llvm/ADT/BitVector.h"
19 #include "llvm/ADT/FoldingSet.h"
20 #include "llvm/ADT/None.h"
1721 #include "llvm/ADT/SmallPtrSet.h"
18 #include "llvm/ADT/SmallSet.h"
1922 #include "llvm/ADT/SmallVector.h"
20 #include "llvm/ADT/StringExtras.h"
23 #include "llvm/ADT/STLExtras.h"
24 #include "llvm/ADT/Triple.h"
25 #include "llvm/ADT/Twine.h"
2126 #include "llvm/Analysis/ValueTracking.h"
27 #include "llvm/CodeGen/ISDOpcodes.h"
2228 #include "llvm/CodeGen/MachineBasicBlock.h"
2329 #include "llvm/CodeGen/MachineConstantPool.h"
2430 #include "llvm/CodeGen/MachineFrameInfo.h"
25 #include "llvm/CodeGen/MachineModuleInfo.h"
31 #include "llvm/CodeGen/MachineFunction.h"
32 #include "llvm/CodeGen/MachineMemOperand.h"
33 #include "llvm/CodeGen/MachineValueType.h"
34 #include "llvm/CodeGen/RuntimeLibcalls.h"
35 #include "llvm/CodeGen/SelectionDAG.h"
36 #include "llvm/CodeGen/SelectionDAGNodes.h"
2637 #include "llvm/CodeGen/SelectionDAGTargetInfo.h"
27 #include "llvm/IR/CallingConv.h"
38 #include "llvm/CodeGen/ValueTypes.h"
39 #include "llvm/IR/Constant.h"
2840 #include "llvm/IR/Constants.h"
2941 #include "llvm/IR/DataLayout.h"
30 #include "llvm/IR/DebugInfo.h"
42 #include "llvm/IR/DebugInfoMetadata.h"
43 #include "llvm/IR/DebugLoc.h"
3144 #include "llvm/IR/DerivedTypes.h"
3245 #include "llvm/IR/Function.h"
33 #include "llvm/IR/GlobalAlias.h"
34 #include "llvm/IR/GlobalVariable.h"
35 #include "llvm/IR/Intrinsics.h"
46 #include "llvm/IR/GlobalValue.h"
47 #include "llvm/IR/Metadata.h"
48 #include "llvm/IR/Type.h"
49 #include "llvm/IR/Value.h"
50 #include "llvm/Support/Casting.h"
51 #include "llvm/Support/CodeGen.h"
52 #include "llvm/Support/Compiler.h"
3653 #include "llvm/Support/Debug.h"
3754 #include "llvm/Support/ErrorHandling.h"
3855 #include "llvm/Support/KnownBits.h"
4057 #include "llvm/Support/MathExtras.h"
4158 #include "llvm/Support/Mutex.h"
4259 #include "llvm/Support/raw_ostream.h"
43 #include "llvm/Target/TargetInstrInfo.h"
44 #include "llvm/Target/TargetIntrinsicInfo.h"
4560 #include "llvm/Target/TargetLowering.h"
4661 #include "llvm/Target/TargetMachine.h"
4762 #include "llvm/Target/TargetOptions.h"
4863 #include "llvm/Target/TargetRegisterInfo.h"
4964 #include "llvm/Target/TargetSubtargetInfo.h"
5065 #include
51 #include math>
66 #include assert>
67 #include
68 #include
69 #include
70 #include
71 #include
5272 #include
73 #include
5374
5475 using namespace llvm;
5576
268289 return ISD::CondCode(Operation);
269290 }
270291
271
272292 /// For an integer comparison, return 1 if the comparison is a signed operation
273293 /// and 2 if the result is an unsigned comparison. Return zero if the operation
274294 /// does not depend on the sign of the input (setne and seteq).
337357 //===----------------------------------------------------------------------===//
338358
339359 /// AddNodeIDOpcode - Add the node opcode to the NodeID data.
340 ///
341360 static void AddNodeIDOpcode(FoldingSetNodeID &ID, unsigned OpC) {
342361 ID.AddInteger(OpC);
343362 }
349368 }
350369
351370 /// AddNodeIDOperands - Various routines for adding operands to the NodeID data.
352 ///
353371 static void AddNodeIDOperands(FoldingSetNodeID &ID,
354372 ArrayRef Ops) {
355373 for (auto& Op : Ops) {
359377 }
360378
361379 /// AddNodeIDOperands - Various routines for adding operands to the NodeID data.
362 ///
363380 static void AddNodeIDOperands(FoldingSetNodeID &ID,
364381 ArrayRef Ops) {
365382 for (auto& Op : Ops) {
391408 break;
392409 }
393410 case ISD::TargetConstantFP:
394 case ISD::ConstantFP: {
411 case ISD::ConstantFP:
395412 ID.AddPointer(cast(N)->getConstantFPValue());
396413 break;
397 }
398414 case ISD::TargetGlobalAddress:
399415 case ISD::GlobalAddress:
400416 case ISD::TargetGlobalTLSAddress:
769785 /// maps and modified in place. Add it back to the CSE maps, unless an identical
770786 /// node already exists, in which case transfer all its users to the existing
771787 /// node. This transfer can potentially trigger recursive merging.
772 ///
773788 void
774789 SelectionDAG::AddModifiedNodeToCSEMaps(SDNode *N) {
775790 // For node types that aren't CSE'd, just act as if no identical node
834849 return Node;
835850 }
836851
837
838852 /// FindModifiedNodeSlot - Find a slot for the specified node if its operands
839853 /// were replaced with those specified. If this node is never memoized,
840854 /// return null, otherwise return a pointer to the slot it would take. If a
863877
864878 // EntryNode could meaningfully have debug info if we can find it...
865879 SelectionDAG::SelectionDAG(const TargetMachine &tm, CodeGenOpt::Level OL)
866 : TM(tm), TSI(nullptr), TLI(nullptr), OptLevel(OL),
880 : TM(tm), OptLevel(OL),
867881 EntryNode(ISD::EntryToken, 0, DebugLoc(), getVTList(MVT::Other)),
868 Root(getEntryNode()), NewNodesMustHaveLegalTypes(false),
869 UpdateListeners(nullptr) {
882 Root(getEntryNode()) {
870883 InsertNode(&EntryNode);
871884 DbgInfo = new SDDbgInfo();
872885 }
10371050 }
10381051
10391052 /// getNOT - Create a bitwise NOT operation as (XOR Val, -1).
1040 ///
10411053 SDValue SelectionDAG::getNOT(const SDLoc &DL, SDValue Val, EVT VT) {
10421054 EVT EltVT = VT.getScalarType();
10431055 SDValue NegOne =
13161328 return SDValue(N, 0);
13171329 }
13181330
1319
13201331 SDValue SelectionDAG::getConstantPool(MachineConstantPoolValue *C, EVT VT,
13211332 unsigned Alignment, int Offset,
13221333 bool isTarget,
14501461 // Validate that all indices in Mask are within the range of the elements
14511462 // input to the shuffle.
14521463 int NElts = Mask.size();
1453 assert(all_of(Mask, [&](int M) { return M < (NElts * 2); }) &&
1464 assert(llvm::all_of(Mask, [&](int M) { return M < (NElts * 2); }) &&
14541465 "Index out of range");
14551466
14561467 // Copy the mask so we can do any needed cleanup.
29172928 else
29182929 DemandedRHS.setBit((unsigned)M % NumElts);
29192930 }
2920 Tmp = UINT_MAX;
2931 Tmp = std::numeric_limits::max();
29212932 if (!!DemandedLHS)
29222933 Tmp = ComputeNumSignBits(Op.getOperand(0), DemandedLHS, Depth + 1);
29232934 if (!!DemandedRHS) {
31213132 unsigned EltIdx = CEltNo->getZExtValue();
31223133
31233134 // If we demand the inserted element then get its sign bits.
3124 Tmp = UINT_MAX;
3135 Tmp = std::numeric_limits::max();
31253136 if (DemandedElts[EltIdx]) {
31263137 // TODO - handle implicit truncation of inserted elements.
31273138 if (InVal.getScalarValueSizeInBits() != VTBits)
31873198 case ISD::CONCAT_VECTORS:
31883199 // Determine the minimum number of sign bits across all demanded
31893200 // elts of the input vectors. Early out if the result is already 1.
3190 Tmp = UINT_MAX;
3201 Tmp = std::numeric_limits::max();
31913202 EVT SubVectorVT = Op.getOperand(0).getValueType();
31923203 unsigned NumSubVectorElts = SubVectorVT.getVectorNumElements();
31933204 unsigned NumSubVectors = Op.getNumOperands();
33263337
33273338 static SDValue FoldCONCAT_VECTORS(const SDLoc &DL, EVT VT,
33283339 ArrayRef Ops,
3329 llvm::SelectionDAG &DAG) {
3340 SelectionDAG &DAG) {
33303341 assert(!Ops.empty() && "Can't concatenate an empty list of vectors!");
33313342 assert(llvm::all_of(Ops,
33323343 [Ops](SDValue Op) {
38353846 return true;
38363847
38373848 return ISD::isBuildVectorOfConstantSDNodes(Divisor.getNode()) &&
3838 any_of(Divisor->op_values(),
3839 [](SDValue V) { return V.isUndef() || isNullConstant(V); });
3849 llvm::any_of(Divisor->op_values(),
3850 [](SDValue V) { return V.isUndef() ||
3851 isNullConstant(V); });
38403852 // TODO: Handle signed overflow.
38413853 }
38423854 // TODO: Handle oversized shifts.
39473959 // All operands must be vector types with the same number of elements as
39483960 // the result type and must be either UNDEF or a build vector of constant
39493961 // or UNDEF scalars.
3950 if (!all_of(Ops, IsConstantBuildVectorOrUndef) ||
3951 !all_of(Ops, IsScalarOrSameVectorSize))
3962 if (!llvm::all_of(Ops, IsConstantBuildVectorOrUndef) ||
3963 !llvm::all_of(Ops, IsScalarOrSameVectorSize))
39523964 return SDValue();
39533965
39543966 // If we are comparing vectors, then the result needs to be a i1 boolean
55495561 Opcode == ISD::PREFETCH ||
55505562 Opcode == ISD::LIFETIME_START ||
55515563 Opcode == ISD::LIFETIME_END ||
5552 (Opcode <= INT_MAX &&
5564 (Opcode <= std::numeric_limits::max() &&
55535565 (int)Opcode >= ISD::FIRST_TARGET_MEMORY_OPCODE)) &&
55545566 "Opcode is not a memory-accessing opcode!");
55555567
58835895 SDValue Ptr, SDValue Mask, SDValue Src0,
58845896 EVT MemVT, MachineMemOperand *MMO,
58855897 ISD::LoadExtType ExtTy, bool isExpanding) {
5886
58875898 SDVTList VTs = getVTList(VT, MVT::Other);
58885899 SDValue Ops[] = { Chain, Ptr, Mask, Src0 };
58895900 FoldingSetNodeID ID;
60376048
60386049 switch (Opcode) {
60396050 default: break;
6040 case ISD::CONCAT_VECTORS: {
6051 case ISD::CONCAT_VECTORS:
60416052 // Attempt to fold CONCAT_VECTORS into BUILD_VECTOR or UNDEF.
60426053 if (SDValue V = FoldCONCAT_VECTORS(DL, VT, Ops, *this))
60436054 return V;
60446055 break;
6045 }
6046 case ISD::SELECT_CC: {
6056 case ISD::SELECT_CC:
60476057 assert(NumOps == 5 && "SELECT_CC takes 5 operands!");
60486058 assert(Ops[0].getValueType() == Ops[1].getValueType() &&
60496059 "LHS and RHS of condition must have same type!");
60526062 assert(Ops[2].getValueType() == VT &&
60536063 "select_cc node must be of same type as true and false value!");
60546064 break;
6055 }
6056 case ISD::BR_CC: {
6065 case ISD::BR_CC:
60576066 assert(NumOps == 5 && "BR_CC takes 5 operands!");
60586067 assert(Ops[2].getValueType() == Ops[3].getValueType() &&
60596068 "LHS/RHS of comparison should match types!");
60606069 break;
6061 }
60626070 }
60636071
60646072 // Memoize nodes.
65986606 return Res;
65996607 }
66006608
6601
66026609 /// getMachineNode - These are used for target selectors to create a new node
66036610 /// with specified return type(s), MachineInstr opcode, and operands.
66046611 ///
68116818 : SelectionDAG::DAGUpdateListener(d), UI(ui), UE(ue) {}
68126819 };
68136820
6814 }
6821 } // end anonymous namespace
68156822
68166823 /// ReplaceAllUsesWith - Modify anything using 'From' to use 'To' instead.
68176824 /// This can cause recursive merging of nodes in the DAG.
68566863 // already exists there, recursively merge the results together.
68576864 AddModifiedNodeToCSEMaps(User);
68586865 }
6859
68606866
68616867 // If we just RAUW'd the root, take note.
68626868 if (FromN == getRoot())
70277033 }
70287034
70297035 namespace {
7036
70307037 /// UseMemo - This class is used by SelectionDAG::ReplaceAllUsesOfValuesWith
70317038 /// to record information about a use.
70327039 struct UseMemo {
70397046 bool operator<(const UseMemo &L, const UseMemo &R) {
70407047 return (intptr_t)L.User < (intptr_t)R.User;
70417048 }
7042 }
7049
7050 } // end anonymous namespace
70437051
70447052 /// ReplaceAllUsesOfValuesWith - Replace any uses of From with To, leaving
70457053 /// uses of other values produced by From.getNode() alone. The same value
71057113 /// based on their topological order. It returns the maximum id and a vector
71067114 /// of the SDNodes* in assigned order by reference.
71077115 unsigned SelectionDAG::AssignTopologicalOrder() {
7108
71097116 unsigned DAGSize = 0;
71107117
71117118 // SortedPos tracks the progress of the algorithm. Nodes before it are
73327339 }
73337340
73347341 namespace {
7342
73357343 struct EVTArray {
73367344 std::vector VTs;
73377345
73417349 VTs.push_back(MVT((MVT::SimpleValueType)i));
73427350 }
73437351 };
7344 }
7345
7346 static ManagedStatic > EVTs;
7352
7353 } // end anonymous namespace
7354
7355 static ManagedStatic> EVTs;
73477356 static ManagedStatic SimpleVTArray;
7348 static ManagedStatic > VTMutex;
7357 static ManagedStatic> VTMutex;
73497358
73507359 /// getValueTypeList - Return a pointer to the specified value type.
73517360 ///
73797388 return NUses == 0;
73807389 }
73817390
7382
73837391 /// hasAnyUseOfValue - Return true if there are any use of the indicated
73847392 /// value. This method ignores uses of other values defined by this operation.
73857393 bool SDNode::hasAnyUseOfValue(unsigned Value) const {
73927400 return false;
73937401 }
73947402
7395
73967403 /// isOnlyUserOf - Return true if this node is the only use of N.
7397 ///
73987404 bool SDNode::isOnlyUserOf(const SDNode *N) const {
73997405 bool Seen = false;
74007406 for (SDNode::use_iterator I = N->use_begin(), E = N->use_end(); I != E; ++I) {
74247430 }
74257431
74267432 /// isOperand - Return true if this node is an operand of N.
7427 ///
74287433 bool SDValue::isOperandOf(const SDNode *N) const {
74297434 for (const SDValue &Op : N->op_values())
74307435 if (*this == Op)
74747479 }
74757480 // Next, try a deep search: check whether every operand of the TokenFactor
74767481 // reaches Dest.
7477 return all_of((*this)->ops(), [=](SDValue Op) {
7482 return llvm::all_of((*this)->ops(), [=](SDValue Op) {
74787483 return Op.reachesChainWithoutSideEffects(Dest, Depth - 1);
74797484 });
74807485 }
76267631 return false;
76277632 }
76287633
7629
76307634 /// InferPtrAlignment - Infer alignment of a load / store address. Return 0 if
76317635 /// it cannot be inferred.
76327636 unsigned SelectionDAG::InferPtrAlignment(SDValue Ptr) const {
77177721 return getGlobal()->getType()->getAddressSpace();
77187722 }
77197723
7720
77217724 Type *ConstantPoolSDNode::getType() const {
77227725 if (isMachineConstantPoolEntry())
77237726 return Val.MachineCPVal->getType();