blob: d15d6942797597b44ebca8bf2f5b85e8db5f04af [file] [log] [blame]
Jyotsna Verma5eb59802013-05-07 19:53:00 +00001//=== HexagonSplitConst32AndConst64.cpp - split CONST32/Const64 into HI/LO ===//
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// When the compiler is invoked with no small data, for instance, with the -G0
Krzysztof Parzyszeka3386502016-08-10 16:46:36 +000011// command line option, then all CONST* opcodes should be broken down into
Jyotsna Verma5eb59802013-05-07 19:53:00 +000012// appropriate LO and HI instructions. This splitting is done by this pass.
13// The only reason this is not done in the DAG lowering itself is that there
14// is no simple way of getting the register allocator to allot the same hard
15// register to the result of LO and HI instructions. This pass is always
16// scheduled after register allocation.
17//
18//===----------------------------------------------------------------------===//
Bill Wendling0cb8c0b2013-08-21 20:36:42 +000019
Chandler Carruth8a8cd2b2014-01-07 11:48:04 +000020#include "HexagonSubtarget.h"
Eric Christopher0120db52014-05-21 22:42:07 +000021#include "HexagonTargetMachine.h"
22#include "HexagonTargetObjectFile.h"
Jyotsna Verma5eb59802013-05-07 19:53:00 +000023#include "llvm/CodeGen/MachineFunctionPass.h"
Bill Wendling0cb8c0b2013-08-21 20:36:42 +000024#include "llvm/CodeGen/MachineInstrBuilder.h"
Bill Wendling0cb8c0b2013-08-21 20:36:42 +000025#include "llvm/CodeGen/Passes.h"
Chandler Carruth8a8cd2b2014-01-07 11:48:04 +000026#include "llvm/Target/TargetInstrInfo.h"
Chandler Carruth8a8cd2b2014-01-07 11:48:04 +000027#include "llvm/Target/TargetRegisterInfo.h"
Jyotsna Verma5eb59802013-05-07 19:53:00 +000028
29using namespace llvm;
30
Chandler Carruth84e68b22014-04-22 02:41:26 +000031#define DEBUG_TYPE "xfer"
32
Colin LeMahieu56efafc2015-06-15 19:05:35 +000033namespace llvm {
34 FunctionPass *createHexagonSplitConst32AndConst64();
35 void initializeHexagonSplitConst32AndConst64Pass(PassRegistry&);
36}
37
Jyotsna Verma5eb59802013-05-07 19:53:00 +000038namespace {
Krzysztof Parzyszek0bbad0f2016-08-10 18:05:47 +000039 class HexagonSplitConst32AndConst64 : public MachineFunctionPass {
40 public:
Jyotsna Verma5eb59802013-05-07 19:53:00 +000041 static char ID;
Krzysztof Parzyszek0bbad0f2016-08-10 18:05:47 +000042 HexagonSplitConst32AndConst64() : MachineFunctionPass(ID) {
43 PassRegistry &R = *PassRegistry::getPassRegistry();
44 initializeHexagonSplitConst32AndConst64Pass(R);
45 }
Craig Topper906c2cd2014-04-29 07:58:16 +000046 const char *getPassName() const override {
Jyotsna Verma5eb59802013-05-07 19:53:00 +000047 return "Hexagon Split Const32s and Const64s";
48 }
Craig Topper906c2cd2014-04-29 07:58:16 +000049 bool runOnMachineFunction(MachineFunction &Fn) override;
Derek Schuff1dbf7a52016-04-04 17:09:25 +000050 MachineFunctionProperties getRequiredProperties() const override {
51 return MachineFunctionProperties().set(
Matthias Braun1eb47362016-08-25 01:27:13 +000052 MachineFunctionProperties::Property::NoVRegs);
Derek Schuff1dbf7a52016-04-04 17:09:25 +000053 }
Krzysztof Parzyszek0bbad0f2016-08-10 18:05:47 +000054 };
55}
Jyotsna Verma5eb59802013-05-07 19:53:00 +000056
57char HexagonSplitConst32AndConst64::ID = 0;
58
Krzysztof Parzyszek0bbad0f2016-08-10 18:05:47 +000059INITIALIZE_PASS(HexagonSplitConst32AndConst64, "split-const-for-sdata",
60 "Hexagon Split Const32s and Const64s", false, false)
Jyotsna Verma5eb59802013-05-07 19:53:00 +000061
62bool HexagonSplitConst32AndConst64::runOnMachineFunction(MachineFunction &Fn) {
Eric Christopher0120db52014-05-21 22:42:07 +000063 const HexagonTargetObjectFile &TLOF =
Eric Christopher01f875e2015-02-02 22:11:43 +000064 *static_cast<const HexagonTargetObjectFile *>(
65 Fn.getTarget().getObjFileLowering());
Krzysztof Parzyszek5de59102016-04-21 18:56:45 +000066 if (TLOF.isSmallDataEnabled())
Eric Christopher0120db52014-05-21 22:42:07 +000067 return true;
68
Eric Christopher01f875e2015-02-02 22:11:43 +000069 const TargetInstrInfo *TII = Fn.getSubtarget().getInstrInfo();
Colin LeMahieu54251092015-03-09 20:11:02 +000070 const TargetRegisterInfo *TRI = Fn.getSubtarget().getRegisterInfo();
Jyotsna Verma5eb59802013-05-07 19:53:00 +000071
72 // Loop over all of the basic blocks
Krzysztof Parzyszek0bbad0f2016-08-10 18:05:47 +000073 for (MachineBasicBlock &B : Fn) {
74 for (auto I = B.begin(), E = B.end(); I != E; ) {
75 MachineInstr &MI = *I;
76 ++I;
77 unsigned Opc = MI.getOpcode();
Jyotsna Verma5eb59802013-05-07 19:53:00 +000078
Krzysztof Parzyszek0bbad0f2016-08-10 18:05:47 +000079 if (Opc == Hexagon::CONST32) {
80 unsigned DestReg = MI.getOperand(0).getReg();
81 uint64_t ImmValue = MI.getOperand(1).getImm();
82 const DebugLoc &DL = MI.getDebugLoc();
83 BuildMI(B, MI, DL, TII->get(Hexagon::A2_tfrsi), DestReg)
Duncan P. N. Exon Smith98226e32016-07-12 01:55:32 +000084 .addImm(ImmValue);
Krzysztof Parzyszek0bbad0f2016-08-10 18:05:47 +000085 B.erase(&MI);
86 } else if (Opc == Hexagon::CONST64) {
87 unsigned DestReg = MI.getOperand(0).getReg();
Krzysztof Parzyszeka3386502016-08-10 16:46:36 +000088 int64_t ImmValue = MI.getOperand(1).getImm();
Krzysztof Parzyszek0bbad0f2016-08-10 18:05:47 +000089 const DebugLoc &DL = MI.getDebugLoc();
Colin LeMahieu54251092015-03-09 20:11:02 +000090 unsigned DestLo = TRI->getSubReg(DestReg, Hexagon::subreg_loreg);
91 unsigned DestHi = TRI->getSubReg(DestReg, Hexagon::subreg_hireg);
Jyotsna Verma5eb59802013-05-07 19:53:00 +000092
93 int32_t LowWord = (ImmValue & 0xFFFFFFFF);
94 int32_t HighWord = (ImmValue >> 32) & 0xFFFFFFFF;
95
Krzysztof Parzyszek0bbad0f2016-08-10 18:05:47 +000096 BuildMI(B, MI, DL, TII->get(Hexagon::A2_tfrsi), DestLo)
Duncan P. N. Exon Smith98226e32016-07-12 01:55:32 +000097 .addImm(LowWord);
Krzysztof Parzyszek0bbad0f2016-08-10 18:05:47 +000098 BuildMI(B, MI, DL, TII->get(Hexagon::A2_tfrsi), DestHi)
Duncan P. N. Exon Smith98226e32016-07-12 01:55:32 +000099 .addImm(HighWord);
Krzysztof Parzyszek0bbad0f2016-08-10 18:05:47 +0000100 B.erase(&MI);
Colin LeMahieu54251092015-03-09 20:11:02 +0000101 }
Jyotsna Verma5eb59802013-05-07 19:53:00 +0000102 }
103 }
104
105 return true;
106}
107
Jyotsna Verma5eb59802013-05-07 19:53:00 +0000108
109//===----------------------------------------------------------------------===//
110// Public Constructor Functions
111//===----------------------------------------------------------------------===//
112
Krzysztof Parzyszek0bbad0f2016-08-10 18:05:47 +0000113FunctionPass *llvm::createHexagonSplitConst32AndConst64() {
Eric Christopher01f875e2015-02-02 22:11:43 +0000114 return new HexagonSplitConst32AndConst64();
Jyotsna Verma5eb59802013-05-07 19:53:00 +0000115}