1 //===-- XCoreFrameToArgsOffsetElim.cpp ----------------------------*- C++ -*-=//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Replace Pseudo FRAME_TO_ARGS_OFFSET with the appropriate real offset.
12 //===----------------------------------------------------------------------===//
15 #include "XCoreInstrInfo.h"
16 #include "XCoreSubtarget.h"
17 #include "llvm/CodeGen/MachineFrameInfo.h"
18 #include "llvm/CodeGen/MachineFunctionPass.h"
19 #include "llvm/CodeGen/MachineInstrBuilder.h"
20 #include "llvm/Support/raw_ostream.h"
21 #include "llvm/Target/TargetMachine.h"
25 struct XCoreFTAOElim : public MachineFunctionPass {
27 XCoreFTAOElim() : MachineFunctionPass(ID) {}
29 bool runOnMachineFunction(MachineFunction &Fn) override;
30 MachineFunctionProperties getRequiredProperties() const override {
31 return MachineFunctionProperties().set(
32 MachineFunctionProperties::Property::NoVRegs);
35 StringRef getPassName() const override {
36 return "XCore FRAME_TO_ARGS_OFFSET Elimination";
39 char XCoreFTAOElim::ID = 0;
42 /// createXCoreFrameToArgsOffsetEliminationPass - returns an instance of the
43 /// Frame to args offset elimination pass
44 FunctionPass *llvm::createXCoreFrameToArgsOffsetEliminationPass() {
45 return new XCoreFTAOElim();
48 bool XCoreFTAOElim::runOnMachineFunction(MachineFunction &MF) {
49 const XCoreInstrInfo &TII =
50 *static_cast<const XCoreInstrInfo *>(MF.getSubtarget().getInstrInfo());
51 unsigned StackSize = MF.getFrameInfo().getStackSize();
52 for (MachineFunction::iterator MFI = MF.begin(), E = MF.end(); MFI != E;
54 MachineBasicBlock &MBB = *MFI;
55 for (MachineBasicBlock::iterator MBBI = MBB.begin(), EE = MBB.end();
57 if (MBBI->getOpcode() == XCore::FRAME_TO_ARGS_OFFSET) {
58 MachineInstr &OldInst = *MBBI;
59 unsigned Reg = OldInst.getOperand(0).getReg();
60 MBBI = TII.loadImmediate(MBB, MBBI, Reg, StackSize);
61 OldInst.eraseFromParent();