From: Bill Wendling Date: Sun, 10 Feb 2013 23:06:02 +0000 (+0000) Subject: Add support for attribute groups in the value enumerator. X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=8c2e77f895301967bf37d04e905fb1f069ec91b2;p=oota-llvm.git Add support for attribute groups in the value enumerator. Attribute groups are essentially all AttributeSets which are used by the program. Enumerate them here. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@174844 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Bitcode/Writer/ValueEnumerator.cpp b/lib/Bitcode/Writer/ValueEnumerator.cpp index b2f7875111d..9f7e17b976b 100644 --- a/lib/Bitcode/Writer/ValueEnumerator.cpp +++ b/lib/Bitcode/Writer/ValueEnumerator.cpp @@ -427,6 +427,16 @@ void ValueEnumerator::EnumerateAttributes(const AttributeSet &PAL) { Attribute.push_back(PAL); Entry = Attribute.size(); } + + // Do lookups for all attribute groups. + for (unsigned i = 0, e = PAL.getNumSlots(); i != e; ++i) { + AttributeSet AS = PAL.getSlotAttributes(i); + unsigned &Entry = AttributeSetMap[AS]; + if (Entry == 0) { + AttributeSets.push_back(AS); + Entry = AttributeSets.size(); + } + } } void ValueEnumerator::incorporateFunction(const Function &F) { diff --git a/lib/Bitcode/Writer/ValueEnumerator.h b/lib/Bitcode/Writer/ValueEnumerator.h index 2d3d570354b..6e91d68fcb0 100644 --- a/lib/Bitcode/Writer/ValueEnumerator.h +++ b/lib/Bitcode/Writer/ValueEnumerator.h @@ -52,6 +52,10 @@ private: SmallVector FunctionLocalMDs; ValueMapType MDValueMap; + typedef DenseMap AttributeSetMapType; + AttributeSetMapType AttributeSetMap; + std::vector AttributeSets; + typedef DenseMap AttributeMapType; AttributeMapType AttributeMap; std::vector Attribute; @@ -105,6 +109,13 @@ public: return I->second; } + unsigned getAttributeSetID(const AttributeSet &PAL) const { + if (PAL.isEmpty()) return 0; // Null maps to zero. + AttributeSetMapType::const_iterator I = AttributeSetMap.find(PAL); + assert(I != AttributeSetMap.end() && "Attribute not in ValueEnumerator!"); + return I->second; + } + /// getFunctionConstantRange - Return the range of values that corresponds to /// function-local constants. void getFunctionConstantRange(unsigned &Start, unsigned &End) const { @@ -124,6 +135,9 @@ public: const std::vector &getAttributes() const { return Attribute; } + const std::vector &getAttributeSets() const { + return AttributeSets; + } /// getGlobalBasicBlockID - This returns the function-specific ID for the /// specified basic block. This is relatively expensive information, so it