Mercurial > hg > CbC > CbC_llvm
diff lib/Target/Hexagon/HexagonSplitDouble.cpp @ 148:63bd29f05246
merged
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 14 Aug 2019 19:46:37 +0900 |
parents | c2174574ed3a |
children |
line wrap: on
line diff
--- a/lib/Target/Hexagon/HexagonSplitDouble.cpp Sun Dec 23 19:23:36 2018 +0900 +++ b/lib/Target/Hexagon/HexagonSplitDouble.cpp Wed Aug 14 19:46:37 2019 +0900 @@ -1,9 +1,8 @@ //===- HexagonSplitDouble.cpp ---------------------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -26,6 +25,7 @@ #include "llvm/CodeGen/MachineOperand.h" #include "llvm/CodeGen/MachineRegisterInfo.h" #include "llvm/CodeGen/TargetRegisterInfo.h" +#include "llvm/Config/llvm-config.h" #include "llvm/IR/DebugLoc.h" #include "llvm/Pass.h" #include "llvm/Support/CommandLine.h" @@ -55,6 +55,8 @@ cl::desc("Maximum number of split partitions")); static cl::opt<bool> MemRefsFixed("hsdr-no-mem", cl::Hidden, cl::init(true), cl::desc("Do not split loads or stores")); + static cl::opt<bool> SplitAll("hsdr-split-all", cl::Hidden, cl::init(false), + cl::desc("Split all partitions")); namespace { @@ -62,9 +64,7 @@ public: static char ID; - HexagonSplitDoubleRegs() : MachineFunctionPass(ID) { - initializeHexagonSplitDoubleRegsPass(*PassRegistry::getPassRegistry()); - } + HexagonSplitDoubleRegs() : MachineFunctionPass(ID) {} StringRef getPassName() const override { return "Hexagon Split Double Registers"; @@ -97,6 +97,7 @@ bool isFixedInstr(const MachineInstr *MI) const; void partitionRegisters(UUSetMap &P2Rs); int32_t profit(const MachineInstr *MI) const; + int32_t profit(unsigned Reg) const; bool isProfitable(const USet &Part, LoopRegMap &IRM) const; void collectIndRegsForLoop(const MachineLoop *L, USet &Rs); @@ -151,8 +152,8 @@ } bool HexagonSplitDoubleRegs::isVolatileInstr(const MachineInstr *MI) const { - for (auto &I : MI->memoperands()) - if (I->isVolatile()) + for (auto &MO : MI->memoperands()) + if (MO->isVolatile() || MO->isAtomic()) return true; return false; } @@ -161,7 +162,7 @@ if (MI->mayLoad() || MI->mayStore()) if (MemRefsFixed || isVolatileInstr(MI)) return true; - if (MI->isDebugValue()) + if (MI->isDebugInstr()) return false; unsigned Opc = MI->getOpcode(); @@ -210,7 +211,7 @@ if (!Op.isReg()) continue; unsigned R = Op.getReg(); - if (!TargetRegisterInfo::isVirtualRegister(R)) + if (!Register::isVirtualRegister(R)) return true; } return false; @@ -223,14 +224,14 @@ unsigned NumRegs = MRI->getNumVirtRegs(); BitVector DoubleRegs(NumRegs); for (unsigned i = 0; i < NumRegs; ++i) { - unsigned R = TargetRegisterInfo::index2VirtReg(i); + unsigned R = Register::index2VirtReg(i); if (MRI->getRegClass(R) == DoubleRC) DoubleRegs.set(i); } BitVector FixedRegs(NumRegs); for (int x = DoubleRegs.find_first(); x >= 0; x = DoubleRegs.find_next(x)) { - unsigned R = TargetRegisterInfo::index2VirtReg(x); + unsigned R = Register::index2VirtReg(x); MachineInstr *DefI = MRI->getVRegDef(R); // In some cases a register may exist, but never be defined or used. // It should never appear anywhere, but mark it as "fixed", just to be @@ -243,8 +244,8 @@ for (int x = DoubleRegs.find_first(); x >= 0; x = DoubleRegs.find_next(x)) { if (FixedRegs[x]) continue; - unsigned R = TargetRegisterInfo::index2VirtReg(x); - DEBUG(dbgs() << printReg(R, TRI) << " ~~"); + unsigned R = Register::index2VirtReg(x); + LLVM_DEBUG(dbgs() << printReg(R, TRI) << " ~~"); USet &Asc = AssocMap[R]; for (auto U = MRI->use_nodbg_begin(R), Z = MRI->use_nodbg_end(); U != Z; ++U) { @@ -258,29 +259,29 @@ if (&MO == &Op || !MO.isReg() || MO.getSubReg()) continue; unsigned T = MO.getReg(); - if (!TargetRegisterInfo::isVirtualRegister(T)) { + if (!Register::isVirtualRegister(T)) { FixedRegs.set(x); continue; } if (MRI->getRegClass(T) != DoubleRC) continue; - unsigned u = TargetRegisterInfo::virtReg2Index(T); + unsigned u = Register::virtReg2Index(T); if (FixedRegs[u]) continue; - DEBUG(dbgs() << ' ' << printReg(T, TRI)); + LLVM_DEBUG(dbgs() << ' ' << printReg(T, TRI)); Asc.insert(T); // Make it symmetric. AssocMap[T].insert(R); } } - DEBUG(dbgs() << '\n'); + LLVM_DEBUG(dbgs() << '\n'); } UUMap R2P; unsigned NextP = 1; USet Visited; for (int x = DoubleRegs.find_first(); x >= 0; x = DoubleRegs.find_next(x)) { - unsigned R = TargetRegisterInfo::index2VirtReg(x); + unsigned R = Register::index2VirtReg(x); if (Visited.count(R)) continue; // Create a new partition for R. @@ -304,15 +305,10 @@ P2Rs[I.second].insert(I.first); } -static inline int32_t profitImm(unsigned Lo, unsigned Hi) { +static inline int32_t profitImm(unsigned Imm) { int32_t P = 0; - bool LoZ1 = false, HiZ1 = false; - if (Lo == 0 || Lo == 0xFFFFFFFF) - P += 10, LoZ1 = true; - if (Hi == 0 || Hi == 0xFFFFFFFF) - P += 10, HiZ1 = true; - if (!LoZ1 && !HiZ1 && Lo == Hi) - P += 3; + if (Imm == 0 || Imm == 0xFFFFFFFF) + P += 10; return P; } @@ -342,21 +338,28 @@ uint64_t D = MI->getOperand(1).getImm(); unsigned Lo = D & 0xFFFFFFFFULL; unsigned Hi = D >> 32; - return profitImm(Lo, Hi); + return profitImm(Lo) + profitImm(Hi); } case Hexagon::A2_combineii: - case Hexagon::A4_combineii: - return profitImm(MI->getOperand(1).getImm(), - MI->getOperand(2).getImm()); + case Hexagon::A4_combineii: { + const MachineOperand &Op1 = MI->getOperand(1); + const MachineOperand &Op2 = MI->getOperand(2); + int32_t Prof1 = Op1.isImm() ? profitImm(Op1.getImm()) : 0; + int32_t Prof2 = Op2.isImm() ? profitImm(Op2.getImm()) : 0; + return Prof1 + Prof2; + } case Hexagon::A4_combineri: ImmX++; // Fall through into A4_combineir. LLVM_FALLTHROUGH; case Hexagon::A4_combineir: { ImmX++; - int64_t V = MI->getOperand(ImmX).getImm(); - if (V == 0 || V == -1) - return 10; + const MachineOperand &OpX = MI->getOperand(ImmX); + if (OpX.isImm()) { + int64_t V = OpX.getImm(); + if (V == 0 || V == -1) + return 10; + } // Fall through into A2_combinew. LLVM_FALLTHROUGH; } @@ -368,8 +371,11 @@ case Hexagon::A2_andp: case Hexagon::A2_orp: - case Hexagon::A2_xorp: - return 1; + case Hexagon::A2_xorp: { + unsigned Rs = MI->getOperand(1).getReg(); + unsigned Rt = MI->getOperand(2).getReg(); + return profit(Rs) + profit(Rt); + } case Hexagon::S2_asl_i_p_or: { unsigned S = MI->getOperand(3).getImm(); @@ -393,6 +399,25 @@ return 0; } +int32_t HexagonSplitDoubleRegs::profit(unsigned Reg) const { + assert(Register::isVirtualRegister(Reg)); + + const MachineInstr *DefI = MRI->getVRegDef(Reg); + switch (DefI->getOpcode()) { + case Hexagon::A2_tfrpi: + case Hexagon::CONST64: + case Hexagon::A2_combineii: + case Hexagon::A4_combineii: + case Hexagon::A4_combineri: + case Hexagon::A4_combineir: + case Hexagon::A2_combinew: + return profit(DefI); + default: + break; + } + return 0; +} + bool HexagonSplitDoubleRegs::isProfitable(const USet &Part, LoopRegMap &IRM) const { unsigned FixedNum = 0, LoopPhiNum = 0; @@ -442,7 +467,9 @@ if (FixedNum > 0 && LoopPhiNum > 0) TotalP -= 20*LoopPhiNum; - DEBUG(dbgs() << "Partition profit: " << TotalP << '\n'); + LLVM_DEBUG(dbgs() << "Partition profit: " << TotalP << '\n'); + if (SplitAll) + return true; return TotalP > 0; } @@ -535,7 +562,7 @@ Rs.insert(CmpR1); Rs.insert(CmpR2); - DEBUG({ + LLVM_DEBUG({ dbgs() << "For loop at " << printMBBReference(*HB) << " ind regs: "; dump_partition(dbgs(), Rs, *TRI); dbgs() << '\n'; @@ -578,7 +605,7 @@ // For register operands, set the subregister. unsigned R = Op.getReg(); unsigned SR = Op.getSubReg(); - bool isVirtReg = TargetRegisterInfo::isVirtualRegister(R); + bool isVirtReg = Register::isVirtualRegister(R); bool isKill = Op.isKill(); if (isVirtReg && MRI->getRegClass(R) == DoubleRC) { isKill = false; @@ -710,23 +737,21 @@ assert(F != PairMap.end()); const UUPair &P = F->second; - if (Op1.isImm()) { + if (!Op1.isReg()) { BuildMI(B, MI, DL, TII->get(Hexagon::A2_tfrsi), P.second) - .addImm(Op1.getImm()); - } else if (Op1.isReg()) { + .add(Op1); + } else { BuildMI(B, MI, DL, TII->get(TargetOpcode::COPY), P.second) .addReg(Op1.getReg(), getRegState(Op1), Op1.getSubReg()); - } else - llvm_unreachable("Unexpected operand"); + } - if (Op2.isImm()) { + if (!Op2.isReg()) { BuildMI(B, MI, DL, TII->get(Hexagon::A2_tfrsi), P.first) - .addImm(Op2.getImm()); - } else if (Op2.isReg()) { + .add(Op2); + } else { BuildMI(B, MI, DL, TII->get(TargetOpcode::COPY), P.first) .addReg(Op2.getReg(), getRegState(Op2), Op2.getSubReg()); - } else - llvm_unreachable("Unexpected operand"); + } } void HexagonSplitDoubleRegs::splitExt(MachineInstr *MI, @@ -970,7 +995,7 @@ const UUPairMap &PairMap) { using namespace Hexagon; - DEBUG(dbgs() << "Splitting: " << *MI); + LLVM_DEBUG(dbgs() << "Splitting: " << *MI); bool Split = false; unsigned Opc = MI->getOpcode(); @@ -1080,7 +1105,7 @@ if (!Op.isReg() || !Op.isUse()) continue; unsigned R = Op.getReg(); - if (!TargetRegisterInfo::isVirtualRegister(R)) + if (!Register::isVirtualRegister(R)) continue; if (MRI->getRegClass(R) != DoubleRC || Op.getSubReg()) continue; @@ -1104,8 +1129,8 @@ const TargetRegisterClass *IntRC = &Hexagon::IntRegsRegClass; bool Changed = false; - DEBUG(dbgs() << "Splitting partition: "; dump_partition(dbgs(), Part, *TRI); - dbgs() << '\n'); + LLVM_DEBUG(dbgs() << "Splitting partition: "; + dump_partition(dbgs(), Part, *TRI); dbgs() << '\n'); UUPairMap PairMap; @@ -1122,8 +1147,9 @@ unsigned LoR = MRI->createVirtualRegister(IntRC); unsigned HiR = MRI->createVirtualRegister(IntRC); - DEBUG(dbgs() << "Created mapping: " << printReg(DR, TRI) << " -> " - << printReg(HiR, TRI) << ':' << printReg(LoR, TRI) << '\n'); + LLVM_DEBUG(dbgs() << "Created mapping: " << printReg(DR, TRI) << " -> " + << printReg(HiR, TRI) << ':' << printReg(LoR, TRI) + << '\n'); PairMap.insert(std::make_pair(DR, UUPair(LoR, HiR))); } @@ -1160,12 +1186,12 @@ } bool HexagonSplitDoubleRegs::runOnMachineFunction(MachineFunction &MF) { - DEBUG(dbgs() << "Splitting double registers in function: " - << MF.getName() << '\n'); - if (skipFunction(MF.getFunction())) return false; + LLVM_DEBUG(dbgs() << "Splitting double registers in function: " + << MF.getName() << '\n'); + auto &ST = MF.getSubtarget<HexagonSubtarget>(); TRI = ST.getRegisterInfo(); TII = ST.getInstrInfo(); @@ -1178,7 +1204,7 @@ collectIndRegs(IRM); partitionRegisters(P2Rs); - DEBUG({ + LLVM_DEBUG({ dbgs() << "Register partitioning: (partition #0 is fixed)\n"; for (UUSetMap::iterator I = P2Rs.begin(), E = P2Rs.end(); I != E; ++I) { dbgs() << '#' << I->first << " -> "; @@ -1196,7 +1222,8 @@ if (Limit >= 0 && Counter >= Limit) break; USet &Part = I->second; - DEBUG(dbgs() << "Calculating profit for partition #" << I->first << '\n'); + LLVM_DEBUG(dbgs() << "Calculating profit for partition #" << I->first + << '\n'); if (!isProfitable(Part, IRM)) continue; Counter++;