1 //===-- XCoreFrameToArgsOffsetElim.cpp ----------------------------*- C++ -*-=// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // Replace Pseudo FRAME_TO_ARGS_OFFSET with the appropriate real offset. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #include "XCore.h" 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/Compiler.h" 21 #include "llvm/Support/raw_ostream.h" 22 #include "llvm/Target/TargetMachine.h" 23 using namespace llvm; 24 25 namespace { 26 struct XCoreFTAOElim : public MachineFunctionPass { 27 static char ID; 28 XCoreFTAOElim() : MachineFunctionPass(ID) {} 29 30 bool runOnMachineFunction(MachineFunction &Fn) override; 31 MachineFunctionProperties getRequiredProperties() const override { 32 return MachineFunctionProperties().set( 33 MachineFunctionProperties::Property::AllVRegsAllocated); 34 } 35 36 const char *getPassName() const override { 37 return "XCore FRAME_TO_ARGS_OFFSET Elimination"; 38 } 39 }; 40 char XCoreFTAOElim::ID = 0; 41 } 42 43 /// createXCoreFrameToArgsOffsetEliminationPass - returns an instance of the 44 /// Frame to args offset elimination pass 45 FunctionPass *llvm::createXCoreFrameToArgsOffsetEliminationPass() { 46 return new XCoreFTAOElim(); 47 } 48 49 bool XCoreFTAOElim::runOnMachineFunction(MachineFunction &MF) { 50 const XCoreInstrInfo &TII = 51 *static_cast<const XCoreInstrInfo *>(MF.getSubtarget().getInstrInfo()); 52 unsigned StackSize = MF.getFrameInfo()->getStackSize(); 53 for (MachineFunction::iterator MFI = MF.begin(), E = MF.end(); MFI != E; 54 ++MFI) { 55 MachineBasicBlock &MBB = *MFI; 56 for (MachineBasicBlock::iterator MBBI = MBB.begin(), EE = MBB.end(); 57 MBBI != EE; ++MBBI) { 58 if (MBBI->getOpcode() == XCore::FRAME_TO_ARGS_OFFSET) { 59 MachineInstr *OldInst = MBBI; 60 unsigned Reg = OldInst->getOperand(0).getReg(); 61 MBBI = TII.loadImmediate(MBB, MBBI, Reg, StackSize); 62 OldInst->eraseFromParent(); 63 } 64 } 65 } 66 return true; 67 } 68