LLVM 23.0.0git
DependencyGraph.h
Go to the documentation of this file.
1//===- DependencyGraph.h ----------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file declares the dependency graph used by the vectorizer's instruction
10// scheduler.
11//
12// The nodes of the graph are objects of the `DGNode` class. Each `DGNode`
13// object points to an instruction.
14// The edges between `DGNode`s are implicitly defined by an ordered set of
15// predecessor nodes, to save memory.
16// Finally the whole dependency graph is an object of the `DependencyGraph`
17// class, which also provides the API for creating/extending the graph from
18// input Sandbox IR.
19//
20//===----------------------------------------------------------------------===//
21
22#ifndef LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_DEPENDENCYGRAPH_H
23#define LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_DEPENDENCYGRAPH_H
24
25#include "llvm/ADT/DenseMap.h"
32
33namespace llvm::sandboxir {
34
35class DependencyGraph;
36class MemDGNode;
37class SchedBundle;
38
39/// SubclassIDs for isa/dyn_cast etc.
40enum class DGNodeID {
43};
44
45class DGNode;
46class MemDGNode;
47class DependencyGraph;
48
49// Defined in Transforms/Vectorize/SandboxVectorizer/Interval.cpp
50extern template class LLVM_TEMPLATE_ABI Interval<MemDGNode>;
51
52/// Iterate over both def-use and mem dependencies.
53class PredIterator {
57 DGNode *N = nullptr;
58 DependencyGraph *DAG = nullptr;
59
60 PredIterator(const User::op_iterator &OpIt, const User::op_iterator &OpItE,
62 DependencyGraph &DAG)
63 : OpIt(OpIt), OpItE(OpItE), MemIt(MemIt), N(N), DAG(&DAG) {}
64 PredIterator(const User::op_iterator &OpIt, const User::op_iterator &OpItE,
65 DGNode *N, DependencyGraph &DAG)
66 : OpIt(OpIt), OpItE(OpItE), N(N), DAG(&DAG) {}
67 friend class DGNode; // For constructor
68 friend class MemDGNode; // For constructor
69
70 /// Skip iterators that don't point instructions or are outside \p DAG,
71 /// starting from \p OpIt and ending before \p OpItE.n
72 LLVM_ABI static User::op_iterator skipBadIt(User::op_iterator OpIt,
74 const DependencyGraph &DAG);
75
76public:
77 using difference_type = std::ptrdiff_t;
78 using value_type = DGNode *;
81 using iterator_category = std::input_iterator_tag;
83 LLVM_ABI PredIterator &operator++();
84 PredIterator operator++(int) {
85 auto Copy = *this;
86 ++(*this);
87 return Copy;
88 }
89 LLVM_ABI bool operator==(const PredIterator &Other) const;
90 bool operator!=(const PredIterator &Other) const { return !(*this == Other); }
91};
92
93/// Iterate over both def-use and mem dependencies.
94class SuccIterator {
96 User::user_iterator UserItE;
98 DGNode *N = nullptr;
99 DependencyGraph *DAG = nullptr;
100
101 SuccIterator(const Value::user_iterator &UserIt,
102 const Value::user_iterator &UserItE,
104 DependencyGraph &DAG)
105 : UserIt(UserIt), UserItE(UserItE), MemIt(MemIt), N(N), DAG(&DAG) {}
106 SuccIterator(const User::user_iterator &UserIt,
107 const User::user_iterator &UserItE, DGNode *N,
108 DependencyGraph &DAG)
109 : UserIt(UserIt), UserItE(UserItE), N(N), DAG(&DAG) {}
110 friend class DGNode; // For constructor
111 friend class MemDGNode; // For constructor
112
113 /// Skip iterators that don't point to instructions or are outside \p DAG,
114 /// starting from \p OpIt and ending before \p OpItE.
116 skipOutOfScope(User::user_iterator UserIt, User::user_iterator UserItE,
117 const DependencyGraph &DAG);
118
119public:
120 using difference_type = std::ptrdiff_t;
124 using iterator_category = std::input_iterator_tag;
126 LLVM_ABI SuccIterator &operator++();
127 SuccIterator operator++(int) {
128 auto Copy = *this;
129 ++(*this);
130 return Copy;
131 }
132 LLVM_ABI bool operator==(const SuccIterator &Other) const;
133 bool operator!=(const SuccIterator &Other) const { return !(*this == Other); }
134};
135
136/// A DependencyGraph Node that points to an Instruction and contains memory
137/// dependency edges.
139protected:
141 // TODO: Use a PointerIntPair for SubclassID and I.
142 /// For isa/dyn_cast etc.
144 /// The number of unscheduled successors. Optional represents whether the
145 /// value is meaningless, e.g., after a node gets scheduled.
146 std::optional<unsigned> UnscheduledSuccs = 0;
147 /// This is true if this node has been scheduled.
148 bool Scheduled = false;
149 /// The scheduler bundle that this node belongs to.
150 SchedBundle *SB = nullptr;
151
153 void clearSchedBundle() { this->SB = nullptr; }
154 friend class SchedBundle; // For setSchedBundle(), clearSchedBundle().
155
157 friend class MemDGNode; // For constructor.
158 friend class DependencyGraph; // For UnscheduledSuccs
159
160public:
162 assert(!isMemDepNodeCandidate(I) && "Expected Non-Mem instruction, ");
163 }
164 DGNode(const DGNode &Other) = delete;
165 virtual ~DGNode();
166 /// \Returns the number of unscheduled successors.
167 unsigned getNumUnscheduledSuccs() const {
168 assert((bool)UnscheduledSuccs && "Invalid UnscheduledSuccs!");
169 return *UnscheduledSuccs;
170 }
171#ifndef NDEBUG
172 /// \returns true unscheduled successors contains valid data (for testing).
173 bool validUnscheduledSuccs() const { return (bool)UnscheduledSuccs; }
174#endif
175 // TODO: Make this private?
177 assert(*UnscheduledSuccs > 0 && "Counting error!");
179 }
183 Scheduled = false;
184 }
185 /// \Returns true if all dependent successors have been scheduled.
186 bool ready() const { return UnscheduledSuccs == 0; }
187 /// \Returns true if this node has been scheduled.
188 bool scheduled() const { return Scheduled; }
190 Scheduled = true;
191 // UnscheduledSuccs is meaningless from this point on, so prohibit its use.
192 UnscheduledSuccs = std::nullopt;
193 }
194 /// \Returns the scheduling bundle that this node belongs to, or nullptr.
195 SchedBundle *getSchedBundle() const { return SB; }
196 /// \Returns true if this is before \p Other in program order.
197 bool comesBefore(const DGNode *Other) { return I->comesBefore(Other->I); }
200 return PredIterator(
201 PredIterator::skipBadIt(I->op_begin(), I->op_end(), DAG), I->op_end(),
202 this, DAG);
203 }
205 return PredIterator(I->op_end(), I->op_end(), this, DAG);
206 }
208 return const_cast<DGNode *>(this)->preds_begin(DAG);
209 }
211 return const_cast<DGNode *>(this)->preds_end(DAG);
212 }
213 /// \Returns a range of DAG predecessors nodes. If this is a MemDGNode then
214 /// this will also include the memory dependency predecessors.
215 /// Please note that this can include the same node more than once, if for
216 /// example it's both a use-def predecessor and a mem dep predecessor.
220
223 return SuccIterator(
224 SuccIterator::skipOutOfScope(I->user_begin(), I->user_end(), DAG),
225 I->user_end(), this, DAG);
226 }
228 return SuccIterator(I->user_end(), I->user_end(), this, DAG);
229 }
231 return const_cast<DGNode *>(this)->succs_begin(DAG);
232 }
234 return const_cast<DGNode *>(this)->succs_end(DAG);
235 }
236 /// \Returns a range of DAG successor nodes. If this is a MemDGNode then
237 /// this will also include the memory dependency successors.
238 /// Please note that this can include the same node more than once, if for
239 /// example it's both a use-def predecessor and a mem dep successor.
243
245 if (auto *II = dyn_cast<IntrinsicInst>(I)) {
246 auto IID = II->getIntrinsicID();
247 return IID == Intrinsic::stackrestore || IID == Intrinsic::stacksave;
248 }
249 return false;
250 }
251
252 /// \Returns true if intrinsic \p I touches memory. This is used by the
253 /// dependency graph.
255 auto IID = I->getIntrinsicID();
256 return IID != Intrinsic::sideeffect && IID != Intrinsic::pseudoprobe;
257 }
258
259 /// We consider \p I as a Memory Dependency Candidate instruction if it
260 /// reads/write memory or if it has side-effects. This is used by the
261 /// dependency graph.
264 return I->mayReadOrWriteMemory() &&
266 }
267
268 /// \Returns true if \p I is fence like. It excludes non-mem intrinsics.
269 static bool isFenceLike(Instruction *I) {
271 return I->isFenceLike() &&
273 }
274
275 /// \Returns true if \p I is a memory dependency candidate instruction.
277 AllocaInst *Alloca;
278 return isMemDepCandidate(I) ||
279 ((Alloca = dyn_cast<AllocaInst>(I)) &&
280 Alloca->isUsedWithInAlloca()) ||
282 }
283
284 Instruction *getInstruction() const { return I; }
285
286#ifndef NDEBUG
287 virtual void print(raw_ostream &OS, bool PrintDeps = true) const;
289 N.print(OS);
290 return OS;
291 }
292 LLVM_DUMP_METHOD void dump() const;
293#endif // NDEBUG
294};
295
296/// A DependencyGraph Node for instructions that may read/write memory, or have
297/// some ordering constraints, like with stacksave/stackrestore and
298/// alloca/inalloca.
299class MemDGNode final : public DGNode {
300 MemDGNode *PrevMemN = nullptr;
301 MemDGNode *NextMemN = nullptr;
302 /// Memory predecessors.
303 DenseSet<MemDGNode *> MemPreds;
304 /// Memory successors.
305 DenseSet<MemDGNode *> MemSuccs;
306 friend class PredIterator; // For MemPreds.
307 friend class SuccIterator; // For MemSuccs.
308 /// Creates both edges: this<->N.
309 void setNextNode(MemDGNode *N) {
310 assert(N != this && "About to point to self!");
311 NextMemN = N;
312 if (NextMemN != nullptr)
313 NextMemN->PrevMemN = this;
314 }
315 /// Creates both edges: N<->this.
316 void setPrevNode(MemDGNode *N) {
317 assert(N != this && "About to point to self!");
318 PrevMemN = N;
319 if (PrevMemN != nullptr)
320 PrevMemN->NextMemN = this;
321 }
322 friend class DependencyGraph; // For setNextNode(), setPrevNode().
323 void detachFromChain() {
324 if (PrevMemN != nullptr)
325 PrevMemN->NextMemN = NextMemN;
326 if (NextMemN != nullptr)
327 NextMemN->PrevMemN = PrevMemN;
328 PrevMemN = nullptr;
329 NextMemN = nullptr;
330 }
331
332public:
334 assert(isMemDepNodeCandidate(I) && "Expected Mem instruction!");
335 }
336 static bool classof(const DGNode *Other) {
337 return Other->SubclassID == DGNodeID::MemDGNode;
338 }
340 auto OpEndIt = I->op_end();
341 return PredIterator(PredIterator::skipBadIt(I->op_begin(), OpEndIt, DAG),
342 OpEndIt, MemPreds.begin(), this, DAG);
343 }
345 return PredIterator(I->op_end(), I->op_end(), MemPreds.end(), this, DAG);
346 }
348 auto UserEndIt = I->user_end();
349 return SuccIterator(
350 SuccIterator::skipOutOfScope(I->user_begin(), UserEndIt, DAG),
351 UserEndIt, MemSuccs.begin(), this, DAG);
352 }
354 return SuccIterator(I->user_end(), I->user_end(), MemSuccs.end(), this,
355 DAG);
356 }
357 /// \Returns the previous Mem DGNode in instruction order.
358 MemDGNode *getPrevNode() const { return PrevMemN; }
359 /// \Returns the next Mem DGNode in instruction order.
360 MemDGNode *getNextNode() const { return NextMemN; }
361 /// Adds the mem dependency edge PredN->this. This also increments the
362 /// UnscheduledSuccs counter of the predecessor if this node has not been
363 /// scheduled.
364 void addMemPred(MemDGNode *PredN) {
365 [[maybe_unused]] auto Inserted = MemPreds.insert(PredN).second;
366 assert(Inserted && "PredN already exists!");
367 assert(PredN != this && "Trying to add a dependency to self!");
368 PredN->MemSuccs.insert(this);
369 if (!Scheduled) {
370 if (!PredN->Scheduled)
371 PredN->incrUnscheduledSuccs();
372 }
373 }
374 /// Removes the memory dependency PredN->this. This also updates the
375 /// UnscheduledSuccs counter of PredN if this node has not been scheduled.
377 MemPreds.erase(PredN);
378 PredN->MemSuccs.erase(this);
379 if (!Scheduled) {
380 if (!PredN->Scheduled)
381 PredN->decrUnscheduledSuccs();
382 }
383 }
384 /// \Returns true if there is a memory dependency N->this.
385 bool hasMemPred(DGNode *N) const {
386 if (auto *MN = dyn_cast<MemDGNode>(N))
387 return MemPreds.count(MN);
388 return false;
389 }
390 /// \Returns all memory dependency predecessors. Used by tests.
392 return make_range(MemPreds.begin(), MemPreds.end());
393 }
394 /// \Returns all memory dependency successors.
396 return make_range(MemSuccs.begin(), MemSuccs.end());
397 }
398#ifndef NDEBUG
399 void print(raw_ostream &OS, bool PrintDeps = true) const override;
400#endif // NDEBUG
401};
402
403/// Convenience builders for a MemDGNode interval.
405public:
406 /// Scans the instruction chain in \p Intvl top-down, returning the top-most
407 /// MemDGNode, or nullptr.
409 const DependencyGraph &DAG);
410 /// Scans the instruction chain in \p Intvl bottom-up, returning the
411 /// bottom-most MemDGNode, or nullptr.
413 const DependencyGraph &DAG);
414 /// Given \p Instrs it finds their closest mem nodes in the interval and
415 /// returns the corresponding mem range. Note: BotN (or its neighboring mem
416 /// node) is included in the range.
418 DependencyGraph &DAG);
419 static Interval<MemDGNode> makeEmpty() { return {}; }
420};
421
423private:
425 /// The DAG spans across all instructions in this interval.
426 Interval<Instruction> DAGInterval;
427
428 Context *Ctx = nullptr;
429 std::optional<Context::CallbackID> CreateInstrCB;
430 std::optional<Context::CallbackID> EraseInstrCB;
431 std::optional<Context::CallbackID> MoveInstrCB;
432 std::optional<Context::CallbackID> SetUseCB;
433
434 std::unique_ptr<BatchAAResults> BatchAA;
435
436 enum class DependencyType {
437 ReadAfterWrite, ///> Memory dependency write -> read
438 WriteAfterWrite, ///> Memory dependency write -> write
439 WriteAfterRead, ///> Memory dependency read -> write
440 Control, ///> Control-related dependency, like with PHI/Terminator
441 Other, ///> Currently used for stack related instrs
442 None, ///> No memory/other dependency
443 };
444 /// \Returns the dependency type depending on whether instructions may
445 /// read/write memory or whether they are some specific opcode-related
446 /// restrictions.
447 /// Note: It does not check whether a memory dependency is actually correct,
448 /// as it won't call AA. Therefore it returns the worst-case dep type.
449 static DependencyType getRoughDepType(Instruction *FromI, Instruction *ToI);
450
451 // TODO: Implement AABudget.
452 /// \Returns true if there is a memory/other dependency \p SrcI->DstI.
453 bool alias(Instruction *SrcI, Instruction *DstI, DependencyType DepType);
454
455 bool hasDep(sandboxir::Instruction *SrcI, sandboxir::Instruction *DstI);
456
457 /// Go through all mem nodes in \p SrcScanRange and try to add dependencies to
458 /// \p DstN.
459 void scanAndAddDeps(MemDGNode &DstN, const Interval<MemDGNode> &SrcScanRange);
460
461 /// Sets the UnscheduledSuccs of all DGNodes in \p NewInterval based on
462 /// def-use edges.
463 void setDefUseUnscheduledSuccs(const Interval<Instruction> &NewInterval);
464
465 /// Create DAG nodes for instrs in \p NewInterval and update the MemNode
466 /// chain.
467 void createNewNodes(const Interval<Instruction> &NewInterval);
468
469 /// Helper for `notify*Instr()`. \Returns the first MemDGNode that comes
470 /// before \p N, skipping \p SkipN, including or excluding \p N based on
471 /// \p IncludingN, or nullptr if not found.
472 MemDGNode *getMemDGNodeBefore(DGNode *N, bool IncludingN,
473 MemDGNode *SkipN = nullptr) const;
474 /// Helper for `notifyMoveInstr()`. \Returns the first MemDGNode that comes
475 /// after \p N, skipping \p SkipN, including or excluding \p N based on \p
476 /// IncludingN, or nullptr if not found.
477 MemDGNode *getMemDGNodeAfter(DGNode *N, bool IncludingN,
478 MemDGNode *SkipN = nullptr) const;
479
480 /// Called by the callbacks when a new instruction \p I has been created.
481 LLVM_ABI void notifyCreateInstr(Instruction *I);
482 /// Called by the callbacks when instruction \p I is about to get
483 /// deleted.
484 LLVM_ABI void notifyEraseInstr(Instruction *I);
485 /// Called by the callbacks when instruction \p I is about to be moved to
486 /// \p To.
487 LLVM_ABI void notifyMoveInstr(Instruction *I, const BBIterator &To);
488 /// Called by the callbacks when \p U's source is about to be set to \p NewSrc
489 LLVM_ABI void notifySetUse(const Use &U, Value *NewSrc);
490
491public:
492 /// This constructor also registers callbacks.
494 : Ctx(&Ctx), BatchAA(std::make_unique<BatchAAResults>(AA)) {
495 CreateInstrCB = Ctx.registerCreateInstrCallback(
496 [this](Instruction *I) { notifyCreateInstr(I); });
497 EraseInstrCB = Ctx.registerEraseInstrCallback(
498 [this](Instruction *I) { notifyEraseInstr(I); });
499 MoveInstrCB = Ctx.registerMoveInstrCallback(
500 [this](Instruction *I, const BBIterator &To) {
501 notifyMoveInstr(I, To);
502 });
503 SetUseCB = Ctx.registerSetUseCallback(
504 [this](const Use &U, Value *NewSrc) { notifySetUse(U, NewSrc); });
505 }
507 if (CreateInstrCB)
508 Ctx->unregisterCreateInstrCallback(*CreateInstrCB);
509 if (EraseInstrCB)
510 Ctx->unregisterEraseInstrCallback(*EraseInstrCB);
511 if (MoveInstrCB)
512 Ctx->unregisterMoveInstrCallback(*MoveInstrCB);
513 if (SetUseCB)
514 Ctx->unregisterSetUseCallback(*SetUseCB);
515 }
516
518 auto It = InstrToNodeMap.find(I);
519 return It != InstrToNodeMap.end() ? It->second.get() : nullptr;
520 }
521 /// Like getNode() but returns nullptr if \p I is nullptr.
523 if (I == nullptr)
524 return nullptr;
525 return getNode(I);
526 }
528 auto [It, NotInMap] = InstrToNodeMap.try_emplace(I);
529 if (NotInMap) {
531 It->second = std::make_unique<MemDGNode>(I);
532 else
533 It->second = std::make_unique<DGNode>(I);
534 }
535 return It->second.get();
536 }
537 /// Build/extend the dependency graph such that it includes \p Instrs. Returns
538 /// the range of instructions added to the DAG.
540 /// \Returns the range of instructions included in the DAG.
541 Interval<Instruction> getInterval() const { return DAGInterval; }
542 void clear() {
543 InstrToNodeMap.clear();
544 DAGInterval = {};
545 }
546#ifndef NDEBUG
547 /// \Returns true if the DAG's state is clear. Used in assertions.
548 bool empty() const {
549 bool IsEmpty = InstrToNodeMap.empty();
550 assert(IsEmpty == DAGInterval.empty() &&
551 "Interval and InstrToNodeMap out of sync!");
552 return IsEmpty;
553 }
554 void print(raw_ostream &OS) const;
555 LLVM_DUMP_METHOD void dump() const;
556#endif // NDEBUG
557};
558} // namespace llvm::sandboxir
559
560#endif // LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_DEPENDENCYGRAPH_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define LLVM_ABI
Definition Compiler.h:213
#define LLVM_TEMPLATE_ABI
Definition Compiler.h:214
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition Compiler.h:661
This file defines the DenseMap class.
#define I(x, y, z)
Definition MD5.cpp:57
std::pair< uint64_t, uint64_t > Interval
uint64_t IntrinsicInst * II
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
This class is a wrapper over an AAResults, and it is intended to be used only when there are no IR ch...
Represent a node in the directed graph.
Implements a dense probed hash-table based set.
Definition DenseSet.h:289
A range adaptor for a pair of iterators.
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
bool isUsedWithInAlloca() const
Return true if this alloca is used as an inalloca argument to a call.
A DependencyGraph Node that points to an Instruction and contains memory dependency edges.
static bool isMemDepCandidate(Instruction *I)
We consider I as a Memory Dependency Candidate instruction if it reads/write memory or if it has side...
virtual iterator preds_end(DependencyGraph &DAG)
static bool isMemIntrinsic(IntrinsicInst *I)
\Returns true if intrinsic I touches memory.
iterator preds_begin(DependencyGraph &DAG) const
DGNode(Instruction *I, DGNodeID ID)
unsigned getNumUnscheduledSuccs() const
\Returns the number of unscheduled successors.
void setSchedBundle(SchedBundle &SB)
bool scheduled() const
\Returns true if this node has been scheduled.
virtual succ_iterator succs_end(DependencyGraph &DAG)
bool validUnscheduledSuccs() const
bool ready() const
\Returns true if all dependent successors have been scheduled.
succ_iterator succs_end(DependencyGraph &DAG) const
iterator_range< iterator > preds(DependencyGraph &DAG) const
\Returns a range of DAG predecessors nodes.
iterator preds_end(DependencyGraph &DAG) const
SchedBundle * SB
The scheduler bundle that this node belongs to.
bool Scheduled
This is true if this node has been scheduled.
std::optional< unsigned > UnscheduledSuccs
The number of unscheduled successors.
static bool isMemDepNodeCandidate(Instruction *I)
\Returns true if I is a memory dependency candidate instruction.
SchedBundle * getSchedBundle() const
\Returns the scheduling bundle that this node belongs to, or nullptr.
iterator_range< succ_iterator > succs(DependencyGraph &DAG) const
\Returns a range of DAG successor nodes.
DGNodeID SubclassID
For isa/dyn_cast etc.
DGNode(const DGNode &Other)=delete
static bool isFenceLike(Instruction *I)
\Returns true if I is fence like. It excludes non-mem intrinsics.
Instruction * getInstruction() const
static bool isStackSaveOrRestoreIntrinsic(Instruction *I)
bool comesBefore(const DGNode *Other)
\Returns true if this is before Other in program order.
virtual succ_iterator succs_begin(DependencyGraph &DAG)
friend raw_ostream & operator<<(raw_ostream &OS, DGNode &N)
virtual iterator preds_begin(DependencyGraph &DAG)
succ_iterator succs_begin(DependencyGraph &DAG) const
Interval< Instruction > getInterval() const
\Returns the range of instructions included in the DAG.
bool empty() const
\Returns true if the DAG's state is clear. Used in assertions.
LLVM_DUMP_METHOD void dump() const
DGNode * getNode(Instruction *I) const
DependencyGraph(AAResults &AA, Context &Ctx)
This constructor also registers callbacks.
DGNode * getNodeOrNull(Instruction *I) const
Like getNode() but returns nullptr if I is nullptr.
void print(raw_ostream &OS) const
DGNode * getOrCreateNode(Instruction *I)
LLVM_ABI Interval< Instruction > extend(ArrayRef< Instruction * > Instrs)
Build/extend the dependency graph such that it includes Instrs.
A sandboxir::User with operands, opcode and linked with previous/next instructions in an instruction ...
Definition Instruction.h:43
Convenience builders for a MemDGNode interval.
static LLVM_ABI MemDGNode * getBotMemDGNode(const Interval< Instruction > &Intvl, const DependencyGraph &DAG)
Scans the instruction chain in Intvl bottom-up, returning the bottom-most MemDGNode,...
static Interval< MemDGNode > makeEmpty()
static LLVM_ABI MemDGNode * getTopMemDGNode(const Interval< Instruction > &Intvl, const DependencyGraph &DAG)
Scans the instruction chain in Intvl top-down, returning the top-most MemDGNode, or nullptr.
static LLVM_ABI Interval< MemDGNode > make(const Interval< Instruction > &Instrs, DependencyGraph &DAG)
Given Instrs it finds their closest mem nodes in the interval and returns the corresponding mem range...
A DependencyGraph Node for instructions that may read/write memory, or have some ordering constraints...
iterator preds_end(DependencyGraph &DAG) override
iterator preds_begin(DependencyGraph &DAG) override
bool hasMemPred(DGNode *N) const
\Returns true if there is a memory dependency N->this.
static bool classof(const DGNode *Other)
iterator_range< DenseSet< MemDGNode * >::const_iterator > memPreds() const
\Returns all memory dependency predecessors. Used by tests.
MemDGNode * getNextNode() const
\Returns the next Mem DGNode in instruction order.
iterator_range< DenseSet< MemDGNode * >::const_iterator > memSuccs() const
\Returns all memory dependency successors.
succ_iterator succs_begin(DependencyGraph &DAG) override
void removeMemPred(MemDGNode *PredN)
Removes the memory dependency PredN->this.
MemDGNode * getPrevNode() const
\Returns the previous Mem DGNode in instruction order.
void addMemPred(MemDGNode *PredN)
Adds the mem dependency edge PredN->this.
succ_iterator succs_end(DependencyGraph &DAG) override
Iterate over both def-use and mem dependencies.
bool operator!=(const PredIterator &Other) const
LLVM_ABI PredIterator & operator++()
std::input_iterator_tag iterator_category
The nodes that need to be scheduled back-to-back in a single scheduling cycle form a SchedBundle.
Definition Scheduler.h:108
Iterate over both def-use and mem dependencies.
LLVM_ABI SuccIterator & operator++()
bool operator!=(const SuccIterator &Other) const
std::input_iterator_tag iterator_category
Represents a Def-use/Use-def edge in SandboxIR.
Definition Use.h:33
OperandUseIterator op_iterator
Definition User.h:98
A SandboxIR Value has users. This is the base class.
Definition Value.h:72
mapped_iterator< sandboxir::UserUseIterator, UseToUser > user_iterator
Definition Value.h:239
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
Abstract Attribute helper functions.
Definition Attributor.h:165
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
DGNodeID
SubclassIDs for isa/dyn_cast etc.
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
Printable print(const GCNRegPressure &RP, const GCNSubtarget *ST=nullptr, unsigned DynamicVGPRBlockSize=0)
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
APInt operator*(APInt a, uint64_t RHS)
Definition APInt.h:2264
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
bool operator==(const AddressRangeValuePair &LHS, const AddressRangeValuePair &RHS)
@ Other
Any other memory.
Definition ModRef.h:68
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:874
#define N