2008-09-26 05:00:45 +08:00
|
|
|
//===-- Attributes.cpp - Implement AttributesList -------------------------===//
|
2008-01-03 07:42:30 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2008-09-26 05:00:45 +08:00
|
|
|
// This file implements the AttributesList class and Attribute utilities.
|
2008-01-03 07:42:30 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2008-09-24 07:03:40 +08:00
|
|
|
#include "llvm/Attributes.h"
|
2008-03-13 01:45:29 +08:00
|
|
|
#include "llvm/Type.h"
|
2008-03-11 07:55:07 +08:00
|
|
|
#include "llvm/ADT/StringExtras.h"
|
2008-03-13 01:45:29 +08:00
|
|
|
#include "llvm/ADT/FoldingSet.h"
|
2010-11-30 02:16:10 +08:00
|
|
|
#include "llvm/Support/Atomic.h"
|
|
|
|
#include "llvm/Support/Mutex.h"
|
2010-01-05 09:29:58 +08:00
|
|
|
#include "llvm/Support/Debug.h"
|
2008-01-03 07:42:30 +08:00
|
|
|
#include "llvm/Support/ManagedStatic.h"
|
2009-08-23 19:37:21 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2008-01-03 07:42:30 +08:00
|
|
|
using namespace llvm;
|
|
|
|
|
2008-03-13 01:45:29 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2008-09-26 05:00:45 +08:00
|
|
|
// Attribute Function Definitions
|
2008-03-13 01:45:29 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2008-01-15 03:52:09 +08:00
|
|
|
|
2012-09-20 22:44:42 +08:00
|
|
|
std::string Attributes::getAsString() const {
|
2008-01-03 07:42:30 +08:00
|
|
|
std::string Result;
|
2012-09-20 22:44:42 +08:00
|
|
|
if (hasZExtAttr())
|
2008-01-03 07:42:30 +08:00
|
|
|
Result += "zeroext ";
|
2012-09-20 22:44:42 +08:00
|
|
|
if (hasSExtAttr())
|
2008-01-03 07:42:30 +08:00
|
|
|
Result += "signext ";
|
2012-09-20 22:44:42 +08:00
|
|
|
if (hasNoReturnAttr())
|
2008-01-03 07:42:30 +08:00
|
|
|
Result += "noreturn ";
|
2012-09-20 22:44:42 +08:00
|
|
|
if (hasNoUnwindAttr())
|
2008-01-03 07:42:30 +08:00
|
|
|
Result += "nounwind ";
|
2012-09-20 22:44:42 +08:00
|
|
|
if (hasUWTableAttr())
|
2011-05-25 11:44:17 +08:00
|
|
|
Result += "uwtable ";
|
2012-09-20 22:44:42 +08:00
|
|
|
if (hasReturnsTwiceAttr())
|
2011-10-03 22:45:37 +08:00
|
|
|
Result += "returns_twice ";
|
2012-09-20 22:44:42 +08:00
|
|
|
if (hasInRegAttr())
|
2008-01-03 07:42:30 +08:00
|
|
|
Result += "inreg ";
|
2012-09-20 22:44:42 +08:00
|
|
|
if (hasNoAliasAttr())
|
2008-01-03 07:42:30 +08:00
|
|
|
Result += "noalias ";
|
2012-09-20 22:44:42 +08:00
|
|
|
if (hasNoCaptureAttr())
|
2008-12-19 17:38:31 +08:00
|
|
|
Result += "nocapture ";
|
2012-09-20 22:44:42 +08:00
|
|
|
if (hasStructRetAttr())
|
2009-07-18 02:07:26 +08:00
|
|
|
Result += "sret ";
|
2012-09-20 22:44:42 +08:00
|
|
|
if (hasByValAttr())
|
2008-01-03 07:42:30 +08:00
|
|
|
Result += "byval ";
|
2012-09-20 22:44:42 +08:00
|
|
|
if (hasNestAttr())
|
2008-01-03 07:42:30 +08:00
|
|
|
Result += "nest ";
|
2012-09-20 22:44:42 +08:00
|
|
|
if (hasReadNoneAttr())
|
2008-01-03 07:42:30 +08:00
|
|
|
Result += "readnone ";
|
2012-09-20 22:44:42 +08:00
|
|
|
if (hasReadOnlyAttr())
|
2008-01-03 07:42:30 +08:00
|
|
|
Result += "readonly ";
|
2012-09-20 22:44:42 +08:00
|
|
|
if (hasOptimizeForSizeAttr())
|
2008-09-27 06:53:05 +08:00
|
|
|
Result += "optsize ";
|
2012-09-20 22:44:42 +08:00
|
|
|
if (hasNoInlineAttr())
|
2008-09-27 06:53:05 +08:00
|
|
|
Result += "noinline ";
|
2012-09-20 22:44:42 +08:00
|
|
|
if (hasInlineHintAttr())
|
2010-02-06 09:16:28 +08:00
|
|
|
Result += "inlinehint ";
|
2012-09-20 22:44:42 +08:00
|
|
|
if (hasAlwaysInlineAttr())
|
2008-09-27 06:53:05 +08:00
|
|
|
Result += "alwaysinline ";
|
2012-09-20 22:44:42 +08:00
|
|
|
if (hasStackProtectAttr())
|
2008-11-13 09:02:14 +08:00
|
|
|
Result += "ssp ";
|
2012-09-20 22:44:42 +08:00
|
|
|
if (hasStackProtectReqAttr())
|
2008-11-13 09:02:14 +08:00
|
|
|
Result += "sspreq ";
|
2012-09-20 22:44:42 +08:00
|
|
|
if (hasNoRedZoneAttr())
|
2009-06-05 06:05:33 +08:00
|
|
|
Result += "noredzone ";
|
2012-09-20 22:44:42 +08:00
|
|
|
if (hasNoImplicitFloatAttr())
|
2009-06-06 05:57:13 +08:00
|
|
|
Result += "noimplicitfloat ";
|
2012-09-20 22:44:42 +08:00
|
|
|
if (hasNakedAttr())
|
2009-07-18 02:07:26 +08:00
|
|
|
Result += "naked ";
|
2012-09-20 22:44:42 +08:00
|
|
|
if (hasNonLazyBindAttr())
|
2011-06-16 04:36:13 +08:00
|
|
|
Result += "nonlazybind ";
|
2012-09-20 22:44:42 +08:00
|
|
|
if (hasAddressSafetyAttr())
|
2012-01-21 01:56:17 +08:00
|
|
|
Result += "address_safety ";
|
2012-09-20 22:44:42 +08:00
|
|
|
if (*this & Attribute::StackAlignment) { // FIXME
|
2010-02-12 08:31:15 +08:00
|
|
|
Result += "alignstack(";
|
2012-09-20 22:44:42 +08:00
|
|
|
Result += utostr(Attribute::getStackAlignmentFromAttrs(*this));
|
2010-02-12 08:31:15 +08:00
|
|
|
Result += ") ";
|
|
|
|
}
|
2012-09-20 22:44:42 +08:00
|
|
|
if (*this & Attribute::Alignment) { // FIXME
|
2008-02-20 07:51:49 +08:00
|
|
|
Result += "align ";
|
2012-09-20 22:44:42 +08:00
|
|
|
Result += utostr(Attribute::getAlignmentFromAttrs(*this));
|
2008-02-20 07:51:49 +08:00
|
|
|
Result += " ";
|
|
|
|
}
|
2008-08-05 23:51:44 +08:00
|
|
|
// Trim the trailing space.
|
2008-12-19 17:38:31 +08:00
|
|
|
assert(!Result.empty() && "Unknown attribute!");
|
2008-08-05 23:51:44 +08:00
|
|
|
Result.erase(Result.end()-1);
|
2008-01-03 07:42:30 +08:00
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2011-07-18 12:54:35 +08:00
|
|
|
Attributes Attribute::typeIncompatible(Type *Ty) {
|
2008-09-24 07:03:40 +08:00
|
|
|
Attributes Incompatible = None;
|
2008-03-13 01:45:29 +08:00
|
|
|
|
2010-02-16 00:12:20 +08:00
|
|
|
if (!Ty->isIntegerTy())
|
2008-03-13 01:45:29 +08:00
|
|
|
// Attributes that only apply to integers.
|
|
|
|
Incompatible |= SExt | ZExt;
|
|
|
|
|
2010-02-16 19:11:14 +08:00
|
|
|
if (!Ty->isPointerTy())
|
2008-03-13 01:45:29 +08:00
|
|
|
// Attributes that only apply to pointers.
|
2008-12-19 17:38:31 +08:00
|
|
|
Incompatible |= ByVal | Nest | NoAlias | StructRet | NoCapture;
|
2008-03-13 01:45:29 +08:00
|
|
|
|
|
|
|
return Incompatible;
|
2008-01-03 07:42:30 +08:00
|
|
|
}
|
|
|
|
|
2008-03-13 01:45:29 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2008-09-24 08:29:49 +08:00
|
|
|
// AttributeListImpl Definition
|
2008-03-13 01:45:29 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2010-11-19 02:59:13 +08:00
|
|
|
namespace llvm {
|
|
|
|
class AttributeListImpl;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ManagedStatic<FoldingSet<AttributeListImpl> > AttributesLists;
|
2010-11-09 08:27:03 +08:00
|
|
|
|
2008-03-13 01:45:29 +08:00
|
|
|
namespace llvm {
|
2010-11-09 08:27:03 +08:00
|
|
|
static ManagedStatic<sys::SmartMutex<true> > ALMutex;
|
|
|
|
|
2008-09-24 08:29:49 +08:00
|
|
|
class AttributeListImpl : public FoldingSetNode {
|
2009-08-21 03:03:20 +08:00
|
|
|
sys::cas_flag RefCount;
|
2008-03-13 01:45:29 +08:00
|
|
|
|
2008-09-26 05:00:45 +08:00
|
|
|
// AttributesList is uniqued, these should not be publicly available.
|
2012-09-18 10:01:41 +08:00
|
|
|
void operator=(const AttributeListImpl &) LLVM_DELETED_FUNCTION;
|
|
|
|
AttributeListImpl(const AttributeListImpl &) LLVM_DELETED_FUNCTION;
|
2008-09-24 08:29:49 +08:00
|
|
|
~AttributeListImpl(); // Private implementation
|
2008-03-13 01:45:29 +08:00
|
|
|
public:
|
2008-09-26 05:00:45 +08:00
|
|
|
SmallVector<AttributeWithIndex, 4> Attrs;
|
2008-03-13 01:45:29 +08:00
|
|
|
|
2012-05-28 09:47:44 +08:00
|
|
|
AttributeListImpl(ArrayRef<AttributeWithIndex> attrs)
|
|
|
|
: Attrs(attrs.begin(), attrs.end()) {
|
2008-03-13 01:45:29 +08:00
|
|
|
RefCount = 0;
|
|
|
|
}
|
|
|
|
|
2010-11-09 08:27:03 +08:00
|
|
|
void AddRef() {
|
|
|
|
sys::SmartScopedLock<true> Lock(*ALMutex);
|
|
|
|
++RefCount;
|
|
|
|
}
|
2009-08-21 03:03:20 +08:00
|
|
|
void DropRef() {
|
2010-11-09 08:27:03 +08:00
|
|
|
sys::SmartScopedLock<true> Lock(*ALMutex);
|
2010-11-19 02:59:13 +08:00
|
|
|
if (!AttributesLists.isConstructed())
|
|
|
|
return;
|
2010-11-10 01:47:10 +08:00
|
|
|
sys::cas_flag new_val = --RefCount;
|
2010-11-10 01:46:38 +08:00
|
|
|
if (new_val == 0)
|
2010-11-09 08:27:03 +08:00
|
|
|
delete this;
|
2009-08-21 03:03:20 +08:00
|
|
|
}
|
2008-03-13 01:45:29 +08:00
|
|
|
|
|
|
|
void Profile(FoldingSetNodeID &ID) const {
|
2012-05-28 09:47:44 +08:00
|
|
|
Profile(ID, Attrs);
|
2008-03-13 01:45:29 +08:00
|
|
|
}
|
2012-05-28 09:47:44 +08:00
|
|
|
static void Profile(FoldingSetNodeID &ID, ArrayRef<AttributeWithIndex> Attrs){
|
|
|
|
for (unsigned i = 0, e = Attrs.size(); i != e; ++i) {
|
|
|
|
ID.AddInteger(Attrs[i].Attrs.Raw());
|
|
|
|
ID.AddInteger(Attrs[i].Index);
|
2012-01-21 01:56:17 +08:00
|
|
|
}
|
2008-03-13 01:45:29 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2008-01-03 07:42:30 +08:00
|
|
|
|
2008-09-24 08:29:49 +08:00
|
|
|
AttributeListImpl::~AttributeListImpl() {
|
2010-11-09 08:27:03 +08:00
|
|
|
// NOTE: Lock must be acquired by caller.
|
2008-09-26 05:00:45 +08:00
|
|
|
AttributesLists->RemoveNode(this);
|
2008-03-13 01:45:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-28 09:47:44 +08:00
|
|
|
AttrListPtr AttrListPtr::get(ArrayRef<AttributeWithIndex> Attrs) {
|
2008-09-26 05:00:45 +08:00
|
|
|
// If there are no attributes then return a null AttributesList pointer.
|
2012-05-28 09:47:44 +08:00
|
|
|
if (Attrs.empty())
|
2008-09-26 05:00:45 +08:00
|
|
|
return AttrListPtr();
|
2008-03-13 01:45:29 +08:00
|
|
|
|
2008-01-03 07:42:30 +08:00
|
|
|
#ifndef NDEBUG
|
2012-05-28 09:47:44 +08:00
|
|
|
for (unsigned i = 0, e = Attrs.size(); i != e; ++i) {
|
2008-09-26 05:00:45 +08:00
|
|
|
assert(Attrs[i].Attrs != Attribute::None &&
|
|
|
|
"Pointless attribute!");
|
2008-03-13 01:45:29 +08:00
|
|
|
assert((!i || Attrs[i-1].Index < Attrs[i].Index) &&
|
2008-09-26 05:00:45 +08:00
|
|
|
"Misordered AttributesList!");
|
2008-01-03 07:42:30 +08:00
|
|
|
}
|
|
|
|
#endif
|
2008-03-13 01:45:29 +08:00
|
|
|
|
2008-01-03 07:42:30 +08:00
|
|
|
// Otherwise, build a key to look up the existing attributes.
|
|
|
|
FoldingSetNodeID ID;
|
2012-05-28 09:47:44 +08:00
|
|
|
AttributeListImpl::Profile(ID, Attrs);
|
2008-01-03 07:42:30 +08:00
|
|
|
void *InsertPos;
|
2009-08-18 01:10:58 +08:00
|
|
|
|
|
|
|
sys::SmartScopedLock<true> Lock(*ALMutex);
|
|
|
|
|
2008-09-24 08:29:49 +08:00
|
|
|
AttributeListImpl *PAL =
|
2008-09-26 05:00:45 +08:00
|
|
|
AttributesLists->FindNodeOrInsertPos(ID, InsertPos);
|
2008-03-13 01:45:29 +08:00
|
|
|
|
2008-01-03 07:42:30 +08:00
|
|
|
// If we didn't find any existing attributes of the same shape then
|
|
|
|
// create a new one and insert it.
|
|
|
|
if (!PAL) {
|
2012-05-28 09:47:44 +08:00
|
|
|
PAL = new AttributeListImpl(Attrs);
|
2008-09-26 05:00:45 +08:00
|
|
|
AttributesLists->InsertNode(PAL, InsertPos);
|
2008-01-03 07:42:30 +08:00
|
|
|
}
|
2008-03-13 01:45:29 +08:00
|
|
|
|
2008-09-26 05:00:45 +08:00
|
|
|
// Return the AttributesList that we found or created.
|
|
|
|
return AttrListPtr(PAL);
|
2008-01-03 07:42:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-13 01:45:29 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2008-09-26 05:00:45 +08:00
|
|
|
// AttrListPtr Method Implementations
|
2008-03-13 01:45:29 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2008-01-03 07:42:30 +08:00
|
|
|
|
2008-09-26 05:00:45 +08:00
|
|
|
AttrListPtr::AttrListPtr(AttributeListImpl *LI) : AttrList(LI) {
|
2008-03-13 01:45:29 +08:00
|
|
|
if (LI) LI->AddRef();
|
|
|
|
}
|
2008-01-03 07:42:30 +08:00
|
|
|
|
2008-09-26 05:00:45 +08:00
|
|
|
AttrListPtr::AttrListPtr(const AttrListPtr &P) : AttrList(P.AttrList) {
|
|
|
|
if (AttrList) AttrList->AddRef();
|
2008-03-13 01:45:29 +08:00
|
|
|
}
|
|
|
|
|
2008-09-26 05:00:45 +08:00
|
|
|
const AttrListPtr &AttrListPtr::operator=(const AttrListPtr &RHS) {
|
2010-09-16 08:27:35 +08:00
|
|
|
sys::SmartScopedLock<true> Lock(*ALMutex);
|
2008-09-26 05:00:45 +08:00
|
|
|
if (AttrList == RHS.AttrList) return *this;
|
|
|
|
if (AttrList) AttrList->DropRef();
|
|
|
|
AttrList = RHS.AttrList;
|
|
|
|
if (AttrList) AttrList->AddRef();
|
2008-03-13 01:45:29 +08:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2008-09-26 05:00:45 +08:00
|
|
|
AttrListPtr::~AttrListPtr() {
|
|
|
|
if (AttrList) AttrList->DropRef();
|
2008-03-13 01:45:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// getNumSlots - Return the number of slots used in this attribute list.
|
|
|
|
/// This is the number of arguments that have an attribute set on them
|
|
|
|
/// (including the function itself).
|
2008-09-26 05:00:45 +08:00
|
|
|
unsigned AttrListPtr::getNumSlots() const {
|
|
|
|
return AttrList ? AttrList->Attrs.size() : 0;
|
2008-03-13 01:45:29 +08:00
|
|
|
}
|
2008-01-03 07:42:30 +08:00
|
|
|
|
2008-09-26 05:00:45 +08:00
|
|
|
/// getSlot - Return the AttributeWithIndex at the specified slot. This
|
|
|
|
/// holds a number plus a set of attributes.
|
|
|
|
const AttributeWithIndex &AttrListPtr::getSlot(unsigned Slot) const {
|
|
|
|
assert(AttrList && Slot < AttrList->Attrs.size() && "Slot # out of range!");
|
|
|
|
return AttrList->Attrs[Slot];
|
2008-03-13 01:45:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-26 05:00:45 +08:00
|
|
|
/// getAttributes - The attributes for the specified index are
|
|
|
|
/// returned. Attributes for the result are denoted with Idx = 0.
|
2008-09-24 06:35:17 +08:00
|
|
|
/// Function notes are denoted with idx = ~0.
|
2008-09-26 05:00:45 +08:00
|
|
|
Attributes AttrListPtr::getAttributes(unsigned Idx) const {
|
|
|
|
if (AttrList == 0) return Attribute::None;
|
2008-03-13 01:45:29 +08:00
|
|
|
|
2008-09-26 05:00:45 +08:00
|
|
|
const SmallVector<AttributeWithIndex, 4> &Attrs = AttrList->Attrs;
|
2008-03-13 01:45:29 +08:00
|
|
|
for (unsigned i = 0, e = Attrs.size(); i != e && Attrs[i].Index <= Idx; ++i)
|
|
|
|
if (Attrs[i].Index == Idx)
|
|
|
|
return Attrs[i].Attrs;
|
2008-09-26 05:00:45 +08:00
|
|
|
return Attribute::None;
|
2008-03-13 01:45:29 +08:00
|
|
|
}
|
2008-01-03 07:42:30 +08:00
|
|
|
|
2008-03-13 01:45:29 +08:00
|
|
|
/// hasAttrSomewhere - Return true if the specified attribute is set for at
|
|
|
|
/// least one parameter or for the return value.
|
2008-09-26 05:00:45 +08:00
|
|
|
bool AttrListPtr::hasAttrSomewhere(Attributes Attr) const {
|
|
|
|
if (AttrList == 0) return false;
|
2008-03-13 01:45:29 +08:00
|
|
|
|
2008-09-26 05:00:45 +08:00
|
|
|
const SmallVector<AttributeWithIndex, 4> &Attrs = AttrList->Attrs;
|
2008-03-13 01:45:29 +08:00
|
|
|
for (unsigned i = 0, e = Attrs.size(); i != e; ++i)
|
|
|
|
if (Attrs[i].Attrs & Attr)
|
|
|
|
return true;
|
|
|
|
return false;
|
2008-01-03 07:42:30 +08:00
|
|
|
}
|
|
|
|
|
2008-03-13 01:45:29 +08:00
|
|
|
|
2008-09-26 05:00:45 +08:00
|
|
|
AttrListPtr AttrListPtr::addAttr(unsigned Idx, Attributes Attrs) const {
|
|
|
|
Attributes OldAttrs = getAttributes(Idx);
|
2008-02-20 07:51:49 +08:00
|
|
|
#ifndef NDEBUG
|
|
|
|
// FIXME it is not obvious how this should work for alignment.
|
|
|
|
// For now, say we can't change a known alignment.
|
2008-09-26 05:00:45 +08:00
|
|
|
Attributes OldAlign = OldAttrs & Attribute::Alignment;
|
|
|
|
Attributes NewAlign = Attrs & Attribute::Alignment;
|
2008-02-20 20:07:57 +08:00
|
|
|
assert((!OldAlign || !NewAlign || OldAlign == NewAlign) &&
|
2008-02-20 07:51:49 +08:00
|
|
|
"Attempt to change alignment!");
|
|
|
|
#endif
|
2008-03-13 01:45:29 +08:00
|
|
|
|
2008-09-24 07:03:40 +08:00
|
|
|
Attributes NewAttrs = OldAttrs | Attrs;
|
2008-01-03 07:42:30 +08:00
|
|
|
if (NewAttrs == OldAttrs)
|
2008-03-13 01:45:29 +08:00
|
|
|
return *this;
|
|
|
|
|
2008-09-26 05:00:45 +08:00
|
|
|
SmallVector<AttributeWithIndex, 8> NewAttrList;
|
|
|
|
if (AttrList == 0)
|
|
|
|
NewAttrList.push_back(AttributeWithIndex::get(Idx, Attrs));
|
2008-03-13 01:45:29 +08:00
|
|
|
else {
|
2008-09-26 05:00:45 +08:00
|
|
|
const SmallVector<AttributeWithIndex, 4> &OldAttrList = AttrList->Attrs;
|
2008-03-13 01:45:29 +08:00
|
|
|
unsigned i = 0, e = OldAttrList.size();
|
|
|
|
// Copy attributes for arguments before this one.
|
|
|
|
for (; i != e && OldAttrList[i].Index < Idx; ++i)
|
|
|
|
NewAttrList.push_back(OldAttrList[i]);
|
|
|
|
|
|
|
|
// If there are attributes already at this index, merge them in.
|
|
|
|
if (i != e && OldAttrList[i].Index == Idx) {
|
|
|
|
Attrs |= OldAttrList[i].Attrs;
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
2008-09-26 05:00:45 +08:00
|
|
|
NewAttrList.push_back(AttributeWithIndex::get(Idx, Attrs));
|
2008-03-13 01:45:29 +08:00
|
|
|
|
|
|
|
// Copy attributes for arguments after this one.
|
|
|
|
NewAttrList.insert(NewAttrList.end(),
|
|
|
|
OldAttrList.begin()+i, OldAttrList.end());
|
|
|
|
}
|
|
|
|
|
2012-05-28 09:47:44 +08:00
|
|
|
return get(NewAttrList);
|
2008-01-03 07:42:30 +08:00
|
|
|
}
|
|
|
|
|
2008-09-26 05:00:45 +08:00
|
|
|
AttrListPtr AttrListPtr::removeAttr(unsigned Idx, Attributes Attrs) const {
|
2008-02-20 07:51:49 +08:00
|
|
|
#ifndef NDEBUG
|
|
|
|
// FIXME it is not obvious how this should work for alignment.
|
|
|
|
// For now, say we can't pass in alignment, which no current use does.
|
2008-09-26 05:00:45 +08:00
|
|
|
assert(!(Attrs & Attribute::Alignment) && "Attempt to exclude alignment!");
|
2008-02-20 07:51:49 +08:00
|
|
|
#endif
|
2008-09-26 05:00:45 +08:00
|
|
|
if (AttrList == 0) return AttrListPtr();
|
2008-03-13 01:45:29 +08:00
|
|
|
|
2008-09-26 05:00:45 +08:00
|
|
|
Attributes OldAttrs = getAttributes(Idx);
|
2008-09-24 07:03:40 +08:00
|
|
|
Attributes NewAttrs = OldAttrs & ~Attrs;
|
2008-01-03 07:42:30 +08:00
|
|
|
if (NewAttrs == OldAttrs)
|
2008-03-13 01:45:29 +08:00
|
|
|
return *this;
|
|
|
|
|
2008-09-26 05:00:45 +08:00
|
|
|
SmallVector<AttributeWithIndex, 8> NewAttrList;
|
|
|
|
const SmallVector<AttributeWithIndex, 4> &OldAttrList = AttrList->Attrs;
|
2008-03-13 01:45:29 +08:00
|
|
|
unsigned i = 0, e = OldAttrList.size();
|
|
|
|
|
|
|
|
// Copy attributes for arguments before this one.
|
|
|
|
for (; i != e && OldAttrList[i].Index < Idx; ++i)
|
|
|
|
NewAttrList.push_back(OldAttrList[i]);
|
|
|
|
|
|
|
|
// If there are attributes already at this index, merge them in.
|
|
|
|
assert(OldAttrList[i].Index == Idx && "Attribute isn't set?");
|
|
|
|
Attrs = OldAttrList[i].Attrs & ~Attrs;
|
|
|
|
++i;
|
|
|
|
if (Attrs) // If any attributes left for this parameter, add them.
|
2008-09-26 05:00:45 +08:00
|
|
|
NewAttrList.push_back(AttributeWithIndex::get(Idx, Attrs));
|
2008-03-13 01:45:29 +08:00
|
|
|
|
|
|
|
// Copy attributes for arguments after this one.
|
|
|
|
NewAttrList.insert(NewAttrList.end(),
|
|
|
|
OldAttrList.begin()+i, OldAttrList.end());
|
|
|
|
|
2012-05-28 09:47:44 +08:00
|
|
|
return get(NewAttrList);
|
2008-01-03 07:42:30 +08:00
|
|
|
}
|
|
|
|
|
2008-09-26 05:00:45 +08:00
|
|
|
void AttrListPtr::dump() const {
|
2010-01-05 09:29:58 +08:00
|
|
|
dbgs() << "PAL[ ";
|
2008-03-13 01:45:29 +08:00
|
|
|
for (unsigned i = 0; i < getNumSlots(); ++i) {
|
2008-09-26 05:00:45 +08:00
|
|
|
const AttributeWithIndex &PAWI = getSlot(i);
|
2010-01-05 09:29:58 +08:00
|
|
|
dbgs() << "{" << PAWI.Index << "," << PAWI.Attrs << "} ";
|
2008-03-13 01:45:29 +08:00
|
|
|
}
|
|
|
|
|
2010-01-05 09:29:58 +08:00
|
|
|
dbgs() << "]\n";
|
2008-01-07 02:27:01 +08:00
|
|
|
}
|