[InstCombine] Signed saturation patterns
[llvm-complete.git] / tools / llvm-exegesis / lib / PowerPC / Target.cpp
blob567d62031f189e8c049396bc73e33b133bc2cd0c
1 //===-- Target.cpp ----------------------------------------------*- C++ -*-===//
2 //
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
6 //
7 // The PowerPC ExegesisTarget.
8 //===----------------------------------------------------------------------===//
9 #include "../Target.h"
10 #include "../Latency.h"
11 #include "PPC.h"
12 #include "PPCRegisterInfo.h"
14 namespace llvm {
15 namespace exegesis {
17 #include "PPCGenExegesis.inc"
19 namespace {
20 class ExegesisPowerPCTarget : public ExegesisTarget {
21 public:
22 ExegesisPowerPCTarget() : ExegesisTarget(PPCCpuPfmCounters) {}
24 private:
25 std::vector<MCInst> setRegTo(const MCSubtargetInfo &STI, unsigned Reg,
26 const APInt &Value) const override;
27 bool matchesArch(Triple::ArchType Arch) const override {
28 return Arch == Triple::ppc64le;
31 } // end anonymous namespace
33 static unsigned getLoadImmediateOpcode(unsigned RegBitWidth) {
34 switch (RegBitWidth) {
35 case 32:
36 return PPC::LI;
37 case 64:
38 return PPC::LI8;
40 llvm_unreachable("Invalid Value Width");
43 // Generates instruction to load an immediate value into a register.
44 static MCInst loadImmediate(unsigned Reg, unsigned RegBitWidth,
45 const APInt &Value) {
46 if (Value.getBitWidth() > RegBitWidth)
47 llvm_unreachable("Value must fit in the Register");
48 return MCInstBuilder(getLoadImmediateOpcode(RegBitWidth))
49 .addReg(Reg)
50 .addImm(Value.getZExtValue());
53 std::vector<MCInst> ExegesisPowerPCTarget::setRegTo(const MCSubtargetInfo &STI,
54 unsigned Reg,
55 const APInt &Value) const {
56 if (PPC::GPRCRegClass.contains(Reg))
57 return {loadImmediate(Reg, 32, Value)};
58 if (PPC::G8RCRegClass.contains(Reg))
59 return {loadImmediate(Reg, 64, Value)};
60 errs() << "setRegTo is not implemented, results will be unreliable\n";
61 return {};
64 static ExegesisTarget *getTheExegesisPowerPCTarget() {
65 static ExegesisPowerPCTarget Target;
66 return &Target;
69 void InitializePowerPCExegesisTarget() {
70 ExegesisTarget::registerTarget(getTheExegesisPowerPCTarget());
73 } // namespace exegesis
74 } // namespace llvm