1//===------- LeonPasses.h - Define passes specific to LEON ----------------===//
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//===----------------------------------------------------------------------===//
8//
9//
10//===----------------------------------------------------------------------===//
11
12#ifndef LLVM_LIB_TARGET_SPARC_LEON_PASSES_H
13#define LLVM_LIB_TARGET_SPARC_LEON_PASSES_H
14
15#include "llvm/CodeGen/MachineBasicBlock.h"
16#include "llvm/CodeGen/MachineFunctionPass.h"
17#include "llvm/CodeGen/Passes.h"
18
19#include "Sparc.h"
20#include "SparcSubtarget.h"
21
22namespace llvm {
23class LLVM_LIBRARY_VISIBILITY LEONMachineFunctionPass
24    : public MachineFunctionPass {
25protected:
26  const SparcSubtarget *Subtarget = nullptr;
27  const int LAST_OPERAND = -1;
28
29  // this vector holds free registers that we allocate in groups for some of the
30  // LEON passes
31  std::vector<int> UsedRegisters;
32
33protected:
34  LEONMachineFunctionPass(char &ID);
35
36  int GetRegIndexForOperand(MachineInstr &MI, int OperandIndex);
37  void clearUsedRegisterList() { UsedRegisters.clear(); }
38
39  void markRegisterUsed(int registerIndex) {
40    UsedRegisters.push_back(registerIndex);
41  }
42  int getUnusedFPRegister(MachineRegisterInfo &MRI);
43};
44
45class LLVM_LIBRARY_VISIBILITY InsertNOPLoad : public LEONMachineFunctionPass {
46public:
47  static char ID;
48
49  InsertNOPLoad();
50  bool runOnMachineFunction(MachineFunction &MF) override;
51
52  StringRef getPassName() const override {
53    return "InsertNOPLoad: Erratum Fix LBR35: insert a NOP instruction after "
54           "every single-cycle load instruction when the next instruction is "
55           "another load/store instruction";
56  }
57};
58
59class LLVM_LIBRARY_VISIBILITY DetectRoundChange
60    : public LEONMachineFunctionPass {
61public:
62  static char ID;
63
64  DetectRoundChange();
65  bool runOnMachineFunction(MachineFunction &MF) override;
66
67  StringRef getPassName() const override {
68    return "DetectRoundChange: Leon erratum detection: detect any rounding "
69           "mode change request: use only the round-to-nearest rounding mode";
70  }
71};
72
73class LLVM_LIBRARY_VISIBILITY FixAllFDIVSQRT : public LEONMachineFunctionPass {
74public:
75  static char ID;
76
77  FixAllFDIVSQRT();
78  bool runOnMachineFunction(MachineFunction &MF) override;
79
80  StringRef getPassName() const override {
81    return "FixAllFDIVSQRT: Erratum Fix LBR34: fix FDIVS/FDIVD/FSQRTS/FSQRTD "
82           "instructions with NOPs and floating-point store";
83  }
84};
85} // namespace llvm
86
87#endif // LLVM_LIB_TARGET_SPARC_LEON_PASSES_H
88