2003-10-13 05:32:08 +02:00
|
|
|
//===-- Function.cpp - Implement the Global object classes ----------------===//
|
2005-04-22 01:48:37 +02:00
|
|
|
//
|
2003-10-20 21:43:21 +02:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 21:36:04 +01:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-22 01:48:37 +02:00
|
|
|
//
|
2003-10-20 21:43:21 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
2001-06-06 22:29:01 +02:00
|
|
|
//
|
2013-01-02 10:10:48 +01:00
|
|
|
// This file implements the Function class for the IR library.
|
2001-06-06 22:29:01 +02:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2013-01-02 12:36:10 +01:00
|
|
|
#include "llvm/IR/Function.h"
|
2013-03-01 19:48:54 +01:00
|
|
|
#include "LLVMContextImpl.h"
|
2012-12-03 17:50:05 +01:00
|
|
|
#include "SymbolTableListTraitsImpl.h"
|
|
|
|
#include "llvm/ADT/DenseMap.h"
|
|
|
|
#include "llvm/ADT/STLExtras.h"
|
|
|
|
#include "llvm/ADT/StringExtras.h"
|
|
|
|
#include "llvm/CodeGen/ValueTypes.h"
|
2013-01-02 12:36:10 +01:00
|
|
|
#include "llvm/IR/DerivedTypes.h"
|
|
|
|
#include "llvm/IR/IntrinsicInst.h"
|
|
|
|
#include "llvm/IR/LLVMContext.h"
|
|
|
|
#include "llvm/IR/Module.h"
|
2010-03-24 14:21:49 +01:00
|
|
|
#include "llvm/Support/CallSite.h"
|
2011-10-05 22:05:13 +02:00
|
|
|
#include "llvm/Support/InstIterator.h"
|
2004-09-02 00:55:40 +02:00
|
|
|
#include "llvm/Support/LeakDetector.h"
|
2009-06-18 00:23:31 +02:00
|
|
|
#include "llvm/Support/ManagedStatic.h"
|
2010-11-29 19:16:10 +01:00
|
|
|
#include "llvm/Support/RWMutex.h"
|
2012-12-03 17:50:05 +01:00
|
|
|
#include "llvm/Support/StringPool.h"
|
2010-11-29 19:16:10 +01:00
|
|
|
#include "llvm/Support/Threading.h"
|
2003-11-21 21:23:48 +01:00
|
|
|
using namespace llvm;
|
2003-11-11 23:41:34 +01:00
|
|
|
|
2002-06-25 18:13:24 +02:00
|
|
|
// Explicit instantiations of SymbolTableListTraits since some of the methods
|
|
|
|
// are not in the public header file...
|
2009-12-19 01:55:12 +01:00
|
|
|
template class llvm::SymbolTableListTraits<Argument, Function>;
|
|
|
|
template class llvm::SymbolTableListTraits<BasicBlock, Function>;
|
2001-06-06 22:29:01 +02:00
|
|
|
|
2002-04-09 21:39:35 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Argument Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2011-12-20 03:50:00 +01:00
|
|
|
void Argument::anchor() { }
|
|
|
|
|
2011-07-18 06:54:35 +02:00
|
|
|
Argument::Argument(Type *Ty, const Twine &Name, Function *Par)
|
2007-02-12 06:18:08 +01:00
|
|
|
: Value(Ty, Value::ArgumentVal) {
|
2002-09-06 23:33:15 +02:00
|
|
|
Parent = 0;
|
2002-09-08 20:59:35 +02:00
|
|
|
|
|
|
|
// Make sure that we get added to a function
|
|
|
|
LeakDetector::addGarbageObject(this);
|
|
|
|
|
2002-09-06 23:33:15 +02:00
|
|
|
if (Par)
|
|
|
|
Par->getArgumentList().push_back(this);
|
2007-02-12 06:18:08 +01:00
|
|
|
setName(Name);
|
2002-09-06 23:33:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Argument::setParent(Function *parent) {
|
2002-09-08 20:59:35 +02:00
|
|
|
if (getParent())
|
|
|
|
LeakDetector::addGarbageObject(this);
|
2002-09-06 23:33:15 +02:00
|
|
|
Parent = parent;
|
2002-09-08 20:59:35 +02:00
|
|
|
if (getParent())
|
|
|
|
LeakDetector::removeGarbageObject(this);
|
2002-09-06 23:33:15 +02:00
|
|
|
}
|
|
|
|
|
2008-01-24 18:47:11 +01:00
|
|
|
/// getArgNo - Return the index of this formal argument in its containing
|
2012-12-17 21:37:55 +01:00
|
|
|
/// function. For example in "void foo(int a, float b)" a is 0 and b is 1.
|
2008-01-24 18:47:11 +01:00
|
|
|
unsigned Argument::getArgNo() const {
|
|
|
|
const Function *F = getParent();
|
|
|
|
assert(F && "Argument is not in a function");
|
2012-12-17 21:37:55 +01:00
|
|
|
|
2008-01-24 18:47:11 +01:00
|
|
|
Function::const_arg_iterator AI = F->arg_begin();
|
|
|
|
unsigned ArgIdx = 0;
|
|
|
|
for (; &*AI != this; ++AI)
|
|
|
|
++ArgIdx;
|
|
|
|
|
|
|
|
return ArgIdx;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// hasByValAttr - Return true if this argument has the byval attribute on it
|
|
|
|
/// in its containing function.
|
|
|
|
bool Argument::hasByValAttr() const {
|
2010-02-16 12:11:14 +01:00
|
|
|
if (!getType()->isPointerTy()) return false;
|
2012-12-30 13:45:13 +01:00
|
|
|
return getParent()->getAttributes().
|
|
|
|
hasAttribute(getArgNo()+1, Attribute::ByVal);
|
2008-01-24 18:47:11 +01:00
|
|
|
}
|
|
|
|
|
2011-05-23 01:57:23 +02:00
|
|
|
unsigned Argument::getParamAlignment() const {
|
|
|
|
assert(getType()->isPointerTy() && "Only pointers have alignments");
|
|
|
|
return getParent()->getParamAlignment(getArgNo()+1);
|
2012-12-17 21:37:55 +01:00
|
|
|
|
2011-05-23 01:57:23 +02:00
|
|
|
}
|
|
|
|
|
2009-12-11 09:36:17 +01:00
|
|
|
/// hasNestAttr - Return true if this argument has the nest attribute on
|
|
|
|
/// it in its containing function.
|
|
|
|
bool Argument::hasNestAttr() const {
|
2010-02-16 12:11:14 +01:00
|
|
|
if (!getType()->isPointerTy()) return false;
|
2012-12-30 13:45:13 +01:00
|
|
|
return getParent()->getAttributes().
|
|
|
|
hasAttribute(getArgNo()+1, Attribute::Nest);
|
2009-12-11 09:36:17 +01:00
|
|
|
}
|
|
|
|
|
2008-01-24 18:47:11 +01:00
|
|
|
/// hasNoAliasAttr - Return true if this argument has the noalias attribute on
|
|
|
|
/// it in its containing function.
|
|
|
|
bool Argument::hasNoAliasAttr() const {
|
2010-02-16 12:11:14 +01:00
|
|
|
if (!getType()->isPointerTy()) return false;
|
2012-12-30 13:45:13 +01:00
|
|
|
return getParent()->getAttributes().
|
|
|
|
hasAttribute(getArgNo()+1, Attribute::NoAlias);
|
2008-01-24 18:47:11 +01:00
|
|
|
}
|
|
|
|
|
2008-12-31 19:08:59 +01:00
|
|
|
/// hasNoCaptureAttr - Return true if this argument has the nocapture attribute
|
|
|
|
/// on it in its containing function.
|
|
|
|
bool Argument::hasNoCaptureAttr() const {
|
2010-02-16 12:11:14 +01:00
|
|
|
if (!getType()->isPointerTy()) return false;
|
2012-12-30 13:45:13 +01:00
|
|
|
return getParent()->getAttributes().
|
|
|
|
hasAttribute(getArgNo()+1, Attribute::NoCapture);
|
2008-12-31 19:08:59 +01:00
|
|
|
}
|
|
|
|
|
2008-02-18 00:22:28 +01:00
|
|
|
/// hasSRetAttr - Return true if this argument has the sret attribute on
|
|
|
|
/// it in its containing function.
|
|
|
|
bool Argument::hasStructRetAttr() const {
|
2010-02-16 12:11:14 +01:00
|
|
|
if (!getType()->isPointerTy()) return false;
|
2008-05-15 12:04:30 +02:00
|
|
|
if (this != getParent()->arg_begin())
|
|
|
|
return false; // StructRet param must be first param
|
2012-12-30 13:45:13 +01:00
|
|
|
return getParent()->getAttributes().
|
|
|
|
hasAttribute(1, Attribute::StructRet);
|
2008-02-18 00:22:28 +01:00
|
|
|
}
|
|
|
|
|
2013-04-20 07:14:40 +02:00
|
|
|
/// hasReturnedAttr - Return true if this argument has the returned attribute on
|
|
|
|
/// it in its containing function.
|
|
|
|
bool Argument::hasReturnedAttr() const {
|
|
|
|
return getParent()->getAttributes().
|
|
|
|
hasAttribute(getArgNo()+1, Attribute::Returned);
|
|
|
|
}
|
|
|
|
|
2013-07-06 02:29:58 +02:00
|
|
|
/// Return true if this argument has the readonly or readnone attribute on it
|
|
|
|
/// in its containing function.
|
|
|
|
bool Argument::onlyReadsMemory() const {
|
|
|
|
return getParent()->getAttributes().
|
|
|
|
hasAttribute(getArgNo()+1, Attribute::ReadOnly) ||
|
|
|
|
getParent()->getAttributes().
|
|
|
|
hasAttribute(getArgNo()+1, Attribute::ReadNone);
|
|
|
|
}
|
|
|
|
|
2013-01-23 07:14:59 +01:00
|
|
|
/// addAttr - Add attributes to an argument.
|
|
|
|
void Argument::addAttr(AttributeSet AS) {
|
2013-02-21 20:46:51 +01:00
|
|
|
assert(AS.getNumSlots() <= 1 &&
|
2013-02-21 00:04:11 +01:00
|
|
|
"Trying to add more than one attribute set to an argument!");
|
|
|
|
AttrBuilder B(AS, AS.getSlotIndex(0));
|
|
|
|
getParent()->addAttributes(getArgNo() + 1,
|
|
|
|
AttributeSet::get(Parent->getContext(),
|
|
|
|
getArgNo() + 1, B));
|
2008-04-28 19:37:06 +02:00
|
|
|
}
|
2008-07-08 11:41:30 +02:00
|
|
|
|
2013-01-23 07:14:59 +01:00
|
|
|
/// removeAttr - Remove attributes from an argument.
|
|
|
|
void Argument::removeAttr(AttributeSet AS) {
|
2013-02-21 20:46:51 +01:00
|
|
|
assert(AS.getNumSlots() <= 1 &&
|
2013-02-21 00:04:11 +01:00
|
|
|
"Trying to remove more than one attribute set from an argument!");
|
|
|
|
AttrBuilder B(AS, AS.getSlotIndex(0));
|
|
|
|
getParent()->removeAttributes(getArgNo() + 1,
|
|
|
|
AttributeSet::get(Parent->getContext(),
|
|
|
|
getArgNo() + 1, B));
|
2008-04-28 19:37:06 +02:00
|
|
|
}
|
2008-01-24 18:47:11 +01:00
|
|
|
|
2007-04-09 17:01:12 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
2008-01-03 00:42:30 +01:00
|
|
|
// Helper Methods in Function
|
2007-04-09 17:01:12 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2009-07-22 02:24:57 +02:00
|
|
|
LLVMContext &Function::getContext() const {
|
|
|
|
return getType()->getContext();
|
2009-07-02 20:03:58 +02:00
|
|
|
}
|
|
|
|
|
Land the long talked about "type system rewrite" patch. This
patch brings numerous advantages to LLVM. One way to look at it
is through diffstat:
109 files changed, 3005 insertions(+), 5906 deletions(-)
Removing almost 3K lines of code is a good thing. Other advantages
include:
1. Value::getType() is a simple load that can be CSE'd, not a mutating
union-find operation.
2. Types a uniqued and never move once created, defining away PATypeHolder.
3. Structs can be "named" now, and their name is part of the identity that
uniques them. This means that the compiler doesn't merge them structurally
which makes the IR much less confusing.
4. Now that there is no way to get a cycle in a type graph without a named
struct type, "upreferences" go away.
5. Type refinement is completely gone, which should make LTO much MUCH faster
in some common cases with C++ code.
6. Types are now generally immutable, so we can use "Type *" instead
"const Type *" everywhere.
Downsides of this patch are that it removes some functions from the C API,
so people using those will have to upgrade to (not yet added) new API.
"LLVM 3.0" is the right time to do this.
There are still some cleanups pending after this, this patch is large enough
as-is.
llvm-svn: 134829
2011-07-09 19:41:24 +02:00
|
|
|
FunctionType *Function::getFunctionType() const {
|
2008-01-03 00:42:30 +01:00
|
|
|
return cast<FunctionType>(getType()->getElementType());
|
2007-04-09 17:01:12 +02:00
|
|
|
}
|
|
|
|
|
2008-01-03 00:42:30 +01:00
|
|
|
bool Function::isVarArg() const {
|
|
|
|
return getFunctionType()->isVarArg();
|
2007-04-09 17:01:12 +02:00
|
|
|
}
|
|
|
|
|
Land the long talked about "type system rewrite" patch. This
patch brings numerous advantages to LLVM. One way to look at it
is through diffstat:
109 files changed, 3005 insertions(+), 5906 deletions(-)
Removing almost 3K lines of code is a good thing. Other advantages
include:
1. Value::getType() is a simple load that can be CSE'd, not a mutating
union-find operation.
2. Types a uniqued and never move once created, defining away PATypeHolder.
3. Structs can be "named" now, and their name is part of the identity that
uniques them. This means that the compiler doesn't merge them structurally
which makes the IR much less confusing.
4. Now that there is no way to get a cycle in a type graph without a named
struct type, "upreferences" go away.
5. Type refinement is completely gone, which should make LTO much MUCH faster
in some common cases with C++ code.
6. Types are now generally immutable, so we can use "Type *" instead
"const Type *" everywhere.
Downsides of this patch are that it removes some functions from the C API,
so people using those will have to upgrade to (not yet added) new API.
"LLVM 3.0" is the right time to do this.
There are still some cleanups pending after this, this patch is large enough
as-is.
llvm-svn: 134829
2011-07-09 19:41:24 +02:00
|
|
|
Type *Function::getReturnType() const {
|
2008-01-03 00:42:30 +01:00
|
|
|
return getFunctionType()->getReturnType();
|
2007-11-25 15:10:56 +01:00
|
|
|
}
|
|
|
|
|
2008-01-03 00:42:30 +01:00
|
|
|
void Function::removeFromParent() {
|
|
|
|
getParent()->getFunctionList().remove(this);
|
2007-11-25 15:10:56 +01:00
|
|
|
}
|
|
|
|
|
2008-01-03 00:42:30 +01:00
|
|
|
void Function::eraseFromParent() {
|
|
|
|
getParent()->getFunctionList().erase(this);
|
2007-04-09 17:01:12 +02:00
|
|
|
}
|
|
|
|
|
2001-09-10 09:58:01 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
2002-03-26 19:01:55 +01:00
|
|
|
// Function Implementation
|
2001-09-10 09:58:01 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2011-07-18 06:54:35 +02:00
|
|
|
Function::Function(FunctionType *Ty, LinkageTypes Linkage,
|
2009-07-25 06:41:11 +02:00
|
|
|
const Twine &name, Module *ParentModule)
|
2012-12-17 21:37:55 +01:00
|
|
|
: GlobalValue(PointerType::getUnqual(Ty),
|
2008-03-12 18:45:29 +01:00
|
|
|
Value::FunctionVal, 0, 0, Linkage, name) {
|
2009-01-05 08:58:59 +01:00
|
|
|
assert(FunctionType::isValidReturnType(getReturnType()) &&
|
Land the long talked about "type system rewrite" patch. This
patch brings numerous advantages to LLVM. One way to look at it
is through diffstat:
109 files changed, 3005 insertions(+), 5906 deletions(-)
Removing almost 3K lines of code is a good thing. Other advantages
include:
1. Value::getType() is a simple load that can be CSE'd, not a mutating
union-find operation.
2. Types a uniqued and never move once created, defining away PATypeHolder.
3. Structs can be "named" now, and their name is part of the identity that
uniques them. This means that the compiler doesn't merge them structurally
which makes the IR much less confusing.
4. Now that there is no way to get a cycle in a type graph without a named
struct type, "upreferences" go away.
5. Type refinement is completely gone, which should make LTO much MUCH faster
in some common cases with C++ code.
6. Types are now generally immutable, so we can use "Type *" instead
"const Type *" everywhere.
Downsides of this patch are that it removes some functions from the C API,
so people using those will have to upgrade to (not yet added) new API.
"LLVM 3.0" is the right time to do this.
There are still some cleanups pending after this, this patch is large enough
as-is.
llvm-svn: 134829
2011-07-09 19:41:24 +02:00
|
|
|
"invalid return type");
|
2007-02-05 21:47:22 +01:00
|
|
|
SymTab = new ValueSymbolTable();
|
2002-09-06 22:46:32 +02:00
|
|
|
|
2007-08-18 08:14:52 +02:00
|
|
|
// If the function has arguments, mark them as lazily built.
|
|
|
|
if (Ty->getNumParams())
|
2009-12-29 03:14:09 +01:00
|
|
|
setValueSubclassData(1); // Set the "has lazy arguments" bit.
|
2012-12-17 21:37:55 +01:00
|
|
|
|
2002-09-08 20:59:35 +02:00
|
|
|
// Make sure that we get added to a function
|
|
|
|
LeakDetector::addGarbageObject(this);
|
|
|
|
|
2002-09-06 22:46:32 +02:00
|
|
|
if (ParentModule)
|
|
|
|
ParentModule->getFunctionList().push_back(this);
|
2008-04-07 15:39:11 +02:00
|
|
|
|
|
|
|
// Ensure intrinsics have the right parameter attributes.
|
2009-02-05 02:49:45 +01:00
|
|
|
if (unsigned IID = getIntrinsicID())
|
2012-10-15 06:46:55 +02:00
|
|
|
setAttributes(Intrinsic::getAttributes(getContext(), Intrinsic::ID(IID)));
|
2008-09-02 22:51:15 +02:00
|
|
|
|
2001-06-06 22:29:01 +02:00
|
|
|
}
|
|
|
|
|
2007-12-10 03:14:30 +01:00
|
|
|
Function::~Function() {
|
|
|
|
dropAllReferences(); // After this it is safe to delete instructions.
|
2001-06-06 22:29:01 +02:00
|
|
|
|
|
|
|
// Delete all of the method arguments and unlink from symbol table...
|
2007-12-10 03:14:30 +01:00
|
|
|
ArgumentList.clear();
|
|
|
|
delete SymTab;
|
2007-04-22 19:28:03 +02:00
|
|
|
|
2008-08-17 20:44:35 +02:00
|
|
|
// Remove the function from the on-the-side GC table.
|
|
|
|
clearGC();
|
2013-03-01 19:48:54 +01:00
|
|
|
|
|
|
|
// Remove the intrinsicID from the Cache.
|
2013-03-20 22:04:53 +01:00
|
|
|
if (getValueName() && isIntrinsic())
|
2013-03-01 19:48:54 +01:00
|
|
|
getContext().pImpl->IntrinsicIDCache.erase(this);
|
2001-06-06 22:29:01 +02:00
|
|
|
}
|
|
|
|
|
2007-08-18 08:14:52 +02:00
|
|
|
void Function::BuildLazyArguments() const {
|
|
|
|
// Create the arguments vector, all arguments start out unnamed.
|
2011-07-18 06:54:35 +02:00
|
|
|
FunctionType *FT = getFunctionType();
|
2007-08-18 08:14:52 +02:00
|
|
|
for (unsigned i = 0, e = FT->getNumParams(); i != e; ++i) {
|
2010-01-05 14:12:22 +01:00
|
|
|
assert(!FT->getParamType(i)->isVoidTy() &&
|
2007-08-18 08:14:52 +02:00
|
|
|
"Cannot have void typed arguments!");
|
|
|
|
ArgumentList.push_back(new Argument(FT->getParamType(i)));
|
|
|
|
}
|
2012-12-17 21:37:55 +01:00
|
|
|
|
2007-08-18 08:14:52 +02:00
|
|
|
// Clear the lazy arguments bit.
|
2009-12-29 03:14:09 +01:00
|
|
|
unsigned SDC = getSubclassDataFromValue();
|
|
|
|
const_cast<Function*>(this)->setValueSubclassData(SDC &= ~1);
|
2007-08-18 08:14:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t Function::arg_size() const {
|
|
|
|
return getFunctionType()->getNumParams();
|
|
|
|
}
|
|
|
|
bool Function::arg_empty() const {
|
|
|
|
return getFunctionType()->getNumParams() == 0;
|
|
|
|
}
|
|
|
|
|
2002-03-23 23:51:58 +01:00
|
|
|
void Function::setParent(Module *parent) {
|
2002-09-08 20:59:35 +02:00
|
|
|
if (getParent())
|
|
|
|
LeakDetector::addGarbageObject(this);
|
2001-06-06 22:29:01 +02:00
|
|
|
Parent = parent;
|
2002-09-08 20:59:35 +02:00
|
|
|
if (getParent())
|
|
|
|
LeakDetector::removeGarbageObject(this);
|
2001-06-06 22:29:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// dropAllReferences() - This function causes all the subinstructions to "let
|
|
|
|
// go" of all references that they are maintaining. This allows one to
|
|
|
|
// 'delete' a whole class at a time, even though there may be circular
|
|
|
|
// references... first all references are dropped, and all use counts go to
|
2003-10-10 19:54:14 +02:00
|
|
|
// zero. Then everything is deleted for real. Note that no operations are
|
2005-04-22 01:48:37 +02:00
|
|
|
// valid on an object that has "dropped all references", except operator
|
2001-06-06 22:29:01 +02:00
|
|
|
// delete.
|
|
|
|
//
|
2002-03-23 23:51:58 +01:00
|
|
|
void Function::dropAllReferences() {
|
2002-06-25 18:13:24 +02:00
|
|
|
for (iterator I = begin(), E = end(); I != E; ++I)
|
|
|
|
I->dropAllReferences();
|
2012-12-17 21:37:55 +01:00
|
|
|
|
2010-12-07 20:56:51 +01:00
|
|
|
// Delete all basic blocks. They are now unused, except possibly by
|
|
|
|
// blockaddresses, but BasicBlock's destructor takes care of those.
|
|
|
|
while (!BasicBlocks.empty())
|
|
|
|
BasicBlocks.begin()->eraseFromParent();
|
2013-09-16 03:08:15 +02:00
|
|
|
|
|
|
|
// Prefix data is stored in a side table.
|
|
|
|
setPrefixData(0);
|
2001-06-06 22:29:01 +02:00
|
|
|
}
|
2001-09-10 09:58:01 +02:00
|
|
|
|
2013-01-23 01:20:53 +01:00
|
|
|
void Function::addAttribute(unsigned i, Attribute::AttrKind attr) {
|
2012-12-08 00:16:57 +01:00
|
|
|
AttributeSet PAL = getAttributes();
|
2013-01-23 01:20:53 +01:00
|
|
|
PAL = PAL.addAttribute(getContext(), i, attr);
|
|
|
|
setAttributes(PAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Function::addAttributes(unsigned i, AttributeSet attrs) {
|
|
|
|
AttributeSet PAL = getAttributes();
|
|
|
|
PAL = PAL.addAttributes(getContext(), i, attrs);
|
2008-09-25 23:00:45 +02:00
|
|
|
setAttributes(PAL);
|
2008-04-08 09:23:58 +02:00
|
|
|
}
|
|
|
|
|
2013-01-23 01:45:55 +01:00
|
|
|
void Function::removeAttributes(unsigned i, AttributeSet attrs) {
|
2012-12-08 00:16:57 +01:00
|
|
|
AttributeSet PAL = getAttributes();
|
2013-01-23 01:45:55 +01:00
|
|
|
PAL = PAL.removeAttributes(getContext(), i, attrs);
|
2008-09-25 23:00:45 +02:00
|
|
|
setAttributes(PAL);
|
2008-05-16 22:39:43 +02:00
|
|
|
}
|
|
|
|
|
2008-08-17 20:44:35 +02:00
|
|
|
// Maintain the GC name for each function in an on-the-side table. This saves
|
|
|
|
// allocating an additional word in Function for programs which do not use GC
|
|
|
|
// (i.e., most programs) at the cost of increased overhead for clients which do
|
|
|
|
// use GC.
|
2009-06-18 01:49:06 +02:00
|
|
|
static DenseMap<const Function*,PooledStringPtr> *GCNames;
|
|
|
|
static StringPool *GCNamePool;
|
2009-06-18 22:56:48 +02:00
|
|
|
static ManagedStatic<sys::SmartRWMutex<true> > GCLock;
|
2007-12-10 04:18:06 +01:00
|
|
|
|
2008-08-17 20:44:35 +02:00
|
|
|
bool Function::hasGC() const {
|
2009-07-07 20:33:04 +02:00
|
|
|
sys::SmartScopedReader<true> Reader(*GCLock);
|
2009-06-18 22:56:48 +02:00
|
|
|
return GCNames && GCNames->count(this);
|
2007-12-10 04:18:06 +01:00
|
|
|
}
|
|
|
|
|
2008-08-17 20:44:35 +02:00
|
|
|
const char *Function::getGC() const {
|
|
|
|
assert(hasGC() && "Function has no collector");
|
2009-07-07 20:33:04 +02:00
|
|
|
sys::SmartScopedReader<true> Reader(*GCLock);
|
2009-06-18 22:56:48 +02:00
|
|
|
return *(*GCNames)[this];
|
2007-12-10 04:18:06 +01:00
|
|
|
}
|
|
|
|
|
2008-08-17 20:44:35 +02:00
|
|
|
void Function::setGC(const char *Str) {
|
2009-07-07 20:33:04 +02:00
|
|
|
sys::SmartScopedWriter<true> Writer(*GCLock);
|
2009-06-18 01:49:06 +02:00
|
|
|
if (!GCNamePool)
|
|
|
|
GCNamePool = new StringPool();
|
|
|
|
if (!GCNames)
|
|
|
|
GCNames = new DenseMap<const Function*,PooledStringPtr>();
|
|
|
|
(*GCNames)[this] = GCNamePool->intern(Str);
|
2007-12-10 04:18:06 +01:00
|
|
|
}
|
|
|
|
|
2008-08-17 20:44:35 +02:00
|
|
|
void Function::clearGC() {
|
2009-07-07 20:33:04 +02:00
|
|
|
sys::SmartScopedWriter<true> Writer(*GCLock);
|
2009-06-18 01:49:06 +02:00
|
|
|
if (GCNames) {
|
2008-08-17 20:44:35 +02:00
|
|
|
GCNames->erase(this);
|
2009-06-18 01:49:06 +02:00
|
|
|
if (GCNames->empty()) {
|
|
|
|
delete GCNames;
|
|
|
|
GCNames = 0;
|
|
|
|
if (GCNamePool->empty()) {
|
|
|
|
delete GCNamePool;
|
|
|
|
GCNamePool = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-12-10 04:18:06 +01:00
|
|
|
}
|
|
|
|
|
2008-05-26 21:58:59 +02:00
|
|
|
/// copyAttributesFrom - copy all additional attributes (those not needed to
|
|
|
|
/// create a Function) from the Function Src to this one.
|
|
|
|
void Function::copyAttributesFrom(const GlobalValue *Src) {
|
|
|
|
assert(isa<Function>(Src) && "Expected a Function!");
|
|
|
|
GlobalValue::copyAttributesFrom(Src);
|
|
|
|
const Function *SrcF = cast<Function>(Src);
|
|
|
|
setCallingConv(SrcF->getCallingConv());
|
2008-09-25 23:00:45 +02:00
|
|
|
setAttributes(SrcF->getAttributes());
|
2008-08-17 20:44:35 +02:00
|
|
|
if (SrcF->hasGC())
|
|
|
|
setGC(SrcF->getGC());
|
|
|
|
else
|
|
|
|
clearGC();
|
2013-09-16 03:08:15 +02:00
|
|
|
if (SrcF->hasPrefixData())
|
|
|
|
setPrefixData(SrcF->getPrefixData());
|
|
|
|
else
|
|
|
|
setPrefixData(0);
|
2008-05-26 21:58:59 +02:00
|
|
|
}
|
|
|
|
|
2003-05-08 05:47:33 +02:00
|
|
|
/// getIntrinsicID - This method returns the ID number of the specified
|
2003-11-11 23:41:34 +01:00
|
|
|
/// function, or Intrinsic::not_intrinsic if the function is not an
|
2003-10-10 19:54:14 +02:00
|
|
|
/// intrinsic, or if the pointer is null. This value is always defined to be
|
2003-05-08 05:47:33 +02:00
|
|
|
/// zero to allow easy checking for whether a function is intrinsic or not. The
|
|
|
|
/// particular intrinsic functions which correspond to this value are defined in
|
2013-03-01 19:48:54 +01:00
|
|
|
/// llvm/Intrinsics.h. Results are cached in the LLVM context, subsequent
|
|
|
|
/// requests for the same ID return results much faster from the cache.
|
2003-05-08 05:47:33 +02:00
|
|
|
///
|
2009-02-05 02:49:45 +01:00
|
|
|
unsigned Function::getIntrinsicID() const {
|
2007-02-15 20:17:16 +01:00
|
|
|
const ValueName *ValName = this->getValueName();
|
2012-12-20 00:17:20 +01:00
|
|
|
if (!ValName || !isIntrinsic())
|
2007-04-16 09:08:44 +02:00
|
|
|
return 0;
|
2013-03-01 19:48:54 +01:00
|
|
|
|
|
|
|
LLVMContextImpl::IntrinsicIDCacheTy &IntrinsicIDCache =
|
|
|
|
getContext().pImpl->IntrinsicIDCache;
|
2013-03-20 22:04:53 +01:00
|
|
|
if (!IntrinsicIDCache.count(this)) {
|
2013-03-01 19:48:54 +01:00
|
|
|
unsigned Id = lookupIntrinsicID();
|
|
|
|
IntrinsicIDCache[this]=Id;
|
|
|
|
return Id;
|
|
|
|
}
|
|
|
|
return IntrinsicIDCache[this];
|
|
|
|
}
|
|
|
|
|
|
|
|
/// This private method does the actual lookup of an intrinsic ID when the query
|
|
|
|
/// could not be answered from the cache.
|
|
|
|
unsigned Function::lookupIntrinsicID() const {
|
|
|
|
const ValueName *ValName = this->getValueName();
|
2007-02-15 20:17:16 +01:00
|
|
|
unsigned Len = ValName->getKeyLength();
|
|
|
|
const char *Name = ValName->getKeyData();
|
2012-12-17 21:37:55 +01:00
|
|
|
|
2006-03-09 21:35:01 +01:00
|
|
|
#define GET_FUNCTION_RECOGNIZER
|
2013-01-02 13:09:16 +01:00
|
|
|
#include "llvm/IR/Intrinsics.gen"
|
2006-03-09 21:35:01 +01:00
|
|
|
#undef GET_FUNCTION_RECOGNIZER
|
2013-03-01 19:48:54 +01:00
|
|
|
|
2003-05-08 05:47:33 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-07-14 19:45:39 +02:00
|
|
|
std::string Intrinsic::getName(ID id, ArrayRef<Type*> Tys) {
|
2006-03-25 07:32:47 +01:00
|
|
|
assert(id < num_intrinsics && "Invalid intrinsic ID!");
|
2011-04-26 00:14:33 +02:00
|
|
|
static const char * const Table[] = {
|
2006-03-25 07:32:47 +01:00
|
|
|
"not_intrinsic",
|
|
|
|
#define GET_INTRINSIC_NAME_TABLE
|
2013-01-02 13:09:16 +01:00
|
|
|
#include "llvm/IR/Intrinsics.gen"
|
2006-03-25 07:32:47 +01:00
|
|
|
#undef GET_INTRINSIC_NAME_TABLE
|
|
|
|
};
|
2011-07-14 19:45:39 +02:00
|
|
|
if (Tys.empty())
|
2007-04-01 09:25:33 +02:00
|
|
|
return Table[id];
|
|
|
|
std::string Result(Table[id]);
|
2011-07-14 19:45:39 +02:00
|
|
|
for (unsigned i = 0; i < Tys.size(); ++i) {
|
2011-07-18 06:54:35 +02:00
|
|
|
if (PointerType* PTyp = dyn_cast<PointerType>(Tys[i])) {
|
2012-12-17 21:37:55 +01:00
|
|
|
Result += ".p" + llvm::utostr(PTyp->getAddressSpace()) +
|
2009-08-11 00:56:29 +02:00
|
|
|
EVT::getEVT(PTyp->getElementType()).getEVTString();
|
2008-07-30 06:36:53 +02:00
|
|
|
}
|
|
|
|
else if (Tys[i])
|
2009-08-11 00:56:29 +02:00
|
|
|
Result += "." + EVT::getEVT(Tys[i]).getEVTString();
|
2008-07-30 06:36:53 +02:00
|
|
|
}
|
2007-04-01 09:25:33 +02:00
|
|
|
return Result;
|
2006-03-25 07:32:47 +01:00
|
|
|
}
|
|
|
|
|
2012-05-16 08:34:44 +02:00
|
|
|
|
2012-05-27 20:28:35 +02:00
|
|
|
/// IIT_Info - These are enumerators that describe the entries returned by the
|
|
|
|
/// getIntrinsicInfoTableEntries function.
|
|
|
|
///
|
|
|
|
/// NOTE: This must be kept in synch with the copy in TblGen/IntrinsicEmitter!
|
|
|
|
enum IIT_Info {
|
|
|
|
// Common values should be encoded with 0-15.
|
|
|
|
IIT_Done = 0,
|
|
|
|
IIT_I1 = 1,
|
|
|
|
IIT_I8 = 2,
|
|
|
|
IIT_I16 = 3,
|
|
|
|
IIT_I32 = 4,
|
|
|
|
IIT_I64 = 5,
|
2013-01-11 02:45:05 +01:00
|
|
|
IIT_F16 = 6,
|
|
|
|
IIT_F32 = 7,
|
|
|
|
IIT_F64 = 8,
|
|
|
|
IIT_V2 = 9,
|
|
|
|
IIT_V4 = 10,
|
|
|
|
IIT_V8 = 11,
|
|
|
|
IIT_V16 = 12,
|
|
|
|
IIT_V32 = 13,
|
2012-05-27 20:28:35 +02:00
|
|
|
IIT_PTR = 14,
|
|
|
|
IIT_ARG = 15,
|
2012-12-17 21:37:55 +01:00
|
|
|
|
2012-05-27 20:28:35 +02:00
|
|
|
// Values from 16+ are only encodable with the inefficient encoding.
|
2013-01-11 02:45:05 +01:00
|
|
|
IIT_MMX = 16,
|
|
|
|
IIT_METADATA = 17,
|
|
|
|
IIT_EMPTYSTRUCT = 18,
|
|
|
|
IIT_STRUCT2 = 19,
|
|
|
|
IIT_STRUCT3 = 20,
|
|
|
|
IIT_STRUCT4 = 21,
|
|
|
|
IIT_STRUCT5 = 22,
|
|
|
|
IIT_EXTEND_VEC_ARG = 23,
|
|
|
|
IIT_TRUNC_VEC_ARG = 24,
|
2013-09-24 04:47:27 +02:00
|
|
|
IIT_ANYPTR = 25,
|
2013-10-31 18:18:11 +01:00
|
|
|
IIT_V1 = 26,
|
|
|
|
IIT_VARARG = 27
|
2012-05-27 20:28:35 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static void DecodeIITType(unsigned &NextElt, ArrayRef<unsigned char> Infos,
|
|
|
|
SmallVectorImpl<Intrinsic::IITDescriptor> &OutputTable) {
|
2012-05-17 07:13:57 +02:00
|
|
|
IIT_Info Info = IIT_Info(Infos[NextElt++]);
|
2012-05-17 07:03:24 +02:00
|
|
|
unsigned StructElts = 2;
|
2012-05-27 20:28:35 +02:00
|
|
|
using namespace Intrinsic;
|
2012-12-17 21:37:55 +01:00
|
|
|
|
2012-05-17 07:13:57 +02:00
|
|
|
switch (Info) {
|
2012-05-27 20:28:35 +02:00
|
|
|
case IIT_Done:
|
|
|
|
OutputTable.push_back(IITDescriptor::get(IITDescriptor::Void, 0));
|
|
|
|
return;
|
2013-10-31 18:18:11 +01:00
|
|
|
case IIT_VARARG:
|
|
|
|
OutputTable.push_back(IITDescriptor::get(IITDescriptor::VarArg, 0));
|
|
|
|
return;
|
2012-05-27 20:28:35 +02:00
|
|
|
case IIT_MMX:
|
|
|
|
OutputTable.push_back(IITDescriptor::get(IITDescriptor::MMX, 0));
|
|
|
|
return;
|
|
|
|
case IIT_METADATA:
|
|
|
|
OutputTable.push_back(IITDescriptor::get(IITDescriptor::Metadata, 0));
|
|
|
|
return;
|
2013-01-11 02:45:05 +01:00
|
|
|
case IIT_F16:
|
|
|
|
OutputTable.push_back(IITDescriptor::get(IITDescriptor::Half, 0));
|
|
|
|
return;
|
2012-05-27 20:28:35 +02:00
|
|
|
case IIT_F32:
|
|
|
|
OutputTable.push_back(IITDescriptor::get(IITDescriptor::Float, 0));
|
|
|
|
return;
|
|
|
|
case IIT_F64:
|
|
|
|
OutputTable.push_back(IITDescriptor::get(IITDescriptor::Double, 0));
|
|
|
|
return;
|
|
|
|
case IIT_I1:
|
|
|
|
OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 1));
|
|
|
|
return;
|
|
|
|
case IIT_I8:
|
|
|
|
OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 8));
|
|
|
|
return;
|
|
|
|
case IIT_I16:
|
|
|
|
OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer,16));
|
|
|
|
return;
|
|
|
|
case IIT_I32:
|
|
|
|
OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 32));
|
|
|
|
return;
|
|
|
|
case IIT_I64:
|
|
|
|
OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 64));
|
|
|
|
return;
|
2013-09-24 04:47:27 +02:00
|
|
|
case IIT_V1:
|
|
|
|
OutputTable.push_back(IITDescriptor::get(IITDescriptor::Vector, 1));
|
|
|
|
DecodeIITType(NextElt, Infos, OutputTable);
|
|
|
|
return;
|
2012-05-17 06:30:58 +02:00
|
|
|
case IIT_V2:
|
2012-05-27 20:28:35 +02:00
|
|
|
OutputTable.push_back(IITDescriptor::get(IITDescriptor::Vector, 2));
|
|
|
|
DecodeIITType(NextElt, Infos, OutputTable);
|
|
|
|
return;
|
2012-05-17 06:30:58 +02:00
|
|
|
case IIT_V4:
|
2012-05-27 20:28:35 +02:00
|
|
|
OutputTable.push_back(IITDescriptor::get(IITDescriptor::Vector, 4));
|
|
|
|
DecodeIITType(NextElt, Infos, OutputTable);
|
|
|
|
return;
|
2012-05-17 06:30:58 +02:00
|
|
|
case IIT_V8:
|
2012-05-27 20:28:35 +02:00
|
|
|
OutputTable.push_back(IITDescriptor::get(IITDescriptor::Vector, 8));
|
|
|
|
DecodeIITType(NextElt, Infos, OutputTable);
|
|
|
|
return;
|
2012-05-17 06:30:58 +02:00
|
|
|
case IIT_V16:
|
2012-05-27 20:28:35 +02:00
|
|
|
OutputTable.push_back(IITDescriptor::get(IITDescriptor::Vector, 16));
|
|
|
|
DecodeIITType(NextElt, Infos, OutputTable);
|
|
|
|
return;
|
2012-05-17 07:03:24 +02:00
|
|
|
case IIT_V32:
|
2012-05-27 20:28:35 +02:00
|
|
|
OutputTable.push_back(IITDescriptor::get(IITDescriptor::Vector, 32));
|
|
|
|
DecodeIITType(NextElt, Infos, OutputTable);
|
|
|
|
return;
|
2012-05-23 07:19:18 +02:00
|
|
|
case IIT_PTR:
|
2012-05-27 20:28:35 +02:00
|
|
|
OutputTable.push_back(IITDescriptor::get(IITDescriptor::Pointer, 0));
|
|
|
|
DecodeIITType(NextElt, Infos, OutputTable);
|
|
|
|
return;
|
2012-05-23 07:19:18 +02:00
|
|
|
case IIT_ANYPTR: { // [ANYPTR addrspace, subtype]
|
2012-12-17 21:37:55 +01:00
|
|
|
OutputTable.push_back(IITDescriptor::get(IITDescriptor::Pointer,
|
2012-05-27 20:28:35 +02:00
|
|
|
Infos[NextElt++]));
|
|
|
|
DecodeIITType(NextElt, Infos, OutputTable);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
case IIT_ARG: {
|
|
|
|
unsigned ArgInfo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
|
|
|
|
OutputTable.push_back(IITDescriptor::get(IITDescriptor::Argument, ArgInfo));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
case IIT_EXTEND_VEC_ARG: {
|
|
|
|
unsigned ArgInfo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
|
|
|
|
OutputTable.push_back(IITDescriptor::get(IITDescriptor::ExtendVecArgument,
|
|
|
|
ArgInfo));
|
|
|
|
return;
|
2012-05-22 01:21:28 +02:00
|
|
|
}
|
2012-05-17 07:03:24 +02:00
|
|
|
case IIT_TRUNC_VEC_ARG: {
|
2012-05-27 20:28:35 +02:00
|
|
|
unsigned ArgInfo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
|
|
|
|
OutputTable.push_back(IITDescriptor::get(IITDescriptor::TruncVecArgument,
|
|
|
|
ArgInfo));
|
|
|
|
return;
|
2012-05-17 07:03:24 +02:00
|
|
|
}
|
2012-05-27 20:28:35 +02:00
|
|
|
case IIT_EMPTYSTRUCT:
|
|
|
|
OutputTable.push_back(IITDescriptor::get(IITDescriptor::Struct, 0));
|
|
|
|
return;
|
2012-05-17 07:03:24 +02:00
|
|
|
case IIT_STRUCT5: ++StructElts; // FALL THROUGH.
|
|
|
|
case IIT_STRUCT4: ++StructElts; // FALL THROUGH.
|
|
|
|
case IIT_STRUCT3: ++StructElts; // FALL THROUGH.
|
|
|
|
case IIT_STRUCT2: {
|
2012-05-27 20:28:35 +02:00
|
|
|
OutputTable.push_back(IITDescriptor::get(IITDescriptor::Struct,StructElts));
|
|
|
|
|
2012-05-17 07:03:24 +02:00
|
|
|
for (unsigned i = 0; i != StructElts; ++i)
|
2012-05-27 20:28:35 +02:00
|
|
|
DecodeIITType(NextElt, Infos, OutputTable);
|
|
|
|
return;
|
2012-05-17 06:30:58 +02:00
|
|
|
}
|
2012-05-16 08:34:44 +02:00
|
|
|
}
|
|
|
|
llvm_unreachable("unhandled");
|
|
|
|
}
|
|
|
|
|
2012-05-27 20:28:35 +02:00
|
|
|
|
|
|
|
#define GET_INTRINSIC_GENERATOR_GLOBAL
|
2013-01-02 13:09:16 +01:00
|
|
|
#include "llvm/IR/Intrinsics.gen"
|
2012-05-27 20:28:35 +02:00
|
|
|
#undef GET_INTRINSIC_GENERATOR_GLOBAL
|
|
|
|
|
2012-12-17 21:37:55 +01:00
|
|
|
void Intrinsic::getIntrinsicInfoTableEntries(ID id,
|
2012-05-27 20:28:35 +02:00
|
|
|
SmallVectorImpl<IITDescriptor> &T){
|
2012-05-16 08:34:44 +02:00
|
|
|
// Check to see if the intrinsic's type was expressible by the table.
|
|
|
|
unsigned TableVal = IIT_Table[id-1];
|
2012-12-17 21:37:55 +01:00
|
|
|
|
2012-05-17 17:55:41 +02:00
|
|
|
// Decode the TableVal into an array of IITValues.
|
|
|
|
SmallVector<unsigned char, 8> IITValues;
|
|
|
|
ArrayRef<unsigned char> IITEntries;
|
|
|
|
unsigned NextElt = 0;
|
|
|
|
if ((TableVal >> 31) != 0) {
|
|
|
|
// This is an offset into the IIT_LongEncodingTable.
|
|
|
|
IITEntries = IIT_LongEncodingTable;
|
2012-12-17 21:37:55 +01:00
|
|
|
|
2012-05-17 17:55:41 +02:00
|
|
|
// Strip sentinel bit.
|
|
|
|
NextElt = (TableVal << 1) >> 1;
|
|
|
|
} else {
|
2012-05-27 20:28:35 +02:00
|
|
|
// Decode the TableVal into an array of IITValues. If the entry was encoded
|
|
|
|
// into a single word in the table itself, decode it now.
|
2012-05-17 07:13:57 +02:00
|
|
|
do {
|
|
|
|
IITValues.push_back(TableVal & 0xF);
|
|
|
|
TableVal >>= 4;
|
|
|
|
} while (TableVal);
|
2012-12-17 21:37:55 +01:00
|
|
|
|
2012-05-17 17:55:41 +02:00
|
|
|
IITEntries = IITValues;
|
|
|
|
NextElt = 0;
|
2012-05-16 08:34:44 +02:00
|
|
|
}
|
2012-05-27 20:28:35 +02:00
|
|
|
|
|
|
|
// Okay, decode the table into the output vector of IITDescriptors.
|
|
|
|
DecodeIITType(NextElt, IITEntries, T);
|
|
|
|
while (NextElt != IITEntries.size() && IITEntries[NextElt] != 0)
|
|
|
|
DecodeIITType(NextElt, IITEntries, T);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static Type *DecodeFixedType(ArrayRef<Intrinsic::IITDescriptor> &Infos,
|
|
|
|
ArrayRef<Type*> Tys, LLVMContext &Context) {
|
|
|
|
using namespace Intrinsic;
|
|
|
|
IITDescriptor D = Infos.front();
|
|
|
|
Infos = Infos.slice(1);
|
2012-12-17 21:37:55 +01:00
|
|
|
|
2012-05-27 20:28:35 +02:00
|
|
|
switch (D.Kind) {
|
|
|
|
case IITDescriptor::Void: return Type::getVoidTy(Context);
|
2013-10-31 18:18:11 +01:00
|
|
|
case IITDescriptor::VarArg: return Type::getVoidTy(Context);
|
2012-05-27 20:28:35 +02:00
|
|
|
case IITDescriptor::MMX: return Type::getX86_MMXTy(Context);
|
|
|
|
case IITDescriptor::Metadata: return Type::getMetadataTy(Context);
|
2013-01-11 02:45:05 +01:00
|
|
|
case IITDescriptor::Half: return Type::getHalfTy(Context);
|
2012-05-27 20:28:35 +02:00
|
|
|
case IITDescriptor::Float: return Type::getFloatTy(Context);
|
|
|
|
case IITDescriptor::Double: return Type::getDoubleTy(Context);
|
2012-12-17 21:37:55 +01:00
|
|
|
|
2012-05-27 20:28:35 +02:00
|
|
|
case IITDescriptor::Integer:
|
|
|
|
return IntegerType::get(Context, D.Integer_Width);
|
|
|
|
case IITDescriptor::Vector:
|
|
|
|
return VectorType::get(DecodeFixedType(Infos, Tys, Context),D.Vector_Width);
|
|
|
|
case IITDescriptor::Pointer:
|
|
|
|
return PointerType::get(DecodeFixedType(Infos, Tys, Context),
|
|
|
|
D.Pointer_AddressSpace);
|
|
|
|
case IITDescriptor::Struct: {
|
|
|
|
Type *Elts[5];
|
|
|
|
assert(D.Struct_NumElements <= 5 && "Can't handle this yet");
|
|
|
|
for (unsigned i = 0, e = D.Struct_NumElements; i != e; ++i)
|
|
|
|
Elts[i] = DecodeFixedType(Infos, Tys, Context);
|
|
|
|
return StructType::get(Context, ArrayRef<Type*>(Elts,D.Struct_NumElements));
|
|
|
|
}
|
|
|
|
|
|
|
|
case IITDescriptor::Argument:
|
|
|
|
return Tys[D.getArgumentNumber()];
|
|
|
|
case IITDescriptor::ExtendVecArgument:
|
|
|
|
return VectorType::getExtendedElementVectorType(cast<VectorType>(
|
|
|
|
Tys[D.getArgumentNumber()]));
|
2012-12-17 21:37:55 +01:00
|
|
|
|
2012-05-27 20:28:35 +02:00
|
|
|
case IITDescriptor::TruncVecArgument:
|
|
|
|
return VectorType::getTruncatedElementVectorType(cast<VectorType>(
|
|
|
|
Tys[D.getArgumentNumber()]));
|
|
|
|
}
|
|
|
|
llvm_unreachable("unhandled");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FunctionType *Intrinsic::getType(LLVMContext &Context,
|
|
|
|
ID id, ArrayRef<Type*> Tys) {
|
|
|
|
SmallVector<IITDescriptor, 8> Table;
|
|
|
|
getIntrinsicInfoTableEntries(id, Table);
|
2012-12-17 21:37:55 +01:00
|
|
|
|
2012-05-27 20:28:35 +02:00
|
|
|
ArrayRef<IITDescriptor> TableRef = Table;
|
|
|
|
Type *ResultTy = DecodeFixedType(TableRef, Tys, Context);
|
2012-12-17 21:37:55 +01:00
|
|
|
|
2012-05-17 17:55:41 +02:00
|
|
|
SmallVector<Type*, 8> ArgTys;
|
2012-05-27 20:28:35 +02:00
|
|
|
while (!TableRef.empty())
|
|
|
|
ArgTys.push_back(DecodeFixedType(TableRef, Tys, Context));
|
2007-02-07 21:38:26 +01:00
|
|
|
|
2012-12-17 21:37:55 +01:00
|
|
|
return FunctionType::get(ResultTy, ArgTys, false);
|
2007-02-07 21:38:26 +01:00
|
|
|
}
|
|
|
|
|
2009-02-25 00:17:49 +01:00
|
|
|
bool Intrinsic::isOverloaded(ID id) {
|
|
|
|
#define GET_INTRINSIC_OVERLOAD_TABLE
|
2013-01-02 13:09:16 +01:00
|
|
|
#include "llvm/IR/Intrinsics.gen"
|
2009-02-25 00:17:49 +01:00
|
|
|
#undef GET_INTRINSIC_OVERLOAD_TABLE
|
|
|
|
}
|
|
|
|
|
2009-01-12 02:18:58 +01:00
|
|
|
/// This defines the "Intrinsic::getAttributes(ID id)" method.
|
2007-12-03 21:06:50 +01:00
|
|
|
#define GET_INTRINSIC_ATTRIBUTES
|
2013-01-02 13:09:16 +01:00
|
|
|
#include "llvm/IR/Intrinsics.gen"
|
2007-12-03 21:06:50 +01:00
|
|
|
#undef GET_INTRINSIC_ATTRIBUTES
|
|
|
|
|
2011-07-14 19:45:39 +02:00
|
|
|
Function *Intrinsic::getDeclaration(Module *M, ID id, ArrayRef<Type*> Tys) {
|
2007-12-03 21:06:50 +01:00
|
|
|
// There can never be multiple globals with the same name of different types,
|
|
|
|
// because intrinsics must be a specific type.
|
2008-04-07 15:39:11 +02:00
|
|
|
return
|
2011-07-14 19:45:39 +02:00
|
|
|
cast<Function>(M->getOrInsertFunction(getName(id, Tys),
|
|
|
|
getType(M->getContext(), id, Tys)));
|
2007-02-07 21:38:26 +01:00
|
|
|
}
|
|
|
|
|
2009-02-05 02:49:45 +01:00
|
|
|
// This defines the "Intrinsic::getIntrinsicForGCCBuiltin()" method.
|
|
|
|
#define GET_LLVM_INTRINSIC_FOR_GCC_BUILTIN
|
2013-01-02 13:09:16 +01:00
|
|
|
#include "llvm/IR/Intrinsics.gen"
|
2009-02-05 02:49:45 +01:00
|
|
|
#undef GET_LLVM_INTRINSIC_FOR_GCC_BUILTIN
|
|
|
|
|
2010-03-23 15:40:20 +01:00
|
|
|
/// hasAddressTaken - returns true if there are any uses of this function
|
|
|
|
/// other than direct calls or invokes to it.
|
2010-03-24 14:21:49 +01:00
|
|
|
bool Function::hasAddressTaken(const User* *PutOffender) const {
|
2010-03-26 00:06:16 +01:00
|
|
|
for (Value::const_use_iterator I = use_begin(), E = use_end(); I != E; ++I) {
|
2010-03-24 14:21:49 +01:00
|
|
|
const User *U = *I;
|
2012-05-12 10:30:16 +02:00
|
|
|
if (isa<BlockAddress>(U))
|
|
|
|
continue;
|
2010-03-24 14:21:49 +01:00
|
|
|
if (!isa<CallInst>(U) && !isa<InvokeInst>(U))
|
|
|
|
return PutOffender ? (*PutOffender = U, true) : true;
|
2010-04-01 10:21:08 +02:00
|
|
|
ImmutableCallSite CS(cast<Instruction>(U));
|
2010-03-24 14:21:49 +01:00
|
|
|
if (!CS.isCallee(I))
|
|
|
|
return PutOffender ? (*PutOffender = U, true) : true;
|
2009-06-10 10:41:11 +02:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-10-20 07:23:42 +02:00
|
|
|
bool Function::isDefTriviallyDead() const {
|
|
|
|
// Check the linkage
|
|
|
|
if (!hasLinkOnceLinkage() && !hasLocalLinkage() &&
|
|
|
|
!hasAvailableExternallyLinkage())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Check if the function is used by anything other than a blockaddress.
|
|
|
|
for (Value::const_use_iterator I = use_begin(), E = use_end(); I != E; ++I)
|
|
|
|
if (!isa<BlockAddress>(*I))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-10-17 20:43:40 +02:00
|
|
|
/// callsFunctionThatReturnsTwice - Return true if the function has a call to
|
|
|
|
/// setjmp or other function that gcc recognizes as "returning twice".
|
|
|
|
bool Function::callsFunctionThatReturnsTwice() const {
|
|
|
|
for (const_inst_iterator
|
|
|
|
I = inst_begin(this), E = inst_end(this); I != E; ++I) {
|
|
|
|
const CallInst* callInst = dyn_cast<CallInst>(&*I);
|
|
|
|
if (!callInst)
|
|
|
|
continue;
|
|
|
|
if (callInst->canReturnTwice())
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2013-09-16 03:08:15 +02:00
|
|
|
|
|
|
|
Constant *Function::getPrefixData() const {
|
|
|
|
assert(hasPrefixData());
|
|
|
|
const LLVMContextImpl::PrefixDataMapTy &PDMap =
|
|
|
|
getContext().pImpl->PrefixDataMap;
|
|
|
|
assert(PDMap.find(this) != PDMap.end());
|
|
|
|
return cast<Constant>(PDMap.find(this)->second->getReturnValue());
|
|
|
|
}
|
|
|
|
|
|
|
|
void Function::setPrefixData(Constant *PrefixData) {
|
|
|
|
if (!PrefixData && !hasPrefixData())
|
|
|
|
return;
|
|
|
|
|
|
|
|
unsigned SCData = getSubclassDataFromValue();
|
|
|
|
LLVMContextImpl::PrefixDataMapTy &PDMap = getContext().pImpl->PrefixDataMap;
|
|
|
|
ReturnInst *&PDHolder = PDMap[this];
|
|
|
|
if (PrefixData) {
|
|
|
|
if (PDHolder)
|
|
|
|
PDHolder->setOperand(0, PrefixData);
|
|
|
|
else
|
|
|
|
PDHolder = ReturnInst::Create(getContext(), PrefixData);
|
|
|
|
SCData |= 2;
|
|
|
|
} else {
|
|
|
|
delete PDHolder;
|
|
|
|
PDMap.erase(this);
|
|
|
|
SCData &= ~2;
|
|
|
|
}
|
|
|
|
setValueSubclassData(SCData);
|
|
|
|
}
|