2011-09-28 00:01:56 +00:00
|
|
|
//===- ExecutionDepsFix.cpp - Fix execution dependecy issues ----*- C++ -*-===//
|
2010-03-25 17:25:00 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2011-09-28 00:01:56 +00:00
|
|
|
// This file contains the execution dependency fix pass.
|
2010-03-25 17:25:00 +00:00
|
|
|
//
|
2011-09-28 00:01:56 +00:00
|
|
|
// Some X86 SSE instructions like mov, and, or, xor are available in different
|
2010-03-25 17:25:00 +00:00
|
|
|
// variants for different operand types. These variant instructions are
|
|
|
|
// equivalent, but on Nehalem and newer cpus there is extra latency
|
2011-09-28 00:01:56 +00:00
|
|
|
// transferring data between integer and floating point domains. ARM cores
|
|
|
|
// have similar issues when they are configured with both VFP and NEON
|
|
|
|
// pipelines.
|
2010-03-25 17:25:00 +00:00
|
|
|
//
|
|
|
|
// This pass changes the variant instructions to minimize domain crossings.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2011-09-27 23:50:46 +00:00
|
|
|
#define DEBUG_TYPE "execution-fix"
|
|
|
|
#include "llvm/CodeGen/Passes.h"
|
2011-11-07 21:59:29 +00:00
|
|
|
#include "llvm/ADT/PostOrderIterator.h"
|
2012-12-03 16:50:05 +00:00
|
|
|
#include "llvm/CodeGen/MachineFunctionPass.h"
|
|
|
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
2010-04-04 18:00:21 +00:00
|
|
|
#include "llvm/Support/Allocator.h"
|
2010-03-25 17:25:00 +00:00
|
|
|
#include "llvm/Support/Debug.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2012-12-03 16:50:05 +00:00
|
|
|
#include "llvm/Target/TargetInstrInfo.h"
|
|
|
|
#include "llvm/Target/TargetMachine.h"
|
2010-03-25 17:25:00 +00:00
|
|
|
using namespace llvm;
|
|
|
|
|
2010-03-31 20:32:51 +00:00
|
|
|
/// A DomainValue is a bit like LiveIntervals' ValNo, but it also keeps track
|
2010-03-29 23:24:21 +00:00
|
|
|
/// of execution domains.
|
|
|
|
///
|
|
|
|
/// An open DomainValue represents a set of instructions that can still switch
|
|
|
|
/// execution domain. Multiple registers may refer to the same open
|
|
|
|
/// DomainValue - they will eventually be collapsed to the same execution
|
|
|
|
/// domain.
|
|
|
|
///
|
|
|
|
/// A collapsed DomainValue represents a single register that has been forced
|
|
|
|
/// into one of more execution domains. There is a separate collapsed
|
|
|
|
/// DomainValue for each register, but it may contain multiple execution
|
|
|
|
/// domains. A register value is initially created in a single execution
|
|
|
|
/// domain, but if we were forced to pay the penalty of a domain crossing, we
|
2011-11-15 01:15:25 +00:00
|
|
|
/// keep track of the fact that the register is now available in multiple
|
2010-03-29 23:24:21 +00:00
|
|
|
/// domains.
|
2010-04-04 18:00:21 +00:00
|
|
|
namespace {
|
2010-03-29 23:24:21 +00:00
|
|
|
struct DomainValue {
|
|
|
|
// Basic reference counting.
|
|
|
|
unsigned Refs;
|
|
|
|
|
2010-04-04 21:27:26 +00:00
|
|
|
// Bitmask of available domains. For an open DomainValue, it is the still
|
|
|
|
// possible domains for collapsing. For a collapsed DomainValue it is the
|
|
|
|
// domains where the register is available for free.
|
|
|
|
unsigned AvailableDomains;
|
2010-03-29 23:24:21 +00:00
|
|
|
|
2011-11-09 00:06:18 +00:00
|
|
|
// Pointer to the next DomainValue in a chain. When two DomainValues are
|
|
|
|
// merged, Victim.Next is set to point to Victor, so old DomainValue
|
2012-06-02 10:20:22 +00:00
|
|
|
// references can be updated by following the chain.
|
2011-11-09 00:06:18 +00:00
|
|
|
DomainValue *Next;
|
|
|
|
|
2010-03-29 23:24:21 +00:00
|
|
|
// Twiddleable instructions using or defining these registers.
|
|
|
|
SmallVector<MachineInstr*, 8> Instrs;
|
|
|
|
|
2010-04-04 21:27:26 +00:00
|
|
|
// A collapsed DomainValue has no instructions to twiddle - it simply keeps
|
2010-03-29 23:24:21 +00:00
|
|
|
// track of the domains where the registers are already available.
|
2010-04-04 21:27:26 +00:00
|
|
|
bool isCollapsed() const { return Instrs.empty(); }
|
2010-03-29 23:24:21 +00:00
|
|
|
|
2010-04-04 21:27:26 +00:00
|
|
|
// Is domain available?
|
|
|
|
bool hasDomain(unsigned domain) const {
|
|
|
|
return AvailableDomains & (1u << domain);
|
2010-03-29 23:24:21 +00:00
|
|
|
}
|
|
|
|
|
2010-03-30 20:04:01 +00:00
|
|
|
// Mark domain as available.
|
2010-04-04 21:27:26 +00:00
|
|
|
void addDomain(unsigned domain) {
|
|
|
|
AvailableDomains |= 1u << domain;
|
2010-03-29 23:24:21 +00:00
|
|
|
}
|
|
|
|
|
2010-04-04 21:27:26 +00:00
|
|
|
// Restrict to a single domain available.
|
|
|
|
void setSingleDomain(unsigned domain) {
|
|
|
|
AvailableDomains = 1u << domain;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return bitmask of domains that are available and in mask.
|
|
|
|
unsigned getCommonDomains(unsigned mask) const {
|
|
|
|
return AvailableDomains & mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
// First domain available.
|
|
|
|
unsigned getFirstDomain() const {
|
|
|
|
return CountTrailingZeros_32(AvailableDomains);
|
2010-03-30 20:04:01 +00:00
|
|
|
}
|
|
|
|
|
2011-11-08 23:26:00 +00:00
|
|
|
DomainValue() : Refs(0) { clear(); }
|
2010-03-29 23:24:21 +00:00
|
|
|
|
2011-11-09 00:06:18 +00:00
|
|
|
// Clear this DomainValue and point to next which has all its data.
|
2010-03-29 23:24:21 +00:00
|
|
|
void clear() {
|
2011-11-15 01:15:25 +00:00
|
|
|
AvailableDomains = 0;
|
2011-11-09 00:06:18 +00:00
|
|
|
Next = 0;
|
2010-03-29 23:24:21 +00:00
|
|
|
Instrs.clear();
|
|
|
|
}
|
|
|
|
};
|
2010-04-04 18:00:21 +00:00
|
|
|
}
|
2010-03-29 23:24:21 +00:00
|
|
|
|
2011-11-15 01:15:25 +00:00
|
|
|
namespace {
|
|
|
|
/// LiveReg - Information about a live register.
|
|
|
|
struct LiveReg {
|
|
|
|
/// Value currently in this register, or NULL when no value is being tracked.
|
|
|
|
/// This counts as a DomainValue reference.
|
|
|
|
DomainValue *Value;
|
|
|
|
|
|
|
|
/// Instruction that defined this register, relative to the beginning of the
|
|
|
|
/// current basic block. When a LiveReg is used to represent a live-out
|
|
|
|
/// register, this value is relative to the end of the basic block, so it
|
|
|
|
/// will be a negative number.
|
|
|
|
int Def;
|
|
|
|
};
|
|
|
|
} // anonynous namespace
|
|
|
|
|
2010-04-04 18:00:21 +00:00
|
|
|
namespace {
|
2011-09-28 00:01:56 +00:00
|
|
|
class ExeDepsFix : public MachineFunctionPass {
|
2010-03-25 17:25:00 +00:00
|
|
|
static char ID;
|
2010-04-04 18:00:21 +00:00
|
|
|
SpecificBumpPtrAllocator<DomainValue> Allocator;
|
|
|
|
SmallVector<DomainValue*,16> Avail;
|
2010-03-25 17:25:00 +00:00
|
|
|
|
2011-09-27 23:50:46 +00:00
|
|
|
const TargetRegisterClass *const RC;
|
2010-03-25 17:25:00 +00:00
|
|
|
MachineFunction *MF;
|
2011-09-27 23:50:46 +00:00
|
|
|
const TargetInstrInfo *TII;
|
2010-03-29 23:24:21 +00:00
|
|
|
const TargetRegisterInfo *TRI;
|
2011-09-27 23:50:46 +00:00
|
|
|
std::vector<int> AliasMap;
|
|
|
|
const unsigned NumRegs;
|
2011-11-15 01:15:25 +00:00
|
|
|
LiveReg *LiveRegs;
|
|
|
|
typedef DenseMap<MachineBasicBlock*, LiveReg*> LiveOutMap;
|
2010-03-30 20:04:01 +00:00
|
|
|
LiveOutMap LiveOuts;
|
2011-11-15 01:15:25 +00:00
|
|
|
|
|
|
|
/// Current instruction number.
|
|
|
|
/// The first instruction in each basic block is 0.
|
|
|
|
int CurInstr;
|
|
|
|
|
|
|
|
/// True when the current block has a predecessor that hasn't been visited
|
|
|
|
/// yet.
|
|
|
|
bool SeenUnknownBackEdge;
|
2010-03-29 23:24:21 +00:00
|
|
|
|
2010-03-25 17:25:00 +00:00
|
|
|
public:
|
2011-09-28 00:01:56 +00:00
|
|
|
ExeDepsFix(const TargetRegisterClass *rc)
|
2011-09-27 23:50:46 +00:00
|
|
|
: MachineFunctionPass(ID), RC(rc), NumRegs(RC->getNumRegs()) {}
|
2010-03-25 17:25:00 +00:00
|
|
|
|
|
|
|
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
|
|
|
AU.setPreservesAll();
|
|
|
|
MachineFunctionPass::getAnalysisUsage(AU);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool runOnMachineFunction(MachineFunction &MF);
|
|
|
|
|
|
|
|
virtual const char *getPassName() const {
|
2011-11-07 21:23:39 +00:00
|
|
|
return "Execution dependency fix";
|
2010-03-25 17:25:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2010-03-29 23:24:21 +00:00
|
|
|
// Register mapping.
|
2011-11-08 21:57:47 +00:00
|
|
|
int regIndex(unsigned Reg);
|
2010-03-29 23:24:21 +00:00
|
|
|
|
2010-04-04 18:00:21 +00:00
|
|
|
// DomainValue allocation.
|
2011-11-08 21:57:47 +00:00
|
|
|
DomainValue *alloc(int domain = -1);
|
2011-11-09 00:06:18 +00:00
|
|
|
DomainValue *retain(DomainValue *DV) {
|
|
|
|
if (DV) ++DV->Refs;
|
|
|
|
return DV;
|
|
|
|
}
|
2011-11-08 21:57:44 +00:00
|
|
|
void release(DomainValue*);
|
2011-11-09 00:06:18 +00:00
|
|
|
DomainValue *resolve(DomainValue*&);
|
2010-04-04 18:00:21 +00:00
|
|
|
|
2010-03-29 23:24:21 +00:00
|
|
|
// LiveRegs manipulations.
|
2011-11-08 21:57:47 +00:00
|
|
|
void setLiveReg(int rx, DomainValue *DV);
|
|
|
|
void kill(int rx);
|
|
|
|
void force(int rx, unsigned domain);
|
|
|
|
void collapse(DomainValue *dv, unsigned domain);
|
|
|
|
bool merge(DomainValue *A, DomainValue *B);
|
2010-03-29 23:24:21 +00:00
|
|
|
|
2011-11-15 01:15:25 +00:00
|
|
|
void enterBasicBlock(MachineBasicBlock*);
|
2011-11-07 21:40:27 +00:00
|
|
|
void leaveBasicBlock(MachineBasicBlock*);
|
|
|
|
void visitInstr(MachineInstr*);
|
2011-11-15 01:15:25 +00:00
|
|
|
void processDefs(MachineInstr*, bool Kill);
|
2010-03-29 23:24:21 +00:00
|
|
|
void visitSoftInstr(MachineInstr*, unsigned mask);
|
|
|
|
void visitHardInstr(MachineInstr*, unsigned domain);
|
2010-03-25 17:25:00 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2011-09-28 00:01:56 +00:00
|
|
|
char ExeDepsFix::ID = 0;
|
2010-03-25 17:25:00 +00:00
|
|
|
|
2010-03-29 23:24:21 +00:00
|
|
|
/// Translate TRI register number to an index into our smaller tables of
|
|
|
|
/// interesting registers. Return -1 for boring registers.
|
2011-11-08 21:57:47 +00:00
|
|
|
int ExeDepsFix::regIndex(unsigned Reg) {
|
2011-09-27 23:50:46 +00:00
|
|
|
assert(Reg < AliasMap.size() && "Invalid register");
|
|
|
|
return AliasMap[Reg];
|
2010-03-29 23:24:21 +00:00
|
|
|
}
|
|
|
|
|
2011-11-08 21:57:47 +00:00
|
|
|
DomainValue *ExeDepsFix::alloc(int domain) {
|
2010-04-04 18:00:21 +00:00
|
|
|
DomainValue *dv = Avail.empty() ?
|
|
|
|
new(Allocator.Allocate()) DomainValue :
|
|
|
|
Avail.pop_back_val();
|
|
|
|
if (domain >= 0)
|
2010-04-04 21:27:26 +00:00
|
|
|
dv->addDomain(domain);
|
2011-11-08 23:26:00 +00:00
|
|
|
assert(dv->Refs == 0 && "Reference count wasn't cleared");
|
2011-11-09 00:06:18 +00:00
|
|
|
assert(!dv->Next && "Chained DomainValue shouldn't have been recycled");
|
2010-04-04 18:00:21 +00:00
|
|
|
return dv;
|
|
|
|
}
|
|
|
|
|
2011-11-08 21:57:44 +00:00
|
|
|
/// release - Release a reference to DV. When the last reference is released,
|
|
|
|
/// collapse if needed.
|
|
|
|
void ExeDepsFix::release(DomainValue *DV) {
|
2011-11-09 00:06:18 +00:00
|
|
|
while (DV) {
|
|
|
|
assert(DV->Refs && "Bad DomainValue");
|
|
|
|
if (--DV->Refs)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// There are no more DV references. Collapse any contained instructions.
|
|
|
|
if (DV->AvailableDomains && !DV->isCollapsed())
|
|
|
|
collapse(DV, DV->getFirstDomain());
|
|
|
|
|
|
|
|
DomainValue *Next = DV->Next;
|
|
|
|
DV->clear();
|
|
|
|
Avail.push_back(DV);
|
|
|
|
// Also release the next DomainValue in the chain.
|
|
|
|
DV = Next;
|
|
|
|
}
|
|
|
|
}
|
2011-11-08 21:57:44 +00:00
|
|
|
|
2011-11-09 00:06:18 +00:00
|
|
|
/// resolve - Follow the chain of dead DomainValues until a live DomainValue is
|
|
|
|
/// reached. Update the referenced pointer when necessary.
|
|
|
|
DomainValue *ExeDepsFix::resolve(DomainValue *&DVRef) {
|
|
|
|
DomainValue *DV = DVRef;
|
|
|
|
if (!DV || !DV->Next)
|
|
|
|
return DV;
|
|
|
|
|
|
|
|
// DV has a chain. Find the end.
|
|
|
|
do DV = DV->Next;
|
|
|
|
while (DV->Next);
|
|
|
|
|
|
|
|
// Update DVRef to point to DV.
|
|
|
|
retain(DV);
|
|
|
|
release(DVRef);
|
|
|
|
DVRef = DV;
|
|
|
|
return DV;
|
2010-04-04 18:00:21 +00:00
|
|
|
}
|
|
|
|
|
2010-03-29 23:24:21 +00:00
|
|
|
/// Set LiveRegs[rx] = dv, updating reference counts.
|
2011-11-08 21:57:47 +00:00
|
|
|
void ExeDepsFix::setLiveReg(int rx, DomainValue *dv) {
|
2010-03-30 20:04:01 +00:00
|
|
|
assert(unsigned(rx) < NumRegs && "Invalid index");
|
2011-11-15 01:15:25 +00:00
|
|
|
assert(LiveRegs && "Must enter basic block first.");
|
2010-03-30 20:04:01 +00:00
|
|
|
|
2011-11-15 01:15:25 +00:00
|
|
|
if (LiveRegs[rx].Value == dv)
|
2010-03-29 23:24:21 +00:00
|
|
|
return;
|
2011-11-15 01:15:25 +00:00
|
|
|
if (LiveRegs[rx].Value)
|
|
|
|
release(LiveRegs[rx].Value);
|
|
|
|
LiveRegs[rx].Value = retain(dv);
|
2010-03-29 23:24:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Kill register rx, recycle or collapse any DomainValue.
|
2011-11-08 21:57:47 +00:00
|
|
|
void ExeDepsFix::kill(int rx) {
|
2010-03-30 20:04:01 +00:00
|
|
|
assert(unsigned(rx) < NumRegs && "Invalid index");
|
2011-11-15 01:15:25 +00:00
|
|
|
assert(LiveRegs && "Must enter basic block first.");
|
|
|
|
if (!LiveRegs[rx].Value)
|
|
|
|
return;
|
2010-03-29 23:24:21 +00:00
|
|
|
|
2011-11-15 01:15:25 +00:00
|
|
|
release(LiveRegs[rx].Value);
|
|
|
|
LiveRegs[rx].Value = 0;
|
2010-03-29 23:24:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Force register rx into domain.
|
2011-11-08 21:57:47 +00:00
|
|
|
void ExeDepsFix::force(int rx, unsigned domain) {
|
2010-03-30 20:04:01 +00:00
|
|
|
assert(unsigned(rx) < NumRegs && "Invalid index");
|
2011-11-15 01:15:25 +00:00
|
|
|
assert(LiveRegs && "Must enter basic block first.");
|
|
|
|
if (DomainValue *dv = LiveRegs[rx].Value) {
|
2010-04-04 21:27:26 +00:00
|
|
|
if (dv->isCollapsed())
|
|
|
|
dv->addDomain(domain);
|
2010-04-06 19:48:56 +00:00
|
|
|
else if (dv->hasDomain(domain))
|
2011-11-08 21:57:47 +00:00
|
|
|
collapse(dv, domain);
|
2010-04-06 19:48:56 +00:00
|
|
|
else {
|
2011-09-28 00:01:56 +00:00
|
|
|
// This is an incompatible open DomainValue. Collapse it to whatever and
|
|
|
|
// force the new value into domain. This costs a domain crossing.
|
2011-11-08 21:57:47 +00:00
|
|
|
collapse(dv, dv->getFirstDomain());
|
2011-11-15 01:15:25 +00:00
|
|
|
assert(LiveRegs[rx].Value && "Not live after collapse?");
|
|
|
|
LiveRegs[rx].Value->addDomain(domain);
|
2010-04-06 19:48:56 +00:00
|
|
|
}
|
2010-03-29 23:24:21 +00:00
|
|
|
} else {
|
2010-03-30 20:04:01 +00:00
|
|
|
// Set up basic collapsed DomainValue.
|
2011-11-08 21:57:47 +00:00
|
|
|
setLiveReg(rx, alloc(domain));
|
2010-03-29 23:24:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Collapse open DomainValue into given domain. If there are multiple
|
|
|
|
/// registers using dv, they each get a unique collapsed DomainValue.
|
2011-11-08 21:57:47 +00:00
|
|
|
void ExeDepsFix::collapse(DomainValue *dv, unsigned domain) {
|
2010-04-04 21:27:26 +00:00
|
|
|
assert(dv->hasDomain(domain) && "Cannot collapse");
|
2010-03-29 23:24:21 +00:00
|
|
|
|
|
|
|
// Collapse all the instructions.
|
2010-04-04 21:27:26 +00:00
|
|
|
while (!dv->Instrs.empty())
|
2011-09-27 22:57:18 +00:00
|
|
|
TII->setExecutionDomain(dv->Instrs.pop_back_val(), domain);
|
2010-04-04 21:27:26 +00:00
|
|
|
dv->setSingleDomain(domain);
|
2010-03-29 23:24:21 +00:00
|
|
|
|
|
|
|
// If there are multiple users, give them new, unique DomainValues.
|
2010-04-04 18:00:21 +00:00
|
|
|
if (LiveRegs && dv->Refs > 1)
|
2010-03-30 20:04:01 +00:00
|
|
|
for (unsigned rx = 0; rx != NumRegs; ++rx)
|
2011-11-15 01:15:25 +00:00
|
|
|
if (LiveRegs[rx].Value == dv)
|
2011-11-08 21:57:47 +00:00
|
|
|
setLiveReg(rx, alloc(domain));
|
2010-03-29 23:24:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Merge - All instructions and registers in B are moved to A, and B is
|
|
|
|
/// released.
|
2011-11-08 21:57:47 +00:00
|
|
|
bool ExeDepsFix::merge(DomainValue *A, DomainValue *B) {
|
2010-04-04 21:27:26 +00:00
|
|
|
assert(!A->isCollapsed() && "Cannot merge into collapsed");
|
|
|
|
assert(!B->isCollapsed() && "Cannot merge from collapsed");
|
2010-03-31 20:05:12 +00:00
|
|
|
if (A == B)
|
2010-03-31 17:13:16 +00:00
|
|
|
return true;
|
2010-04-04 21:27:26 +00:00
|
|
|
// Restrict to the domains that A and B have in common.
|
|
|
|
unsigned common = A->getCommonDomains(B->AvailableDomains);
|
|
|
|
if (!common)
|
2010-03-29 23:24:21 +00:00
|
|
|
return false;
|
2010-04-04 21:27:26 +00:00
|
|
|
A->AvailableDomains = common;
|
2010-03-29 23:24:21 +00:00
|
|
|
A->Instrs.append(B->Instrs.begin(), B->Instrs.end());
|
2011-11-08 20:57:04 +00:00
|
|
|
|
|
|
|
// Clear the old DomainValue so we won't try to swizzle instructions twice.
|
2011-11-08 23:26:00 +00:00
|
|
|
B->clear();
|
2011-11-09 00:06:18 +00:00
|
|
|
// All uses of B are referred to A.
|
|
|
|
B->Next = retain(A);
|
2011-11-08 20:57:04 +00:00
|
|
|
|
2010-03-30 20:04:01 +00:00
|
|
|
for (unsigned rx = 0; rx != NumRegs; ++rx)
|
2011-11-15 01:15:25 +00:00
|
|
|
if (LiveRegs[rx].Value == B)
|
2011-11-08 21:57:47 +00:00
|
|
|
setLiveReg(rx, A);
|
2010-03-29 23:24:21 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-11-09 01:06:56 +00:00
|
|
|
// enterBasicBlock - Set up LiveRegs by merging predecessor live-out values.
|
2011-11-15 01:15:25 +00:00
|
|
|
void ExeDepsFix::enterBasicBlock(MachineBasicBlock *MBB) {
|
2011-11-09 01:06:56 +00:00
|
|
|
// Detect back-edges from predecessors we haven't processed yet.
|
2011-11-15 01:15:25 +00:00
|
|
|
SeenUnknownBackEdge = false;
|
2011-11-09 01:06:56 +00:00
|
|
|
|
2011-11-15 01:15:25 +00:00
|
|
|
// Reset instruction counter in each basic block.
|
|
|
|
CurInstr = 0;
|
|
|
|
|
|
|
|
// Set up LiveRegs to represent registers entering MBB.
|
|
|
|
if (!LiveRegs)
|
|
|
|
LiveRegs = new LiveReg[NumRegs];
|
|
|
|
|
|
|
|
// Default values are 'nothing happened a long time ago'.
|
|
|
|
for (unsigned rx = 0; rx != NumRegs; ++rx) {
|
|
|
|
LiveRegs[rx].Value = 0;
|
|
|
|
LiveRegs[rx].Def = -(1 << 20);
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is the entry block.
|
|
|
|
if (MBB->pred_empty()) {
|
|
|
|
for (MachineBasicBlock::livein_iterator i = MBB->livein_begin(),
|
2010-03-30 20:04:01 +00:00
|
|
|
e = MBB->livein_end(); i != e; ++i) {
|
2011-11-15 01:15:25 +00:00
|
|
|
int rx = regIndex(*i);
|
|
|
|
if (rx < 0)
|
2011-11-09 01:06:56 +00:00
|
|
|
continue;
|
2011-11-15 01:15:25 +00:00
|
|
|
// Treat function live-ins as if they were defined just before the first
|
|
|
|
// instruction. Usually, function arguments are set up immediately
|
|
|
|
// before the call.
|
|
|
|
LiveRegs[rx].Def = -1;
|
|
|
|
}
|
|
|
|
DEBUG(dbgs() << "BB#" << MBB->getNumber() << ": entry\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Try to coalesce live-out registers from predecessors.
|
|
|
|
for (MachineBasicBlock::const_pred_iterator pi = MBB->pred_begin(),
|
|
|
|
pe = MBB->pred_end(); pi != pe; ++pi) {
|
|
|
|
LiveOutMap::const_iterator fi = LiveOuts.find(*pi);
|
|
|
|
if (fi == LiveOuts.end()) {
|
|
|
|
SeenUnknownBackEdge = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
assert(fi->second && "Can't have NULL entries");
|
|
|
|
|
|
|
|
for (unsigned rx = 0; rx != NumRegs; ++rx) {
|
|
|
|
// Use the most recent predecessor def for each register.
|
|
|
|
LiveRegs[rx].Def = std::max(LiveRegs[rx].Def, fi->second[rx].Def);
|
|
|
|
|
|
|
|
DomainValue *pdv = resolve(fi->second[rx].Value);
|
|
|
|
if (!pdv)
|
2011-11-09 01:06:56 +00:00
|
|
|
continue;
|
2011-11-15 01:15:25 +00:00
|
|
|
if (!LiveRegs[rx].Value) {
|
2011-11-08 21:57:47 +00:00
|
|
|
setLiveReg(rx, pdv);
|
2010-03-31 20:32:51 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We have a live DomainValue from more than one predecessor.
|
2011-11-15 01:15:25 +00:00
|
|
|
if (LiveRegs[rx].Value->isCollapsed()) {
|
2010-03-31 20:32:51 +00:00
|
|
|
// We are already collapsed, but predecessor is not. Force him.
|
2011-11-15 01:15:25 +00:00
|
|
|
unsigned Domain = LiveRegs[rx].Value->getFirstDomain();
|
|
|
|
if (!pdv->isCollapsed() && pdv->hasDomain(Domain))
|
|
|
|
collapse(pdv, Domain);
|
2010-03-31 20:32:51 +00:00
|
|
|
continue;
|
2010-03-30 20:04:01 +00:00
|
|
|
}
|
2010-04-04 18:00:21 +00:00
|
|
|
|
2010-03-31 20:32:51 +00:00
|
|
|
// Currently open, merge in predecessor.
|
2010-04-04 21:27:26 +00:00
|
|
|
if (!pdv->isCollapsed())
|
2011-11-15 01:15:25 +00:00
|
|
|
merge(LiveRegs[rx].Value, pdv);
|
2010-03-31 20:32:51 +00:00
|
|
|
else
|
2011-11-08 21:57:47 +00:00
|
|
|
force(rx, pdv->getFirstDomain());
|
2010-03-30 20:04:01 +00:00
|
|
|
}
|
|
|
|
}
|
2011-11-15 01:15:25 +00:00
|
|
|
DEBUG(dbgs() << "BB#" << MBB->getNumber()
|
|
|
|
<< (SeenUnknownBackEdge ? ": incomplete\n" : ": all preds known\n"));
|
2010-03-29 23:24:21 +00:00
|
|
|
}
|
|
|
|
|
2011-11-07 21:40:27 +00:00
|
|
|
void ExeDepsFix::leaveBasicBlock(MachineBasicBlock *MBB) {
|
2011-11-15 01:15:25 +00:00
|
|
|
assert(LiveRegs && "Must enter basic block first.");
|
2011-11-07 21:40:27 +00:00
|
|
|
// Save live registers at end of MBB - used by enterBasicBlock().
|
2011-11-09 01:06:56 +00:00
|
|
|
// Also use LiveOuts as a visited set to detect back-edges.
|
2011-11-15 01:15:25 +00:00
|
|
|
bool First = LiveOuts.insert(std::make_pair(MBB, LiveRegs)).second;
|
|
|
|
|
|
|
|
if (First) {
|
|
|
|
// LiveRegs was inserted in LiveOuts. Adjust all defs to be relative to
|
|
|
|
// the end of this block instead of the beginning.
|
|
|
|
for (unsigned i = 0, e = NumRegs; i != e; ++i)
|
|
|
|
LiveRegs[i].Def -= CurInstr;
|
|
|
|
} else {
|
2011-11-09 01:06:56 +00:00
|
|
|
// Insertion failed, this must be the second pass.
|
|
|
|
// Release all the DomainValues instead of keeping them.
|
|
|
|
for (unsigned i = 0, e = NumRegs; i != e; ++i)
|
2011-11-15 01:15:25 +00:00
|
|
|
release(LiveRegs[i].Value);
|
2011-11-09 01:06:56 +00:00
|
|
|
delete[] LiveRegs;
|
|
|
|
}
|
2011-11-07 21:40:27 +00:00
|
|
|
LiveRegs = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExeDepsFix::visitInstr(MachineInstr *MI) {
|
|
|
|
if (MI->isDebugValue())
|
|
|
|
return;
|
2011-11-15 01:15:25 +00:00
|
|
|
|
|
|
|
// Update instructions with explicit execution domains.
|
|
|
|
std::pair<uint16_t, uint16_t> DomP = TII->getExecutionDomain(MI);
|
|
|
|
if (DomP.first) {
|
|
|
|
if (DomP.second)
|
|
|
|
visitSoftInstr(MI, DomP.second);
|
2011-11-07 21:40:27 +00:00
|
|
|
else
|
2011-11-15 01:15:25 +00:00
|
|
|
visitHardInstr(MI, DomP.first);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Process defs to track register ages, and kill values clobbered by generic
|
|
|
|
// instructions.
|
|
|
|
processDefs(MI, !DomP.first);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update def-ages for registers defined by MI.
|
|
|
|
// If Kill is set, also kill off DomainValues clobbered by the defs.
|
|
|
|
void ExeDepsFix::processDefs(MachineInstr *MI, bool Kill) {
|
|
|
|
assert(!MI->isDebugValue() && "Won't process debug values");
|
|
|
|
const MCInstrDesc &MCID = MI->getDesc();
|
|
|
|
for (unsigned i = 0,
|
2011-12-07 07:15:52 +00:00
|
|
|
e = MI->isVariadic() ? MI->getNumOperands() : MCID.getNumDefs();
|
2011-11-15 01:15:25 +00:00
|
|
|
i != e; ++i) {
|
|
|
|
MachineOperand &MO = MI->getOperand(i);
|
|
|
|
if (!MO.isReg())
|
|
|
|
continue;
|
|
|
|
if (MO.isImplicit())
|
|
|
|
break;
|
|
|
|
if (MO.isUse())
|
|
|
|
continue;
|
|
|
|
int rx = regIndex(MO.getReg());
|
|
|
|
if (rx < 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// This instruction explicitly defines rx.
|
|
|
|
DEBUG(dbgs() << TRI->getName(RC->getRegister(rx)) << ":\t" << CurInstr
|
|
|
|
<< '\t' << *MI);
|
|
|
|
|
2011-11-15 01:15:30 +00:00
|
|
|
// How many instructions since rx was last written?
|
|
|
|
unsigned Clearance = CurInstr - LiveRegs[rx].Def;
|
2011-11-15 01:15:25 +00:00
|
|
|
LiveRegs[rx].Def = CurInstr;
|
|
|
|
|
|
|
|
// Kill off domains redefined by generic instructions.
|
|
|
|
if (Kill)
|
|
|
|
kill(rx);
|
2011-11-15 01:15:30 +00:00
|
|
|
|
|
|
|
// Verify clearance before partial register updates.
|
|
|
|
unsigned Pref = TII->getPartialRegUpdateClearance(MI, i, TRI);
|
|
|
|
if (!Pref)
|
|
|
|
continue;
|
|
|
|
DEBUG(dbgs() << "Clearance: " << Clearance << ", want " << Pref);
|
|
|
|
if (Pref > Clearance) {
|
|
|
|
DEBUG(dbgs() << ": Break dependency.\n");
|
|
|
|
TII->breakPartialRegDependency(MI, i, TRI);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The current clearance seems OK, but we may be ignoring a def from a
|
|
|
|
// back-edge.
|
|
|
|
if (!SeenUnknownBackEdge || Pref <= unsigned(CurInstr)) {
|
|
|
|
DEBUG(dbgs() << ": OK.\n");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// A def from an unprocessed back-edge may make us break this dependency.
|
|
|
|
DEBUG(dbgs() << ": Wait for back-edge to resolve.\n");
|
2011-11-15 01:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
++CurInstr;
|
2011-11-07 21:40:27 +00:00
|
|
|
}
|
|
|
|
|
2010-03-29 23:24:21 +00:00
|
|
|
// A hard instruction only works in one domain. All input registers will be
|
|
|
|
// forced into that domain.
|
2011-09-28 00:01:56 +00:00
|
|
|
void ExeDepsFix::visitHardInstr(MachineInstr *mi, unsigned domain) {
|
2010-03-29 23:24:21 +00:00
|
|
|
// Collapse all uses.
|
|
|
|
for (unsigned i = mi->getDesc().getNumDefs(),
|
|
|
|
e = mi->getDesc().getNumOperands(); i != e; ++i) {
|
|
|
|
MachineOperand &mo = mi->getOperand(i);
|
|
|
|
if (!mo.isReg()) continue;
|
2011-11-08 21:57:47 +00:00
|
|
|
int rx = regIndex(mo.getReg());
|
2010-03-29 23:24:21 +00:00
|
|
|
if (rx < 0) continue;
|
2011-11-08 21:57:47 +00:00
|
|
|
force(rx, domain);
|
2010-03-29 23:24:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Kill all defs and force them.
|
|
|
|
for (unsigned i = 0, e = mi->getDesc().getNumDefs(); i != e; ++i) {
|
|
|
|
MachineOperand &mo = mi->getOperand(i);
|
|
|
|
if (!mo.isReg()) continue;
|
2011-11-08 21:57:47 +00:00
|
|
|
int rx = regIndex(mo.getReg());
|
2010-03-29 23:24:21 +00:00
|
|
|
if (rx < 0) continue;
|
2011-11-08 21:57:47 +00:00
|
|
|
kill(rx);
|
|
|
|
force(rx, domain);
|
2010-03-29 23:24:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// A soft instruction can be changed to work in other domains given by mask.
|
2011-09-28 00:01:56 +00:00
|
|
|
void ExeDepsFix::visitSoftInstr(MachineInstr *mi, unsigned mask) {
|
2010-04-04 21:27:26 +00:00
|
|
|
// Bitmask of available domains for this instruction after taking collapsed
|
|
|
|
// operands into account.
|
|
|
|
unsigned available = mask;
|
|
|
|
|
2010-03-29 23:24:21 +00:00
|
|
|
// Scan the explicit use operands for incoming domains.
|
|
|
|
SmallVector<int, 4> used;
|
2010-03-30 20:04:01 +00:00
|
|
|
if (LiveRegs)
|
|
|
|
for (unsigned i = mi->getDesc().getNumDefs(),
|
|
|
|
e = mi->getDesc().getNumOperands(); i != e; ++i) {
|
2010-03-31 20:32:51 +00:00
|
|
|
MachineOperand &mo = mi->getOperand(i);
|
|
|
|
if (!mo.isReg()) continue;
|
2011-11-08 21:57:47 +00:00
|
|
|
int rx = regIndex(mo.getReg());
|
2010-03-31 20:32:51 +00:00
|
|
|
if (rx < 0) continue;
|
2011-11-15 01:15:25 +00:00
|
|
|
if (DomainValue *dv = LiveRegs[rx].Value) {
|
2010-04-04 21:27:26 +00:00
|
|
|
// Bitmask of domains that dv and available have in common.
|
|
|
|
unsigned common = dv->getCommonDomains(available);
|
2010-03-31 20:32:51 +00:00
|
|
|
// Is it possible to use this collapsed register for free?
|
2010-04-04 21:27:26 +00:00
|
|
|
if (dv->isCollapsed()) {
|
|
|
|
// Restrict available domains to the ones in common with the operand.
|
|
|
|
// If there are no common domains, we must pay the cross-domain
|
|
|
|
// penalty for this operand.
|
|
|
|
if (common) available = common;
|
|
|
|
} else if (common)
|
|
|
|
// Open DomainValue is compatible, save it for merging.
|
2010-03-31 20:32:51 +00:00
|
|
|
used.push_back(rx);
|
|
|
|
else
|
2010-04-04 21:27:26 +00:00
|
|
|
// Open DomainValue is not compatible with instruction. It is useless
|
|
|
|
// now.
|
2011-11-08 21:57:47 +00:00
|
|
|
kill(rx);
|
2010-03-31 20:32:51 +00:00
|
|
|
}
|
2010-03-29 23:24:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// If the collapsed operands force a single domain, propagate the collapse.
|
2010-04-04 21:27:26 +00:00
|
|
|
if (isPowerOf2_32(available)) {
|
|
|
|
unsigned domain = CountTrailingZeros_32(available);
|
2011-09-27 22:57:18 +00:00
|
|
|
TII->setExecutionDomain(mi, domain);
|
2010-03-29 23:24:21 +00:00
|
|
|
visitHardInstr(mi, domain);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-04-04 21:27:26 +00:00
|
|
|
// Kill off any remaining uses that don't match available, and build a list of
|
|
|
|
// incoming DomainValues that we want to merge.
|
2011-11-15 01:15:25 +00:00
|
|
|
SmallVector<LiveReg, 4> Regs;
|
2010-03-29 23:24:21 +00:00
|
|
|
for (SmallVector<int, 4>::iterator i=used.begin(), e=used.end(); i!=e; ++i) {
|
|
|
|
int rx = *i;
|
2011-11-15 01:15:25 +00:00
|
|
|
const LiveReg &LR = LiveRegs[rx];
|
2010-03-30 20:04:01 +00:00
|
|
|
// This useless DomainValue could have been missed above.
|
2011-11-15 01:15:25 +00:00
|
|
|
if (!LR.Value->getCommonDomains(available)) {
|
|
|
|
kill(rx);
|
2010-03-29 23:24:21 +00:00
|
|
|
continue;
|
|
|
|
}
|
2011-11-15 01:15:25 +00:00
|
|
|
// Sorted insertion.
|
|
|
|
bool Inserted = false;
|
|
|
|
for (SmallVector<LiveReg, 4>::iterator i = Regs.begin(), e = Regs.end();
|
|
|
|
i != e && !Inserted; ++i) {
|
|
|
|
if (LR.Def < i->Def) {
|
|
|
|
Inserted = true;
|
|
|
|
Regs.insert(i, LR);
|
2010-03-29 23:24:21 +00:00
|
|
|
}
|
|
|
|
}
|
2011-11-15 01:15:25 +00:00
|
|
|
if (!Inserted)
|
|
|
|
Regs.push_back(LR);
|
2010-03-29 23:24:21 +00:00
|
|
|
}
|
|
|
|
|
2010-04-04 21:27:26 +00:00
|
|
|
// doms are now sorted in order of appearance. Try to merge them all, giving
|
|
|
|
// priority to the latest ones.
|
2010-03-29 23:24:21 +00:00
|
|
|
DomainValue *dv = 0;
|
2011-11-15 01:15:25 +00:00
|
|
|
while (!Regs.empty()) {
|
2010-03-31 20:32:51 +00:00
|
|
|
if (!dv) {
|
2011-11-15 01:15:25 +00:00
|
|
|
dv = Regs.pop_back_val().Value;
|
2011-11-23 04:03:08 +00:00
|
|
|
// Force the first dv to match the current instruction.
|
|
|
|
dv->AvailableDomains = dv->getCommonDomains(available);
|
|
|
|
assert(dv->AvailableDomains && "Domain should have been filtered");
|
2010-03-31 20:32:51 +00:00
|
|
|
continue;
|
|
|
|
}
|
2010-04-04 18:00:21 +00:00
|
|
|
|
2011-11-15 01:15:25 +00:00
|
|
|
DomainValue *Latest = Regs.pop_back_val().Value;
|
|
|
|
// Skip already merged values.
|
|
|
|
if (Latest == dv || Latest->Next)
|
|
|
|
continue;
|
|
|
|
if (merge(dv, Latest))
|
|
|
|
continue;
|
2010-04-04 18:00:21 +00:00
|
|
|
|
2010-04-04 21:27:26 +00:00
|
|
|
// If latest didn't merge, it is useless now. Kill all registers using it.
|
2010-03-31 20:32:51 +00:00
|
|
|
for (SmallVector<int,4>::iterator i=used.begin(), e=used.end(); i != e; ++i)
|
2011-11-15 01:15:25 +00:00
|
|
|
if (LiveRegs[*i].Value == Latest)
|
2011-11-08 21:57:47 +00:00
|
|
|
kill(*i);
|
2010-03-29 23:24:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// dv is the DomainValue we are going to use for this instruction.
|
2011-11-23 04:03:08 +00:00
|
|
|
if (!dv) {
|
2011-11-08 21:57:47 +00:00
|
|
|
dv = alloc();
|
2011-11-23 04:03:08 +00:00
|
|
|
dv->AvailableDomains = available;
|
|
|
|
}
|
2010-03-29 23:24:21 +00:00
|
|
|
dv->Instrs.push_back(mi);
|
|
|
|
|
2012-10-03 08:29:36 +00:00
|
|
|
// Finally set all defs and non-collapsed uses to dv. We must iterate through
|
|
|
|
// all the operators, including imp-def ones.
|
|
|
|
for (MachineInstr::mop_iterator ii = mi->operands_begin(),
|
|
|
|
ee = mi->operands_end();
|
|
|
|
ii != ee; ++ii) {
|
|
|
|
MachineOperand &mo = *ii;
|
2010-03-29 23:24:21 +00:00
|
|
|
if (!mo.isReg()) continue;
|
2011-11-08 21:57:47 +00:00
|
|
|
int rx = regIndex(mo.getReg());
|
2010-03-29 23:24:21 +00:00
|
|
|
if (rx < 0) continue;
|
2011-11-15 01:15:25 +00:00
|
|
|
if (!LiveRegs[rx].Value || (mo.isDef() && LiveRegs[rx].Value != dv)) {
|
2011-11-08 21:57:47 +00:00
|
|
|
kill(rx);
|
|
|
|
setLiveReg(rx, dv);
|
2010-03-29 23:24:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-28 00:01:56 +00:00
|
|
|
bool ExeDepsFix::runOnMachineFunction(MachineFunction &mf) {
|
2010-03-25 17:25:00 +00:00
|
|
|
MF = &mf;
|
2011-09-27 23:50:46 +00:00
|
|
|
TII = MF->getTarget().getInstrInfo();
|
2010-03-29 23:24:21 +00:00
|
|
|
TRI = MF->getTarget().getRegisterInfo();
|
2010-03-30 20:04:01 +00:00
|
|
|
LiveRegs = 0;
|
2011-09-27 23:50:46 +00:00
|
|
|
assert(NumRegs == RC->getNumRegs() && "Bad regclass");
|
2010-03-25 17:25:00 +00:00
|
|
|
|
2011-11-15 01:15:25 +00:00
|
|
|
DEBUG(dbgs() << "********** FIX EXECUTION DEPENDENCIES: "
|
|
|
|
<< RC->getName() << " **********\n");
|
|
|
|
|
2011-09-28 00:01:56 +00:00
|
|
|
// If no relevant registers are used in the function, we can skip it
|
|
|
|
// completely.
|
2010-03-29 23:24:21 +00:00
|
|
|
bool anyregs = false;
|
2011-09-27 23:50:46 +00:00
|
|
|
for (TargetRegisterClass::const_iterator I = RC->begin(), E = RC->end();
|
|
|
|
I != E; ++I)
|
2012-10-17 18:44:18 +00:00
|
|
|
if (MF->getRegInfo().isPhysRegUsed(*I)) {
|
2011-12-21 19:50:05 +00:00
|
|
|
anyregs = true;
|
|
|
|
break;
|
|
|
|
}
|
2010-03-29 23:24:21 +00:00
|
|
|
if (!anyregs) return false;
|
2010-03-25 17:25:00 +00:00
|
|
|
|
2011-09-27 23:50:46 +00:00
|
|
|
// Initialize the AliasMap on the first use.
|
|
|
|
if (AliasMap.empty()) {
|
|
|
|
// Given a PhysReg, AliasMap[PhysReg] is either the relevant index into RC,
|
|
|
|
// or -1.
|
|
|
|
AliasMap.resize(TRI->getNumRegs(), -1);
|
|
|
|
for (unsigned i = 0, e = RC->getNumRegs(); i != e; ++i)
|
2012-06-01 23:28:30 +00:00
|
|
|
for (MCRegAliasIterator AI(RC->getRegister(i), TRI, true);
|
|
|
|
AI.isValid(); ++AI)
|
2011-09-27 23:50:46 +00:00
|
|
|
AliasMap[*AI] = i;
|
|
|
|
}
|
|
|
|
|
2010-03-25 17:25:00 +00:00
|
|
|
MachineBasicBlock *Entry = MF->begin();
|
2011-11-07 21:59:29 +00:00
|
|
|
ReversePostOrderTraversal<MachineBasicBlock*> RPOT(Entry);
|
2011-11-09 01:06:56 +00:00
|
|
|
SmallVector<MachineBasicBlock*, 16> Loops;
|
2011-11-07 21:59:29 +00:00
|
|
|
for (ReversePostOrderTraversal<MachineBasicBlock*>::rpo_iterator
|
|
|
|
MBBI = RPOT.begin(), MBBE = RPOT.end(); MBBI != MBBE; ++MBBI) {
|
|
|
|
MachineBasicBlock *MBB = *MBBI;
|
2011-11-15 01:15:25 +00:00
|
|
|
enterBasicBlock(MBB);
|
|
|
|
if (SeenUnknownBackEdge)
|
2011-11-09 01:06:56 +00:00
|
|
|
Loops.push_back(MBB);
|
2010-03-25 17:25:00 +00:00
|
|
|
for (MachineBasicBlock::iterator I = MBB->begin(), E = MBB->end(); I != E;
|
2011-11-07 21:40:27 +00:00
|
|
|
++I)
|
|
|
|
visitInstr(I);
|
|
|
|
leaveBasicBlock(MBB);
|
2010-03-25 17:25:00 +00:00
|
|
|
}
|
2010-03-29 23:24:21 +00:00
|
|
|
|
2011-11-09 01:06:56 +00:00
|
|
|
// Visit all the loop blocks again in order to merge DomainValues from
|
|
|
|
// back-edges.
|
|
|
|
for (unsigned i = 0, e = Loops.size(); i != e; ++i) {
|
|
|
|
MachineBasicBlock *MBB = Loops[i];
|
|
|
|
enterBasicBlock(MBB);
|
2011-11-15 01:15:30 +00:00
|
|
|
for (MachineBasicBlock::iterator I = MBB->begin(), E = MBB->end(); I != E;
|
|
|
|
++I)
|
|
|
|
if (!I->isDebugValue())
|
|
|
|
processDefs(I, false);
|
2011-11-09 01:06:56 +00:00
|
|
|
leaveBasicBlock(MBB);
|
|
|
|
}
|
|
|
|
|
2011-11-07 23:08:21 +00:00
|
|
|
// Clear the LiveOuts vectors and collapse any remaining DomainValues.
|
|
|
|
for (ReversePostOrderTraversal<MachineBasicBlock*>::rpo_iterator
|
|
|
|
MBBI = RPOT.begin(), MBBE = RPOT.end(); MBBI != MBBE; ++MBBI) {
|
|
|
|
LiveOutMap::const_iterator FI = LiveOuts.find(*MBBI);
|
2011-11-09 01:06:56 +00:00
|
|
|
if (FI == LiveOuts.end() || !FI->second)
|
2011-11-07 23:08:21 +00:00
|
|
|
continue;
|
|
|
|
for (unsigned i = 0, e = NumRegs; i != e; ++i)
|
2011-11-15 01:15:25 +00:00
|
|
|
if (FI->second[i].Value)
|
|
|
|
release(FI->second[i].Value);
|
2011-11-08 22:05:17 +00:00
|
|
|
delete[] FI->second;
|
2011-11-07 23:08:21 +00:00
|
|
|
}
|
2010-03-30 20:04:01 +00:00
|
|
|
LiveOuts.clear();
|
2010-04-04 18:00:21 +00:00
|
|
|
Avail.clear();
|
|
|
|
Allocator.DestroyAll();
|
2010-03-29 23:24:21 +00:00
|
|
|
|
2010-03-25 17:25:00 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-09-27 23:50:46 +00:00
|
|
|
FunctionPass *
|
|
|
|
llvm::createExecutionDependencyFixPass(const TargetRegisterClass *RC) {
|
2011-09-28 00:01:56 +00:00
|
|
|
return new ExeDepsFix(RC);
|
2010-03-25 17:25:00 +00:00
|
|
|
}
|