LLVM 24.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"
20#include "llvm/IR/Analysis.h"
21#include "llvm/Pass.h"
23using namespace llvm;
24
25namespace {
26struct XCoreFrameToArgsOffsetEliminationLegacy : public MachineFunctionPass {
27 static char ID;
28 XCoreFrameToArgsOffsetEliminationLegacy() : MachineFunctionPass(ID) {}
29
30 bool runOnMachineFunction(MachineFunction &Fn) override;
31 MachineFunctionProperties getRequiredProperties() const override {
32 return MachineFunctionProperties().setNoVRegs();
33 }
34
35 StringRef getPassName() const override {
36 return "XCore FRAME_TO_ARGS_OFFSET Elimination";
37 }
38
39 void getAnalysisUsage(AnalysisUsage &AU) const override {
40 AU.setPreservesCFG();
42 }
43};
44char XCoreFrameToArgsOffsetEliminationLegacy::ID = 0;
45}
46
47/// createXCoreFrameToArgsOffsetEliminationPass - returns an instance of the
48/// Frame to args offset elimination pass
50 return new XCoreFrameToArgsOffsetEliminationLegacy();
51}
52
54 const XCoreInstrInfo &TII =
55 *static_cast<const XCoreInstrInfo *>(MF.getSubtarget().getInstrInfo());
56 unsigned StackSize = MF.getFrameInfo().getStackSize();
57 for (MachineBasicBlock &MBB : MF) {
58 for (MachineBasicBlock::iterator MBBI = MBB.begin(), EE = MBB.end();
59 MBBI != EE; ++MBBI) {
60 if (MBBI->getOpcode() == XCore::FRAME_TO_ARGS_OFFSET) {
61 MachineInstr &OldInst = *MBBI;
62 Register Reg = OldInst.getOperand(0).getReg();
63 MBBI = TII.loadImmediate(MBB, MBBI, Reg, StackSize);
64 OldInst.eraseFromParent();
65 }
66 }
67 }
68 return true;
69}
70
71bool XCoreFrameToArgsOffsetEliminationLegacy::runOnMachineFunction(
72 MachineFunction &MF) {
74}
75
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator MBBI
const HexagonInstrInfo * TII
Register Reg
static bool runFrameToArgOffsetElimination(MachineFunction &MF)
LLVM_ABI void setPreservesCFG()
This function should be called by the pass, iff they do not:
Definition Pass.cpp:280
Represents analyses that only rely on functions' control flow.
Definition Analysis.h:73
FunctionPass class - This class is used to implement most global optimizations.
Definition Pass.h:312
MachineInstrBundleIterator< MachineInstr > iterator
uint64_t getStackSize() const
Return the number of bytes that must be allocated to hold all of the fixed size frame objects.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
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.
Representation of each machine instruction.
const MachineOperand & getOperand(unsigned i) const
LLVM_ABI MachineInstrBundleIterator< MachineInstr > eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
Register getReg() const
getReg - Returns the register number.
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition Analysis.h:118
PreservedAnalyses & preserveSet()
Mark an analysis set as preserved.
Definition Analysis.h:151
Wrapper class representing virtual and physical registers.
Definition Register.h:20
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
Pass manager infrastructure for declaring and invalidating analyses.
This is an optimization pass for GlobalISel generic memory operations.
FunctionPass * createXCoreFrameToArgsOffsetEliminationLegacyPass()
createXCoreFrameToArgsOffsetEliminationPass - returns an instance of the Frame to args offset elimina...
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
LLVM_ABI PreservedAnalyses getMachineFunctionPassPreservedAnalyses()
Returns the minimum set of Analyses that all machine function passes must preserve.