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 // The PowerPC ExegesisTarget.
8 //===----------------------------------------------------------------------===//
11 #include "PPCRegisterInfo.h"
16 #include "PPCGenExegesis.inc"
19 class ExegesisPowerPCTarget
: public ExegesisTarget
{
21 ExegesisPowerPCTarget() : ExegesisTarget(PPCCpuPfmCounters
) {}
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::ppc64le
;
30 } // end anonymous namespace
32 static unsigned getLoadImmediateOpcode(unsigned RegBitWidth
) {
33 switch (RegBitWidth
) {
39 llvm_unreachable("Invalid Value Width");
42 // Generates instruction to load an immediate value into a register.
43 static MCInst
loadImmediate(unsigned Reg
, unsigned RegBitWidth
,
45 if (Value
.getBitWidth() > RegBitWidth
)
46 llvm_unreachable("Value must fit in the Register");
47 return MCInstBuilder(getLoadImmediateOpcode(RegBitWidth
))
49 .addImm(Value
.getZExtValue());
52 std::vector
<MCInst
> ExegesisPowerPCTarget::setRegTo(const MCSubtargetInfo
&STI
,
54 const APInt
&Value
) const {
55 if (PPC::GPRCRegClass
.contains(Reg
))
56 return {loadImmediate(Reg
, 32, Value
)};
57 if (PPC::G8RCRegClass
.contains(Reg
))
58 return {loadImmediate(Reg
, 64, Value
)};
59 errs() << "setRegTo is not implemented, results will be unreliable\n";
63 static ExegesisTarget
*getTheExegesisPowerPCTarget() {
64 static ExegesisPowerPCTarget Target
;
68 void InitializePowerPCExegesisTarget() {
69 ExegesisTarget::registerTarget(getTheExegesisPowerPCTarget());
72 } // namespace exegesis