Targets
targets
¶
This file provides tools to describe toolchain targets.
Based on:
[1]: `RISC-V ABIs Specification, Document Version 1.0', Editors Kito Cheng and Jessica Clarke, RISC-V International, November 2022. https://github.com/riscv-non-isa/riscv-elf-psabi-doc/releases/tag/v1.0 [2]: “The RISC-V Instruction Set Manual, Volume I: User-Level ISA, Document Version 20191213”, Editors Andrew Waterman and Krste Asanovi´c, RISC-V Foundation, December 2019. https://github.com/riscv/riscv-isa-manual/releases/download/Ratified-IMAFDQC/riscv-spec-20191213.pdf
ABISpec
dataclass
¶
This defines the ABI.
Largely based on chapter 2 of [1]
Source code in xdsl/backend/riscv/targets.py
int_width: int
instance-attribute
¶
long_width: int
instance-attribute
¶
pointer_width: int
instance-attribute
¶
abi_flen: Literal[0, 32, 64, 128]
instance-attribute
¶
ABI_FLEN refers to the width of a floating-point register in the ABI. The ABI_FLEN must be no wider than the ISA's FLEN. The ISA might have wider floating-point registers than the ABI.
(cited from section 2.2 [1], p. 10)
file_format: str = 'elf'
class-attribute
instance-attribute
¶
The output file format (for example of object files).
"elf" is the default for most
stack_alignment: int = 128
class-attribute
instance-attribute
¶
The stack grows downwards (towards lower addresses) and the stack pointer shall be aligned to a 128-bit boundary upon procedure entry. The first argument passed on the stack is located at offset zero of the stack pointer on function entry; following arguments are stored at correspondingly higher addresses.
(cited from section 2.1 [1] p. 9)
A supporting illustration:
+--------------------------+ <--- stack "end", higher address | In-use stack | | (from calling functions) | +--------------------------+ | Padding if needed | +--------------------------+ | stack argument n | | stack argument n-1 | | ... | | stack argument 0 | +--------------------------+ <--- Stack pointer, aligned to 128 bits | empty | | | +--------------------------+ <--- stack "start", lower address
This means 0(sp) is stack argument 0, and 4*n(sp) is stack argument n.
__init__(int_width: int, long_width: int, pointer_width: int, abi_flen: Literal[0, 32, 64, 128], file_format: str = 'elf', stack_alignment: int = 128) -> None
¶
MachineArchSpec
dataclass
¶
Machine architecture spec, bitwidth, extensions, etc.
Source code in xdsl/backend/riscv/targets.py
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 | |
xlen: int
instance-attribute
¶
Register size, basically 32/64, for RV32/RV64 respectively
flen: int
instance-attribute
¶
Floating point register width (0/32/64/128)
extensions: tuple[str, ...]
instance-attribute
¶
A list of extensions, fully expanded.
RV32G would be: ["I", "M", "A", "F", "D", "Zifencei", "Zicsr"]
spec_string: str
property
¶
__repr__()
¶
__init__(march: str)
¶
Source code in xdsl/backend/riscv/targets.py
supports_mabi(abi: ABISpec) -> bool
¶
Implements checks lined out in section 2.4 of [2], p. 12
Source code in xdsl/backend/riscv/targets.py
TargetDefinition
dataclass
¶
Source code in xdsl/backend/riscv/targets.py
abi: ABISpec
instance-attribute
¶
Target ABI (type bitwidth, stack alignment, argument passing)
march: MachineArchSpec
instance-attribute
¶
Machine architecture (handled by -march=RV...)
code_model: Literal['any', 'low'] = 'any'
class-attribute
instance-attribute
¶
Code model (usually handled by -mcmodel=med
low: The program and its statically defined symbols must lie within a single 2GiB address range, between the absolute addresses -2GiB and +2GiB. lui and addi pairs are used to generate addresses.
any: The program and its statically defined symbols must lie within a single 4GiB address range. auipc and addi pairs are used to generate addresses.
__init__(abi: ABISpec, march: MachineArchSpec, code_model: Literal['any', 'low'] = 'any') -> None
¶
MAbi
¶
Bases: Enum
Collection of named ABIs as per chapter 2.4 of [1].
ILP32E is omitted as the E extension is currently not ratified.
Source code in xdsl/backend/riscv/targets.py
ILP32 = ABISpec(32, 32, 32, abi_flen=0)
class-attribute
instance-attribute
¶
ILP32F = ABISpec(32, 32, 32, abi_flen=32)
class-attribute
instance-attribute
¶
ILP32D = ABISpec(32, 32, 32, abi_flen=64)
class-attribute
instance-attribute
¶
LP64 = ABISpec(32, 64, 64, abi_flen=0)
class-attribute
instance-attribute
¶
LP64F = ABISpec(32, 64, 64, abi_flen=32)
class-attribute
instance-attribute
¶
LP64D = ABISpec(32, 64, 64, abi_flen=64)
class-attribute
instance-attribute
¶
LP64Q = ABISpec(32, 64, 64, abi_flen=128)
class-attribute
instance-attribute
¶
RecognizedTargets
¶
Bases: Enum