LLVM 24.0.0git
RISCVExpandPseudoBase.cpp
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
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
12#include "RISCVInstrInfo.h"
13#include "RISCVSubtarget.h"
14
15using namespace llvm;
16
17#ifndef NDEBUG
18static unsigned getFuncSizeFromInsts(const MachineFunction &MF,
19 const RISCVInstrInfo *TII) {
20 unsigned Size = 0;
21 for (auto &MBB : MF)
22 for (auto &MI : MBB)
23 Size += TII->getInstSizeInBytes(MI);
24 return Size;
25}
26#endif
27
30 TII = STI->getInstrInfo();
31
32#ifndef NDEBUG
33 const unsigned OldSize = getFuncSizeFromInsts(MF, TII);
34#endif
35
36 bool Modified = false;
37 for (auto &MBB : MF)
38 Modified |= expandMBB(MBB);
39
40#ifndef NDEBUG
41 const unsigned NewSize = getFuncSizeFromInsts(MF, TII);
42 assert(OldSize >= NewSize &&
43 "Expanding Pseudos should not increase function size estimate");
44#endif
45 return Modified;
46}
47
48bool RISCVExpandPseudoImplBase::expandMBB(MachineBasicBlock &MBB) const {
49 bool Modified = false;
50
51 MachineBasicBlock::iterator MBBI = MBB.begin(), E = MBB.end();
52 while (MBBI != E) {
53 MachineBasicBlock::iterator NMBBI = std::next(MBBI);
54 Modified |= expandMI(MBB, MBBI, NMBBI);
55 MBBI = NMBBI;
56 }
57
58 return Modified;
59}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator MBBI
const HexagonInstrInfo * TII
IRTranslator LLVM IR MI
static unsigned getFuncSizeFromInsts(const MachineFunction &MF, const RISCVInstrInfo *TII)
MachineInstrBundleIterator< MachineInstr > iterator
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
const RISCVInstrInfo * TII
The derived TargetInstrInfo for the current function.
virtual bool expandMI(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, MachineBasicBlock::iterator &NextMBBI) const
This method should be implemented to expand the instruction at *MBBI.
bool run(MachineFunction &MF)
Expand a subset of pseudos in the current function.
const RISCVSubtarget * STI
The Subtarget for the current function.
This is an optimization pass for GlobalISel generic memory operations.