Repository navigation
SelectionDAG 11 comparison glossary
Relevant source files
The following files were used as context for generating this wiki page:
This page compares SelectionDAG with FastISel and GlobalISel, summarises the traversal orders, and defines the vocabulary used across the wiki.
flowchart LR
IR["LLVM IR"] --> SD["SelectionDAG<br/>DAG per block"]
IR --> FI["FastISel<br/>direct, backward in block"]
IR --> GI["GlobalISel<br/>IRTranslator to generic MIR"]
FI -.->|falls back per instruction| SD
GI -.->|falls back per function| SD
SD --> MIR["Selected MIR"]
FI --> MIR
GI --> MIR
| SelectionDAG | FastISel | GlobalISel | |
|---|---|---|---|
| Default on AArch64 |
-O1 and above |
Exists (AArch64FastISel) but only used on request |
-O0 (controlled by -aarch64-enable-global-isel-at-O); falls back to SelectionDAG per function |
| Intermediate form | A DAG of SDNodes per block |
None: emits MachineInstrs directly |
Generic MIR (G_ADD, G_LOAD, with low-level types such as s32, <4 x s32>) |
| Scope | One block | One block, walked backward from the terminator | Whole function |
| Optimisation |
DAGCombiner, up to four runs |
None | Rule-based combiners before and after legalization, written in TableGen (GICombineRule) |
| Legalization | Type legalizer, then operation legalizer (+ vector legalizer) | None: gives up on anything it cannot select | One Legalizer pass driven by per-opcode LegalizerInfo rules |
| Instruction choice | Generated matcher from TableGen patterns | Hand-written plus generated fast selectors for common cases | Generated from the same Pat records and ComplexPatterns (GIComplexPatternEquiv, seen as gi_ro_Xindexed32 in AArch64InstrFormats.td) |
| Register class or bank | Picked during selection from the instruction's operand constraints | Same | A separate RegBankSelect pass (general vs FP/SIMD), then instruction selection |
| PHIs | Machine PHIs created ahead of time; operands added per block (PHI Node Resolution) | Shares the SelectionDAG driver and its PHI machinery |
IRTranslator creates G_PHI directly; no export step is needed because the whole function is visible |
| Failure mode | A Cannot select fatal error |
Falls back to SelectionDAG for the rest of the block | Falls back to SelectionDAG for the whole function ("Instruction selection used fallback path") |
| Strength | Best code quality, the most mature target coverage | Very fast compile at -O0
|
Faster than SelectionDAG, good cross-block optimisation, still maturing |
The llc used for the examples confirmed two of these directly. At -O0, -global-isel-abort=1 produced no error for the example functions, so GlobalISel selected them. At -O2, the pass list printed by -debug-pass=Structure contains the GlobalISel passes, but the IRTranslator immediately marks the function as failed and the aarch64-isel pass (the SelectionDAG selector) does the work; -global-isel-abort=2 reports "Instruction selection used fallback path". FastISel iterates each block backward from the terminator, as SelectAllBasicBlocks shows (for (; BI != Begin; --BI)).
Sources: llvm/lib/Target/AArch64/AArch64TargetMachine.cpp:404-418, llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:1656-1971, llvm/lib/Target/AArch64/AArch64InstrFormats.td:3927-3949
| Step | Visit order | In one sentence |
|---|---|---|
| Block order | Reverse post-order of the CFG | Predecessors are selected before successors where the CFG allows |
| Build DAG | IR instruction order inside the block | One visit per IR instruction, forward |
| DAGCombiner | Worklist, last-in-first-out, seeded in AllNodes order |
Starts at the root, then descends into operands; every change re-queues the changed node's users |
| Type legalizer | Operands before users | A node is processed once all its operands are |
| Vector legalizer | Operands before users (topological order) | One sweep |
| Operation legalizer | Users before operands, sweeps repeated until nothing new is legalized | Reaches a fixed point because legalization creates new nodes |
| Instruction selection | Root first, single sweep | Users first, so a pattern can absorb its operands |
| Scheduling | Bottom-up list scheduling from the exit node, then reversed | Source-order priority on AArch64 |
| Emission | The scheduled sequence, forward | One MachineInstr per machine node |
| Term | Meaning |
|---|---|
| SDNode / SDValue | A DAG node, and one of its results (node pointer plus result number) |
| MVT / EVT | Simple and extended value types (i32, v4i32; i7, i128) |
| Chain |
MVT::Other edge that orders side effects; starts at EntryToken
|
| Glue |
MVT::Glue edge that forces two nodes to be adjacent |
| ISD node | Target-independent opcode in the ISD:: namespace |
| Target node | Opcode in the AArch64ISD:: namespace, still a DAG node |
| Machine node | A node whose opcode is an instruction (AArch64::ADDWrr), created by selection |
| Legalization | Rewriting the DAG so every type and operation is supported by the target |
| Promote / Expand / Custom / LibCall / Legal | The five actions a target can register for an operation |
| LowerOperation / ReplaceNodeResults | Target hooks called for Custom operations (legal result types and illegal result types respectively) |
| DAGCombine | The DAG peephole optimiser; the target hook is PerformDAGCombine
|
| PatFrag | A named TableGen sub-pattern, often with a C++ predicate |
| ComplexPattern | A pattern operand matched by a C++ function (addressing modes, shifted operands) |
| SDNodeXForm | A C++ transformation applied to a matched constant before it is used |
| AddedComplexity | Manual priority bonus for a pattern |
| Matcher table | The generated bytecode that SelectCodeCommon interprets |
| Fold | A pattern absorbing an operand node (needs one use and legality) |
| SUnit | A scheduling unit: a machine node or a glued group of them |
| Export register | A virtual register used to carry an IR value across blocks |
| PHINodesToUpdate | List of (machine PHI, vreg) pairs waiting for the block to be emitted |
| MIR | Machine IR: MachineInstrs in a MachineFunction, with virtual registers before allocation |
| NZCV | AArch64 condition-flags register, written by SUBS, ADDS, ANDS, read by CSEL and Bcc
|
| Question | Look at |
|---|---|
| Why did my IR instruction become a libcall or a long sequence? |
setOperationAction(...) for that opcode and type in AArch64ISelLowering.cpp (Operation and Vector Legalization) |
| Why did this type change before selection? |
addRegisterClass, getTypeAction (Type Legalization) |
| Which AArch64 instruction does a node become? | The patterns in AArch64InstrInfo.td and AArch64InstrFormats.td, or a tryXxx in AArch64ISelDAGToDAG.cpp (Instruction Selection) |
| Why was an addressing mode not folded? | The ComplexPattern function (SelectAddrModeXRO and friends) and the one-use rule (Matcher Interpreter and Folding) |
Why is a madd or ldp missing right after ISel? |
They are formed after selection: MachineCombiner and the load/store optimiser |
Why do I see a COPY for a value that never leaves the block? |
Cross-block exports and PHI copies (PHI Node Resolution) |
Cannot select: tN: ... |
A node with no pattern and no custom lowering; check legalization actions first |
| A fold fires too early or too late | Its CombineLevel guard, isBeforeLegalizeOps() and friends (DAG Combiner) |
- 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