diff options
Diffstat (limited to 'llvm/lib/IR/AsmWriter.cpp')
-rw-r--r-- | llvm/lib/IR/AsmWriter.cpp | 50 |
1 files changed, 22 insertions, 28 deletions
diff --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp index 3afa3986052..f8481039c66 100644 --- a/llvm/lib/IR/AsmWriter.cpp +++ b/llvm/lib/IR/AsmWriter.cpp @@ -21,6 +21,8 @@ #include "llvm/ADT/SmallString.h" #include "llvm/ADT/StringExtras.h" #include "llvm/IR/AssemblyAnnotationWriter.h" +#include "llvm/IR/AttributeSetNode.h" +#include "llvm/IR/Attributes.h" #include "llvm/IR/CFG.h" #include "llvm/IR/CallingConv.h" #include "llvm/IR/Constants.h" @@ -604,7 +606,7 @@ private: unsigned mdnNext; /// asMap - The slot map for attribute sets. - DenseMap<AttributeList, unsigned> asMap; + DenseMap<AttributeSetNode *, unsigned> asMap; unsigned asNext; public: /// Construct from a module. @@ -627,7 +629,7 @@ public: int getLocalSlot(const Value *V); int getGlobalSlot(const GlobalValue *V); int getMetadataSlot(const MDNode *N); - int getAttributeGroupSlot(AttributeList AS); + int getAttributeGroupSlot(AttributeSetNode *AS); /// If you'd like to deal with a function instead of just a module, use /// this method to get its data into the SlotTracker. @@ -650,8 +652,8 @@ public: unsigned mdn_size() const { return mdnMap.size(); } bool mdn_empty() const { return mdnMap.empty(); } - /// AttributeList map iterators. - typedef DenseMap<AttributeList, unsigned>::iterator as_iterator; + /// AttributeSetNode map iterators. + typedef DenseMap<AttributeSetNode *, unsigned>::iterator as_iterator; as_iterator as_begin() { return asMap.begin(); } as_iterator as_end() { return asMap.end(); } unsigned as_size() const { return asMap.size(); } @@ -671,8 +673,8 @@ private: /// CreateFunctionSlot - Insert the specified Value* into the slot table. void CreateFunctionSlot(const Value *V); - /// \brief Insert the specified AttributeList into the slot table. - void CreateAttributeSetSlot(AttributeList AS); + /// \brief Insert the specified AttributeSetNode into the slot table. + void CreateAttributeSetSlot(AttributeSetNode *AS); /// Add all of the module level global variables (and their initializers) /// and function declarations, but not the contents of those functions. @@ -831,8 +833,8 @@ void SlotTracker::processModule() { // Add all the function attributes to the table. // FIXME: Add attributes of other objects? - AttributeList FnAttrs = F.getAttributes().getFnAttributes(); - if (FnAttrs.hasAttributes(AttributeList::FunctionIndex)) + AttributeSetNode *FnAttrs = F.getAttributes().getFnAttributes(); + if (FnAttrs) CreateAttributeSetSlot(FnAttrs); } @@ -869,13 +871,13 @@ void SlotTracker::processFunction() { // target may not be linked into the optimizer. if (const CallInst *CI = dyn_cast<CallInst>(&I)) { // Add all the call attributes to the table. - AttributeList Attrs = CI->getAttributes().getFnAttributes(); - if (Attrs.hasAttributes(AttributeList::FunctionIndex)) + AttributeSetNode *Attrs = CI->getAttributes().getFnAttributes(); + if (Attrs) CreateAttributeSetSlot(Attrs); } else if (const InvokeInst *II = dyn_cast<InvokeInst>(&I)) { // Add all the call attributes to the table. - AttributeList Attrs = II->getAttributes().getFnAttributes(); - if (Attrs.hasAttributes(AttributeList::FunctionIndex)) + AttributeSetNode *Attrs = II->getAttributes().getFnAttributes(); + if (Attrs) CreateAttributeSetSlot(Attrs); } } @@ -961,11 +963,11 @@ int SlotTracker::getLocalSlot(const Value *V) { return FI == fMap.end() ? -1 : (int)FI->second; } -int SlotTracker::getAttributeGroupSlot(AttributeList AS) { +int SlotTracker::getAttributeGroupSlot(AttributeSetNode *AS) { // Check for uninitialized state and do lazy initialization. initialize(); - // Find the AttributeList in the module map. + // Find the AttributeSetNode in the module map. as_iterator AI = asMap.find(AS); return AI == asMap.end() ? -1 : (int)AI->second; } @@ -1015,9 +1017,8 @@ void SlotTracker::CreateMetadataSlot(const MDNode *N) { CreateMetadataSlot(Op); } -void SlotTracker::CreateAttributeSetSlot(AttributeList AS) { - assert(AS.hasAttributes(AttributeList::FunctionIndex) && - "Doesn't need a slot!"); +void SlotTracker::CreateAttributeSetSlot(AttributeSetNode *AS) { + assert(AS && "Doesn't need a slot!"); as_iterator I = asMap.find(AS); if (I != asMap.end()) @@ -2606,17 +2607,10 @@ void AssemblyWriter::printFunction(const Function *F) { const AttributeList &Attrs = F->getAttributes(); if (Attrs.hasAttributes(AttributeList::FunctionIndex)) { - AttributeList AS = Attrs.getFnAttributes(); + AttributeSetNode *AS = Attrs.getFnAttributes(); std::string AttrStr; - unsigned Idx = 0; - for (unsigned E = AS.getNumSlots(); Idx != E; ++Idx) - if (AS.getSlotIndex(Idx) == AttributeList::FunctionIndex) - break; - - for (AttributeList::iterator I = AS.begin(Idx), E = AS.end(Idx); I != E; - ++I) { - Attribute Attr = *I; + for (const Attribute &Attr : *AS) { if (!Attr.isStringAttribute()) { if (!AttrStr.empty()) AttrStr += ' '; AttrStr += Attr.getAsString(); @@ -3250,7 +3244,7 @@ void AssemblyWriter::printMDNodeBody(const MDNode *Node) { } void AssemblyWriter::writeAllAttributeGroups() { - std::vector<std::pair<AttributeList, unsigned>> asVec; + std::vector<std::pair<AttributeSetNode *, unsigned>> asVec; asVec.resize(Machine.as_size()); for (SlotTracker::as_iterator I = Machine.as_begin(), E = Machine.as_end(); @@ -3259,7 +3253,7 @@ void AssemblyWriter::writeAllAttributeGroups() { for (const auto &I : asVec) Out << "attributes #" << I.second << " = { " - << I.first.getAsString(AttributeList::FunctionIndex, true) << " }\n"; + << I.first->getAsString(true) << " }\n"; } void AssemblyWriter::printUseListOrder(const UseListOrder &Order) { |