1 //===-- XCoreFrameToArgsOffsetElim.cpp ----------------------------*- C++ -*-=//
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
7 //===----------------------------------------------------------------------===//
9 // Replace Pseudo FRAME_TO_ARGS_OFFSET with the appropriate real offset.
11 //===----------------------------------------------------------------------===//
14 #include "XCoreInstrInfo.h"
15 #include "XCoreSubtarget.h"
16 #include "llvm/CodeGen/MachineFrameInfo.h"
17 #include "llvm/CodeGen/MachineFunctionPass.h"
18 #include "llvm/CodeGen/MachineInstrBuilder.h"
19 #include "llvm/Support/raw_ostream.h"
20 #include "llvm/Target/TargetMachine.h"
24 struct XCoreFTAOElim
: public MachineFunctionPass
{
26 XCoreFTAOElim() : MachineFunctionPass(ID
) {}
28 bool runOnMachineFunction(MachineFunction
&Fn
) override
;
29 MachineFunctionProperties
getRequiredProperties() const override
{
30 return MachineFunctionProperties().set(
31 MachineFunctionProperties::Property::NoVRegs
);
34 StringRef
getPassName() const override
{
35 return "XCore FRAME_TO_ARGS_OFFSET Elimination";
38 char XCoreFTAOElim::ID
= 0;
41 /// createXCoreFrameToArgsOffsetEliminationPass - returns an instance of the
42 /// Frame to args offset elimination pass
43 FunctionPass
*llvm::createXCoreFrameToArgsOffsetEliminationPass() {
44 return new XCoreFTAOElim();
47 bool XCoreFTAOElim::runOnMachineFunction(MachineFunction
&MF
) {
48 const XCoreInstrInfo
&TII
=
49 *static_cast<const XCoreInstrInfo
*>(MF
.getSubtarget().getInstrInfo());
50 unsigned StackSize
= MF
.getFrameInfo().getStackSize();
51 for (MachineFunction::iterator MFI
= MF
.begin(), E
= MF
.end(); MFI
!= E
;
53 MachineBasicBlock
&MBB
= *MFI
;
54 for (MachineBasicBlock::iterator MBBI
= MBB
.begin(), EE
= MBB
.end();
56 if (MBBI
->getOpcode() == XCore::FRAME_TO_ARGS_OFFSET
) {
57 MachineInstr
&OldInst
= *MBBI
;
58 Register Reg
= OldInst
.getOperand(0).getReg();
59 MBBI
= TII
.loadImmediate(MBB
, MBBI
, Reg
, StackSize
);
60 OldInst
.eraseFromParent();