mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-20 14:29:27 +00:00
implement the struct version of the array speedup, speeding up the
testcase a bit more from 1:48 -> 1.40. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23619 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
ab55698349
commit
c182a88aec
@ -889,8 +889,9 @@ namespace llvm {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
static ValueMap<std::vector<Constant*>, StructType,
|
typedef ValueMap<std::vector<Constant*>, StructType,
|
||||||
ConstantStruct> StructConstants;
|
ConstantStruct> StructConstantsTy;
|
||||||
|
static StructConstantsTy StructConstants;
|
||||||
|
|
||||||
static std::vector<Constant*> getValType(ConstantStruct *CS) {
|
static std::vector<Constant*> getValType(ConstantStruct *CS) {
|
||||||
std::vector<Constant*> Elements;
|
std::vector<Constant*> Elements;
|
||||||
@ -1346,6 +1347,7 @@ const char *ConstantExpr::getOpcodeName() const {
|
|||||||
void ConstantArray::replaceUsesOfWithOnConstant(Value *From, Value *To,
|
void ConstantArray::replaceUsesOfWithOnConstant(Value *From, Value *To,
|
||||||
bool DisableChecking) {
|
bool DisableChecking) {
|
||||||
assert(isa<Constant>(To) && "Cannot make Constant refer to non-constant!");
|
assert(isa<Constant>(To) && "Cannot make Constant refer to non-constant!");
|
||||||
|
Constant *ToC = cast<Constant>(To);
|
||||||
|
|
||||||
std::pair<ArrayConstantsTy::MapKey, ConstantArray*> Lookup;
|
std::pair<ArrayConstantsTy::MapKey, ConstantArray*> Lookup;
|
||||||
Lookup.first.first = getType();
|
Lookup.first.first = getType();
|
||||||
@ -1353,10 +1355,12 @@ void ConstantArray::replaceUsesOfWithOnConstant(Value *From, Value *To,
|
|||||||
std::vector<Constant*> &Values = Lookup.first.second;
|
std::vector<Constant*> &Values = Lookup.first.second;
|
||||||
Values.reserve(getNumOperands()); // Build replacement array.
|
Values.reserve(getNumOperands()); // Build replacement array.
|
||||||
|
|
||||||
bool isAllZeros = false; // Does this turn into an all-zeros array?
|
// Fill values with the modified operands of the constant array. Also,
|
||||||
|
// compute whether this turns into an all-zeros array.
|
||||||
|
bool isAllZeros = ToC->isNullValue();
|
||||||
for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
|
for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
|
||||||
Constant *Val = getOperand(i);
|
Constant *Val = getOperand(i);
|
||||||
if (Val == From) Val = cast<Constant>(To);
|
if (Val == From) Val = ToC;
|
||||||
Values.push_back(Val);
|
Values.push_back(Val);
|
||||||
if (isAllZeros) isAllZeros = Val->isNullValue();
|
if (isAllZeros) isAllZeros = Val->isNullValue();
|
||||||
}
|
}
|
||||||
@ -1384,7 +1388,7 @@ void ConstantArray::replaceUsesOfWithOnConstant(Value *From, Value *To,
|
|||||||
// Update to the new values.
|
// Update to the new values.
|
||||||
for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
|
for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
|
||||||
if (getOperand(i) == From)
|
if (getOperand(i) == From)
|
||||||
setOperand(i, cast<Constant>(To));
|
setOperand(i, ToC);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1405,16 +1409,52 @@ void ConstantArray::replaceUsesOfWithOnConstant(Value *From, Value *To,
|
|||||||
void ConstantStruct::replaceUsesOfWithOnConstant(Value *From, Value *To,
|
void ConstantStruct::replaceUsesOfWithOnConstant(Value *From, Value *To,
|
||||||
bool DisableChecking) {
|
bool DisableChecking) {
|
||||||
assert(isa<Constant>(To) && "Cannot make Constant refer to non-constant!");
|
assert(isa<Constant>(To) && "Cannot make Constant refer to non-constant!");
|
||||||
|
Constant *ToC = cast<Constant>(To);
|
||||||
|
|
||||||
std::vector<Constant*> Values;
|
std::pair<StructConstantsTy::MapKey, ConstantStruct*> Lookup;
|
||||||
Values.reserve(getNumOperands()); // Build replacement array...
|
Lookup.first.first = getType();
|
||||||
|
Lookup.second = this;
|
||||||
|
std::vector<Constant*> &Values = Lookup.first.second;
|
||||||
|
Values.reserve(getNumOperands()); // Build replacement struct.
|
||||||
|
|
||||||
|
// Fill values with the modified operands of the constant struct. Also,
|
||||||
|
// compute whether this turns into an all-zeros struct.
|
||||||
|
bool isAllZeros = ToC->isNullValue();
|
||||||
for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
|
for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
|
||||||
Constant *Val = getOperand(i);
|
Constant *Val = getOperand(i);
|
||||||
if (Val == From) Val = cast<Constant>(To);
|
if (Val == From) Val = ToC;
|
||||||
Values.push_back(Val);
|
Values.push_back(Val);
|
||||||
|
if (isAllZeros) isAllZeros = Val->isNullValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
Constant *Replacement = 0;
|
||||||
|
if (isAllZeros) {
|
||||||
|
Replacement = ConstantAggregateZero::get(getType());
|
||||||
|
} else {
|
||||||
|
// Check to see if we have this array type already.
|
||||||
|
bool Exists;
|
||||||
|
StructConstantsTy::MapIterator I =
|
||||||
|
StructConstants.InsertOrGetItem(Lookup, Exists);
|
||||||
|
|
||||||
|
if (Exists) {
|
||||||
|
Replacement = I->second;
|
||||||
|
} else {
|
||||||
|
// Okay, the new shape doesn't exist in the system yet. Instead of
|
||||||
|
// creating a new constant struct, inserting it, replaceallusesof'ing the
|
||||||
|
// old with the new, then deleting the old... just update the current one
|
||||||
|
// in place!
|
||||||
|
if (I != StructConstants.map_end() && I->second == this)
|
||||||
|
++I; // Do not invalidate iterator!
|
||||||
|
StructConstants.remove(this); // Remove old shape from the map.
|
||||||
|
|
||||||
|
// Update to the new values.
|
||||||
|
for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
|
||||||
|
if (getOperand(i) == From)
|
||||||
|
setOperand(i, ToC);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Constant *Replacement = ConstantStruct::get(getType(), Values);
|
|
||||||
assert(Replacement != this && "I didn't contain From!");
|
assert(Replacement != this && "I didn't contain From!");
|
||||||
|
|
||||||
// Everyone using this now uses the replacement...
|
// Everyone using this now uses the replacement...
|
||||||
|
Loading…
x
Reference in New Issue
Block a user