blob: 045056643b548cc2cdd96e4b52fc2a8fe2a203b2 [file] [log] [blame]
Chris Lattner44d2c352003-10-13 03:32:08 +00001//===-- Function.cpp - Implement the Global object classes ----------------===//
Misha Brukmanb1c93172005-04-21 23:48:37 +00002//
John Criswell482202a2003-10-20 19:43:21 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Misha Brukmanb1c93172005-04-21 23:48:37 +00007//
John Criswell482202a2003-10-20 19:43:21 +00008//===----------------------------------------------------------------------===//
Chris Lattner2f7c9632001-06-06 20:29:01 +00009//
Reid Spencer3aaaa0b2007-02-05 20:47:22 +000010// This file implements the Function class for the VMCore library.
Chris Lattner2f7c9632001-06-06 20:29:01 +000011//
12//===----------------------------------------------------------------------===//
13
Chris Lattner2f7c9632001-06-06 20:29:01 +000014#include "llvm/Module.h"
Chris Lattner6213ae02002-09-06 20:46:32 +000015#include "llvm/DerivedTypes.h"
Chris Lattner89046ca2004-10-12 04:20:25 +000016#include "llvm/IntrinsicInst.h"
Dan Gohman3a071482007-08-20 19:23:34 +000017#include "llvm/CodeGen/ValueTypes.h"
Reid Spencer7c16caa2004-09-01 22:55:40 +000018#include "llvm/Support/LeakDetector.h"
Owen Andersonaab59c52009-06-17 22:23:31 +000019#include "llvm/Support/ManagedStatic.h"
Gordon Henriksen71183b62007-12-10 03:18:06 +000020#include "llvm/Support/StringPool.h"
Owen Andersonaab59c52009-06-17 22:23:31 +000021#include "llvm/System/RWMutex.h"
Owen Anderson7d42b952009-06-18 16:54:52 +000022#include "llvm/System/Threading.h"
Chris Lattner113f4f42002-06-25 16:13:24 +000023#include "SymbolTableListTraitsImpl.h"
Gordon Henriksen71183b62007-12-10 03:18:06 +000024#include "llvm/ADT/DenseMap.h"
Chris Lattnerb392d302004-12-05 06:43:27 +000025#include "llvm/ADT/StringExtras.h"
Chris Lattner189d19f2003-11-21 20:23:48 +000026using namespace llvm;
Brian Gaeke960707c2003-11-11 22:41:34 +000027
Chris Lattner113f4f42002-06-25 16:13:24 +000028
29// Explicit instantiations of SymbolTableListTraits since some of the methods
30// are not in the public header file...
Chris Lattnerb47aa542007-04-17 03:26:42 +000031template class SymbolTableListTraits<Argument, Function>;
32template class SymbolTableListTraits<BasicBlock, Function>;
Chris Lattner2f7c9632001-06-06 20:29:01 +000033
Chris Lattnerda975502001-09-10 07:58:01 +000034//===----------------------------------------------------------------------===//
Chris Lattnerd255ae22002-04-09 19:39:35 +000035// Argument Implementation
36//===----------------------------------------------------------------------===//
37
Misha Brukmanb1c93172005-04-21 23:48:37 +000038Argument::Argument(const Type *Ty, const std::string &Name, Function *Par)
Chris Lattner32ab6432007-02-12 05:18:08 +000039 : Value(Ty, Value::ArgumentVal) {
Chris Lattner9ed7aef2002-09-06 21:33:15 +000040 Parent = 0;
Chris Lattner184b2982002-09-08 18:59:35 +000041
42 // Make sure that we get added to a function
43 LeakDetector::addGarbageObject(this);
44
Chris Lattner9ed7aef2002-09-06 21:33:15 +000045 if (Par)
46 Par->getArgumentList().push_back(this);
Chris Lattner32ab6432007-02-12 05:18:08 +000047 setName(Name);
Chris Lattner9ed7aef2002-09-06 21:33:15 +000048}
49
Chris Lattner9ed7aef2002-09-06 21:33:15 +000050void Argument::setParent(Function *parent) {
Chris Lattner184b2982002-09-08 18:59:35 +000051 if (getParent())
52 LeakDetector::addGarbageObject(this);
Chris Lattner9ed7aef2002-09-06 21:33:15 +000053 Parent = parent;
Chris Lattner184b2982002-09-08 18:59:35 +000054 if (getParent())
55 LeakDetector::removeGarbageObject(this);
Chris Lattner9ed7aef2002-09-06 21:33:15 +000056}
57
Chris Lattnere30f09d2008-01-24 17:47:11 +000058/// getArgNo - Return the index of this formal argument in its containing
59/// function. For example in "void foo(int a, float b)" a is 0 and b is 1.
60unsigned Argument::getArgNo() const {
61 const Function *F = getParent();
62 assert(F && "Argument is not in a function");
63
64 Function::const_arg_iterator AI = F->arg_begin();
65 unsigned ArgIdx = 0;
66 for (; &*AI != this; ++AI)
67 ++ArgIdx;
68
69 return ArgIdx;
70}
71
72/// hasByValAttr - Return true if this argument has the byval attribute on it
73/// in its containing function.
74bool Argument::hasByValAttr() const {
75 if (!isa<PointerType>(getType())) return false;
Devang Patel4c758ea2008-09-25 21:00:45 +000076 return getParent()->paramHasAttr(getArgNo()+1, Attribute::ByVal);
Chris Lattnere30f09d2008-01-24 17:47:11 +000077}
78
79/// hasNoAliasAttr - Return true if this argument has the noalias attribute on
80/// it in its containing function.
81bool Argument::hasNoAliasAttr() const {
82 if (!isa<PointerType>(getType())) return false;
Devang Patel4c758ea2008-09-25 21:00:45 +000083 return getParent()->paramHasAttr(getArgNo()+1, Attribute::NoAlias);
Chris Lattnere30f09d2008-01-24 17:47:11 +000084}
85
Duncan Sandsdf128eb2008-12-31 18:08:59 +000086/// hasNoCaptureAttr - Return true if this argument has the nocapture attribute
87/// on it in its containing function.
88bool Argument::hasNoCaptureAttr() const {
89 if (!isa<PointerType>(getType())) return false;
90 return getParent()->paramHasAttr(getArgNo()+1, Attribute::NoCapture);
91}
92
Owen Andersonc64dfb42008-02-17 23:22:28 +000093/// hasSRetAttr - Return true if this argument has the sret attribute on
94/// it in its containing function.
95bool Argument::hasStructRetAttr() const {
96 if (!isa<PointerType>(getType())) return false;
Gabor Greif697e94c2008-05-15 10:04:30 +000097 if (this != getParent()->arg_begin())
98 return false; // StructRet param must be first param
Devang Patel4c758ea2008-09-25 21:00:45 +000099 return getParent()->paramHasAttr(1, Attribute::StructRet);
Owen Andersonc64dfb42008-02-17 23:22:28 +0000100}
101
Devang Patel4c758ea2008-09-25 21:00:45 +0000102/// addAttr - Add a Attribute to an argument
Devang Patelba3fa6c2008-09-23 23:03:40 +0000103void Argument::addAttr(Attributes attr) {
Devang Patel4c758ea2008-09-25 21:00:45 +0000104 getParent()->addAttribute(getArgNo() + 1, attr);
Gordon Henriksen2d9cc212008-04-28 17:37:06 +0000105}
Chris Lattnere30f09d2008-01-24 17:47:11 +0000106
Devang Patel4c758ea2008-09-25 21:00:45 +0000107/// removeAttr - Remove a Attribute from an argument
Devang Patelba3fa6c2008-09-23 23:03:40 +0000108void Argument::removeAttr(Attributes attr) {
Devang Patel4c758ea2008-09-25 21:00:45 +0000109 getParent()->removeAttribute(getArgNo() + 1, attr);
Duncan Sands66336db2008-07-08 09:41:30 +0000110}
Chris Lattnere30f09d2008-01-24 17:47:11 +0000111
112
Chris Lattnerd255ae22002-04-09 19:39:35 +0000113//===----------------------------------------------------------------------===//
Chris Lattner3e13b8c2008-01-02 23:42:30 +0000114// Helper Methods in Function
Reid Spencer019c8862007-04-09 15:01:12 +0000115//===----------------------------------------------------------------------===//
116
Chris Lattner3e13b8c2008-01-02 23:42:30 +0000117const FunctionType *Function::getFunctionType() const {
118 return cast<FunctionType>(getType()->getElementType());
Reid Spencer019c8862007-04-09 15:01:12 +0000119}
120
Chris Lattner3e13b8c2008-01-02 23:42:30 +0000121bool Function::isVarArg() const {
122 return getFunctionType()->isVarArg();
Reid Spencer019c8862007-04-09 15:01:12 +0000123}
124
Chris Lattner3e13b8c2008-01-02 23:42:30 +0000125const Type *Function::getReturnType() const {
126 return getFunctionType()->getReturnType();
Duncan Sands185eeac2007-11-25 14:10:56 +0000127}
128
Chris Lattner3e13b8c2008-01-02 23:42:30 +0000129void Function::removeFromParent() {
130 getParent()->getFunctionList().remove(this);
Duncan Sands185eeac2007-11-25 14:10:56 +0000131}
132
Chris Lattner3e13b8c2008-01-02 23:42:30 +0000133void Function::eraseFromParent() {
134 getParent()->getFunctionList().erase(this);
Reid Spencer019c8862007-04-09 15:01:12 +0000135}
136
Reid Spencer019c8862007-04-09 15:01:12 +0000137//===----------------------------------------------------------------------===//
Chris Lattner57698e22002-03-26 18:01:55 +0000138// Function Implementation
Chris Lattnerda975502001-09-10 07:58:01 +0000139//===----------------------------------------------------------------------===//
140
Chris Lattner379a8d22003-04-16 20:28:45 +0000141Function::Function(const FunctionType *Ty, LinkageTypes Linkage,
Chris Lattner6213ae02002-09-06 20:46:32 +0000142 const std::string &name, Module *ParentModule)
Christopher Lambedf07882007-12-17 01:12:55 +0000143 : GlobalValue(PointerType::getUnqual(Ty),
Chris Lattner8a923e72008-03-12 17:45:29 +0000144 Value::FunctionVal, 0, 0, Linkage, name) {
Chris Lattner654695b2009-01-05 07:58:59 +0000145 assert(FunctionType::isValidReturnType(getReturnType()) &&
146 !isa<OpaqueType>(getReturnType()) && "invalid return type");
Reid Spencer3aaaa0b2007-02-05 20:47:22 +0000147 SymTab = new ValueSymbolTable();
Chris Lattner6213ae02002-09-06 20:46:32 +0000148
Chris Lattnere2de9082007-08-18 06:14:52 +0000149 // If the function has arguments, mark them as lazily built.
150 if (Ty->getNumParams())
151 SubclassData = 1; // Set the "has lazy arguments" bit.
152
Chris Lattner184b2982002-09-08 18:59:35 +0000153 // Make sure that we get added to a function
154 LeakDetector::addGarbageObject(this);
155
Chris Lattner6213ae02002-09-06 20:46:32 +0000156 if (ParentModule)
157 ParentModule->getFunctionList().push_back(this);
Duncan Sandsa8ff6ca2008-04-07 13:39:11 +0000158
159 // Ensure intrinsics have the right parameter attributes.
Dale Johannesenb842d522009-02-05 01:49:45 +0000160 if (unsigned IID = getIntrinsicID())
Devang Patel4c758ea2008-09-25 21:00:45 +0000161 setAttributes(Intrinsic::getAttributes(Intrinsic::ID(IID)));
Devang Pateld334a432008-09-02 20:51:15 +0000162
Chris Lattner2f7c9632001-06-06 20:29:01 +0000163}
164
Gordon Henriksen14a55692007-12-10 02:14:30 +0000165Function::~Function() {
166 dropAllReferences(); // After this it is safe to delete instructions.
Chris Lattner2f7c9632001-06-06 20:29:01 +0000167
Chris Lattner2f7c9632001-06-06 20:29:01 +0000168 // Delete all of the method arguments and unlink from symbol table...
Gordon Henriksen14a55692007-12-10 02:14:30 +0000169 ArgumentList.clear();
170 delete SymTab;
Reid Spencerc6a83842007-04-22 17:28:03 +0000171
Gordon Henriksend930f912008-08-17 18:44:35 +0000172 // Remove the function from the on-the-side GC table.
173 clearGC();
Chris Lattner2f7c9632001-06-06 20:29:01 +0000174}
175
Chris Lattnere2de9082007-08-18 06:14:52 +0000176void Function::BuildLazyArguments() const {
177 // Create the arguments vector, all arguments start out unnamed.
178 const FunctionType *FT = getFunctionType();
179 for (unsigned i = 0, e = FT->getNumParams(); i != e; ++i) {
180 assert(FT->getParamType(i) != Type::VoidTy &&
181 "Cannot have void typed arguments!");
182 ArgumentList.push_back(new Argument(FT->getParamType(i)));
183 }
184
185 // Clear the lazy arguments bit.
186 const_cast<Function*>(this)->SubclassData &= ~1;
187}
188
189size_t Function::arg_size() const {
190 return getFunctionType()->getNumParams();
191}
192bool Function::arg_empty() const {
193 return getFunctionType()->getNumParams() == 0;
194}
195
Chris Lattner4e8c4872002-03-23 22:51:58 +0000196void Function::setParent(Module *parent) {
Chris Lattner184b2982002-09-08 18:59:35 +0000197 if (getParent())
198 LeakDetector::addGarbageObject(this);
Chris Lattner2f7c9632001-06-06 20:29:01 +0000199 Parent = parent;
Chris Lattner184b2982002-09-08 18:59:35 +0000200 if (getParent())
201 LeakDetector::removeGarbageObject(this);
Chris Lattner2f7c9632001-06-06 20:29:01 +0000202}
203
Chris Lattner2f7c9632001-06-06 20:29:01 +0000204// dropAllReferences() - This function causes all the subinstructions to "let
205// go" of all references that they are maintaining. This allows one to
206// 'delete' a whole class at a time, even though there may be circular
207// references... first all references are dropped, and all use counts go to
Misha Brukmanfa100532003-10-10 17:54:14 +0000208// zero. Then everything is deleted for real. Note that no operations are
Misha Brukmanb1c93172005-04-21 23:48:37 +0000209// valid on an object that has "dropped all references", except operator
Chris Lattner2f7c9632001-06-06 20:29:01 +0000210// delete.
211//
Chris Lattner4e8c4872002-03-23 22:51:58 +0000212void Function::dropAllReferences() {
Chris Lattner113f4f42002-06-25 16:13:24 +0000213 for (iterator I = begin(), E = end(); I != E; ++I)
214 I->dropAllReferences();
Chris Lattnerc1b16512003-09-17 04:58:59 +0000215 BasicBlocks.clear(); // Delete all basic blocks...
Chris Lattner2f7c9632001-06-06 20:29:01 +0000216}
Chris Lattnerda975502001-09-10 07:58:01 +0000217
Devang Patel4c758ea2008-09-25 21:00:45 +0000218void Function::addAttribute(unsigned i, Attributes attr) {
219 AttrListPtr PAL = getAttributes();
Eric Christopher901b1a72008-05-16 20:39:43 +0000220 PAL = PAL.addAttr(i, attr);
Devang Patel4c758ea2008-09-25 21:00:45 +0000221 setAttributes(PAL);
Eric Christopher901b1a72008-05-16 20:39:43 +0000222}
223
Devang Patel4c758ea2008-09-25 21:00:45 +0000224void Function::removeAttribute(unsigned i, Attributes attr) {
225 AttrListPtr PAL = getAttributes();
Duncan Sands66336db2008-07-08 09:41:30 +0000226 PAL = PAL.removeAttr(i, attr);
Devang Patel4c758ea2008-09-25 21:00:45 +0000227 setAttributes(PAL);
Duncan Sands66336db2008-07-08 09:41:30 +0000228}
229
Gordon Henriksend930f912008-08-17 18:44:35 +0000230// Maintain the GC name for each function in an on-the-side table. This saves
231// allocating an additional word in Function for programs which do not use GC
232// (i.e., most programs) at the cost of increased overhead for clients which do
233// use GC.
Owen Andersoned14e762009-06-17 23:49:06 +0000234static DenseMap<const Function*,PooledStringPtr> *GCNames;
235static StringPool *GCNamePool;
Owen Anderson7f1ef672009-06-18 20:56:48 +0000236static ManagedStatic<sys::SmartRWMutex<true> > GCLock;
Gordon Henriksen71183b62007-12-10 03:18:06 +0000237
Gordon Henriksend930f912008-08-17 18:44:35 +0000238bool Function::hasGC() const {
Owen Anderson7f1ef672009-06-18 20:56:48 +0000239 sys::SmartScopedReader<true> Reader(&*GCLock);
240 return GCNames && GCNames->count(this);
Gordon Henriksen71183b62007-12-10 03:18:06 +0000241}
242
Gordon Henriksend930f912008-08-17 18:44:35 +0000243const char *Function::getGC() const {
244 assert(hasGC() && "Function has no collector");
Owen Anderson7f1ef672009-06-18 20:56:48 +0000245 sys::SmartScopedReader<true> Reader(&*GCLock);
246 return *(*GCNames)[this];
Gordon Henriksen71183b62007-12-10 03:18:06 +0000247}
248
Gordon Henriksend930f912008-08-17 18:44:35 +0000249void Function::setGC(const char *Str) {
Owen Anderson7f1ef672009-06-18 20:56:48 +0000250 sys::SmartScopedWriter<true> Writer(&*GCLock);
Owen Andersoned14e762009-06-17 23:49:06 +0000251 if (!GCNamePool)
252 GCNamePool = new StringPool();
253 if (!GCNames)
254 GCNames = new DenseMap<const Function*,PooledStringPtr>();
255 (*GCNames)[this] = GCNamePool->intern(Str);
Gordon Henriksen71183b62007-12-10 03:18:06 +0000256}
257
Gordon Henriksend930f912008-08-17 18:44:35 +0000258void Function::clearGC() {
Owen Anderson7f1ef672009-06-18 20:56:48 +0000259 sys::SmartScopedWriter<true> Writer(&*GCLock);
Owen Andersoned14e762009-06-17 23:49:06 +0000260 if (GCNames) {
Gordon Henriksend930f912008-08-17 18:44:35 +0000261 GCNames->erase(this);
Owen Andersoned14e762009-06-17 23:49:06 +0000262 if (GCNames->empty()) {
263 delete GCNames;
264 GCNames = 0;
265 if (GCNamePool->empty()) {
266 delete GCNamePool;
267 GCNamePool = 0;
268 }
269 }
270 }
Gordon Henriksen71183b62007-12-10 03:18:06 +0000271}
272
Duncan Sandsdd7daee2008-05-26 19:58:59 +0000273/// copyAttributesFrom - copy all additional attributes (those not needed to
274/// create a Function) from the Function Src to this one.
275void Function::copyAttributesFrom(const GlobalValue *Src) {
276 assert(isa<Function>(Src) && "Expected a Function!");
277 GlobalValue::copyAttributesFrom(Src);
278 const Function *SrcF = cast<Function>(Src);
279 setCallingConv(SrcF->getCallingConv());
Devang Patel4c758ea2008-09-25 21:00:45 +0000280 setAttributes(SrcF->getAttributes());
Gordon Henriksend930f912008-08-17 18:44:35 +0000281 if (SrcF->hasGC())
282 setGC(SrcF->getGC());
283 else
284 clearGC();
Duncan Sandsdd7daee2008-05-26 19:58:59 +0000285}
286
Chris Lattnerbb346d02003-05-08 03:47:33 +0000287/// getIntrinsicID - This method returns the ID number of the specified
Brian Gaeke960707c2003-11-11 22:41:34 +0000288/// function, or Intrinsic::not_intrinsic if the function is not an
Misha Brukmanfa100532003-10-10 17:54:14 +0000289/// intrinsic, or if the pointer is null. This value is always defined to be
Chris Lattnerbb346d02003-05-08 03:47:33 +0000290/// zero to allow easy checking for whether a function is intrinsic or not. The
291/// particular intrinsic functions which correspond to this value are defined in
292/// llvm/Intrinsics.h.
293///
Dale Johannesenb842d522009-02-05 01:49:45 +0000294unsigned Function::getIntrinsicID() const {
Chris Lattner1e92e062007-02-15 19:17:16 +0000295 const ValueName *ValName = this->getValueName();
Reid Spencerc5f397a2007-04-16 07:08:44 +0000296 if (!ValName)
297 return 0;
Chris Lattner1e92e062007-02-15 19:17:16 +0000298 unsigned Len = ValName->getKeyLength();
299 const char *Name = ValName->getKeyData();
300
Reid Spencer78d71f12007-04-16 16:56:54 +0000301 if (Len < 5 || Name[4] != '.' || Name[0] != 'l' || Name[1] != 'l'
Reid Spencerb4f9a6f2006-01-16 21:12:35 +0000302 || Name[2] != 'v' || Name[3] != 'm')
Chris Lattnerbb346d02003-05-08 03:47:33 +0000303 return 0; // All intrinsics start with 'llvm.'
Chris Lattner3284ed72003-09-19 19:31:41 +0000304
Chris Lattnerff4d4ee2006-03-09 20:35:01 +0000305#define GET_FUNCTION_RECOGNIZER
306#include "llvm/Intrinsics.gen"
307#undef GET_FUNCTION_RECOGNIZER
Chris Lattnerbb346d02003-05-08 03:47:33 +0000308 return 0;
309}
310
Reid Spencer2a2117c2007-04-01 07:25:33 +0000311std::string Intrinsic::getName(ID id, const Type **Tys, unsigned numTys) {
Chris Lattner71b8c982006-03-25 06:32:47 +0000312 assert(id < num_intrinsics && "Invalid intrinsic ID!");
313 const char * const Table[] = {
314 "not_intrinsic",
315#define GET_INTRINSIC_NAME_TABLE
316#include "llvm/Intrinsics.gen"
317#undef GET_INTRINSIC_NAME_TABLE
318 };
Reid Spencer2a2117c2007-04-01 07:25:33 +0000319 if (numTys == 0)
320 return Table[id];
321 std::string Result(Table[id]);
Mon P Wang2c839d42008-07-30 04:36:53 +0000322 for (unsigned i = 0; i < numTys; ++i) {
323 if (const PointerType* PTyp = dyn_cast<PointerType>(Tys[i])) {
324 Result += ".p" + llvm::utostr(PTyp->getAddressSpace()) +
325 MVT::getMVT(PTyp->getElementType()).getMVTString();
326 }
327 else if (Tys[i])
Duncan Sands13237ac2008-06-06 12:08:01 +0000328 Result += "." + MVT::getMVT(Tys[i]).getMVTString();
Mon P Wang2c839d42008-07-30 04:36:53 +0000329 }
Reid Spencer2a2117c2007-04-01 07:25:33 +0000330 return Result;
Chris Lattner71b8c982006-03-25 06:32:47 +0000331}
332
Reid Spencer2a2117c2007-04-01 07:25:33 +0000333const FunctionType *Intrinsic::getType(ID id, const Type **Tys,
Chris Lattner31f82df2007-06-05 23:49:06 +0000334 unsigned numTys) {
Jim Laskey2682ea62007-02-07 20:38:26 +0000335 const Type *ResultTy = NULL;
336 std::vector<const Type*> ArgTys;
Jim Laskey2682ea62007-02-07 20:38:26 +0000337 bool IsVarArg = false;
338
339#define GET_INTRINSIC_GENERATOR
340#include "llvm/Intrinsics.gen"
341#undef GET_INTRINSIC_GENERATOR
342
Reid Spencer26d9ff62007-04-09 06:11:23 +0000343 return FunctionType::get(ResultTy, ArgTys, IsVarArg);
Jim Laskey2682ea62007-02-07 20:38:26 +0000344}
345
Mon P Wangb4024932009-02-24 23:17:49 +0000346bool Intrinsic::isOverloaded(ID id) {
347 const bool OTable[] = {
348 false,
349#define GET_INTRINSIC_OVERLOAD_TABLE
350#include "llvm/Intrinsics.gen"
351#undef GET_INTRINSIC_OVERLOAD_TABLE
352 };
353 return OTable[id];
354}
355
Chris Lattner49b7ee12009-01-12 01:18:58 +0000356/// This defines the "Intrinsic::getAttributes(ID id)" method.
Duncan Sands38ef3a82007-12-03 20:06:50 +0000357#define GET_INTRINSIC_ATTRIBUTES
358#include "llvm/Intrinsics.gen"
359#undef GET_INTRINSIC_ATTRIBUTES
360
Reid Spencer2a2117c2007-04-01 07:25:33 +0000361Function *Intrinsic::getDeclaration(Module *M, ID id, const Type **Tys,
362 unsigned numTys) {
Duncan Sands38ef3a82007-12-03 20:06:50 +0000363 // There can never be multiple globals with the same name of different types,
364 // because intrinsics must be a specific type.
Duncan Sandsa8ff6ca2008-04-07 13:39:11 +0000365 return
Duncan Sands38ef3a82007-12-03 20:06:50 +0000366 cast<Function>(M->getOrInsertFunction(getName(id, Tys, numTys),
367 getType(id, Tys, numTys)));
Jim Laskey2682ea62007-02-07 20:38:26 +0000368}
369
Dale Johannesenb842d522009-02-05 01:49:45 +0000370// This defines the "Intrinsic::getIntrinsicForGCCBuiltin()" method.
371#define GET_LLVM_INTRINSIC_FOR_GCC_BUILTIN
372#include "llvm/Intrinsics.gen"
373#undef GET_LLVM_INTRINSIC_FOR_GCC_BUILTIN
374
Jay Foad557169d2009-06-10 08:41:11 +0000375 /// hasAddressTaken - returns true if there are any uses of this function
376 /// other than direct calls or invokes to it.
377bool Function::hasAddressTaken() const {
378 for (Value::use_const_iterator I = use_begin(), E = use_end(); I != E; ++I) {
379 if (I.getOperandNo() != 0 ||
380 (!isa<CallInst>(*I) && !isa<InvokeInst>(*I)))
381 return true;
382 }
383 return false;
384}
385
Reid Spencerc49dd8d2004-07-17 23:50:19 +0000386// vim: sw=2 ai