[llvm-commits] [llvm] r73631 - /llvm/trunk/lib/VMCore/Constants.cpp

Bill Wendling isanbard at gmail.com
Wed Jun 17 14:01:29 PDT 2009


Thanks! :-)

-bw

On Wed, Jun 17, 2009 at 1:43 PM, Owen Anderson<resistor at mac.com> wrote:
> Author: resistor
> Date: Wed Jun 17 15:43:39 2009
> New Revision: 73631
>
> URL: http://llvm.org/viewvc/llvm-project?rev=73631&view=rev
> Log:
> Factor out some common code.
>
> Modified:
>    llvm/trunk/lib/VMCore/Constants.cpp
>
> Modified: llvm/trunk/lib/VMCore/Constants.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Constants.cpp?rev=73631&r1=73630&r2=73631&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/VMCore/Constants.cpp (original)
> +++ llvm/trunk/lib/VMCore/Constants.cpp Wed Jun 17 15:43:39 2009
> @@ -1221,6 +1221,34 @@
>       }
>       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 @@
>             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 @@
>           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);
>       }
>     }
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>




More information about the llvm-commits mailing list