From 14c67ccf02ab1de28c7e726493619881a41c4438 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Wed, 28 Jan 2004 03:01:22 +0000 Subject: [PATCH] Keep track of all of the globals inserted into the scalar map git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@10995 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Analysis/DSGraph.h | 30 ++++++++++++++++--- include/llvm/Analysis/DataStructure/DSGraph.h | 30 ++++++++++++++++--- 2 files changed, 52 insertions(+), 8 deletions(-) diff --git a/include/llvm/Analysis/DSGraph.h b/include/llvm/Analysis/DSGraph.h index e81f139fb5f..a86f5218eb1 100644 --- a/include/llvm/Analysis/DSGraph.h +++ b/include/llvm/Analysis/DSGraph.h @@ -32,10 +32,12 @@ class GlobalValue; /// of DSA. In all of these cases, the DSA phase is really trying to identify /// globals or unique node handles active in the function. /// - class DSScalarMap { typedef hash_map ValueMapTy; ValueMapTy ValueMap; + + typedef hash_set GlobalSetTy; + GlobalSetTy GlobalSet; public: // Compatibility methods: provide an interface compatible with a map of @@ -50,15 +52,35 @@ public: const_iterator find(Value *V) const { return ValueMap.find(V); } unsigned count(Value *V) const { return ValueMap.count(V); } - void erase(iterator I) { ValueMap.erase(I); } - void erase(Value *V) { ValueMap.erase(V); } + void erase(Value *V) { erase(find(V)); } - DSNodeHandle &operator[](Value *V) { return ValueMap[V]; } + DSNodeHandle &operator[](Value *V) { + std::pair IP = + ValueMap.insert(std::make_pair(V, DSNodeHandle())); + if (IP.second) { // Inserted the new entry into the map. + if (GlobalValue *GV = dyn_cast(V)) + GlobalSet.insert(GV); + } + return IP.first->second; + } + + void erase(iterator I) { + assert(I != ValueMap.end() && "Cannot erase end!"); + if (GlobalValue *GV = dyn_cast(I->first)) + GlobalSet.erase(GV); + ValueMap.erase(I); + } void clear() { ValueMap.clear(); + GlobalSet.clear(); } + // Access to the global set: the set of all globals currently in the + // scalar map. + typedef GlobalSetTy::const_iterator global_iterator; + global_iterator global_begin() const { return GlobalSet.begin(); } + global_iterator global_end() const { return GlobalSet.end(); } }; diff --git a/include/llvm/Analysis/DataStructure/DSGraph.h b/include/llvm/Analysis/DataStructure/DSGraph.h index e81f139fb5f..a86f5218eb1 100644 --- a/include/llvm/Analysis/DataStructure/DSGraph.h +++ b/include/llvm/Analysis/DataStructure/DSGraph.h @@ -32,10 +32,12 @@ class GlobalValue; /// of DSA. In all of these cases, the DSA phase is really trying to identify /// globals or unique node handles active in the function. /// - class DSScalarMap { typedef hash_map ValueMapTy; ValueMapTy ValueMap; + + typedef hash_set GlobalSetTy; + GlobalSetTy GlobalSet; public: // Compatibility methods: provide an interface compatible with a map of @@ -50,15 +52,35 @@ public: const_iterator find(Value *V) const { return ValueMap.find(V); } unsigned count(Value *V) const { return ValueMap.count(V); } - void erase(iterator I) { ValueMap.erase(I); } - void erase(Value *V) { ValueMap.erase(V); } + void erase(Value *V) { erase(find(V)); } - DSNodeHandle &operator[](Value *V) { return ValueMap[V]; } + DSNodeHandle &operator[](Value *V) { + std::pair IP = + ValueMap.insert(std::make_pair(V, DSNodeHandle())); + if (IP.second) { // Inserted the new entry into the map. + if (GlobalValue *GV = dyn_cast(V)) + GlobalSet.insert(GV); + } + return IP.first->second; + } + + void erase(iterator I) { + assert(I != ValueMap.end() && "Cannot erase end!"); + if (GlobalValue *GV = dyn_cast(I->first)) + GlobalSet.erase(GV); + ValueMap.erase(I); + } void clear() { ValueMap.clear(); + GlobalSet.clear(); } + // Access to the global set: the set of all globals currently in the + // scalar map. + typedef GlobalSetTy::const_iterator global_iterator; + global_iterator global_begin() const { return GlobalSet.begin(); } + global_iterator global_end() const { return GlobalSet.end(); } }; -- 2.34.1