Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/Target/XCore/XCoreFrameToArgsOffsetElim.cpp
Line
Count
Source
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"
16
#include "llvm/CodeGen/MachineFrameInfo.h"
17
#include "llvm/CodeGen/MachineFunctionPass.h"
18
#include "llvm/CodeGen/MachineInstrBuilder.h"
19
#include "llvm/Support/raw_ostream.h"
20
#include "llvm/Target/TargetMachine.h"
21
using namespace llvm;
22
23
namespace {
24
  struct XCoreFTAOElim : public MachineFunctionPass {
25
    static char ID;
26
70
    XCoreFTAOElim() : MachineFunctionPass(ID) {}
27
28
    bool runOnMachineFunction(MachineFunction &Fn) override;
29
70
    MachineFunctionProperties getRequiredProperties() const override {
30
70
      return MachineFunctionProperties().set(
31
70
          MachineFunctionProperties::Property::NoVRegs);
32
70
    }
33
34
349
    StringRef getPassName() const override {
35
349
      return "XCore FRAME_TO_ARGS_OFFSET Elimination";
36
349
    }
37
  };
38
  char XCoreFTAOElim::ID = 0;
39
}
40
41
/// createXCoreFrameToArgsOffsetEliminationPass - returns an instance of the
42
/// Frame to args offset elimination pass
43
70
FunctionPass *llvm::createXCoreFrameToArgsOffsetEliminationPass() {
44
70
  return new XCoreFTAOElim();
45
70
}
46
47
279
bool XCoreFTAOElim::runOnMachineFunction(MachineFunction &MF) {
48
279
  const XCoreInstrInfo &TII =
49
279
      *static_cast<const XCoreInstrInfo *>(MF.getSubtarget().getInstrInfo());
50
279
  unsigned StackSize = MF.getFrameInfo().getStackSize();
51
625
  for (MachineFunction::iterator MFI = MF.begin(), E = MF.end(); MFI != E;
52
346
       ++MFI) {
53
346
    MachineBasicBlock &MBB = *MFI;
54
346
    for (MachineBasicBlock::iterator MBBI = MBB.begin(), EE = MBB.end();
55
2.12k
         MBBI != EE; 
++MBBI1.78k
) {
56
1.78k
      if (MBBI->getOpcode() == XCore::FRAME_TO_ARGS_OFFSET) {
57
12
        MachineInstr &OldInst = *MBBI;
58
12
        unsigned Reg = OldInst.getOperand(0).getReg();
59
12
        MBBI = TII.loadImmediate(MBB, MBBI, Reg, StackSize);
60
12
        OldInst.eraseFromParent();
61
12
      }
62
1.78k
    }
63
346
  }
64
279
  return true;
65
279
}