LLVM 24.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
43#ifndef NDEBUG
44StringLiteral schedDirectionToStr(SchedDirection Dir);
45#endif
46
47/// SubclassIDs for isa/dyn_cast etc.
48enum class DGNodeID {
51};
52
53class DGNode;
54class MemDGNode;
55class DependencyGraph;
56
57// Defined in Transforms/Vectorize/SandboxVectorizer/Interval.cpp
58extern template class LLVM_TEMPLATE_ABI Interval<MemDGNode>;
59
60/// Iterate over both def-use and mem dependencies.
61class PredIterator {
65 DGNode *N = nullptr;
66 DependencyGraph *DAG = nullptr;
67
68 PredIterator(const User::op_iterator &OpIt, const User::op_iterator &OpItE,
70 DependencyGraph &DAG)
71 : OpIt(OpIt), OpItE(OpItE), MemIt(MemIt), N(N), DAG(&DAG) {}
72 PredIterator(const User::op_iterator &OpIt, const User::op_iterator &OpItE,
73 DGNode *N, DependencyGraph &DAG)
74 : OpIt(OpIt), OpItE(OpItE), N(N), DAG(&DAG) {}
75 friend class DGNode; // For constructor
76 friend class MemDGNode; // For constructor
77
78 /// Skip iterators that don't point instructions or are outside \p DAG,
79 /// starting from \p OpIt and ending before \p OpItE.n
80 LLVM_ABI static User::op_iterator skipBadIt(User::op_iterator OpIt,
82 const DependencyGraph &DAG);
83
84public:
85 using difference_type = std::ptrdiff_t;
86 using value_type = DGNode *;
89 using iterator_category = std::input_iterator_tag;
91 LLVM_ABI PredIterator &operator++();
92 PredIterator operator++(int) {
93 auto Copy = *this;
94 ++(*this);
95 return Copy;
96 }
97 LLVM_ABI bool operator==(const PredIterator &Other) const;
98 bool operator!=(const PredIterator &Other) const { return !(*this == Other); }
99};
100
101/// Iterate over both def-use and mem dependencies.
102class SuccIterator {
103 User::user_iterator UserIt;
104 User::user_iterator UserItE;
106 DGNode *N = nullptr;
107 DependencyGraph *DAG = nullptr;
108
109 SuccIterator(const Value::user_iterator &UserIt,
110 const Value::user_iterator &UserItE,
112 DependencyGraph &DAG)
113 : UserIt(UserIt), UserItE(UserItE), MemIt(MemIt), N(N), DAG(&DAG) {}
114 SuccIterator(const User::user_iterator &UserIt,
115 const User::user_iterator &UserItE, DGNode *N,
116 DependencyGraph &DAG)
117 : UserIt(UserIt), UserItE(UserItE), N(N), DAG(&DAG) {}
118 friend class DGNode; // For constructor
119 friend class MemDGNode; // For constructor
120
121 /// Skip iterators that don't point to instructions or are outside \p DAG,
122 /// starting from \p OpIt and ending before \p OpItE.
124 skipOutOfScope(User::user_iterator UserIt, User::user_iterator UserItE,
125 const DependencyGraph &DAG);
126
127public:
128 using difference_type = std::ptrdiff_t;
132 using iterator_category = std::input_iterator_tag;
134 LLVM_ABI SuccIterator &operator++();
135 SuccIterator operator++(int) {
136 auto Copy = *this;
137 ++(*this);
138 return Copy;
139 }
140 LLVM_ABI bool operator==(const SuccIterator &Other) const;
141 bool operator!=(const SuccIterator &Other) const { return !(*this == Other); }
142};
143
144/// A DependencyGraph Node that points to an Instruction and contains memory
145/// dependency edges.
147protected:
149 // TODO: Use a PointerIntPair for SubclassID and I.
150 /// For isa/dyn_cast etc.
152 /// The number of unscheduled successors (predecessors) depending on the
153 /// scheduling direction. Optional represents whether the value is
154 /// meaningless, e.g., after a node gets scheduled.
155 std::optional<unsigned> UnscheduledDeps = 0;
156 /// This is true if this node has been scheduled.
157 bool Scheduled = false;
158 /// The scheduler bundle that this node belongs to.
159 SchedBundle *SB = nullptr;
160
162 void clearSchedBundle() { this->SB = nullptr; }
163 friend class SchedBundle; // For setSchedBundle(), clearSchedBundle().
164
166 friend class MemDGNode; // For constructor.
167 friend class DependencyGraph; // For UnscheduledSuccs
168
169public:
171 assert(!isMemDepNodeCandidate(I) && "Expected Non-Mem instruction, ");
172 }
173 DGNode(const DGNode &Other) = delete;
174 virtual ~DGNode();
175 /// \Returns the number of unscheduled successors.
176 unsigned getNumUnscheduledDeps() const {
177 assert((bool)UnscheduledDeps && "Invalid UnscheduledDeps!");
178 return *UnscheduledDeps;
179 }
180#ifndef NDEBUG
181 /// \returns true if unscheduled successors(predecessors) contains valid data
182 /// (for testing).
183 bool validUnscheduledDeps() const { return (bool)UnscheduledDeps; }
184#endif
185 // TODO: Make this private?
187 assert(*UnscheduledDeps > 0 && "Counting error!");
189 }
191
193 UnscheduledDeps = 0;
194 Scheduled = false;
195 }
196 /// \Returns true if all dependent successors (or predecessors during top-down
197 /// scheduling) have been scheduled.
198 bool ready() const { return UnscheduledDeps == 0; }
199 /// \Returns true if this node has been scheduled.
200 bool scheduled() const { return Scheduled; }
202 Scheduled = true;
203 // UnscheduledDeps is meaningless from this point on, so prohibit its use.
204 UnscheduledDeps = std::nullopt;
205 }
206 /// \Returns the scheduling bundle that this node belongs to, or nullptr.
207 SchedBundle *getSchedBundle() const { return SB; }
208 /// \Returns true if this is before \p Other in program order.
209 bool comesBefore(const DGNode *Other) { return I->comesBefore(Other->I); }
212 return PredIterator(
213 PredIterator::skipBadIt(I->op_begin(), I->op_end(), DAG), I->op_end(),
214 this, DAG);
215 }
217 return PredIterator(I->op_end(), I->op_end(), this, DAG);
218 }
220 return const_cast<DGNode *>(this)->preds_begin(DAG);
221 }
223 return const_cast<DGNode *>(this)->preds_end(DAG);
224 }
225 /// \Returns a range of DAG predecessors nodes. If this is a MemDGNode then
226 /// this will also include the memory dependency predecessors.
227 /// Please note that this can include the same node more than once, if for
228 /// example it's both a use-def predecessor and a mem dep predecessor.
232
235 return SuccIterator(
236 SuccIterator::skipOutOfScope(I->user_begin(), I->user_end(), DAG),
237 I->user_end(), this, DAG);
238 }
240 return SuccIterator(I->user_end(), I->user_end(), this, DAG);
241 }
243 return const_cast<DGNode *>(this)->succs_begin(DAG);
244 }
246 return const_cast<DGNode *>(this)->succs_end(DAG);
247 }
248 /// \Returns a range of DAG successor nodes. If this is a MemDGNode then
249 /// this will also include the memory dependency successors.
250 /// Please note that this can include the same node more than once, if for
251 /// example it's both a use-def predecessor and a mem dep successor.
255
257 if (auto *II = dyn_cast<IntrinsicInst>(I)) {
258 auto IID = II->getIntrinsicID();
259 return IID == Intrinsic::stackrestore || IID == Intrinsic::stacksave;
260 }
261 return false;
262 }
263
264 /// \Returns true if intrinsic \p I touches memory. This is used by the
265 /// dependency graph.
267 auto IID = I->getIntrinsicID();
268 return IID != Intrinsic::sideeffect && IID != Intrinsic::pseudoprobe;
269 }
270
271 /// We consider \p I as a Memory Dependency Candidate instruction if it
272 /// reads/write memory or if it has side-effects. This is used by the
273 /// dependency graph.
276 return I->mayReadOrWriteMemory() &&
278 }
279
280 /// \Returns true if \p I is fence like. It excludes non-mem intrinsics.
281 static bool isFenceLike(Instruction *I) {
283 return I->isFenceLike() &&
285 }
286
287 /// \Returns true if \p I is a memory dependency candidate instruction.
289 AllocaInst *Alloca;
290 return isMemDepCandidate(I) ||
291 ((Alloca = dyn_cast<AllocaInst>(I)) &&
292 Alloca->isUsedWithInAlloca()) ||
294 }
295
296 Instruction *getInstruction() const { return I; }
297
298#ifndef NDEBUG
299 virtual void print(raw_ostream &OS, bool PrintDeps = true) const;
301 N.print(OS);
302 return OS;
303 }
304 LLVM_DUMP_METHOD void dump() const;
305#endif // NDEBUG
306};
307
308/// A DependencyGraph Node for instructions that may read/write memory, or have
309/// some ordering constraints, like with stacksave/stackrestore and
310/// alloca/inalloca.
311class MemDGNode final : public DGNode {
312 MemDGNode *PrevMemN = nullptr;
313 MemDGNode *NextMemN = nullptr;
314 /// Memory predecessors.
315 DenseSet<MemDGNode *> MemPreds;
316 /// Memory successors.
317 DenseSet<MemDGNode *> MemSuccs;
318 friend class PredIterator; // For MemPreds.
319 friend class SuccIterator; // For MemSuccs.
320 /// Creates both edges: this<->N.
321 void setNextNode(MemDGNode *N) {
322 assert(N != this && "About to point to self!");
323 NextMemN = N;
324 if (NextMemN != nullptr)
325 NextMemN->PrevMemN = this;
326 }
327 /// Creates both edges: N<->this.
328 void setPrevNode(MemDGNode *N) {
329 assert(N != this && "About to point to self!");
330 PrevMemN = N;
331 if (PrevMemN != nullptr)
332 PrevMemN->NextMemN = this;
333 }
334 friend class DependencyGraph; // For setNextNode(), setPrevNode().
335 void detachFromChain() {
336 if (PrevMemN != nullptr)
337 PrevMemN->NextMemN = NextMemN;
338 if (NextMemN != nullptr)
339 NextMemN->PrevMemN = PrevMemN;
340 PrevMemN = nullptr;
341 NextMemN = nullptr;
342 }
343
344public:
346 assert(isMemDepNodeCandidate(I) && "Expected Mem instruction!");
347 }
348 static bool classof(const DGNode *Other) {
349 return Other->SubclassID == DGNodeID::MemDGNode;
350 }
352 auto OpEndIt = I->op_end();
353 return PredIterator(PredIterator::skipBadIt(I->op_begin(), OpEndIt, DAG),
354 OpEndIt, MemPreds.begin(), this, DAG);
355 }
357 return PredIterator(I->op_end(), I->op_end(), MemPreds.end(), this, DAG);
358 }
360 auto UserEndIt = I->user_end();
361 return SuccIterator(
362 SuccIterator::skipOutOfScope(I->user_begin(), UserEndIt, DAG),
363 UserEndIt, MemSuccs.begin(), this, DAG);
364 }
366 return SuccIterator(I->user_end(), I->user_end(), MemSuccs.end(), this,
367 DAG);
368 }
369 /// \Returns the previous Mem DGNode in instruction order.
370 MemDGNode *getPrevNode() const { return PrevMemN; }
371 /// \Returns the next Mem DGNode in instruction order.
372 MemDGNode *getNextNode() const { return NextMemN; }
373
374 // TODO: addMemPred() and removeMemPred() should be private.
375 /// Adds the mem dependency edge PredN->this. This also increments the
376 /// UnscheduledDeps counter of the predecessor if this node has not been
377 /// scheduled.
379 [[maybe_unused]] auto Inserted = MemPreds.insert(PredN).second;
380 assert(Inserted && "PredN already exists!");
381 assert(PredN != this && "Trying to add a dependency to self!");
382 PredN->MemSuccs.insert(this);
383 if (!Scheduled) {
384 if (!PredN->Scheduled) {
385 if (Dir == SchedDirection::BottomUp)
386 PredN->incrUnscheduledDeps();
387 else
389 }
390 }
391 }
392 /// Removes the memory dependency PredN->this. This also updates the
393 /// UnscheduledSuccs counter of PredN if this node has not been scheduled.
395 MemPreds.erase(PredN);
396 PredN->MemSuccs.erase(this);
397 if (!Scheduled) {
398 if (!PredN->Scheduled) {
399 if (Dir == SchedDirection::BottomUp)
400 PredN->decrUnscheduledDeps();
401 else
403 }
404 }
405 }
406
407 /// \Returns true if there is a memory dependency N->this.
408 bool hasMemPred(DGNode *N) const {
409 if (auto *MN = dyn_cast<MemDGNode>(N))
410 return MemPreds.count(MN);
411 return false;
412 }
413 /// \Returns all memory dependency predecessors. Used by tests.
415 return make_range(MemPreds.begin(), MemPreds.end());
416 }
417 /// \Returns all memory dependency successors.
419 return make_range(MemSuccs.begin(), MemSuccs.end());
420 }
421#ifndef NDEBUG
422 void print(raw_ostream &OS, bool PrintDeps = true) const override;
423#endif // NDEBUG
424};
425
426/// Convenience builders for a MemDGNode interval.
428public:
429 /// Scans the instruction chain in \p Intvl top-down, returning the top-most
430 /// MemDGNode, or nullptr.
432 const DependencyGraph &DAG);
433 /// Scans the instruction chain in \p Intvl bottom-up, returning the
434 /// bottom-most MemDGNode, or nullptr.
436 const DependencyGraph &DAG);
437 /// Given \p Instrs it finds their closest mem nodes in the interval and
438 /// returns the corresponding mem range. Note: BotN (or its neighboring mem
439 /// node) is included in the range.
441 DependencyGraph &DAG);
442 static Interval<MemDGNode> makeEmpty() { return {}; }
443};
444
446private:
448 /// The DAG spans across all instructions in this interval.
449 Interval<Instruction> DAGInterval;
450
451 SchedDirection Dir;
452
453 Context *Ctx = nullptr;
454 std::optional<Context::CallbackID> CreateInstrCB;
455 std::optional<Context::CallbackID> EraseInstrCB;
456 std::optional<Context::CallbackID> MoveInstrCB;
457 std::optional<Context::CallbackID> SetUseCB;
458
459 std::unique_ptr<BatchAAResults> BatchAA;
460
461 enum class DependencyType {
462 ReadAfterWrite, ///> Memory dependency write -> read
463 WriteAfterWrite, ///> Memory dependency write -> write
464 WriteAfterRead, ///> Memory dependency read -> write
465 Control, ///> Control-related dependency, like with PHI/Terminator
466 Other, ///> Currently used for stack related instrs
467 None, ///> No memory/other dependency
468 };
469 /// \Returns the dependency type depending on whether instructions may
470 /// read/write memory or whether they are some specific opcode-related
471 /// restrictions.
472 /// Note: It does not check whether a memory dependency is actually correct,
473 /// as it won't call AA. Therefore it returns the worst-case dep type.
474 static DependencyType getRoughDepType(Instruction *FromI, Instruction *ToI);
475
476 // TODO: Implement AABudget.
477 /// \Returns true if there is a memory/other dependency \p SrcI->DstI.
478 bool alias(Instruction *SrcI, Instruction *DstI, DependencyType DepType);
479
480 bool hasDep(sandboxir::Instruction *SrcI, sandboxir::Instruction *DstI);
481
482 /// Go through all mem nodes in \p SrcScanRange and try to add dependencies to
483 /// \p DstN.
484 void scanAndAddDeps(MemDGNode &DstN, const Interval<MemDGNode> &SrcScanRange);
485
486 /// Sets the UnscheduledSuccs of all DGNodes in \p NewInterval based on
487 /// def-use edges.
488 void setDefUseUnscheduledSuccs(const Interval<Instruction> &NewInterval);
489
490 /// Create DAG nodes for instrs in \p NewInterval and update the MemNode
491 /// chain.
492 void createNewNodes(const Interval<Instruction> &NewInterval);
493
494 /// Helper for `notify*Instr()`. \Returns the first MemDGNode that comes
495 /// before \p N, skipping \p SkipN, including or excluding \p N based on
496 /// \p IncludingN, or nullptr if not found.
497 MemDGNode *getMemDGNodeBefore(DGNode *N, bool IncludingN,
498 MemDGNode *SkipN = nullptr) const;
499 /// Helper for `notifyMoveInstr()`. \Returns the first MemDGNode that comes
500 /// after \p N, skipping \p SkipN, including or excluding \p N based on \p
501 /// IncludingN, or nullptr if not found.
502 MemDGNode *getMemDGNodeAfter(DGNode *N, bool IncludingN,
503 MemDGNode *SkipN = nullptr) const;
504
505 /// Called by the callbacks when a new instruction \p I has been created.
506 LLVM_ABI void notifyCreateInstr(Instruction *I);
507 /// Called by the callbacks when instruction \p I is about to get
508 /// deleted.
509 LLVM_ABI void notifyEraseInstr(Instruction *I);
510 /// Called by the callbacks when instruction \p I is about to be moved to
511 /// \p To.
512 LLVM_ABI void notifyMoveInstr(Instruction *I, const BBIterator &To);
513 /// Called by the callbacks when \p U's source is about to be set to \p NewSrc
514 LLVM_ABI void notifySetUse(const Use &U, Value *NewSrc);
515
516public:
517 /// This constructor also registers callbacks.
519 : Dir(Dir), Ctx(&Ctx), BatchAA(std::make_unique<BatchAAResults>(AA)) {
520 CreateInstrCB = Ctx.registerCreateInstrCallback(
521 [this](Instruction *I) { notifyCreateInstr(I); });
522 EraseInstrCB = Ctx.registerEraseInstrCallback(
523 [this](Instruction *I) { notifyEraseInstr(I); });
524 MoveInstrCB = Ctx.registerMoveInstrCallback(
525 [this](Instruction *I, const BBIterator &To) {
526 notifyMoveInstr(I, To);
527 });
528 SetUseCB = Ctx.registerSetUseCallback(
529 [this](const Use &U, Value *NewSrc) { notifySetUse(U, NewSrc); });
530 }
532 if (CreateInstrCB)
533 Ctx->unregisterCreateInstrCallback(*CreateInstrCB);
534 if (EraseInstrCB)
535 Ctx->unregisterEraseInstrCallback(*EraseInstrCB);
536 if (MoveInstrCB)
537 Ctx->unregisterMoveInstrCallback(*MoveInstrCB);
538 if (SetUseCB)
539 Ctx->unregisterSetUseCallback(*SetUseCB);
540 }
541
543 auto It = InstrToNodeMap.find(I);
544 return It != InstrToNodeMap.end() ? It->second.get() : nullptr;
545 }
546 /// Like getNode() but returns nullptr if \p I is nullptr.
548 if (I == nullptr)
549 return nullptr;
550 return getNode(I);
551 }
553 auto [It, NotInMap] = InstrToNodeMap.try_emplace(I);
554 if (NotInMap) {
556 It->second = std::make_unique<MemDGNode>(I);
557 else
558 It->second = std::make_unique<DGNode>(I);
559 }
560 return It->second.get();
561 }
562 /// Build/extend the dependency graph such that it includes \p Instrs. Returns
563 /// the range of instructions added to the DAG.
565 /// \Returns the range of instructions included in the DAG.
566 Interval<Instruction> getInterval() const { return DAGInterval; }
567 void clear() {
568 InstrToNodeMap.clear();
569 DAGInterval = {};
570 }
571#ifndef NDEBUG
572 /// \Returns true if the DAG's state is clear. Used in assertions.
573 bool empty() const {
574 bool IsEmpty = InstrToNodeMap.empty();
575 assert(IsEmpty == DAGInterval.empty() &&
576 "Interval and InstrToNodeMap out of sync!");
577 return IsEmpty;
578 }
579 void print(raw_ostream &OS) const;
580 LLVM_DUMP_METHOD void dump() const;
581#endif // NDEBUG
582};
583} // namespace llvm::sandboxir
584
585#endif // LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_DEPENDENCYGRAPH_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define LLVM_ABI
Definition Compiler.h:215
#define LLVM_TEMPLATE_ABI
Definition Compiler.h:216
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition Compiler.h:678
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:281
A wrapper around a string literal that serves as a proxy for constructing global tables of StringRefs...
Definition StringRef.h:888
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.
bool validUnscheduledDeps() const
iterator preds_begin(DependencyGraph &DAG) const
std::optional< unsigned > UnscheduledDeps
The number of unscheduled successors (predecessors) depending on the scheduling direction.
DGNode(Instruction *I, DGNodeID ID)
unsigned getNumUnscheduledDeps() 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 ready() const
\Returns true if all dependent successors (or predecessors during top-down scheduling) have been sche...
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.
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
DGNode * getNodeOrNull(Instruction *I) const
Like getNode() but returns nullptr if I is nullptr.
void print(raw_ostream &OS) const
DependencyGraph(SchedDirection Dir, AAResults &AA, Context &Ctx)
This constructor also registers callbacks.
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)
void addMemPred(MemDGNode *PredN, SchedDirection Dir)
Adds the mem dependency edge PredN->this.
void removeMemPred(MemDGNode *PredN, SchedDirection Dir)
Removes the memory dependency PredN->this.
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
MemDGNode * getPrevNode() const
\Returns the previous Mem DGNode in instruction order.
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:115
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:43
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
StringLiteral schedDirectionToStr(SchedDirection Dir)
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:2262
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:878
#define N