-bool llvm::GetConstantStringInfo(Value *V, std::string &Str, uint64_t Offset,
- bool StopAtNul) {
- // If V is NULL then return false;
- if (V == NULL) return false;
+const char *llvm::GetConstantStringInfo(Value *V, uint64_t Offset,
+ bool StopAtNul) {
+ static DenseMap<Value*, std::string> StringInfoMap;
+ static DenseMap<Value*, bool> NulMap;
+
+ // If we've already determined that the Value is NUL, then return 0.
+ if (NulMap[V])
+ return 0;
+
+ // Check to see if we've already calculated the string info.
+ if (StringInfoMap.find(V) != StringInfoMap.end())
+ return StringInfoMap.lookup(V).c_str();
+
+ // If V is NULL then return nul.
+ if (V == 0) {
+ NulMap[V] = true;
+ return 0;
+ }
+
+ std::string *Str = &StringInfoMap.FindAndConstruct(V).second;
+ Str->clear();