2012-05-04 05:52:53 +08:00
|
|
|
//===----- HexagonPacketizer.cpp - vliw packetizer ---------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This implements a simple VLIW packetizer using DFA. The packetizer works on
|
|
|
|
// machine basic blocks. For each instruction I in BB, the packetizer consults
|
|
|
|
// the DFA to see if machine resources are available to execute I. If so, the
|
|
|
|
// packetizer checks if I depends on any instruction J in the current packet.
|
|
|
|
// If no dependency is found, I is added to current packet and machine resource
|
|
|
|
// is marked as taken. If any dependency is found, a target API call is made to
|
|
|
|
// prune the dependence.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2014-01-07 19:48:04 +08:00
|
|
|
#include "HexagonRegisterInfo.h"
|
|
|
|
#include "HexagonSubtarget.h"
|
|
|
|
#include "HexagonTargetMachine.h"
|
2015-12-17 03:36:12 +08:00
|
|
|
#include "HexagonVLIWPacketizer.h"
|
|
|
|
#include "llvm/Analysis/AliasAnalysis.h"
|
2012-05-04 05:52:53 +08:00
|
|
|
#include "llvm/CodeGen/MachineDominators.h"
|
|
|
|
#include "llvm/CodeGen/MachineFunctionPass.h"
|
|
|
|
#include "llvm/CodeGen/MachineLoopInfo.h"
|
2014-01-07 19:48:04 +08:00
|
|
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
|
|
|
#include "llvm/CodeGen/Passes.h"
|
2013-03-02 01:37:13 +08:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2012-05-04 05:52:53 +08:00
|
|
|
#include "llvm/Support/Debug.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2014-04-22 10:41:26 +08:00
|
|
|
#define DEBUG_TYPE "packets"
|
|
|
|
|
2015-12-17 03:36:12 +08:00
|
|
|
static cl::opt<bool> DisablePacketizer("disable-packetizer", cl::Hidden,
|
|
|
|
cl::ZeroOrMore, cl::init(false),
|
|
|
|
cl::desc("Disable Hexagon packetizer pass"));
|
|
|
|
|
2013-05-02 23:39:30 +08:00
|
|
|
static cl::opt<bool> PacketizeVolatiles("hexagon-packetize-volatiles",
|
2015-12-17 03:36:12 +08:00
|
|
|
cl::ZeroOrMore, cl::Hidden, cl::init(true),
|
|
|
|
cl::desc("Allow non-solo packetization of volatile memory references"));
|
|
|
|
|
|
|
|
static cl::opt<bool> EnableGenAllInsnClass("enable-gen-insn", cl::init(false),
|
|
|
|
cl::Hidden, cl::ZeroOrMore, cl::desc("Generate all instruction with TC"));
|
|
|
|
|
|
|
|
static cl::opt<bool> DisableVecDblNVStores("disable-vecdbl-nv-stores",
|
|
|
|
cl::init(false), cl::Hidden, cl::ZeroOrMore,
|
|
|
|
cl::desc("Disable vector double new-value-stores"));
|
|
|
|
|
|
|
|
extern cl::opt<bool> ScheduleInlineAsm;
|
2013-05-02 23:39:30 +08:00
|
|
|
|
|
|
|
namespace llvm {
|
2015-06-16 03:05:35 +08:00
|
|
|
FunctionPass *createHexagonPacketizer();
|
2013-05-02 23:39:30 +08:00
|
|
|
void initializeHexagonPacketizerPass(PassRegistry&);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-04 05:52:53 +08:00
|
|
|
namespace {
|
|
|
|
class HexagonPacketizer : public MachineFunctionPass {
|
|
|
|
public:
|
|
|
|
static char ID;
|
2013-05-02 23:39:30 +08:00
|
|
|
HexagonPacketizer() : MachineFunctionPass(ID) {
|
|
|
|
initializeHexagonPacketizerPass(*PassRegistry::getPassRegistry());
|
|
|
|
}
|
2012-05-04 05:52:53 +08:00
|
|
|
|
2014-04-29 15:58:16 +08:00
|
|
|
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
2012-05-04 05:52:53 +08:00
|
|
|
AU.setPreservesCFG();
|
2015-12-17 03:36:12 +08:00
|
|
|
AU.addRequired<AAResultsWrapperPass>();
|
2013-05-02 23:39:30 +08:00
|
|
|
AU.addRequired<MachineBranchProbabilityInfo>();
|
2015-12-17 03:36:12 +08:00
|
|
|
AU.addRequired<MachineDominatorTree>();
|
2012-05-04 05:52:53 +08:00
|
|
|
AU.addRequired<MachineLoopInfo>();
|
2015-12-17 03:36:12 +08:00
|
|
|
AU.addPreserved<MachineDominatorTree>();
|
2012-05-04 05:52:53 +08:00
|
|
|
AU.addPreserved<MachineLoopInfo>();
|
|
|
|
MachineFunctionPass::getAnalysisUsage(AU);
|
|
|
|
}
|
2016-10-01 10:56:57 +08:00
|
|
|
StringRef getPassName() const override { return "Hexagon Packetizer"; }
|
2014-04-29 15:58:16 +08:00
|
|
|
bool runOnMachineFunction(MachineFunction &Fn) override;
|
2016-04-05 01:09:25 +08:00
|
|
|
MachineFunctionProperties getRequiredProperties() const override {
|
|
|
|
return MachineFunctionProperties().set(
|
2016-08-25 09:27:13 +08:00
|
|
|
MachineFunctionProperties::Property::NoVRegs);
|
2016-04-05 01:09:25 +08:00
|
|
|
}
|
2012-05-04 05:52:53 +08:00
|
|
|
|
|
|
|
private:
|
2015-12-17 03:36:12 +08:00
|
|
|
const HexagonInstrInfo *HII;
|
|
|
|
const HexagonRegisterInfo *HRI;
|
2012-05-04 05:52:53 +08:00
|
|
|
};
|
2015-12-17 03:36:12 +08:00
|
|
|
|
|
|
|
char HexagonPacketizer::ID = 0;
|
2015-06-23 17:49:53 +08:00
|
|
|
}
|
2012-05-04 05:52:53 +08:00
|
|
|
|
2013-05-02 23:39:30 +08:00
|
|
|
INITIALIZE_PASS_BEGIN(HexagonPacketizer, "packets", "Hexagon Packetizer",
|
|
|
|
false, false)
|
|
|
|
INITIALIZE_PASS_DEPENDENCY(MachineDominatorTree)
|
|
|
|
INITIALIZE_PASS_DEPENDENCY(MachineBranchProbabilityInfo)
|
|
|
|
INITIALIZE_PASS_DEPENDENCY(MachineLoopInfo)
|
[PM/AA] Rebuild LLVM's alias analysis infrastructure in a way compatible
with the new pass manager, and no longer relying on analysis groups.
This builds essentially a ground-up new AA infrastructure stack for
LLVM. The core ideas are the same that are used throughout the new pass
manager: type erased polymorphism and direct composition. The design is
as follows:
- FunctionAAResults is a type-erasing alias analysis results aggregation
interface to walk a single query across a range of results from
different alias analyses. Currently this is function-specific as we
always assume that aliasing queries are *within* a function.
- AAResultBase is a CRTP utility providing stub implementations of
various parts of the alias analysis result concept, notably in several
cases in terms of other more general parts of the interface. This can
be used to implement only a narrow part of the interface rather than
the entire interface. This isn't really ideal, this logic should be
hoisted into FunctionAAResults as currently it will cause
a significant amount of redundant work, but it faithfully models the
behavior of the prior infrastructure.
- All the alias analysis passes are ported to be wrapper passes for the
legacy PM and new-style analysis passes for the new PM with a shared
result object. In some cases (most notably CFL), this is an extremely
naive approach that we should revisit when we can specialize for the
new pass manager.
- BasicAA has been restructured to reflect that it is much more
fundamentally a function analysis because it uses dominator trees and
loop info that need to be constructed for each function.
All of the references to getting alias analysis results have been
updated to use the new aggregation interface. All the preservation and
other pass management code has been updated accordingly.
The way the FunctionAAResultsWrapperPass works is to detect the
available alias analyses when run, and add them to the results object.
This means that we should be able to continue to respect when various
passes are added to the pipeline, for example adding CFL or adding TBAA
passes should just cause their results to be available and to get folded
into this. The exception to this rule is BasicAA which really needs to
be a function pass due to using dominator trees and loop info. As
a consequence, the FunctionAAResultsWrapperPass directly depends on
BasicAA and always includes it in the aggregation.
This has significant implications for preserving analyses. Generally,
most passes shouldn't bother preserving FunctionAAResultsWrapperPass
because rebuilding the results just updates the set of known AA passes.
The exception to this rule are LoopPass instances which need to preserve
all the function analyses that the loop pass manager will end up
needing. This means preserving both BasicAAWrapperPass and the
aggregating FunctionAAResultsWrapperPass.
Now, when preserving an alias analysis, you do so by directly preserving
that analysis. This is only necessary for non-immutable-pass-provided
alias analyses though, and there are only three of interest: BasicAA,
GlobalsAA (formerly GlobalsModRef), and SCEVAA. Usually BasicAA is
preserved when needed because it (like DominatorTree and LoopInfo) is
marked as a CFG-only pass. I've expanded GlobalsAA into the preserved
set everywhere we previously were preserving all of AliasAnalysis, and
I've added SCEVAA in the intersection of that with where we preserve
SCEV itself.
One significant challenge to all of this is that the CGSCC passes were
actually using the alias analysis implementations by taking advantage of
a pretty amazing set of loop holes in the old pass manager's analysis
management code which allowed analysis groups to slide through in many
cases. Moving away from analysis groups makes this problem much more
obvious. To fix it, I've leveraged the flexibility the design of the new
PM components provides to just directly construct the relevant alias
analyses for the relevant functions in the IPO passes that need them.
This is a bit hacky, but should go away with the new pass manager, and
is already in many ways cleaner than the prior state.
Another significant challenge is that various facilities of the old
alias analysis infrastructure just don't fit any more. The most
significant of these is the alias analysis 'counter' pass. That pass
relied on the ability to snoop on AA queries at different points in the
analysis group chain. Instead, I'm planning to build printing
functionality directly into the aggregation layer. I've not included
that in this patch merely to keep it smaller.
Note that all of this needs a nearly complete rewrite of the AA
documentation. I'm planning to do that, but I'd like to make sure the
new design settles, and to flesh out a bit more of what it looks like in
the new pass manager first.
Differential Revision: http://reviews.llvm.org/D12080
llvm-svn: 247167
2015-09-10 01:55:00 +08:00
|
|
|
INITIALIZE_PASS_DEPENDENCY(AAResultsWrapperPass)
|
2013-05-02 23:39:30 +08:00
|
|
|
INITIALIZE_PASS_END(HexagonPacketizer, "packets", "Hexagon Packetizer",
|
|
|
|
false, false)
|
|
|
|
|
2015-12-17 03:36:12 +08:00
|
|
|
HexagonPacketizerList::HexagonPacketizerList(MachineFunction &MF,
|
|
|
|
MachineLoopInfo &MLI, AliasAnalysis *AA,
|
|
|
|
const MachineBranchProbabilityInfo *MBPI)
|
|
|
|
: VLIWPacketizerList(MF, MLI, AA), MBPI(MBPI), MLI(&MLI) {
|
|
|
|
HII = MF.getSubtarget<HexagonSubtarget>().getInstrInfo();
|
|
|
|
HRI = MF.getSubtarget<HexagonSubtarget>().getRegisterInfo();
|
2016-07-16 01:48:09 +08:00
|
|
|
|
|
|
|
addMutation(make_unique<HexagonSubtarget::HexagonDAGMutation>());
|
2012-05-04 05:52:53 +08:00
|
|
|
}
|
|
|
|
|
2015-12-17 03:36:12 +08:00
|
|
|
// Check if FirstI modifies a register that SecondI reads.
|
2016-07-12 09:55:32 +08:00
|
|
|
static bool hasWriteToReadDep(const MachineInstr &FirstI,
|
|
|
|
const MachineInstr &SecondI,
|
|
|
|
const TargetRegisterInfo *TRI) {
|
|
|
|
for (auto &MO : FirstI.operands()) {
|
2015-12-17 03:36:12 +08:00
|
|
|
if (!MO.isReg() || !MO.isDef())
|
|
|
|
continue;
|
|
|
|
unsigned R = MO.getReg();
|
2016-07-12 09:55:32 +08:00
|
|
|
if (SecondI.readsRegister(R, TRI))
|
2015-12-17 03:36:12 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-07-30 05:49:42 +08:00
|
|
|
static MachineBasicBlock::iterator moveInstrOut(MachineInstr &MI,
|
2015-12-17 03:36:12 +08:00
|
|
|
MachineBasicBlock::iterator BundleIt, bool Before) {
|
|
|
|
MachineBasicBlock::instr_iterator InsertPt;
|
|
|
|
if (Before)
|
2016-02-23 05:30:15 +08:00
|
|
|
InsertPt = BundleIt.getInstrIterator();
|
2015-12-17 03:36:12 +08:00
|
|
|
else
|
2016-02-23 05:30:15 +08:00
|
|
|
InsertPt = std::next(BundleIt).getInstrIterator();
|
2015-12-17 03:36:12 +08:00
|
|
|
|
2016-07-30 05:49:42 +08:00
|
|
|
MachineBasicBlock &B = *MI.getParent();
|
2015-12-17 03:36:12 +08:00
|
|
|
// The instruction should at least be bundled with the preceding instruction
|
|
|
|
// (there will always be one, i.e. BUNDLE, if nothing else).
|
2016-07-30 05:49:42 +08:00
|
|
|
assert(MI.isBundledWithPred());
|
|
|
|
if (MI.isBundledWithSucc()) {
|
|
|
|
MI.clearFlag(MachineInstr::BundledSucc);
|
|
|
|
MI.clearFlag(MachineInstr::BundledPred);
|
2015-12-17 03:36:12 +08:00
|
|
|
} else {
|
|
|
|
// If it's not bundled with the successor (i.e. it is the last one
|
|
|
|
// in the bundle), then we can simply unbundle it from the predecessor,
|
|
|
|
// which will take care of updating the predecessor's flag.
|
2016-07-30 05:49:42 +08:00
|
|
|
MI.unbundleFromPred();
|
2015-12-17 03:36:12 +08:00
|
|
|
}
|
2016-07-30 05:49:42 +08:00
|
|
|
B.splice(InsertPt, &B, MI.getIterator());
|
2015-12-17 03:36:12 +08:00
|
|
|
|
|
|
|
// Get the size of the bundle without asserting.
|
2016-07-12 09:55:32 +08:00
|
|
|
MachineBasicBlock::const_instr_iterator I = BundleIt.getInstrIterator();
|
2015-12-17 03:36:12 +08:00
|
|
|
MachineBasicBlock::const_instr_iterator E = B.instr_end();
|
|
|
|
unsigned Size = 0;
|
|
|
|
for (++I; I != E && I->isBundledWithPred(); ++I)
|
|
|
|
++Size;
|
|
|
|
|
|
|
|
// If there are still two or more instructions, then there is nothing
|
|
|
|
// else to be done.
|
|
|
|
if (Size > 1)
|
|
|
|
return BundleIt;
|
|
|
|
|
|
|
|
// Otherwise, extract the single instruction out and delete the bundle.
|
|
|
|
MachineBasicBlock::iterator NextIt = std::next(BundleIt);
|
2016-07-30 05:49:42 +08:00
|
|
|
MachineInstr &SingleI = *BundleIt->getNextNode();
|
|
|
|
SingleI.unbundleFromPred();
|
|
|
|
assert(!SingleI.isBundledWithSucc());
|
2015-12-17 03:36:12 +08:00
|
|
|
BundleIt->eraseFromParent();
|
|
|
|
return NextIt;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool HexagonPacketizer::runOnMachineFunction(MachineFunction &MF) {
|
2016-04-27 03:46:28 +08:00
|
|
|
if (DisablePacketizer || skipFunction(*MF.getFunction()))
|
2015-12-17 03:36:12 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
HII = MF.getSubtarget<HexagonSubtarget>().getInstrInfo();
|
|
|
|
HRI = MF.getSubtarget<HexagonSubtarget>().getRegisterInfo();
|
|
|
|
auto &MLI = getAnalysis<MachineLoopInfo>();
|
|
|
|
auto *AA = &getAnalysis<AAResultsWrapperPass>().getAAResults();
|
|
|
|
auto *MBPI = &getAnalysis<MachineBranchProbabilityInfo>();
|
|
|
|
|
|
|
|
if (EnableGenAllInsnClass)
|
|
|
|
HII->genAllInsnTimingClasses(MF);
|
|
|
|
|
2012-05-04 05:52:53 +08:00
|
|
|
// Instantiate the packetizer.
|
2015-12-17 03:36:12 +08:00
|
|
|
HexagonPacketizerList Packetizer(MF, MLI, AA, MBPI);
|
2012-05-04 05:52:53 +08:00
|
|
|
|
|
|
|
// DFA state table should not be empty.
|
|
|
|
assert(Packetizer.getResourceTracker() && "Empty DFA table!");
|
|
|
|
|
|
|
|
//
|
|
|
|
// Loop over all basic blocks and remove KILL pseudo-instructions
|
|
|
|
// These instructions confuse the dependence analysis. Consider:
|
|
|
|
// D0 = ... (Insn 0)
|
|
|
|
// R0 = KILL R0, D0 (Insn 1)
|
|
|
|
// R0 = ... (Insn 2)
|
|
|
|
// Here, Insn 1 will result in the dependence graph not emitting an output
|
|
|
|
// dependence between Insn 0 and Insn 2. This can lead to incorrect
|
|
|
|
// packetization
|
|
|
|
//
|
2015-12-17 03:36:12 +08:00
|
|
|
for (auto &MB : MF) {
|
|
|
|
auto End = MB.end();
|
|
|
|
auto MI = MB.begin();
|
2012-05-04 05:52:53 +08:00
|
|
|
while (MI != End) {
|
2015-12-17 03:36:12 +08:00
|
|
|
auto NextI = std::next(MI);
|
2012-05-04 05:52:53 +08:00
|
|
|
if (MI->isKill()) {
|
2015-12-17 03:36:12 +08:00
|
|
|
MB.erase(MI);
|
|
|
|
End = MB.end();
|
2012-05-04 05:52:53 +08:00
|
|
|
}
|
2015-12-17 03:36:12 +08:00
|
|
|
MI = NextI;
|
2012-05-04 05:52:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Loop over all of the basic blocks.
|
2015-12-17 03:36:12 +08:00
|
|
|
for (auto &MB : MF) {
|
|
|
|
auto Begin = MB.begin(), End = MB.end();
|
|
|
|
while (Begin != End) {
|
|
|
|
// First the first non-boundary starting from the end of the last
|
|
|
|
// scheduling region.
|
|
|
|
MachineBasicBlock::iterator RB = Begin;
|
2016-06-30 08:01:54 +08:00
|
|
|
while (RB != End && HII->isSchedulingBoundary(*RB, &MB, MF))
|
2015-12-17 03:36:12 +08:00
|
|
|
++RB;
|
|
|
|
// First the first boundary starting from the beginning of the new
|
|
|
|
// region.
|
|
|
|
MachineBasicBlock::iterator RE = RB;
|
2016-06-30 08:01:54 +08:00
|
|
|
while (RE != End && !HII->isSchedulingBoundary(*RE, &MB, MF))
|
2015-12-17 03:36:12 +08:00
|
|
|
++RE;
|
|
|
|
// Add the scheduling boundary if it's not block end.
|
|
|
|
if (RE != End)
|
|
|
|
++RE;
|
|
|
|
// If RB == End, then RE == End.
|
|
|
|
if (RB != End)
|
|
|
|
Packetizer.PacketizeMIs(&MB, RB, RE);
|
|
|
|
|
|
|
|
Begin = RE;
|
2012-05-04 05:52:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-17 03:36:12 +08:00
|
|
|
Packetizer.unpacketizeSoloInstrs(MF);
|
2012-05-04 05:52:53 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-12-17 03:36:12 +08:00
|
|
|
// Reserve resources for a constant extender. Trigger an assertion if the
|
|
|
|
// reservation fails.
|
|
|
|
void HexagonPacketizerList::reserveResourcesForConstExt() {
|
|
|
|
if (!tryAllocateResourcesForConstExt(true))
|
|
|
|
llvm_unreachable("Resources not available");
|
2012-05-04 05:52:53 +08:00
|
|
|
}
|
|
|
|
|
2015-12-17 03:36:12 +08:00
|
|
|
bool HexagonPacketizerList::canReserveResourcesForConstExt() {
|
|
|
|
return tryAllocateResourcesForConstExt(false);
|
2012-05-04 05:52:53 +08:00
|
|
|
}
|
|
|
|
|
2015-12-17 03:36:12 +08:00
|
|
|
// Allocate resources (i.e. 4 bytes) for constant extender. If succeeded,
|
|
|
|
// return true, otherwise, return false.
|
|
|
|
bool HexagonPacketizerList::tryAllocateResourcesForConstExt(bool Reserve) {
|
|
|
|
auto *ExtMI = MF.CreateMachineInstr(HII->get(Hexagon::A4_ext), DebugLoc());
|
2016-02-28 03:09:00 +08:00
|
|
|
bool Avail = ResourceTracker->canReserveResources(*ExtMI);
|
2015-12-17 03:36:12 +08:00
|
|
|
if (Reserve && Avail)
|
2016-02-28 03:09:00 +08:00
|
|
|
ResourceTracker->reserveResources(*ExtMI);
|
2015-12-17 03:36:12 +08:00
|
|
|
MF.DeleteMachineInstr(ExtMI);
|
|
|
|
return Avail;
|
2012-05-04 05:52:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-07-30 05:49:42 +08:00
|
|
|
bool HexagonPacketizerList::isCallDependent(const MachineInstr &MI,
|
2015-12-17 03:36:12 +08:00
|
|
|
SDep::Kind DepType, unsigned DepReg) {
|
|
|
|
// Check for LR dependence.
|
|
|
|
if (DepReg == HRI->getRARegister())
|
2012-05-04 05:52:53 +08:00
|
|
|
return true;
|
|
|
|
|
2015-12-17 03:36:12 +08:00
|
|
|
if (HII->isDeallocRet(MI))
|
|
|
|
if (DepReg == HRI->getFrameRegister() || DepReg == HRI->getStackRegister())
|
2012-05-04 05:52:53 +08:00
|
|
|
return true;
|
|
|
|
|
2015-12-17 03:36:12 +08:00
|
|
|
// Check if this is a predicate dependence.
|
|
|
|
const TargetRegisterClass* RC = HRI->getMinimalPhysRegClass(DepReg);
|
|
|
|
if (RC == &Hexagon::PredRegsRegClass)
|
2012-05-04 05:52:53 +08:00
|
|
|
return true;
|
|
|
|
|
2015-12-17 03:36:12 +08:00
|
|
|
// Assumes that the first operand of the CALLr is the function address.
|
|
|
|
if (HII->isIndirectCall(MI) && (DepType == SDep::Data)) {
|
2016-08-20 05:07:35 +08:00
|
|
|
const MachineOperand MO = MI.getOperand(0);
|
2015-12-17 03:36:12 +08:00
|
|
|
if (MO.isReg() && MO.isUse() && (MO.getReg() == DepReg))
|
2012-05-04 05:52:53 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-08-20 05:07:35 +08:00
|
|
|
if (HII->isJumpR(MI)) {
|
|
|
|
const MachineOperand &MO = HII->isPredicated(MI) ? MI.getOperand(1)
|
|
|
|
: MI.getOperand(0);
|
|
|
|
assert(MO.isReg() && MO.isUse());
|
|
|
|
if (MO.getReg() == DepReg)
|
|
|
|
return true;
|
|
|
|
}
|
2012-05-04 05:52:53 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-12-17 03:36:12 +08:00
|
|
|
static bool isRegDependence(const SDep::Kind DepType) {
|
|
|
|
return DepType == SDep::Data || DepType == SDep::Anti ||
|
|
|
|
DepType == SDep::Output;
|
2012-05-04 05:52:53 +08:00
|
|
|
}
|
|
|
|
|
2016-07-30 05:49:42 +08:00
|
|
|
static bool isDirectJump(const MachineInstr &MI) {
|
|
|
|
return MI.getOpcode() == Hexagon::J2_jump;
|
2012-05-04 05:52:53 +08:00
|
|
|
}
|
|
|
|
|
2016-07-30 05:49:42 +08:00
|
|
|
static bool isSchedBarrier(const MachineInstr &MI) {
|
|
|
|
switch (MI.getOpcode()) {
|
2015-02-06 02:56:28 +08:00
|
|
|
case Hexagon::Y2_barrier:
|
2012-05-04 05:52:53 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-07-30 05:49:42 +08:00
|
|
|
static bool isControlFlow(const MachineInstr &MI) {
|
|
|
|
return MI.getDesc().isTerminator() || MI.getDesc().isCall();
|
2012-05-04 05:52:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-12-17 03:36:12 +08:00
|
|
|
/// Returns true if the instruction modifies a callee-saved register.
|
2016-07-30 05:49:42 +08:00
|
|
|
static bool doesModifyCalleeSavedReg(const MachineInstr &MI,
|
2012-05-04 05:52:53 +08:00
|
|
|
const TargetRegisterInfo *TRI) {
|
2016-07-30 05:49:42 +08:00
|
|
|
const MachineFunction &MF = *MI.getParent()->getParent();
|
2015-12-17 03:36:12 +08:00
|
|
|
for (auto *CSR = TRI->getCalleeSavedRegs(&MF); CSR && *CSR; ++CSR)
|
2016-07-30 05:49:42 +08:00
|
|
|
if (MI.modifiesRegister(*CSR, TRI))
|
2012-05-04 05:52:53 +08:00
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-12-17 03:36:12 +08:00
|
|
|
// Returns true if an instruction can be promoted to .new predicate or
|
|
|
|
// new-value store.
|
2016-07-30 05:49:42 +08:00
|
|
|
bool HexagonPacketizerList::isNewifiable(const MachineInstr &MI,
|
2016-07-27 04:30:30 +08:00
|
|
|
const TargetRegisterClass *NewRC) {
|
|
|
|
// Vector stores can be predicated, and can be new-value stores, but
|
|
|
|
// they cannot be predicated on a .new predicate value.
|
|
|
|
if (NewRC == &Hexagon::PredRegsRegClass)
|
2017-05-04 04:10:36 +08:00
|
|
|
if (HII->isHVXVec(MI) && MI.mayStore())
|
2016-07-27 04:30:30 +08:00
|
|
|
return false;
|
2016-08-24 00:01:01 +08:00
|
|
|
return HII->isCondInst(MI) || HII->isJumpR(MI) || MI.isReturn() ||
|
|
|
|
HII->mayBeNewStore(MI);
|
2012-05-04 05:52:53 +08:00
|
|
|
}
|
|
|
|
|
2015-12-17 03:36:12 +08:00
|
|
|
// Promote an instructiont to its .cur form.
|
|
|
|
// At this time, we have already made a call to canPromoteToDotCur and made
|
|
|
|
// sure that it can *indeed* be promoted.
|
2016-07-30 05:49:42 +08:00
|
|
|
bool HexagonPacketizerList::promoteToDotCur(MachineInstr &MI,
|
2015-12-17 03:36:12 +08:00
|
|
|
SDep::Kind DepType, MachineBasicBlock::iterator &MII,
|
|
|
|
const TargetRegisterClass* RC) {
|
|
|
|
assert(DepType == SDep::Data);
|
|
|
|
int CurOpcode = HII->getDotCurOp(MI);
|
2016-07-30 05:49:42 +08:00
|
|
|
MI.setDesc(HII->get(CurOpcode));
|
2015-12-17 03:36:12 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void HexagonPacketizerList::cleanUpDotCur() {
|
2016-07-30 05:49:42 +08:00
|
|
|
MachineInstr *MI = nullptr;
|
2015-12-17 03:36:12 +08:00
|
|
|
for (auto BI : CurrentPacketMIs) {
|
|
|
|
DEBUG(dbgs() << "Cleanup packet has "; BI->dump(););
|
2017-05-03 23:28:56 +08:00
|
|
|
if (HII->isDotCurInst(*BI)) {
|
2015-12-17 03:36:12 +08:00
|
|
|
MI = BI;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (MI) {
|
|
|
|
for (auto &MO : BI->operands())
|
|
|
|
if (MO.isReg() && MO.getReg() == MI->getOperand(0).getReg())
|
|
|
|
return;
|
|
|
|
}
|
2012-05-04 05:52:53 +08:00
|
|
|
}
|
2015-12-17 03:36:12 +08:00
|
|
|
if (!MI)
|
|
|
|
return;
|
|
|
|
// We did not find a use of the CUR, so de-cur it.
|
2017-05-03 23:28:56 +08:00
|
|
|
MI->setDesc(HII->get(HII->getNonDotCurOp(*MI)));
|
2015-12-17 03:36:12 +08:00
|
|
|
DEBUG(dbgs() << "Demoted CUR "; MI->dump(););
|
2012-05-04 05:52:53 +08:00
|
|
|
}
|
|
|
|
|
2015-12-17 03:36:12 +08:00
|
|
|
// Check to see if an instruction can be dot cur.
|
2016-07-30 05:49:42 +08:00
|
|
|
bool HexagonPacketizerList::canPromoteToDotCur(const MachineInstr &MI,
|
2015-12-17 03:36:12 +08:00
|
|
|
const SUnit *PacketSU, unsigned DepReg, MachineBasicBlock::iterator &MII,
|
|
|
|
const TargetRegisterClass *RC) {
|
2017-05-04 04:10:36 +08:00
|
|
|
if (!HII->isHVXVec(MI))
|
2015-12-17 03:36:12 +08:00
|
|
|
return false;
|
2017-05-04 04:10:36 +08:00
|
|
|
if (!HII->isHVXVec(*MII))
|
2015-12-17 03:36:12 +08:00
|
|
|
return false;
|
2012-05-15 03:35:42 +08:00
|
|
|
|
2015-12-17 03:36:12 +08:00
|
|
|
// Already a dot new instruction.
|
|
|
|
if (HII->isDotCurInst(MI) && !HII->mayBeCurLoad(MI))
|
|
|
|
return false;
|
2012-05-04 05:52:53 +08:00
|
|
|
|
2015-12-17 03:36:12 +08:00
|
|
|
if (!HII->mayBeCurLoad(MI))
|
|
|
|
return false;
|
2012-05-04 05:52:53 +08:00
|
|
|
|
2015-12-17 03:36:12 +08:00
|
|
|
// The "cur value" cannot come from inline asm.
|
|
|
|
if (PacketSU->getInstr()->isInlineAsm())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Make sure candidate instruction uses cur.
|
|
|
|
DEBUG(dbgs() << "Can we DOT Cur Vector MI\n";
|
2016-07-30 05:49:42 +08:00
|
|
|
MI.dump();
|
2015-12-17 03:36:12 +08:00
|
|
|
dbgs() << "in packet\n";);
|
2016-07-12 09:55:32 +08:00
|
|
|
MachineInstr &MJ = *MII;
|
|
|
|
DEBUG({
|
|
|
|
dbgs() << "Checking CUR against ";
|
|
|
|
MJ.dump();
|
|
|
|
});
|
2016-07-30 05:49:42 +08:00
|
|
|
unsigned DestReg = MI.getOperand(0).getReg();
|
2015-12-17 03:36:12 +08:00
|
|
|
bool FoundMatch = false;
|
2016-07-12 09:55:32 +08:00
|
|
|
for (auto &MO : MJ.operands())
|
2015-12-17 03:36:12 +08:00
|
|
|
if (MO.isReg() && MO.getReg() == DestReg)
|
|
|
|
FoundMatch = true;
|
|
|
|
if (!FoundMatch)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Check for existing uses of a vector register within the packet which
|
|
|
|
// would be affected by converting a vector load into .cur formt.
|
|
|
|
for (auto BI : CurrentPacketMIs) {
|
|
|
|
DEBUG(dbgs() << "packet has "; BI->dump(););
|
|
|
|
if (BI->readsRegister(DepReg, MF.getSubtarget().getRegisterInfo()))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-07-30 05:49:42 +08:00
|
|
|
DEBUG(dbgs() << "Can Dot CUR MI\n"; MI.dump(););
|
2015-12-17 03:36:12 +08:00
|
|
|
// We can convert the opcode into a .cur.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Promote an instruction to its .new form. At this time, we have already
|
|
|
|
// made a call to canPromoteToDotNew and made sure that it can *indeed* be
|
|
|
|
// promoted.
|
2016-07-30 05:49:42 +08:00
|
|
|
bool HexagonPacketizerList::promoteToDotNew(MachineInstr &MI,
|
2015-12-17 03:36:12 +08:00
|
|
|
SDep::Kind DepType, MachineBasicBlock::iterator &MII,
|
|
|
|
const TargetRegisterClass* RC) {
|
|
|
|
assert (DepType == SDep::Data);
|
2012-05-04 05:52:53 +08:00
|
|
|
int NewOpcode;
|
|
|
|
if (RC == &Hexagon::PredRegsRegClass)
|
2015-12-17 03:36:12 +08:00
|
|
|
NewOpcode = HII->getDotNewPredOp(MI, MBPI);
|
2012-05-04 05:52:53 +08:00
|
|
|
else
|
2015-12-17 03:36:12 +08:00
|
|
|
NewOpcode = HII->getDotNewOp(MI);
|
2016-07-30 05:49:42 +08:00
|
|
|
MI.setDesc(HII->get(NewOpcode));
|
2012-05-04 05:52:53 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-07-30 05:49:42 +08:00
|
|
|
bool HexagonPacketizerList::demoteToDotOld(MachineInstr &MI) {
|
2017-03-07 01:03:16 +08:00
|
|
|
int NewOpcode = HII->getDotOldOp(MI);
|
2016-07-30 05:49:42 +08:00
|
|
|
MI.setDesc(HII->get(NewOpcode));
|
2012-05-04 05:52:53 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-07-30 05:49:42 +08:00
|
|
|
bool HexagonPacketizerList::useCallersSP(MachineInstr &MI) {
|
|
|
|
unsigned Opc = MI.getOpcode();
|
2016-07-26 22:24:46 +08:00
|
|
|
switch (Opc) {
|
|
|
|
case Hexagon::S2_storerd_io:
|
|
|
|
case Hexagon::S2_storeri_io:
|
|
|
|
case Hexagon::S2_storerh_io:
|
|
|
|
case Hexagon::S2_storerb_io:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
llvm_unreachable("Unexpected instruction");
|
|
|
|
}
|
2016-07-29 02:40:00 +08:00
|
|
|
unsigned FrameSize = MF.getFrameInfo().getStackSize();
|
2016-07-30 05:49:42 +08:00
|
|
|
MachineOperand &Off = MI.getOperand(1);
|
2016-07-26 22:24:46 +08:00
|
|
|
int64_t NewOff = Off.getImm() - (FrameSize + HEXAGON_LRFP_SIZE);
|
|
|
|
if (HII->isValidOffset(Opc, NewOff)) {
|
|
|
|
Off.setImm(NewOff);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-07-30 05:49:42 +08:00
|
|
|
void HexagonPacketizerList::useCalleesSP(MachineInstr &MI) {
|
|
|
|
unsigned Opc = MI.getOpcode();
|
2016-07-26 22:24:46 +08:00
|
|
|
switch (Opc) {
|
|
|
|
case Hexagon::S2_storerd_io:
|
|
|
|
case Hexagon::S2_storeri_io:
|
|
|
|
case Hexagon::S2_storerh_io:
|
|
|
|
case Hexagon::S2_storerb_io:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
llvm_unreachable("Unexpected instruction");
|
|
|
|
}
|
2016-07-29 02:40:00 +08:00
|
|
|
unsigned FrameSize = MF.getFrameInfo().getStackSize();
|
2016-07-30 05:49:42 +08:00
|
|
|
MachineOperand &Off = MI.getOperand(1);
|
2016-07-26 22:24:46 +08:00
|
|
|
Off.setImm(Off.getImm() + FrameSize + HEXAGON_LRFP_SIZE);
|
|
|
|
}
|
|
|
|
|
2013-05-11 04:27:34 +08:00
|
|
|
enum PredicateKind {
|
|
|
|
PK_False,
|
|
|
|
PK_True,
|
|
|
|
PK_Unknown
|
|
|
|
};
|
2012-05-04 05:52:53 +08:00
|
|
|
|
2013-05-11 04:27:34 +08:00
|
|
|
/// Returns true if an instruction is predicated on p0 and false if it's
|
|
|
|
/// predicated on !p0.
|
2016-02-23 10:46:52 +08:00
|
|
|
static PredicateKind getPredicateSense(const MachineInstr &MI,
|
2015-12-17 03:36:12 +08:00
|
|
|
const HexagonInstrInfo *HII) {
|
|
|
|
if (!HII->isPredicated(MI))
|
2013-05-11 04:27:34 +08:00
|
|
|
return PK_Unknown;
|
2015-12-17 03:36:12 +08:00
|
|
|
if (HII->isPredicatedTrue(MI))
|
2013-05-11 04:27:34 +08:00
|
|
|
return PK_True;
|
|
|
|
return PK_False;
|
2012-05-04 05:52:53 +08:00
|
|
|
}
|
|
|
|
|
2016-07-30 05:49:42 +08:00
|
|
|
static const MachineOperand &getPostIncrementOperand(const MachineInstr &MI,
|
2015-12-17 03:36:12 +08:00
|
|
|
const HexagonInstrInfo *HII) {
|
2016-08-02 01:55:48 +08:00
|
|
|
assert(HII->isPostIncrement(MI) && "Not a post increment operation.");
|
2012-05-04 05:52:53 +08:00
|
|
|
#ifndef NDEBUG
|
|
|
|
// Post Increment means duplicates. Use dense map to find duplicates in the
|
|
|
|
// list. Caution: Densemap initializes with the minimum of 64 buckets,
|
|
|
|
// whereas there are at most 5 operands in the post increment.
|
2015-12-17 03:36:12 +08:00
|
|
|
DenseSet<unsigned> DefRegsSet;
|
2016-07-30 05:49:42 +08:00
|
|
|
for (auto &MO : MI.operands())
|
2015-12-17 03:36:12 +08:00
|
|
|
if (MO.isReg() && MO.isDef())
|
|
|
|
DefRegsSet.insert(MO.getReg());
|
|
|
|
|
2016-07-30 05:49:42 +08:00
|
|
|
for (auto &MO : MI.operands())
|
2015-12-17 03:36:12 +08:00
|
|
|
if (MO.isReg() && MO.isUse() && DefRegsSet.count(MO.getReg()))
|
|
|
|
return MO;
|
2012-05-04 05:52:53 +08:00
|
|
|
#else
|
2016-07-30 05:49:42 +08:00
|
|
|
if (MI.mayLoad()) {
|
|
|
|
const MachineOperand &Op1 = MI.getOperand(1);
|
2012-05-04 05:52:53 +08:00
|
|
|
// The 2nd operand is always the post increment operand in load.
|
2015-12-17 03:36:12 +08:00
|
|
|
assert(Op1.isReg() && "Post increment operand has be to a register.");
|
|
|
|
return Op1;
|
2012-05-04 05:52:53 +08:00
|
|
|
}
|
2016-07-30 05:49:42 +08:00
|
|
|
if (MI.getDesc().mayStore()) {
|
|
|
|
const MachineOperand &Op0 = MI.getOperand(0);
|
2012-05-04 05:52:53 +08:00
|
|
|
// The 1st operand is always the post increment operand in store.
|
2015-12-17 03:36:12 +08:00
|
|
|
assert(Op0.isReg() && "Post increment operand has be to a register.");
|
|
|
|
return Op0;
|
2012-05-04 05:52:53 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
// we should never come here.
|
|
|
|
llvm_unreachable("mayLoad or mayStore not set for Post Increment operation");
|
|
|
|
}
|
|
|
|
|
2015-12-17 03:36:12 +08:00
|
|
|
// Get the value being stored.
|
2016-07-30 05:49:42 +08:00
|
|
|
static const MachineOperand& getStoreValueOperand(const MachineInstr &MI) {
|
2012-05-04 05:52:53 +08:00
|
|
|
// value being stored is always the last operand.
|
2016-07-30 05:49:42 +08:00
|
|
|
return MI.getOperand(MI.getNumOperands()-1);
|
2012-05-04 05:52:53 +08:00
|
|
|
}
|
|
|
|
|
2016-07-30 05:49:42 +08:00
|
|
|
static bool isLoadAbsSet(const MachineInstr &MI) {
|
|
|
|
unsigned Opc = MI.getOpcode();
|
2015-12-17 03:36:12 +08:00
|
|
|
switch (Opc) {
|
|
|
|
case Hexagon::L4_loadrd_ap:
|
|
|
|
case Hexagon::L4_loadrb_ap:
|
|
|
|
case Hexagon::L4_loadrh_ap:
|
|
|
|
case Hexagon::L4_loadrub_ap:
|
|
|
|
case Hexagon::L4_loadruh_ap:
|
|
|
|
case Hexagon::L4_loadri_ap:
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-07-30 05:49:42 +08:00
|
|
|
static const MachineOperand &getAbsSetOperand(const MachineInstr &MI) {
|
2015-12-17 03:36:12 +08:00
|
|
|
assert(isLoadAbsSet(MI));
|
2016-07-30 05:49:42 +08:00
|
|
|
return MI.getOperand(1);
|
2015-12-17 03:36:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Can be new value store?
|
2012-05-04 05:52:53 +08:00
|
|
|
// Following restrictions are to be respected in convert a store into
|
|
|
|
// a new value store.
|
|
|
|
// 1. If an instruction uses auto-increment, its address register cannot
|
|
|
|
// be a new-value register. Arch Spec 5.4.2.1
|
2015-12-17 03:36:12 +08:00
|
|
|
// 2. If an instruction uses absolute-set addressing mode, its address
|
|
|
|
// register cannot be a new-value register. Arch Spec 5.4.2.1.
|
2012-05-04 05:52:53 +08:00
|
|
|
// 3. If an instruction produces a 64-bit result, its registers cannot be used
|
|
|
|
// as new-value registers. Arch Spec 5.4.2.2.
|
2015-12-17 03:36:12 +08:00
|
|
|
// 4. If the instruction that sets the new-value register is conditional, then
|
2012-05-04 05:52:53 +08:00
|
|
|
// the instruction that uses the new-value register must also be conditional,
|
|
|
|
// and both must always have their predicates evaluate identically.
|
|
|
|
// Arch Spec 5.4.2.3.
|
2015-12-17 03:36:12 +08:00
|
|
|
// 5. There is an implied restriction that a packet cannot have another store,
|
|
|
|
// if there is a new value store in the packet. Corollary: if there is
|
2012-05-04 05:52:53 +08:00
|
|
|
// already a store in a packet, there can not be a new value store.
|
|
|
|
// Arch Spec: 3.4.4.2
|
2016-07-30 05:49:42 +08:00
|
|
|
bool HexagonPacketizerList::canPromoteToNewValueStore(const MachineInstr &MI,
|
|
|
|
const MachineInstr &PacketMI, unsigned DepReg) {
|
2013-05-11 04:58:11 +08:00
|
|
|
// Make sure we are looking at the store, that can be promoted.
|
2015-12-17 03:36:12 +08:00
|
|
|
if (!HII->mayBeNewStore(MI))
|
2012-05-04 05:52:53 +08:00
|
|
|
return false;
|
|
|
|
|
2015-12-17 03:36:12 +08:00
|
|
|
// Make sure there is dependency and can be new value'd.
|
|
|
|
const MachineOperand &Val = getStoreValueOperand(MI);
|
|
|
|
if (Val.isReg() && Val.getReg() != DepReg)
|
2012-05-04 05:52:53 +08:00
|
|
|
return false;
|
|
|
|
|
2016-07-30 05:49:42 +08:00
|
|
|
const MCInstrDesc& MCID = PacketMI.getDesc();
|
2012-05-04 05:52:53 +08:00
|
|
|
|
2015-12-17 03:36:12 +08:00
|
|
|
// First operand is always the result.
|
|
|
|
const TargetRegisterClass *PacketRC = HII->getRegClass(MCID, 0, HRI, MF);
|
|
|
|
// Double regs can not feed into new value store: PRM section: 5.4.2.2.
|
|
|
|
if (PacketRC == &Hexagon::DoubleRegsRegClass)
|
2012-05-04 05:52:53 +08:00
|
|
|
return false;
|
2015-12-17 03:36:12 +08:00
|
|
|
|
|
|
|
// New-value stores are of class NV (slot 0), dual stores require class ST
|
|
|
|
// in slot 0 (PRM 5.5).
|
|
|
|
for (auto I : CurrentPacketMIs) {
|
|
|
|
SUnit *PacketSU = MIToSUnit.find(I)->second;
|
|
|
|
if (PacketSU->getInstr()->mayStore())
|
|
|
|
return false;
|
2012-05-04 05:52:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure it's NOT the post increment register that we are going to
|
|
|
|
// new value.
|
2016-08-02 01:55:48 +08:00
|
|
|
if (HII->isPostIncrement(MI) &&
|
2015-12-17 03:36:12 +08:00
|
|
|
getPostIncrementOperand(MI, HII).getReg() == DepReg) {
|
2012-05-04 05:52:53 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-08-02 01:55:48 +08:00
|
|
|
if (HII->isPostIncrement(PacketMI) && PacketMI.mayLoad() &&
|
2015-12-17 03:36:12 +08:00
|
|
|
getPostIncrementOperand(PacketMI, HII).getReg() == DepReg) {
|
|
|
|
// If source is post_inc, or absolute-set addressing, it can not feed
|
|
|
|
// into new value store
|
|
|
|
// r3 = memw(r2++#4)
|
|
|
|
// memw(r30 + #-1404) = r2.new -> can not be new value store
|
|
|
|
// arch spec section: 5.4.2.1.
|
2012-05-04 05:52:53 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-12-17 03:36:12 +08:00
|
|
|
if (isLoadAbsSet(PacketMI) && getAbsSetOperand(PacketMI).getReg() == DepReg)
|
|
|
|
return false;
|
|
|
|
|
2012-05-04 05:52:53 +08:00
|
|
|
// If the source that feeds the store is predicated, new value store must
|
2013-05-11 04:58:11 +08:00
|
|
|
// also be predicated.
|
2016-07-30 05:49:42 +08:00
|
|
|
if (HII->isPredicated(PacketMI)) {
|
|
|
|
if (!HII->isPredicated(MI))
|
2012-05-04 05:52:53 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// Check to make sure that they both will have their predicates
|
2015-12-17 03:36:12 +08:00
|
|
|
// evaluate identically.
|
2012-05-12 04:00:34 +08:00
|
|
|
unsigned predRegNumSrc = 0;
|
|
|
|
unsigned predRegNumDst = 0;
|
2014-04-25 13:30:21 +08:00
|
|
|
const TargetRegisterClass* predRegClass = nullptr;
|
2012-05-04 05:52:53 +08:00
|
|
|
|
2015-12-17 03:36:12 +08:00
|
|
|
// Get predicate register used in the source instruction.
|
2016-07-30 05:49:42 +08:00
|
|
|
for (auto &MO : PacketMI.operands()) {
|
2015-12-17 03:36:12 +08:00
|
|
|
if (!MO.isReg())
|
|
|
|
continue;
|
|
|
|
predRegNumSrc = MO.getReg();
|
|
|
|
predRegClass = HRI->getMinimalPhysRegClass(predRegNumSrc);
|
|
|
|
if (predRegClass == &Hexagon::PredRegsRegClass)
|
2012-05-04 05:52:53 +08:00
|
|
|
break;
|
|
|
|
}
|
2015-12-17 03:36:12 +08:00
|
|
|
assert((predRegClass == &Hexagon::PredRegsRegClass) &&
|
|
|
|
"predicate register not found in a predicated PacketMI instruction");
|
|
|
|
|
|
|
|
// Get predicate register used in new-value store instruction.
|
2016-07-30 05:49:42 +08:00
|
|
|
for (auto &MO : MI.operands()) {
|
2015-12-17 03:36:12 +08:00
|
|
|
if (!MO.isReg())
|
|
|
|
continue;
|
|
|
|
predRegNumDst = MO.getReg();
|
|
|
|
predRegClass = HRI->getMinimalPhysRegClass(predRegNumDst);
|
|
|
|
if (predRegClass == &Hexagon::PredRegsRegClass)
|
2012-05-04 05:52:53 +08:00
|
|
|
break;
|
|
|
|
}
|
2015-12-17 03:36:12 +08:00
|
|
|
assert((predRegClass == &Hexagon::PredRegsRegClass) &&
|
|
|
|
"predicate register not found in a predicated MI instruction");
|
2012-05-04 05:52:53 +08:00
|
|
|
|
|
|
|
// New-value register producer and user (store) need to satisfy these
|
|
|
|
// constraints:
|
|
|
|
// 1) Both instructions should be predicated on the same register.
|
|
|
|
// 2) If producer of the new-value register is .new predicated then store
|
|
|
|
// should also be .new predicated and if producer is not .new predicated
|
|
|
|
// then store should not be .new predicated.
|
|
|
|
// 3) Both new-value register producer and user should have same predicate
|
2015-12-17 03:36:12 +08:00
|
|
|
// sense, i.e, either both should be negated or both should be non-negated.
|
|
|
|
if (predRegNumDst != predRegNumSrc ||
|
2016-02-23 10:46:52 +08:00
|
|
|
HII->isDotNewInst(PacketMI) != HII->isDotNewInst(MI) ||
|
2016-07-30 05:49:42 +08:00
|
|
|
getPredicateSense(MI, HII) != getPredicateSense(PacketMI, HII))
|
2012-05-04 05:52:53 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure that other than the new-value register no other store instruction
|
|
|
|
// register has been modified in the same packet. Predicate registers can be
|
|
|
|
// modified by they should not be modified between the producer and the store
|
|
|
|
// instruction as it will make them both conditional on different values.
|
|
|
|
// We already know this to be true for all the instructions before and
|
|
|
|
// including PacketMI. Howerver, we need to perform the check for the
|
|
|
|
// remaining instructions in the packet.
|
|
|
|
|
|
|
|
unsigned StartCheck = 0;
|
|
|
|
|
2015-12-17 03:36:12 +08:00
|
|
|
for (auto I : CurrentPacketMIs) {
|
|
|
|
SUnit *TempSU = MIToSUnit.find(I)->second;
|
2016-07-30 05:49:42 +08:00
|
|
|
MachineInstr &TempMI = *TempSU->getInstr();
|
2012-05-04 05:52:53 +08:00
|
|
|
|
|
|
|
// Following condition is true for all the instructions until PacketMI is
|
|
|
|
// reached (StartCheck is set to 0 before the for loop).
|
|
|
|
// StartCheck flag is 1 for all the instructions after PacketMI.
|
2016-07-30 05:49:42 +08:00
|
|
|
if (&TempMI != &PacketMI && !StartCheck) // Start processing only after
|
|
|
|
continue; // encountering PacketMI.
|
2012-05-04 05:52:53 +08:00
|
|
|
|
|
|
|
StartCheck = 1;
|
2016-07-30 05:49:42 +08:00
|
|
|
if (&TempMI == &PacketMI) // We don't want to check PacketMI for dependence.
|
2012-05-04 05:52:53 +08:00
|
|
|
continue;
|
|
|
|
|
2016-07-30 05:49:42 +08:00
|
|
|
for (auto &MO : MI.operands())
|
2015-12-17 03:36:12 +08:00
|
|
|
if (MO.isReg() && TempSU->getInstr()->modifiesRegister(MO.getReg(), HRI))
|
2012-05-04 05:52:53 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-12-05 13:44:44 +08:00
|
|
|
// Make sure that for non-POST_INC stores:
|
2012-05-04 05:52:53 +08:00
|
|
|
// 1. The only use of reg is DepReg and no other registers.
|
|
|
|
// This handles V4 base+index registers.
|
|
|
|
// The following store can not be dot new.
|
2015-12-17 03:36:12 +08:00
|
|
|
// Eg. r0 = add(r0, #3)
|
2012-05-04 05:52:53 +08:00
|
|
|
// memw(r1+r0<<#2) = r0
|
2016-08-02 01:55:48 +08:00
|
|
|
if (!HII->isPostIncrement(MI)) {
|
2016-07-30 05:49:42 +08:00
|
|
|
for (unsigned opNum = 0; opNum < MI.getNumOperands()-1; opNum++) {
|
|
|
|
const MachineOperand &MO = MI.getOperand(opNum);
|
2015-12-17 03:36:12 +08:00
|
|
|
if (MO.isReg() && MO.getReg() == DepReg)
|
2012-05-04 05:52:53 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-17 03:36:12 +08:00
|
|
|
// If data definition is because of implicit definition of the register,
|
|
|
|
// do not newify the store. Eg.
|
|
|
|
// %R9<def> = ZXTH %R12, %D6<imp-use>, %R12<imp-def>
|
|
|
|
// S2_storerh_io %R8, 2, %R12<kill>; mem:ST2[%scevgep343]
|
2016-07-30 05:49:42 +08:00
|
|
|
for (auto &MO : PacketMI.operands()) {
|
2017-02-18 06:14:51 +08:00
|
|
|
if (MO.isRegMask() && MO.clobbersPhysReg(DepReg))
|
|
|
|
return false;
|
2015-12-17 03:36:12 +08:00
|
|
|
if (!MO.isReg() || !MO.isDef() || !MO.isImplicit())
|
|
|
|
continue;
|
|
|
|
unsigned R = MO.getReg();
|
|
|
|
if (R == DepReg || HRI->isSuperRegister(DepReg, R))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle imp-use of super reg case. There is a target independent side
|
|
|
|
// change that should prevent this situation but I am handling it for
|
|
|
|
// just-in-case. For example, we cannot newify R2 in the following case:
|
|
|
|
// %R3<def> = A2_tfrsi 0;
|
|
|
|
// S2_storeri_io %R0<kill>, 0, %R2<kill>, %D1<imp-use,kill>;
|
2016-07-30 05:49:42 +08:00
|
|
|
for (auto &MO : MI.operands()) {
|
2015-12-17 03:36:12 +08:00
|
|
|
if (MO.isReg() && MO.isUse() && MO.isImplicit() && MO.getReg() == DepReg)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-05-04 05:52:53 +08:00
|
|
|
// Can be dot new store.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-12-17 03:36:12 +08:00
|
|
|
// Can this MI to promoted to either new value store or new value jump.
|
2016-07-30 05:49:42 +08:00
|
|
|
bool HexagonPacketizerList::canPromoteToNewValue(const MachineInstr &MI,
|
2015-12-17 03:36:12 +08:00
|
|
|
const SUnit *PacketSU, unsigned DepReg,
|
|
|
|
MachineBasicBlock::iterator &MII) {
|
|
|
|
if (!HII->mayBeNewStore(MI))
|
2012-05-04 05:52:53 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// Check to see the store can be new value'ed.
|
2016-07-30 05:49:42 +08:00
|
|
|
MachineInstr &PacketMI = *PacketSU->getInstr();
|
2015-12-17 03:36:12 +08:00
|
|
|
if (canPromoteToNewValueStore(MI, PacketMI, DepReg))
|
2012-05-04 05:52:53 +08:00
|
|
|
return true;
|
|
|
|
|
|
|
|
// Check to see the compare/jump can be new value'ed.
|
|
|
|
// This is done as a pass on its own. Don't need to check it here.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-07-30 05:49:42 +08:00
|
|
|
static bool isImplicitDependency(const MachineInstr &I, unsigned DepReg) {
|
2017-02-18 06:14:51 +08:00
|
|
|
for (auto &MO : I.operands()) {
|
|
|
|
if (MO.isRegMask() && MO.clobbersPhysReg(DepReg))
|
|
|
|
return true;
|
2015-12-17 03:36:12 +08:00
|
|
|
if (MO.isReg() && MO.isDef() && (MO.getReg() == DepReg) && MO.isImplicit())
|
|
|
|
return true;
|
2017-02-18 06:14:51 +08:00
|
|
|
}
|
2015-12-17 03:36:12 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-05-04 05:52:53 +08:00
|
|
|
// Check to see if an instruction can be dot new
|
|
|
|
// There are three kinds.
|
|
|
|
// 1. dot new on predicate - V2/V3/V4
|
|
|
|
// 2. dot new on stores NV/ST - V4
|
|
|
|
// 3. dot new on jump NV/J - V4 -- This is generated in a pass.
|
2016-07-30 05:49:42 +08:00
|
|
|
bool HexagonPacketizerList::canPromoteToDotNew(const MachineInstr &MI,
|
2015-12-17 03:36:12 +08:00
|
|
|
const SUnit *PacketSU, unsigned DepReg, MachineBasicBlock::iterator &MII,
|
|
|
|
const TargetRegisterClass* RC) {
|
2013-03-29 03:44:04 +08:00
|
|
|
// Already a dot new instruction.
|
2015-12-17 03:36:12 +08:00
|
|
|
if (HII->isDotNewInst(MI) && !HII->mayBeNewStore(MI))
|
2012-05-04 05:52:53 +08:00
|
|
|
return false;
|
|
|
|
|
2016-07-27 04:30:30 +08:00
|
|
|
if (!isNewifiable(MI, RC))
|
2012-05-04 05:52:53 +08:00
|
|
|
return false;
|
|
|
|
|
2016-07-30 05:49:42 +08:00
|
|
|
const MachineInstr &PI = *PacketSU->getInstr();
|
2015-12-17 03:36:12 +08:00
|
|
|
|
|
|
|
// The "new value" cannot come from inline asm.
|
2016-07-30 05:49:42 +08:00
|
|
|
if (PI.isInlineAsm())
|
2015-12-17 03:36:12 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// IMPLICIT_DEFs won't materialize as real instructions, so .new makes no
|
|
|
|
// sense.
|
2016-07-30 05:49:42 +08:00
|
|
|
if (PI.isImplicitDef())
|
2015-12-17 03:36:12 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// If dependency is trough an implicitly defined register, we should not
|
|
|
|
// newify the use.
|
|
|
|
if (isImplicitDependency(PI, DepReg))
|
|
|
|
return false;
|
|
|
|
|
2016-07-30 05:49:42 +08:00
|
|
|
const MCInstrDesc& MCID = PI.getDesc();
|
2015-12-17 03:36:12 +08:00
|
|
|
const TargetRegisterClass *VecRC = HII->getRegClass(MCID, 0, HRI, MF);
|
|
|
|
if (DisableVecDblNVStores && VecRC == &Hexagon::VecDblRegsRegClass)
|
|
|
|
return false;
|
|
|
|
|
2012-05-04 05:52:53 +08:00
|
|
|
// predicate .new
|
2015-12-17 03:36:12 +08:00
|
|
|
if (RC == &Hexagon::PredRegsRegClass)
|
2016-08-24 00:01:01 +08:00
|
|
|
if (HII->isCondInst(MI) || HII->isJumpR(MI) || MI.isReturn())
|
2015-12-17 03:36:12 +08:00
|
|
|
return HII->predCanBeUsedAsDotNew(PI, DepReg);
|
|
|
|
|
|
|
|
if (RC != &Hexagon::PredRegsRegClass && !HII->mayBeNewStore(MI))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Create a dot new machine instruction to see if resources can be
|
|
|
|
// allocated. If not, bail out now.
|
|
|
|
int NewOpcode = HII->getDotNewOp(MI);
|
|
|
|
const MCInstrDesc &D = HII->get(NewOpcode);
|
|
|
|
MachineInstr *NewMI = MF.CreateMachineInstr(D, DebugLoc());
|
2016-02-28 03:09:00 +08:00
|
|
|
bool ResourcesAvailable = ResourceTracker->canReserveResources(*NewMI);
|
2015-12-17 03:36:12 +08:00
|
|
|
MF.DeleteMachineInstr(NewMI);
|
|
|
|
if (!ResourcesAvailable)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// New Value Store only. New Value Jump generated as a separate pass.
|
|
|
|
if (!canPromoteToNewValue(MI, PacketSU, DepReg, MII))
|
2012-05-04 05:52:53 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-12-17 03:36:12 +08:00
|
|
|
// Go through the packet instructions and search for an anti dependency between
|
|
|
|
// them and DepReg from MI. Consider this case:
|
2012-05-04 05:52:53 +08:00
|
|
|
// Trying to add
|
|
|
|
// a) %R1<def> = TFRI_cdNotPt %P3, 2
|
|
|
|
// to this packet:
|
|
|
|
// {
|
2015-12-17 03:36:12 +08:00
|
|
|
// b) %P0<def> = C2_or %P3<kill>, %P0<kill>
|
|
|
|
// c) %P3<def> = C2_tfrrp %R23
|
|
|
|
// d) %R1<def> = C2_cmovenewit %P3, 4
|
2012-05-04 05:52:53 +08:00
|
|
|
// }
|
|
|
|
// The P3 from a) and d) will be complements after
|
|
|
|
// a)'s P3 is converted to .new form
|
2015-12-17 03:36:12 +08:00
|
|
|
// Anti-dep between c) and b) is irrelevant for this case
|
2016-07-30 05:49:42 +08:00
|
|
|
bool HexagonPacketizerList::restrictingDepExistInPacket(MachineInstr &MI,
|
2015-12-17 03:36:12 +08:00
|
|
|
unsigned DepReg) {
|
2016-07-30 05:49:42 +08:00
|
|
|
SUnit *PacketSUDep = MIToSUnit.find(&MI)->second;
|
2012-05-04 05:52:53 +08:00
|
|
|
|
2015-12-17 03:36:12 +08:00
|
|
|
for (auto I : CurrentPacketMIs) {
|
2012-05-04 05:52:53 +08:00
|
|
|
// We only care for dependencies to predicated instructions
|
2016-02-23 10:46:52 +08:00
|
|
|
if (!HII->isPredicated(*I))
|
2015-12-17 03:36:12 +08:00
|
|
|
continue;
|
2012-05-04 05:52:53 +08:00
|
|
|
|
|
|
|
// Scheduling Unit for current insn in the packet
|
2015-12-17 03:36:12 +08:00
|
|
|
SUnit *PacketSU = MIToSUnit.find(I)->second;
|
2012-05-04 05:52:53 +08:00
|
|
|
|
2015-12-17 03:36:12 +08:00
|
|
|
// Look at dependencies between current members of the packet and
|
|
|
|
// predicate defining instruction MI. Make sure that dependency is
|
|
|
|
// on the exact register we care about.
|
2012-05-04 05:52:53 +08:00
|
|
|
if (PacketSU->isSucc(PacketSUDep)) {
|
|
|
|
for (unsigned i = 0; i < PacketSU->Succs.size(); ++i) {
|
2015-12-17 03:36:12 +08:00
|
|
|
auto &Dep = PacketSU->Succs[i];
|
|
|
|
if (Dep.getSUnit() == PacketSUDep && Dep.getKind() == SDep::Anti &&
|
|
|
|
Dep.getReg() == DepReg)
|
2012-05-04 05:52:53 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-15 00:36:34 +08:00
|
|
|
/// Gets the predicate register of a predicated instruction.
|
2016-02-23 10:46:52 +08:00
|
|
|
static unsigned getPredicatedRegister(MachineInstr &MI,
|
2013-05-23 23:43:11 +08:00
|
|
|
const HexagonInstrInfo *QII) {
|
2013-05-15 00:36:34 +08:00
|
|
|
/// We use the following rule: The first predicate register that is a use is
|
|
|
|
/// the predicate register of a predicated instruction.
|
|
|
|
assert(QII->isPredicated(MI) && "Must be predicated instruction");
|
|
|
|
|
2016-02-23 10:46:52 +08:00
|
|
|
for (auto &Op : MI.operands()) {
|
2013-05-15 00:36:34 +08:00
|
|
|
if (Op.isReg() && Op.getReg() && Op.isUse() &&
|
|
|
|
Hexagon::PredRegsRegClass.contains(Op.getReg()))
|
|
|
|
return Op.getReg();
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm_unreachable("Unknown instruction operand layout");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-05-04 05:52:53 +08:00
|
|
|
// Given two predicated instructions, this function detects whether
|
2015-12-17 03:36:12 +08:00
|
|
|
// the predicates are complements.
|
2016-02-23 10:46:52 +08:00
|
|
|
bool HexagonPacketizerList::arePredicatesComplements(MachineInstr &MI1,
|
|
|
|
MachineInstr &MI2) {
|
2013-05-15 00:36:34 +08:00
|
|
|
// If we don't know the predicate sense of the instructions bail out early, we
|
|
|
|
// need it later.
|
2015-12-17 03:36:12 +08:00
|
|
|
if (getPredicateSense(MI1, HII) == PK_Unknown ||
|
|
|
|
getPredicateSense(MI2, HII) == PK_Unknown)
|
2012-05-04 05:52:53 +08:00
|
|
|
return false;
|
|
|
|
|
2015-12-17 03:36:12 +08:00
|
|
|
// Scheduling unit for candidate.
|
2016-02-23 10:46:52 +08:00
|
|
|
SUnit *SU = MIToSUnit[&MI1];
|
2012-05-04 05:52:53 +08:00
|
|
|
|
|
|
|
// One corner case deals with the following scenario:
|
|
|
|
// Trying to add
|
2015-12-17 03:36:12 +08:00
|
|
|
// a) %R24<def> = A2_tfrt %P0, %R25
|
2012-05-04 05:52:53 +08:00
|
|
|
// to this packet:
|
|
|
|
// {
|
2015-12-17 03:36:12 +08:00
|
|
|
// b) %R25<def> = A2_tfrf %P0, %R24
|
|
|
|
// c) %P0<def> = C2_cmpeqi %R26, 1
|
2012-05-04 05:52:53 +08:00
|
|
|
// }
|
|
|
|
//
|
2015-12-17 03:36:12 +08:00
|
|
|
// On general check a) and b) are complements, but presence of c) will
|
|
|
|
// convert a) to .new form, and then it is not a complement.
|
|
|
|
// We attempt to detect it by analyzing existing dependencies in the packet.
|
2012-05-04 05:52:53 +08:00
|
|
|
|
|
|
|
// Analyze relationships between all existing members of the packet.
|
2015-12-17 03:36:12 +08:00
|
|
|
// Look for Anti dependecy on the same predicate reg as used in the
|
|
|
|
// candidate.
|
|
|
|
for (auto I : CurrentPacketMIs) {
|
|
|
|
// Scheduling Unit for current insn in the packet.
|
|
|
|
SUnit *PacketSU = MIToSUnit.find(I)->second;
|
2012-05-04 05:52:53 +08:00
|
|
|
|
|
|
|
// If this instruction in the packet is succeeded by the candidate...
|
|
|
|
if (PacketSU->isSucc(SU)) {
|
|
|
|
for (unsigned i = 0; i < PacketSU->Succs.size(); ++i) {
|
2015-12-17 03:36:12 +08:00
|
|
|
auto Dep = PacketSU->Succs[i];
|
|
|
|
// The corner case exist when there is true data dependency between
|
|
|
|
// candidate and one of current packet members, this dep is on
|
|
|
|
// predicate reg, and there already exist anti dep on the same pred in
|
2012-05-04 05:52:53 +08:00
|
|
|
// the packet.
|
2015-12-17 03:36:12 +08:00
|
|
|
if (Dep.getSUnit() == SU && Dep.getKind() == SDep::Data &&
|
|
|
|
Hexagon::PredRegsRegClass.contains(Dep.getReg())) {
|
|
|
|
// Here I know that I is predicate setting instruction with true
|
|
|
|
// data dep to candidate on the register we care about - c) in the
|
|
|
|
// above example. Now I need to see if there is an anti dependency
|
|
|
|
// from c) to any other instruction in the same packet on the pred
|
|
|
|
// reg of interest.
|
2016-07-30 05:49:42 +08:00
|
|
|
if (restrictingDepExistInPacket(*I, Dep.getReg()))
|
2015-12-17 03:36:12 +08:00
|
|
|
return false;
|
2012-05-04 05:52:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-17 03:36:12 +08:00
|
|
|
// If the above case does not apply, check regular complement condition.
|
|
|
|
// Check that the predicate register is the same and that the predicate
|
|
|
|
// sense is different We also need to differentiate .old vs. .new: !p0
|
|
|
|
// is not complementary to p0.new.
|
|
|
|
unsigned PReg1 = getPredicatedRegister(MI1, HII);
|
|
|
|
unsigned PReg2 = getPredicatedRegister(MI2, HII);
|
|
|
|
return PReg1 == PReg2 &&
|
|
|
|
Hexagon::PredRegsRegClass.contains(PReg1) &&
|
|
|
|
Hexagon::PredRegsRegClass.contains(PReg2) &&
|
|
|
|
getPredicateSense(MI1, HII) != getPredicateSense(MI2, HII) &&
|
2016-07-30 05:49:42 +08:00
|
|
|
HII->isDotNewInst(MI1) == HII->isDotNewInst(MI2);
|
2012-05-04 05:52:53 +08:00
|
|
|
}
|
|
|
|
|
2015-12-17 03:36:12 +08:00
|
|
|
// Initialize packetizer flags.
|
2012-05-04 05:52:53 +08:00
|
|
|
void HexagonPacketizerList::initPacketizerState() {
|
|
|
|
Dependence = false;
|
|
|
|
PromotedToDotNew = false;
|
|
|
|
GlueToNewValueJump = false;
|
|
|
|
GlueAllocframeStore = false;
|
|
|
|
FoundSequentialDependence = false;
|
|
|
|
}
|
|
|
|
|
2015-12-17 03:36:12 +08:00
|
|
|
// Ignore bundling of pseudo instructions.
|
2016-02-28 03:09:00 +08:00
|
|
|
bool HexagonPacketizerList::ignorePseudoInstruction(const MachineInstr &MI,
|
|
|
|
const MachineBasicBlock *) {
|
|
|
|
if (MI.isDebugValue())
|
2012-05-04 05:52:53 +08:00
|
|
|
return true;
|
|
|
|
|
2016-02-28 03:09:00 +08:00
|
|
|
if (MI.isCFIInstruction())
|
2015-04-22 23:47:35 +08:00
|
|
|
return false;
|
|
|
|
|
2015-12-17 03:36:12 +08:00
|
|
|
// We must print out inline assembly.
|
2016-02-28 03:09:00 +08:00
|
|
|
if (MI.isInlineAsm())
|
2012-05-04 05:52:53 +08:00
|
|
|
return false;
|
|
|
|
|
2016-02-28 03:09:00 +08:00
|
|
|
if (MI.isImplicitDef())
|
2015-12-17 03:36:12 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// We check if MI has any functional units mapped to it. If it doesn't,
|
|
|
|
// we ignore the instruction.
|
2016-02-28 03:09:00 +08:00
|
|
|
const MCInstrDesc& TID = MI.getDesc();
|
2015-12-17 03:36:12 +08:00
|
|
|
auto *IS = ResourceTracker->getInstrItins()->beginStage(TID.getSchedClass());
|
2012-06-23 04:27:13 +08:00
|
|
|
unsigned FuncUnits = IS->getUnits();
|
2012-05-04 05:52:53 +08:00
|
|
|
return !FuncUnits;
|
|
|
|
}
|
|
|
|
|
2016-02-28 03:09:00 +08:00
|
|
|
bool HexagonPacketizerList::isSoloInstruction(const MachineInstr &MI) {
|
|
|
|
if (MI.isEHLabel() || MI.isCFIInstruction())
|
2012-05-04 05:52:53 +08:00
|
|
|
return true;
|
|
|
|
|
2015-12-17 03:36:12 +08:00
|
|
|
// Consider inline asm to not be a solo instruction by default.
|
|
|
|
// Inline asm will be put in a packet temporarily, but then it will be
|
|
|
|
// removed, and placed outside of the packet (before or after, depending
|
|
|
|
// on dependencies). This is to reduce the impact of inline asm as a
|
|
|
|
// "packet splitting" instruction.
|
2016-02-28 03:09:00 +08:00
|
|
|
if (MI.isInlineAsm() && !ScheduleInlineAsm)
|
2012-05-04 05:52:53 +08:00
|
|
|
return true;
|
|
|
|
|
|
|
|
// From Hexagon V4 Programmer's Reference Manual 3.4.4 Grouping constraints:
|
|
|
|
// trap, pause, barrier, icinva, isync, and syncht are solo instructions.
|
|
|
|
// They must not be grouped with other instructions in a packet.
|
2016-07-30 05:49:42 +08:00
|
|
|
if (isSchedBarrier(MI))
|
2015-12-17 03:36:12 +08:00
|
|
|
return true;
|
|
|
|
|
2016-07-30 05:49:42 +08:00
|
|
|
if (HII->isSolo(MI))
|
2015-12-17 03:36:12 +08:00
|
|
|
return true;
|
|
|
|
|
2016-02-28 03:09:00 +08:00
|
|
|
if (MI.getOpcode() == Hexagon::A2_nop)
|
2012-05-04 05:52:53 +08:00
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-12-17 03:36:12 +08:00
|
|
|
// Quick check if instructions MI and MJ cannot coexist in the same packet.
|
|
|
|
// Limit the tests to be "one-way", e.g. "if MI->isBranch and MJ->isInlineAsm",
|
|
|
|
// but not the symmetric case: "if MJ->isBranch and MI->isInlineAsm".
|
|
|
|
// For full test call this function twice:
|
|
|
|
// cannotCoexistAsymm(MI, MJ) || cannotCoexistAsymm(MJ, MI)
|
|
|
|
// Doing the test only one way saves the amount of code in this function,
|
|
|
|
// since every test would need to be repeated with the MI and MJ reversed.
|
2016-07-30 05:49:42 +08:00
|
|
|
static bool cannotCoexistAsymm(const MachineInstr &MI, const MachineInstr &MJ,
|
2015-12-17 03:36:12 +08:00
|
|
|
const HexagonInstrInfo &HII) {
|
2016-07-30 05:49:42 +08:00
|
|
|
const MachineFunction *MF = MI.getParent()->getParent();
|
2015-12-17 03:36:12 +08:00
|
|
|
if (MF->getSubtarget<HexagonSubtarget>().hasV60TOpsOnly() &&
|
|
|
|
HII.isHVXMemWithAIndirect(MI, MJ))
|
|
|
|
return true;
|
2012-05-04 05:52:53 +08:00
|
|
|
|
2015-12-17 03:36:12 +08:00
|
|
|
// An inline asm cannot be together with a branch, because we may not be
|
|
|
|
// able to remove the asm out after packetizing (i.e. if the asm must be
|
|
|
|
// moved past the bundle). Similarly, two asms cannot be together to avoid
|
|
|
|
// complications when determining their relative order outside of a bundle.
|
2016-07-30 05:49:42 +08:00
|
|
|
if (MI.isInlineAsm())
|
|
|
|
return MJ.isInlineAsm() || MJ.isBranch() || MJ.isBarrier() ||
|
|
|
|
MJ.isCall() || MJ.isTerminator();
|
2012-05-04 05:52:53 +08:00
|
|
|
|
2016-08-20 00:57:05 +08:00
|
|
|
switch (MI.getOpcode()) {
|
|
|
|
case (Hexagon::S2_storew_locked):
|
|
|
|
case (Hexagon::S4_stored_locked):
|
|
|
|
case (Hexagon::L2_loadw_locked):
|
|
|
|
case (Hexagon::L4_loadd_locked):
|
|
|
|
case (Hexagon::Y4_l2fetch): {
|
|
|
|
// These instructions can only be grouped with ALU32 or non-floating-point
|
|
|
|
// XTYPE instructions. Since there is no convenient way of identifying fp
|
|
|
|
// XTYPE instructions, only allow grouping with ALU32 for now.
|
|
|
|
unsigned TJ = HII.getType(MJ);
|
2017-02-08 01:47:37 +08:00
|
|
|
if (TJ != HexagonII::TypeALU32_2op &&
|
|
|
|
TJ != HexagonII::TypeALU32_3op &&
|
|
|
|
TJ != HexagonII::TypeALU32_ADDI)
|
2016-08-20 00:57:05 +08:00
|
|
|
return true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-12-17 03:36:12 +08:00
|
|
|
// "False" really means that the quick check failed to determine if
|
|
|
|
// I and J cannot coexist.
|
|
|
|
return false;
|
|
|
|
}
|
2012-05-04 05:52:53 +08:00
|
|
|
|
|
|
|
|
2015-12-17 03:36:12 +08:00
|
|
|
// Full, symmetric check.
|
2016-07-30 05:49:42 +08:00
|
|
|
bool HexagonPacketizerList::cannotCoexist(const MachineInstr &MI,
|
|
|
|
const MachineInstr &MJ) {
|
2015-12-17 03:36:12 +08:00
|
|
|
return cannotCoexistAsymm(MI, MJ, *HII) || cannotCoexistAsymm(MJ, MI, *HII);
|
|
|
|
}
|
2012-05-04 05:52:53 +08:00
|
|
|
|
2015-12-17 03:36:12 +08:00
|
|
|
void HexagonPacketizerList::unpacketizeSoloInstrs(MachineFunction &MF) {
|
|
|
|
for (auto &B : MF) {
|
|
|
|
MachineBasicBlock::iterator BundleIt;
|
|
|
|
MachineBasicBlock::instr_iterator NextI;
|
|
|
|
for (auto I = B.instr_begin(), E = B.instr_end(); I != E; I = NextI) {
|
|
|
|
NextI = std::next(I);
|
2016-07-30 05:49:42 +08:00
|
|
|
MachineInstr &MI = *I;
|
|
|
|
if (MI.isBundle())
|
2015-12-17 03:36:12 +08:00
|
|
|
BundleIt = I;
|
2016-07-30 05:49:42 +08:00
|
|
|
if (!MI.isInsideBundle())
|
2015-12-17 03:36:12 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// Decide on where to insert the instruction that we are pulling out.
|
|
|
|
// Debug instructions always go before the bundle, but the placement of
|
|
|
|
// INLINE_ASM depends on potential dependencies. By default, try to
|
|
|
|
// put it before the bundle, but if the asm writes to a register that
|
|
|
|
// other instructions in the bundle read, then we need to place it
|
|
|
|
// after the bundle (to preserve the bundle semantics).
|
|
|
|
bool InsertBeforeBundle;
|
2016-07-30 05:49:42 +08:00
|
|
|
if (MI.isInlineAsm())
|
|
|
|
InsertBeforeBundle = !hasWriteToReadDep(MI, *BundleIt, HRI);
|
|
|
|
else if (MI.isDebugValue())
|
2015-12-17 03:36:12 +08:00
|
|
|
InsertBeforeBundle = true;
|
|
|
|
else
|
|
|
|
continue;
|
|
|
|
|
|
|
|
BundleIt = moveInstrOut(MI, BundleIt, InsertBeforeBundle);
|
|
|
|
}
|
2012-05-04 05:52:53 +08:00
|
|
|
}
|
2015-12-17 03:36:12 +08:00
|
|
|
}
|
2012-05-04 05:52:53 +08:00
|
|
|
|
2015-12-17 03:36:12 +08:00
|
|
|
// Check if a given instruction is of class "system".
|
2016-07-30 05:49:42 +08:00
|
|
|
static bool isSystemInstr(const MachineInstr &MI) {
|
|
|
|
unsigned Opc = MI.getOpcode();
|
2015-12-17 03:36:12 +08:00
|
|
|
switch (Opc) {
|
|
|
|
case Hexagon::Y2_barrier:
|
|
|
|
case Hexagon::Y2_dcfetchbo:
|
|
|
|
return true;
|
2012-05-04 05:52:53 +08:00
|
|
|
}
|
2015-12-17 03:36:12 +08:00
|
|
|
return false;
|
|
|
|
}
|
2012-05-04 05:52:53 +08:00
|
|
|
|
2016-07-30 05:49:42 +08:00
|
|
|
bool HexagonPacketizerList::hasDeadDependence(const MachineInstr &I,
|
|
|
|
const MachineInstr &J) {
|
2015-12-17 03:36:12 +08:00
|
|
|
// The dependence graph may not include edges between dead definitions,
|
|
|
|
// so without extra checks, we could end up packetizing two instruction
|
|
|
|
// defining the same (dead) register.
|
2016-07-30 05:49:42 +08:00
|
|
|
if (I.isCall() || J.isCall())
|
2012-05-04 05:52:53 +08:00
|
|
|
return false;
|
2016-07-30 05:49:42 +08:00
|
|
|
if (HII->isPredicated(I) || HII->isPredicated(J))
|
2012-05-04 05:52:53 +08:00
|
|
|
return false;
|
2015-12-17 03:36:12 +08:00
|
|
|
|
|
|
|
BitVector DeadDefs(Hexagon::NUM_TARGET_REGS);
|
2016-07-30 05:49:42 +08:00
|
|
|
for (auto &MO : I.operands()) {
|
2015-12-17 03:36:12 +08:00
|
|
|
if (!MO.isReg() || !MO.isDef() || !MO.isDead())
|
|
|
|
continue;
|
|
|
|
DeadDefs[MO.getReg()] = true;
|
2012-05-04 05:52:53 +08:00
|
|
|
}
|
|
|
|
|
2016-07-30 05:49:42 +08:00
|
|
|
for (auto &MO : J.operands()) {
|
2015-12-17 03:36:12 +08:00
|
|
|
if (!MO.isReg() || !MO.isDef() || !MO.isDead())
|
|
|
|
continue;
|
|
|
|
unsigned R = MO.getReg();
|
|
|
|
if (R != Hexagon::USR_OVF && DeadDefs[R])
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-07-30 05:49:42 +08:00
|
|
|
bool HexagonPacketizerList::hasControlDependence(const MachineInstr &I,
|
|
|
|
const MachineInstr &J) {
|
2015-12-17 03:36:12 +08:00
|
|
|
// A save callee-save register function call can only be in a packet
|
|
|
|
// with instructions that don't write to the callee-save registers.
|
|
|
|
if ((HII->isSaveCalleeSavedRegsCall(I) &&
|
|
|
|
doesModifyCalleeSavedReg(J, HRI)) ||
|
|
|
|
(HII->isSaveCalleeSavedRegsCall(J) &&
|
|
|
|
doesModifyCalleeSavedReg(I, HRI)))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Two control flow instructions cannot go in the same packet.
|
|
|
|
if (isControlFlow(I) && isControlFlow(J))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// \ref-manual (7.3.4) A loop setup packet in loopN or spNloop0 cannot
|
|
|
|
// contain a speculative indirect jump,
|
|
|
|
// a new-value compare jump or a dealloc_return.
|
2016-07-30 05:49:42 +08:00
|
|
|
auto isBadForLoopN = [this] (const MachineInstr &MI) -> bool {
|
|
|
|
if (MI.isCall() || HII->isDeallocRet(MI) || HII->isNewValueJump(MI))
|
2015-12-17 03:36:12 +08:00
|
|
|
return true;
|
2016-07-30 05:49:42 +08:00
|
|
|
if (HII->isPredicated(MI) && HII->isPredicatedNew(MI) && HII->isJumpR(MI))
|
2015-12-17 03:36:12 +08:00
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
if (HII->isLoopN(I) && isBadForLoopN(J))
|
|
|
|
return true;
|
|
|
|
if (HII->isLoopN(J) && isBadForLoopN(I))
|
|
|
|
return true;
|
|
|
|
|
2012-05-04 05:52:53 +08:00
|
|
|
// dealloc_return cannot appear in the same packet as a conditional or
|
|
|
|
// unconditional jump.
|
2015-12-17 03:36:12 +08:00
|
|
|
return HII->isDeallocRet(I) &&
|
2016-07-30 05:49:42 +08:00
|
|
|
(J.isBranch() || J.isCall() || J.isBarrier());
|
2015-12-17 03:36:12 +08:00
|
|
|
}
|
|
|
|
|
2017-02-18 06:14:51 +08:00
|
|
|
bool HexagonPacketizerList::hasRegMaskDependence(const MachineInstr &I,
|
|
|
|
const MachineInstr &J) {
|
|
|
|
// Adding I to a packet that has J.
|
|
|
|
|
|
|
|
// Regmasks are not reflected in the scheduling dependency graph, so
|
|
|
|
// we need to check them manually. This code assumes that regmasks only
|
|
|
|
// occur on calls, and the problematic case is when we add an instruction
|
|
|
|
// defining a register R to a packet that has a call that clobbers R via
|
|
|
|
// a regmask. Those cannot be packetized together, because the call will
|
|
|
|
// be executed last. That's also a reson why it is ok to add a call
|
|
|
|
// clobbering R to a packet that defines R.
|
|
|
|
|
|
|
|
// Look for regmasks in J.
|
|
|
|
for (const MachineOperand &OpJ : J.operands()) {
|
|
|
|
if (!OpJ.isRegMask())
|
|
|
|
continue;
|
|
|
|
assert((J.isCall() || HII->isTailCall(J)) && "Regmask on a non-call");
|
|
|
|
for (const MachineOperand &OpI : I.operands()) {
|
|
|
|
if (OpI.isReg()) {
|
|
|
|
if (OpJ.clobbersPhysReg(OpI.getReg()))
|
|
|
|
return true;
|
|
|
|
} else if (OpI.isRegMask()) {
|
|
|
|
// Both are regmasks. Assume that they intersect.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-07-30 05:49:42 +08:00
|
|
|
bool HexagonPacketizerList::hasV4SpecificDependence(const MachineInstr &I,
|
|
|
|
const MachineInstr &J) {
|
2015-12-17 03:36:12 +08:00
|
|
|
bool SysI = isSystemInstr(I), SysJ = isSystemInstr(J);
|
2016-07-30 05:49:42 +08:00
|
|
|
bool StoreI = I.mayStore(), StoreJ = J.mayStore();
|
2015-12-17 03:36:12 +08:00
|
|
|
if ((SysI && StoreJ) || (SysJ && StoreI))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (StoreI && StoreJ) {
|
|
|
|
if (HII->isNewValueInst(J) || HII->isMemOp(J) || HII->isMemOp(I))
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
// A memop cannot be in the same packet with another memop or a store.
|
|
|
|
// Two stores can be together, but here I and J cannot both be stores.
|
|
|
|
bool MopStI = HII->isMemOp(I) || StoreI;
|
|
|
|
bool MopStJ = HII->isMemOp(J) || StoreJ;
|
|
|
|
if (MopStI && MopStJ)
|
|
|
|
return true;
|
2012-05-04 05:52:53 +08:00
|
|
|
}
|
|
|
|
|
2015-12-17 03:36:12 +08:00
|
|
|
return (StoreJ && HII->isDeallocRet(I)) || (StoreI && HII->isDeallocRet(J));
|
|
|
|
}
|
2012-05-04 05:52:53 +08:00
|
|
|
|
2015-12-17 03:36:12 +08:00
|
|
|
// SUI is the current instruction that is out side of the current packet.
|
|
|
|
// SUJ is the current instruction inside the current packet against which that
|
|
|
|
// SUI will be packetized.
|
|
|
|
bool HexagonPacketizerList::isLegalToPacketizeTogether(SUnit *SUI, SUnit *SUJ) {
|
2016-07-30 05:49:42 +08:00
|
|
|
assert(SUI->getInstr() && SUJ->getInstr());
|
|
|
|
MachineInstr &I = *SUI->getInstr();
|
|
|
|
MachineInstr &J = *SUJ->getInstr();
|
2015-12-17 03:36:12 +08:00
|
|
|
|
|
|
|
// Clear IgnoreDepMIs when Packet starts.
|
|
|
|
if (CurrentPacketMIs.size() == 1)
|
|
|
|
IgnoreDepMIs.clear();
|
|
|
|
|
2016-07-30 05:49:42 +08:00
|
|
|
MachineBasicBlock::iterator II = I.getIterator();
|
2015-12-17 03:36:12 +08:00
|
|
|
|
|
|
|
// Solo instructions cannot go in the packet.
|
2016-07-30 05:49:42 +08:00
|
|
|
assert(!isSoloInstruction(I) && "Unexpected solo instr!");
|
2015-12-17 03:36:12 +08:00
|
|
|
|
|
|
|
if (cannotCoexist(I, J))
|
2015-02-10 05:56:37 +08:00
|
|
|
return false;
|
2012-05-04 05:52:53 +08:00
|
|
|
|
2015-12-17 03:36:12 +08:00
|
|
|
Dependence = hasDeadDependence(I, J) || hasControlDependence(I, J);
|
|
|
|
if (Dependence)
|
2015-02-10 05:56:37 +08:00
|
|
|
return false;
|
2012-05-04 05:52:53 +08:00
|
|
|
|
2017-02-18 06:14:51 +08:00
|
|
|
// Regmasks are not accounted for in the scheduling graph, so we need
|
|
|
|
// to explicitly check for dependencies caused by them. They should only
|
|
|
|
// appear on calls, so it's not too pessimistic to reject all regmask
|
|
|
|
// dependencies.
|
|
|
|
Dependence = hasRegMaskDependence(I, J);
|
|
|
|
if (Dependence)
|
|
|
|
return false;
|
|
|
|
|
2015-12-17 03:36:12 +08:00
|
|
|
// V4 allows dual stores. It does not allow second store, if the first
|
|
|
|
// store is not in SLOT0. New value store, new value jump, dealloc_return
|
|
|
|
// and memop always take SLOT0. Arch spec 3.4.4.2.
|
|
|
|
Dependence = hasV4SpecificDependence(I, J);
|
|
|
|
if (Dependence)
|
2015-02-10 05:56:37 +08:00
|
|
|
return false;
|
2012-05-04 05:52:53 +08:00
|
|
|
|
2015-02-10 05:56:37 +08:00
|
|
|
// If an instruction feeds new value jump, glue it.
|
2016-07-30 05:49:42 +08:00
|
|
|
MachineBasicBlock::iterator NextMII = I.getIterator();
|
2015-02-10 05:56:37 +08:00
|
|
|
++NextMII;
|
2016-07-30 05:49:42 +08:00
|
|
|
if (NextMII != I.getParent()->end() && HII->isNewValueJump(*NextMII)) {
|
2016-07-12 09:55:32 +08:00
|
|
|
MachineInstr &NextMI = *NextMII;
|
2012-05-04 05:52:53 +08:00
|
|
|
|
2015-02-10 05:56:37 +08:00
|
|
|
bool secondRegMatch = false;
|
2016-07-12 09:55:32 +08:00
|
|
|
const MachineOperand &NOp0 = NextMI.getOperand(0);
|
|
|
|
const MachineOperand &NOp1 = NextMI.getOperand(1);
|
2012-05-04 05:52:53 +08:00
|
|
|
|
2016-07-30 05:49:42 +08:00
|
|
|
if (NOp1.isReg() && I.getOperand(0).getReg() == NOp1.getReg())
|
2015-02-10 05:56:37 +08:00
|
|
|
secondRegMatch = true;
|
2012-05-04 05:52:53 +08:00
|
|
|
|
2016-07-30 05:49:42 +08:00
|
|
|
for (auto T : CurrentPacketMIs) {
|
|
|
|
SUnit *PacketSU = MIToSUnit.find(T)->second;
|
|
|
|
MachineInstr &PI = *PacketSU->getInstr();
|
2015-12-17 03:36:12 +08:00
|
|
|
// NVJ can not be part of the dual jump - Arch Spec: section 7.8.
|
2016-07-30 05:49:42 +08:00
|
|
|
if (PI.isCall()) {
|
2015-02-10 05:56:37 +08:00
|
|
|
Dependence = true;
|
|
|
|
break;
|
|
|
|
}
|
2015-12-17 03:36:12 +08:00
|
|
|
// Validate:
|
2015-02-10 05:56:37 +08:00
|
|
|
// 1. Packet does not have a store in it.
|
|
|
|
// 2. If the first operand of the nvj is newified, and the second
|
|
|
|
// operand is also a reg, it (second reg) is not defined in
|
|
|
|
// the same packet.
|
|
|
|
// 3. If the second operand of the nvj is newified, (which means
|
|
|
|
// first operand is also a reg), first reg is not defined in
|
|
|
|
// the same packet.
|
2016-07-30 05:49:42 +08:00
|
|
|
if (PI.getOpcode() == Hexagon::S2_allocframe || PI.mayStore() ||
|
2015-12-17 03:36:12 +08:00
|
|
|
HII->isLoopN(PI)) {
|
|
|
|
Dependence = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// Check #2/#3.
|
|
|
|
const MachineOperand &OpR = secondRegMatch ? NOp0 : NOp1;
|
2016-07-30 05:49:42 +08:00
|
|
|
if (OpR.isReg() && PI.modifiesRegister(OpR.getReg(), HRI)) {
|
2015-02-10 05:56:37 +08:00
|
|
|
Dependence = true;
|
|
|
|
break;
|
2012-05-04 05:52:53 +08:00
|
|
|
}
|
|
|
|
}
|
2015-12-17 03:36:12 +08:00
|
|
|
|
|
|
|
if (Dependence)
|
2015-02-10 05:56:37 +08:00
|
|
|
return false;
|
2015-12-17 03:36:12 +08:00
|
|
|
GlueToNewValueJump = true;
|
2012-05-04 05:52:53 +08:00
|
|
|
}
|
|
|
|
|
2015-12-17 03:36:12 +08:00
|
|
|
// There no dependency between a prolog instruction and its successor.
|
|
|
|
if (!SUJ->isSucc(SUI))
|
|
|
|
return true;
|
2012-05-04 05:52:53 +08:00
|
|
|
|
2015-12-17 03:36:12 +08:00
|
|
|
for (unsigned i = 0; i < SUJ->Succs.size(); ++i) {
|
|
|
|
if (FoundSequentialDependence)
|
|
|
|
break;
|
2012-05-04 05:52:53 +08:00
|
|
|
|
2015-12-17 03:36:12 +08:00
|
|
|
if (SUJ->Succs[i].getSUnit() != SUI)
|
|
|
|
continue;
|
2012-05-04 05:52:53 +08:00
|
|
|
|
2015-12-17 03:36:12 +08:00
|
|
|
SDep::Kind DepType = SUJ->Succs[i].getKind();
|
|
|
|
// For direct calls:
|
|
|
|
// Ignore register dependences for call instructions for packetization
|
|
|
|
// purposes except for those due to r31 and predicate registers.
|
|
|
|
//
|
|
|
|
// For indirect calls:
|
|
|
|
// Same as direct calls + check for true dependences to the register
|
|
|
|
// used in the indirect call.
|
|
|
|
//
|
|
|
|
// We completely ignore Order dependences for call instructions.
|
|
|
|
//
|
|
|
|
// For returns:
|
|
|
|
// Ignore register dependences for return instructions like jumpr,
|
|
|
|
// dealloc return unless we have dependencies on the explicit uses
|
|
|
|
// of the registers used by jumpr (like r31) or dealloc return
|
|
|
|
// (like r29 or r30).
|
|
|
|
unsigned DepReg = 0;
|
|
|
|
const TargetRegisterClass *RC = nullptr;
|
|
|
|
if (DepType == SDep::Data) {
|
|
|
|
DepReg = SUJ->Succs[i].getReg();
|
|
|
|
RC = HRI->getMinimalPhysRegClass(DepReg);
|
|
|
|
}
|
2012-05-04 05:52:53 +08:00
|
|
|
|
2016-08-24 00:01:01 +08:00
|
|
|
if (I.isCall() || HII->isJumpR(I) || I.isReturn() || HII->isTailCall(I)) {
|
2015-12-17 03:36:12 +08:00
|
|
|
if (!isRegDependence(DepType))
|
|
|
|
continue;
|
|
|
|
if (!isCallDependent(I, DepType, SUJ->Succs[i].getReg()))
|
|
|
|
continue;
|
|
|
|
}
|
2012-05-04 05:52:53 +08:00
|
|
|
|
2015-12-17 03:36:12 +08:00
|
|
|
if (DepType == SDep::Data) {
|
|
|
|
if (canPromoteToDotCur(J, SUJ, DepReg, II, RC))
|
|
|
|
if (promoteToDotCur(J, DepType, II, RC))
|
|
|
|
continue;
|
|
|
|
}
|
2012-05-04 05:52:53 +08:00
|
|
|
|
2015-12-17 03:36:12 +08:00
|
|
|
// Data dpendence ok if we have load.cur.
|
|
|
|
if (DepType == SDep::Data && HII->isDotCurInst(J)) {
|
2017-05-04 04:10:36 +08:00
|
|
|
if (HII->isHVXVec(I))
|
2015-12-17 03:36:12 +08:00
|
|
|
continue;
|
|
|
|
}
|
2012-05-04 05:52:53 +08:00
|
|
|
|
2015-12-17 03:36:12 +08:00
|
|
|
// For instructions that can be promoted to dot-new, try to promote.
|
|
|
|
if (DepType == SDep::Data) {
|
|
|
|
if (canPromoteToDotNew(I, SUJ, DepReg, II, RC)) {
|
|
|
|
if (promoteToDotNew(I, DepType, II, RC)) {
|
|
|
|
PromotedToDotNew = true;
|
2017-05-04 04:10:36 +08:00
|
|
|
if (cannotCoexist(I, J))
|
|
|
|
FoundSequentialDependence = true;
|
2015-12-17 03:36:12 +08:00
|
|
|
continue;
|
|
|
|
}
|
2012-05-04 05:52:53 +08:00
|
|
|
}
|
2015-12-17 03:36:12 +08:00
|
|
|
if (HII->isNewValueJump(I))
|
|
|
|
continue;
|
|
|
|
}
|
2012-05-04 05:52:53 +08:00
|
|
|
|
2015-12-17 03:36:12 +08:00
|
|
|
// For predicated instructions, if the predicates are complements then
|
|
|
|
// there can be no dependence.
|
2016-07-30 05:49:42 +08:00
|
|
|
if (HII->isPredicated(I) && HII->isPredicated(J) &&
|
|
|
|
arePredicatesComplements(I, J)) {
|
2015-12-17 03:36:12 +08:00
|
|
|
// Not always safe to do this translation.
|
|
|
|
// DAG Builder attempts to reduce dependence edges using transitive
|
|
|
|
// nature of dependencies. Here is an example:
|
2012-05-04 05:52:53 +08:00
|
|
|
//
|
2015-12-17 03:36:12 +08:00
|
|
|
// r0 = tfr_pt ... (1)
|
|
|
|
// r0 = tfr_pf ... (2)
|
|
|
|
// r0 = tfr_pt ... (3)
|
2012-05-04 05:52:53 +08:00
|
|
|
//
|
2015-12-17 03:36:12 +08:00
|
|
|
// There will be an output dependence between (1)->(2) and (2)->(3).
|
|
|
|
// However, there is no dependence edge between (1)->(3). This results
|
|
|
|
// in all 3 instructions going in the same packet. We ignore dependce
|
|
|
|
// only once to avoid this situation.
|
2016-08-12 06:21:41 +08:00
|
|
|
auto Itr = find(IgnoreDepMIs, &J);
|
2015-12-17 03:36:12 +08:00
|
|
|
if (Itr != IgnoreDepMIs.end()) {
|
|
|
|
Dependence = true;
|
|
|
|
return false;
|
|
|
|
}
|
2016-07-30 05:49:42 +08:00
|
|
|
IgnoreDepMIs.push_back(&I);
|
2015-12-17 03:36:12 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ignore Order dependences between unconditional direct branches
|
|
|
|
// and non-control-flow instructions.
|
2016-07-30 05:49:42 +08:00
|
|
|
if (isDirectJump(I) && !J.isBranch() && !J.isCall() &&
|
2015-12-17 03:36:12 +08:00
|
|
|
DepType == SDep::Order)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Ignore all dependences for jumps except for true and output
|
|
|
|
// dependences.
|
2016-07-30 05:49:42 +08:00
|
|
|
if (I.isConditionalBranch() && DepType != SDep::Data &&
|
2015-12-17 03:36:12 +08:00
|
|
|
DepType != SDep::Output)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (DepType == SDep::Output) {
|
|
|
|
FoundSequentialDependence = true;
|
|
|
|
break;
|
|
|
|
}
|
2012-05-04 05:52:53 +08:00
|
|
|
|
2015-12-17 03:36:12 +08:00
|
|
|
// For Order dependences:
|
|
|
|
// 1. On V4 or later, volatile loads/stores can be packetized together,
|
|
|
|
// unless other rules prevent is.
|
|
|
|
// 2. Store followed by a load is not allowed.
|
|
|
|
// 3. Store followed by a store is only valid on V4 or later.
|
|
|
|
// 4. Load followed by any memory operation is allowed.
|
|
|
|
if (DepType == SDep::Order) {
|
|
|
|
if (!PacketizeVolatiles) {
|
2016-07-30 05:49:42 +08:00
|
|
|
bool OrdRefs = I.hasOrderedMemoryRef() || J.hasOrderedMemoryRef();
|
2015-12-17 03:36:12 +08:00
|
|
|
if (OrdRefs) {
|
2012-05-04 05:52:53 +08:00
|
|
|
FoundSequentialDependence = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-12-17 03:36:12 +08:00
|
|
|
// J is first, I is second.
|
2016-07-30 05:49:42 +08:00
|
|
|
bool LoadJ = J.mayLoad(), StoreJ = J.mayStore();
|
|
|
|
bool LoadI = I.mayLoad(), StoreI = I.mayStore();
|
2015-12-17 03:36:12 +08:00
|
|
|
if (StoreJ) {
|
|
|
|
// Two stores are only allowed on V4+. Load following store is never
|
|
|
|
// allowed.
|
|
|
|
if (LoadI) {
|
2012-05-04 05:52:53 +08:00
|
|
|
FoundSequentialDependence = true;
|
|
|
|
break;
|
|
|
|
}
|
2015-12-17 03:36:12 +08:00
|
|
|
} else if (!LoadJ || (!LoadI && !StoreI)) {
|
|
|
|
// If J is neither load nor store, assume a dependency.
|
|
|
|
// If J is a load, but I is neither, also assume a dependency.
|
2012-05-04 05:52:53 +08:00
|
|
|
FoundSequentialDependence = true;
|
|
|
|
break;
|
|
|
|
}
|
2015-12-17 03:36:12 +08:00
|
|
|
// Store followed by store: not OK on V2.
|
|
|
|
// Store followed by load: not OK on all.
|
|
|
|
// Load followed by store: OK on all.
|
|
|
|
// Load followed by load: OK on all.
|
|
|
|
continue;
|
2012-05-04 05:52:53 +08:00
|
|
|
}
|
|
|
|
|
2015-12-17 03:36:12 +08:00
|
|
|
// For V4, special case ALLOCFRAME. Even though there is dependency
|
|
|
|
// between ALLOCFRAME and subsequent store, allow it to be packetized
|
|
|
|
// in a same packet. This implies that the store is using the caller's
|
|
|
|
// SP. Hence, offset needs to be updated accordingly.
|
2016-07-30 05:49:42 +08:00
|
|
|
if (DepType == SDep::Data && J.getOpcode() == Hexagon::S2_allocframe) {
|
|
|
|
unsigned Opc = I.getOpcode();
|
2015-12-17 03:36:12 +08:00
|
|
|
switch (Opc) {
|
|
|
|
case Hexagon::S2_storerd_io:
|
|
|
|
case Hexagon::S2_storeri_io:
|
|
|
|
case Hexagon::S2_storerh_io:
|
|
|
|
case Hexagon::S2_storerb_io:
|
2016-07-30 05:49:42 +08:00
|
|
|
if (I.getOperand(0).getReg() == HRI->getStackRegister()) {
|
2016-07-26 22:24:46 +08:00
|
|
|
// Since this store is to be glued with allocframe in the same
|
|
|
|
// packet, it will use SP of the previous stack frame, i.e.
|
|
|
|
// caller's SP. Therefore, we need to recalculate offset
|
|
|
|
// according to this change.
|
|
|
|
GlueAllocframeStore = useCallersSP(I);
|
|
|
|
if (GlueAllocframeStore)
|
2015-12-17 03:36:12 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-07 03:13:38 +08:00
|
|
|
// There are certain anti-dependencies that cannot be ignored.
|
|
|
|
// Specifically:
|
|
|
|
// J2_call ... %R0<imp-def> ; SUJ
|
|
|
|
// R0 = ... ; SUI
|
|
|
|
// Those cannot be packetized together, since the call will observe
|
|
|
|
// the effect of the assignment to R0.
|
2017-02-18 06:14:51 +08:00
|
|
|
if ((DepType == SDep::Anti || DepType == SDep::Output) && J.isCall()) {
|
2016-05-07 03:13:38 +08:00
|
|
|
// Check if I defines any volatile register. We should also check
|
|
|
|
// registers that the call may read, but these happen to be a
|
|
|
|
// subset of the volatile register set.
|
2017-02-18 06:14:51 +08:00
|
|
|
for (const MachineOperand &Op : I.operands()) {
|
|
|
|
if (Op.isReg() && Op.isDef()) {
|
|
|
|
unsigned R = Op.getReg();
|
|
|
|
if (!J.readsRegister(R, HRI) && !J.modifiesRegister(R, HRI))
|
|
|
|
continue;
|
|
|
|
} else if (!Op.isRegMask()) {
|
|
|
|
// If I has a regmask assume dependency.
|
2016-05-07 03:13:38 +08:00
|
|
|
continue;
|
2017-02-18 06:14:51 +08:00
|
|
|
}
|
2016-05-07 03:13:38 +08:00
|
|
|
FoundSequentialDependence = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Skip over remaining anti-dependences. Two instructions that are
|
|
|
|
// anti-dependent can share a packet, since in most such cases all
|
|
|
|
// operands are read before any modifications take place.
|
|
|
|
// The exceptions are branch and call instructions, since they are
|
|
|
|
// executed after all other instructions have completed (at least
|
|
|
|
// conceptually).
|
2015-12-17 03:36:12 +08:00
|
|
|
if (DepType != SDep::Anti) {
|
|
|
|
FoundSequentialDependence = true;
|
|
|
|
break;
|
2012-05-04 05:52:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-17 03:36:12 +08:00
|
|
|
if (FoundSequentialDependence) {
|
|
|
|
Dependence = true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-05-04 05:52:53 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HexagonPacketizerList::isLegalToPruneDependencies(SUnit *SUI, SUnit *SUJ) {
|
2016-07-30 05:49:42 +08:00
|
|
|
assert(SUI->getInstr() && SUJ->getInstr());
|
|
|
|
MachineInstr &I = *SUI->getInstr();
|
|
|
|
MachineInstr &J = *SUJ->getInstr();
|
2012-05-04 05:52:53 +08:00
|
|
|
|
2017-05-04 04:10:36 +08:00
|
|
|
bool Coexist = !cannotCoexist(I, J);
|
2012-05-04 05:52:53 +08:00
|
|
|
|
2017-05-04 04:10:36 +08:00
|
|
|
if (Coexist && !Dependence)
|
2015-12-17 03:36:12 +08:00
|
|
|
return true;
|
2012-05-04 05:52:53 +08:00
|
|
|
|
2015-12-17 03:36:12 +08:00
|
|
|
// Check if the instruction was promoted to a dot-new. If so, demote it
|
|
|
|
// back into a dot-old.
|
|
|
|
if (PromotedToDotNew)
|
|
|
|
demoteToDotOld(I);
|
|
|
|
|
|
|
|
cleanUpDotCur();
|
|
|
|
// Check if the instruction (must be a store) was glued with an allocframe
|
|
|
|
// instruction. If so, restore its offset to its original value, i.e. use
|
|
|
|
// current SP instead of caller's SP.
|
|
|
|
if (GlueAllocframeStore) {
|
2016-07-26 22:24:46 +08:00
|
|
|
useCalleesSP(I);
|
|
|
|
GlueAllocframeStore = false;
|
2012-05-04 05:52:53 +08:00
|
|
|
}
|
2015-12-17 03:36:12 +08:00
|
|
|
return false;
|
2012-05-04 05:52:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
MachineBasicBlock::iterator
|
2016-02-28 03:09:00 +08:00
|
|
|
HexagonPacketizerList::addToPacket(MachineInstr &MI) {
|
2016-07-30 05:49:42 +08:00
|
|
|
MachineBasicBlock::iterator MII = MI.getIterator();
|
2016-02-28 03:09:00 +08:00
|
|
|
MachineBasicBlock *MBB = MI.getParent();
|
2017-05-03 02:12:19 +08:00
|
|
|
|
|
|
|
if (CurrentPacketMIs.size() == 0)
|
|
|
|
PacketStalls = false;
|
|
|
|
PacketStalls |= producesStall(MI);
|
|
|
|
|
|
|
|
if (MI.isImplicitDef())
|
2015-12-17 03:36:12 +08:00
|
|
|
return MII;
|
|
|
|
assert(ResourceTracker->canReserveResources(MI));
|
|
|
|
|
2016-07-30 05:49:42 +08:00
|
|
|
bool ExtMI = HII->isExtended(MI) || HII->isConstExtended(MI);
|
2015-12-17 03:36:12 +08:00
|
|
|
bool Good = true;
|
|
|
|
|
|
|
|
if (GlueToNewValueJump) {
|
2016-02-28 03:09:00 +08:00
|
|
|
MachineInstr &NvjMI = *++MII;
|
2015-12-17 03:36:12 +08:00
|
|
|
// We need to put both instructions in the same packet: MI and NvjMI.
|
|
|
|
// Either of them can require a constant extender. Try to add both to
|
|
|
|
// the current packet, and if that fails, end the packet and start a
|
|
|
|
// new one.
|
|
|
|
ResourceTracker->reserveResources(MI);
|
|
|
|
if (ExtMI)
|
|
|
|
Good = tryAllocateResourcesForConstExt(true);
|
|
|
|
|
2016-07-30 05:49:42 +08:00
|
|
|
bool ExtNvjMI = HII->isExtended(NvjMI) || HII->isConstExtended(NvjMI);
|
2015-12-17 03:36:12 +08:00
|
|
|
if (Good) {
|
|
|
|
if (ResourceTracker->canReserveResources(NvjMI))
|
|
|
|
ResourceTracker->reserveResources(NvjMI);
|
|
|
|
else
|
|
|
|
Good = false;
|
|
|
|
}
|
|
|
|
if (Good && ExtNvjMI)
|
|
|
|
Good = tryAllocateResourcesForConstExt(true);
|
2012-05-04 05:52:53 +08:00
|
|
|
|
2015-12-17 03:36:12 +08:00
|
|
|
if (!Good) {
|
|
|
|
endPacket(MBB, MI);
|
2012-05-04 05:52:53 +08:00
|
|
|
assert(ResourceTracker->canReserveResources(MI));
|
|
|
|
ResourceTracker->reserveResources(MI);
|
2015-12-17 03:36:12 +08:00
|
|
|
if (ExtMI) {
|
|
|
|
assert(canReserveResourcesForConstExt());
|
|
|
|
tryAllocateResourcesForConstExt(true);
|
2012-05-04 05:52:53 +08:00
|
|
|
}
|
2015-12-17 03:36:12 +08:00
|
|
|
assert(ResourceTracker->canReserveResources(NvjMI));
|
|
|
|
ResourceTracker->reserveResources(NvjMI);
|
|
|
|
if (ExtNvjMI) {
|
|
|
|
assert(canReserveResourcesForConstExt());
|
|
|
|
reserveResourcesForConstExt();
|
2012-05-04 05:52:53 +08:00
|
|
|
}
|
|
|
|
}
|
2016-02-28 03:09:00 +08:00
|
|
|
CurrentPacketMIs.push_back(&MI);
|
|
|
|
CurrentPacketMIs.push_back(&NvjMI);
|
2012-05-04 05:52:53 +08:00
|
|
|
return MII;
|
2015-12-17 03:36:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ResourceTracker->reserveResources(MI);
|
|
|
|
if (ExtMI && !tryAllocateResourcesForConstExt(true)) {
|
|
|
|
endPacket(MBB, MI);
|
|
|
|
if (PromotedToDotNew)
|
2016-07-30 05:49:42 +08:00
|
|
|
demoteToDotOld(MI);
|
2016-07-26 22:24:46 +08:00
|
|
|
if (GlueAllocframeStore) {
|
2016-07-30 05:49:42 +08:00
|
|
|
useCalleesSP(MI);
|
2016-07-26 22:24:46 +08:00
|
|
|
GlueAllocframeStore = false;
|
|
|
|
}
|
2015-12-17 03:36:12 +08:00
|
|
|
ResourceTracker->reserveResources(MI);
|
|
|
|
reserveResourcesForConstExt();
|
|
|
|
}
|
|
|
|
|
2016-02-28 03:09:00 +08:00
|
|
|
CurrentPacketMIs.push_back(&MI);
|
2015-12-17 03:36:12 +08:00
|
|
|
return MII;
|
|
|
|
}
|
|
|
|
|
|
|
|
void HexagonPacketizerList::endPacket(MachineBasicBlock *MBB,
|
2016-02-28 03:09:00 +08:00
|
|
|
MachineBasicBlock::iterator MI) {
|
2015-12-17 03:36:12 +08:00
|
|
|
OldPacketMIs = CurrentPacketMIs;
|
|
|
|
VLIWPacketizerList::endPacket(MBB, MI);
|
|
|
|
}
|
|
|
|
|
2016-02-28 03:09:00 +08:00
|
|
|
bool HexagonPacketizerList::shouldAddToPacket(const MachineInstr &MI) {
|
2016-07-30 05:49:42 +08:00
|
|
|
return !producesStall(MI);
|
2015-12-17 03:36:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// V60 forward scheduling.
|
2016-07-30 05:49:42 +08:00
|
|
|
bool HexagonPacketizerList::producesStall(const MachineInstr &I) {
|
2017-05-03 02:12:19 +08:00
|
|
|
// If the packet already stalls, then ignore the stall from a subsequent
|
|
|
|
// instruction in the same packet.
|
|
|
|
if (PacketStalls)
|
|
|
|
return false;
|
|
|
|
|
2015-12-17 03:36:12 +08:00
|
|
|
// Check whether the previous packet is in a different loop. If this is the
|
|
|
|
// case, there is little point in trying to avoid a stall because that would
|
|
|
|
// favor the rare case (loop entry) over the common case (loop iteration).
|
|
|
|
//
|
|
|
|
// TODO: We should really be able to check all the incoming edges if this is
|
|
|
|
// the first packet in a basic block, so we can avoid stalls from the loop
|
|
|
|
// backedge.
|
|
|
|
if (!OldPacketMIs.empty()) {
|
|
|
|
auto *OldBB = OldPacketMIs.front()->getParent();
|
2016-07-30 05:49:42 +08:00
|
|
|
auto *ThisBB = I.getParent();
|
2015-12-17 03:36:12 +08:00
|
|
|
if (MLI->getLoopFor(OldBB) != MLI->getLoopFor(ThisBB))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-05-04 04:10:36 +08:00
|
|
|
SUnit *SUI = MIToSUnit[const_cast<MachineInstr *>(&I)];
|
2017-05-03 02:12:19 +08:00
|
|
|
|
2017-05-04 04:10:36 +08:00
|
|
|
// Check if the latency is 0 between this instruction and any instruction
|
|
|
|
// in the current packet. If so, we disregard any potential stalls due to
|
|
|
|
// the instructions in the previous packet. Most of the instruction pairs
|
|
|
|
// that can go together in the same packet have 0 latency between them.
|
|
|
|
// Only exceptions are newValueJumps as they're generated much later and
|
|
|
|
// the latencies can't be changed at that point. Another is .cur
|
|
|
|
// instructions if its consumer has a 0 latency successor (such as .new).
|
|
|
|
// In this case, the latency between .cur and the consumer stays non-zero
|
|
|
|
// even though we can have both .cur and .new in the same packet. Changing
|
|
|
|
// the latency to 0 is not an option as it causes software pipeliner to
|
|
|
|
// not pipeline in some cases.
|
|
|
|
|
|
|
|
// For Example:
|
|
|
|
// {
|
|
|
|
// I1: v6.cur = vmem(r0++#1)
|
|
|
|
// I2: v7 = valign(v6,v4,r2)
|
|
|
|
// I3: vmem(r5++#1) = v7.new
|
|
|
|
// }
|
|
|
|
// Here I2 and I3 has 0 cycle latency, but I1 and I2 has 2.
|
2015-12-17 03:36:12 +08:00
|
|
|
|
2017-05-04 04:10:36 +08:00
|
|
|
for (auto J : CurrentPacketMIs) {
|
|
|
|
SUnit *SUJ = MIToSUnit[J];
|
|
|
|
for (auto &Pred : SUI->Preds)
|
|
|
|
if (Pred.getSUnit() == SUJ &&
|
|
|
|
(Pred.getLatency() == 0 || HII->isNewValueJump(I) ||
|
|
|
|
HII->isToBeScheduledASAP(*J, I)))
|
|
|
|
return false;
|
|
|
|
}
|
2015-12-17 03:36:12 +08:00
|
|
|
|
2017-05-04 04:10:36 +08:00
|
|
|
// Check if the latency is greater than one between this instruction and any
|
|
|
|
// instruction in the previous packet.
|
|
|
|
for (auto J : OldPacketMIs) {
|
|
|
|
SUnit *SUJ = MIToSUnit[J];
|
|
|
|
for (auto &Pred : SUI->Preds)
|
|
|
|
if (Pred.getSUnit() == SUJ && Pred.getLatency() > 1)
|
2015-12-17 03:36:12 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-05-03 02:12:19 +08:00
|
|
|
// Check if the latency is greater than one between this instruction and any
|
|
|
|
// instruction in the previous packet.
|
|
|
|
for (auto J : OldPacketMIs) {
|
|
|
|
SUnit *SUJ = MIToSUnit[J];
|
|
|
|
for (auto &Pred : SUI->Preds)
|
|
|
|
if (Pred.getSUnit() == SUJ && Pred.getLatency() > 1)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-12-17 03:36:12 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-05-04 05:52:53 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Public Constructor Functions
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
FunctionPass *llvm::createHexagonPacketizer() {
|
|
|
|
return new HexagonPacketizer();
|
|
|
|
}
|