2011-12-14 10:11:42 +08:00
|
|
|
//===-- lib/CodeGen/MachineInstrBundle.cpp --------------------------------===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// 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
|
2011-12-14 10:11:42 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/CodeGen/MachineInstrBundle.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/ADT/SmallSet.h"
|
|
|
|
#include "llvm/ADT/SmallVector.h"
|
|
|
|
#include "llvm/CodeGen/MachineFunctionPass.h"
|
2011-12-14 10:11:42 +08:00
|
|
|
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
|
|
|
#include "llvm/CodeGen/Passes.h"
|
2017-11-08 09:01:31 +08:00
|
|
|
#include "llvm/CodeGen/TargetInstrInfo.h"
|
2017-11-17 09:07:10 +08:00
|
|
|
#include "llvm/CodeGen/TargetRegisterInfo.h"
|
|
|
|
#include "llvm/CodeGen/TargetSubtargetInfo.h"
|
Sink all InitializePasses.h includes
This file lists every pass in LLVM, and is included by Pass.h, which is
very popular. Every time we add, remove, or rename a pass in LLVM, it
caused lots of recompilation.
I found this fact by looking at this table, which is sorted by the
number of times a file was changed over the last 100,000 git commits
multiplied by the number of object files that depend on it in the
current checkout:
recompiles touches affected_files header
342380 95 3604 llvm/include/llvm/ADT/STLExtras.h
314730 234 1345 llvm/include/llvm/InitializePasses.h
307036 118 2602 llvm/include/llvm/ADT/APInt.h
213049 59 3611 llvm/include/llvm/Support/MathExtras.h
170422 47 3626 llvm/include/llvm/Support/Compiler.h
162225 45 3605 llvm/include/llvm/ADT/Optional.h
158319 63 2513 llvm/include/llvm/ADT/Triple.h
140322 39 3598 llvm/include/llvm/ADT/StringRef.h
137647 59 2333 llvm/include/llvm/Support/Error.h
131619 73 1803 llvm/include/llvm/Support/FileSystem.h
Before this change, touching InitializePasses.h would cause 1345 files
to recompile. After this change, touching it only causes 550 compiles in
an incremental rebuild.
Reviewers: bkramer, asbirlea, bollu, jdoerfert
Differential Revision: https://reviews.llvm.org/D70211
2019-11-14 05:15:01 +08:00
|
|
|
#include "llvm/InitializePasses.h"
|
2011-12-14 10:11:42 +08:00
|
|
|
#include "llvm/Target/TargetMachine.h"
|
2016-05-27 22:27:24 +08:00
|
|
|
#include <utility>
|
2011-12-14 10:11:42 +08:00
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
class UnpackMachineBundles : public MachineFunctionPass {
|
|
|
|
public:
|
|
|
|
static char ID; // Pass identification
|
2016-10-25 07:23:02 +08:00
|
|
|
UnpackMachineBundles(
|
|
|
|
std::function<bool(const MachineFunction &)> Ftor = nullptr)
|
2016-05-27 22:27:24 +08:00
|
|
|
: MachineFunctionPass(ID), PredicateFtor(std::move(Ftor)) {
|
2011-12-14 10:11:42 +08:00
|
|
|
initializeUnpackMachineBundlesPass(*PassRegistry::getPassRegistry());
|
|
|
|
}
|
|
|
|
|
2014-03-07 17:26:03 +08:00
|
|
|
bool runOnMachineFunction(MachineFunction &MF) override;
|
2015-06-09 02:50:43 +08:00
|
|
|
|
|
|
|
private:
|
2016-10-25 07:23:02 +08:00
|
|
|
std::function<bool(const MachineFunction &)> PredicateFtor;
|
2011-12-14 10:11:42 +08:00
|
|
|
};
|
|
|
|
} // end anonymous namespace
|
|
|
|
|
|
|
|
char UnpackMachineBundles::ID = 0;
|
2012-02-09 05:23:13 +08:00
|
|
|
char &llvm::UnpackMachineBundlesID = UnpackMachineBundles::ID;
|
2012-01-19 15:47:03 +08:00
|
|
|
INITIALIZE_PASS(UnpackMachineBundles, "unpack-mi-bundles",
|
2011-12-14 10:11:42 +08:00
|
|
|
"Unpack machine instruction bundles", false, false)
|
|
|
|
|
|
|
|
bool UnpackMachineBundles::runOnMachineFunction(MachineFunction &MF) {
|
2016-10-25 07:23:02 +08:00
|
|
|
if (PredicateFtor && !PredicateFtor(MF))
|
2015-06-09 02:50:43 +08:00
|
|
|
return false;
|
|
|
|
|
2011-12-14 10:11:42 +08:00
|
|
|
bool Changed = false;
|
|
|
|
for (MachineFunction::iterator I = MF.begin(), E = MF.end(); I != E; ++I) {
|
|
|
|
MachineBasicBlock *MBB = &*I;
|
|
|
|
|
|
|
|
for (MachineBasicBlock::instr_iterator MII = MBB->instr_begin(),
|
|
|
|
MIE = MBB->instr_end(); MII != MIE; ) {
|
|
|
|
MachineInstr *MI = &*MII;
|
|
|
|
|
|
|
|
// Remove BUNDLE instruction and the InsideBundle flags from bundled
|
|
|
|
// instructions.
|
|
|
|
if (MI->isBundle()) {
|
2012-12-14 07:23:46 +08:00
|
|
|
while (++MII != MIE && MII->isBundledWithPred()) {
|
|
|
|
MII->unbundleFromPred();
|
2011-12-14 10:11:42 +08:00
|
|
|
for (unsigned i = 0, e = MII->getNumOperands(); i != e; ++i) {
|
|
|
|
MachineOperand &MO = MII->getOperand(i);
|
|
|
|
if (MO.isReg() && MO.isInternalRead())
|
|
|
|
MO.setIsInternalRead(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
MI->eraseFromParent();
|
|
|
|
|
|
|
|
Changed = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
++MII;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Changed;
|
|
|
|
}
|
|
|
|
|
2015-06-09 02:50:43 +08:00
|
|
|
FunctionPass *
|
2016-10-25 07:23:02 +08:00
|
|
|
llvm::createUnpackMachineBundles(
|
|
|
|
std::function<bool(const MachineFunction &)> Ftor) {
|
2016-06-13 00:13:55 +08:00
|
|
|
return new UnpackMachineBundles(std::move(Ftor));
|
2015-06-09 02:50:43 +08:00
|
|
|
}
|
2012-01-19 15:47:03 +08:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
class FinalizeMachineBundles : public MachineFunctionPass {
|
|
|
|
public:
|
|
|
|
static char ID; // Pass identification
|
|
|
|
FinalizeMachineBundles() : MachineFunctionPass(ID) {
|
|
|
|
initializeFinalizeMachineBundlesPass(*PassRegistry::getPassRegistry());
|
|
|
|
}
|
|
|
|
|
2014-03-07 17:26:03 +08:00
|
|
|
bool runOnMachineFunction(MachineFunction &MF) override;
|
2012-01-19 15:47:03 +08:00
|
|
|
};
|
|
|
|
} // end anonymous namespace
|
|
|
|
|
|
|
|
char FinalizeMachineBundles::ID = 0;
|
2012-02-09 05:23:13 +08:00
|
|
|
char &llvm::FinalizeMachineBundlesID = FinalizeMachineBundles::ID;
|
2012-01-19 15:47:03 +08:00
|
|
|
INITIALIZE_PASS(FinalizeMachineBundles, "finalize-mi-bundles",
|
|
|
|
"Finalize machine instruction bundles", false, false)
|
|
|
|
|
|
|
|
bool FinalizeMachineBundles::runOnMachineFunction(MachineFunction &MF) {
|
|
|
|
return llvm::finalizeBundles(MF);
|
|
|
|
}
|
|
|
|
|
2018-08-21 18:59:50 +08:00
|
|
|
/// Return the first found DebugLoc that has a DILocation, given a range of
|
|
|
|
/// instructions. The search range is from FirstMI to LastMI (exclusive). If no
|
|
|
|
/// DILocation is found, then an empty location is returned.
|
|
|
|
static DebugLoc getDebugLoc(MachineBasicBlock::instr_iterator FirstMI,
|
|
|
|
MachineBasicBlock::instr_iterator LastMI) {
|
|
|
|
for (auto MII = FirstMI; MII != LastMI; ++MII)
|
|
|
|
if (MII->getDebugLoc().get())
|
|
|
|
return MII->getDebugLoc();
|
|
|
|
return DebugLoc();
|
|
|
|
}
|
2012-01-19 15:47:03 +08:00
|
|
|
|
2012-01-19 08:06:10 +08:00
|
|
|
/// finalizeBundle - Finalize a machine instruction bundle which includes
|
2012-01-19 08:46:06 +08:00
|
|
|
/// a sequence of instructions starting from FirstMI to LastMI (exclusive).
|
2011-12-14 10:11:42 +08:00
|
|
|
/// This routine adds a BUNDLE instruction to represent the bundle, it adds
|
|
|
|
/// IsInternalRead markers to MachineOperands which are defined inside the
|
|
|
|
/// bundle, and it copies externally visible defs and uses to the BUNDLE
|
|
|
|
/// instruction.
|
2012-01-19 08:06:10 +08:00
|
|
|
void llvm::finalizeBundle(MachineBasicBlock &MBB,
|
2011-12-14 10:11:42 +08:00
|
|
|
MachineBasicBlock::instr_iterator FirstMI,
|
|
|
|
MachineBasicBlock::instr_iterator LastMI) {
|
2012-01-19 08:46:06 +08:00
|
|
|
assert(FirstMI != LastMI && "Empty bundle?");
|
2012-12-14 07:23:46 +08:00
|
|
|
MIBundleBuilder Bundle(MBB, FirstMI, LastMI);
|
2012-01-19 08:46:06 +08:00
|
|
|
|
2014-10-14 14:26:55 +08:00
|
|
|
MachineFunction &MF = *MBB.getParent();
|
|
|
|
const TargetInstrInfo *TII = MF.getSubtarget().getInstrInfo();
|
|
|
|
const TargetRegisterInfo *TRI = MF.getSubtarget().getRegisterInfo();
|
2011-12-14 10:11:42 +08:00
|
|
|
|
2014-10-14 14:26:55 +08:00
|
|
|
MachineInstrBuilder MIB =
|
2018-08-21 18:59:50 +08:00
|
|
|
BuildMI(MF, getDebugLoc(FirstMI, LastMI), TII->get(TargetOpcode::BUNDLE));
|
2012-12-14 07:23:46 +08:00
|
|
|
Bundle.prepend(MIB);
|
2011-12-14 10:11:42 +08:00
|
|
|
|
2012-09-18 02:31:15 +08:00
|
|
|
SmallVector<unsigned, 32> LocalDefs;
|
|
|
|
SmallSet<unsigned, 32> LocalDefSet;
|
2011-12-14 10:11:42 +08:00
|
|
|
SmallSet<unsigned, 8> DeadDefSet;
|
2012-09-18 02:31:15 +08:00
|
|
|
SmallSet<unsigned, 16> KilledDefSet;
|
2011-12-14 10:11:42 +08:00
|
|
|
SmallVector<unsigned, 8> ExternUses;
|
|
|
|
SmallSet<unsigned, 8> ExternUseSet;
|
|
|
|
SmallSet<unsigned, 8> KilledUseSet;
|
|
|
|
SmallSet<unsigned, 8> UndefUseSet;
|
|
|
|
SmallVector<MachineOperand*, 4> Defs;
|
2018-08-25 19:26:17 +08:00
|
|
|
for (auto MII = FirstMI; MII != LastMI; ++MII) {
|
|
|
|
for (unsigned i = 0, e = MII->getNumOperands(); i != e; ++i) {
|
|
|
|
MachineOperand &MO = MII->getOperand(i);
|
2011-12-14 10:11:42 +08:00
|
|
|
if (!MO.isReg())
|
|
|
|
continue;
|
|
|
|
if (MO.isDef()) {
|
|
|
|
Defs.push_back(&MO);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
Apply llvm-prefer-register-over-unsigned from clang-tidy to LLVM
Summary:
This clang-tidy check is looking for unsigned integer variables whose initializer
starts with an implicit cast from llvm::Register and changes the type of the
variable to llvm::Register (dropping the llvm:: where possible).
Partial reverts in:
X86FrameLowering.cpp - Some functions return unsigned and arguably should be MCRegister
X86FixupLEAs.cpp - Some functions return unsigned and arguably should be MCRegister
X86FrameLowering.cpp - Some functions return unsigned and arguably should be MCRegister
HexagonBitSimplify.cpp - Function takes BitTracker::RegisterRef which appears to be unsigned&
MachineVerifier.cpp - Ambiguous operator==() given MCRegister and const Register
PPCFastISel.cpp - No Register::operator-=()
PeepholeOptimizer.cpp - TargetInstrInfo::optimizeLoadInstr() takes an unsigned&
MachineTraceMetrics.cpp - MachineTraceMetrics lacks a suitable constructor
Manual fixups in:
ARMFastISel.cpp - ARMEmitLoad() now takes a Register& instead of unsigned&
HexagonSplitDouble.cpp - Ternary operator was ambiguous between unsigned/Register
HexagonConstExtenders.cpp - Has a local class named Register, used llvm::Register instead of Register.
PPCFastISel.cpp - PPCEmitLoad() now takes a Register& instead of unsigned&
Depends on D65919
Reviewers: arsenm, bogner, craig.topper, RKSimon
Reviewed By: arsenm
Subscribers: RKSimon, craig.topper, lenary, aemerson, wuzish, jholewinski, MatzeB, qcolombet, dschuff, jyknight, dylanmckay, sdardis, nemanjai, jvesely, wdng, nhaehnle, sbc100, jgravelle-google, kristof.beyls, hiraditya, aheejin, kbarton, fedor.sergeev, javed.absar, asb, rbar, johnrusso, simoncook, apazos, sabuasal, niosHD, jrtc27, MaskRay, zzheng, edward-jones, atanasyan, rogfer01, MartinMosbeck, brucehoult, the_o, tpr, PkmX, jocewei, jsji, Petar.Avramovic, asbirlea, Jim, s.egerton, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65962
llvm-svn: 369041
2019-08-16 03:22:08 +08:00
|
|
|
Register Reg = MO.getReg();
|
2011-12-14 10:11:42 +08:00
|
|
|
if (!Reg)
|
|
|
|
continue;
|
2019-08-02 02:41:28 +08:00
|
|
|
|
2011-12-14 10:11:42 +08:00
|
|
|
if (LocalDefSet.count(Reg)) {
|
|
|
|
MO.setIsInternalRead();
|
|
|
|
if (MO.isKill())
|
|
|
|
// Internal def is now killed.
|
|
|
|
KilledDefSet.insert(Reg);
|
|
|
|
} else {
|
2014-11-19 15:49:26 +08:00
|
|
|
if (ExternUseSet.insert(Reg).second) {
|
2011-12-14 10:11:42 +08:00
|
|
|
ExternUses.push_back(Reg);
|
|
|
|
if (MO.isUndef())
|
|
|
|
UndefUseSet.insert(Reg);
|
|
|
|
}
|
|
|
|
if (MO.isKill())
|
|
|
|
// External def is now killed.
|
|
|
|
KilledUseSet.insert(Reg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (unsigned i = 0, e = Defs.size(); i != e; ++i) {
|
|
|
|
MachineOperand &MO = *Defs[i];
|
Apply llvm-prefer-register-over-unsigned from clang-tidy to LLVM
Summary:
This clang-tidy check is looking for unsigned integer variables whose initializer
starts with an implicit cast from llvm::Register and changes the type of the
variable to llvm::Register (dropping the llvm:: where possible).
Partial reverts in:
X86FrameLowering.cpp - Some functions return unsigned and arguably should be MCRegister
X86FixupLEAs.cpp - Some functions return unsigned and arguably should be MCRegister
X86FrameLowering.cpp - Some functions return unsigned and arguably should be MCRegister
HexagonBitSimplify.cpp - Function takes BitTracker::RegisterRef which appears to be unsigned&
MachineVerifier.cpp - Ambiguous operator==() given MCRegister and const Register
PPCFastISel.cpp - No Register::operator-=()
PeepholeOptimizer.cpp - TargetInstrInfo::optimizeLoadInstr() takes an unsigned&
MachineTraceMetrics.cpp - MachineTraceMetrics lacks a suitable constructor
Manual fixups in:
ARMFastISel.cpp - ARMEmitLoad() now takes a Register& instead of unsigned&
HexagonSplitDouble.cpp - Ternary operator was ambiguous between unsigned/Register
HexagonConstExtenders.cpp - Has a local class named Register, used llvm::Register instead of Register.
PPCFastISel.cpp - PPCEmitLoad() now takes a Register& instead of unsigned&
Depends on D65919
Reviewers: arsenm, bogner, craig.topper, RKSimon
Reviewed By: arsenm
Subscribers: RKSimon, craig.topper, lenary, aemerson, wuzish, jholewinski, MatzeB, qcolombet, dschuff, jyknight, dylanmckay, sdardis, nemanjai, jvesely, wdng, nhaehnle, sbc100, jgravelle-google, kristof.beyls, hiraditya, aheejin, kbarton, fedor.sergeev, javed.absar, asb, rbar, johnrusso, simoncook, apazos, sabuasal, niosHD, jrtc27, MaskRay, zzheng, edward-jones, atanasyan, rogfer01, MartinMosbeck, brucehoult, the_o, tpr, PkmX, jocewei, jsji, Petar.Avramovic, asbirlea, Jim, s.egerton, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65962
llvm-svn: 369041
2019-08-16 03:22:08 +08:00
|
|
|
Register Reg = MO.getReg();
|
2011-12-14 10:11:42 +08:00
|
|
|
if (!Reg)
|
|
|
|
continue;
|
|
|
|
|
2014-11-19 15:49:26 +08:00
|
|
|
if (LocalDefSet.insert(Reg).second) {
|
2011-12-14 10:11:42 +08:00
|
|
|
LocalDefs.push_back(Reg);
|
|
|
|
if (MO.isDead()) {
|
|
|
|
DeadDefSet.insert(Reg);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Re-defined inside the bundle, it's no longer killed.
|
|
|
|
KilledDefSet.erase(Reg);
|
|
|
|
if (!MO.isDead())
|
|
|
|
// Previously defined but dead.
|
|
|
|
DeadDefSet.erase(Reg);
|
|
|
|
}
|
|
|
|
|
2019-08-02 07:27:28 +08:00
|
|
|
if (!MO.isDead() && Register::isPhysicalRegister(Reg)) {
|
2012-06-02 07:28:30 +08:00
|
|
|
for (MCSubRegIterator SubRegs(Reg, TRI); SubRegs.isValid(); ++SubRegs) {
|
|
|
|
unsigned SubReg = *SubRegs;
|
2014-11-19 15:49:26 +08:00
|
|
|
if (LocalDefSet.insert(SubReg).second)
|
2011-12-14 10:11:42 +08:00
|
|
|
LocalDefs.push_back(SubReg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Defs.clear();
|
2012-01-19 08:46:06 +08:00
|
|
|
}
|
2011-12-14 10:11:42 +08:00
|
|
|
|
2012-09-18 02:31:15 +08:00
|
|
|
SmallSet<unsigned, 32> Added;
|
2011-12-14 10:11:42 +08:00
|
|
|
for (unsigned i = 0, e = LocalDefs.size(); i != e; ++i) {
|
|
|
|
unsigned Reg = LocalDefs[i];
|
2014-11-19 15:49:26 +08:00
|
|
|
if (Added.insert(Reg).second) {
|
2011-12-14 10:11:42 +08:00
|
|
|
// If it's not live beyond end of the bundle, mark it dead.
|
|
|
|
bool isDead = DeadDefSet.count(Reg) || KilledDefSet.count(Reg);
|
|
|
|
MIB.addReg(Reg, getDefRegState(true) | getDeadRegState(isDead) |
|
|
|
|
getImplRegState(true));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (unsigned i = 0, e = ExternUses.size(); i != e; ++i) {
|
|
|
|
unsigned Reg = ExternUses[i];
|
|
|
|
bool isKill = KilledUseSet.count(Reg);
|
|
|
|
bool isUndef = UndefUseSet.count(Reg);
|
|
|
|
MIB.addReg(Reg, getKillRegState(isKill) | getUndefRegState(isUndef) |
|
|
|
|
getImplRegState(true));
|
|
|
|
}
|
2018-08-25 19:26:17 +08:00
|
|
|
|
|
|
|
// Set FrameSetup/FrameDestroy for the bundle. If any of the instructions got
|
|
|
|
// the property, then also set it on the bundle.
|
|
|
|
for (auto MII = FirstMI; MII != LastMI; ++MII) {
|
|
|
|
if (MII->getFlag(MachineInstr::FrameSetup))
|
|
|
|
MIB.setMIFlag(MachineInstr::FrameSetup);
|
|
|
|
if (MII->getFlag(MachineInstr::FrameDestroy))
|
|
|
|
MIB.setMIFlag(MachineInstr::FrameDestroy);
|
|
|
|
}
|
2011-12-14 10:11:42 +08:00
|
|
|
}
|
2012-01-19 08:46:06 +08:00
|
|
|
|
|
|
|
/// finalizeBundle - Same functionality as the previous finalizeBundle except
|
|
|
|
/// the last instruction in the bundle is not provided as an input. This is
|
|
|
|
/// used in cases where bundles are pre-determined by marking instructions
|
2012-01-19 14:13:10 +08:00
|
|
|
/// with 'InsideBundle' marker. It returns the MBB instruction iterator that
|
|
|
|
/// points to the end of the bundle.
|
|
|
|
MachineBasicBlock::instr_iterator
|
|
|
|
llvm::finalizeBundle(MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock::instr_iterator FirstMI) {
|
2012-01-19 08:46:06 +08:00
|
|
|
MachineBasicBlock::instr_iterator E = MBB.instr_end();
|
2014-03-02 20:27:27 +08:00
|
|
|
MachineBasicBlock::instr_iterator LastMI = std::next(FirstMI);
|
2012-01-19 08:46:06 +08:00
|
|
|
while (LastMI != E && LastMI->isInsideBundle())
|
|
|
|
++LastMI;
|
|
|
|
finalizeBundle(MBB, FirstMI, LastMI);
|
2012-01-19 14:13:10 +08:00
|
|
|
return LastMI;
|
2012-01-19 08:46:06 +08:00
|
|
|
}
|
2012-01-19 15:47:03 +08:00
|
|
|
|
|
|
|
/// finalizeBundles - Finalize instruction bundles in the specified
|
|
|
|
/// MachineFunction. Return true if any bundles are finalized.
|
|
|
|
bool llvm::finalizeBundles(MachineFunction &MF) {
|
|
|
|
bool Changed = false;
|
|
|
|
for (MachineFunction::iterator I = MF.begin(), E = MF.end(); I != E; ++I) {
|
|
|
|
MachineBasicBlock &MBB = *I;
|
|
|
|
MachineBasicBlock::instr_iterator MII = MBB.instr_begin();
|
|
|
|
MachineBasicBlock::instr_iterator MIE = MBB.instr_end();
|
2012-03-06 10:00:52 +08:00
|
|
|
if (MII == MIE)
|
|
|
|
continue;
|
2013-01-05 06:17:31 +08:00
|
|
|
assert(!MII->isInsideBundle() &&
|
|
|
|
"First instr cannot be inside bundle before finalization!");
|
|
|
|
|
2012-01-19 15:47:03 +08:00
|
|
|
for (++MII; MII != MIE; ) {
|
|
|
|
if (!MII->isInsideBundle())
|
|
|
|
++MII;
|
|
|
|
else {
|
2014-03-02 20:27:27 +08:00
|
|
|
MII = finalizeBundle(MBB, std::prev(MII));
|
2012-01-19 15:47:03 +08:00
|
|
|
Changed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Changed;
|
|
|
|
}
|
2012-02-29 09:40:37 +08:00
|
|
|
|
2019-12-03 03:41:09 +08:00
|
|
|
VirtRegInfo llvm::AnalyzeVirtRegInBundle(
|
|
|
|
MachineInstr &MI, unsigned Reg,
|
|
|
|
SmallVectorImpl<std::pair<MachineInstr *, unsigned>> *Ops) {
|
|
|
|
VirtRegInfo RI = {false, false, false};
|
|
|
|
for (MIBundleOperands O(MI); O.isValid(); ++O) {
|
|
|
|
MachineOperand &MO = *O;
|
2012-02-29 09:40:37 +08:00
|
|
|
if (!MO.isReg() || MO.getReg() != Reg)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Remember each (MI, OpNo) that refers to Reg.
|
|
|
|
if (Ops)
|
2019-12-03 03:41:09 +08:00
|
|
|
Ops->push_back(std::make_pair(MO.getParent(), O.getOperandNo()));
|
2012-02-29 09:40:37 +08:00
|
|
|
|
|
|
|
// Both defs and uses can read virtual registers.
|
|
|
|
if (MO.readsReg()) {
|
|
|
|
RI.Reads = true;
|
|
|
|
if (MO.isDef())
|
|
|
|
RI.Tied = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Only defs can write.
|
|
|
|
if (MO.isDef())
|
|
|
|
RI.Writes = true;
|
2019-12-03 03:41:09 +08:00
|
|
|
else if (!RI.Tied &&
|
|
|
|
MO.getParent()->isRegTiedToDefOperand(O.getOperandNo()))
|
2012-02-29 09:40:37 +08:00
|
|
|
RI.Tied = true;
|
|
|
|
}
|
|
|
|
return RI;
|
|
|
|
}
|
2012-09-12 18:03:31 +08:00
|
|
|
|
2019-12-03 04:00:56 +08:00
|
|
|
PhysRegInfo llvm::AnalyzePhysRegInBundle(const MachineInstr &MI, unsigned Reg,
|
|
|
|
const TargetRegisterInfo *TRI) {
|
2012-09-12 18:03:31 +08:00
|
|
|
bool AllDefsDead = true;
|
2016-04-27 07:14:24 +08:00
|
|
|
PhysRegInfo PRI = {false, false, false, false, false, false, false, false};
|
2012-09-12 18:03:31 +08:00
|
|
|
|
2019-08-02 07:27:28 +08:00
|
|
|
assert(Register::isPhysicalRegister(Reg) &&
|
2012-09-12 18:03:31 +08:00
|
|
|
"analyzePhysReg not given a physical register!");
|
2019-12-03 04:00:56 +08:00
|
|
|
for (ConstMIBundleOperands O(MI); O.isValid(); ++O) {
|
|
|
|
const MachineOperand &MO = *O;
|
2012-09-12 18:03:31 +08:00
|
|
|
|
2015-12-12 03:42:09 +08:00
|
|
|
if (MO.isRegMask() && MO.clobbersPhysReg(Reg)) {
|
|
|
|
PRI.Clobbered = true;
|
|
|
|
continue;
|
|
|
|
}
|
2012-09-12 18:03:31 +08:00
|
|
|
|
|
|
|
if (!MO.isReg())
|
|
|
|
continue;
|
|
|
|
|
Apply llvm-prefer-register-over-unsigned from clang-tidy to LLVM
Summary:
This clang-tidy check is looking for unsigned integer variables whose initializer
starts with an implicit cast from llvm::Register and changes the type of the
variable to llvm::Register (dropping the llvm:: where possible).
Partial reverts in:
X86FrameLowering.cpp - Some functions return unsigned and arguably should be MCRegister
X86FixupLEAs.cpp - Some functions return unsigned and arguably should be MCRegister
X86FrameLowering.cpp - Some functions return unsigned and arguably should be MCRegister
HexagonBitSimplify.cpp - Function takes BitTracker::RegisterRef which appears to be unsigned&
MachineVerifier.cpp - Ambiguous operator==() given MCRegister and const Register
PPCFastISel.cpp - No Register::operator-=()
PeepholeOptimizer.cpp - TargetInstrInfo::optimizeLoadInstr() takes an unsigned&
MachineTraceMetrics.cpp - MachineTraceMetrics lacks a suitable constructor
Manual fixups in:
ARMFastISel.cpp - ARMEmitLoad() now takes a Register& instead of unsigned&
HexagonSplitDouble.cpp - Ternary operator was ambiguous between unsigned/Register
HexagonConstExtenders.cpp - Has a local class named Register, used llvm::Register instead of Register.
PPCFastISel.cpp - PPCEmitLoad() now takes a Register& instead of unsigned&
Depends on D65919
Reviewers: arsenm, bogner, craig.topper, RKSimon
Reviewed By: arsenm
Subscribers: RKSimon, craig.topper, lenary, aemerson, wuzish, jholewinski, MatzeB, qcolombet, dschuff, jyknight, dylanmckay, sdardis, nemanjai, jvesely, wdng, nhaehnle, sbc100, jgravelle-google, kristof.beyls, hiraditya, aheejin, kbarton, fedor.sergeev, javed.absar, asb, rbar, johnrusso, simoncook, apazos, sabuasal, niosHD, jrtc27, MaskRay, zzheng, edward-jones, atanasyan, rogfer01, MartinMosbeck, brucehoult, the_o, tpr, PkmX, jocewei, jsji, Petar.Avramovic, asbirlea, Jim, s.egerton, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65962
llvm-svn: 369041
2019-08-16 03:22:08 +08:00
|
|
|
Register MOReg = MO.getReg();
|
2019-08-02 07:27:28 +08:00
|
|
|
if (!MOReg || !Register::isPhysicalRegister(MOReg))
|
2012-09-12 18:03:31 +08:00
|
|
|
continue;
|
|
|
|
|
2015-12-12 03:42:09 +08:00
|
|
|
if (!TRI->regsOverlap(MOReg, Reg))
|
2012-09-12 18:03:31 +08:00
|
|
|
continue;
|
|
|
|
|
2016-01-05 08:45:35 +08:00
|
|
|
bool Covered = TRI->isSuperRegisterEq(Reg, MOReg);
|
2015-12-12 03:42:09 +08:00
|
|
|
if (MO.readsReg()) {
|
|
|
|
PRI.Read = true;
|
|
|
|
if (Covered) {
|
|
|
|
PRI.FullyRead = true;
|
|
|
|
if (MO.isKill())
|
|
|
|
PRI.Killed = true;
|
|
|
|
}
|
|
|
|
} else if (MO.isDef()) {
|
|
|
|
PRI.Defined = true;
|
|
|
|
if (Covered)
|
|
|
|
PRI.FullyDefined = true;
|
2012-09-12 18:03:31 +08:00
|
|
|
if (!MO.isDead())
|
|
|
|
AllDefsDead = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-27 07:14:24 +08:00
|
|
|
if (AllDefsDead) {
|
|
|
|
if (PRI.FullyDefined || PRI.Clobbered)
|
|
|
|
PRI.DeadDef = true;
|
2016-04-27 08:16:29 +08:00
|
|
|
else if (PRI.Defined)
|
2016-04-27 07:14:24 +08:00
|
|
|
PRI.PartialDeadDef = true;
|
|
|
|
}
|
2012-09-12 18:03:31 +08:00
|
|
|
|
|
|
|
return PRI;
|
|
|
|
}
|