LLVM  14.0.0git
XCoreFrameToArgsOffsetElim.cpp
Go to the documentation of this file.
1 //===-- XCoreFrameToArgsOffsetElim.cpp ----------------------------*- C++ -*-=//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Replace Pseudo FRAME_TO_ARGS_OFFSET with the appropriate real offset.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "XCore.h"
14 #include "XCoreInstrInfo.h"
15 #include "XCoreSubtarget.h"
21 using namespace llvm;
22 
23 namespace {
24  struct XCoreFTAOElim : public MachineFunctionPass {
25  static char ID;
26  XCoreFTAOElim() : MachineFunctionPass(ID) {}
27 
28  bool runOnMachineFunction(MachineFunction &Fn) override;
29  MachineFunctionProperties getRequiredProperties() const override {
32  }
33 
34  StringRef getPassName() const override {
35  return "XCore FRAME_TO_ARGS_OFFSET Elimination";
36  }
37  };
38  char XCoreFTAOElim::ID = 0;
39 }
40 
41 /// createXCoreFrameToArgsOffsetEliminationPass - returns an instance of the
42 /// Frame to args offset elimination pass
44  return new XCoreFTAOElim();
45 }
46 
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;
52  ++MFI) {
53  MachineBasicBlock &MBB = *MFI;
55  MBBI != EE; ++MBBI) {
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();
61  }
62  }
63  }
64  return true;
65 }
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
Reg
unsigned Reg
Definition: MachineSink.cpp:1566
llvm::createXCoreFrameToArgsOffsetEliminationPass
FunctionPass * createXCoreFrameToArgsOffsetEliminationPass()
createXCoreFrameToArgsOffsetEliminationPass - returns an instance of the Frame to args offset elimina...
Definition: XCoreFrameToArgsOffsetElim.cpp:43
llvm::TargetSubtargetInfo::getInstrInfo
virtual const TargetInstrInfo * getInstrInfo() const
Definition: TargetSubtargetInfo.h:92
XCore.h
llvm::MachineFunction::end
iterator end()
Definition: MachineFunction.h:818
llvm::MachineFunctionPass
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
Definition: MachineFunctionPass.h:30
llvm::MachineFunctionProperties
Properties which a MachineFunction may have at a given point in time.
Definition: MachineFunction.h:111
llvm::XCoreInstrInfo
Definition: XCoreInstrInfo.h:24
TargetMachine.h
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
llvm::MachineInstr::getOperand
const MachineOperand & getOperand(unsigned i) const
Definition: MachineInstr.h:499
XCoreInstrInfo.h
TII
const HexagonInstrInfo * TII
Definition: HexagonCopyToCombine.cpp:129
llvm::MachineFunctionProperties::set
MachineFunctionProperties & set(Property P)
Definition: MachineFunction.h:173
llvm::MachineFunction::begin
iterator begin()
Definition: MachineFunction.h:816
llvm::MachineFrameInfo::getStackSize
uint64_t getStackSize() const
Return the number of bytes that must be allocated to hold all of the fixed size frame objects.
Definition: MachineFrameInfo.h:553
XCoreSubtarget.h
llvm::MachineBasicBlock
Definition: MachineBasicBlock.h:95
llvm::MachineFunctionProperties::Property::NoVRegs
@ NoVRegs
llvm::MachineFunction::getSubtarget
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Definition: MachineFunction.h:634
llvm::MachineInstr
Representation of each machine instruction.
Definition: MachineInstr.h:64
MachineFunctionPass.h
llvm::MachineFunction::getFrameInfo
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
Definition: MachineFunction.h:650
llvm::MachineOperand::getReg
Register getReg() const
getReg - Returns the register number.
Definition: MachineOperand.h:360
llvm::MachineFunction
Definition: MachineFunction.h:234
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
MBBI
MachineBasicBlock MachineBasicBlock::iterator MBBI
Definition: AArch64SLSHardening.cpp:75
llvm::Register
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
MBB
MachineBasicBlock & MBB
Definition: AArch64SLSHardening.cpp:74
llvm::ilist_iterator
Iterator for intrusive lists based on ilist_node.
Definition: ilist_iterator.h:57
MachineFrameInfo.h
llvm::ISD::FRAME_TO_ARGS_OFFSET
@ FRAME_TO_ARGS_OFFSET
FRAME_TO_ARGS_OFFSET - This node represents offset from frame pointer to first (possible) on-stack ar...
Definition: ISDOpcodes.h:124
llvm::MachineBasicBlock::begin
iterator begin()
Definition: MachineBasicBlock.h:268
MachineInstrBuilder.h
llvm::FunctionPass
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:298
raw_ostream.h
llvm::MachineInstr::eraseFromParent
void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
Definition: MachineInstr.cpp:680
llvm::MachineInstrBundleIterator< MachineInstr >
llvm::MachineBasicBlock::end
iterator end()
Definition: MachineBasicBlock.h:270
llvm::Intrinsic::ID
unsigned ID
Definition: TargetTransformInfo.h:37