LLVM  8.0.1
XCoreFrameToArgsOffsetElim.cpp
Go to the documentation of this file.
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"
22 using namespace llvm;
23 
24 namespace {
25  struct XCoreFTAOElim : public MachineFunctionPass {
26  static char ID;
27  XCoreFTAOElim() : MachineFunctionPass(ID) {}
28 
29  bool runOnMachineFunction(MachineFunction &Fn) override;
30  MachineFunctionProperties getRequiredProperties() const override {
33  }
34 
35  StringRef getPassName() const override {
36  return "XCore FRAME_TO_ARGS_OFFSET Elimination";
37  }
38  };
39  char XCoreFTAOElim::ID = 0;
40 }
41 
42 /// createXCoreFrameToArgsOffsetEliminationPass - returns an instance of the
43 /// Frame to args offset elimination pass
45  return new XCoreFTAOElim();
46 }
47 
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;
53  ++MFI) {
54  MachineBasicBlock &MBB = *MFI;
55  for (MachineBasicBlock::iterator MBBI = MBB.begin(), EE = MBB.end();
56  MBBI != EE; ++MBBI) {
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();
62  }
63  }
64  }
65  return true;
66 }
This class represents lattice values for constants.
Definition: AllocatorList.h:24
unsigned getReg() const
getReg - Returns the register number.
unsigned Reg
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const HexagonInstrInfo * TII
void eraseFromParent()
Unlink &#39;this&#39; from the containing basic block and delete it.
FRAME_TO_ARGS_OFFSET - This node represents offset from frame pointer to first (possible) on-stack ar...
Definition: ISDOpcodes.h:91
virtual const TargetInstrInfo * getInstrInfo() const
FunctionPass * createXCoreFrameToArgsOffsetEliminationPass()
createXCoreFrameToArgsOffsetEliminationPass - returns an instance of the Frame to args offset elimina...
MachineBasicBlock::iterator loadImmediate(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, unsigned Reg, uint64_t Value) const
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.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:285
Iterator for intrusive lists based on ilist_node.
MachineFunctionProperties & set(Property P)
Representation of each machine instruction.
Definition: MachineInstr.h:64
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
const MachineOperand & getOperand(unsigned i) const
Definition: MachineInstr.h:414
uint64_t getStackSize() const
Return the number of bytes that must be allocated to hold all of the fixed size frame objects...
Properties which a MachineFunction may have at a given point in time.