aboutsummaryrefslogtreecommitdiffstats
path: root/lib/VMCore
diff options
context:
space:
mode:
authorOwen Anderson <resistor@mac.com>2009-06-17 20:43:39 +0000
committerOwen Anderson <resistor@mac.com>2009-06-17 20:43:39 +0000
commit32a25568fc4a06c81e9f6a0d4a5c3a6388ad8c35 (patch)
treee765c7422e726c45e5b324023f40cff739d8b7fe /lib/VMCore
parentdd561e153971c058138eed7a8212a26d011bbbef (diff)
downloadexternal_llvm-32a25568fc4a06c81e9f6a0d4a5c3a6388ad8c35.zip
external_llvm-32a25568fc4a06c81e9f6a0d4a5c3a6388ad8c35.tar.gz
external_llvm-32a25568fc4a06c81e9f6a0d4a5c3a6388ad8c35.tar.bz2
Factor out some common code.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@73631 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore')
-rw-r--r--lib/VMCore/Constants.cpp74
1 files changed, 30 insertions, 44 deletions
diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp
index 9ffa5aa..043a30f 100644
--- a/lib/VMCore/Constants.cpp
+++ b/lib/VMCore/Constants.cpp
@@ -1221,6 +1221,34 @@ private:
}
return I;
}
+
+ ConstantClass* Create(const TypeClass *Ty, const ValType &V,
+ typename MapTy::iterator I) {
+ ConstantClass* Result =
+ ConstantCreator<ConstantClass,TypeClass,ValType>::create(Ty, V);
+
+ assert(Result->getType() == Ty && "Type specified is not correct!");
+ I = Map.insert(I, std::make_pair(MapKey(Ty, V), Result));
+
+ if (HasLargeKey) // Remember the reverse mapping if needed.
+ InverseMap.insert(std::make_pair(Result, I));
+
+ // If the type of the constant is abstract, make sure that an entry
+ // exists for it in the AbstractTypeMap.
+ if (Ty->isAbstract()) {
+ typename AbstractTypeMapTy::iterator TI =
+ AbstractTypeMap.find(Ty);
+
+ if (TI == AbstractTypeMap.end()) {
+ // Add ourselves to the ATU list of the type.
+ cast<DerivedType>(Ty)->addAbstractTypeUser(this);
+
+ AbstractTypeMap.insert(TI, std::make_pair(Ty, I));
+ }
+ }
+
+ return Result;
+ }
public:
/// getOrCreate - Return the specified constant from the map, creating it if
@@ -1245,28 +1273,7 @@ public:
Result = static_cast<ConstantClass *>(I->second);
if (!Result) {
// If no preexisting value, create one now...
- Result =
- ConstantCreator<ConstantClass,TypeClass,ValType>::create(Ty, V);
-
- assert(Result->getType() == Ty && "Type specified is not correct!");
- I = Map.insert(I, std::make_pair(MapKey(Ty, V), Result));
-
- if (HasLargeKey) // Remember the reverse mapping if needed.
- InverseMap.insert(std::make_pair(Result, I));
-
- // If the type of the constant is abstract, make sure that an entry
- // exists for it in the AbstractTypeMap.
- if (Ty->isAbstract()) {
- typename AbstractTypeMapTy::iterator TI =
- AbstractTypeMap.find(Ty);
-
- if (TI == AbstractTypeMap.end()) {
- // Add ourselves to the ATU list of the type.
- cast<DerivedType>(Ty)->addAbstractTypeUser(this);
-
- AbstractTypeMap.insert(TI, std::make_pair(Ty, I));
- }
- }
+ Result = Create(Ty, V, I);
}
}
@@ -1278,28 +1285,7 @@ public:
return static_cast<ConstantClass *>(I->second);
// If no preexisting value, create one now...
- ConstantClass *Result =
- ConstantCreator<ConstantClass,TypeClass,ValType>::create(Ty, V);
-
- assert(Result->getType() == Ty && "Type specified is not correct!");
- I = Map.insert(I, std::make_pair(MapKey(Ty, V), Result));
-
- if (HasLargeKey) // Remember the reverse mapping if needed.
- InverseMap.insert(std::make_pair(Result, I));
-
- // If the type of the constant is abstract, make sure that an entry
- // exists for it in the AbstractTypeMap.
- if (Ty->isAbstract()) {
- typename AbstractTypeMapTy::iterator TI = AbstractTypeMap.find(Ty);
-
- if (TI == AbstractTypeMap.end()) {
- // Add ourselves to the ATU list of the type.
- cast<DerivedType>(Ty)->addAbstractTypeUser(this);
-
- AbstractTypeMap.insert(TI, std::make_pair(Ty, I));
- }
- }
- return Result;
+ return Create(Ty, V, I);
}
}