From 50954f5cba406a88011cc8ade3ceb4235830f907 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Thu, 3 May 2007 22:46:43 +0000 Subject: [PATCH] enumerate parameter attr lists. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@36709 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Bitcode/Writer/ValueEnumerator.cpp | 17 +++++++++++++++++ lib/Bitcode/Writer/ValueEnumerator.h | 16 ++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/lib/Bitcode/Writer/ValueEnumerator.cpp b/lib/Bitcode/Writer/ValueEnumerator.cpp index 4d3f0fd792a..ba091b564f0 100644 --- a/lib/Bitcode/Writer/ValueEnumerator.cpp +++ b/lib/Bitcode/Writer/ValueEnumerator.cpp @@ -12,6 +12,7 @@ //===----------------------------------------------------------------------===// #include "ValueEnumerator.h" +#include "llvm/DerivedTypes.h" #include "llvm/Module.h" #include "llvm/TypeSymbolTable.h" #include "llvm/ValueSymbolTable.h" @@ -143,8 +144,24 @@ void ValueEnumerator::EnumerateType(const Type *Ty) { for (Type::subtype_iterator I = Ty->subtype_begin(), E = Ty->subtype_end(); I != E; ++I) EnumerateType(*I); + + // If this is a function type, enumerate the param attrs. + if (const FunctionType *FTy = dyn_cast(Ty)) + EnumerateParamAttrs(FTy->getParamAttrs()); } +void ValueEnumerator::EnumerateParamAttrs(const ParamAttrsList *PAL) { + if (PAL == 0) return; // null is always 0. + // Do a lookup. + unsigned &Entry = ParamAttrMap[PAL]; + if (Entry == 0) { + // Never saw this before, add it. + ParamAttrs.push_back(PAL); + Entry = ParamAttrs.size(); + } +} + + /// PurgeAggregateValues - If there are any aggregate values at the end of the /// value list, remove them and return the count of the remaining values. If /// there are none, return -1. diff --git a/lib/Bitcode/Writer/ValueEnumerator.h b/lib/Bitcode/Writer/ValueEnumerator.h index 77f27dad68b..d78fdb8af95 100644 --- a/lib/Bitcode/Writer/ValueEnumerator.h +++ b/lib/Bitcode/Writer/ValueEnumerator.h @@ -24,6 +24,7 @@ class Value; class BasicBlock; class Function; class Module; +class ParamAttrsList; class TypeSymbolTable; class ValueSymbolTable; @@ -43,6 +44,10 @@ private: ValueMapType ValueMap; ValueList Values; + typedef DenseMap ParamAttrMapType; + ParamAttrMapType ParamAttrMap; + std::vector ParamAttrs; + /// BasicBlocks - This contains all the basic blocks for the currently /// incorporated function. Their reverse mapping is stored in ValueMap. std::vector BasicBlocks; @@ -69,6 +74,13 @@ public: assert(I != TypeMap.end() && "Type not in ValueEnumerator!"); return I->second-1; } + + unsigned getParamAttrID(const ParamAttrsList *PAL) const { + if (PAL == 0) return 0; // Null maps to zero. + ParamAttrMapType::const_iterator I = ParamAttrMap.find(PAL); + assert(I != ParamAttrMap.end() && "ParamAttr not in ValueEnumerator!"); + return I->second; + } /// getFunctionConstantRange - Return the range of values that corresponds to /// function-local constants. @@ -82,6 +94,9 @@ public: const std::vector &getBasicBlocks() const { return BasicBlocks; } + const std::vector getParamAttrs() const { + return ParamAttrs; + } /// PurgeAggregateValues - If there are any aggregate values at the end of the /// value list, remove them and return the count of the remaining values. If @@ -97,6 +112,7 @@ public: private: void EnumerateValue(const Value *V); void EnumerateType(const Type *T); + void EnumerateParamAttrs(const ParamAttrsList *PAL); void EnumerateTypeSymbolTable(const TypeSymbolTable &ST); void EnumerateValueSymbolTable(const ValueSymbolTable &ST);