Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/Target/Hexagon/HexagonSplitConst32AndConst64.cpp
Line
Count
Source (jump to first uncovered line)
1
//=== HexagonSplitConst32AndConst64.cpp - split CONST32/Const64 into HI/LO ===//
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
// When the compiler is invoked with no small data, for instance, with the -G0
10
// command line option, then all CONST* opcodes should be broken down into
11
// appropriate LO and HI instructions. This splitting is done by this pass.
12
// The only reason this is not done in the DAG lowering itself is that there
13
// is no simple way of getting the register allocator to allot the same hard
14
// register to the result of LO and HI instructions. This pass is always
15
// scheduled after register allocation.
16
//
17
//===----------------------------------------------------------------------===//
18
19
#include "HexagonSubtarget.h"
20
#include "HexagonTargetMachine.h"
21
#include "HexagonTargetObjectFile.h"
22
#include "llvm/CodeGen/MachineFunctionPass.h"
23
#include "llvm/CodeGen/MachineInstrBuilder.h"
24
#include "llvm/CodeGen/Passes.h"
25
#include "llvm/CodeGen/TargetInstrInfo.h"
26
#include "llvm/CodeGen/TargetRegisterInfo.h"
27
28
using namespace llvm;
29
30
#define DEBUG_TYPE "xfer"
31
32
namespace llvm {
33
  FunctionPass *createHexagonSplitConst32AndConst64();
34
  void initializeHexagonSplitConst32AndConst64Pass(PassRegistry&);
35
}
36
37
namespace {
38
  class HexagonSplitConst32AndConst64 : public MachineFunctionPass {
39
  public:
40
    static char ID;
41
919
    HexagonSplitConst32AndConst64() : MachineFunctionPass(ID) {
42
919
      PassRegistry &R = *PassRegistry::getPassRegistry();
43
919
      initializeHexagonSplitConst32AndConst64Pass(R);
44
919
    }
45
5.88k
    StringRef getPassName() const override {
46
5.88k
      return "Hexagon Split Const32s and Const64s";
47
5.88k
    }
48
    bool runOnMachineFunction(MachineFunction &Fn) override;
49
915
    MachineFunctionProperties getRequiredProperties() const override {
50
915
      return MachineFunctionProperties().set(
51
915
          MachineFunctionProperties::Property::NoVRegs);
52
915
    }
53
  };
54
}
55
56
char HexagonSplitConst32AndConst64::ID = 0;
57
58
INITIALIZE_PASS(HexagonSplitConst32AndConst64, "split-const-for-sdata",
59
      "Hexagon Split Const32s and Const64s", false, false)
60
61
4.97k
bool HexagonSplitConst32AndConst64::runOnMachineFunction(MachineFunction &Fn) {
62
4.97k
  auto &HST = Fn.getSubtarget<HexagonSubtarget>();
63
4.97k
  auto &HTM = static_cast<const HexagonTargetMachine&>(Fn.getTarget());
64
4.97k
  auto &TLOF = *HTM.getObjFileLowering();
65
4.97k
  if (HST.useSmallData() && TLOF.isSmallDataEnabled(HTM))
66
4.88k
    return false;
67
84
68
84
  const TargetInstrInfo *TII = HST.getInstrInfo();
69
84
  const TargetRegisterInfo *TRI = HST.getRegisterInfo();
70
84
71
84
  // Loop over all of the basic blocks
72
163
  for (MachineBasicBlock &B : Fn) {
73
994
    for (auto I = B.begin(), E = B.end(); I != E; ) {
74
831
      MachineInstr &MI = *I;
75
831
      ++I;
76
831
      unsigned Opc = MI.getOpcode();
77
831
78
831
      if (Opc == Hexagon::CONST32) {
79
0
        unsigned DestReg = MI.getOperand(0).getReg();
80
0
        uint64_t ImmValue = MI.getOperand(1).getImm();
81
0
        const DebugLoc &DL = MI.getDebugLoc();
82
0
        BuildMI(B, MI, DL, TII->get(Hexagon::A2_tfrsi), DestReg)
83
0
            .addImm(ImmValue);
84
0
        B.erase(&MI);
85
831
      } else if (Opc == Hexagon::CONST64) {
86
3
        unsigned DestReg = MI.getOperand(0).getReg();
87
3
        int64_t ImmValue = MI.getOperand(1).getImm();
88
3
        const DebugLoc &DL = MI.getDebugLoc();
89
3
        unsigned DestLo = TRI->getSubReg(DestReg, Hexagon::isub_lo);
90
3
        unsigned DestHi = TRI->getSubReg(DestReg, Hexagon::isub_hi);
91
3
92
3
        int32_t LowWord = (ImmValue & 0xFFFFFFFF);
93
3
        int32_t HighWord = (ImmValue >> 32) & 0xFFFFFFFF;
94
3
95
3
        BuildMI(B, MI, DL, TII->get(Hexagon::A2_tfrsi), DestLo)
96
3
            .addImm(LowWord);
97
3
        BuildMI(B, MI, DL, TII->get(Hexagon::A2_tfrsi), DestHi)
98
3
            .addImm(HighWord);
99
3
        B.erase(&MI);
100
3
      }
101
831
    }
102
163
  }
103
84
104
84
  return true;
105
84
}
106
107
108
//===----------------------------------------------------------------------===//
109
//                         Public Constructor Functions
110
//===----------------------------------------------------------------------===//
111
919
FunctionPass *llvm::createHexagonSplitConst32AndConst64() {
112
919
  return new HexagonSplitConst32AndConst64();
113
919
}