HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Moduleghc-9.10.3GHC2021

GHC.Cmm.Switch

  • 2 types
  • 12 values
  • Packageghc-9.10.3
  • Exports14
  • LanguageGHC2021
  • LicenceBSD-3-Clause
  • SourceSwitch.hs
datadata SwitchTargets
#

A value of type SwitchTargets contains the alternatives for a CmmSwitch value, and knows whether the value is signed, the possible range, an optional default value and a map from values to jump labels.

Instances2Eq, Show

switchTargetsToTable creates a dense jump table, usable for code generation.

Also returns an offset to add to the value; the list is 0-based on the result of that addition.

The conversion from Integer to Int is a bit of a wart, as the actual scrutinee might be an unsigned word, but it just works, due to wrap-around arithmetic (as verified by the CmmSwitchTest test case).

The back end targets a technology that implements switch natively. (For example, LLVM or C.) Therefore it is not necessary for GHC to ccompile a Cmm Switch form into a decision tree with jump tables at the leaves.