Services and Modeling for Embedded Software Development
Embecosm divider strip
Prev  Next

4.3. Register Support Function

Before the instruction encoding class can be implemented, it is useful to implement a function that will convert a register symbol to its register value.

A version of this function is generated by TableGen, though it is dependent on the order that registers are defined in a register class (assuming the first register defined is encoded as zero, etc.). Therefore if the register class does not match this (e.g. the class is defined in a different order for allocation purposes), then a custom function is required.

The register number support function is a simple switch statement which returns the encoding of a register to be used in an instruction. The default case should be a call to llvm_unreachable to warn of a problem where the encoding of an invalid register is requested.

The following example demonstrates how the function looks for the OpenRISC 1000  implementation.

static inline unsigned getOR1KRegisterNumbering(unsigned Reg) {
  switch(Reg) {
    case OR1K::R0  : return 0;
    case OR1K::R1  : return 1;
    ... other cases not shown ...
    case OR1K::R31 : return 31;
    default: llvm_unreachable("Unknown register number!");
Embecosm divider strip