2003-10-13 03:32:08 +00:00
|
|
|
//===-- Function.cpp - Implement the Global object classes ----------------===//
|
2005-04-21 23:48:37 +00:00
|
|
|
//
|
2003-10-20 19:43:21 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:36:04 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-21 23:48:37 +00:00
|
|
|
//
|
2003-10-20 19:43:21 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2001-06-06 20:29:01 +00:00
|
|
|
//
|
2007-02-05 20:47:22 +00:00
|
|
|
// This file implements the Function class for the VMCore library.
|
2001-06-06 20:29:01 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/Module.h"
|
2002-09-06 20:46:32 +00:00
|
|
|
#include "llvm/DerivedTypes.h"
|
2004-10-12 04:20:25 +00:00
|
|
|
#include "llvm/IntrinsicInst.h"
|
2009-07-07 23:43:39 +00:00
|
|
|
#include "llvm/LLVMContext.h"
|
2007-08-20 19:23:34 +00:00
|
|
|
#include "llvm/CodeGen/ValueTypes.h"
|
2010-03-24 13:21:49 +00:00
|
|
|
#include "llvm/Support/CallSite.h"
|
2004-09-01 22:55:40 +00:00
|
|
|
#include "llvm/Support/LeakDetector.h"
|
2009-06-17 22:23:31 +00:00
|
|
|
#include "llvm/Support/ManagedStatic.h"
|
2007-12-10 03:18:06 +00:00
|
|
|
#include "llvm/Support/StringPool.h"
|
2009-06-17 22:23:31 +00:00
|
|
|
#include "llvm/System/RWMutex.h"
|
2009-06-18 16:54:52 +00:00
|
|
|
#include "llvm/System/Threading.h"
|
2002-06-25 16:13:24 +00:00
|
|
|
#include "SymbolTableListTraitsImpl.h"
|
2007-12-10 03:18:06 +00:00
|
|
|
#include "llvm/ADT/DenseMap.h"
|
2004-12-05 06:43:27 +00:00
|
|
|
#include "llvm/ADT/StringExtras.h"
|
2003-11-21 20:23:48 +00:00
|
|
|
using namespace llvm;
|
2003-11-11 22:41:34 +00:00
|
|
|
|
2002-06-25 16:13:24 +00:00
|
|
|
|
|
|
|
// Explicit instantiations of SymbolTableListTraits since some of the methods
|
|
|
|
// are not in the public header file...
|
2009-12-19 00:55:12 +00:00
|
|
|
template class llvm::SymbolTableListTraits<Argument, Function>;
|
|
|
|
template class llvm::SymbolTableListTraits<BasicBlock, Function>;
|
2001-06-06 20:29:01 +00:00
|
|
|
|
2002-04-09 19:39:35 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Argument Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2009-07-25 04:41:11 +00:00
|
|
|
Argument::Argument(const Type *Ty, const Twine &Name, Function *Par)
|
2007-02-12 05:18:08 +00:00
|
|
|
: Value(Ty, Value::ArgumentVal) {
|
2002-09-06 21:33:15 +00:00
|
|
|
Parent = 0;
|
2002-09-08 18:59:35 +00:00
|
|
|
|
|
|
|
// Make sure that we get added to a function
|
|
|
|
LeakDetector::addGarbageObject(this);
|
|
|
|
|
2002-09-06 21:33:15 +00:00
|
|
|
if (Par)
|
|
|
|
Par->getArgumentList().push_back(this);
|
2007-02-12 05:18:08 +00:00
|
|
|
setName(Name);
|
2002-09-06 21:33:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Argument::setParent(Function *parent) {
|
2002-09-08 18:59:35 +00:00
|
|
|
if (getParent())
|
|
|
|
LeakDetector::addGarbageObject(this);
|
2002-09-06 21:33:15 +00:00
|
|
|
Parent = parent;
|
2002-09-08 18:59:35 +00:00
|
|
|
if (getParent())
|
|
|
|
LeakDetector::removeGarbageObject(this);
|
2002-09-06 21:33:15 +00:00
|
|
|
}
|
|
|
|
|
2008-01-24 17:47:11 +00:00
|
|
|
/// getArgNo - Return the index of this formal argument in its containing
|
|
|
|
/// function. For example in "void foo(int a, float b)" a is 0 and b is 1.
|
|
|
|
unsigned Argument::getArgNo() const {
|
|
|
|
const Function *F = getParent();
|
|
|
|
assert(F && "Argument is not in a function");
|
|
|
|
|
|
|
|
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 11:11:14 +00:00
|
|
|
if (!getType()->isPointerTy()) return false;
|
2008-09-25 21:00:45 +00:00
|
|
|
return getParent()->paramHasAttr(getArgNo()+1, Attribute::ByVal);
|
2008-01-24 17:47:11 +00:00
|
|
|
}
|
|
|
|
|
2009-12-11 08:36:17 +00:00
|
|
|
/// hasNestAttr - Return true if this argument has the nest attribute on
|
|
|
|
/// it in its containing function.
|
|
|
|
bool Argument::hasNestAttr() const {
|
2010-02-16 11:11:14 +00:00
|
|
|
if (!getType()->isPointerTy()) return false;
|
2009-12-11 08:36:17 +00:00
|
|
|
return getParent()->paramHasAttr(getArgNo()+1, Attribute::Nest);
|
|
|
|
}
|
|
|
|
|
2008-01-24 17:47:11 +00:00
|
|
|
/// hasNoAliasAttr - Return true if this argument has the noalias attribute on
|
|
|
|
/// it in its containing function.
|
|
|
|
bool Argument::hasNoAliasAttr() const {
|
2010-02-16 11:11:14 +00:00
|
|
|
if (!getType()->isPointerTy()) return false;
|
2008-09-25 21:00:45 +00:00
|
|
|
return getParent()->paramHasAttr(getArgNo()+1, Attribute::NoAlias);
|
2008-01-24 17:47:11 +00:00
|
|
|
}
|
|
|
|
|
2008-12-31 18:08:59 +00:00
|
|
|
/// hasNoCaptureAttr - Return true if this argument has the nocapture attribute
|
|
|
|
/// on it in its containing function.
|
|
|
|
bool Argument::hasNoCaptureAttr() const {
|
2010-02-16 11:11:14 +00:00
|
|
|
if (!getType()->isPointerTy()) return false;
|
2008-12-31 18:08:59 +00:00
|
|
|
return getParent()->paramHasAttr(getArgNo()+1, Attribute::NoCapture);
|
|
|
|
}
|
|
|
|
|
2008-02-17 23:22:28 +00:00
|
|
|
/// hasSRetAttr - Return true if this argument has the sret attribute on
|
|
|
|
/// it in its containing function.
|
|
|
|
bool Argument::hasStructRetAttr() const {
|
2010-02-16 11:11:14 +00:00
|
|
|
if (!getType()->isPointerTy()) return false;
|
2008-05-15 10:04:30 +00:00
|
|
|
if (this != getParent()->arg_begin())
|
|
|
|
return false; // StructRet param must be first param
|
2008-09-25 21:00:45 +00:00
|
|
|
return getParent()->paramHasAttr(1, Attribute::StructRet);
|
2008-02-17 23:22:28 +00:00
|
|
|
}
|
|
|
|
|
2008-09-25 21:00:45 +00:00
|
|
|
/// addAttr - Add a Attribute to an argument
|
2008-09-23 23:03:40 +00:00
|
|
|
void Argument::addAttr(Attributes attr) {
|
2008-09-25 21:00:45 +00:00
|
|
|
getParent()->addAttribute(getArgNo() + 1, attr);
|
2008-04-28 17:37:06 +00:00
|
|
|
}
|
2008-07-08 09:41:30 +00:00
|
|
|
|
2008-09-25 21:00:45 +00:00
|
|
|
/// removeAttr - Remove a Attribute from an argument
|
2008-09-23 23:03:40 +00:00
|
|
|
void Argument::removeAttr(Attributes attr) {
|
2008-09-25 21:00:45 +00:00
|
|
|
getParent()->removeAttribute(getArgNo() + 1, attr);
|
2008-04-28 17:37:06 +00:00
|
|
|
}
|
2008-01-24 17:47:11 +00:00
|
|
|
|
|
|
|
|
2007-04-09 15:01:12 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2008-01-02 23:42:30 +00:00
|
|
|
// Helper Methods in Function
|
2007-04-09 15:01:12 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2009-07-22 00:24:57 +00:00
|
|
|
LLVMContext &Function::getContext() const {
|
|
|
|
return getType()->getContext();
|
2009-07-02 18:03:58 +00:00
|
|
|
}
|
|
|
|
|
2008-01-02 23:42:30 +00:00
|
|
|
const FunctionType *Function::getFunctionType() const {
|
|
|
|
return cast<FunctionType>(getType()->getElementType());
|
2007-04-09 15:01:12 +00:00
|
|
|
}
|
|
|
|
|
2008-01-02 23:42:30 +00:00
|
|
|
bool Function::isVarArg() const {
|
|
|
|
return getFunctionType()->isVarArg();
|
2007-04-09 15:01:12 +00:00
|
|
|
}
|
|
|
|
|
2008-01-02 23:42:30 +00:00
|
|
|
const Type *Function::getReturnType() const {
|
|
|
|
return getFunctionType()->getReturnType();
|
2007-11-25 14:10:56 +00:00
|
|
|
}
|
|
|
|
|
2008-01-02 23:42:30 +00:00
|
|
|
void Function::removeFromParent() {
|
|
|
|
getParent()->getFunctionList().remove(this);
|
2007-11-25 14:10:56 +00:00
|
|
|
}
|
|
|
|
|
2008-01-02 23:42:30 +00:00
|
|
|
void Function::eraseFromParent() {
|
|
|
|
getParent()->getFunctionList().erase(this);
|
2007-04-09 15:01:12 +00:00
|
|
|
}
|
|
|
|
|
2001-09-10 07:58:01 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2002-03-26 18:01:55 +00:00
|
|
|
// Function Implementation
|
2001-09-10 07:58:01 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2003-04-16 20:28:45 +00:00
|
|
|
Function::Function(const FunctionType *Ty, LinkageTypes Linkage,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &name, Module *ParentModule)
|
2007-12-17 01:12:55 +00:00
|
|
|
: GlobalValue(PointerType::getUnqual(Ty),
|
2008-03-12 17:45:29 +00:00
|
|
|
Value::FunctionVal, 0, 0, Linkage, name) {
|
2009-01-05 07:58:59 +00:00
|
|
|
assert(FunctionType::isValidReturnType(getReturnType()) &&
|
2010-02-16 14:50:09 +00:00
|
|
|
!getReturnType()->isOpaqueTy() && "invalid return type");
|
2007-02-05 20:47:22 +00:00
|
|
|
SymTab = new ValueSymbolTable();
|
2002-09-06 20:46:32 +00:00
|
|
|
|
2007-08-18 06:14:52 +00:00
|
|
|
// If the function has arguments, mark them as lazily built.
|
|
|
|
if (Ty->getNumParams())
|
2009-12-29 02:14:09 +00:00
|
|
|
setValueSubclassData(1); // Set the "has lazy arguments" bit.
|
2007-08-18 06:14:52 +00:00
|
|
|
|
2002-09-08 18:59:35 +00:00
|
|
|
// Make sure that we get added to a function
|
|
|
|
LeakDetector::addGarbageObject(this);
|
|
|
|
|
2002-09-06 20:46:32 +00:00
|
|
|
if (ParentModule)
|
|
|
|
ParentModule->getFunctionList().push_back(this);
|
2008-04-07 13:39:11 +00:00
|
|
|
|
|
|
|
// Ensure intrinsics have the right parameter attributes.
|
2009-02-05 01:49:45 +00:00
|
|
|
if (unsigned IID = getIntrinsicID())
|
2008-09-25 21:00:45 +00:00
|
|
|
setAttributes(Intrinsic::getAttributes(Intrinsic::ID(IID)));
|
2008-09-02 20:51:15 +00:00
|
|
|
|
2001-06-06 20:29:01 +00:00
|
|
|
}
|
|
|
|
|
2007-12-10 02:14:30 +00:00
|
|
|
Function::~Function() {
|
|
|
|
dropAllReferences(); // After this it is safe to delete instructions.
|
2001-06-06 20:29:01 +00:00
|
|
|
|
|
|
|
// Delete all of the method arguments and unlink from symbol table...
|
2007-12-10 02:14:30 +00:00
|
|
|
ArgumentList.clear();
|
|
|
|
delete SymTab;
|
2007-04-22 17:28:03 +00:00
|
|
|
|
2008-08-17 18:44:35 +00:00
|
|
|
// Remove the function from the on-the-side GC table.
|
|
|
|
clearGC();
|
2001-06-06 20:29:01 +00:00
|
|
|
}
|
|
|
|
|
2007-08-18 06:14:52 +00:00
|
|
|
void Function::BuildLazyArguments() const {
|
|
|
|
// Create the arguments vector, all arguments start out unnamed.
|
|
|
|
const FunctionType *FT = getFunctionType();
|
|
|
|
for (unsigned i = 0, e = FT->getNumParams(); i != e; ++i) {
|
2010-01-05 13:12:22 +00:00
|
|
|
assert(!FT->getParamType(i)->isVoidTy() &&
|
2007-08-18 06:14:52 +00:00
|
|
|
"Cannot have void typed arguments!");
|
|
|
|
ArgumentList.push_back(new Argument(FT->getParamType(i)));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clear the lazy arguments bit.
|
2009-12-29 02:14:09 +00:00
|
|
|
unsigned SDC = getSubclassDataFromValue();
|
|
|
|
const_cast<Function*>(this)->setValueSubclassData(SDC &= ~1);
|
2007-08-18 06:14:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t Function::arg_size() const {
|
|
|
|
return getFunctionType()->getNumParams();
|
|
|
|
}
|
|
|
|
bool Function::arg_empty() const {
|
|
|
|
return getFunctionType()->getNumParams() == 0;
|
|
|
|
}
|
|
|
|
|
2002-03-23 22:51:58 +00:00
|
|
|
void Function::setParent(Module *parent) {
|
2002-09-08 18:59:35 +00:00
|
|
|
if (getParent())
|
|
|
|
LeakDetector::addGarbageObject(this);
|
2001-06-06 20:29:01 +00:00
|
|
|
Parent = parent;
|
2002-09-08 18:59:35 +00:00
|
|
|
if (getParent())
|
|
|
|
LeakDetector::removeGarbageObject(this);
|
2001-06-06 20:29:01 +00: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 17:54:14 +00:00
|
|
|
// zero. Then everything is deleted for real. Note that no operations are
|
2005-04-21 23:48:37 +00:00
|
|
|
// valid on an object that has "dropped all references", except operator
|
2001-06-06 20:29:01 +00:00
|
|
|
// delete.
|
|
|
|
//
|
2002-03-23 22:51:58 +00:00
|
|
|
void Function::dropAllReferences() {
|
2002-06-25 16:13:24 +00:00
|
|
|
for (iterator I = begin(), E = end(); I != E; ++I)
|
|
|
|
I->dropAllReferences();
|
2009-10-28 03:37:35 +00:00
|
|
|
|
|
|
|
// Delete all basic blocks.
|
|
|
|
while (!BasicBlocks.empty()) {
|
|
|
|
// If there is still a reference to the block, it must be a 'blockaddress'
|
|
|
|
// constant pointing to it. Just replace the BlockAddress with undef.
|
|
|
|
BasicBlock *BB = BasicBlocks.begin();
|
|
|
|
if (!BB->use_empty()) {
|
|
|
|
BlockAddress *BA = cast<BlockAddress>(BB->use_back());
|
|
|
|
BA->replaceAllUsesWith(UndefValue::get(BA->getType()));
|
|
|
|
BA->destroyConstant();
|
|
|
|
}
|
|
|
|
|
|
|
|
BB->eraseFromParent();
|
|
|
|
}
|
2001-06-06 20:29:01 +00:00
|
|
|
}
|
2001-09-10 07:58:01 +00:00
|
|
|
|
2008-09-25 21:00:45 +00:00
|
|
|
void Function::addAttribute(unsigned i, Attributes attr) {
|
|
|
|
AttrListPtr PAL = getAttributes();
|
2008-07-08 09:41:30 +00:00
|
|
|
PAL = PAL.addAttr(i, attr);
|
2008-09-25 21:00:45 +00:00
|
|
|
setAttributes(PAL);
|
2008-04-08 07:23:58 +00:00
|
|
|
}
|
|
|
|
|
2008-09-25 21:00:45 +00:00
|
|
|
void Function::removeAttribute(unsigned i, Attributes attr) {
|
|
|
|
AttrListPtr PAL = getAttributes();
|
2008-07-08 09:41:30 +00:00
|
|
|
PAL = PAL.removeAttr(i, attr);
|
2008-09-25 21:00:45 +00:00
|
|
|
setAttributes(PAL);
|
2008-05-16 20:39:43 +00:00
|
|
|
}
|
|
|
|
|
2008-08-17 18:44:35 +00: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-17 23:49:06 +00:00
|
|
|
static DenseMap<const Function*,PooledStringPtr> *GCNames;
|
|
|
|
static StringPool *GCNamePool;
|
2009-06-18 20:56:48 +00:00
|
|
|
static ManagedStatic<sys::SmartRWMutex<true> > GCLock;
|
2007-12-10 03:18:06 +00:00
|
|
|
|
2008-08-17 18:44:35 +00:00
|
|
|
bool Function::hasGC() const {
|
2009-07-07 18:33:04 +00:00
|
|
|
sys::SmartScopedReader<true> Reader(*GCLock);
|
2009-06-18 20:56:48 +00:00
|
|
|
return GCNames && GCNames->count(this);
|
2007-12-10 03:18:06 +00:00
|
|
|
}
|
|
|
|
|
2008-08-17 18:44:35 +00:00
|
|
|
const char *Function::getGC() const {
|
|
|
|
assert(hasGC() && "Function has no collector");
|
2009-07-07 18:33:04 +00:00
|
|
|
sys::SmartScopedReader<true> Reader(*GCLock);
|
2009-06-18 20:56:48 +00:00
|
|
|
return *(*GCNames)[this];
|
2007-12-10 03:18:06 +00:00
|
|
|
}
|
|
|
|
|
2008-08-17 18:44:35 +00:00
|
|
|
void Function::setGC(const char *Str) {
|
2009-07-07 18:33:04 +00:00
|
|
|
sys::SmartScopedWriter<true> Writer(*GCLock);
|
2009-06-17 23:49:06 +00:00
|
|
|
if (!GCNamePool)
|
|
|
|
GCNamePool = new StringPool();
|
|
|
|
if (!GCNames)
|
|
|
|
GCNames = new DenseMap<const Function*,PooledStringPtr>();
|
|
|
|
(*GCNames)[this] = GCNamePool->intern(Str);
|
2007-12-10 03:18:06 +00:00
|
|
|
}
|
|
|
|
|
2008-08-17 18:44:35 +00:00
|
|
|
void Function::clearGC() {
|
2009-07-07 18:33:04 +00:00
|
|
|
sys::SmartScopedWriter<true> Writer(*GCLock);
|
2009-06-17 23:49:06 +00:00
|
|
|
if (GCNames) {
|
2008-08-17 18:44:35 +00:00
|
|
|
GCNames->erase(this);
|
2009-06-17 23:49:06 +00:00
|
|
|
if (GCNames->empty()) {
|
|
|
|
delete GCNames;
|
|
|
|
GCNames = 0;
|
|
|
|
if (GCNamePool->empty()) {
|
|
|
|
delete GCNamePool;
|
|
|
|
GCNamePool = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-12-10 03:18:06 +00:00
|
|
|
}
|
|
|
|
|
2008-05-26 19:58:59 +00: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 21:00:45 +00:00
|
|
|
setAttributes(SrcF->getAttributes());
|
2008-08-17 18:44:35 +00:00
|
|
|
if (SrcF->hasGC())
|
|
|
|
setGC(SrcF->getGC());
|
|
|
|
else
|
|
|
|
clearGC();
|
2008-05-26 19:58:59 +00:00
|
|
|
}
|
|
|
|
|
2003-05-08 03:47:33 +00:00
|
|
|
/// getIntrinsicID - This method returns the ID number of the specified
|
2003-11-11 22:41:34 +00:00
|
|
|
/// function, or Intrinsic::not_intrinsic if the function is not an
|
2003-10-10 17:54:14 +00:00
|
|
|
/// intrinsic, or if the pointer is null. This value is always defined to be
|
2003-05-08 03:47:33 +00: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
|
|
|
|
/// llvm/Intrinsics.h.
|
|
|
|
///
|
2009-02-05 01:49:45 +00:00
|
|
|
unsigned Function::getIntrinsicID() const {
|
2007-02-15 19:17:16 +00:00
|
|
|
const ValueName *ValName = this->getValueName();
|
2007-04-16 07:08:44 +00:00
|
|
|
if (!ValName)
|
|
|
|
return 0;
|
2007-02-15 19:17:16 +00:00
|
|
|
unsigned Len = ValName->getKeyLength();
|
|
|
|
const char *Name = ValName->getKeyData();
|
|
|
|
|
2007-04-16 16:56:54 +00:00
|
|
|
if (Len < 5 || Name[4] != '.' || Name[0] != 'l' || Name[1] != 'l'
|
For PR411:
This patch is an incremental step towards supporting a flat symbol table.
It de-overloads the intrinsic functions by providing type-specific intrinsics
and arranging for automatically upgrading from the old overloaded name to
the new non-overloaded name. Specifically:
llvm.isunordered -> llvm.isunordered.f32, llvm.isunordered.f64
llvm.sqrt -> llvm.sqrt.f32, llvm.sqrt.f64
llvm.ctpop -> llvm.ctpop.i8, llvm.ctpop.i16, llvm.ctpop.i32, llvm.ctpop.i64
llvm.ctlz -> llvm.ctlz.i8, llvm.ctlz.i16, llvm.ctlz.i32, llvm.ctlz.i64
llvm.cttz -> llvm.cttz.i8, llvm.cttz.i16, llvm.cttz.i32, llvm.cttz.i64
New code should not use the overloaded intrinsic names. Warnings will be
emitted if they are used.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25366 91177308-0d34-0410-b5e6-96231b3b80d8
2006-01-16 21:12:35 +00:00
|
|
|
|| Name[2] != 'v' || Name[3] != 'm')
|
2003-05-08 03:47:33 +00:00
|
|
|
return 0; // All intrinsics start with 'llvm.'
|
2003-09-19 19:31:41 +00:00
|
|
|
|
2006-03-09 20:35:01 +00:00
|
|
|
#define GET_FUNCTION_RECOGNIZER
|
|
|
|
#include "llvm/Intrinsics.gen"
|
|
|
|
#undef GET_FUNCTION_RECOGNIZER
|
2003-05-08 03:47:33 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-04-01 07:25:33 +00:00
|
|
|
std::string Intrinsic::getName(ID id, const Type **Tys, unsigned numTys) {
|
2006-03-25 06:32:47 +00:00
|
|
|
assert(id < num_intrinsics && "Invalid intrinsic ID!");
|
|
|
|
const char * const Table[] = {
|
|
|
|
"not_intrinsic",
|
|
|
|
#define GET_INTRINSIC_NAME_TABLE
|
|
|
|
#include "llvm/Intrinsics.gen"
|
|
|
|
#undef GET_INTRINSIC_NAME_TABLE
|
|
|
|
};
|
2007-04-01 07:25:33 +00:00
|
|
|
if (numTys == 0)
|
|
|
|
return Table[id];
|
|
|
|
std::string Result(Table[id]);
|
2008-07-30 04:36:53 +00:00
|
|
|
for (unsigned i = 0; i < numTys; ++i) {
|
|
|
|
if (const PointerType* PTyp = dyn_cast<PointerType>(Tys[i])) {
|
|
|
|
Result += ".p" + llvm::utostr(PTyp->getAddressSpace()) +
|
2009-08-10 22:56:29 +00:00
|
|
|
EVT::getEVT(PTyp->getElementType()).getEVTString();
|
2008-07-30 04:36:53 +00:00
|
|
|
}
|
|
|
|
else if (Tys[i])
|
2009-08-10 22:56:29 +00:00
|
|
|
Result += "." + EVT::getEVT(Tys[i]).getEVTString();
|
2008-07-30 04:36:53 +00:00
|
|
|
}
|
2007-04-01 07:25:33 +00:00
|
|
|
return Result;
|
2006-03-25 06:32:47 +00:00
|
|
|
}
|
|
|
|
|
2009-07-07 23:43:39 +00:00
|
|
|
const FunctionType *Intrinsic::getType(LLVMContext &Context,
|
|
|
|
ID id, const Type **Tys,
|
2007-06-05 23:49:06 +00:00
|
|
|
unsigned numTys) {
|
2007-02-07 20:38:26 +00:00
|
|
|
const Type *ResultTy = NULL;
|
|
|
|
std::vector<const Type*> ArgTys;
|
|
|
|
bool IsVarArg = false;
|
|
|
|
|
|
|
|
#define GET_INTRINSIC_GENERATOR
|
|
|
|
#include "llvm/Intrinsics.gen"
|
|
|
|
#undef GET_INTRINSIC_GENERATOR
|
|
|
|
|
2009-07-29 22:17:13 +00:00
|
|
|
return FunctionType::get(ResultTy, ArgTys, IsVarArg);
|
2007-02-07 20:38:26 +00:00
|
|
|
}
|
|
|
|
|
2009-02-24 23:17:49 +00:00
|
|
|
bool Intrinsic::isOverloaded(ID id) {
|
|
|
|
const bool OTable[] = {
|
|
|
|
false,
|
|
|
|
#define GET_INTRINSIC_OVERLOAD_TABLE
|
|
|
|
#include "llvm/Intrinsics.gen"
|
|
|
|
#undef GET_INTRINSIC_OVERLOAD_TABLE
|
|
|
|
};
|
|
|
|
return OTable[id];
|
|
|
|
}
|
|
|
|
|
2009-01-12 01:18:58 +00:00
|
|
|
/// This defines the "Intrinsic::getAttributes(ID id)" method.
|
2007-12-03 20:06:50 +00:00
|
|
|
#define GET_INTRINSIC_ATTRIBUTES
|
|
|
|
#include "llvm/Intrinsics.gen"
|
|
|
|
#undef GET_INTRINSIC_ATTRIBUTES
|
|
|
|
|
2007-04-01 07:25:33 +00:00
|
|
|
Function *Intrinsic::getDeclaration(Module *M, ID id, const Type **Tys,
|
|
|
|
unsigned numTys) {
|
2007-12-03 20:06:50 +00:00
|
|
|
// There can never be multiple globals with the same name of different types,
|
|
|
|
// because intrinsics must be a specific type.
|
2008-04-07 13:39:11 +00:00
|
|
|
return
|
2007-12-03 20:06:50 +00:00
|
|
|
cast<Function>(M->getOrInsertFunction(getName(id, Tys, numTys),
|
2009-07-07 23:43:39 +00:00
|
|
|
getType(M->getContext(),
|
|
|
|
id, Tys, numTys)));
|
2007-02-07 20:38:26 +00:00
|
|
|
}
|
|
|
|
|
2009-02-05 01:49:45 +00:00
|
|
|
// This defines the "Intrinsic::getIntrinsicForGCCBuiltin()" method.
|
|
|
|
#define GET_LLVM_INTRINSIC_FOR_GCC_BUILTIN
|
|
|
|
#include "llvm/Intrinsics.gen"
|
|
|
|
#undef GET_LLVM_INTRINSIC_FOR_GCC_BUILTIN
|
|
|
|
|
2010-03-23 14:40:20 +00:00
|
|
|
/// hasAddressTaken - returns true if there are any uses of this function
|
|
|
|
/// other than direct calls or invokes to it.
|
2010-03-24 13:21:49 +00:00
|
|
|
bool Function::hasAddressTaken(const User* *PutOffender) const {
|
2010-03-25 23:06:16 +00:00
|
|
|
for (Value::const_use_iterator I = use_begin(), E = use_end(); I != E; ++I) {
|
2010-03-24 13:21:49 +00:00
|
|
|
const User *U = *I;
|
|
|
|
if (!isa<CallInst>(U) && !isa<InvokeInst>(U))
|
|
|
|
return PutOffender ? (*PutOffender = U, true) : true;
|
|
|
|
CallSite CS(const_cast<Instruction*>(static_cast<const Instruction*>(U)));
|
|
|
|
if (!CS.isCallee(I))
|
|
|
|
return PutOffender ? (*PutOffender = U, true) : true;
|
2009-06-10 08:41:11 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2004-07-17 23:50:19 +00:00
|
|
|
// vim: sw=2 ai
|