|
@@ -1,4 +1,4 @@
|
|
-//===-- Attributes.cpp - Implement AttributesList -------------------------===//
|
|
|
|
|
|
+//===- Attributes.cpp - Implement AttributesList --------------------------===//
|
|
//
|
|
//
|
|
// The LLVM Compiler Infrastructure
|
|
// The LLVM Compiler Infrastructure
|
|
//
|
|
//
|
|
@@ -13,19 +13,35 @@
|
|
//
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
-#include "llvm/IR/Attributes.h"
|
|
|
|
-#include "llvm/IR/Function.h"
|
|
|
|
#include "AttributeImpl.h"
|
|
#include "AttributeImpl.h"
|
|
|
|
+#include "AttributeSetNode.h"
|
|
#include "LLVMContextImpl.h"
|
|
#include "LLVMContextImpl.h"
|
|
|
|
+#include "llvm/ADT/ArrayRef.h"
|
|
|
|
+#include "llvm/ADT/FoldingSet.h"
|
|
|
|
+#include "llvm/ADT/Optional.h"
|
|
|
|
+#include "llvm/ADT/SmallVector.h"
|
|
#include "llvm/ADT/STLExtras.h"
|
|
#include "llvm/ADT/STLExtras.h"
|
|
#include "llvm/ADT/StringExtras.h"
|
|
#include "llvm/ADT/StringExtras.h"
|
|
|
|
+#include "llvm/ADT/StringRef.h"
|
|
|
|
+#include "llvm/ADT/Twine.h"
|
|
|
|
+#include "llvm/IR/Attributes.h"
|
|
|
|
+#include "llvm/IR/Function.h"
|
|
|
|
+#include "llvm/IR/LLVMContext.h"
|
|
#include "llvm/IR/Type.h"
|
|
#include "llvm/IR/Type.h"
|
|
-#include "llvm/Support/Atomic.h"
|
|
|
|
|
|
+#include "llvm/Support/Compiler.h"
|
|
#include "llvm/Support/Debug.h"
|
|
#include "llvm/Support/Debug.h"
|
|
-#include "llvm/Support/ManagedStatic.h"
|
|
|
|
-#include "llvm/Support/Mutex.h"
|
|
|
|
|
|
+#include "llvm/Support/ErrorHandling.h"
|
|
|
|
+#include "llvm/Support/MathExtras.h"
|
|
#include "llvm/Support/raw_ostream.h"
|
|
#include "llvm/Support/raw_ostream.h"
|
|
#include <algorithm>
|
|
#include <algorithm>
|
|
|
|
+#include <cassert>
|
|
|
|
+#include <cstdint>
|
|
|
|
+#include <limits>
|
|
|
|
+#include <map>
|
|
|
|
+#include <string>
|
|
|
|
+#include <tuple>
|
|
|
|
+#include <utility>
|
|
|
|
+
|
|
using namespace llvm;
|
|
using namespace llvm;
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
//===----------------------------------------------------------------------===//
|
|
@@ -411,9 +427,12 @@ bool Attribute::operator<(Attribute A) const {
|
|
//===----------------------------------------------------------------------===//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
// Pin the vtables to this file.
|
|
// Pin the vtables to this file.
|
|
-AttributeImpl::~AttributeImpl() {}
|
|
|
|
|
|
+AttributeImpl::~AttributeImpl() = default;
|
|
|
|
+
|
|
void EnumAttributeImpl::anchor() {}
|
|
void EnumAttributeImpl::anchor() {}
|
|
|
|
+
|
|
void IntAttributeImpl::anchor() {}
|
|
void IntAttributeImpl::anchor() {}
|
|
|
|
+
|
|
void StringAttributeImpl::anchor() {}
|
|
void StringAttributeImpl::anchor() {}
|
|
|
|
|
|
bool AttributeImpl::hasAttribute(Attribute::AttrKind A) const {
|
|
bool AttributeImpl::hasAttribute(Attribute::AttrKind A) const {
|
|
@@ -593,7 +612,7 @@ LLVM_DUMP_METHOD void AttributeSetImpl::dump() const {
|
|
|
|
|
|
AttributeSet
|
|
AttributeSet
|
|
AttributeSet::getImpl(LLVMContext &C,
|
|
AttributeSet::getImpl(LLVMContext &C,
|
|
- ArrayRef<std::pair<unsigned, AttributeSetNode*> > Attrs) {
|
|
|
|
|
|
+ ArrayRef<std::pair<unsigned, AttributeSetNode*>> Attrs) {
|
|
LLVMContextImpl *pImpl = C.pImpl;
|
|
LLVMContextImpl *pImpl = C.pImpl;
|
|
FoldingSetNodeID ID;
|
|
FoldingSetNodeID ID;
|
|
AttributeSetImpl::Profile(ID, Attrs);
|
|
AttributeSetImpl::Profile(ID, Attrs);
|
|
@@ -616,7 +635,7 @@ AttributeSet::getImpl(LLVMContext &C,
|
|
}
|
|
}
|
|
|
|
|
|
AttributeSet AttributeSet::get(LLVMContext &C,
|
|
AttributeSet AttributeSet::get(LLVMContext &C,
|
|
- ArrayRef<std::pair<unsigned, Attribute> > Attrs){
|
|
|
|
|
|
+ ArrayRef<std::pair<unsigned, Attribute>> Attrs) {
|
|
// If there are no attributes then return a null AttributesList pointer.
|
|
// If there are no attributes then return a null AttributesList pointer.
|
|
if (Attrs.empty())
|
|
if (Attrs.empty())
|
|
return AttributeSet();
|
|
return AttributeSet();
|
|
@@ -635,7 +654,7 @@ AttributeSet AttributeSet::get(LLVMContext &C,
|
|
// Create a vector if (unsigned, AttributeSetNode*) pairs from the attributes
|
|
// Create a vector if (unsigned, AttributeSetNode*) pairs from the attributes
|
|
// list.
|
|
// list.
|
|
SmallVector<std::pair<unsigned, AttributeSetNode*>, 8> AttrPairVec;
|
|
SmallVector<std::pair<unsigned, AttributeSetNode*>, 8> AttrPairVec;
|
|
- for (ArrayRef<std::pair<unsigned, Attribute> >::iterator I = Attrs.begin(),
|
|
|
|
|
|
+ for (ArrayRef<std::pair<unsigned, Attribute>>::iterator I = Attrs.begin(),
|
|
E = Attrs.end(); I != E; ) {
|
|
E = Attrs.end(); I != E; ) {
|
|
unsigned Index = I->first;
|
|
unsigned Index = I->first;
|
|
SmallVector<Attribute, 4> AttrVec;
|
|
SmallVector<Attribute, 4> AttrVec;
|
|
@@ -652,7 +671,7 @@ AttributeSet AttributeSet::get(LLVMContext &C,
|
|
|
|
|
|
AttributeSet AttributeSet::get(LLVMContext &C,
|
|
AttributeSet AttributeSet::get(LLVMContext &C,
|
|
ArrayRef<std::pair<unsigned,
|
|
ArrayRef<std::pair<unsigned,
|
|
- AttributeSetNode*> > Attrs) {
|
|
|
|
|
|
+ AttributeSetNode*>> Attrs) {
|
|
// If there are no attributes then return a null AttributesList pointer.
|
|
// If there are no attributes then return a null AttributesList pointer.
|
|
if (Attrs.empty())
|
|
if (Attrs.empty())
|
|
return AttributeSet();
|
|
return AttributeSet();
|
|
@@ -760,7 +779,7 @@ AttributeSet AttributeSet::addAttribute(LLVMContext &C, unsigned Index,
|
|
|
|
|
|
AttributeSet AttributeSet::addAttribute(LLVMContext &C, unsigned Index,
|
|
AttributeSet AttributeSet::addAttribute(LLVMContext &C, unsigned Index,
|
|
StringRef Kind, StringRef Value) const {
|
|
StringRef Kind, StringRef Value) const {
|
|
- llvm::AttrBuilder B;
|
|
|
|
|
|
+ AttrBuilder B;
|
|
B.addAttribute(Kind, Value);
|
|
B.addAttribute(Kind, Value);
|
|
return addAttributes(C, Index, AttributeSet::get(C, Index, B));
|
|
return addAttributes(C, Index, AttributeSet::get(C, Index, B));
|
|
}
|
|
}
|
|
@@ -937,7 +956,7 @@ AttributeSet AttributeSet::removeAttributes(LLVMContext &C, unsigned Index,
|
|
|
|
|
|
AttributeSet AttributeSet::addDereferenceableAttr(LLVMContext &C, unsigned Index,
|
|
AttributeSet AttributeSet::addDereferenceableAttr(LLVMContext &C, unsigned Index,
|
|
uint64_t Bytes) const {
|
|
uint64_t Bytes) const {
|
|
- llvm::AttrBuilder B;
|
|
|
|
|
|
+ AttrBuilder B;
|
|
B.addDereferenceableAttr(Bytes);
|
|
B.addDereferenceableAttr(Bytes);
|
|
return addAttributes(C, Index, AttributeSet::get(C, Index, B));
|
|
return addAttributes(C, Index, AttributeSet::get(C, Index, B));
|
|
}
|
|
}
|
|
@@ -945,7 +964,7 @@ AttributeSet AttributeSet::addDereferenceableAttr(LLVMContext &C, unsigned Index
|
|
AttributeSet AttributeSet::addDereferenceableOrNullAttr(LLVMContext &C,
|
|
AttributeSet AttributeSet::addDereferenceableOrNullAttr(LLVMContext &C,
|
|
unsigned Index,
|
|
unsigned Index,
|
|
uint64_t Bytes) const {
|
|
uint64_t Bytes) const {
|
|
- llvm::AttrBuilder B;
|
|
|
|
|
|
+ AttrBuilder B;
|
|
B.addDereferenceableOrNullAttr(Bytes);
|
|
B.addDereferenceableOrNullAttr(Bytes);
|
|
return addAttributes(C, Index, AttributeSet::get(C, Index, B));
|
|
return addAttributes(C, Index, AttributeSet::get(C, Index, B));
|
|
}
|
|
}
|
|
@@ -954,7 +973,7 @@ AttributeSet
|
|
AttributeSet::addAllocSizeAttr(LLVMContext &C, unsigned Index,
|
|
AttributeSet::addAllocSizeAttr(LLVMContext &C, unsigned Index,
|
|
unsigned ElemSizeArg,
|
|
unsigned ElemSizeArg,
|
|
const Optional<unsigned> &NumElemsArg) {
|
|
const Optional<unsigned> &NumElemsArg) {
|
|
- llvm::AttrBuilder B;
|
|
|
|
|
|
+ AttrBuilder B;
|
|
B.addAllocSizeAttr(ElemSizeArg, NumElemsArg);
|
|
B.addAllocSizeAttr(ElemSizeArg, NumElemsArg);
|
|
return addAttributes(C, Index, AttributeSet::get(C, Index, B));
|
|
return addAttributes(C, Index, AttributeSet::get(C, Index, B));
|
|
}
|
|
}
|
|
@@ -970,7 +989,7 @@ LLVMContext &AttributeSet::getContext() const {
|
|
AttributeSet AttributeSet::getParamAttributes(unsigned Index) const {
|
|
AttributeSet AttributeSet::getParamAttributes(unsigned Index) const {
|
|
return pImpl && hasAttributes(Index) ?
|
|
return pImpl && hasAttributes(Index) ?
|
|
AttributeSet::get(pImpl->getContext(),
|
|
AttributeSet::get(pImpl->getContext(),
|
|
- ArrayRef<std::pair<unsigned, AttributeSetNode*> >(
|
|
|
|
|
|
+ ArrayRef<std::pair<unsigned, AttributeSetNode*>>(
|
|
std::make_pair(Index, getAttributes(Index)))) :
|
|
std::make_pair(Index, getAttributes(Index)))) :
|
|
AttributeSet();
|
|
AttributeSet();
|
|
}
|
|
}
|
|
@@ -978,7 +997,7 @@ AttributeSet AttributeSet::getParamAttributes(unsigned Index) const {
|
|
AttributeSet AttributeSet::getRetAttributes() const {
|
|
AttributeSet AttributeSet::getRetAttributes() const {
|
|
return pImpl && hasAttributes(ReturnIndex) ?
|
|
return pImpl && hasAttributes(ReturnIndex) ?
|
|
AttributeSet::get(pImpl->getContext(),
|
|
AttributeSet::get(pImpl->getContext(),
|
|
- ArrayRef<std::pair<unsigned, AttributeSetNode*> >(
|
|
|
|
|
|
+ ArrayRef<std::pair<unsigned, AttributeSetNode*>>(
|
|
std::make_pair(ReturnIndex,
|
|
std::make_pair(ReturnIndex,
|
|
getAttributes(ReturnIndex)))) :
|
|
getAttributes(ReturnIndex)))) :
|
|
AttributeSet();
|
|
AttributeSet();
|
|
@@ -987,7 +1006,7 @@ AttributeSet AttributeSet::getRetAttributes() const {
|
|
AttributeSet AttributeSet::getFnAttributes() const {
|
|
AttributeSet AttributeSet::getFnAttributes() const {
|
|
return pImpl && hasAttributes(FunctionIndex) ?
|
|
return pImpl && hasAttributes(FunctionIndex) ?
|
|
AttributeSet::get(pImpl->getContext(),
|
|
AttributeSet::get(pImpl->getContext(),
|
|
- ArrayRef<std::pair<unsigned, AttributeSetNode*> >(
|
|
|
|
|
|
+ ArrayRef<std::pair<unsigned, AttributeSetNode*>>(
|
|
std::make_pair(FunctionIndex,
|
|
std::make_pair(FunctionIndex,
|
|
getAttributes(FunctionIndex)))) :
|
|
getAttributes(FunctionIndex)))) :
|
|
AttributeSet();
|
|
AttributeSet();
|
|
@@ -1139,9 +1158,7 @@ LLVM_DUMP_METHOD void AttributeSet::dump() const {
|
|
// AttrBuilder Method Implementations
|
|
// AttrBuilder Method Implementations
|
|
//===----------------------------------------------------------------------===//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
-AttrBuilder::AttrBuilder(AttributeSet AS, unsigned Index)
|
|
|
|
- : Attrs(0), Alignment(0), StackAlignment(0), DerefBytes(0),
|
|
|
|
- DerefOrNullBytes(0), AllocSizeArgs(0) {
|
|
|
|
|
|
+AttrBuilder::AttrBuilder(AttributeSet AS, unsigned Index) {
|
|
AttributeSetImpl *pImpl = AS.pImpl;
|
|
AttributeSetImpl *pImpl = AS.pImpl;
|
|
if (!pImpl) return;
|
|
if (!pImpl) return;
|
|
|
|
|
|
@@ -1514,7 +1531,6 @@ bool AttributeFuncs::areInlineCompatible(const Function &Caller,
|
|
return hasCompatibleFnAttrs(Caller, Callee);
|
|
return hasCompatibleFnAttrs(Caller, Callee);
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
void AttributeFuncs::mergeAttributesForInlining(Function &Caller,
|
|
void AttributeFuncs::mergeAttributesForInlining(Function &Caller,
|
|
const Function &Callee) {
|
|
const Function &Callee) {
|
|
mergeFnAttrs(Caller, Callee);
|
|
mergeFnAttrs(Caller, Callee);
|