Perf: cache connection between const/non-const struct variants.
In one very large program, we were spending quite a bit of time repeatedly getting const variants of StructTypes. This speeds up the front-end by about 40% for that test case. (This is something of a band-aid, pending uniquing types.)
This commit is contained in:
34
type.cpp
34
type.cpp
@@ -1754,8 +1754,10 @@ StructType::StructType(const std::string &n, const std::vector<const Type *> &el
|
|||||||
const std::vector<std::string> &en,
|
const std::vector<std::string> &en,
|
||||||
const std::vector<SourcePos> &ep,
|
const std::vector<SourcePos> &ep,
|
||||||
bool ic, Variability v, SourcePos p)
|
bool ic, Variability v, SourcePos p)
|
||||||
: name(n), elementTypes(elts), elementNames(en), elementPositions(ep),
|
: CollectionType(STRUCT_TYPE), name(n), elementTypes(elts), elementNames(en),
|
||||||
variability(v), isConst(ic), pos(p) {
|
elementPositions(ep), variability(v), isConst(ic), pos(p) {
|
||||||
|
oppositeConstStructType = NULL;
|
||||||
|
|
||||||
if (variability != Variability::Unbound) {
|
if (variability != Variability::Unbound) {
|
||||||
// For structs with non-unbound variability, we'll create the
|
// For structs with non-unbound variability, we'll create the
|
||||||
// correspoing LLVM struct type now, if one hasn't been made
|
// correspoing LLVM struct type now, if one hasn't been made
|
||||||
@@ -1908,21 +1910,33 @@ StructType::ResolveUnboundVariability(Variability v) const {
|
|||||||
|
|
||||||
const StructType *
|
const StructType *
|
||||||
StructType::GetAsConstType() const {
|
StructType::GetAsConstType() const {
|
||||||
if (IsConstType())
|
if (isConst == true)
|
||||||
return this;
|
return this;
|
||||||
else
|
else if (oppositeConstStructType != NULL)
|
||||||
return new StructType(name, elementTypes, elementNames, elementPositions,
|
return oppositeConstStructType;
|
||||||
true, variability, pos);
|
else {
|
||||||
|
oppositeConstStructType =
|
||||||
|
new StructType(name, elementTypes, elementNames, elementPositions,
|
||||||
|
true, variability, pos);
|
||||||
|
oppositeConstStructType->oppositeConstStructType = this;
|
||||||
|
return oppositeConstStructType;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const StructType *
|
const StructType *
|
||||||
StructType::GetAsNonConstType() const {
|
StructType::GetAsNonConstType() const {
|
||||||
if (!IsConstType())
|
if (isConst == false)
|
||||||
return this;
|
return this;
|
||||||
else
|
else if (oppositeConstStructType != NULL)
|
||||||
return new StructType(name, elementTypes, elementNames, elementPositions,
|
return oppositeConstStructType;
|
||||||
false, variability, pos);
|
else {
|
||||||
|
oppositeConstStructType =
|
||||||
|
new StructType(name, elementTypes, elementNames, elementPositions,
|
||||||
|
false, variability, pos);
|
||||||
|
oppositeConstStructType->oppositeConstStructType = this;
|
||||||
|
return oppositeConstStructType;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user