2017-08-24 23:21:39 +02:00
|
|
|
//===- LiveRangeShrink.cpp - Move instructions to shrink live range -------===//
|
Add LiveRangeShrink pass to shrink live range within BB.
Summary: LiveRangeShrink pass moves instruction right after the definition with the same BB if the instruction and its operands all have more than one use. This pass is inexpensive and guarantees optimal live-range within BB.
Reviewers: davidxl, wmi, hfinkel, MatzeB, andreadb
Reviewed By: MatzeB, andreadb
Subscribers: hiraditya, jyknight, sanjoy, skatkov, gberry, jholewinski, qcolombet, javed.absar, krytarowski, atrick, spatel, RKSimon, andreadb, MatzeB, mehdi_amini, mgorny, efriedma, davide, dberlin, llvm-commits
Differential Revision: https://reviews.llvm.org/D32563
llvm-svn: 304371
2017-06-01 01:25:25 +02:00
|
|
|
//
|
2019-01-19 09:50:56 +01: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
|
Add LiveRangeShrink pass to shrink live range within BB.
Summary: LiveRangeShrink pass moves instruction right after the definition with the same BB if the instruction and its operands all have more than one use. This pass is inexpensive and guarantees optimal live-range within BB.
Reviewers: davidxl, wmi, hfinkel, MatzeB, andreadb
Reviewed By: MatzeB, andreadb
Subscribers: hiraditya, jyknight, sanjoy, skatkov, gberry, jholewinski, qcolombet, javed.absar, krytarowski, atrick, spatel, RKSimon, andreadb, MatzeB, mehdi_amini, mgorny, efriedma, davide, dberlin, llvm-commits
Differential Revision: https://reviews.llvm.org/D32563
llvm-svn: 304371
2017-06-01 01:25:25 +02:00
|
|
|
//
|
|
|
|
///===---------------------------------------------------------------------===//
|
|
|
|
///
|
|
|
|
/// \file
|
|
|
|
/// This pass moves instructions close to the definition of its operands to
|
|
|
|
/// shrink live range of the def instruction. The code motion is limited within
|
|
|
|
/// the basic block. The moved instruction should have 1 def, and more than one
|
|
|
|
/// uses, all of which are the only use of the def.
|
|
|
|
///
|
|
|
|
///===---------------------------------------------------------------------===//
|
2017-08-24 23:21:39 +02:00
|
|
|
|
|
|
|
#include "llvm/ADT/DenseMap.h"
|
Add LiveRangeShrink pass to shrink live range within BB.
Summary: LiveRangeShrink pass moves instruction right after the definition with the same BB if the instruction and its operands all have more than one use. This pass is inexpensive and guarantees optimal live-range within BB.
Reviewers: davidxl, wmi, hfinkel, MatzeB, andreadb
Reviewed By: MatzeB, andreadb
Subscribers: hiraditya, jyknight, sanjoy, skatkov, gberry, jholewinski, qcolombet, javed.absar, krytarowski, atrick, spatel, RKSimon, andreadb, MatzeB, mehdi_amini, mgorny, efriedma, davide, dberlin, llvm-commits
Differential Revision: https://reviews.llvm.org/D32563
llvm-svn: 304371
2017-06-01 01:25:25 +02:00
|
|
|
#include "llvm/ADT/Statistic.h"
|
2017-08-24 23:21:39 +02:00
|
|
|
#include "llvm/ADT/iterator_range.h"
|
|
|
|
#include "llvm/CodeGen/MachineBasicBlock.h"
|
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
Add LiveRangeShrink pass to shrink live range within BB.
Summary: LiveRangeShrink pass moves instruction right after the definition with the same BB if the instruction and its operands all have more than one use. This pass is inexpensive and guarantees optimal live-range within BB.
Reviewers: davidxl, wmi, hfinkel, MatzeB, andreadb
Reviewed By: MatzeB, andreadb
Subscribers: hiraditya, jyknight, sanjoy, skatkov, gberry, jholewinski, qcolombet, javed.absar, krytarowski, atrick, spatel, RKSimon, andreadb, MatzeB, mehdi_amini, mgorny, efriedma, davide, dberlin, llvm-commits
Differential Revision: https://reviews.llvm.org/D32563
llvm-svn: 304371
2017-06-01 01:25:25 +02:00
|
|
|
#include "llvm/CodeGen/MachineFunctionPass.h"
|
2017-08-24 23:21:39 +02:00
|
|
|
#include "llvm/CodeGen/MachineInstr.h"
|
|
|
|
#include "llvm/CodeGen/MachineOperand.h"
|
2017-11-17 02:07:10 +01:00
|
|
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
|
|
|
#include "llvm/CodeGen/TargetRegisterInfo.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-13 22:15:01 +01:00
|
|
|
#include "llvm/InitializePasses.h"
|
2017-08-24 23:21:39 +02:00
|
|
|
#include "llvm/Pass.h"
|
Add LiveRangeShrink pass to shrink live range within BB.
Summary: LiveRangeShrink pass moves instruction right after the definition with the same BB if the instruction and its operands all have more than one use. This pass is inexpensive and guarantees optimal live-range within BB.
Reviewers: davidxl, wmi, hfinkel, MatzeB, andreadb
Reviewed By: MatzeB, andreadb
Subscribers: hiraditya, jyknight, sanjoy, skatkov, gberry, jholewinski, qcolombet, javed.absar, krytarowski, atrick, spatel, RKSimon, andreadb, MatzeB, mehdi_amini, mgorny, efriedma, davide, dberlin, llvm-commits
Differential Revision: https://reviews.llvm.org/D32563
llvm-svn: 304371
2017-06-01 01:25:25 +02:00
|
|
|
#include "llvm/Support/Debug.h"
|
2017-08-24 23:21:39 +02:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
#include <iterator>
|
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
using namespace llvm;
|
Add LiveRangeShrink pass to shrink live range within BB.
Summary: LiveRangeShrink pass moves instruction right after the definition with the same BB if the instruction and its operands all have more than one use. This pass is inexpensive and guarantees optimal live-range within BB.
Reviewers: davidxl, wmi, hfinkel, MatzeB, andreadb
Reviewed By: MatzeB, andreadb
Subscribers: hiraditya, jyknight, sanjoy, skatkov, gberry, jholewinski, qcolombet, javed.absar, krytarowski, atrick, spatel, RKSimon, andreadb, MatzeB, mehdi_amini, mgorny, efriedma, davide, dberlin, llvm-commits
Differential Revision: https://reviews.llvm.org/D32563
llvm-svn: 304371
2017-06-01 01:25:25 +02:00
|
|
|
|
|
|
|
#define DEBUG_TYPE "lrshrink"
|
|
|
|
|
|
|
|
STATISTIC(NumInstrsHoistedToShrinkLiveRange,
|
|
|
|
"Number of insructions hoisted to shrink live range.");
|
|
|
|
|
|
|
|
namespace {
|
2017-08-24 23:21:39 +02:00
|
|
|
|
Add LiveRangeShrink pass to shrink live range within BB.
Summary: LiveRangeShrink pass moves instruction right after the definition with the same BB if the instruction and its operands all have more than one use. This pass is inexpensive and guarantees optimal live-range within BB.
Reviewers: davidxl, wmi, hfinkel, MatzeB, andreadb
Reviewed By: MatzeB, andreadb
Subscribers: hiraditya, jyknight, sanjoy, skatkov, gberry, jholewinski, qcolombet, javed.absar, krytarowski, atrick, spatel, RKSimon, andreadb, MatzeB, mehdi_amini, mgorny, efriedma, davide, dberlin, llvm-commits
Differential Revision: https://reviews.llvm.org/D32563
llvm-svn: 304371
2017-06-01 01:25:25 +02:00
|
|
|
class LiveRangeShrink : public MachineFunctionPass {
|
|
|
|
public:
|
|
|
|
static char ID;
|
|
|
|
|
|
|
|
LiveRangeShrink() : MachineFunctionPass(ID) {
|
|
|
|
initializeLiveRangeShrinkPass(*PassRegistry::getPassRegistry());
|
|
|
|
}
|
|
|
|
|
|
|
|
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
|
|
|
AU.setPreservesCFG();
|
|
|
|
MachineFunctionPass::getAnalysisUsage(AU);
|
|
|
|
}
|
|
|
|
|
|
|
|
StringRef getPassName() const override { return "Live Range Shrink"; }
|
|
|
|
|
|
|
|
bool runOnMachineFunction(MachineFunction &MF) override;
|
|
|
|
};
|
2017-08-24 23:21:39 +02:00
|
|
|
|
|
|
|
} // end anonymous namespace
|
Add LiveRangeShrink pass to shrink live range within BB.
Summary: LiveRangeShrink pass moves instruction right after the definition with the same BB if the instruction and its operands all have more than one use. This pass is inexpensive and guarantees optimal live-range within BB.
Reviewers: davidxl, wmi, hfinkel, MatzeB, andreadb
Reviewed By: MatzeB, andreadb
Subscribers: hiraditya, jyknight, sanjoy, skatkov, gberry, jholewinski, qcolombet, javed.absar, krytarowski, atrick, spatel, RKSimon, andreadb, MatzeB, mehdi_amini, mgorny, efriedma, davide, dberlin, llvm-commits
Differential Revision: https://reviews.llvm.org/D32563
llvm-svn: 304371
2017-06-01 01:25:25 +02:00
|
|
|
|
|
|
|
char LiveRangeShrink::ID = 0;
|
2017-08-24 23:21:39 +02:00
|
|
|
|
Add LiveRangeShrink pass to shrink live range within BB.
Summary: LiveRangeShrink pass moves instruction right after the definition with the same BB if the instruction and its operands all have more than one use. This pass is inexpensive and guarantees optimal live-range within BB.
Reviewers: davidxl, wmi, hfinkel, MatzeB, andreadb
Reviewed By: MatzeB, andreadb
Subscribers: hiraditya, jyknight, sanjoy, skatkov, gberry, jholewinski, qcolombet, javed.absar, krytarowski, atrick, spatel, RKSimon, andreadb, MatzeB, mehdi_amini, mgorny, efriedma, davide, dberlin, llvm-commits
Differential Revision: https://reviews.llvm.org/D32563
llvm-svn: 304371
2017-06-01 01:25:25 +02:00
|
|
|
char &llvm::LiveRangeShrinkID = LiveRangeShrink::ID;
|
|
|
|
|
|
|
|
INITIALIZE_PASS(LiveRangeShrink, "lrshrink", "Live Range Shrink Pass", false,
|
|
|
|
false)
|
2017-08-24 23:21:39 +02:00
|
|
|
|
|
|
|
using InstOrderMap = DenseMap<MachineInstr *, unsigned>;
|
Add LiveRangeShrink pass to shrink live range within BB.
Summary: LiveRangeShrink pass moves instruction right after the definition with the same BB if the instruction and its operands all have more than one use. This pass is inexpensive and guarantees optimal live-range within BB.
Reviewers: davidxl, wmi, hfinkel, MatzeB, andreadb
Reviewed By: MatzeB, andreadb
Subscribers: hiraditya, jyknight, sanjoy, skatkov, gberry, jholewinski, qcolombet, javed.absar, krytarowski, atrick, spatel, RKSimon, andreadb, MatzeB, mehdi_amini, mgorny, efriedma, davide, dberlin, llvm-commits
Differential Revision: https://reviews.llvm.org/D32563
llvm-svn: 304371
2017-06-01 01:25:25 +02:00
|
|
|
|
|
|
|
/// Returns \p New if it's dominated by \p Old, otherwise return \p Old.
|
|
|
|
/// \p M maintains a map from instruction to its dominating order that satisfies
|
|
|
|
/// M[A] > M[B] guarantees that A is dominated by B.
|
|
|
|
/// If \p New is not in \p M, return \p Old. Otherwise if \p Old is null, return
|
|
|
|
/// \p New.
|
2017-08-24 23:21:39 +02:00
|
|
|
static MachineInstr *FindDominatedInstruction(MachineInstr &New,
|
|
|
|
MachineInstr *Old,
|
|
|
|
const InstOrderMap &M) {
|
Add LiveRangeShrink pass to shrink live range within BB.
Summary: LiveRangeShrink pass moves instruction right after the definition with the same BB if the instruction and its operands all have more than one use. This pass is inexpensive and guarantees optimal live-range within BB.
Reviewers: davidxl, wmi, hfinkel, MatzeB, andreadb
Reviewed By: MatzeB, andreadb
Subscribers: hiraditya, jyknight, sanjoy, skatkov, gberry, jholewinski, qcolombet, javed.absar, krytarowski, atrick, spatel, RKSimon, andreadb, MatzeB, mehdi_amini, mgorny, efriedma, davide, dberlin, llvm-commits
Differential Revision: https://reviews.llvm.org/D32563
llvm-svn: 304371
2017-06-01 01:25:25 +02:00
|
|
|
auto NewIter = M.find(&New);
|
|
|
|
if (NewIter == M.end())
|
|
|
|
return Old;
|
|
|
|
if (Old == nullptr)
|
|
|
|
return &New;
|
|
|
|
unsigned OrderOld = M.find(Old)->second;
|
|
|
|
unsigned OrderNew = NewIter->second;
|
|
|
|
if (OrderOld != OrderNew)
|
|
|
|
return OrderOld < OrderNew ? &New : Old;
|
|
|
|
// OrderOld == OrderNew, we need to iterate down from Old to see if it
|
|
|
|
// can reach New, if yes, New is dominated by Old.
|
|
|
|
for (MachineInstr *I = Old->getNextNode(); M.find(I)->second == OrderNew;
|
|
|
|
I = I->getNextNode())
|
|
|
|
if (I == &New)
|
|
|
|
return &New;
|
|
|
|
return Old;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Builds Instruction to its dominating order number map \p M by traversing
|
|
|
|
/// from instruction \p Start.
|
2017-08-24 23:21:39 +02:00
|
|
|
static void BuildInstOrderMap(MachineBasicBlock::iterator Start,
|
|
|
|
InstOrderMap &M) {
|
Add LiveRangeShrink pass to shrink live range within BB.
Summary: LiveRangeShrink pass moves instruction right after the definition with the same BB if the instruction and its operands all have more than one use. This pass is inexpensive and guarantees optimal live-range within BB.
Reviewers: davidxl, wmi, hfinkel, MatzeB, andreadb
Reviewed By: MatzeB, andreadb
Subscribers: hiraditya, jyknight, sanjoy, skatkov, gberry, jholewinski, qcolombet, javed.absar, krytarowski, atrick, spatel, RKSimon, andreadb, MatzeB, mehdi_amini, mgorny, efriedma, davide, dberlin, llvm-commits
Differential Revision: https://reviews.llvm.org/D32563
llvm-svn: 304371
2017-06-01 01:25:25 +02:00
|
|
|
M.clear();
|
|
|
|
unsigned i = 0;
|
|
|
|
for (MachineInstr &I : make_range(Start, Start->getParent()->end()))
|
|
|
|
M[&I] = i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool LiveRangeShrink::runOnMachineFunction(MachineFunction &MF) {
|
2017-12-15 23:22:58 +01:00
|
|
|
if (skipFunction(MF.getFunction()))
|
Add LiveRangeShrink pass to shrink live range within BB.
Summary: LiveRangeShrink pass moves instruction right after the definition with the same BB if the instruction and its operands all have more than one use. This pass is inexpensive and guarantees optimal live-range within BB.
Reviewers: davidxl, wmi, hfinkel, MatzeB, andreadb
Reviewed By: MatzeB, andreadb
Subscribers: hiraditya, jyknight, sanjoy, skatkov, gberry, jholewinski, qcolombet, javed.absar, krytarowski, atrick, spatel, RKSimon, andreadb, MatzeB, mehdi_amini, mgorny, efriedma, davide, dberlin, llvm-commits
Differential Revision: https://reviews.llvm.org/D32563
llvm-svn: 304371
2017-06-01 01:25:25 +02:00
|
|
|
return false;
|
|
|
|
|
|
|
|
MachineRegisterInfo &MRI = MF.getRegInfo();
|
|
|
|
|
2018-05-14 14:53:11 +02:00
|
|
|
LLVM_DEBUG(dbgs() << "**** Analysing " << MF.getName() << '\n');
|
Add LiveRangeShrink pass to shrink live range within BB.
Summary: LiveRangeShrink pass moves instruction right after the definition with the same BB if the instruction and its operands all have more than one use. This pass is inexpensive and guarantees optimal live-range within BB.
Reviewers: davidxl, wmi, hfinkel, MatzeB, andreadb
Reviewed By: MatzeB, andreadb
Subscribers: hiraditya, jyknight, sanjoy, skatkov, gberry, jholewinski, qcolombet, javed.absar, krytarowski, atrick, spatel, RKSimon, andreadb, MatzeB, mehdi_amini, mgorny, efriedma, davide, dberlin, llvm-commits
Differential Revision: https://reviews.llvm.org/D32563
llvm-svn: 304371
2017-06-01 01:25:25 +02:00
|
|
|
|
|
|
|
InstOrderMap IOM;
|
|
|
|
// Map from register to instruction order (value of IOM) where the
|
|
|
|
// register is used last. When moving instructions up, we need to
|
|
|
|
// make sure all its defs (including dead def) will not cross its
|
|
|
|
// last use when moving up.
|
|
|
|
DenseMap<unsigned, std::pair<unsigned, MachineInstr *>> UseMap;
|
|
|
|
|
|
|
|
for (MachineBasicBlock &MBB : MF) {
|
|
|
|
if (MBB.empty())
|
|
|
|
continue;
|
|
|
|
bool SawStore = false;
|
|
|
|
BuildInstOrderMap(MBB.begin(), IOM);
|
|
|
|
UseMap.clear();
|
|
|
|
|
|
|
|
for (MachineBasicBlock::iterator Next = MBB.begin(); Next != MBB.end();) {
|
|
|
|
MachineInstr &MI = *Next;
|
|
|
|
++Next;
|
2018-05-09 04:42:00 +02:00
|
|
|
if (MI.isPHI() || MI.isDebugInstr())
|
Add LiveRangeShrink pass to shrink live range within BB.
Summary: LiveRangeShrink pass moves instruction right after the definition with the same BB if the instruction and its operands all have more than one use. This pass is inexpensive and guarantees optimal live-range within BB.
Reviewers: davidxl, wmi, hfinkel, MatzeB, andreadb
Reviewed By: MatzeB, andreadb
Subscribers: hiraditya, jyknight, sanjoy, skatkov, gberry, jholewinski, qcolombet, javed.absar, krytarowski, atrick, spatel, RKSimon, andreadb, MatzeB, mehdi_amini, mgorny, efriedma, davide, dberlin, llvm-commits
Differential Revision: https://reviews.llvm.org/D32563
llvm-svn: 304371
2017-06-01 01:25:25 +02:00
|
|
|
continue;
|
|
|
|
if (MI.mayStore())
|
|
|
|
SawStore = true;
|
|
|
|
|
|
|
|
unsigned CurrentOrder = IOM[&MI];
|
|
|
|
unsigned Barrier = 0;
|
|
|
|
MachineInstr *BarrierMI = nullptr;
|
|
|
|
for (const MachineOperand &MO : MI.operands()) {
|
|
|
|
if (!MO.isReg() || MO.isDebug())
|
|
|
|
continue;
|
|
|
|
if (MO.isUse())
|
|
|
|
UseMap[MO.getReg()] = std::make_pair(CurrentOrder, &MI);
|
|
|
|
else if (MO.isDead() && UseMap.count(MO.getReg()))
|
|
|
|
// Barrier is the last instruction where MO get used. MI should not
|
|
|
|
// be moved above Barrier.
|
|
|
|
if (Barrier < UseMap[MO.getReg()].first) {
|
|
|
|
Barrier = UseMap[MO.getReg()].first;
|
|
|
|
BarrierMI = UseMap[MO.getReg()].second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!MI.isSafeToMove(nullptr, SawStore)) {
|
|
|
|
// If MI has side effects, it should become a barrier for code motion.
|
|
|
|
// IOM is rebuild from the next instruction to prevent later
|
|
|
|
// instructions from being moved before this MI.
|
2021-02-08 07:49:20 +01:00
|
|
|
if (MI.hasUnmodeledSideEffects() && !MI.isPseudoProbe() &&
|
|
|
|
Next != MBB.end()) {
|
Add LiveRangeShrink pass to shrink live range within BB.
Summary: LiveRangeShrink pass moves instruction right after the definition with the same BB if the instruction and its operands all have more than one use. This pass is inexpensive and guarantees optimal live-range within BB.
Reviewers: davidxl, wmi, hfinkel, MatzeB, andreadb
Reviewed By: MatzeB, andreadb
Subscribers: hiraditya, jyknight, sanjoy, skatkov, gberry, jholewinski, qcolombet, javed.absar, krytarowski, atrick, spatel, RKSimon, andreadb, MatzeB, mehdi_amini, mgorny, efriedma, davide, dberlin, llvm-commits
Differential Revision: https://reviews.llvm.org/D32563
llvm-svn: 304371
2017-06-01 01:25:25 +02:00
|
|
|
BuildInstOrderMap(Next, IOM);
|
|
|
|
SawStore = false;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
const MachineOperand *DefMO = nullptr;
|
|
|
|
MachineInstr *Insert = nullptr;
|
|
|
|
|
|
|
|
// Number of live-ranges that will be shortened. We do not count
|
|
|
|
// live-ranges that are defined by a COPY as it could be coalesced later.
|
|
|
|
unsigned NumEligibleUse = 0;
|
|
|
|
|
|
|
|
for (const MachineOperand &MO : MI.operands()) {
|
|
|
|
if (!MO.isReg() || MO.isDead() || MO.isDebug())
|
|
|
|
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-15 21:22:08 +02:00
|
|
|
Register Reg = MO.getReg();
|
Add LiveRangeShrink pass to shrink live range within BB.
Summary: LiveRangeShrink pass moves instruction right after the definition with the same BB if the instruction and its operands all have more than one use. This pass is inexpensive and guarantees optimal live-range within BB.
Reviewers: davidxl, wmi, hfinkel, MatzeB, andreadb
Reviewed By: MatzeB, andreadb
Subscribers: hiraditya, jyknight, sanjoy, skatkov, gberry, jholewinski, qcolombet, javed.absar, krytarowski, atrick, spatel, RKSimon, andreadb, MatzeB, mehdi_amini, mgorny, efriedma, davide, dberlin, llvm-commits
Differential Revision: https://reviews.llvm.org/D32563
llvm-svn: 304371
2017-06-01 01:25:25 +02:00
|
|
|
// Do not move the instruction if it def/uses a physical register,
|
|
|
|
// unless it is a constant physical register or a noreg.
|
2019-08-02 01:27:28 +02:00
|
|
|
if (!Register::isVirtualRegister(Reg)) {
|
Add LiveRangeShrink pass to shrink live range within BB.
Summary: LiveRangeShrink pass moves instruction right after the definition with the same BB if the instruction and its operands all have more than one use. This pass is inexpensive and guarantees optimal live-range within BB.
Reviewers: davidxl, wmi, hfinkel, MatzeB, andreadb
Reviewed By: MatzeB, andreadb
Subscribers: hiraditya, jyknight, sanjoy, skatkov, gberry, jholewinski, qcolombet, javed.absar, krytarowski, atrick, spatel, RKSimon, andreadb, MatzeB, mehdi_amini, mgorny, efriedma, davide, dberlin, llvm-commits
Differential Revision: https://reviews.llvm.org/D32563
llvm-svn: 304371
2017-06-01 01:25:25 +02:00
|
|
|
if (!Reg || MRI.isConstantPhysReg(Reg))
|
|
|
|
continue;
|
|
|
|
Insert = nullptr;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (MO.isDef()) {
|
|
|
|
// Do not move if there is more than one def.
|
|
|
|
if (DefMO) {
|
|
|
|
Insert = nullptr;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
DefMO = &MO;
|
|
|
|
} else if (MRI.hasOneNonDBGUse(Reg) && MRI.hasOneDef(Reg) && DefMO &&
|
|
|
|
MRI.getRegClass(DefMO->getReg()) ==
|
|
|
|
MRI.getRegClass(MO.getReg())) {
|
|
|
|
// The heuristic does not handle different register classes yet
|
|
|
|
// (registers of different sizes, looser/tighter constraints). This
|
|
|
|
// is because it needs more accurate model to handle register
|
|
|
|
// pressure correctly.
|
|
|
|
MachineInstr &DefInstr = *MRI.def_instr_begin(Reg);
|
|
|
|
if (!DefInstr.isCopy())
|
|
|
|
NumEligibleUse++;
|
|
|
|
Insert = FindDominatedInstruction(DefInstr, Insert, IOM);
|
|
|
|
} else {
|
|
|
|
Insert = nullptr;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If Barrier equals IOM[I], traverse forward to find if BarrierMI is
|
|
|
|
// after Insert, if yes, then we should not hoist.
|
|
|
|
for (MachineInstr *I = Insert; I && IOM[I] == Barrier;
|
|
|
|
I = I->getNextNode())
|
|
|
|
if (I == BarrierMI) {
|
|
|
|
Insert = nullptr;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// Move the instruction when # of shrunk live range > 1.
|
|
|
|
if (DefMO && Insert && NumEligibleUse > 1 && Barrier <= IOM[Insert]) {
|
|
|
|
MachineBasicBlock::iterator I = std::next(Insert->getIterator());
|
|
|
|
// Skip all the PHI and debug instructions.
|
2018-05-09 04:42:00 +02:00
|
|
|
while (I != MBB.end() && (I->isPHI() || I->isDebugInstr()))
|
Add LiveRangeShrink pass to shrink live range within BB.
Summary: LiveRangeShrink pass moves instruction right after the definition with the same BB if the instruction and its operands all have more than one use. This pass is inexpensive and guarantees optimal live-range within BB.
Reviewers: davidxl, wmi, hfinkel, MatzeB, andreadb
Reviewed By: MatzeB, andreadb
Subscribers: hiraditya, jyknight, sanjoy, skatkov, gberry, jholewinski, qcolombet, javed.absar, krytarowski, atrick, spatel, RKSimon, andreadb, MatzeB, mehdi_amini, mgorny, efriedma, davide, dberlin, llvm-commits
Differential Revision: https://reviews.llvm.org/D32563
llvm-svn: 304371
2017-06-01 01:25:25 +02:00
|
|
|
I = std::next(I);
|
|
|
|
if (I == MI.getIterator())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Update the dominator order to be the same as the insertion point.
|
|
|
|
// We do this to maintain a non-decreasing order without need to update
|
|
|
|
// all instruction orders after the insertion point.
|
|
|
|
unsigned NewOrder = IOM[&*I];
|
|
|
|
IOM[&MI] = NewOrder;
|
|
|
|
NumInstrsHoistedToShrinkLiveRange++;
|
|
|
|
|
|
|
|
// Find MI's debug value following MI.
|
|
|
|
MachineBasicBlock::iterator EndIter = std::next(MI.getIterator());
|
|
|
|
if (MI.getOperand(0).isReg())
|
|
|
|
for (; EndIter != MBB.end() && EndIter->isDebugValue() &&
|
2021-03-04 13:02:28 +01:00
|
|
|
EndIter->hasDebugOperandForReg(MI.getOperand(0).getReg());
|
Add LiveRangeShrink pass to shrink live range within BB.
Summary: LiveRangeShrink pass moves instruction right after the definition with the same BB if the instruction and its operands all have more than one use. This pass is inexpensive and guarantees optimal live-range within BB.
Reviewers: davidxl, wmi, hfinkel, MatzeB, andreadb
Reviewed By: MatzeB, andreadb
Subscribers: hiraditya, jyknight, sanjoy, skatkov, gberry, jholewinski, qcolombet, javed.absar, krytarowski, atrick, spatel, RKSimon, andreadb, MatzeB, mehdi_amini, mgorny, efriedma, davide, dberlin, llvm-commits
Differential Revision: https://reviews.llvm.org/D32563
llvm-svn: 304371
2017-06-01 01:25:25 +02:00
|
|
|
++EndIter, ++Next)
|
|
|
|
IOM[&*EndIter] = NewOrder;
|
|
|
|
MBB.splice(I, &MBB, MI.getIterator(), EndIter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|