summaryrefslogtreecommitdiffstats
path: root/llvm/lib/IR
diff options
context:
space:
mode:
authorMichael Gottesman <mgottesman@apple.com>2013-06-27 00:25:01 +0000
committerMichael Gottesman <mgottesman@apple.com>2013-06-27 00:25:01 +0000
commit41748d7c86b06142f81c2742ce39114bce1c3a17 (patch)
tree65718734a59de6781c0045d1da651290ce20e32b /llvm/lib/IR
parent6467ff9aea6bfceb26388180ec2d26bc93446ed0 (diff)
downloadbcm5719-llvm-41748d7c86b06142f81c2742ce39114bce1c3a17.tar.gz
bcm5719-llvm-41748d7c86b06142f81c2742ce39114bce1c3a17.zip
Added support for the Builtin attribute.
The Builtin attribute is an attribute that can be placed on function call site that signal that even though a function is declared as being a builtin, rdar://problem/13727199 llvm-svn: 185049
Diffstat (limited to 'llvm/lib/IR')
-rw-r--r--llvm/lib/IR/Attributes.cpp3
-rw-r--r--llvm/lib/IR/Instructions.cpp4
-rw-r--r--llvm/lib/IR/Verifier.cpp16
3 files changed, 21 insertions, 2 deletions
diff --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp
index e48ebb13352..2160ea24641 100644
--- a/llvm/lib/IR/Attributes.cpp
+++ b/llvm/lib/IR/Attributes.cpp
@@ -157,6 +157,8 @@ std::string Attribute::getAsString(bool InAttrGrp) const {
return "sanitize_address";
if (hasAttribute(Attribute::AlwaysInline))
return "alwaysinline";
+ if (hasAttribute(Attribute::Builtin))
+ return "builtin";
if (hasAttribute(Attribute::ByVal))
return "byval";
if (hasAttribute(Attribute::InlineHint))
@@ -399,6 +401,7 @@ uint64_t AttributeImpl::getAttrMask(Attribute::AttrKind Val) {
case Attribute::NoBuiltin: return 1ULL << 38;
case Attribute::Returned: return 1ULL << 39;
case Attribute::Cold: return 1ULL << 40;
+ case Attribute::Builtin: return 1ULL << 41;
}
llvm_unreachable("Unsupported attribute type");
}
diff --git a/llvm/lib/IR/Instructions.cpp b/llvm/lib/IR/Instructions.cpp
index d58877ef773..5878f77dc17 100644
--- a/llvm/lib/IR/Instructions.cpp
+++ b/llvm/lib/IR/Instructions.cpp
@@ -346,7 +346,7 @@ void CallInst::removeAttribute(unsigned i, Attribute attr) {
setAttributes(PAL);
}
-bool CallInst::hasFnAttr(Attribute::AttrKind A) const {
+bool CallInst::hasFnAttrImpl(Attribute::AttrKind A) const {
if (AttributeList.hasAttribute(AttributeSet::FunctionIndex, A))
return true;
if (const Function *F = getCalledFunction())
@@ -574,7 +574,7 @@ void InvokeInst::setSuccessorV(unsigned idx, BasicBlock *B) {
return setSuccessor(idx, B);
}
-bool InvokeInst::hasFnAttr(Attribute::AttrKind A) const {
+bool InvokeInst::hasFnAttrImpl(Attribute::AttrKind A) const {
if (AttributeList.hasAttribute(AttributeSet::FunctionIndex, A))
return true;
if (const Function *F = getCalledFunction())
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 1b1b3b8a1ea..7123eaf18a0 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -692,6 +692,7 @@ void Verifier::VerifyAttributeTypes(AttributeSet Attrs, unsigned Idx,
I->getKindAsEnum() == Attribute::SanitizeMemory ||
I->getKindAsEnum() == Attribute::MinSize ||
I->getKindAsEnum() == Attribute::NoDuplicate ||
+ I->getKindAsEnum() == Attribute::Builtin ||
I->getKindAsEnum() == Attribute::NoBuiltin ||
I->getKindAsEnum() == Attribute::Cold) {
if (!isFunction)
@@ -877,6 +878,13 @@ void Verifier::visitFunction(Function &F) {
// Check function attributes.
VerifyFunctionAttrs(FT, Attrs, &F);
+ // On function declarations/definitions, we do not support the builtin
+ // attribute. We do not check this in VerifyFunctionAttrs since that is
+ // checking for Attributes that can/can not ever be on functions.
+ Assert1(!Attrs.hasAttribute(AttributeSet::FunctionIndex,
+ Attribute::Builtin),
+ "Attribute 'builtin' can only be applied to a callsite.", &F);
+
// Check that this function meets the restrictions on this calling convention.
switch (F.getCallingConv()) {
default:
@@ -1435,6 +1443,14 @@ void Verifier::VerifyCallSite(CallSite CS) {
"Function has metadata parameter but isn't an intrinsic", I);
}
+ // If the call site has the 'builtin' attribute, verify that it's applied to a
+ // direct call to a function with the 'nobuiltin' attribute.
+ if (CS.hasFnAttr(Attribute::Builtin))
+ Assert1(CS.getCalledFunction() &&
+ CS.getCalledFunction()->hasFnAttribute(Attribute::NoBuiltin),
+ "Attribute 'builtin' can only be used in a call to a function with "
+ "the 'nobuiltin' attribute.", I);
+
visitInstruction(*I);
}
OpenPOWER on IntegriCloud