1 //===-- Target.cpp ----------------------------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "../Latency.h"
11 #include "MipsRegisterInfo.h"
16 #include "MipsGenExegesis.inc"
19 class ExegesisMipsTarget
: public ExegesisTarget
{
21 ExegesisMipsTarget() : ExegesisTarget(MipsCpuPfmCounters
) {}
24 std::vector
<MCInst
> setRegTo(const MCSubtargetInfo
&STI
, unsigned Reg
,
25 const APInt
&Value
) const override
;
26 bool matchesArch(Triple::ArchType Arch
) const override
{
27 return Arch
== Triple::mips
|| Arch
== Triple::mipsel
||
28 Arch
== Triple::mips64
|| Arch
== Triple::mips64el
;
31 } // end anonymous namespace
33 // Generates instruction to load an immediate value into a register.
34 static MCInst
loadImmediate(unsigned Reg
, unsigned RegBitWidth
,
36 if (Value
.getActiveBits() > 16)
37 llvm_unreachable("Not implemented for Values wider than 16 bits");
38 if (Value
.getBitWidth() > RegBitWidth
)
39 llvm_unreachable("Value must fit in the Register");
40 return MCInstBuilder(Mips::ORi
)
43 .addImm(Value
.getZExtValue());
46 std::vector
<MCInst
> ExegesisMipsTarget::setRegTo(const MCSubtargetInfo
&STI
,
48 const APInt
&Value
) const {
49 if (Mips::GPR32RegClass
.contains(Reg
))
50 return {loadImmediate(Reg
, 32, Value
)};
51 if (Mips::GPR64RegClass
.contains(Reg
))
52 return {loadImmediate(Reg
, 64, Value
)};
53 errs() << "setRegTo is not implemented, results will be unreliable\n";
57 static ExegesisTarget
*getTheExegesisMipsTarget() {
58 static ExegesisMipsTarget Target
;
62 void InitializeMipsExegesisTarget() {
63 ExegesisTarget::registerTarget(getTheExegesisMipsTarget());
66 } // namespace exegesis