Professional Documents
Culture Documents
I. INTRODUCTION
As the LLVM Compiler Infrastructure [1] has become
popular due to its advanced design and handy set of tools,
there is a need for more architectures support. MicroMIPS
is one of the latest architecture from MIPS family of
architectures. MicroMIPS is designed to reduce the code
size without performance losses. Some tests showed that it
is possible to reduce the code size up to 35% with only 2%
of performance loss [2].
This work describes how to add support for microMIPS
backend to the LLVM Compiler Infrastructure. Part II
describes LLVM in general, and also its domain specific
language called TableGen, that is used to add new
backends. Part III describes microMIPS architecture, how
it is designed and its differences when compared to
MIPS32 architecture. Part IV shows how TableGen is used
to add new microMIPS backend, and mentions other steps
that must be performed in order to get new backend
worked.
II. THE LLVM COMPILER INFRASTRUCTURE
LLVM Compiler Infrastructure is a set of modular and
extensible compiler tools and libraries. It consists of many
subprojects and the most important of them are [1]:
LLVM Core libraries - represents optimizer which
operates on source code and machine target independent
intermediate representation known as LLVM IR. Along
with this optimizer comes a code generation support for
many CPUs.
Clang - a C/C++/Objective-C front-end for LLVM.
Clang parses the source code and generates the LLVM IR.
One of the interesting tool that is built using this front-end
Jozef Kolek, RT-RK, Computer Based Systems, Novi Sad, Narodnog
Fronta 23a, 21000 Novi Sad, Serbia (e-mail: jozef.kolek@rt-rk.com)
Zoran Jovanovi, RT-RK, Computer Based Systems, Novi Sad,
Narodnog Fronta 23a, 21000 Novi Sad, Serbia (e-mail:
zoran.jovanovic@rt-rk.com)
Nenad ljivi, RT-RK, Computer Based Systems, Novi Sad,
Narodnog Fronta 23a, 21000 Novi Sad, Serbia (e-mail:
nenad.sljivic@rt-rk.com)
Dragan Narani, RT-RK, Computer Based Systems, Novi Sad,
Narodnog Fronta 23a, 21000 Novi Sad, Serbia (e-mail:
dragan.narancic@rt-rk.com)
1015
let
let
let
let
Inst{31-26}
Inst{25-21}
Inst{20-16}
Inst{15-0}
=
=
=
=
op;
rs;
rt;
imm16;
}
// Arithmetic and logical instructions with 2
// register operands.
class ArithLogicI<string opstr,
Operand Od, RegisterOperand RO,
InstrItinClass Itin = NoItinerary,
SDPatternOperator imm_type = null_frag,
SDPatternOperator OpNode = null_frag> :
InstSE<(outs RO:$rt),
(ins RO:$rs, Od:$imm16),
!strconcat(opstr, "\t$rt, $rs, $imm16"),
[(set RO:$rt,
(OpNode RO:$rs, imm_type:$imm16))],
Itin, FrmI, opstr> {
let isReMaterializable = 1;
let TwoOperandAliasConstraint = "$rs = $rt";
}
def ADDIU : ArithLogicI<"addiu",
simm16, GPR32Opnd, IIArith,
immSExt16, add>,
ADDI_FM<0x9>;
1016
Inst{31-26}
Inst{25-21}
Inst{20-16}
Inst{15-0}
=
=
=
=
op;
rt;
rs;
imm16;
}
def ADDIU_MM : MMRel, ArithLogicI<"addiu",
simm16, GPR32Opnd, IIArith,
immSExt16, add>,
ADDI_FM_MM<0x9>;
1017
CONCLUSION
Instruction mapping reduces the code size, the
implementation time and therefore overall effort that
implementation of a new backend took. Precondition for
instruction mapping is that corresponding backend must
already be implemented, so few of already implemented
phases of the code generation can be reused. In our case
almost all of the 32-bit recoded MIPS32 instructions in
microMIPS are mapped with the MIPS32 instructions that
has been already implemented in LLVM. That is to say
175 instructions are mapped and 58 instructions are
implemented from scratch. To compare, target description
file for microMIPS instructions (MicroMipsInstrInfo.td) is
near 500 lines of code long, target description file for
MIPS32 instructions (MipsInstrInfo.td) is near 1400 lines
of code long, and target description file for MIPS16
architecture is over 1800 lines of code long, which is more
than three times longer than microMIPS target description
file.
Another benefit of instruction mapping is that a testing
and verification time of the implemented backend is much
shorter than it would be otherwise. Number of newly
developed tests is reduced because reused parts of
implementation are already verified and tested. Same
stand for the number of detected bugs and effort needed to
fix them.
ACKNOWLEDGMENT
This work was partially supported by the Ministry of
Education, Science and Technological Development of the
Republic of Serbia under Grant TR-32034.
REFERENCES
[1]
[2]
[3]
[4]
[5]
[6]
[7]
[8]
[9]
[10]
[11]
1018