Clang] Fix expansion of response files in -Wp after integrated-cc1 change
[llvm-project.git] / llvm / tools / llvm-exegesis / lib / PowerPC / Target.cpp
blob771b01a5790b6e59f18a54f87e7d4b0653e3927b
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 "PPC.h"
11 #include "PPCRegisterInfo.h"
13 namespace llvm {
14 namespace exegesis {
16 #include "PPCGenExegesis.inc"
18 namespace {
19 class ExegesisPowerPCTarget : public ExegesisTarget {
20 public:
21 ExegesisPowerPCTarget() : ExegesisTarget(PPCCpuPfmCounters) {}
23 private:
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) {
34 case 32:
35 return PPC::LI;
36 case 64:
37 return PPC::LI8;
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,
44 const APInt &Value) {
45 if (Value.getBitWidth() > RegBitWidth)
46 llvm_unreachable("Value must fit in the Register");
47 return MCInstBuilder(getLoadImmediateOpcode(RegBitWidth))
48 .addReg(Reg)
49 .addImm(Value.getZExtValue());
52 std::vector<MCInst> ExegesisPowerPCTarget::setRegTo(const MCSubtargetInfo &STI,
53 unsigned Reg,
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";
60 return {};
63 static ExegesisTarget *getTheExegesisPowerPCTarget() {
64 static ExegesisPowerPCTarget Target;
65 return &Target;
68 void InitializePowerPCExegesisTarget() {
69 ExegesisTarget::registerTarget(getTheExegesisPowerPCTarget());
72 } // namespace exegesis
73 } // namespace llvm