LLVM 19.0.0git
RISCVPostRAExpandPseudoInsts.cpp
Go to the documentation of this file.
1//===-- RISCVPostRAExpandPseudoInsts.cpp - Expand pseudo instrs ----===//
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// This file contains a pass that expands the pseudo instruction pseudolisimm32
10// into target instructions. This pass should be run during the post-regalloc
11// passes, before post RA scheduling.
12//
13//===----------------------------------------------------------------------===//
14
16#include "RISCV.h"
17#include "RISCVInstrInfo.h"
18#include "RISCVTargetMachine.h"
21
22using namespace llvm;
23
24#define RISCV_POST_RA_EXPAND_PSEUDO_NAME \
25 "RISC-V post-regalloc pseudo instruction expansion pass"
26
27namespace {
28
29class RISCVPostRAExpandPseudo : public MachineFunctionPass {
30public:
31 const RISCVInstrInfo *TII;
32 static char ID;
33
34 RISCVPostRAExpandPseudo() : MachineFunctionPass(ID) {}
35
36 bool runOnMachineFunction(MachineFunction &MF) override;
37
38 StringRef getPassName() const override {
40 }
41
42private:
43 bool expandMBB(MachineBasicBlock &MBB);
47};
48
49char RISCVPostRAExpandPseudo::ID = 0;
50
51bool RISCVPostRAExpandPseudo::runOnMachineFunction(MachineFunction &MF) {
52 TII = static_cast<const RISCVInstrInfo *>(MF.getSubtarget().getInstrInfo());
53 bool Modified = false;
54 for (auto &MBB : MF)
55 Modified |= expandMBB(MBB);
56 return Modified;
57}
58
59bool RISCVPostRAExpandPseudo::expandMBB(MachineBasicBlock &MBB) {
60 bool Modified = false;
61
63 while (MBBI != E) {
64 MachineBasicBlock::iterator NMBBI = std::next(MBBI);
65 Modified |= expandMI(MBB, MBBI, NMBBI);
66 MBBI = NMBBI;
67 }
68
69 return Modified;
70}
71
72bool RISCVPostRAExpandPseudo::expandMI(MachineBasicBlock &MBB,
75 switch (MBBI->getOpcode()) {
76 case RISCV::PseudoMovImm:
77 return expandMovImm(MBB, MBBI);
78 default:
79 return false;
80 }
81}
82
83bool RISCVPostRAExpandPseudo::expandMovImm(MachineBasicBlock &MBB,
85 DebugLoc DL = MBBI->getDebugLoc();
86
87 int64_t Val = MBBI->getOperand(1).getImm();
88
91 assert(!Seq.empty());
92
93 Register DstReg = MBBI->getOperand(0).getReg();
94 bool DstIsDead = MBBI->getOperand(0).isDead();
95 bool Renamable = MBBI->getOperand(0).isRenamable();
96
97 TII->movImm(MBB, MBBI, DL, DstReg, Val, MachineInstr::NoFlags, Renamable,
98 DstIsDead);
99
101 return true;
102}
103
104} // end of anonymous namespace
105
106INITIALIZE_PASS(RISCVPostRAExpandPseudo, "riscv-expand-pseudolisimm32",
108namespace llvm {
109
111 return new RISCVPostRAExpandPseudo();
112}
113
114} // end of namespace llvm
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
MachineBasicBlock MachineBasicBlock::iterator MBBI
const HexagonInstrInfo * TII
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:38
#define RISCV_POST_RA_EXPAND_PSEUDO_NAME
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
A debug info location.
Definition: DebugLoc.h:33
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:311
void eraseFromParent()
This method unlinks 'this' from the containing function and deletes it.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
virtual bool runOnMachineFunction(MachineFunction &MF)=0
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
virtual StringRef getPassName() const
getPassName - Return a nice clean name for a pass.
Definition: Pass.cpp:81
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
bool empty() const
Definition: SmallVector.h:94
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1209
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
virtual const TargetInstrInfo * getInstrInfo() const
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition: CallingConv.h:24
InstSeq generateInstSeq(int64_t Val, const MCSubtargetInfo &STI)
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
FunctionPass * createRISCVPostRAExpandPseudoPass()