And lastly rename NewProjection to Projection. This is a NFC. rdar://24520269

This commit is contained in:
Xin Tong
2016-02-09 17:30:14 -08:00
parent 042c6e033d
commit 84a6ff1d98
19 changed files with 460 additions and 460 deletions

View File

@@ -76,7 +76,7 @@ struct PointerIntEnumIndexKindValue
/// determine what cases are pointer and which are indices. For instance the one
/// used by Projection in swift is:
///
/// enum class NewProjectionKind : unsigned {
/// enum class ProjectionKind : unsigned {
/// // PointerProjectionKinds
/// Upcast = 0,
/// RefCast = 1,

View File

@@ -33,8 +33,8 @@
namespace swift {
class SILBuilder;
class NewProjectionPath;
using NewProjectionPathList = llvm::SmallVector<Optional<NewProjectionPath>, 8>;
class ProjectionPath;
using ProjectionPathList = llvm::SmallVector<Optional<ProjectionPath>, 8>;
enum class SubSeqRelation_t : uint8_t {
Unknown,
@@ -78,9 +78,9 @@ bool getIntegerIndex(SILValue IndexVal, unsigned &IndexConst);
/// most cases this will not happen. For simplicity, we limit such kinds to use
/// no more than 4 bits.
///
/// The NewProjection class contains the logic to use NewProjectionKind in this
/// The Projection class contains the logic to use ProjectionKind in this
/// manner.
enum class NewProjectionKind : unsigned {
enum class ProjectionKind : unsigned {
// PointerProjectionKinds
Upcast = 0,
RefCast = 1,
@@ -90,34 +90,34 @@ enum class NewProjectionKind : unsigned {
// Index Projection Kinds
FirstIndexKind = 7,
Struct = PointerIntEnumIndexKindValue<0, NewProjectionKind>::value,
Tuple = PointerIntEnumIndexKindValue<1, NewProjectionKind>::value,
Index = PointerIntEnumIndexKindValue<2, NewProjectionKind>::value,
Class = PointerIntEnumIndexKindValue<3, NewProjectionKind>::value,
Enum = PointerIntEnumIndexKindValue<4, NewProjectionKind>::value,
Box = PointerIntEnumIndexKindValue<5, NewProjectionKind>::value,
Struct = PointerIntEnumIndexKindValue<0, ProjectionKind>::value,
Tuple = PointerIntEnumIndexKindValue<1, ProjectionKind>::value,
Index = PointerIntEnumIndexKindValue<2, ProjectionKind>::value,
Class = PointerIntEnumIndexKindValue<3, ProjectionKind>::value,
Enum = PointerIntEnumIndexKindValue<4, ProjectionKind>::value,
Box = PointerIntEnumIndexKindValue<5, ProjectionKind>::value,
LastIndexKind = Enum,
};
constexpr unsigned MaxPointerProjectionKind = ((1 << TypeAlignInBits) - 1);
/// Make sure that our tagged pointer assumptions are true. See comment above
/// the declaration of NewProjectionKind.
static_assert(unsigned(NewProjectionKind::LastPointerKind) <=
/// the declaration of ProjectionKind.
static_assert(unsigned(ProjectionKind::LastPointerKind) <=
unsigned(MaxPointerProjectionKind),
"Too many projection kinds to fit in Projection");
static inline bool isCastNewProjectionKind(NewProjectionKind Kind) {
static inline bool isCastProjectionKind(ProjectionKind Kind) {
switch (Kind) {
case NewProjectionKind::Upcast:
case NewProjectionKind::RefCast:
case NewProjectionKind::BitwiseCast:
case ProjectionKind::Upcast:
case ProjectionKind::RefCast:
case ProjectionKind::BitwiseCast:
return true;
case NewProjectionKind::Struct:
case NewProjectionKind::Tuple:
case NewProjectionKind::Index:
case NewProjectionKind::Class:
case NewProjectionKind::Enum:
case NewProjectionKind::Box:
case ProjectionKind::Struct:
case ProjectionKind::Tuple:
case ProjectionKind::Index:
case ProjectionKind::Class:
case ProjectionKind::Enum:
case ProjectionKind::Box:
return false;
}
}
@@ -126,11 +126,11 @@ static inline bool isCastNewProjectionKind(NewProjectionKind Kind) {
/// that immediately contains it.
///
/// This lightweight utility maps a SIL address projection to an index.
struct NewProjectionIndex {
struct ProjectionIndex {
SILValue Aggregate;
unsigned Index;
explicit NewProjectionIndex(SILValue V) :Index(~0U) {
explicit ProjectionIndex(SILValue V) :Index(~0U) {
switch (V->getKind()) {
default:
break;
@@ -190,10 +190,10 @@ struct NewProjectionIndex {
/// projections.
///
/// It is intended to be pointer sized and trivially copyable so that memcpy can
/// be used to copy a NewProjection.
class NewProjection {
/// be used to copy a Projection.
class Projection {
friend NewProjectionPath;
friend ProjectionPath;
static constexpr unsigned NumPointerKindBits = TypeAlignInBits;
@@ -201,7 +201,7 @@ class NewProjection {
/// the top of our word.
static constexpr unsigned NumIndexKindBits = 4;
using ValueTy = PointerIntEnum<NewProjectionKind, TypeBase *,
using ValueTy = PointerIntEnum<ProjectionKind, TypeBase *,
NumPointerKindBits, NumIndexKindBits>;
/// A pointer sized type that is used to store the kind of projection that is
/// being represented and also all of the necessary information to convert a
@@ -209,25 +209,25 @@ class NewProjection {
ValueTy Value;
public:
NewProjection() = delete;
Projection() = delete;
explicit NewProjection(SILValue V)
: NewProjection(dyn_cast<SILInstruction>(V)) {}
explicit NewProjection(SILInstruction *I);
explicit Projection(SILValue V)
: Projection(dyn_cast<SILInstruction>(V)) {}
explicit Projection(SILInstruction *I);
NewProjection(NewProjectionKind Kind, unsigned NewIndex)
Projection(ProjectionKind Kind, unsigned NewIndex)
: Value(Kind, NewIndex) {}
NewProjection(NewProjectionKind Kind, TypeBase *Ptr)
Projection(ProjectionKind Kind, TypeBase *Ptr)
: Value(Kind, Ptr) {}
NewProjection(NewProjection &&P) = default;
NewProjection(const NewProjection &P) = default;
~NewProjection() = default;
Projection(Projection &&P) = default;
Projection(const Projection &P) = default;
~Projection() = default;
NewProjection &operator=(const NewProjection &P) = default;
Projection &operator=(const Projection &P) = default;
NewProjection &operator=(NewProjection &&P) = default;
Projection &operator=(Projection &&P) = default;
bool isValid() const { return Value.isValid(); }
@@ -240,7 +240,7 @@ public:
/// Determine if I is a value projection instruction whose corresponding
/// projection equals this projection.
bool matchesObjectProjection(SILInstruction *I) const {
NewProjection P(I);
Projection P(I);
return P.isValid() && P == *this;
}
@@ -274,21 +274,21 @@ public:
SILType getType(SILType BaseType, SILModule &M) const {
assert(isValid());
switch (getKind()) {
case NewProjectionKind::Struct:
case NewProjectionKind::Class:
case ProjectionKind::Struct:
case ProjectionKind::Class:
return BaseType.getFieldType(getVarDecl(BaseType), M);
case NewProjectionKind::Enum:
case ProjectionKind::Enum:
return BaseType.getEnumElementType(getEnumElementDecl(BaseType), M);
case NewProjectionKind::Box:
case ProjectionKind::Box:
return SILType::getPrimitiveAddressType(BaseType.castTo<SILBoxType>()->
getBoxedType());
case NewProjectionKind::Tuple:
case ProjectionKind::Tuple:
return BaseType.getTupleElementType(getIndex());
case NewProjectionKind::Upcast:
case NewProjectionKind::RefCast:
case NewProjectionKind::BitwiseCast:
case ProjectionKind::Upcast:
case ProjectionKind::RefCast:
case ProjectionKind::BitwiseCast:
return getCastType(BaseType);
case NewProjectionKind::Index:
case ProjectionKind::Index:
// Index types do not change the underlying type.
return BaseType;
}
@@ -296,8 +296,8 @@ public:
VarDecl *getVarDecl(SILType BaseType) const {
assert(isValid());
assert((getKind() == NewProjectionKind::Struct ||
getKind() == NewProjectionKind::Class));
assert((getKind() == ProjectionKind::Struct ||
getKind() == ProjectionKind::Class));
assert(BaseType.getNominalOrBoundGenericNominal() &&
"This should only be called with a nominal type");
auto *NDecl = BaseType.getNominalOrBoundGenericNominal();
@@ -308,7 +308,7 @@ public:
EnumElementDecl *getEnumElementDecl(SILType BaseType) const {
assert(isValid());
assert(getKind() == NewProjectionKind::Enum);
assert(getKind() == ProjectionKind::Enum);
assert(BaseType.getEnumOrBoundGenericEnum() && "Expected enum type");
auto Iter = BaseType.getEnumOrBoundGenericEnum()->getAllElements().begin();
std::advance(Iter, getIndex());
@@ -318,39 +318,39 @@ public:
ValueDecl *getValueDecl(SILType BaseType) const {
assert(isValid());
switch (getKind()) {
case NewProjectionKind::Enum:
case ProjectionKind::Enum:
return getEnumElementDecl(BaseType);
case NewProjectionKind::Struct:
case NewProjectionKind::Class:
case ProjectionKind::Struct:
case ProjectionKind::Class:
return getVarDecl(BaseType);
case NewProjectionKind::Upcast:
case NewProjectionKind::RefCast:
case NewProjectionKind::BitwiseCast:
case NewProjectionKind::Index:
case NewProjectionKind::Tuple:
case NewProjectionKind::Box:
llvm_unreachable("NewProjectionKind that does not have a value decl?");
case ProjectionKind::Upcast:
case ProjectionKind::RefCast:
case ProjectionKind::BitwiseCast:
case ProjectionKind::Index:
case ProjectionKind::Tuple:
case ProjectionKind::Box:
llvm_unreachable("ProjectionKind that does not have a value decl?");
}
}
SILType getCastType(SILType BaseType) const {
assert(isValid());
assert(getKind() == NewProjectionKind::Upcast ||
getKind() == NewProjectionKind::RefCast ||
getKind() == NewProjectionKind::BitwiseCast);
assert(getKind() == ProjectionKind::Upcast ||
getKind() == ProjectionKind::RefCast ||
getKind() == ProjectionKind::BitwiseCast);
auto *Ty = getPointer();
assert(Ty->isCanonical());
return SILType::getPrimitiveType(Ty->getCanonicalType(),
BaseType.getCategory());
}
bool operator<(const NewProjection &Other) const;
bool operator<(const Projection &Other) const;
bool operator==(const NewProjection &Other) const {
bool operator==(const Projection &Other) const {
return Value == Other.Value;
}
bool operator!=(const NewProjection &Other) const {
bool operator!=(const Projection &Other) const {
return !(*this == Other);
}
@@ -360,7 +360,7 @@ public:
SILValue getOperandForAggregate(SILInstruction *I) const;
/// Convenience method for getting the raw underlying kind.
NewProjectionKind getKind() const { return *Value.getKind(); }
ProjectionKind getKind() const { return *Value.getKind(); }
/// Returns true if this instruction projects from an address type to an
/// address subtype.
@@ -403,7 +403,7 @@ public:
/// Given a specific SILType, return all first level projections if it is an
/// aggregate.
static void getFirstLevelProjections(SILType V, SILModule &Mod,
llvm::SmallVectorImpl<NewProjection> &Out);
llvm::SmallVectorImpl<Projection> &Out);
/// Is this cast which only allows for equality?
///
@@ -414,32 +414,32 @@ public:
/// relationships when TBAA would say that aliasing can not occur.
bool isAliasingCast() const {
switch (getKind()) {
case NewProjectionKind::RefCast:
case NewProjectionKind::BitwiseCast:
case ProjectionKind::RefCast:
case ProjectionKind::BitwiseCast:
return true;
case NewProjectionKind::Upcast:
case NewProjectionKind::Struct:
case NewProjectionKind::Tuple:
case NewProjectionKind::Index:
case NewProjectionKind::Class:
case NewProjectionKind::Enum:
case NewProjectionKind::Box:
case ProjectionKind::Upcast:
case ProjectionKind::Struct:
case ProjectionKind::Tuple:
case ProjectionKind::Index:
case ProjectionKind::Class:
case ProjectionKind::Enum:
case ProjectionKind::Box:
return false;
}
}
bool isNominalKind() const {
switch (getKind()) {
case NewProjectionKind::Class:
case NewProjectionKind::Enum:
case NewProjectionKind::Struct:
case ProjectionKind::Class:
case ProjectionKind::Enum:
case ProjectionKind::Struct:
return true;
case NewProjectionKind::BitwiseCast:
case NewProjectionKind::Index:
case NewProjectionKind::RefCast:
case NewProjectionKind::Tuple:
case NewProjectionKind::Upcast:
case NewProjectionKind::Box:
case ProjectionKind::BitwiseCast:
case ProjectionKind::Index:
case ProjectionKind::RefCast:
case ProjectionKind::Tuple:
case ProjectionKind::Upcast:
case ProjectionKind::Box:
return false;
}
}
@@ -464,7 +464,7 @@ private:
/// This is to make sure that new projection is never bigger than a
/// pointer. This is just for performance.
static_assert(sizeof(NewProjection) == sizeof(uintptr_t),
static_assert(sizeof(Projection) == sizeof(uintptr_t),
"IndexType should be pointer sized");
/// A "path" of projections abstracting either value or aggregate projections
@@ -476,9 +476,9 @@ static_assert(sizeof(NewProjection) == sizeof(uintptr_t),
/// 1. Converting value projections to aggregate projections or vis-a-versa.
/// 2. Performing tuple operations on two paths (using the mathematical
/// definition of tuples as ordered sets).
class NewProjectionPath {
class ProjectionPath {
public:
using PathTy = llvm::SmallVector<NewProjection, 4>;
using PathTy = llvm::SmallVector<Projection, 4>;
private:
SILType BaseType;
@@ -488,30 +488,30 @@ private:
public:
/// Create an empty path which serves as a stack. Use push_back() to populate
/// the stack with members.
NewProjectionPath(SILType Base)
ProjectionPath(SILType Base)
: BaseType(Base), MostDerivedType(SILType()), Path() {}
NewProjectionPath(SILType Base, SILType End)
ProjectionPath(SILType Base, SILType End)
: BaseType(Base), MostDerivedType(End), Path() {}
~NewProjectionPath() = default;
~ProjectionPath() = default;
/// Do not allow copy construction. The only way to get one of these is from
/// getProjectionPath.
NewProjectionPath(const NewProjectionPath &Other) {
ProjectionPath(const ProjectionPath &Other) {
BaseType = Other.BaseType;
MostDerivedType = Other.MostDerivedType;
Path = Other.Path;
}
NewProjectionPath &operator=(const NewProjectionPath &O) {
ProjectionPath &operator=(const ProjectionPath &O) {
BaseType = O.BaseType;
MostDerivedType = O.MostDerivedType;
Path = O.Path;
return *this;
}
/// We only allow for moves of NewProjectionPath since we only want them to be
/// We only allow for moves of ProjectionPath since we only want them to be
/// able to be constructed by calling our factory method.
NewProjectionPath(NewProjectionPath &&O) {
ProjectionPath(ProjectionPath &&O) {
BaseType = O.BaseType;
MostDerivedType = O.MostDerivedType;
Path = O.Path;
@@ -520,7 +520,7 @@ public:
O.Path.clear();
}
NewProjectionPath &operator=(NewProjectionPath &&O) {
ProjectionPath &operator=(ProjectionPath &&O) {
BaseType = O.BaseType;
MostDerivedType = O.MostDerivedType;
Path = O.Path;
@@ -531,7 +531,7 @@ public:
}
/// Append the projection \p P onto this.
NewProjectionPath &append(const NewProjection &P) {
ProjectionPath &append(const Projection &P) {
push_back(P);
// Invalidate most derived type.
MostDerivedType = SILType();
@@ -539,7 +539,7 @@ public:
}
/// Append the projections in \p Other onto this.
NewProjectionPath &append(const NewProjectionPath &Other) {
ProjectionPath &append(const ProjectionPath &Other) {
for (auto &X : Other.Path) {
push_back(X);
}
@@ -554,7 +554,7 @@ public:
/// *NOTE* This method allows for transitions from object types to address
/// types via ref_element_addr. If Start is an address type though, End will
/// always also be an address type.
static Optional<NewProjectionPath> getProjectionPath(SILValue Start,
static Optional<ProjectionPath> getProjectionPath(SILValue Start,
SILValue End);
/// Treating a projection path as an ordered set, if RHS is a prefix of LHS,
@@ -563,8 +563,8 @@ public:
/// An example of this transformation would be:
///
/// LHS = [A, B, C, D, E], RHS = [A, B, C] => Result = [D, E]
static Optional<NewProjectionPath>
removePrefix(const NewProjectionPath &Path, const NewProjectionPath &Prefix);
static Optional<ProjectionPath>
removePrefix(const ProjectionPath &Path, const ProjectionPath &Prefix);
/// Given the SILType Base, expand every leaf nodes in the type tree.
///
@@ -572,7 +572,7 @@ public:
/// is a leaf node in the type tree.
static void expandTypeIntoLeafProjectionPaths(SILType BaseType,
SILModule *Mod,
NewProjectionPathList &P);
ProjectionPathList &P);
/// Given the SILType Base, expand every intermediate and leaf nodes in the
/// type tree.
@@ -581,19 +581,19 @@ public:
/// is a leaf node in the type tree.
static void expandTypeIntoNodeProjectionPaths(SILType BaseType,
SILModule *Mod,
NewProjectionPathList &P);
ProjectionPathList &P);
/// Returns true if the two paths have a non-empty symmetric
/// difference.
///
/// This means that the two objects have the same base but access different
/// fields of the base object.
bool hasNonEmptySymmetricDifference(const NewProjectionPath &RHS) const;
bool hasNonEmptySymmetricDifference(const ProjectionPath &RHS) const;
/// Compute the subsequence relation in between LHS and RHS which tells the
/// user whether or not the two sequences are unrelated, equal, or if one is a
/// subsequence of the other.
SubSeqRelation_t computeSubSeqRelation(const NewProjectionPath &RHS) const;
SubSeqRelation_t computeSubSeqRelation(const ProjectionPath &RHS) const;
/// Returns true if this is a projection path that takes an address base type
/// to an address derived type.
@@ -617,21 +617,21 @@ public:
SILValue Base);
/// Pushes an element to the path.
void push_back(const NewProjection &Proj) { Path.push_back(Proj); }
void push_back(const Projection &Proj) { Path.push_back(Proj); }
/// Removes the last element from the path.
void pop_back() { Path.pop_back(); }
/// Returns the last element of the path.
const NewProjection &back() const { return Path.back(); }
const Projection &back() const { return Path.back(); }
/// Returns true if LHS and RHS have all the same projections in the same
/// order.
bool operator==(const NewProjectionPath &RHS) const {
bool operator==(const ProjectionPath &RHS) const {
return computeSubSeqRelation(RHS) == SubSeqRelation_t::Equal;
}
bool operator!=(const NewProjectionPath &RHS) const {
bool operator!=(const ProjectionPath &RHS) const {
return !(*this == RHS);
}
@@ -693,22 +693,22 @@ public:
};
/// Returns the hashcode for the new projection path.
static inline llvm::hash_code hash_value(const NewProjectionPath &P) {
static inline llvm::hash_code hash_value(const ProjectionPath &P) {
return llvm::hash_combine_range(P.begin(), P.end());
}
/// Returns the hashcode for the projection path.
static inline llvm::hash_code hash_value(const NewProjection &P) {
static inline llvm::hash_code hash_value(const Projection &P) {
return llvm::hash_combine(static_cast<unsigned>(P.getKind()));
}
class NewProjectionTree;
class ProjectionTree;
class NewProjectionTreeNode {
friend class NewProjectionTree;
class ProjectionTreeNode {
friend class ProjectionTree;
/// The index of the current node in the tree. Can be used to lookup this node
/// from the NewProjectionTree. The reason why we use an Index instead of a
/// from the ProjectionTree. The reason why we use an Index instead of a
/// pointer is that the SmallVector that we use to store these can reallocate
/// invalidating our pointers.
unsigned Index;
@@ -728,7 +728,7 @@ class NewProjectionTreeNode {
llvm::SmallVector<SILValue, 4> BaseValues;
/// The projection that this node represents. None in the root.
llvm::Optional<NewProjection> Proj;
llvm::Optional<Projection> Proj;
/// The index of the parent of this projection tree node in the projection
/// tree. None in the root.
@@ -761,13 +761,13 @@ class NewProjectionTreeNode {
};
/// Constructor for the root of the tree.
NewProjectionTreeNode(SILType BaseTy)
ProjectionTreeNode(SILType BaseTy)
: Index(0), BaseType(BaseTy), BaseValues(), Proj(), Parent(),
NonProjUsers(), ChildProjections(), Initialized(false), IsLive(false) {}
// Normal constructor for non-root nodes.
NewProjectionTreeNode(NewProjectionTreeNode *Parent, unsigned Index, SILType BaseTy,
NewProjection P)
ProjectionTreeNode(ProjectionTreeNode *Parent, unsigned Index, SILType BaseTy,
Projection P)
: Index(Index), BaseType(BaseTy), BaseValues(), Proj(P),
Parent(Parent->getIndex()), NonProjUsers(), ChildProjections(),
Initialized(false), IsLive(false) {}
@@ -775,14 +775,14 @@ class NewProjectionTreeNode {
public:
class NewAggregateBuilder;
~NewProjectionTreeNode() = default;
NewProjectionTreeNode(const NewProjectionTreeNode &) = default;
~ProjectionTreeNode() = default;
ProjectionTreeNode(const ProjectionTreeNode &) = default;
llvm::ArrayRef<unsigned> getChildProjections() {
return llvm::makeArrayRef(ChildProjections);
}
llvm::Optional<NewProjection> &getProjection() {
llvm::Optional<Projection> &getProjection() {
return Proj;
}
@@ -804,8 +804,8 @@ public:
return BaseType;
}
NewProjectionTreeNode *getChildForProjection(NewProjectionTree &Tree,
const NewProjection &P);
ProjectionTreeNode *getChildForProjection(ProjectionTree &Tree,
const Projection &P);
NullablePtr<SILInstruction> createProjection(SILBuilder &B, SILLocation Loc,
SILValue Arg) const;
@@ -816,17 +816,17 @@ public:
unsigned getIndex() const { return Index; }
NewProjectionTreeNode *getParent(NewProjectionTree &Tree);
const NewProjectionTreeNode *getParent(const NewProjectionTree &Tree) const;
ProjectionTreeNode *getParent(ProjectionTree &Tree);
const ProjectionTreeNode *getParent(const ProjectionTree &Tree) const;
NewProjectionTreeNode *getParentOrNull(NewProjectionTree &Tree) {
ProjectionTreeNode *getParentOrNull(ProjectionTree &Tree) {
if (!Parent.hasValue())
return nullptr;
return getParent(Tree);
}
llvm::Optional<NewProjection> getProjection() const { return Proj; }
llvm::Optional<Projection> getProjection() const { return Proj; }
private:
void addNonProjectionUser(Operand *Op) {
@@ -834,42 +834,42 @@ private:
NonProjUsers.push_back(Op);
}
using ValueNodePair = std::pair<SILValue, NewProjectionTreeNode *>;
using ValueNodePair = std::pair<SILValue, ProjectionTreeNode *>;
void processUsersOfValue(NewProjectionTree &Tree,
void processUsersOfValue(ProjectionTree &Tree,
llvm::SmallVectorImpl<ValueNodePair> &Worklist,
SILValue Value);
void createNextLevelChildren(NewProjectionTree &Tree);
void createNextLevelChildren(ProjectionTree &Tree);
void createNextLevelChildrenForStruct(NewProjectionTree &Tree, StructDecl *SD);
void createNextLevelChildrenForStruct(ProjectionTree &Tree, StructDecl *SD);
void createNextLevelChildrenForTuple(NewProjectionTree &Tree, TupleType *TT);
void createNextLevelChildrenForTuple(ProjectionTree &Tree, TupleType *TT);
};
class NewProjectionTree {
friend class NewProjectionTreeNode;
class ProjectionTree {
friend class ProjectionTreeNode;
SILModule &Mod;
llvm::BumpPtrAllocator &Allocator;
// A common pattern is a 3 field struct.
llvm::SmallVector<NewProjectionTreeNode *, 4> NewProjectionTreeNodes;
llvm::SmallVector<ProjectionTreeNode *, 4> ProjectionTreeNodes;
llvm::SmallVector<unsigned, 3> LeafIndices;
using LeafValueMapTy = llvm::DenseMap<unsigned, SILValue>;
public:
/// Construct a projection tree from BaseTy.
NewProjectionTree(SILModule &Mod, llvm::BumpPtrAllocator &Allocator,
ProjectionTree(SILModule &Mod, llvm::BumpPtrAllocator &Allocator,
SILType BaseTy);
~NewProjectionTree();
NewProjectionTree(const NewProjectionTree &) = delete;
NewProjectionTree(NewProjectionTree &&) = default;
NewProjectionTree &operator=(const NewProjectionTree &) = delete;
NewProjectionTree &operator=(NewProjectionTree &&) = default;
~ProjectionTree();
ProjectionTree(const ProjectionTree &) = delete;
ProjectionTree(ProjectionTree &&) = default;
ProjectionTree &operator=(const ProjectionTree &) = delete;
ProjectionTree &operator=(ProjectionTree &&) = default;
/// Compute liveness and use information in this projection tree using Base.
/// All debug instructions (debug_value, debug_value_addr) are ignored.
@@ -882,39 +882,39 @@ public:
llvm::SmallVector<SILValue, 8> &LVs);
SILValue computeExplodedArgumentValueInner(SILBuilder &Builder,
SILLocation Loc,
NewProjectionTreeNode *Node,
ProjectionTreeNode *Node,
LeafValueMapTy &LeafValues);
/// Return the module associated with this tree.
SILModule &getModule() const { return Mod; }
llvm::ArrayRef<NewProjectionTreeNode *> getNewProjectionTreeNodes() {
return llvm::makeArrayRef(NewProjectionTreeNodes);
llvm::ArrayRef<ProjectionTreeNode *> getProjectionTreeNodes() {
return llvm::makeArrayRef(ProjectionTreeNodes);
}
/// Iterate over all values in the tree. The function should return false if
/// it wants the iteration to end and true if it wants to continue.
void visitNewProjectionTreeNodes(std::function<bool (NewProjectionTreeNode &)> F);
void visitProjectionTreeNodes(std::function<bool (ProjectionTreeNode &)> F);
NewProjectionTreeNode *getRoot() {
return getNode(NewProjectionTreeNode::RootIndex);
ProjectionTreeNode *getRoot() {
return getNode(ProjectionTreeNode::RootIndex);
}
const NewProjectionTreeNode *getRoot() const {
return getNode(NewProjectionTreeNode::RootIndex);
const ProjectionTreeNode *getRoot() const {
return getNode(ProjectionTreeNode::RootIndex);
}
NewProjectionTreeNode *getNode(unsigned i) {
return NewProjectionTreeNodes[i];
ProjectionTreeNode *getNode(unsigned i) {
return ProjectionTreeNodes[i];
}
const NewProjectionTreeNode *getNode(unsigned i) const {
return NewProjectionTreeNodes[i];
const ProjectionTreeNode *getNode(unsigned i) const {
return ProjectionTreeNodes[i];
}
bool isSingleton() const {
// If we only have one root node, there is no interesting explosion
// here. Exit early.
if (NewProjectionTreeNodes.size() == 1)
if (ProjectionTreeNodes.size() == 1)
return true;
// Now we know that we have multiple level node hierarchy. See if we have a
@@ -938,7 +938,7 @@ public:
void getLeafTypes(llvm::SmallVectorImpl<SILType> &OutArray) const {
for (unsigned LeafIndex : LeafIndices) {
const NewProjectionTreeNode *Node = getNode(LeafIndex);
const ProjectionTreeNode *Node = getNode(LeafIndex);
assert(Node->IsLive && "We are only interested in leafs that are live");
OutArray.push_back(Node->getType());
}
@@ -958,41 +958,41 @@ public:
private:
void createRoot(SILType BaseTy) {
assert(NewProjectionTreeNodes.empty() &&
"Should only create root when NewProjectionTreeNodes is empty");
auto *Node = new (Allocator) NewProjectionTreeNode(BaseTy);
NewProjectionTreeNodes.push_back(Node);
assert(ProjectionTreeNodes.empty() &&
"Should only create root when ProjectionTreeNodes is empty");
auto *Node = new (Allocator) ProjectionTreeNode(BaseTy);
ProjectionTreeNodes.push_back(Node);
}
NewProjectionTreeNode *createChild(NewProjectionTreeNode *Parent,
ProjectionTreeNode *createChild(ProjectionTreeNode *Parent,
SILType BaseTy,
const NewProjection &P) {
unsigned Index = NewProjectionTreeNodes.size();
auto *Node = new (Allocator) NewProjectionTreeNode(Parent, Index, BaseTy, P);
NewProjectionTreeNodes.push_back(Node);
return NewProjectionTreeNodes[Index];
const Projection &P) {
unsigned Index = ProjectionTreeNodes.size();
auto *Node = new (Allocator) ProjectionTreeNode(Parent, Index, BaseTy, P);
ProjectionTreeNodes.push_back(Node);
return ProjectionTreeNodes[Index];
}
NewProjectionTreeNode *
createChildForStruct(NewProjectionTreeNode *Parent, SILType Ty, ValueDecl *VD,
ProjectionTreeNode *
createChildForStruct(ProjectionTreeNode *Parent, SILType Ty, ValueDecl *VD,
unsigned Index) {
NewProjection P = NewProjection(NewProjectionKind::Struct, Index);
NewProjectionTreeNode *N = createChild(Parent, Ty, P);
Projection P = Projection(ProjectionKind::Struct, Index);
ProjectionTreeNode *N = createChild(Parent, Ty, P);
return N;
}
NewProjectionTreeNode *
createChildForClass(NewProjectionTreeNode *Parent, SILType Ty, ValueDecl *VD,
ProjectionTreeNode *
createChildForClass(ProjectionTreeNode *Parent, SILType Ty, ValueDecl *VD,
unsigned Index) {
NewProjection P = NewProjection(NewProjectionKind::Class, Index);
NewProjectionTreeNode *N = createChild(Parent, Ty, P);
Projection P = Projection(ProjectionKind::Class, Index);
ProjectionTreeNode *N = createChild(Parent, Ty, P);
return N;
}
NewProjectionTreeNode *
createChildForTuple(NewProjectionTreeNode *Parent, SILType Ty, unsigned Index) {
NewProjection P = NewProjection(NewProjectionKind::Tuple, Index);
NewProjectionTreeNode *N = createChild(Parent, Ty, P);
ProjectionTreeNode *
createChildForTuple(ProjectionTreeNode *Parent, SILType Ty, unsigned Index) {
Projection P = Projection(ProjectionKind::Tuple, Index);
ProjectionTreeNode *N = createChild(Parent, Ty, P);
return N;
}
};

View File

@@ -11,15 +11,15 @@
//===----------------------------------------------------------------------===//
///
/// This file defines SILValueProjection, a class containing a SILValue base
/// and a NewProjectionPath. It is used as the base class for LSLocation and
/// and a ProjectionPath. It is used as the base class for LSLocation and
/// LSValue.
///
/// In the case of LSLocation, the base represents the base of the allocated
/// objects and the NewProjectionPath tells which field in the object the
/// objects and the ProjectionPath tells which field in the object the
/// LSLocation represents.
///
/// In the case of LSValue, the base represents the root of loaded or stored
/// value it represents. And the NewProjectionPath represents the field in the
/// value it represents. And the ProjectionPath represents the field in the
/// loaded/store value the LSValue represents.
///
//===----------------------------------------------------------------------===//
@@ -61,14 +61,14 @@ protected:
/// Empty key, tombstone key or normal key.
KeyKind Kind;
/// The path to reach the accessed field of the object.
Optional<NewProjectionPath> Path;
Optional<ProjectionPath> Path;
public:
/// Constructors.
SILValueProjection() : Base(), Kind(Normal) {}
SILValueProjection(KeyKind Kind) : Base(), Kind(Kind) {}
SILValueProjection(SILValue B) : Base(B), Kind(Normal) {}
SILValueProjection(SILValue B, const Optional<NewProjectionPath> &P,
SILValueProjection(SILValue B, const Optional<ProjectionPath> &P,
KeyKind Kind = Normal)
: Base(B), Kind(Kind), Path(P) {}
@@ -93,7 +93,7 @@ public:
/// Getters for SILValueProjection.
KeyKind getKind() const { return Kind; }
SILValue getBase() const { return Base; }
const Optional<NewProjectionPath> &getPath() const { return Path; }
const Optional<ProjectionPath> &getPath() const { return Path; }
/// Reset the SILValueProjection, i.e. clear base and path.
void reset() {
@@ -106,21 +106,21 @@ public:
virtual bool isValid() const { return Base && Path.hasValue(); }
/// Returns true if the SILValueProjection has a non-empty projection path.
bool hasEmptyNewProjectionPath() const { return !Path.getValue().size(); }
bool hasEmptyProjectionPath() const { return !Path.getValue().size(); }
/// return true if that the two objects have the same base but access different
/// fields of the base object.
bool hasNonEmptySymmetricPathDifference(const SILValueProjection &RHS) const {
const NewProjectionPath &P = RHS.Path.getValue();
const ProjectionPath &P = RHS.Path.getValue();
return Path.getValue().hasNonEmptySymmetricDifference(P);
}
/// Subtract the given path from the NewProjectionPath.
void removePathPrefix(Optional<NewProjectionPath> &P) {
/// Subtract the given path from the ProjectionPath.
void removePathPrefix(Optional<ProjectionPath> &P) {
if (!P.hasValue())
return;
// Remove prefix does not modify the Path in-place.
Path = NewProjectionPath::removePrefix(Path.getValue(), P.getValue());
Path = ProjectionPath::removePrefix(Path.getValue(), P.getValue());
}
/// Return true if the RHS have identical projection paths.
@@ -174,13 +174,13 @@ public:
/// Create a path of AddrProjection or ValueProjection with the given VA
/// and Path.
static SILValue createExtract(SILValue VA,
const Optional<NewProjectionPath> &Path,
const Optional<ProjectionPath> &Path,
SILInstruction *Inst, bool IsValExt);
};
static inline llvm::hash_code hash_value(const SILValueProjection &S) {
const SILValue Base = S.getBase();
const Optional<NewProjectionPath> &Path = S.getPath();
const Optional<ProjectionPath> &Path = S.getPath();
llvm::hash_code HC = llvm::hash_combine(Base.getOpaqueValue());
if (!Path.hasValue())
return HC;
@@ -234,7 +234,7 @@ using ValueTableMap = llvm::SmallMapVector<unsigned, unsigned, 8>;
///
/// LSValue can take 2 forms.
///
/// 1. It can take a concrete value, i.e. with a valid Base and NewProjectionPath.
/// 1. It can take a concrete value, i.e. with a valid Base and ProjectionPath.
/// using the extract function, it can be materialized in IR.
///
/// 2. It can represent a covering set of LSValues from all predecessor
@@ -246,9 +246,9 @@ using ValueTableMap = llvm::SmallMapVector<unsigned, unsigned, 8>;
/// reduce will create the forwarding SILValue by merging them while
/// creating as few value extraction and aggregation as possible.
///
/// NOTE: NewProjectionPath in LSValue could be replaced by the
/// NewProjectionPath in the LSLocation, but that would require we break the
/// NewProjectionPath into 2 parts, 1 for the Base to the accessed (aggregate) node
/// NOTE: ProjectionPath in LSValue could be replaced by the
/// ProjectionPath in the LSLocation, but that would require we break the
/// ProjectionPath into 2 parts, 1 for the Base to the accessed (aggregate) node
/// and another 1 for the accessed (aggregate) node to the leaf node the
/// LSLocation represents.
///
@@ -263,7 +263,7 @@ class LSValue : public SILValueProjection {
public:
/// Constructors.
LSValue() : SILValueProjection(), IsCoveringValue(false) {}
LSValue(SILValue B, const NewProjectionPath &P)
LSValue(SILValue B, const ProjectionPath &P)
: SILValueProjection(B, P), IsCoveringValue(false) {
assert(isValid() && "Trying to create invalid LSValue");
}
@@ -344,7 +344,7 @@ public:
///
/// TODO: we do not really need the llvm::DenseMap<LSLocation, LSValue> here
/// we only need a map between the projection tree of a SILType and the value
/// each leaf node takes. This will be implemented once NewProjectionPath memory
/// each leaf node takes. This will be implemented once ProjectionPath memory
/// cost is reduced and made copyable (its copy constructor is deleted at the
/// moment).
static SILValue reduce(LSLocation &Base, SILModule *Mod,
@@ -404,20 +404,20 @@ class LSLocation : public SILValueProjection {
public:
/// Constructors.
LSLocation() {}
LSLocation(SILValue B, const Optional<NewProjectionPath> &P, KeyKind K = Normal)
LSLocation(SILValue B, const Optional<ProjectionPath> &P, KeyKind K = Normal)
: SILValueProjection(B, P, K) {}
LSLocation(KeyKind Kind) : SILValueProjection(Kind) {}
/// Use the concatenation of the 2 NewProjectionPaths as the Path.
LSLocation(SILValue B, const NewProjectionPath &BP, const NewProjectionPath &AP)
/// Use the concatenation of the 2 ProjectionPaths as the Path.
LSLocation(SILValue B, const ProjectionPath &BP, const ProjectionPath &AP)
: SILValueProjection(B) {
NewProjectionPath P((*Base).getType());
ProjectionPath P((*Base).getType());
P.append(BP);
P.append(AP);
Path = P;
}
/// Initialize a location with a new set of base, projectionpath and kind.
void init(SILValue B, const Optional<NewProjectionPath> &P, KeyKind K= Normal) {
void init(SILValue B, const Optional<ProjectionPath> &P, KeyKind K= Normal) {
Base = B;
Path = P;
Kind = K;

View File

@@ -26,7 +26,7 @@ enum class TEKind {
TENode // Intermediate and leaf nodes expansion.
};
using TypeExpansionMap = llvm::DenseMap<SILType, NewProjectionPathList>;
using TypeExpansionMap = llvm::DenseMap<SILType, ProjectionPathList>;
/// This analysis determines memory effects during destruction.
class TypeExpansionAnalysis : public SILAnalysis {
@@ -45,7 +45,7 @@ public:
}
/// Return ProjectionPath to every leaf or intermediate node of the given type.
const NewProjectionPathList &getTypeExpansion(SILType B, SILModule *Mod,
const ProjectionPathList &getTypeExpansion(SILType B, SILModule *Mod,
TEKind K);
};
}

View File

@@ -135,7 +135,7 @@ SILValue swift::stripClassCasts(SILValue V) {
SILValue swift::stripAddressProjections(SILValue V) {
while (true) {
V = stripSinglePredecessorArgs(V);
if (!NewProjection::isAddressProjection(V))
if (!Projection::isAddressProjection(V))
return V;
V = cast<SILInstruction>(V)->getOperand(0);
}
@@ -144,7 +144,7 @@ SILValue swift::stripAddressProjections(SILValue V) {
SILValue swift::stripUnaryAddressProjections(SILValue V) {
while (true) {
V = stripSinglePredecessorArgs(V);
if (!NewProjection::isAddressProjection(V))
if (!Projection::isAddressProjection(V))
return V;
auto *Inst = cast<SILInstruction>(V);
if (Inst->getNumOperands() > 1)
@@ -156,7 +156,7 @@ SILValue swift::stripUnaryAddressProjections(SILValue V) {
SILValue swift::stripValueProjections(SILValue V) {
while (true) {
V = stripSinglePredecessorArgs(V);
if (!NewProjection::isObjectProjection(V))
if (!Projection::isObjectProjection(V))
return V;
V = cast<SILInstruction>(V)->getOperand(0);
}

View File

@@ -29,7 +29,7 @@ using namespace swift;
/// These are just for performance and verification. If one needs to make
/// changes that cause the asserts the fire, please update them. The purpose is
/// to prevent these predicates from changing values by mistake.
static_assert(std::is_standard_layout<NewProjection>::value,
static_assert(std::is_standard_layout<Projection>::value,
"Expected projection to be a standard layout type");
@@ -51,10 +51,10 @@ bool swift::getIntegerIndex(SILValue IndexVal, unsigned &IndexConst) {
}
//===----------------------------------------------------------------------===//
// New Projection
// Projection
//===----------------------------------------------------------------------===//
NewProjection::NewProjection(SILInstruction *I) : Value() {
Projection::Projection(SILInstruction *I) : Value() {
if (!I)
return;
/// Initialize given the specific instruction type and verify with asserts
@@ -66,8 +66,8 @@ NewProjection::NewProjection(SILInstruction *I) : Value() {
return;
case ValueKind::StructElementAddrInst: {
auto *SEAI = cast<StructElementAddrInst>(I);
Value = ValueTy(NewProjectionKind::Struct, SEAI->getFieldNo());
assert(getKind() == NewProjectionKind::Struct);
Value = ValueTy(ProjectionKind::Struct, SEAI->getFieldNo());
assert(getKind() == ProjectionKind::Struct);
assert(getIndex() == SEAI->getFieldNo());
assert(getType(SEAI->getOperand()->getType(), SEAI->getModule()) ==
SEAI->getType());
@@ -75,8 +75,8 @@ NewProjection::NewProjection(SILInstruction *I) : Value() {
}
case ValueKind::StructExtractInst: {
auto *SEI = cast<StructExtractInst>(I);
Value = ValueTy(NewProjectionKind::Struct, SEI->getFieldNo());
assert(getKind() == NewProjectionKind::Struct);
Value = ValueTy(ProjectionKind::Struct, SEI->getFieldNo());
assert(getKind() == ProjectionKind::Struct);
assert(getIndex() == SEI->getFieldNo());
assert(getType(SEI->getOperand()->getType(), SEI->getModule()) ==
SEI->getType());
@@ -84,8 +84,8 @@ NewProjection::NewProjection(SILInstruction *I) : Value() {
}
case ValueKind::RefElementAddrInst: {
auto *REAI = cast<RefElementAddrInst>(I);
Value = ValueTy(NewProjectionKind::Class, REAI->getFieldNo());
assert(getKind() == NewProjectionKind::Class);
Value = ValueTy(ProjectionKind::Class, REAI->getFieldNo());
assert(getKind() == ProjectionKind::Class);
assert(getIndex() == REAI->getFieldNo());
assert(getType(REAI->getOperand()->getType(), REAI->getModule()) ==
REAI->getType());
@@ -93,8 +93,8 @@ NewProjection::NewProjection(SILInstruction *I) : Value() {
}
case ValueKind::ProjectBoxInst: {
auto *PBI = cast<ProjectBoxInst>(I);
Value = ValueTy(NewProjectionKind::Box, (unsigned)0);
assert(getKind() == NewProjectionKind::Box);
Value = ValueTy(ProjectionKind::Box, (unsigned)0);
assert(getKind() == ProjectionKind::Box);
assert(getIndex() == 0);
assert(getType(PBI->getOperand()->getType(), PBI->getModule()) ==
PBI->getType());
@@ -103,8 +103,8 @@ NewProjection::NewProjection(SILInstruction *I) : Value() {
}
case ValueKind::TupleExtractInst: {
auto *TEI = cast<TupleExtractInst>(I);
Value = ValueTy(NewProjectionKind::Tuple, TEI->getFieldNo());
assert(getKind() == NewProjectionKind::Tuple);
Value = ValueTy(ProjectionKind::Tuple, TEI->getFieldNo());
assert(getKind() == ProjectionKind::Tuple);
assert(getIndex() == TEI->getFieldNo());
assert(getType(TEI->getOperand()->getType(), TEI->getModule()) ==
TEI->getType());
@@ -112,8 +112,8 @@ NewProjection::NewProjection(SILInstruction *I) : Value() {
}
case ValueKind::TupleElementAddrInst: {
auto *TEAI = cast<TupleElementAddrInst>(I);
Value = ValueTy(NewProjectionKind::Tuple, TEAI->getFieldNo());
assert(getKind() == NewProjectionKind::Tuple);
Value = ValueTy(ProjectionKind::Tuple, TEAI->getFieldNo());
assert(getKind() == ProjectionKind::Tuple);
assert(getIndex() == TEAI->getFieldNo());
assert(getType(TEAI->getOperand()->getType(), TEAI->getModule()) ==
TEAI->getType());
@@ -121,8 +121,8 @@ NewProjection::NewProjection(SILInstruction *I) : Value() {
}
case ValueKind::UncheckedEnumDataInst: {
auto *UEDI = cast<UncheckedEnumDataInst>(I);
Value = ValueTy(NewProjectionKind::Enum, UEDI->getElementNo());
assert(getKind() == NewProjectionKind::Enum);
Value = ValueTy(ProjectionKind::Enum, UEDI->getElementNo());
assert(getKind() == ProjectionKind::Enum);
assert(getIndex() == UEDI->getElementNo());
assert(getType(UEDI->getOperand()->getType(), UEDI->getModule()) ==
UEDI->getType());
@@ -130,8 +130,8 @@ NewProjection::NewProjection(SILInstruction *I) : Value() {
}
case ValueKind::UncheckedTakeEnumDataAddrInst: {
auto *UTEDAI = cast<UncheckedTakeEnumDataAddrInst>(I);
Value = ValueTy(NewProjectionKind::Enum, UTEDAI->getElementNo());
assert(getKind() == NewProjectionKind::Enum);
Value = ValueTy(ProjectionKind::Enum, UTEDAI->getElementNo());
assert(getKind() == ProjectionKind::Enum);
assert(getIndex() == UTEDAI->getElementNo());
assert(getType(UTEDAI->getOperand()->getType(), UTEDAI->getModule()) ==
UTEDAI->getType());
@@ -148,8 +148,8 @@ NewProjection::NewProjection(SILInstruction *I) : Value() {
if (getIntegerIndex(IAI->getIndex(), NewIndex)) {
assert(NewIndex != unsigned(~0) && "NewIndex should have been changed "
"by getIntegerIndex?!");
Value = ValueTy(NewProjectionKind::Index, NewIndex);
assert(getKind() == NewProjectionKind::Index);
Value = ValueTy(ProjectionKind::Index, NewIndex);
assert(getKind() == ProjectionKind::Index);
assert(getIndex() == NewIndex);
}
break;
@@ -157,8 +157,8 @@ NewProjection::NewProjection(SILInstruction *I) : Value() {
case ValueKind::UpcastInst: {
auto *Ty = I->getType().getSwiftRValueType().getPointer();
assert(Ty->isCanonical());
Value = ValueTy(NewProjectionKind::Upcast, Ty);
assert(getKind() == NewProjectionKind::Upcast);
Value = ValueTy(ProjectionKind::Upcast, Ty);
assert(getKind() == ProjectionKind::Upcast);
assert(getType(I->getOperand(0)->getType(), I->getModule()) ==
I->getType());
break;
@@ -166,8 +166,8 @@ NewProjection::NewProjection(SILInstruction *I) : Value() {
case ValueKind::UncheckedRefCastInst: {
auto *Ty = I->getType().getSwiftRValueType().getPointer();
assert(Ty->isCanonical());
Value = ValueTy(NewProjectionKind::RefCast, Ty);
assert(getKind() == NewProjectionKind::RefCast);
Value = ValueTy(ProjectionKind::RefCast, Ty);
assert(getKind() == ProjectionKind::RefCast);
assert(getType(I->getOperand(0)->getType(), I->getModule()) ==
I->getType());
break;
@@ -176,8 +176,8 @@ NewProjection::NewProjection(SILInstruction *I) : Value() {
case ValueKind::UncheckedAddrCastInst: {
auto *Ty = I->getType().getSwiftRValueType().getPointer();
assert(Ty->isCanonical());
Value = ValueTy(NewProjectionKind::BitwiseCast, Ty);
assert(getKind() == NewProjectionKind::BitwiseCast);
Value = ValueTy(ProjectionKind::BitwiseCast, Ty);
assert(getKind() == ProjectionKind::BitwiseCast);
assert(getType(I->getOperand(0)->getType(), I->getModule()) ==
I->getType());
break;
@@ -186,7 +186,7 @@ NewProjection::NewProjection(SILInstruction *I) : Value() {
}
NullablePtr<SILInstruction>
NewProjection::createObjectProjection(SILBuilder &B, SILLocation Loc,
Projection::createObjectProjection(SILBuilder &B, SILLocation Loc,
SILValue Base) const {
SILType BaseTy = Base->getType();
@@ -198,29 +198,29 @@ NewProjection::createObjectProjection(SILBuilder &B, SILLocation Loc,
// of this projection match and that this projection can be represented as
// value. Create the instruction if we can. Otherwise, return nullptr.
switch (getKind()) {
case NewProjectionKind::Struct:
case ProjectionKind::Struct:
return B.createStructExtract(Loc, Base, getVarDecl(BaseTy));
case NewProjectionKind::Tuple:
case ProjectionKind::Tuple:
return B.createTupleExtract(Loc, Base, getIndex());
case NewProjectionKind::Index:
case ProjectionKind::Index:
return nullptr;
case NewProjectionKind::Enum:
case ProjectionKind::Enum:
return B.createUncheckedEnumData(Loc, Base, getEnumElementDecl(BaseTy));
case NewProjectionKind::Class:
case ProjectionKind::Class:
return nullptr;
case NewProjectionKind::Box:
case ProjectionKind::Box:
return nullptr;
case NewProjectionKind::Upcast:
case ProjectionKind::Upcast:
return B.createUpcast(Loc, Base, getCastType(BaseTy));
case NewProjectionKind::RefCast:
case ProjectionKind::RefCast:
return B.createUncheckedRefCast(Loc, Base, getCastType(BaseTy));
case NewProjectionKind::BitwiseCast:
case ProjectionKind::BitwiseCast:
return B.createUncheckedBitwiseCast(Loc, Base, getCastType(BaseTy));
}
}
NullablePtr<SILInstruction>
NewProjection::createAddressProjection(SILBuilder &B, SILLocation Loc,
Projection::createAddressProjection(SILBuilder &B, SILLocation Loc,
SILValue Base) const {
SILType BaseTy = Base->getType();
@@ -233,40 +233,40 @@ NewProjection::createAddressProjection(SILBuilder &B, SILLocation Loc,
// of this projection match and that this projection can be represented as
// value. Create the instruction if we can. Otherwise, return nullptr.
switch (getKind()) {
case NewProjectionKind::Struct:
case ProjectionKind::Struct:
return B.createStructElementAddr(Loc, Base, getVarDecl(BaseTy));
case NewProjectionKind::Tuple:
case ProjectionKind::Tuple:
return B.createTupleElementAddr(Loc, Base, getIndex());
case NewProjectionKind::Index: {
case ProjectionKind::Index: {
auto IntLiteralTy =
SILType::getBuiltinIntegerType(64, B.getModule().getASTContext());
auto IntLiteralIndex =
B.createIntegerLiteral(Loc, IntLiteralTy, getIndex());
return B.createIndexAddr(Loc, Base, IntLiteralIndex);
}
case NewProjectionKind::Enum:
case ProjectionKind::Enum:
return B.createUncheckedTakeEnumDataAddr(Loc, Base,
getEnumElementDecl(BaseTy));
case NewProjectionKind::Class:
case ProjectionKind::Class:
return B.createRefElementAddr(Loc, Base, getVarDecl(BaseTy));
case NewProjectionKind::Box:
case ProjectionKind::Box:
return B.createProjectBox(Loc, Base);
case NewProjectionKind::Upcast:
case ProjectionKind::Upcast:
return B.createUpcast(Loc, Base, getCastType(BaseTy));
case NewProjectionKind::RefCast:
case NewProjectionKind::BitwiseCast:
case ProjectionKind::RefCast:
case ProjectionKind::BitwiseCast:
return B.createUncheckedAddrCast(Loc, Base, getCastType(BaseTy));
}
}
void NewProjection::getFirstLevelProjections(
SILType Ty, SILModule &Mod, llvm::SmallVectorImpl<NewProjection> &Out) {
void Projection::getFirstLevelProjections(
SILType Ty, SILModule &Mod, llvm::SmallVectorImpl<Projection> &Out) {
if (auto *S = Ty.getStructOrBoundGenericStruct()) {
unsigned Count = 0;
for (auto *VDecl : S->getStoredProperties()) {
(void) VDecl;
NewProjection P(NewProjectionKind::Struct, Count++);
DEBUG(NewProjectionPath X(Ty);
Projection P(ProjectionKind::Struct, Count++);
DEBUG(ProjectionPath X(Ty);
assert(X.getMostDerivedType(Mod) == Ty);
X.append(P);
assert(X.getMostDerivedType(Mod) == Ty.getFieldType(VDecl, Mod));
@@ -278,8 +278,8 @@ void NewProjection::getFirstLevelProjections(
if (auto TT = Ty.getAs<TupleType>()) {
for (unsigned i = 0, e = TT->getNumElements(); i != e; ++i) {
NewProjection P(NewProjectionKind::Tuple, i);
DEBUG(NewProjectionPath X(Ty);
Projection P(ProjectionKind::Tuple, i);
DEBUG(ProjectionPath X(Ty);
assert(X.getMostDerivedType(Mod) == Ty);
X.append(P);
assert(X.getMostDerivedType(Mod) == Ty.getTupleElementType(i));
@@ -293,8 +293,8 @@ void NewProjection::getFirstLevelProjections(
unsigned Count = 0;
for (auto *VDecl : C->getStoredProperties()) {
(void) VDecl;
NewProjection P(NewProjectionKind::Class, Count++);
DEBUG(NewProjectionPath X(Ty);
Projection P(ProjectionKind::Class, Count++);
DEBUG(ProjectionPath X(Ty);
assert(X.getMostDerivedType(Mod) == Ty);
X.append(P);
assert(X.getMostDerivedType(Mod) == Ty.getFieldType(VDecl, Mod));
@@ -305,8 +305,8 @@ void NewProjection::getFirstLevelProjections(
}
if (auto Box = Ty.getAs<SILBoxType>()) {
NewProjection P(NewProjectionKind::Box, (unsigned)0);
DEBUG(NewProjectionPath X(Ty);
Projection P(ProjectionKind::Box, (unsigned)0);
DEBUG(ProjectionPath X(Ty);
assert(X.getMostDerivedType(Mod) == Ty);
X.append(P);
assert(X.getMostDerivedType(Mod) == SILType::getPrimitiveAddressType(
@@ -322,9 +322,9 @@ void NewProjection::getFirstLevelProjections(
// New Projection Path
//===----------------------------------------------------------------------===//
Optional<NewProjectionPath> NewProjectionPath::getProjectionPath(SILValue Start,
Optional<ProjectionPath> ProjectionPath::getProjectionPath(SILValue Start,
SILValue End) {
NewProjectionPath P(Start->getType(), End->getType());
ProjectionPath P(Start->getType(), End->getType());
// If Start == End, there is a "trivial" projection path in between the
// two. This is represented by returning an empty ProjectionPath.
@@ -339,7 +339,7 @@ Optional<NewProjectionPath> NewProjectionPath::getProjectionPath(SILValue Start,
auto Iter = End;
while (Start != Iter) {
NewProjection AP(Iter);
Projection AP(Iter);
if (!AP.isValid())
break;
P.Path.push_back(AP);
@@ -348,7 +348,7 @@ Optional<NewProjectionPath> NewProjectionPath::getProjectionPath(SILValue Start,
// Return None if we have an empty projection list or if Start == Iter.
// We do not worry about th implicit #0 in case of index_addr, as the
// NewProjectionPath never allow paths to be compared as a list of indices.
// ProjectionPath never allow paths to be compared as a list of indices.
// Only the encoded type+index pair will be compared.
if (P.empty() || Start != Iter)
return llvm::NoneType::None;
@@ -364,8 +364,8 @@ Optional<NewProjectionPath> NewProjectionPath::getProjectionPath(SILValue Start,
///
/// This means that the two objects have the same base but access different
/// fields of the base object.
bool NewProjectionPath::hasNonEmptySymmetricDifference(
const NewProjectionPath &RHS) const {
bool ProjectionPath::hasNonEmptySymmetricDifference(
const ProjectionPath &RHS) const {
// First make sure that both of our base types are the same.
if (BaseType != RHS.BaseType)
return false;
@@ -389,8 +389,8 @@ bool NewProjectionPath::hasNonEmptySymmetricDifference(
unsigned i = 0;
for (unsigned e = std::min(size(), RHS.size()); i != e; ++i) {
// Grab the current projections.
const NewProjection &LHSProj = *LHSIter;
const NewProjection &RHSProj = *RHSIter;
const Projection &LHSProj = *LHSIter;
const Projection &RHSProj = *RHSIter;
// If we are accessing different fields of a common object, the two
// projection paths may have a non-empty symmetric difference. We check if
@@ -433,7 +433,7 @@ bool NewProjectionPath::hasNonEmptySymmetricDifference(
/// TODO: Integrate has empty non-symmetric difference into here.
SubSeqRelation_t
NewProjectionPath::computeSubSeqRelation(const NewProjectionPath &RHS) const {
ProjectionPath::computeSubSeqRelation(const ProjectionPath &RHS) const {
// Make sure that both base types are the same. Otherwise, we can not compare
// the projections as sequences.
if (BaseType != RHS.BaseType)
@@ -451,8 +451,8 @@ NewProjectionPath::computeSubSeqRelation(const NewProjectionPath &RHS) const {
// For each index i until min path size...
for (unsigned i = 0; i != MinPathSize; ++i) {
// Grab the current projections.
const NewProjection &LHSProj = *LHSIter;
const NewProjection &RHSProj = *RHSIter;
const Projection &LHSProj = *LHSIter;
const Projection &RHSProj = *RHSIter;
// If the two projections do not equal exactly, return Unrelated.
//
@@ -489,7 +489,7 @@ NewProjectionPath::computeSubSeqRelation(const NewProjectionPath &RHS) const {
return SubSeqRelation_t::RHSStrictSubSeqOfLHS;
}
bool NewProjectionPath::findMatchingObjectProjectionPaths(
bool ProjectionPath::findMatchingObjectProjectionPaths(
SILInstruction *I, SmallVectorImpl<SILInstruction *> &T) const {
// We only support unary instructions.
if (I->getNumOperands() != 1)
@@ -543,9 +543,9 @@ bool NewProjectionPath::findMatchingObjectProjectionPaths(
return true;
}
Optional<NewProjectionPath>
NewProjectionPath::removePrefix(const NewProjectionPath &Path,
const NewProjectionPath &Prefix) {
Optional<ProjectionPath>
ProjectionPath::removePrefix(const ProjectionPath &Path,
const ProjectionPath &Prefix) {
// We can only subtract paths that have the same base.
if (Path.BaseType != Prefix.BaseType)
return llvm::NoneType::None;
@@ -559,7 +559,7 @@ NewProjectionPath::removePrefix(const NewProjectionPath &Path,
return llvm::NoneType::None;
// First make sure that the prefix matches.
Optional<NewProjectionPath> P = NewProjectionPath(Path.BaseType);
Optional<ProjectionPath> P = ProjectionPath(Path.BaseType);
for (unsigned i = 0; i < PrefixSize; i++) {
if (Path.Path[i] != Prefix.Path[i]) {
P.reset();
@@ -575,7 +575,7 @@ NewProjectionPath::removePrefix(const NewProjectionPath &Path,
return P;
}
SILValue NewProjectionPath::createObjectProjections(SILBuilder &B,
SILValue ProjectionPath::createObjectProjections(SILBuilder &B,
SILLocation Loc,
SILValue Base) {
assert(BaseType.isAddress());
@@ -588,7 +588,7 @@ SILValue NewProjectionPath::createObjectProjections(SILBuilder &B,
return Val;
}
raw_ostream &NewProjectionPath::print(raw_ostream &os, SILModule &M) {
raw_ostream &ProjectionPath::print(raw_ostream &os, SILModule &M) {
// Match how the memlocation print tests expect us to print projection paths.
//
// TODO: It sort of sucks having to print these bottom up computationally. We
@@ -608,7 +608,7 @@ raw_ostream &NewProjectionPath::print(raw_ostream &os, SILModule &M) {
continue;
}
if (IterProj.getKind() == NewProjectionKind::Tuple) {
if (IterProj.getKind() == ProjectionKind::Tuple) {
IterType = IterProj.getType(IterType, M);
os << IterType.getAddressType() << "\n";
os << "Index: ";
@@ -616,7 +616,7 @@ raw_ostream &NewProjectionPath::print(raw_ostream &os, SILModule &M) {
continue;
}
if (IterProj.getKind() == NewProjectionKind::Box) {
if (IterProj.getKind() == ProjectionKind::Box) {
os << "Box: ";
continue;
}
@@ -629,7 +629,7 @@ raw_ostream &NewProjectionPath::print(raw_ostream &os, SILModule &M) {
os << "(Projection Path [";
SILType NextType = BaseType;
os << NextType;
for (const NewProjection &P : Path) {
for (const Projection &P : Path) {
os << ", ";
NextType = P.getType(NextType, M);
os << NextType;
@@ -639,7 +639,7 @@ raw_ostream &NewProjectionPath::print(raw_ostream &os, SILModule &M) {
return os;
}
raw_ostream &NewProjectionPath::printProjections(raw_ostream &os, SILModule &M) const {
raw_ostream &ProjectionPath::printProjections(raw_ostream &os, SILModule &M) const {
// Match how the memlocation print tests expect us to print projection paths.
//
// TODO: It sort of sucks having to print these bottom up computationally. We
@@ -652,7 +652,7 @@ raw_ostream &NewProjectionPath::printProjections(raw_ostream &os, SILModule &M)
continue;
}
if (IterProj.getKind() == NewProjectionKind::Tuple) {
if (IterProj.getKind() == ProjectionKind::Tuple) {
os << "Index: " << IterProj.getIndex() << "\n";
continue;
}
@@ -663,16 +663,16 @@ raw_ostream &NewProjectionPath::printProjections(raw_ostream &os, SILModule &M)
return os;
}
void NewProjectionPath::dump(SILModule &M) {
void ProjectionPath::dump(SILModule &M) {
print(llvm::outs(), M);
llvm::outs() << "\n";
}
void NewProjectionPath::dumpProjections(SILModule &M) const {
void ProjectionPath::dumpProjections(SILModule &M) const {
printProjections(llvm::outs(), M);
}
void NewProjectionPath::verify(SILModule &M) {
void ProjectionPath::verify(SILModule &M) {
#ifndef NDEBUG
SILType IterTy = getBaseType();
assert(IterTy);
@@ -684,19 +684,19 @@ void NewProjectionPath::verify(SILModule &M) {
}
void
NewProjectionPath::expandTypeIntoLeafProjectionPaths(SILType B, SILModule *Mod,
NewProjectionPathList &Paths) {
ProjectionPath::expandTypeIntoLeafProjectionPaths(SILType B, SILModule *Mod,
ProjectionPathList &Paths) {
// Perform a BFS to expand the given type into projectionpath each of
// which contains 1 field from the type.
llvm::SmallVector<NewProjectionPath, 8> Worklist;
llvm::SmallVector<NewProjection, 8> Projections;
llvm::SmallVector<ProjectionPath, 8> Worklist;
llvm::SmallVector<Projection, 8> Projections;
// Push an empty projection path to get started.
NewProjectionPath P(B);
ProjectionPath P(B);
Worklist.push_back(P);
do {
// Get the next level projections based on current projection's type.
NewProjectionPath PP = Worklist.pop_back_val();
ProjectionPath PP = Worklist.pop_back_val();
// Get the current type to process.
SILType Ty = PP.getMostDerivedType(*Mod);
@@ -704,7 +704,7 @@ NewProjectionPath::expandTypeIntoLeafProjectionPaths(SILType B, SILModule *Mod,
// Get the first level projection of the current type.
Projections.clear();
NewProjection::getFirstLevelProjections(Ty, *Mod, Projections);
Projection::getFirstLevelProjections(Ty, *Mod, Projections);
// Reached the end of the projection tree, this field can not be expanded
// anymore.
@@ -739,7 +739,7 @@ NewProjectionPath::expandTypeIntoLeafProjectionPaths(SILType B, SILModule *Mod,
// Keep expanding the location.
for (auto &P : Projections) {
NewProjectionPath X(B);
ProjectionPath X(B);
X.append(PP);
///assert(PP.getMostDerivedType(*Mod) == X.getMostDerivedType(*Mod));
X.append(P);
@@ -750,19 +750,19 @@ NewProjectionPath::expandTypeIntoLeafProjectionPaths(SILType B, SILModule *Mod,
}
void
NewProjectionPath::expandTypeIntoNodeProjectionPaths(SILType B, SILModule *Mod,
NewProjectionPathList &Paths) {
ProjectionPath::expandTypeIntoNodeProjectionPaths(SILType B, SILModule *Mod,
ProjectionPathList &Paths) {
// Perform a BFS to expand the given type into projectionpath each of
// which contains 1 field from the type.
llvm::SmallVector<NewProjectionPath, 8> Worklist;
llvm::SmallVector<NewProjection, 8> Projections;
llvm::SmallVector<ProjectionPath, 8> Worklist;
llvm::SmallVector<Projection, 8> Projections;
// Push an empty projection path to get started.
NewProjectionPath P(B);
ProjectionPath P(B);
Worklist.push_back(P);
do {
// Get the next level projections based on current projection's type.
NewProjectionPath PP = Worklist.pop_back_val();
ProjectionPath PP = Worklist.pop_back_val();
// Get the current type to process.
SILType Ty = PP.getMostDerivedType(*Mod);
@@ -770,7 +770,7 @@ NewProjectionPath::expandTypeIntoNodeProjectionPaths(SILType B, SILModule *Mod,
// Get the first level projection of the current type.
Projections.clear();
NewProjection::getFirstLevelProjections(Ty, *Mod, Projections);
Projection::getFirstLevelProjections(Ty, *Mod, Projections);
// Reached the end of the projection tree, this field can not be expanded
// anymore.
@@ -809,7 +809,7 @@ NewProjectionPath::expandTypeIntoNodeProjectionPaths(SILType B, SILModule *Mod,
// Keep expanding the location.
for (auto &P : Projections) {
NewProjectionPath X(B);
ProjectionPath X(B);
X.append(PP);
assert(PP.getMostDerivedType(*Mod) == X.getMostDerivedType(*Mod));
X.append(P);
@@ -821,7 +821,7 @@ NewProjectionPath::expandTypeIntoNodeProjectionPaths(SILType B, SILModule *Mod,
}
bool
NewProjection::operator<(const NewProjection &Other) const {
Projection::operator<(const Projection &Other) const {
// If we have a nominal kind...
if (isNominalKind()) {
// And Other is also nominal...
@@ -845,7 +845,7 @@ NewProjection::operator<(const NewProjection &Other) const {
}
NullablePtr<SILInstruction>
NewProjection::
Projection::
createAggFromFirstLevelProjections(SILBuilder &B, SILLocation Loc,
SILType BaseType,
llvm::SmallVectorImpl<SILValue> &Values) {
@@ -860,19 +860,19 @@ createAggFromFirstLevelProjections(SILBuilder &B, SILLocation Loc,
return nullptr;
}
SILValue NewProjection::getOperandForAggregate(SILInstruction *I) const {
SILValue Projection::getOperandForAggregate(SILInstruction *I) const {
switch (getKind()) {
case NewProjectionKind::Struct:
case ProjectionKind::Struct:
if (isa<StructInst>(I))
return I->getOperand(getIndex());
break;
case NewProjectionKind::Tuple:
case ProjectionKind::Tuple:
if (isa<TupleInst>(I))
return I->getOperand(getIndex());
break;
case NewProjectionKind::Index:
case ProjectionKind::Index:
break;
case NewProjectionKind::Enum:
case ProjectionKind::Enum:
if (EnumInst *EI = dyn_cast<EnumInst>(I)) {
if (EI->getElement() == getEnumElementDecl(I->getType())) {
assert(EI->hasOperand() && "expected data operand");
@@ -880,11 +880,11 @@ SILValue NewProjection::getOperandForAggregate(SILInstruction *I) const {
}
}
break;
case NewProjectionKind::Class:
case NewProjectionKind::Box:
case NewProjectionKind::Upcast:
case NewProjectionKind::RefCast:
case NewProjectionKind::BitwiseCast:
case ProjectionKind::Class:
case ProjectionKind::Box:
case ProjectionKind::Upcast:
case ProjectionKind::RefCast:
case ProjectionKind::BitwiseCast:
// There is no SIL instruction to create a class or box by aggregating
// values.
break;
@@ -893,14 +893,14 @@ SILValue NewProjection::getOperandForAggregate(SILInstruction *I) const {
}
//===----------------------------------------------------------------------===//
// NewProjectionTreeNode
// ProjectionTreeNode
//===----------------------------------------------------------------------===//
NewProjectionTreeNode *
NewProjectionTreeNode::getChildForProjection(NewProjectionTree &Tree,
const NewProjection &P) {
ProjectionTreeNode *
ProjectionTreeNode::getChildForProjection(ProjectionTree &Tree,
const Projection &P) {
for (unsigned Index : ChildProjections) {
NewProjectionTreeNode *N = Tree.getNode(Index);
ProjectionTreeNode *N = Tree.getNode(Index);
if (N->Proj && N->Proj.getValue() == P) {
return N;
}
@@ -909,22 +909,22 @@ NewProjectionTreeNode::getChildForProjection(NewProjectionTree &Tree,
return nullptr;
}
NewProjectionTreeNode *
NewProjectionTreeNode::getParent(NewProjectionTree &Tree) {
ProjectionTreeNode *
ProjectionTreeNode::getParent(ProjectionTree &Tree) {
if (!Parent)
return nullptr;
return Tree.getNode(Parent.getValue());
}
const NewProjectionTreeNode *
NewProjectionTreeNode::getParent(const NewProjectionTree &Tree) const {
const ProjectionTreeNode *
ProjectionTreeNode::getParent(const ProjectionTree &Tree) const {
if (!Parent)
return nullptr;
return Tree.getNode(Parent.getValue());
}
NullablePtr<SILInstruction>
NewProjectionTreeNode::
ProjectionTreeNode::
createProjection(SILBuilder &B, SILLocation Loc, SILValue Arg) const {
if (!Proj)
return nullptr;
@@ -934,8 +934,8 @@ createProjection(SILBuilder &B, SILLocation Loc, SILValue Arg) const {
void
NewProjectionTreeNode::
processUsersOfValue(NewProjectionTree &Tree,
ProjectionTreeNode::
processUsersOfValue(ProjectionTree &Tree,
llvm::SmallVectorImpl<ValueNodePair> &Worklist,
SILValue Value) {
DEBUG(llvm::dbgs() << " Looking at Users:\n");
@@ -948,7 +948,7 @@ processUsersOfValue(NewProjectionTree &Tree,
DEBUG(llvm::dbgs() << " " << *User);
// First try to create a Projection for User.
auto P = NewProjection::NewProjection(User);
auto P = Projection::Projection(User);
// If we fail to create a projection, add User as a user to this node and
// continue.
@@ -991,8 +991,8 @@ processUsersOfValue(NewProjectionTree &Tree,
}
void
NewProjectionTreeNode::
createNextLevelChildrenForStruct(NewProjectionTree &Tree, StructDecl *SD) {
ProjectionTreeNode::
createNextLevelChildrenForStruct(ProjectionTree &Tree, StructDecl *SD) {
SILModule &Mod = Tree.getModule();
unsigned ChildIndex = 0;
SILType Ty = getType();
@@ -1011,8 +1011,8 @@ createNextLevelChildrenForStruct(NewProjectionTree &Tree, StructDecl *SD) {
}
void
NewProjectionTreeNode::
createNextLevelChildrenForTuple(NewProjectionTree &Tree, TupleType *TT) {
ProjectionTreeNode::
createNextLevelChildrenForTuple(ProjectionTree &Tree, TupleType *TT) {
SILType Ty = getType();
for (unsigned i = 0, e = TT->getNumElements(); i != e; ++i) {
assert(Tree.getNode(Index) == this && "Node is not mapped to itself?");
@@ -1029,8 +1029,8 @@ createNextLevelChildrenForTuple(NewProjectionTree &Tree, TupleType *TT) {
}
void
NewProjectionTreeNode::
createNextLevelChildren(NewProjectionTree &Tree) {
ProjectionTreeNode::
createNextLevelChildren(ProjectionTree &Tree) {
DEBUG(llvm::dbgs() << " Creating children for: " << getType() << "\n");
if (Initialized) {
DEBUG(llvm::dbgs() << " Already initialized! bailing!\n");
@@ -1064,7 +1064,7 @@ createNextLevelChildren(NewProjectionTree &Tree) {
}
SILInstruction *
NewProjectionTreeNode::
ProjectionTreeNode::
createAggregate(SILBuilder &B, SILLocation Loc, ArrayRef<SILValue> Args) const {
assert(Initialized && "Node must be initialized to create aggregates");
@@ -1081,8 +1081,8 @@ createAggregate(SILBuilder &B, SILLocation Loc, ArrayRef<SILValue> Args) const {
llvm_unreachable("Unhandled type");
}
class NewProjectionTreeNode::NewAggregateBuilder {
NewProjectionTreeNode *Node;
class ProjectionTreeNode::NewAggregateBuilder {
ProjectionTreeNode *Node;
SILBuilder &Builder;
SILLocation Loc;
llvm::SmallVector<SILValue, 8> Values;
@@ -1091,7 +1091,7 @@ class NewProjectionTreeNode::NewAggregateBuilder {
bool Invalidated;
public:
NewAggregateBuilder(NewProjectionTreeNode *N, SILBuilder &B, SILLocation L)
NewAggregateBuilder(ProjectionTreeNode *N, SILBuilder &B, SILLocation L)
: Node(N), Builder(B), Loc(L), Values(), Invalidated(false) {
assert(N->Initialized && "N must be initialized since we are mapping Node "
"Children -> SILValues");
@@ -1120,7 +1120,7 @@ public:
return Node->createAggregate(Builder, Loc, Values);
}
void setValueForChild(NewProjectionTreeNode *Child, SILValue V) {
void setValueForChild(ProjectionTreeNode *Child, SILValue V) {
assert(!Invalidated && "Must not be invalidated to set value for child");
Values[Child->Proj.getValue().getIndex()] = V;
}
@@ -1128,7 +1128,7 @@ public:
namespace {
using NewAggregateBuilder = NewProjectionTreeNode::NewAggregateBuilder;
using NewAggregateBuilder = ProjectionTreeNode::NewAggregateBuilder;
/// A wrapper around a MapVector with generalized operations on the map.
///
@@ -1138,7 +1138,7 @@ using NewAggregateBuilder = NewProjectionTreeNode::NewAggregateBuilder;
class NewAggregateBuilderMap {
SILBuilder &Builder;
SILLocation Loc;
llvm::MapVector<NewProjectionTreeNode *, NewAggregateBuilder> NodeBuilderMap;
llvm::MapVector<ProjectionTreeNode *, NewAggregateBuilder> NodeBuilderMap;
public:
@@ -1147,7 +1147,7 @@ public:
/// Get the NewAggregateBuilder associated with Node or if none is created,
/// create one for Node.
NewAggregateBuilder &getBuilder(NewProjectionTreeNode *Node) {
NewAggregateBuilder &getBuilder(ProjectionTreeNode *Node) {
auto I = NodeBuilderMap.find(Node);
if (I != NodeBuilderMap.end()) {
return I->second;
@@ -1159,33 +1159,33 @@ public:
}
/// Get the NewAggregateBuilder associated with Node. Assert on failure.
NewAggregateBuilder &get(NewProjectionTreeNode *Node) {
NewAggregateBuilder &get(ProjectionTreeNode *Node) {
auto It = NodeBuilderMap.find(Node);
assert(It != NodeBuilderMap.end() && "Every item in the worklist should have "
"an NewAggregateBuilder associated with it");
return It->second;
}
bool isComplete(NewProjectionTreeNode *Node) {
bool isComplete(ProjectionTreeNode *Node) {
return get(Node).isComplete();
}
bool isInvalidated(NewProjectionTreeNode *Node) {
bool isInvalidated(ProjectionTreeNode *Node) {
return get(Node).isInvalidated();
}
NewProjectionTreeNode *
getNextValidNode(llvm::SmallVectorImpl<NewProjectionTreeNode *> &Worklist,
ProjectionTreeNode *
getNextValidNode(llvm::SmallVectorImpl<ProjectionTreeNode *> &Worklist,
bool CheckForDeadLock=false);
};
} // end anonymous namespace
//===----------------------------------------------------------------------===//
// NewProjectionTree
// ProjectionTree
//===----------------------------------------------------------------------===//
NewProjectionTree::NewProjectionTree(SILModule &Mod, llvm::BumpPtrAllocator &BPA,
ProjectionTree::ProjectionTree(SILModule &Mod, llvm::BumpPtrAllocator &BPA,
SILType BaseTy) : Mod(Mod), Allocator(BPA) {
DEBUG(llvm::dbgs() << "Constructing Projection Tree For : " << BaseTy);
@@ -1195,15 +1195,15 @@ NewProjectionTree::NewProjectionTree(SILModule &Mod, llvm::BumpPtrAllocator &BPA
// Create the rest of the type tree lazily based on uses.
}
NewProjectionTree::~NewProjectionTree() {
for (auto *N : NewProjectionTreeNodes)
N->~NewProjectionTreeNode();
ProjectionTree::~ProjectionTree() {
for (auto *N : ProjectionTreeNodes)
N->~ProjectionTreeNode();
}
SILValue
NewProjectionTree::computeExplodedArgumentValueInner(SILBuilder &Builder,
ProjectionTree::computeExplodedArgumentValueInner(SILBuilder &Builder,
SILLocation Loc,
NewProjectionTreeNode *Node,
ProjectionTreeNode *Node,
LeafValueMapTy &LeafValues) {
// Use the child node value if the child is alive.
if (Node->ChildProjections.empty()) {
@@ -1221,14 +1221,14 @@ NewProjectionTree::computeExplodedArgumentValueInner(SILBuilder &Builder,
// recursion should be fine.
llvm::SmallVector<SILValue, 8> ChildValues;
for (unsigned ChildIdx : Node->ChildProjections) {
NewProjectionTreeNode *Child = getNode(ChildIdx);
ProjectionTreeNode *Child = getNode(ChildIdx);
ChildValues.push_back(computeExplodedArgumentValueInner(Builder, Loc, Child,
LeafValues));
}
// Form and return the aggregate.
NullablePtr<swift::SILInstruction> AI =
NewProjection::createAggFromFirstLevelProjections(Builder, Loc,
Projection::createAggFromFirstLevelProjections(Builder, Loc,
Node->getType(),
ChildValues);
@@ -1237,7 +1237,7 @@ NewProjectionTree::computeExplodedArgumentValueInner(SILBuilder &Builder,
}
SILValue
NewProjectionTree::computeExplodedArgumentValue(SILBuilder &Builder,
ProjectionTree::computeExplodedArgumentValue(SILBuilder &Builder,
SILLocation Loc,
llvm::SmallVector<SILValue, 8> &LeafValues) {
// Construct the leaf index to leaf value map.
@@ -1252,9 +1252,9 @@ NewProjectionTree::computeExplodedArgumentValue(SILBuilder &Builder,
}
void
NewProjectionTree::computeUsesAndLiveness(SILValue Base) {
ProjectionTree::computeUsesAndLiveness(SILValue Base) {
// Propagate liveness and users through the tree.
llvm::SmallVector<NewProjectionTreeNode::ValueNodePair, 32> UseWorklist;
llvm::SmallVector<ProjectionTreeNode::ValueNodePair, 32> UseWorklist;
UseWorklist.push_back({Base, getRoot()});
// Then until the worklist is empty...
@@ -1270,7 +1270,7 @@ NewProjectionTree::computeUsesAndLiveness(SILValue Base) {
});
SILValue Value;
NewProjectionTreeNode *Node;
ProjectionTreeNode *Node;
// Pop off the top type, value, and node.
std::tie(Value, Node) = UseWorklist.pop_back_val();
@@ -1289,7 +1289,7 @@ NewProjectionTree::computeUsesAndLiveness(SILValue Base) {
if (Node->IsLive) {
DEBUG(llvm::dbgs() << "Node Is Live. Marking Children Live!\n");
for (unsigned ChildIdx : Node->ChildProjections) {
NewProjectionTreeNode *Child = getNode(ChildIdx);
ProjectionTreeNode *Child = getNode(ChildIdx);
Child->IsLive = true;
DEBUG(llvm::dbgs() << " Marking child live: " << Child->getType() << "\n");
UseWorklist.push_back({SILValue(), Child});
@@ -1300,10 +1300,10 @@ NewProjectionTree::computeUsesAndLiveness(SILValue Base) {
// Then setup the leaf list by iterating through our Nodes looking for live
// leafs. We use a DFS order, always processing the left leafs first so that
// we match the order in which we will lay out arguments.
llvm::SmallVector<NewProjectionTreeNode *, 8> Worklist;
llvm::SmallVector<ProjectionTreeNode *, 8> Worklist;
Worklist.push_back(getRoot());
while (!Worklist.empty()) {
NewProjectionTreeNode *Node = Worklist.pop_back_val();
ProjectionTreeNode *Node = Worklist.pop_back_val();
// If node is not a leaf, add its children to the worklist and continue.
if (!Node->ChildProjections.empty()) {
@@ -1332,13 +1332,13 @@ NewProjectionTree::computeUsesAndLiveness(SILValue Base) {
}
void
NewProjectionTree::
ProjectionTree::
createTreeFromValue(SILBuilder &B, SILLocation Loc, SILValue NewBase,
llvm::SmallVectorImpl<SILValue> &Leafs) const {
DEBUG(llvm::dbgs() << "Recreating tree from value: " << NewBase);
using WorklistEntry =
std::tuple<const NewProjectionTreeNode *, SILValue>;
std::tuple<const ProjectionTreeNode *, SILValue>;
llvm::SmallVector<WorklistEntry, 32> Worklist;
// Start our worklist with NewBase and Root.
@@ -1347,7 +1347,7 @@ createTreeFromValue(SILBuilder &B, SILLocation Loc, SILValue NewBase,
// Then until our worklist is clear...
while (Worklist.size()) {
// Pop off the top of the list.
const NewProjectionTreeNode *Node = std::get<0>(Worklist.back());
const ProjectionTreeNode *Node = std::get<0>(Worklist.back());
SILValue V = std::get<1>(Worklist.back());
Worklist.pop_back();
@@ -1361,7 +1361,7 @@ createTreeFromValue(SILBuilder &B, SILLocation Loc, SILValue NewBase,
// Create projections for each one of them and the child node and
// projection to the worklist for processing.
for (unsigned ChildIdx : reversed(Node->ChildProjections)) {
const NewProjectionTreeNode *ChildNode = getNode(ChildIdx);
const ProjectionTreeNode *ChildNode = getNode(ChildIdx);
SILInstruction *I = ChildNode->createProjection(B, Loc, V).get();
DEBUG(llvm::dbgs() << " Adding Child: " << I->getType() << ": " << *I);
Worklist.push_back(std::make_tuple(ChildNode, SILValue(I)));
@@ -1379,14 +1379,14 @@ createTreeFromValue(SILBuilder &B, SILLocation Loc, SILValue NewBase,
}
}
NewProjectionTreeNode *
ProjectionTreeNode *
NewAggregateBuilderMap::
getNextValidNode(llvm::SmallVectorImpl<NewProjectionTreeNode *> &Worklist,
getNextValidNode(llvm::SmallVectorImpl<ProjectionTreeNode *> &Worklist,
bool CheckForDeadLock) {
if (Worklist.empty())
return nullptr;
NewProjectionTreeNode *Node = Worklist.back();
ProjectionTreeNode *Node = Worklist.back();
// If the Node is not complete, then we have reached a dead lock. This should never happen.
//
@@ -1413,21 +1413,21 @@ getNextValidNode(llvm::SmallVectorImpl<NewProjectionTreeNode *> &Worklist,
}
void
NewProjectionTree::
ProjectionTree::
replaceValueUsesWithLeafUses(SILBuilder &Builder, SILLocation Loc,
llvm::SmallVectorImpl<SILValue> &Leafs) {
assert(Leafs.size() == LeafIndices.size() && "Leafs and leaf indices must "
"equal in size.");
NewAggregateBuilderMap AggBuilderMap(Builder, Loc);
llvm::SmallVector<NewProjectionTreeNode *, 8> Worklist;
llvm::SmallVector<ProjectionTreeNode *, 8> Worklist;
DEBUG(llvm::dbgs() << "Replacing all uses in callee with leafs!\n");
// For each Leaf we have as input...
for (unsigned i = 0, e = Leafs.size(); i != e; ++i) {
SILValue Leaf = Leafs[i];
NewProjectionTreeNode *Node = getNode(LeafIndices[i]);
ProjectionTreeNode *Node = getNode(LeafIndices[i]);
DEBUG(llvm::dbgs() << " Visiting leaf: " << Leaf);
@@ -1442,7 +1442,7 @@ replaceValueUsesWithLeafUses(SILBuilder &Builder, SILLocation Loc,
}
// Grab the parent of this node.
NewProjectionTreeNode *Parent = Node->getParent(*this);
ProjectionTreeNode *Parent = Node->getParent(*this);
DEBUG(llvm::dbgs() << " Visiting parent of leaf: " <<
Parent->getType() << "\n");
@@ -1469,7 +1469,7 @@ replaceValueUsesWithLeafUses(SILBuilder &Builder, SILLocation Loc,
// A utility array to add new Nodes to the list so we maintain while
// processing the current worklist we maintain only completed items at the end
// of the list.
llvm::SmallVector<NewProjectionTreeNode *, 8> NewNodes;
llvm::SmallVector<ProjectionTreeNode *, 8> NewNodes;
DEBUG(llvm::dbgs() << "Processing worklist!\n");
@@ -1480,8 +1480,8 @@ replaceValueUsesWithLeafUses(SILBuilder &Builder, SILLocation Loc,
// TODO: Just change this into a partition method. Should be significantly
// faster.
std::sort(Worklist.begin(), Worklist.end(),
[&AggBuilderMap](NewProjectionTreeNode *N1,
NewProjectionTreeNode *N2) -> bool {
[&AggBuilderMap](ProjectionTreeNode *N1,
ProjectionTreeNode *N2) -> bool {
bool IsComplete1 = AggBuilderMap.isComplete(N1);
bool IsComplete2 = AggBuilderMap.isComplete(N2);
@@ -1503,7 +1503,7 @@ replaceValueUsesWithLeafUses(SILBuilder &Builder, SILLocation Loc,
// Find the first non invalidated node. If we have all invalidated nodes,
// this will return nullptr.
NewProjectionTreeNode *Node = AggBuilderMap.getNextValidNode(Worklist, true);
ProjectionTreeNode *Node = AggBuilderMap.getNextValidNode(Worklist, true);
// Then until we find a node that is not complete...
while (Node && AggBuilderMap.isComplete(Node)) {
@@ -1517,7 +1517,7 @@ replaceValueUsesWithLeafUses(SILBuilder &Builder, SILLocation Loc,
}
// If this node has a parent and that parent is alive...
NewProjectionTreeNode *Parent = Node->getParentOrNull(*this);
ProjectionTreeNode *Parent = Node->getParentOrNull(*this);
if (Parent && Parent->IsLive) {
// Create or lookup the node builder for the parent and associate the
// newly created aggregate with this node.

View File

@@ -37,7 +37,7 @@ void SILValueProjection::print(SILModule *Mod) {
}
SILValue SILValueProjection::createExtract(SILValue Base,
const Optional<NewProjectionPath> &Path,
const Optional<ProjectionPath> &Path,
SILInstruction *Inst,
bool IsValExt) {
// If we found a projection path, but there are no projections, then the two
@@ -95,7 +95,7 @@ SILValue LSValue::reduce(LSLocation &Base, SILModule *M,
// First, get a list of all the leaf nodes and intermediate nodes for the
// Base memory location.
LSLocationList ALocs;
const NewProjectionPath &BasePath = Base.getPath().getValue();
const ProjectionPath &BasePath = Base.getPath().getValue();
for (const auto &P : TE->getTypeExpansion(Base.getType(M), M, TEKind::TENode)) {
ALocs.push_back(LSLocation(Base.getBase(), BasePath, P.getValue()));
}
@@ -121,7 +121,7 @@ SILValue LSValue::reduce(LSLocation &Base, SILModule *M,
// empty, keep stripping it.
auto Iter = FirstLevel.begin();
LSValue &FirstVal = Values[*Iter];
if (FirstLevel.size() == 1 && !FirstVal.hasEmptyNewProjectionPath()) {
if (FirstLevel.size() == 1 && !FirstVal.hasEmptyProjectionPath()) {
Values[*I] = FirstVal.stripLastLevelProjection();
// We have a value for the parent, remove all the values for children.
removeLSLocations(Values, FirstLevel);
@@ -143,7 +143,7 @@ SILValue LSValue::reduce(LSLocation &Base, SILModule *M,
}
if (FirstLevel.size() > 1 && HasIdenticalValueBase &&
!FirstVal.hasEmptyNewProjectionPath()) {
!FirstVal.hasEmptyProjectionPath()) {
Values[*I] = FirstVal.stripLastLevelProjection();
// We have a value for the parent, remove all the values for children.
removeLSLocations(Values, FirstLevel);
@@ -171,12 +171,12 @@ SILValue LSValue::reduce(LSLocation &Base, SILModule *M,
// We use an auto-generated SILLocation for now.
// TODO: make the sil location more precise.
NullablePtr<swift::SILInstruction> AI =
NewProjection::createAggFromFirstLevelProjections(
Projection::createAggFromFirstLevelProjections(
Builder, RegularLocation::getAutoGeneratedLocation(),
I->getType(M).getObjectType(),
Vals);
// This is the Value for the current node.
NewProjectionPath P(Base.getType(M));
ProjectionPath P(Base.getType(M));
Values[*I] = LSValue(SILValue(AI.get()), P);
removeLSLocations(Values, FirstLevel);
@@ -238,10 +238,10 @@ bool LSLocation::isNonEscapingLocalLSLocation(SILFunction *Fn,
void LSLocation::getFirstLevelLSLocations(LSLocationList &Locs,
SILModule *Mod) {
SILType Ty = getType(Mod);
llvm::SmallVector<NewProjection, 8> Out;
NewProjection::getFirstLevelProjections(Ty, *Mod, Out);
llvm::SmallVector<Projection, 8> Out;
Projection::getFirstLevelProjections(Ty, *Mod, Out);
for (auto &X : Out) {
NewProjectionPath P((*Base).getType());
ProjectionPath P((*Base).getType());
P.append(Path.getValue());
P.append(X);
Locs.push_back(LSLocation(Base, P));
@@ -256,7 +256,7 @@ void LSLocation::expand(LSLocation Base, SILModule *M, LSLocationList &Locs,
//
// Construct the LSLocation by appending the projection path from the
// accessed node to the leaf nodes.
const NewProjectionPath &BasePath = Base.getPath().getValue();
const ProjectionPath &BasePath = Base.getPath().getValue();
for (const auto &P : TE->getTypeExpansion(Base.getType(M), M, TEKind::TELeaf)) {
Locs.push_back(LSLocation(Base.getBase(), BasePath, P.getValue()));
}
@@ -267,7 +267,7 @@ void LSLocation::reduce(LSLocation Base, SILModule *M, LSLocationSet &Locs,
// First, construct the LSLocation by appending the projection path from the
// accessed node to the leaf nodes.
LSLocationList Nodes;
const NewProjectionPath &BasePath = Base.getPath().getValue();
const ProjectionPath &BasePath = Base.getPath().getValue();
for (const auto &P : TE->getTypeExpansion(Base.getType(M), M, TEKind::TENode)) {
Nodes.push_back(LSLocation(Base.getBase(), BasePath, P.getValue()));
}
@@ -312,7 +312,7 @@ void LSLocation::enumerateLSLocation(SILModule *M, SILValue Mem,
// Construct a Location to represent the memory written by this instruction.
SILValue UO = getUnderlyingObject(Mem);
LSLocation L(UO, NewProjectionPath::getProjectionPath(UO, Mem));
LSLocation L(UO, ProjectionPath::getProjectionPath(UO, Mem));
// If we cant figure out the Base or Projection Path for the memory location,
// simply ignore it for now.

View File

@@ -216,7 +216,7 @@ AliasResult AliasAnalysis::aliasAddressProjection(SILValue V1, SILValue V2,
// If V2 is also a gep instruction with a must-alias or not-aliasing base
// pointer, figure out if the indices of the GEPs tell us anything about the
// derived pointers.
if (!NewProjection::isAddressProjection(V2)) {
if (!Projection::isAddressProjection(V2)) {
// Ok, V2 is not an address projection. See if V2 after stripping casts
// aliases O1. If so, then we know that V2 must partially alias V1 via a
// must alias relation on O1. This ensures that given an alloc_stack and a
@@ -227,9 +227,9 @@ AliasResult AliasAnalysis::aliasAddressProjection(SILValue V1, SILValue V2,
return AliasResult::MayAlias;
}
assert(!NewProjection::isAddressProjection(O1) &&
assert(!Projection::isAddressProjection(O1) &&
"underlying object may not be a projection");
assert(!NewProjection::isAddressProjection(O2) &&
assert(!Projection::isAddressProjection(O2) &&
"underlying object may not be a projection");
// Do the base pointers alias?
@@ -241,8 +241,8 @@ AliasResult AliasAnalysis::aliasAddressProjection(SILValue V1, SILValue V2,
return AliasResult::NoAlias;
// Let's do alias checking based on projections.
auto V1Path = NewProjectionPath::getProjectionPath(O1, V1);
auto V2Path = NewProjectionPath::getProjectionPath(O2, V2);
auto V1Path = ProjectionPath::getProjectionPath(O1, V1);
auto V2Path = ProjectionPath::getProjectionPath(O2, V2);
// getUnderlyingPath and findAddressProjectionPathBetweenValues disagree on
// what the base pointer of the two values are. Be conservative and return
@@ -612,15 +612,15 @@ AliasResult AliasAnalysis::aliasInner(SILValue V1, SILValue V2,
// First if one instruction is a gep and the other is not, canonicalize our
// inputs so that V1 always is the instruction containing the GEP.
if (!NewProjection::isAddressProjection(V1) &&
NewProjection::isAddressProjection(V2)) {
if (!Projection::isAddressProjection(V1) &&
Projection::isAddressProjection(V2)) {
std::swap(V1, V2);
std::swap(O1, O2);
}
// If V1 is an address projection, attempt to use information from the
// aggregate type tree to disambiguate it from V2.
if (NewProjection::isAddressProjection(V1)) {
if (Projection::isAddressProjection(V1)) {
AliasResult Result = aliasAddressProjection(V1, V2, O1, O2);
if (Result != AliasResult::MayAlias)
return Result;

View File

@@ -23,7 +23,7 @@ using namespace swift;
// memory usage of this cache.
static const int TypeExpansionAnalysisMaxCacheSize = 4096;
const NewProjectionPathList &
const ProjectionPathList &
TypeExpansionAnalysis::getTypeExpansion(SILType B, SILModule *Mod, TEKind Kind){
// Which cache we should be looking up.
bool IsLeaf = Kind == TEKind::TELeaf;
@@ -42,12 +42,12 @@ TypeExpansionAnalysis::getTypeExpansion(SILType B, SILModule *Mod, TEKind Kind){
// Build the type expansion for the leaf nodes.
if (IsLeaf) {
NewProjectionPath::expandTypeIntoLeafProjectionPaths(B, Mod, Cache[B]);
ProjectionPath::expandTypeIntoLeafProjectionPaths(B, Mod, Cache[B]);
return Cache[B];
}
// Build the type expansion for the internal and leaf nodes.
NewProjectionPath::expandTypeIntoNodeProjectionPaths(B, Mod, Cache[B]);
ProjectionPath::expandTypeIntoNodeProjectionPaths(B, Mod, Cache[B]);
return Cache[B];
}

View File

@@ -145,7 +145,7 @@ struct ArgumentDescriptor {
SILInstruction *CalleeReleaseInThrowBlock;
/// The projection tree of this arguments.
NewProjectionTree ProjTree;
ProjectionTree ProjTree;
ArgumentDescriptor() = delete;

View File

@@ -132,12 +132,12 @@ namespace {
// Returns the base address, i.e. the first address which is not a
// projection.
SILValue scanProjections(SILValue addr,
SmallVectorImpl<NewProjection> *Result = nullptr);
SmallVectorImpl<Projection> *Result = nullptr);
// Get the stored value for a load. The loadInst can be either a real load
// or a copy_addr.
SILValue getStoredValue(SILInstruction *loadInst,
NewProjectionPath &projStack);
ProjectionPath &projStack);
// Gets the parameter in the caller for a function argument.
SILValue getParam(SILValue value) {
@@ -162,7 +162,7 @@ namespace {
}
// Gets the estimated definition of a value.
SILInstruction *getDef(SILValue val, NewProjectionPath &projStack);
SILInstruction *getDef(SILValue val, ProjectionPath &projStack);
// Gets the estimated integer constant result of a builtin.
IntConst getBuiltinConst(BuiltinInst *BI, int depth);
@@ -191,7 +191,7 @@ namespace {
// Gets the estimated definition of a value.
SILInstruction *getDef(SILValue val) {
NewProjectionPath projStack(val->getType());
ProjectionPath projStack(val->getType());
return getDef(val, projStack);
}
@@ -285,12 +285,12 @@ void ConstantTracker::trackInst(SILInstruction *inst) {
}
SILValue ConstantTracker::scanProjections(SILValue addr,
SmallVectorImpl<NewProjection> *Result) {
SmallVectorImpl<Projection> *Result) {
for (;;) {
if (NewProjection::isAddressProjection(addr)) {
if (Projection::isAddressProjection(addr)) {
SILInstruction *I = cast<SILInstruction>(addr);
if (Result) {
Result->push_back(NewProjection(I));
Result->push_back(Projection(I));
}
addr = I->getOperand(0);
continue;
@@ -306,7 +306,7 @@ SILValue ConstantTracker::scanProjections(SILValue addr,
}
SILValue ConstantTracker::getStoredValue(SILInstruction *loadInst,
NewProjectionPath &projStack) {
ProjectionPath &projStack) {
SILInstruction *store = links[loadInst];
if (!store && callerTracker)
store = callerTracker->links[loadInst];
@@ -315,18 +315,18 @@ SILValue ConstantTracker::getStoredValue(SILInstruction *loadInst,
assert(isa<LoadInst>(loadInst) || isa<CopyAddrInst>(loadInst));
// Push the address projections of the load onto the stack.
SmallVector<NewProjection, 4> loadProjections;
SmallVector<Projection, 4> loadProjections;
scanProjections(loadInst->getOperand(0), &loadProjections);
for (const NewProjection &proj : loadProjections) {
for (const Projection &proj : loadProjections) {
projStack.push_back(proj);
}
// Pop the address projections of the store from the stack.
SmallVector<NewProjection, 4> storeProjections;
SmallVector<Projection, 4> storeProjections;
scanProjections(store->getOperand(1), &storeProjections);
for (auto iter = storeProjections.rbegin(); iter != storeProjections.rend();
++iter) {
const NewProjection &proj = *iter;
const Projection &proj = *iter;
// The corresponding load-projection must match the store-projection.
if (projStack.empty() || projStack.back() != proj)
return SILValue();
@@ -343,23 +343,23 @@ SILValue ConstantTracker::getStoredValue(SILInstruction *loadInst,
}
// Get the aggregate member based on the top of the projection stack.
static SILValue getMember(SILInstruction *inst, NewProjectionPath &projStack) {
static SILValue getMember(SILInstruction *inst, ProjectionPath &projStack) {
if (!projStack.empty()) {
const NewProjection &proj = projStack.back();
const Projection &proj = projStack.back();
return proj.getOperandForAggregate(inst);
}
return SILValue();
}
SILInstruction *ConstantTracker::getDef(SILValue val,
NewProjectionPath &projStack) {
ProjectionPath &projStack) {
// Track the value up the dominator tree.
for (;;) {
if (SILInstruction *inst = dyn_cast<SILInstruction>(val)) {
if (NewProjection::isObjectProjection(inst)) {
if (Projection::isObjectProjection(inst)) {
// Extract a member from a struct/tuple/enum.
projStack.push_back(NewProjection(inst));
projStack.push_back(Projection(inst));
val = inst->getOperand(0);
continue;
} else if (SILValue member = getMember(inst, projStack)) {

View File

@@ -52,7 +52,7 @@ COWViewCFGFunction("view-cfg-before-cow-for", llvm::cl::init(""),
/// either refer to the next element (indexed) or a subelement.
static SILValue getAccessPath(SILValue V, SmallVectorImpl<unsigned>& Path) {
V = stripCasts(V);
NewProjectionIndex PI(V);
ProjectionIndex PI(V);
if (!PI.isValid() || V->getKind() == ValueKind::IndexAddrInst)
return V;
@@ -201,7 +201,7 @@ protected:
continue;
}
NewProjectionIndex PI(UseInst);
ProjectionIndex PI(UseInst);
// Do not form a path from an IndexAddrInst without otherwise
// distinguishing it from subelement addressing.
if (!PI.isValid() || V->getKind() == ValueKind::IndexAddrInst) {

View File

@@ -394,7 +394,7 @@ SILInstruction *SILCombiner::visitLoadInst(LoadInst *LI) {
// Given a load with multiple struct_extracts/tuple_extracts and no other
// uses, canonicalize the load into several (struct_element_addr (load))
// pairs.
using ProjInstPairTy = std::pair<NewProjection, SILInstruction *>;
using ProjInstPairTy = std::pair<Projection, SILInstruction *>;
// Go through the loads uses and add any users that are projections to the
// projection list.
@@ -406,7 +406,7 @@ SILInstruction *SILCombiner::visitLoadInst(LoadInst *LI) {
if (!isa<StructExtractInst>(User) && !isa<TupleExtractInst>(User))
return nullptr;
Projections.push_back({NewProjection(User), User});
Projections.push_back({Projection(User), User});
}
// The reason why we sort the list is so that we will process projections with
@@ -416,7 +416,7 @@ SILInstruction *SILCombiner::visitLoadInst(LoadInst *LI) {
std::sort(Projections.begin(), Projections.end());
// Go through our sorted list creating new GEPs only when we need to.
NewProjection *LastProj = nullptr;
Projection *LastProj = nullptr;
LoadInst *LastNewLoad = nullptr;
for (auto &Pair : Projections) {
auto &Proj = Pair.first;

View File

@@ -463,11 +463,11 @@ recursivelyCollectInteriorUses(ValueBase *DefInst,
continue;
}
// Recursively follow projections.
NewProjectionIndex PI(User);
ProjectionIndex PI(User);
if (PI.isValid()) {
IndexTrieNode *ProjAddrNode = AddressNode;
bool ProjInteriorAddr = IsInteriorAddress;
if (NewProjection::isAddressProjection(User)) {
if (Projection::isAddressProjection(User)) {
if (User->getKind() == ValueKind::IndexAddrInst) {
// Don't support indexing within an interior address.
if (IsInteriorAddress)

View File

@@ -777,7 +777,7 @@ void DSEContext::processRead(SILInstruction *I, BlockState *S, SILValue Mem,
L = BaseToLocIndex[Mem];
} else {
SILValue UO = getUnderlyingObject(Mem);
L = LSLocation(UO, NewProjectionPath::getProjectionPath(UO, Mem));
L = LSLocation(UO, ProjectionPath::getProjectionPath(UO, Mem));
}
// If we cant figure out the Base or Projection Path for the read instruction,
@@ -862,7 +862,7 @@ void DSEContext::processWrite(SILInstruction *I, BlockState *S, SILValue Val,
L = BaseToLocIndex[Mem];
} else {
SILValue UO = getUnderlyingObject(Mem);
L = LSLocation(UO, NewProjectionPath::getProjectionPath(UO, Mem));
L = LSLocation(UO, ProjectionPath::getProjectionPath(UO, Mem));
}
// If we cant figure out the Base or Projection Path for the store
@@ -943,7 +943,7 @@ void DSEContext::processWrite(SILInstruction *I, BlockState *S, SILValue Val,
// particular instruction may not be accessing the base, so we need to
// *rebase* the locations w.r.t. to the current instruction.
SILValue B = Locs[0].getBase();
Optional<NewProjectionPath> BP = NewProjectionPath::getProjectionPath(B, Mem);
Optional<ProjectionPath> BP = ProjectionPath::getProjectionPath(B, Mem);
// Strip off the projection path from base to the accessed field.
for (auto &X : Alives) {
X.removePathPrefix(BP);

View File

@@ -645,7 +645,7 @@ bool BlockState::setupRLE(RLEContext &Ctx, SILInstruction *I, SILValue Mem) {
L = BaseToLocIndex[Mem];
} else {
SILValue UO = getUnderlyingObject(Mem);
L = LSLocation(UO, NewProjectionPath::getProjectionPath(UO, Mem));
L = LSLocation(UO, ProjectionPath::getProjectionPath(UO, Mem));
}
LSLocationValueMap Values;
@@ -777,7 +777,7 @@ void BlockState::processWrite(RLEContext &Ctx, SILInstruction *I, SILValue Mem,
L = BaseToLocIndex[Mem];
} else {
SILValue UO = getUnderlyingObject(Mem);
L = LSLocation(UO, NewProjectionPath::getProjectionPath(UO, Mem));
L = LSLocation(UO, ProjectionPath::getProjectionPath(UO, Mem));
}
// If we cant figure out the Base or Projection Path for the write,
@@ -834,7 +834,7 @@ void BlockState::processRead(RLEContext &Ctx, SILInstruction *I, SILValue Mem,
L = BaseToLocIndex[Mem];
} else {
SILValue UO = getUnderlyingObject(Mem);
L = LSLocation(UO, NewProjectionPath::getProjectionPath(UO, Mem));
L = LSLocation(UO, ProjectionPath::getProjectionPath(UO, Mem));
}
// If we cant figure out the Base or Projection Path for the read, simply

View File

@@ -319,17 +319,17 @@ static void collectLoads(SILInstruction *I, SmallVectorImpl<LoadInst *> &Loads)
static void replaceLoad(LoadInst *LI, SILValue val, AllocStackInst *ASI) {
NewProjectionPath projections(val->getType());
ProjectionPath projections(val->getType());
SILValue op = LI->getOperand();
while (op != ASI) {
assert(isa<StructElementAddrInst>(op) || isa<TupleElementAddrInst>(op));
SILInstruction *Inst = cast<SILInstruction>(op);
projections.push_back(NewProjection(Inst));
projections.push_back(Projection(Inst));
op = Inst->getOperand(0);
}
SILBuilder builder(LI);
for (auto iter = projections.rbegin(); iter != projections.rend(); ++iter) {
const NewProjection &projection = *iter;
const Projection &projection = *iter;
val = projection.createObjectProjection(builder, LI->getLoc(), val).get();
}
op = LI->getOperand();

View File

@@ -2318,7 +2318,7 @@ class ArgumentSplitter {
llvm::SmallVector<std::pair<SILBasicBlock *, SILValue>, 8> IncomingValues;
/// The list of first level projections that Arg can be split into.
llvm::SmallVector<NewProjection, 4> Projections;
llvm::SmallVector<Projection, 4> Projections;
llvm::Optional<int> FirstNewArgIndex;
@@ -2404,7 +2404,7 @@ bool ArgumentSplitter::createNewArguments() {
return false;
// Get the first level projection for the struct or tuple type.
NewProjection::getFirstLevelProjections(Arg->getType(), Mod, Projections);
Projection::getFirstLevelProjections(Arg->getType(), Mod, Projections);
// We do not want to split arguments with less than 2 projections.
if (Projections.size() < 2)
@@ -2413,7 +2413,7 @@ bool ArgumentSplitter::createNewArguments() {
// We do not want to split arguments that have less than 2 non-trivial
// projections.
if (std::count_if(Projections.begin(), Projections.end(),
[&](const NewProjection &P) {
[&](const Projection &P) {
return !P.getType(Ty, Mod).isTrivial(Mod);
}) < 2)
return false;
@@ -2445,7 +2445,7 @@ bool ArgumentSplitter::createNewArguments() {
//
// TODO: What is the right location to use here.
auto Loc = RegularLocation::getAutoGeneratedLocation();
Agg = NewProjection::createAggFromFirstLevelProjections(
Agg = Projection::createAggFromFirstLevelProjections(
B, Loc, Arg->getType(), NewArgumentValues).get();
assert(Agg->hasValue() && "Expected a result");
}

View File

@@ -52,7 +52,7 @@ static llvm::cl::opt<MLKind> LSLocationKinds(
"only-type-expansion"),
clEnumValN(MLKind::All, "all", "all"), clEnumValEnd));
static llvm::cl::opt<bool> UseNewProjection("lslocation-dump-use-new-projection",
static llvm::cl::opt<bool> UseProjection("lslocation-dump-use-new-projection",
llvm::cl::init(false));
namespace {
@@ -70,7 +70,7 @@ public:
///
void printTypeExpansion(SILFunction &Fn) {
SILModule *M = &Fn.getModule();
NewProjectionPathList PPList;
ProjectionPathList PPList;
unsigned Counter = 0;
for (auto &BB : Fn) {
for (auto &II : BB) {
@@ -78,12 +78,12 @@ public:
SILValue V = LI->getOperand();
// This is an address type, take it object type.
SILType Ty = V->getType().getObjectType();
NewProjectionPath::expandTypeIntoLeafProjectionPaths(Ty, M, PPList);
ProjectionPath::expandTypeIntoLeafProjectionPaths(Ty, M, PPList);
} else if (auto *SI = dyn_cast<StoreInst>(&II)) {
SILValue V = SI->getDest();
// This is an address type, take it object type.
SILType Ty = V->getType().getObjectType();
NewProjectionPath::expandTypeIntoLeafProjectionPaths(Ty, M, PPList);
ProjectionPath::expandTypeIntoLeafProjectionPaths(Ty, M, PPList);
} else {
// Not interested in these instructions yet.
continue;
@@ -99,9 +99,9 @@ public:
llvm::outs() << "\n";
}
void printTypeExpansionWithNewProjection(SILFunction &Fn) {
void printTypeExpansionWithProjection(SILFunction &Fn) {
SILModule *M = &Fn.getModule();
llvm::SmallVector<Optional<NewProjectionPath>, 8> PPList;
llvm::SmallVector<Optional<ProjectionPath>, 8> PPList;
unsigned Counter = 0;
for (auto &BB : Fn) {
for (auto &II : BB) {
@@ -111,12 +111,12 @@ public:
V = LI->getOperand();
// This is an address type, take it object type.
Ty = V->getType().getObjectType();
NewProjectionPath::expandTypeIntoLeafProjectionPaths(Ty, M, PPList);
ProjectionPath::expandTypeIntoLeafProjectionPaths(Ty, M, PPList);
} else if (auto *SI = dyn_cast<StoreInst>(&II)) {
V = SI->getDest();
// This is an address type, take it object type.
Ty = V->getType().getObjectType();
NewProjectionPath::expandTypeIntoLeafProjectionPaths(Ty, M, PPList);
ProjectionPath::expandTypeIntoLeafProjectionPaths(Ty, M, PPList);
} else {
// Not interested in these instructions yet.
continue;
@@ -147,14 +147,14 @@ public:
if (auto *LI = dyn_cast<LoadInst>(&II)) {
SILValue Mem = LI->getOperand();
SILValue UO = getUnderlyingObject(Mem);
L.init(UO, NewProjectionPath::getProjectionPath(UO, Mem));
L.init(UO, ProjectionPath::getProjectionPath(UO, Mem));
if (!L.isValid())
continue;
LSLocation::expand(L, &Fn.getModule(), Locs, TE);
} else if (auto *SI = dyn_cast<StoreInst>(&II)) {
SILValue Mem = SI->getDest();
SILValue UO = getUnderlyingObject(Mem);
L.init(UO, NewProjectionPath::getProjectionPath(UO, Mem));
L.init(UO, ProjectionPath::getProjectionPath(UO, Mem));
if (!L.isValid())
continue;
LSLocation::expand(L, &Fn.getModule(), Locs, TE);
@@ -191,14 +191,14 @@ public:
if (auto *LI = dyn_cast<LoadInst>(&II)) {
SILValue Mem = LI->getOperand();
SILValue UO = getUnderlyingObject(Mem);
L.init(UO, NewProjectionPath::getProjectionPath(UO, Mem));
L.init(UO, ProjectionPath::getProjectionPath(UO, Mem));
if (!L.isValid())
continue;
LSLocation::expand(L, &Fn.getModule(), Locs, TE);
} else if (auto *SI = dyn_cast<StoreInst>(&II)) {
SILValue Mem = SI->getDest();
SILValue UO = getUnderlyingObject(Mem);
L.init(UO, NewProjectionPath::getProjectionPath(UO, Mem));
L.init(UO, ProjectionPath::getProjectionPath(UO, Mem));
if (!L.isValid())
continue;
LSLocation::expand(L, &Fn.getModule(), Locs, TE);
@@ -239,7 +239,7 @@ public:
llvm::outs() << "@" << Fn.getName() << "\n";
switch (LSLocationKinds) {
case MLKind::OnlyTypeExpansion:
printTypeExpansionWithNewProjection(Fn);
printTypeExpansionWithProjection(Fn);
break;
case MLKind::OnlyExpansion:
printMemExpansion(Fn);