Repository navigation
Scheduling 02 schedule dag
Relevant source files
The following files were used as context for generating this wiki page:
The node and edge types, and how each kind of edge is found. How the DAG is used is on MachineScheduler. The SelectionDAG has a different DAG (of SDNodes); see the SelectionDAG data structures page.
enum Kind {
Data, ///< Regular data dependence (aka true-dependence).
Anti, ///< A register anti-dependence (aka WAR).
Output, ///< A register output-dependence (aka WAW).
Order ///< Any other ordering dependency.
};Order edges have a sub-kind:
Barrier, ///< An unknown scheduling barrier.
MayAliasMem, ///< Nonvolatile load/Store instructions that may alias.
MustAliasMem, ///< Nonvolatile load/Store instructions that must alias.
Artificial, ///< Arbitrary strong DAG edge (no real dependence).
Weak, ///< Arbitrary weak DAG edge.
Cluster ///< Weak DAG edge linking a chain of clustered instrs.| Edge | Example | Latency |
|---|---|---|
| Data (RAW) |
%2 = LDRXui ... then MADDXrrr %2, ...
|
Producer's write latency (minus any ReadAdvance) |
| Anti (WAR) | read of $x0, then a later write of $x0
|
0 |
| Output (WAW) | two writes of the same register | usually 1 |
| Memory order | store then a load that may alias | 0 or 1 |
| Barrier | call, hasUnmodeledSideEffects, volatile access |
— |
| Weak / Cluster | added by mutations | may be violated |
Before allocation most values are virtual registers in SSA form, so Anti and Output edges come mostly from physical registers (arguments, return values, $sp). After allocation every register is physical, so post-RA DAGs have many more of them.
Sources: llvm/include/llvm/CodeGen/ScheduleDAG.h:55-77
buildSchedGraph (line 710) walks the region bottom to top, keeping maps from each register and each memory object to the instructions that use or define it:
| Function | Line | Adds |
|---|---|---|
addPhysRegDataDeps |
247 | Data edges for physical register uses (SDep(SU, SDep::Data, UseReg), line 286) |
addPhysRegDeps |
303 | Anti/Output edges for physical registers (line 319) |
addVRegDefDeps |
413 | Data edges from a virtual register def to its uses (463), Output edges (507) |
addVRegUseDeps |
533 | Records virtual register uses |
addChainDependencies |
683, 690 | Memory edges between possibly aliasing accesses |
addBarrierChain |
699 | Edges to a barrier instruction from everything pending |
For memory, each access is mapped to its underlying IR objects; two accesses that depend only on different identified objects need no edge. Spill and reload instructions are in their own NonAlias domain because they never alias IR values.
Sources: llvm/lib/CodeGen/ScheduleDAGInstrs.cpp:247-319, llvm/lib/CodeGen/ScheduleDAGInstrs.cpp:413-533, llvm/lib/CodeGen/ScheduleDAGInstrs.cpp:683-759
The dot-product region from the walkthroughs, before the pre-RA scheduler:
%2:gpr64 = LDRXui %0, 0 :: (load (s64) from %ir.a)
%3:gpr64 = LDRXui %1, 0 :: (load (s64) from %ir.b)
%5:gpr64 = LDRXui %0, 1 :: (load (s64) from %ir.pa1)
%6:gpr64 = LDRXui %1, 1 :: (load (s64) from %ir.pb1)
%7:gpr64 = MADDXrrr %5, %6, $xzr
%8:gpr64 = LDRXui %0, 2 :: (load (s64) from %ir.pa2)
%9:gpr64 = LDRXui %1, 2 :: (load (s64) from %ir.pb2)
%11:gpr64 = MADDXrrr %2, %3, %7
%12:gpr64 = MADDXrrr %8, %9, %11
flowchart TD
L2["%2 LDR a[0]"] --> M11["%11 MADD"]
L3["%3 LDR b[0]"] --> M11
L5["%5 LDR a[1]"] --> M7["%7 MUL"]
L6["%6 LDR b[1]"] --> M7
M7 --> M11
L8["%8 LDR a[2]"] --> M12["%12 MADD"]
L9["%9 LDR b[2]"] --> M12
M11 --> M12
All edges are Data edges. The six loads only read memory, so there are no memory edges between them and the scheduler may put them in any order.
After the graph is built, target DAG mutations may add edges before scheduling starts. AArch64 adds load and store clustering (Cluster edges between memory operations on the same base, so they end up adjacent and can be paired) and, on CPUs that support it, macro fusion (instruction pairs the hardware fuses). See Wiring.
- Computer Architecture Overview
- Fundamentals: CPU, Memory and Instructions
- Pipelining
- Branches and Remedies
- Instruction-Level Parallelism
- Memory and Ordering
- Caches and Coherence
- Multicore
- Multithreading in Hardware
- SIMD and GPUs
- Glossary and Summary
- Hexagon Overview and Processor Properties
- ISA Fundamentals: Packets, Slots and Threads
- Registers
- Instruction Encoding and Mnemonics
- Data, Memory and Control Instructions
- Floating Point, HVX and Alignment
- Caches, MMU and Glossary
- Operating Systems Overview
- Processes
- Threads
- CPU Scheduling
- Synchronization
- Deadlock
- Memory Management
- Virtual Memory
- Files, Storage and I/O
- Kernel and System Calls
- Interview Q&A and Glossary
- C++ for LLVM Development: Overview
- C++ Basics
- Classes and RAII
- Ownership and Move Semantics
- Templates and Lambdas
- LLVM Data Structures (ADT)
- LLVM-Style RTTI: isa, cast, dyn_cast
- Errors, Output and Assertions
- Iterators and Ranges
- Building, Debugging and Exercises
- LLVM IR Overview
- Structure: Modules, Functions, Blocks and Values
- Type System
- Arithmetic, Bitwise and Cast Instructions
- Compare and Select
- Memory: alloca, load, store and getelementptr
- Control Flow: br, switch, ret and call
- SSA and Phi
- Control Flow Graph and Loops
- Dominance, Dominator Tree and Dominance Frontier
- Data-flow Analysis
- Writing an IR Pass
- Common Passes
- Exercises, Tooling and Glossary
- SelectionDAG Overview
- Pipeline, Phases and Traversal Orders
- Core Data Structures
- DAG Construction
- DAG Combiner
- Legalization
- Type Legalization
- Operation and Vector Legalization
- Instruction Selection
- TableGen Pattern Language
- Matcher Interpreter and Folding
- AArch64 Instruction Selection
- Scheduling and MIR Emission
- PHI Node Resolution
- AArch64 Walkthroughs
- Arithmetic and Data Movement
- Memory Instructions
- Control Flow and Calls
- End-to-End Example
- Tooling, Debugging and Extending
- Selector Comparison and Glossary
- Assignments: Build the Toy Backend
- Stage 1: Build Setup
- Stage 2: Target Registration
- Stage 3: TableGen Skeleton
- Stage 4: MC Layer for Assembly Output
- Stage 5: TargetMachine and Subtarget
- Stage 6: TargetLowering, Arguments and Returns
- Stage 7: Instruction Selection and the First Function
- Stage 8: Registers, Copies and Spills
- Stage 9: Frame Lowering
- Stage 10: Memory, Globals and Control Flow
- Stage 11: Calls
- Stage 12: Scheduling Model
- Stage 13: Object Files
- Stage 14: Capstone, a Complete Toy Backend
- Target Bring-up Overview
- Directory Layout, CMake and Registration
- The Target .td File
- TargetMachine and Subtarget
- TargetLowering Setup
- Calling Conventions
- Instructions and Instruction Selection
- Registers and Allocation Hooks
- Frame Lowering
- AsmPrinter and the MC Layer
- Scheduling
- A Minimal Toy Target
- Bring-up Checklist and AArch64 File Map
- Tooling and Glossary
- Calling Conventions Overview
- The CallingConv.td Language
- CCState and CCValAssign
- LowerFormalArguments
- LowerCall
- LowerReturn and CanLowerReturn
- Varargs, byval, sret and swifterror
- Tail Calls and Sibling Calls
- Custom Backend Guide and Checklist
- AArch64 Walkthroughs
- Tooling and Glossary
- Frame Lowering Overview
- MachineFrameInfo
- TargetFrameLowering Hooks
- The PEI Pass
- Callee-Saved Registers and Stack Layout
- Frame Index Elimination and the Register Scavenger
- Shrink Wrapping
- CFI and Unwind Information
- Custom Backend Guide and Checklist
- AArch64 Walkthroughs
- Tooling and Glossary
- MC Layer Overview
- Core Data Structures
- Streamers
- Assembler and Layout
- Fixups and Relocations
- Writing an MC Layer for a Custom Backend
- MCAsmInfo and the Instruction Printer
- Code Emitter
- AsmBackend and Object Writer
- Assembly Parser and Disassembler
- Bring-up Checklist and Common Failures
- Tooling and Glossary
- Register Allocation Overview
- The Register Allocation Pipeline
- Registers, Virtual Registers and Register Classes
- Liveness: Slot Indexes and Live Intervals
- Preparing Code for Allocation
- PHI Elimination and Two-Address Lowering
- Register Coalescer
- Allocation Framework
- The Register Allocators
- Fast Register Allocator
- Basic Register Allocator
- Greedy Register Allocator
- PBQP Register Allocator
- Spilling and Splitting
- Spill Weights and Copy Hints
- The Inline Spiller
- Live Range Splitting
- Rewriting and Post-RA Passes
- Writing Register Allocation Support for a Custom Backend
- Register Definitions in TableGen
- TargetRegisterInfo Hooks
- TargetInstrInfo Hooks
- Pass Pipeline Hooks
- Bring-up Checklist and Common Failures
- AArch64 Walkthroughs
- Tooling and Debugging
- Glossary and Where Do I Look