blob: 96c679240510b846aeb4d302cd7e2f9fe343b116 [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"
Chris Lattner113f4f42002-06-25 16:13:24 +000022#include "SymbolTableListTraitsImpl.h"
Gordon Henriksen71183b62007-12-10 03:18:06 +000023#include "llvm/ADT/DenseMap.h"
Chris Lattnerb392d302004-12-05 06:43:27 +000024#include "llvm/ADT/StringExtras.h"
Chris Lattner189d19f2003-11-21 20:23:48 +000025using namespace llvm;
Brian Gaeke960707c2003-11-11 22:41:34 +000026
Chris Lattner113f4f42002-06-25 16:13:24 +000027
28// Explicit instantiations of SymbolTableListTraits since some of the methods
29// are not in the public header file...
Chris Lattnerb47aa542007-04-17 03:26:42 +000030template class SymbolTableListTraits<Argument, Function>;
31template class SymbolTableListTraits<BasicBlock, Function>;
Chris Lattner2f7c9632001-06-06 20:29:01 +000032
Chris Lattnerda975502001-09-10 07:58:01 +000033//===----------------------------------------------------------------------===//
Chris Lattnerd255ae22002-04-09 19:39:35 +000034// Argument Implementation
35//===----------------------------------------------------------------------===//
36
Misha Brukmanb1c93172005-04-21 23:48:37 +000037Argument::Argument(const Type *Ty, const std::string &Name, Function *Par)
Chris Lattner32ab6432007-02-12 05:18:08 +000038 : Value(Ty, Value::ArgumentVal) {
Chris Lattner9ed7aef2002-09-06 21:33:15 +000039 Parent = 0;
Chris Lattner184b2982002-09-08 18:59:35 +000040
41 // Make sure that we get added to a function
42 LeakDetector::addGarbageObject(this);
43
Chris Lattner9ed7aef2002-09-06 21:33:15 +000044 if (Par)
45 Par->getArgumentList().push_back(this);
Chris Lattner32ab6432007-02-12 05:18:08 +000046 setName(Name);
Chris Lattner9ed7aef2002-09-06 21:33:15 +000047}
48
Chris Lattner9ed7aef2002-09-06 21:33:15 +000049void Argument::setParent(Function *parent) {
Chris Lattner184b2982002-09-08 18:59:35 +000050 if (getParent())
51 LeakDetector::addGarbageObject(this);
Chris Lattner9ed7aef2002-09-06 21:33:15 +000052 Parent = parent;
Chris Lattner184b2982002-09-08 18:59:35 +000053 if (getParent())
54 LeakDetector::removeGarbageObject(this);
Chris Lattner9ed7aef2002-09-06 21:33:15 +000055}
56
Chris Lattnere30f09d2008-01-24 17:47:11 +000057/// getArgNo - Return the index of this formal argument in its containing
58/// function. For example in "void foo(int a, float b)" a is 0 and b is 1.
59unsigned Argument::getArgNo() const {
60 const Function *F = getParent();
61 assert(F && "Argument is not in a function");
62
63 Function::const_arg_iterator AI = F->arg_begin();
64 unsigned ArgIdx = 0;
65 for (; &*AI != this; ++AI)
66 ++ArgIdx;
67
68 return ArgIdx;
69}
70
71/// hasByValAttr - Return true if this argument has the byval attribute on it
72/// in its containing function.
73bool Argument::hasByValAttr() const {
74 if (!isa<PointerType>(getType())) return false;
Devang Patel4c758ea2008-09-25 21:00:45 +000075 return getParent()->paramHasAttr(getArgNo()+1, Attribute::ByVal);
Chris Lattnere30f09d2008-01-24 17:47:11 +000076}
77
78/// hasNoAliasAttr - Return true if this argument has the noalias attribute on
79/// it in its containing function.
80bool Argument::hasNoAliasAttr() const {
81 if (!isa<PointerType>(getType())) return false;
Devang Patel4c758ea2008-09-25 21:00:45 +000082 return getParent()->paramHasAttr(getArgNo()+1, Attribute::NoAlias);
Chris Lattnere30f09d2008-01-24 17:47:11 +000083}
84
Duncan Sandsdf128eb2008-12-31 18:08:59 +000085/// hasNoCaptureAttr - Return true if this argument has the nocapture attribute
86/// on it in its containing function.
87bool Argument::hasNoCaptureAttr() const {
88 if (!isa<PointerType>(getType())) return false;
89 return getParent()->paramHasAttr(getArgNo()+1, Attribute::NoCapture);
90}
91
Owen Andersonc64dfb42008-02-17 23:22:28 +000092/// hasSRetAttr - Return true if this argument has the sret attribute on
93/// it in its containing function.
94bool Argument::hasStructRetAttr() const {
95 if (!isa<PointerType>(getType())) return false;
Gabor Greif697e94c2008-05-15 10:04:30 +000096 if (this != getParent()->arg_begin())
97 return false; // StructRet param must be first param
Devang Patel4c758ea2008-09-25 21:00:45 +000098 return getParent()->paramHasAttr(1, Attribute::StructRet);
Owen Andersonc64dfb42008-02-17 23:22:28 +000099}
100
Devang Patel4c758ea2008-09-25 21:00:45 +0000101/// addAttr - Add a Attribute to an argument
Devang Patelba3fa6c2008-09-23 23:03:40 +0000102void Argument::addAttr(Attributes attr) {
Devang Patel4c758ea2008-09-25 21:00:45 +0000103 getParent()->addAttribute(getArgNo() + 1, attr);
Gordon Henriksen2d9cc212008-04-28 17:37:06 +0000104}
Chris Lattnere30f09d2008-01-24 17:47:11 +0000105
Devang Patel4c758ea2008-09-25 21:00:45 +0000106/// removeAttr - Remove a Attribute from an argument
Devang Patelba3fa6c2008-09-23 23:03:40 +0000107void Argument::removeAttr(Attributes attr) {
Devang Patel4c758ea2008-09-25 21:00:45 +0000108 getParent()->removeAttribute(getArgNo() + 1, attr);
Duncan Sands66336db2008-07-08 09:41:30 +0000109}
Chris Lattnere30f09d2008-01-24 17:47:11 +0000110
111
Chris Lattnerd255ae22002-04-09 19:39:35 +0000112//===----------------------------------------------------------------------===//
Chris Lattner3e13b8c2008-01-02 23:42:30 +0000113// Helper Methods in Function
Reid Spencer019c8862007-04-09 15:01:12 +0000114//===----------------------------------------------------------------------===//
115
Chris Lattner3e13b8c2008-01-02 23:42:30 +0000116const FunctionType *Function::getFunctionType() const {
117 return cast<FunctionType>(getType()->getElementType());
Reid Spencer019c8862007-04-09 15:01:12 +0000118}
119
Chris Lattner3e13b8c2008-01-02 23:42:30 +0000120bool Function::isVarArg() const {
121 return getFunctionType()->isVarArg();
Reid Spencer019c8862007-04-09 15:01:12 +0000122}
123
Chris Lattner3e13b8c2008-01-02 23:42:30 +0000124const Type *Function::getReturnType() const {
125 return getFunctionType()->getReturnType();
Duncan Sands185eeac2007-11-25 14:10:56 +0000126}
127
Chris Lattner3e13b8c2008-01-02 23:42:30 +0000128void Function::removeFromParent() {
129 getParent()->getFunctionList().remove(this);
Duncan Sands185eeac2007-11-25 14:10:56 +0000130}
131
Chris Lattner3e13b8c2008-01-02 23:42:30 +0000132void Function::eraseFromParent() {
133 getParent()->getFunctionList().erase(this);
Reid Spencer019c8862007-04-09 15:01:12 +0000134}
135
Reid Spencer019c8862007-04-09 15:01:12 +0000136//===----------------------------------------------------------------------===//
Chris Lattner57698e22002-03-26 18:01:55 +0000137// Function Implementation
Chris Lattnerda975502001-09-10 07:58:01 +0000138//===----------------------------------------------------------------------===//
139
Chris Lattner379a8d22003-04-16 20:28:45 +0000140Function::Function(const FunctionType *Ty, LinkageTypes Linkage,
Chris Lattner6213ae02002-09-06 20:46:32 +0000141 const std::string &name, Module *ParentModule)
Christopher Lambedf07882007-12-17 01:12:55 +0000142 : GlobalValue(PointerType::getUnqual(Ty),
Chris Lattner8a923e72008-03-12 17:45:29 +0000143 Value::FunctionVal, 0, 0, Linkage, name) {
Chris Lattner654695b2009-01-05 07:58:59 +0000144 assert(FunctionType::isValidReturnType(getReturnType()) &&
145 !isa<OpaqueType>(getReturnType()) && "invalid return type");
Reid Spencer3aaaa0b2007-02-05 20:47:22 +0000146 SymTab = new ValueSymbolTable();
Chris Lattner6213ae02002-09-06 20:46:32 +0000147
Chris Lattnere2de9082007-08-18 06:14:52 +0000148 // If the function has arguments, mark them as lazily built.
149 if (Ty->getNumParams())
150 SubclassData = 1; // Set the "has lazy arguments" bit.
151
Chris Lattner184b2982002-09-08 18:59:35 +0000152 // Make sure that we get added to a function
153 LeakDetector::addGarbageObject(this);
154
Chris Lattner6213ae02002-09-06 20:46:32 +0000155 if (ParentModule)
156 ParentModule->getFunctionList().push_back(this);
Duncan Sandsa8ff6ca2008-04-07 13:39:11 +0000157
158 // Ensure intrinsics have the right parameter attributes.
Dale Johannesenb842d522009-02-05 01:49:45 +0000159 if (unsigned IID = getIntrinsicID())
Devang Patel4c758ea2008-09-25 21:00:45 +0000160 setAttributes(Intrinsic::getAttributes(Intrinsic::ID(IID)));
Devang Pateld334a432008-09-02 20:51:15 +0000161
Chris Lattner2f7c9632001-06-06 20:29:01 +0000162}
163
Gordon Henriksen14a55692007-12-10 02:14:30 +0000164Function::~Function() {
165 dropAllReferences(); // After this it is safe to delete instructions.
Chris Lattner2f7c9632001-06-06 20:29:01 +0000166
Chris Lattner2f7c9632001-06-06 20:29:01 +0000167 // Delete all of the method arguments and unlink from symbol table...
Gordon Henriksen14a55692007-12-10 02:14:30 +0000168 ArgumentList.clear();
169 delete SymTab;
Reid Spencerc6a83842007-04-22 17:28:03 +0000170
Gordon Henriksend930f912008-08-17 18:44:35 +0000171 // Remove the function from the on-the-side GC table.
172 clearGC();
Chris Lattner2f7c9632001-06-06 20:29:01 +0000173}
174
Chris Lattnere2de9082007-08-18 06:14:52 +0000175void Function::BuildLazyArguments() const {
176 // Create the arguments vector, all arguments start out unnamed.
177 const FunctionType *FT = getFunctionType();
178 for (unsigned i = 0, e = FT->getNumParams(); i != e; ++i) {
179 assert(FT->getParamType(i) != Type::VoidTy &&
180 "Cannot have void typed arguments!");
181 ArgumentList.push_back(new Argument(FT->getParamType(i)));
182 }
183
184 // Clear the lazy arguments bit.
185 const_cast<Function*>(this)->SubclassData &= ~1;
186}
187
188size_t Function::arg_size() const {
189 return getFunctionType()->getNumParams();
190}
191bool Function::arg_empty() const {
192 return getFunctionType()->getNumParams() == 0;
193}
194
Chris Lattner4e8c4872002-03-23 22:51:58 +0000195void Function::setParent(Module *parent) {
Chris Lattner184b2982002-09-08 18:59:35 +0000196 if (getParent())
197 LeakDetector::addGarbageObject(this);
Chris Lattner2f7c9632001-06-06 20:29:01 +0000198 Parent = parent;
Chris Lattner184b2982002-09-08 18:59:35 +0000199 if (getParent())
200 LeakDetector::removeGarbageObject(this);
Chris Lattner2f7c9632001-06-06 20:29:01 +0000201}
202
Chris Lattner2f7c9632001-06-06 20:29:01 +0000203// dropAllReferences() - This function causes all the subinstructions to "let
204// go" of all references that they are maintaining. This allows one to
205// 'delete' a whole class at a time, even though there may be circular
206// references... first all references are dropped, and all use counts go to
Misha Brukmanfa100532003-10-10 17:54:14 +0000207// zero. Then everything is deleted for real. Note that no operations are
Misha Brukmanb1c93172005-04-21 23:48:37 +0000208// valid on an object that has "dropped all references", except operator
Chris Lattner2f7c9632001-06-06 20:29:01 +0000209// delete.
210//
Chris Lattner4e8c4872002-03-23 22:51:58 +0000211void Function::dropAllReferences() {
Chris Lattner113f4f42002-06-25 16:13:24 +0000212 for (iterator I = begin(), E = end(); I != E; ++I)
213 I->dropAllReferences();
Chris Lattnerc1b16512003-09-17 04:58:59 +0000214 BasicBlocks.clear(); // Delete all basic blocks...
Chris Lattner2f7c9632001-06-06 20:29:01 +0000215}
Chris Lattnerda975502001-09-10 07:58:01 +0000216
Devang Patel4c758ea2008-09-25 21:00:45 +0000217void Function::addAttribute(unsigned i, Attributes attr) {
218 AttrListPtr PAL = getAttributes();
Eric Christopher901b1a72008-05-16 20:39:43 +0000219 PAL = PAL.addAttr(i, attr);
Devang Patel4c758ea2008-09-25 21:00:45 +0000220 setAttributes(PAL);
Eric Christopher901b1a72008-05-16 20:39:43 +0000221}
222
Devang Patel4c758ea2008-09-25 21:00:45 +0000223void Function::removeAttribute(unsigned i, Attributes attr) {
224 AttrListPtr PAL = getAttributes();
Duncan Sands66336db2008-07-08 09:41:30 +0000225 PAL = PAL.removeAttr(i, attr);
Devang Patel4c758ea2008-09-25 21:00:45 +0000226 setAttributes(PAL);
Duncan Sands66336db2008-07-08 09:41:30 +0000227}
228
Gordon Henriksend930f912008-08-17 18:44:35 +0000229// Maintain the GC name for each function in an on-the-side table. This saves
230// allocating an additional word in Function for programs which do not use GC
231// (i.e., most programs) at the cost of increased overhead for clients which do
232// use GC.
Owen Andersonaab59c52009-06-17 22:23:31 +0000233static ManagedStatic<DenseMap<const Function*,PooledStringPtr> > GCNames;
234static ManagedStatic<StringPool> GCNamePool;
235static ManagedStatic<sys::RWMutex> GCLock;
Gordon Henriksen71183b62007-12-10 03:18:06 +0000236
Gordon Henriksend930f912008-08-17 18:44:35 +0000237bool Function::hasGC() const {
Owen Andersonaab59c52009-06-17 22:23:31 +0000238 if (llvm_is_multithreaded()) {
239 sys::ScopedReader Reader(&*GCLock);
240 return GCNames->count(this);
241 } else
242 return GCNames->count(this);
Gordon Henriksen71183b62007-12-10 03:18:06 +0000243}
244
Gordon Henriksend930f912008-08-17 18:44:35 +0000245const char *Function::getGC() const {
246 assert(hasGC() && "Function has no collector");
Owen Andersonaab59c52009-06-17 22:23:31 +0000247
248 if (llvm_is_multithreaded()) {
249 sys::ScopedReader Reader(&*GCLock);
250 return *(*GCNames)[this];
251 } else
252 return *(*GCNames)[this];
Gordon Henriksen71183b62007-12-10 03:18:06 +0000253}
254
Gordon Henriksend930f912008-08-17 18:44:35 +0000255void Function::setGC(const char *Str) {
Owen Andersonaab59c52009-06-17 22:23:31 +0000256 if (llvm_is_multithreaded()) {
257 sys::ScopedWriter Writer(&*GCLock);
258 (*GCNames)[this] = GCNamePool->intern(Str);
259 } else
260 (*GCNames)[this] = GCNamePool->intern(Str);
Gordon Henriksen71183b62007-12-10 03:18:06 +0000261}
262
Gordon Henriksend930f912008-08-17 18:44:35 +0000263void Function::clearGC() {
Owen Andersonaab59c52009-06-17 22:23:31 +0000264 if (llvm_is_multithreaded()) {
265 sys::ScopedWriter Writer(&*GCLock);
Gordon Henriksend930f912008-08-17 18:44:35 +0000266 GCNames->erase(this);
Owen Andersonaab59c52009-06-17 22:23:31 +0000267 } else
268 GCNames->erase(this);
Gordon Henriksen71183b62007-12-10 03:18:06 +0000269}
270
Duncan Sandsdd7daee2008-05-26 19:58:59 +0000271/// copyAttributesFrom - copy all additional attributes (those not needed to
272/// create a Function) from the Function Src to this one.
273void Function::copyAttributesFrom(const GlobalValue *Src) {
274 assert(isa<Function>(Src) && "Expected a Function!");
275 GlobalValue::copyAttributesFrom(Src);
276 const Function *SrcF = cast<Function>(Src);
277 setCallingConv(SrcF->getCallingConv());
Devang Patel4c758ea2008-09-25 21:00:45 +0000278 setAttributes(SrcF->getAttributes());
Gordon Henriksend930f912008-08-17 18:44:35 +0000279 if (SrcF->hasGC())
280 setGC(SrcF->getGC());
281 else
282 clearGC();
Duncan Sandsdd7daee2008-05-26 19:58:59 +0000283}
284
Chris Lattnerbb346d02003-05-08 03:47:33 +0000285/// getIntrinsicID - This method returns the ID number of the specified
Brian Gaeke960707c2003-11-11 22:41:34 +0000286/// function, or Intrinsic::not_intrinsic if the function is not an
Misha Brukmanfa100532003-10-10 17:54:14 +0000287/// intrinsic, or if the pointer is null. This value is always defined to be
Chris Lattnerbb346d02003-05-08 03:47:33 +0000288/// zero to allow easy checking for whether a function is intrinsic or not. The
289/// particular intrinsic functions which correspond to this value are defined in
290/// llvm/Intrinsics.h.
291///
Dale Johannesenb842d522009-02-05 01:49:45 +0000292unsigned Function::getIntrinsicID() const {
Chris Lattner1e92e062007-02-15 19:17:16 +0000293 const ValueName *ValName = this->getValueName();
Reid Spencerc5f397a2007-04-16 07:08:44 +0000294 if (!ValName)
295 return 0;
Chris Lattner1e92e062007-02-15 19:17:16 +0000296 unsigned Len = ValName->getKeyLength();
297 const char *Name = ValName->getKeyData();
298
Reid Spencer78d71f12007-04-16 16:56:54 +0000299 if (Len < 5 || Name[4] != '.' || Name[0] != 'l' || Name[1] != 'l'
Reid Spencerb4f9a6f2006-01-16 21:12:35 +0000300 || Name[2] != 'v' || Name[3] != 'm')
Chris Lattnerbb346d02003-05-08 03:47:33 +0000301 return 0; // All intrinsics start with 'llvm.'
Chris Lattner3284ed72003-09-19 19:31:41 +0000302
Chris Lattnerff4d4ee2006-03-09 20:35:01 +0000303#define GET_FUNCTION_RECOGNIZER
304#include "llvm/Intrinsics.gen"
305#undef GET_FUNCTION_RECOGNIZER
Chris Lattnerbb346d02003-05-08 03:47:33 +0000306 return 0;
307}
308
Reid Spencer2a2117c2007-04-01 07:25:33 +0000309std::string Intrinsic::getName(ID id, const Type **Tys, unsigned numTys) {
Chris Lattner71b8c982006-03-25 06:32:47 +0000310 assert(id < num_intrinsics && "Invalid intrinsic ID!");
311 const char * const Table[] = {
312 "not_intrinsic",
313#define GET_INTRINSIC_NAME_TABLE
314#include "llvm/Intrinsics.gen"
315#undef GET_INTRINSIC_NAME_TABLE
316 };
Reid Spencer2a2117c2007-04-01 07:25:33 +0000317 if (numTys == 0)
318 return Table[id];
319 std::string Result(Table[id]);
Mon P Wang2c839d42008-07-30 04:36:53 +0000320 for (unsigned i = 0; i < numTys; ++i) {
321 if (const PointerType* PTyp = dyn_cast<PointerType>(Tys[i])) {
322 Result += ".p" + llvm::utostr(PTyp->getAddressSpace()) +
323 MVT::getMVT(PTyp->getElementType()).getMVTString();
324 }
325 else if (Tys[i])
Duncan Sands13237ac2008-06-06 12:08:01 +0000326 Result += "." + MVT::getMVT(Tys[i]).getMVTString();
Mon P Wang2c839d42008-07-30 04:36:53 +0000327 }
Reid Spencer2a2117c2007-04-01 07:25:33 +0000328 return Result;
Chris Lattner71b8c982006-03-25 06:32:47 +0000329}
330
Reid Spencer2a2117c2007-04-01 07:25:33 +0000331const FunctionType *Intrinsic::getType(ID id, const Type **Tys,
Chris Lattner31f82df2007-06-05 23:49:06 +0000332 unsigned numTys) {
Jim Laskey2682ea62007-02-07 20:38:26 +0000333 const Type *ResultTy = NULL;
334 std::vector<const Type*> ArgTys;
Jim Laskey2682ea62007-02-07 20:38:26 +0000335 bool IsVarArg = false;
336
337#define GET_INTRINSIC_GENERATOR
338#include "llvm/Intrinsics.gen"
339#undef GET_INTRINSIC_GENERATOR
340
Reid Spencer26d9ff62007-04-09 06:11:23 +0000341 return FunctionType::get(ResultTy, ArgTys, IsVarArg);
Jim Laskey2682ea62007-02-07 20:38:26 +0000342}
343
Mon P Wangb4024932009-02-24 23:17:49 +0000344bool Intrinsic::isOverloaded(ID id) {
345 const bool OTable[] = {
346 false,
347#define GET_INTRINSIC_OVERLOAD_TABLE
348#include "llvm/Intrinsics.gen"
349#undef GET_INTRINSIC_OVERLOAD_TABLE
350 };
351 return OTable[id];
352}
353
Chris Lattner49b7ee12009-01-12 01:18:58 +0000354/// This defines the "Intrinsic::getAttributes(ID id)" method.
Duncan Sands38ef3a82007-12-03 20:06:50 +0000355#define GET_INTRINSIC_ATTRIBUTES
356#include "llvm/Intrinsics.gen"
357#undef GET_INTRINSIC_ATTRIBUTES
358
Reid Spencer2a2117c2007-04-01 07:25:33 +0000359Function *Intrinsic::getDeclaration(Module *M, ID id, const Type **Tys,
360 unsigned numTys) {
Duncan Sands38ef3a82007-12-03 20:06:50 +0000361 // There can never be multiple globals with the same name of different types,
362 // because intrinsics must be a specific type.
Duncan Sandsa8ff6ca2008-04-07 13:39:11 +0000363 return
Duncan Sands38ef3a82007-12-03 20:06:50 +0000364 cast<Function>(M->getOrInsertFunction(getName(id, Tys, numTys),
365 getType(id, Tys, numTys)));
Jim Laskey2682ea62007-02-07 20:38:26 +0000366}
367
Dale Johannesenb842d522009-02-05 01:49:45 +0000368// This defines the "Intrinsic::getIntrinsicForGCCBuiltin()" method.
369#define GET_LLVM_INTRINSIC_FOR_GCC_BUILTIN
370#include "llvm/Intrinsics.gen"
371#undef GET_LLVM_INTRINSIC_FOR_GCC_BUILTIN
372
Jay Foad557169d2009-06-10 08:41:11 +0000373 /// hasAddressTaken - returns true if there are any uses of this function
374 /// other than direct calls or invokes to it.
375bool Function::hasAddressTaken() const {
376 for (Value::use_const_iterator I = use_begin(), E = use_end(); I != E; ++I) {
377 if (I.getOperandNo() != 0 ||
378 (!isa<CallInst>(*I) && !isa<InvokeInst>(*I)))
379 return true;
380 }
381 return false;
382}
383
Reid Spencerc49dd8d2004-07-17 23:50:19 +0000384// vim: sw=2 ai