mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-11 11:34:02 +00:00
SelectionDAGBuilder::Clusterify : main functinality was replaced with CRSBuilder::optimize, so big part of Clusterify's code was reduced.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@156804 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
24d86e0ca9
commit
a62e235c1c
@ -51,6 +51,7 @@
|
|||||||
#include "llvm/Target/TargetLowering.h"
|
#include "llvm/Target/TargetLowering.h"
|
||||||
#include "llvm/Target/TargetOptions.h"
|
#include "llvm/Target/TargetOptions.h"
|
||||||
#include "llvm/Support/CommandLine.h"
|
#include "llvm/Support/CommandLine.h"
|
||||||
|
#include "llvm/Support/CRSBuilder.h"
|
||||||
#include "llvm/Support/Debug.h"
|
#include "llvm/Support/Debug.h"
|
||||||
#include "llvm/Support/ErrorHandling.h"
|
#include "llvm/Support/ErrorHandling.h"
|
||||||
#include "llvm/Support/MathExtras.h"
|
#include "llvm/Support/MathExtras.h"
|
||||||
@ -2038,7 +2039,7 @@ static inline bool areJTsAllowed(const TargetLowering &TLI) {
|
|||||||
|
|
||||||
static APInt ComputeRange(const APInt &First, const APInt &Last) {
|
static APInt ComputeRange(const APInt &First, const APInt &Last) {
|
||||||
uint32_t BitWidth = std::max(Last.getBitWidth(), First.getBitWidth()) + 1;
|
uint32_t BitWidth = std::max(Last.getBitWidth(), First.getBitWidth()) + 1;
|
||||||
APInt LastExt = Last.sext(BitWidth), FirstExt = First.sext(BitWidth);
|
APInt LastExt = Last.zext(BitWidth), FirstExt = First.zext(BitWidth);
|
||||||
return (LastExt - FirstExt + 1ULL);
|
return (LastExt - FirstExt + 1ULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2104,7 +2105,7 @@ bool SelectionDAGBuilder::handleJTSwitchCase(CaseRec &CR,
|
|||||||
const APInt &Low = cast<ConstantInt>(I->Low)->getValue();
|
const APInt &Low = cast<ConstantInt>(I->Low)->getValue();
|
||||||
const APInt &High = cast<ConstantInt>(I->High)->getValue();
|
const APInt &High = cast<ConstantInt>(I->High)->getValue();
|
||||||
|
|
||||||
if (Low.sle(TEI) && TEI.sle(High)) {
|
if (Low.ule(TEI) && TEI.ule(High)) {
|
||||||
DestBBs.push_back(I->BB);
|
DestBBs.push_back(I->BB);
|
||||||
if (TEI==High)
|
if (TEI==High)
|
||||||
++I;
|
++I;
|
||||||
@ -2183,8 +2184,10 @@ bool SelectionDAGBuilder::handleBTSplitSwitchCase(CaseRec& CR,
|
|||||||
const APInt &LEnd = cast<ConstantInt>(I->High)->getValue();
|
const APInt &LEnd = cast<ConstantInt>(I->High)->getValue();
|
||||||
const APInt &RBegin = cast<ConstantInt>(J->Low)->getValue();
|
const APInt &RBegin = cast<ConstantInt>(J->Low)->getValue();
|
||||||
APInt Range = ComputeRange(LEnd, RBegin);
|
APInt Range = ComputeRange(LEnd, RBegin);
|
||||||
assert((Range - 2ULL).isNonNegative() &&
|
// Old: assert((Range - 2ULL).isNonNegative() && "Invalid case distance");
|
||||||
"Invalid case distance");
|
// Why APInt::sge wasn't used?
|
||||||
|
assert(Range.uge(APInt(Range.getBitWidth(), 2)) && "Invalid case distance");
|
||||||
|
|
||||||
// Use volatile double here to avoid excess precision issues on some hosts,
|
// Use volatile double here to avoid excess precision issues on some hosts,
|
||||||
// e.g. that use 80-bit X87 registers.
|
// e.g. that use 80-bit X87 registers.
|
||||||
volatile double LDensity =
|
volatile double LDensity =
|
||||||
@ -2407,57 +2410,43 @@ bool SelectionDAGBuilder::handleBitTestsSwitchCase(CaseRec& CR,
|
|||||||
/// Clusterify - Transform simple list of Cases into list of CaseRange's
|
/// Clusterify - Transform simple list of Cases into list of CaseRange's
|
||||||
size_t SelectionDAGBuilder::Clusterify(CaseVector& Cases,
|
size_t SelectionDAGBuilder::Clusterify(CaseVector& Cases,
|
||||||
const SwitchInst& SI) {
|
const SwitchInst& SI) {
|
||||||
size_t numCmps = 0;
|
|
||||||
|
/// Use a shorter form of declaration, and also
|
||||||
|
/// show the we want to use CRSBuilder as Clusterifier.
|
||||||
|
typedef CRSBuilderBase<MachineBasicBlock, true> Clusterifier;
|
||||||
|
|
||||||
|
Clusterifier TheClusterifier;
|
||||||
|
|
||||||
BranchProbabilityInfo *BPI = FuncInfo.BPI;
|
|
||||||
// Start with "simple" cases
|
// Start with "simple" cases
|
||||||
for (SwitchInst::ConstCaseIt i = SI.case_begin(), e = SI.case_end();
|
for (SwitchInst::ConstCaseIt i = SI.case_begin(), e = SI.case_end();
|
||||||
i != e; ++i) {
|
i != e; ++i) {
|
||||||
const BasicBlock *SuccBB = i.getCaseSuccessor();
|
const BasicBlock *SuccBB = i.getCaseSuccessor();
|
||||||
MachineBasicBlock *SMBB = FuncInfo.MBBMap[SuccBB];
|
MachineBasicBlock *SMBB = FuncInfo.MBBMap[SuccBB];
|
||||||
|
|
||||||
uint32_t ExtraWeight = BPI ? BPI->getEdgeWeight(SI.getParent(), SuccBB) : 0;
|
TheClusterifier.add(i.getCaseValueEx(), SMBB);
|
||||||
|
|
||||||
Cases.push_back(Case(i.getCaseValue(), i.getCaseValue(),
|
|
||||||
SMBB, ExtraWeight));
|
|
||||||
}
|
}
|
||||||
std::sort(Cases.begin(), Cases.end(), CaseCmp());
|
|
||||||
|
TheClusterifier.optimize();
|
||||||
// Merge case into clusters
|
|
||||||
if (Cases.size() >= 2)
|
BranchProbabilityInfo *BPI = FuncInfo.BPI;
|
||||||
// Must recompute end() each iteration because it may be
|
size_t numCmps = 0;
|
||||||
// invalidated by erase if we hold on to it
|
for (Clusterifier::RangeIterator i = TheClusterifier.begin(),
|
||||||
for (CaseItr I = Cases.begin(), J = llvm::next(Cases.begin());
|
e = TheClusterifier.end(); i != e; ++i, ++numCmps) {
|
||||||
J != Cases.end(); ) {
|
Clusterifier::Cluster &C = *i;
|
||||||
const APInt& nextValue = cast<ConstantInt>(J->Low)->getValue();
|
unsigned W = 0;
|
||||||
const APInt& currentValue = cast<ConstantInt>(I->High)->getValue();
|
if (BPI) {
|
||||||
MachineBasicBlock* nextBB = J->BB;
|
W = BPI->getEdgeWeight(SI.getParent(), C.second->getBasicBlock());
|
||||||
MachineBasicBlock* currentBB = I->BB;
|
if (!W)
|
||||||
|
W = 16;
|
||||||
// If the two neighboring cases go to the same destination, merge them
|
W *= C.first.Weight;
|
||||||
// into a single case.
|
BPI->setEdgeWeight(SI.getParent(), C.second->getBasicBlock(), W);
|
||||||
if ((nextValue - currentValue == 1) && (currentBB == nextBB)) {
|
|
||||||
I->High = J->High;
|
|
||||||
J = Cases.erase(J);
|
|
||||||
|
|
||||||
if (BranchProbabilityInfo *BPI = FuncInfo.BPI) {
|
|
||||||
uint32_t CurWeight = currentBB->getBasicBlock() ?
|
|
||||||
BPI->getEdgeWeight(SI.getParent(), currentBB->getBasicBlock()) : 16;
|
|
||||||
uint32_t NextWeight = nextBB->getBasicBlock() ?
|
|
||||||
BPI->getEdgeWeight(SI.getParent(), nextBB->getBasicBlock()) : 16;
|
|
||||||
|
|
||||||
BPI->setEdgeWeight(SI.getParent(), currentBB->getBasicBlock(),
|
|
||||||
CurWeight + NextWeight);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
I = J++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (CaseItr I=Cases.begin(), E=Cases.end(); I!=E; ++I, ++numCmps) {
|
Cases.push_back(Case(C.first.Low, C.first.High, C.second, W));
|
||||||
if (I->Low != I->High)
|
|
||||||
// A range counts double, since it requires two compares.
|
if (C.first.Low != C.first.High)
|
||||||
++numCmps;
|
// A range counts double, since it requires two compares.
|
||||||
|
++numCmps;
|
||||||
}
|
}
|
||||||
|
|
||||||
return numCmps;
|
return numCmps;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user