LLVM 22.0.0git
XCoreFrameToArgsOffsetElim.cpp
Go to the documentation of this file.
1//===-- XCoreFrameToArgsOffsetElim.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//===----------------------------------------------------------------------===//
8//
9// Replace Pseudo FRAME_TO_ARGS_OFFSET with the appropriate real offset.
10//
11//===----------------------------------------------------------------------===//
12
13#include "XCore.h"
14#include "XCoreInstrInfo.h"
15#include "XCoreSubtarget.h"
19using namespace llvm;
20
21namespace {
22 struct XCoreFTAOElim : public MachineFunctionPass {
23 static char ID;
24 XCoreFTAOElim() : MachineFunctionPass(ID) {}
25
26 bool runOnMachineFunction(MachineFunction &Fn) override;
27 MachineFunctionProperties getRequiredProperties() const override {
28 return MachineFunctionProperties().setNoVRegs();
29 }
30
31 StringRef getPassName() const override {
32 return "XCore FRAME_TO_ARGS_OFFSET Elimination";
33 }
34 };
35 char XCoreFTAOElim::ID = 0;
36}
37
38/// createXCoreFrameToArgsOffsetEliminationPass - returns an instance of the
39/// Frame to args offset elimination pass
43
44bool XCoreFTAOElim::runOnMachineFunction(MachineFunction &MF) {
45 const XCoreInstrInfo &TII =
46 *static_cast<const XCoreInstrInfo *>(MF.getSubtarget().getInstrInfo());
47 unsigned StackSize = MF.getFrameInfo().getStackSize();
48 for (MachineBasicBlock &MBB : MF) {
49 for (MachineBasicBlock::iterator MBBI = MBB.begin(), EE = MBB.end();
50 MBBI != EE; ++MBBI) {
51 if (MBBI->getOpcode() == XCore::FRAME_TO_ARGS_OFFSET) {
52 MachineInstr &OldInst = *MBBI;
53 Register Reg = OldInst.getOperand(0).getReg();
54 MBBI = TII.loadImmediate(MBB, MBBI, Reg, StackSize);
55 OldInst.eraseFromParent();
56 }
57 }
58 }
59 return true;
60}
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator MBBI
const HexagonInstrInfo * TII
Register Reg
FunctionPass class - This class is used to implement most global optimizations.
Definition Pass.h:314
MachineInstrBundleIterator< MachineInstr > iterator
uint64_t getStackSize() const
Return the number of bytes that must be allocated to hold all of the fixed size frame objects.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
Representation of each machine instruction.
LLVM_ABI void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
const MachineOperand & getOperand(unsigned i) const
Register getReg() const
getReg - Returns the register number.
Wrapper class representing virtual and physical registers.
Definition Register.h:19
This is an optimization pass for GlobalISel generic memory operations.
FunctionPass * createXCoreFrameToArgsOffsetEliminationPass()
createXCoreFrameToArgsOffsetEliminationPass - returns an instance of the Frame to args offset elimina...