#define LLVM_ANALYSIS_DSNODE_H
#include "llvm/Analysis/DSSupport.h"
+
template<typename BaseType>
class DSNodeIterator; // Data structure graph traversal iterator
GlobalNode = 1 << 2, // This node was allocated by a global var decl
UnknownNode = 1 << 3, // This node points to unknown allocated memory
Incomplete = 1 << 4, // This node may not be complete
+
Modified = 1 << 5, // This node is modified in this context
Read = 1 << 6, // This node is read in this context
+
Array = 1 << 7, // This node is treated like an array
-#if 1
+ //#ifndef NDEBUG
DEAD = 1 << 8, // This node is dead and should not be pointed to
-#endif
+ //#endif
Composition = AllocaNode | HeapNode | GlobalNode | UnknownNode,
};
/// NodeType - A union of the above bits. "Shadow" nodes do not add any flags
/// to the nodes in the data structure graph, so it is possible to have nodes
- /// with a value of 0 for their NodeType. Scalar and Alloca markers go away
- /// when function graphs are inlined.
+ /// with a value of 0 for their NodeType.
///
+private:
unsigned short NodeType;
+public:
- DSNode(unsigned NodeTy, const Type *T, DSGraph *G);
+ DSNode(const Type *T, DSGraph *G);
DSNode(const DSNode &, DSGraph *G);
~DSNode() {
/// return the number of nodes forwarding over the node!
unsigned getNumReferrers() const { return NumReferrers; }
- /// isModified - Return true if this node may be modified in this context
- ///
- bool isModified() const { return (NodeType & Modified) != 0; }
-
- /// isRead - Return true if this node may be read in this context
- ///
- bool isRead() const { return (NodeType & Read) != 0; }
-
DSGraph *getParentGraph() const { return ParentGraph; }
void setParentGraph(DSGraph *G) { ParentGraph = G; }
/// This method returns true if the node is completely folded, otherwise
/// false.
///
- bool mergeTypeInfo(const Type *Ty, unsigned Offset);
+ bool mergeTypeInfo(const Type *Ty, unsigned Offset,
+ bool FoldIfIncompatible = true);
/// foldNodeCompletely - If we determine that this node has some funny
/// behavior happening to it that we cannot represent, we fold it down to a
///
void addGlobal(GlobalValue *GV);
const std::vector<GlobalValue*> &getGlobals() const { return Globals; }
- std::vector<GlobalValue*> &getGlobals() { return Globals; }
+
+ /// maskNodeTypes - Apply a mask to the node types bitfield.
+ ///
+ void maskNodeTypes(unsigned Mask) {
+ NodeType &= Mask;
+ }
+
+ /// getNodeFlags - Return all of the flags set on the node. If the DEAD flag
+ /// is set, hide it from the caller.
+ unsigned getNodeFlags() const { return NodeType & ~DEAD; }
+
+ bool isAllocaNode() const { return NodeType & AllocaNode; }
+ bool isHeapNode() const { return NodeType & HeapNode; }
+ bool isGlobalNode() const { return NodeType & GlobalNode; }
+ bool isUnknownNode() const { return NodeType & UnknownNode; }
+
+ bool isModified() const { return NodeType & Modified; }
+ bool isRead() const { return NodeType & Read; }
+
+ bool isIncomplete() const { return NodeType & Incomplete; }
+ bool isComplete() const { return !isIncomplete(); }
+ bool isDeadNode() const { return NodeType & DEAD; }
+
+ DSNode *setAllocaNodeMarker() { NodeType |= AllocaNode; return this; }
+ DSNode *setHeapNodeMarker() { NodeType |= HeapNode; return this; }
+ DSNode *setGlobalNodeMarker() { NodeType |= GlobalNode; return this; }
+ DSNode *setUnknownNodeMarker() { NodeType |= UnknownNode; return this; }
+
+ DSNode *setIncompleteMarker() { NodeType |= Incomplete; return this; }
+ DSNode *setModifiedMarker() { NodeType |= Modified; return this; }
+ DSNode *setReadMarker() { NodeType |= Read; return this; }
+
+ void makeNodeDead() {
+ Globals.clear();
+ assert(hasNoReferrers() && "Dead node shouldn't have refs!");
+ NodeType = DEAD;
+ }
/// forwardNode - Mark this node as being obsolete, and all references to it
/// should be forwarded to the specified node and offset.
if (!N || N->ForwardNH.isNull())
return N;
- // Handle node forwarding here!
- DSNode *Next = N->ForwardNH.getNode(); // Cause recursive shrinkage
- Offset += N->ForwardNH.getOffset();
-
- if (--N->NumReferrers == 0) {
- // Removing the last referrer to the node, sever the forwarding link
- N->stopForwarding();
- }
-
- N = Next;
- N->NumReferrers++;
- if (N->Size <= Offset) {
- assert(N->Size <= 1 && "Forwarded to shrunk but not collapsed node?");
- Offset = 0;
- }
- return N;
+ return HandleForwarding();
}
inline void DSNodeHandle::setNode(DSNode *n) {
}
}
assert(!N || ((N->NodeType & DSNode::DEAD) == 0));
-
assert((!N || Offset < N->Size || (N->Size == 0 && Offset == 0) ||
!N->ForwardNH.isNull()) && "Node handle offset out of range!");
}