LLVM 17.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"
21using namespace llvm;
22
23namespace {
24 struct XCoreFTAOElim : public MachineFunctionPass {
25 static char ID;
26 XCoreFTAOElim() : MachineFunctionPass(ID) {}
27
28 bool runOnMachineFunction(MachineFunction &Fn) override;
31 MachineFunctionProperties::Property::NoVRegs);
32 }
33
34 StringRef getPassName() const override {
35 return "XCore FRAME_TO_ARGS_OFFSET Elimination";
36 }
37 };
38 char XCoreFTAOElim::ID = 0;
39}
40
41/// createXCoreFrameToArgsOffsetEliminationPass - returns an instance of the
42/// Frame to args offset elimination pass
44 return new XCoreFTAOElim();
45}
46
47bool XCoreFTAOElim::runOnMachineFunction(MachineFunction &MF) {
48 const XCoreInstrInfo &TII =
49 *static_cast<const XCoreInstrInfo *>(MF.getSubtarget().getInstrInfo());
50 unsigned StackSize = MF.getFrameInfo().getStackSize();
51 for (MachineBasicBlock &MBB : MF) {
53 MBBI != EE; ++MBBI) {
54 if (MBBI->getOpcode() == XCore::FRAME_TO_ARGS_OFFSET) {
55 MachineInstr &OldInst = *MBBI;
56 Register Reg = OldInst.getOperand(0).getReg();
57 MBBI = TII.loadImmediate(MBB, MBBI, Reg, StackSize);
58 OldInst.eraseFromParent();
59 }
60 }
61 }
62 return true;
63}
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator MBBI
const HexagonInstrInfo * TII
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:308
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...
virtual bool runOnMachineFunction(MachineFunction &MF)=0
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
virtual MachineFunctionProperties getRequiredProperties() const
Properties which a MachineFunction may have at a given point in time.
MachineFunctionProperties & set(Property P)
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.
Definition: MachineInstr.h:68
void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
const MachineOperand & getOperand(unsigned i) const
Definition: MachineInstr.h:526
Register getReg() const
getReg - Returns the register number.
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
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
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
FunctionPass * createXCoreFrameToArgsOffsetEliminationPass()
createXCoreFrameToArgsOffsetEliminationPass - returns an instance of the Frame to args offset elimina...