LLVM API Documentation
00001 //===-- XCoreFrameToArgsOffsetElim.cpp ----------------------------*- C++ -*-=// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // Replace Pseudo FRAME_TO_ARGS_OFFSET with the appropriate real offset. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #include "XCore.h" 00015 #include "XCoreInstrInfo.h" 00016 #include "XCoreSubtarget.h" 00017 #include "llvm/CodeGen/MachineFrameInfo.h" 00018 #include "llvm/CodeGen/MachineFunctionPass.h" 00019 #include "llvm/CodeGen/MachineInstrBuilder.h" 00020 #include "llvm/Support/Compiler.h" 00021 #include "llvm/Support/raw_ostream.h" 00022 #include "llvm/Target/TargetMachine.h" 00023 using namespace llvm; 00024 00025 namespace { 00026 struct XCoreFTAOElim : public MachineFunctionPass { 00027 static char ID; 00028 XCoreFTAOElim() : MachineFunctionPass(ID) {} 00029 00030 bool runOnMachineFunction(MachineFunction &Fn) override; 00031 00032 const char *getPassName() const override { 00033 return "XCore FRAME_TO_ARGS_OFFSET Elimination"; 00034 } 00035 }; 00036 char XCoreFTAOElim::ID = 0; 00037 } 00038 00039 /// createXCoreFrameToArgsOffsetEliminationPass - returns an instance of the 00040 /// Frame to args offset elimination pass 00041 FunctionPass *llvm::createXCoreFrameToArgsOffsetEliminationPass() { 00042 return new XCoreFTAOElim(); 00043 } 00044 00045 bool XCoreFTAOElim::runOnMachineFunction(MachineFunction &MF) { 00046 const XCoreInstrInfo &TII = 00047 *static_cast<const XCoreInstrInfo *>(MF.getSubtarget().getInstrInfo()); 00048 unsigned StackSize = MF.getFrameInfo()->getStackSize(); 00049 for (MachineFunction::iterator MFI = MF.begin(), E = MF.end(); MFI != E; 00050 ++MFI) { 00051 MachineBasicBlock &MBB = *MFI; 00052 for (MachineBasicBlock::iterator MBBI = MBB.begin(), EE = MBB.end(); 00053 MBBI != EE; ++MBBI) { 00054 if (MBBI->getOpcode() == XCore::FRAME_TO_ARGS_OFFSET) { 00055 MachineInstr *OldInst = MBBI; 00056 unsigned Reg = OldInst->getOperand(0).getReg(); 00057 MBBI = TII.loadImmediate(MBB, MBBI, Reg, StackSize); 00058 OldInst->eraseFromParent(); 00059 } 00060 } 00061 } 00062 return true; 00063 }