blob: bda2eff4c99c3b48140e1ac7938f8e6fa225f742 [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"
Gordon Henriksen71183b62007-12-10 03:18:06 +000019#include "llvm/Support/StringPool.h"
Chris Lattner113f4f42002-06-25 16:13:24 +000020#include "SymbolTableListTraitsImpl.h"
Gordon Henriksen71183b62007-12-10 03:18:06 +000021#include "llvm/ADT/DenseMap.h"
Chris Lattnerb392d302004-12-05 06:43:27 +000022#include "llvm/ADT/StringExtras.h"
Chris Lattner189d19f2003-11-21 20:23:48 +000023using namespace llvm;
Brian Gaeke960707c2003-11-11 22:41:34 +000024
Chris Lattnerf6c93e32005-01-30 00:09:23 +000025BasicBlock *ilist_traits<BasicBlock>::createSentinel() {
Gabor Greife9ecc682008-04-06 20:25:17 +000026 BasicBlock *Ret = BasicBlock::Create();
Chris Lattner184b2982002-09-08 18:59:35 +000027 // This should not be garbage monitored.
28 LeakDetector::removeGarbageObject(Ret);
29 return Ret;
Chris Lattner9ed7aef2002-09-06 21:33:15 +000030}
31
Chris Lattner113f4f42002-06-25 16:13:24 +000032iplist<BasicBlock> &ilist_traits<BasicBlock>::getList(Function *F) {
33 return F->getBasicBlockList();
34}
35
Chris Lattnerf6c93e32005-01-30 00:09:23 +000036Argument *ilist_traits<Argument>::createSentinel() {
Reid Spencer8d9336d2006-12-31 05:26:44 +000037 Argument *Ret = new Argument(Type::Int32Ty);
Chris Lattner184b2982002-09-08 18:59:35 +000038 // This should not be garbage monitored.
39 LeakDetector::removeGarbageObject(Ret);
40 return Ret;
Chris Lattner113f4f42002-06-25 16:13:24 +000041}
42
43iplist<Argument> &ilist_traits<Argument>::getList(Function *F) {
44 return F->getArgumentList();
45}
46
47// Explicit instantiations of SymbolTableListTraits since some of the methods
48// are not in the public header file...
Chris Lattnerb47aa542007-04-17 03:26:42 +000049template class SymbolTableListTraits<Argument, Function>;
50template class SymbolTableListTraits<BasicBlock, Function>;
Chris Lattner2f7c9632001-06-06 20:29:01 +000051
Chris Lattnerda975502001-09-10 07:58:01 +000052//===----------------------------------------------------------------------===//
Chris Lattnerd255ae22002-04-09 19:39:35 +000053// Argument Implementation
54//===----------------------------------------------------------------------===//
55
Misha Brukmanb1c93172005-04-21 23:48:37 +000056Argument::Argument(const Type *Ty, const std::string &Name, Function *Par)
Chris Lattner32ab6432007-02-12 05:18:08 +000057 : Value(Ty, Value::ArgumentVal) {
Chris Lattner9ed7aef2002-09-06 21:33:15 +000058 Parent = 0;
Chris Lattner184b2982002-09-08 18:59:35 +000059
60 // Make sure that we get added to a function
61 LeakDetector::addGarbageObject(this);
62
Chris Lattner9ed7aef2002-09-06 21:33:15 +000063 if (Par)
64 Par->getArgumentList().push_back(this);
Chris Lattner32ab6432007-02-12 05:18:08 +000065 setName(Name);
Chris Lattner9ed7aef2002-09-06 21:33:15 +000066}
67
Chris Lattner9ed7aef2002-09-06 21:33:15 +000068void Argument::setParent(Function *parent) {
Chris Lattner184b2982002-09-08 18:59:35 +000069 if (getParent())
70 LeakDetector::addGarbageObject(this);
Chris Lattner9ed7aef2002-09-06 21:33:15 +000071 Parent = parent;
Chris Lattner184b2982002-09-08 18:59:35 +000072 if (getParent())
73 LeakDetector::removeGarbageObject(this);
Chris Lattner9ed7aef2002-09-06 21:33:15 +000074}
75
Chris Lattnere30f09d2008-01-24 17:47:11 +000076/// getArgNo - Return the index of this formal argument in its containing
77/// function. For example in "void foo(int a, float b)" a is 0 and b is 1.
78unsigned Argument::getArgNo() const {
79 const Function *F = getParent();
80 assert(F && "Argument is not in a function");
81
82 Function::const_arg_iterator AI = F->arg_begin();
83 unsigned ArgIdx = 0;
84 for (; &*AI != this; ++AI)
85 ++ArgIdx;
86
87 return ArgIdx;
88}
89
90/// hasByValAttr - Return true if this argument has the byval attribute on it
91/// in its containing function.
92bool Argument::hasByValAttr() const {
93 if (!isa<PointerType>(getType())) return false;
Devang Patel4c758ea2008-09-25 21:00:45 +000094 return getParent()->paramHasAttr(getArgNo()+1, Attribute::ByVal);
Chris Lattnere30f09d2008-01-24 17:47:11 +000095}
96
97/// hasNoAliasAttr - Return true if this argument has the noalias attribute on
98/// it in its containing function.
99bool Argument::hasNoAliasAttr() const {
100 if (!isa<PointerType>(getType())) return false;
Devang Patel4c758ea2008-09-25 21:00:45 +0000101 return getParent()->paramHasAttr(getArgNo()+1, Attribute::NoAlias);
Chris Lattnere30f09d2008-01-24 17:47:11 +0000102}
103
Duncan Sandsdf128eb2008-12-31 18:08:59 +0000104/// hasNoCaptureAttr - Return true if this argument has the nocapture attribute
105/// on it in its containing function.
106bool Argument::hasNoCaptureAttr() const {
107 if (!isa<PointerType>(getType())) return false;
108 return getParent()->paramHasAttr(getArgNo()+1, Attribute::NoCapture);
109}
110
Owen Andersonc64dfb42008-02-17 23:22:28 +0000111/// hasSRetAttr - Return true if this argument has the sret attribute on
112/// it in its containing function.
113bool Argument::hasStructRetAttr() const {
114 if (!isa<PointerType>(getType())) return false;
Gabor Greif697e94c2008-05-15 10:04:30 +0000115 if (this != getParent()->arg_begin())
116 return false; // StructRet param must be first param
Devang Patel4c758ea2008-09-25 21:00:45 +0000117 return getParent()->paramHasAttr(1, Attribute::StructRet);
Owen Andersonc64dfb42008-02-17 23:22:28 +0000118}
119
Devang Patel4c758ea2008-09-25 21:00:45 +0000120/// addAttr - Add a Attribute to an argument
Devang Patelba3fa6c2008-09-23 23:03:40 +0000121void Argument::addAttr(Attributes attr) {
Devang Patel4c758ea2008-09-25 21:00:45 +0000122 getParent()->addAttribute(getArgNo() + 1, attr);
Gordon Henriksen2d9cc212008-04-28 17:37:06 +0000123}
Chris Lattnere30f09d2008-01-24 17:47:11 +0000124
Devang Patel4c758ea2008-09-25 21:00:45 +0000125/// removeAttr - Remove a Attribute from an argument
Devang Patelba3fa6c2008-09-23 23:03:40 +0000126void Argument::removeAttr(Attributes attr) {
Devang Patel4c758ea2008-09-25 21:00:45 +0000127 getParent()->removeAttribute(getArgNo() + 1, attr);
Duncan Sands66336db2008-07-08 09:41:30 +0000128}
Chris Lattnere30f09d2008-01-24 17:47:11 +0000129
130
Chris Lattnerd255ae22002-04-09 19:39:35 +0000131//===----------------------------------------------------------------------===//
Chris Lattner3e13b8c2008-01-02 23:42:30 +0000132// Helper Methods in Function
Reid Spencer019c8862007-04-09 15:01:12 +0000133//===----------------------------------------------------------------------===//
134
Chris Lattner3e13b8c2008-01-02 23:42:30 +0000135const FunctionType *Function::getFunctionType() const {
136 return cast<FunctionType>(getType()->getElementType());
Reid Spencer019c8862007-04-09 15:01:12 +0000137}
138
Chris Lattner3e13b8c2008-01-02 23:42:30 +0000139bool Function::isVarArg() const {
140 return getFunctionType()->isVarArg();
Reid Spencer019c8862007-04-09 15:01:12 +0000141}
142
Chris Lattner3e13b8c2008-01-02 23:42:30 +0000143const Type *Function::getReturnType() const {
144 return getFunctionType()->getReturnType();
Duncan Sands185eeac2007-11-25 14:10:56 +0000145}
146
Chris Lattner3e13b8c2008-01-02 23:42:30 +0000147void Function::removeFromParent() {
148 getParent()->getFunctionList().remove(this);
Duncan Sands185eeac2007-11-25 14:10:56 +0000149}
150
Chris Lattner3e13b8c2008-01-02 23:42:30 +0000151void Function::eraseFromParent() {
152 getParent()->getFunctionList().erase(this);
Reid Spencer019c8862007-04-09 15:01:12 +0000153}
154
Reid Spencer019c8862007-04-09 15:01:12 +0000155//===----------------------------------------------------------------------===//
Chris Lattner57698e22002-03-26 18:01:55 +0000156// Function Implementation
Chris Lattnerda975502001-09-10 07:58:01 +0000157//===----------------------------------------------------------------------===//
158
Chris Lattner379a8d22003-04-16 20:28:45 +0000159Function::Function(const FunctionType *Ty, LinkageTypes Linkage,
Chris Lattner6213ae02002-09-06 20:46:32 +0000160 const std::string &name, Module *ParentModule)
Christopher Lambedf07882007-12-17 01:12:55 +0000161 : GlobalValue(PointerType::getUnqual(Ty),
Chris Lattner8a923e72008-03-12 17:45:29 +0000162 Value::FunctionVal, 0, 0, Linkage, name) {
Chris Lattner654695b2009-01-05 07:58:59 +0000163 assert(FunctionType::isValidReturnType(getReturnType()) &&
164 !isa<OpaqueType>(getReturnType()) && "invalid return type");
Reid Spencer3aaaa0b2007-02-05 20:47:22 +0000165 SymTab = new ValueSymbolTable();
Chris Lattner6213ae02002-09-06 20:46:32 +0000166
Chris Lattnere2de9082007-08-18 06:14:52 +0000167 // If the function has arguments, mark them as lazily built.
168 if (Ty->getNumParams())
169 SubclassData = 1; // Set the "has lazy arguments" bit.
170
Chris Lattner184b2982002-09-08 18:59:35 +0000171 // Make sure that we get added to a function
172 LeakDetector::addGarbageObject(this);
173
Chris Lattner6213ae02002-09-06 20:46:32 +0000174 if (ParentModule)
175 ParentModule->getFunctionList().push_back(this);
Duncan Sandsa8ff6ca2008-04-07 13:39:11 +0000176
177 // Ensure intrinsics have the right parameter attributes.
Dale Johannesenae616c22009-02-04 22:47:25 +0000178 if (unsigned IID = getIntrinsicID(true))
Devang Patel4c758ea2008-09-25 21:00:45 +0000179 setAttributes(Intrinsic::getAttributes(Intrinsic::ID(IID)));
Devang Pateld334a432008-09-02 20:51:15 +0000180
Chris Lattner2f7c9632001-06-06 20:29:01 +0000181}
182
Gordon Henriksen14a55692007-12-10 02:14:30 +0000183Function::~Function() {
184 dropAllReferences(); // After this it is safe to delete instructions.
Chris Lattner2f7c9632001-06-06 20:29:01 +0000185
Chris Lattner2f7c9632001-06-06 20:29:01 +0000186 // Delete all of the method arguments and unlink from symbol table...
Gordon Henriksen14a55692007-12-10 02:14:30 +0000187 ArgumentList.clear();
188 delete SymTab;
Reid Spencerc6a83842007-04-22 17:28:03 +0000189
Gordon Henriksend930f912008-08-17 18:44:35 +0000190 // Remove the function from the on-the-side GC table.
191 clearGC();
Chris Lattner2f7c9632001-06-06 20:29:01 +0000192}
193
Chris Lattnere2de9082007-08-18 06:14:52 +0000194void Function::BuildLazyArguments() const {
195 // Create the arguments vector, all arguments start out unnamed.
196 const FunctionType *FT = getFunctionType();
197 for (unsigned i = 0, e = FT->getNumParams(); i != e; ++i) {
198 assert(FT->getParamType(i) != Type::VoidTy &&
199 "Cannot have void typed arguments!");
200 ArgumentList.push_back(new Argument(FT->getParamType(i)));
201 }
202
203 // Clear the lazy arguments bit.
204 const_cast<Function*>(this)->SubclassData &= ~1;
205}
206
207size_t Function::arg_size() const {
208 return getFunctionType()->getNumParams();
209}
210bool Function::arg_empty() const {
211 return getFunctionType()->getNumParams() == 0;
212}
213
Chris Lattner4e8c4872002-03-23 22:51:58 +0000214void Function::setParent(Module *parent) {
Chris Lattner184b2982002-09-08 18:59:35 +0000215 if (getParent())
216 LeakDetector::addGarbageObject(this);
Chris Lattner2f7c9632001-06-06 20:29:01 +0000217 Parent = parent;
Chris Lattner184b2982002-09-08 18:59:35 +0000218 if (getParent())
219 LeakDetector::removeGarbageObject(this);
Chris Lattner2f7c9632001-06-06 20:29:01 +0000220}
221
Chris Lattner2f7c9632001-06-06 20:29:01 +0000222// dropAllReferences() - This function causes all the subinstructions to "let
223// go" of all references that they are maintaining. This allows one to
224// 'delete' a whole class at a time, even though there may be circular
225// references... first all references are dropped, and all use counts go to
Misha Brukmanfa100532003-10-10 17:54:14 +0000226// zero. Then everything is deleted for real. Note that no operations are
Misha Brukmanb1c93172005-04-21 23:48:37 +0000227// valid on an object that has "dropped all references", except operator
Chris Lattner2f7c9632001-06-06 20:29:01 +0000228// delete.
229//
Chris Lattner4e8c4872002-03-23 22:51:58 +0000230void Function::dropAllReferences() {
Chris Lattner113f4f42002-06-25 16:13:24 +0000231 for (iterator I = begin(), E = end(); I != E; ++I)
232 I->dropAllReferences();
Chris Lattnerc1b16512003-09-17 04:58:59 +0000233 BasicBlocks.clear(); // Delete all basic blocks...
Chris Lattner2f7c9632001-06-06 20:29:01 +0000234}
Chris Lattnerda975502001-09-10 07:58:01 +0000235
Devang Patel4c758ea2008-09-25 21:00:45 +0000236void Function::addAttribute(unsigned i, Attributes attr) {
237 AttrListPtr PAL = getAttributes();
Eric Christopher901b1a72008-05-16 20:39:43 +0000238 PAL = PAL.addAttr(i, attr);
Devang Patel4c758ea2008-09-25 21:00:45 +0000239 setAttributes(PAL);
Eric Christopher901b1a72008-05-16 20:39:43 +0000240}
241
Devang Patel4c758ea2008-09-25 21:00:45 +0000242void Function::removeAttribute(unsigned i, Attributes attr) {
243 AttrListPtr PAL = getAttributes();
Duncan Sands66336db2008-07-08 09:41:30 +0000244 PAL = PAL.removeAttr(i, attr);
Devang Patel4c758ea2008-09-25 21:00:45 +0000245 setAttributes(PAL);
Duncan Sands66336db2008-07-08 09:41:30 +0000246}
247
Gordon Henriksend930f912008-08-17 18:44:35 +0000248// Maintain the GC name for each function in an on-the-side table. This saves
249// allocating an additional word in Function for programs which do not use GC
250// (i.e., most programs) at the cost of increased overhead for clients which do
251// use GC.
252static DenseMap<const Function*,PooledStringPtr> *GCNames;
253static StringPool *GCNamePool;
Gordon Henriksen71183b62007-12-10 03:18:06 +0000254
Gordon Henriksend930f912008-08-17 18:44:35 +0000255bool Function::hasGC() const {
256 return GCNames && GCNames->count(this);
Gordon Henriksen71183b62007-12-10 03:18:06 +0000257}
258
Gordon Henriksend930f912008-08-17 18:44:35 +0000259const char *Function::getGC() const {
260 assert(hasGC() && "Function has no collector");
261 return *(*GCNames)[this];
Gordon Henriksen71183b62007-12-10 03:18:06 +0000262}
263
Gordon Henriksend930f912008-08-17 18:44:35 +0000264void Function::setGC(const char *Str) {
265 if (!GCNamePool)
266 GCNamePool = new StringPool();
267 if (!GCNames)
268 GCNames = new DenseMap<const Function*,PooledStringPtr>();
269 (*GCNames)[this] = GCNamePool->intern(Str);
Gordon Henriksen71183b62007-12-10 03:18:06 +0000270}
271
Gordon Henriksend930f912008-08-17 18:44:35 +0000272void Function::clearGC() {
273 if (GCNames) {
274 GCNames->erase(this);
275 if (GCNames->empty()) {
276 delete GCNames;
277 GCNames = 0;
278 if (GCNamePool->empty()) {
279 delete GCNamePool;
280 GCNamePool = 0;
Gordon Henriksen4b904b92007-12-10 03:35:18 +0000281 }
Gordon Henriksen71183b62007-12-10 03:18:06 +0000282 }
283 }
284}
285
Duncan Sandsdd7daee2008-05-26 19:58:59 +0000286/// copyAttributesFrom - copy all additional attributes (those not needed to
287/// create a Function) from the Function Src to this one.
288void Function::copyAttributesFrom(const GlobalValue *Src) {
289 assert(isa<Function>(Src) && "Expected a Function!");
290 GlobalValue::copyAttributesFrom(Src);
291 const Function *SrcF = cast<Function>(Src);
292 setCallingConv(SrcF->getCallingConv());
Devang Patel4c758ea2008-09-25 21:00:45 +0000293 setAttributes(SrcF->getAttributes());
Gordon Henriksend930f912008-08-17 18:44:35 +0000294 if (SrcF->hasGC())
295 setGC(SrcF->getGC());
296 else
297 clearGC();
Duncan Sandsdd7daee2008-05-26 19:58:59 +0000298}
299
Chris Lattnerbb346d02003-05-08 03:47:33 +0000300/// getIntrinsicID - This method returns the ID number of the specified
Brian Gaeke960707c2003-11-11 22:41:34 +0000301/// function, or Intrinsic::not_intrinsic if the function is not an
Misha Brukmanfa100532003-10-10 17:54:14 +0000302/// intrinsic, or if the pointer is null. This value is always defined to be
Chris Lattnerbb346d02003-05-08 03:47:33 +0000303/// zero to allow easy checking for whether a function is intrinsic or not. The
304/// particular intrinsic functions which correspond to this value are defined in
305/// llvm/Intrinsics.h.
306///
Dale Johannesenae616c22009-02-04 22:47:25 +0000307unsigned Function::getIntrinsicID(bool noAssert) const {
Chris Lattner1e92e062007-02-15 19:17:16 +0000308 const ValueName *ValName = this->getValueName();
Reid Spencerc5f397a2007-04-16 07:08:44 +0000309 if (!ValName)
310 return 0;
Chris Lattner1e92e062007-02-15 19:17:16 +0000311 unsigned Len = ValName->getKeyLength();
312 const char *Name = ValName->getKeyData();
313
Reid Spencer78d71f12007-04-16 16:56:54 +0000314 if (Len < 5 || Name[4] != '.' || Name[0] != 'l' || Name[1] != 'l'
Reid Spencerb4f9a6f2006-01-16 21:12:35 +0000315 || Name[2] != 'v' || Name[3] != 'm')
Chris Lattnerbb346d02003-05-08 03:47:33 +0000316 return 0; // All intrinsics start with 'llvm.'
Chris Lattner3284ed72003-09-19 19:31:41 +0000317
Dale Johannesenae616c22009-02-04 22:47:25 +0000318 assert((Len != 5 || noAssert) && "'llvm.' is an invalid intrinsic name!");
319
Chris Lattnerff4d4ee2006-03-09 20:35:01 +0000320#define GET_FUNCTION_RECOGNIZER
321#include "llvm/Intrinsics.gen"
322#undef GET_FUNCTION_RECOGNIZER
Dale Johannesenae616c22009-02-04 22:47:25 +0000323 assert(noAssert && "Invalid LLVM intrinsic name");
Chris Lattnerbb346d02003-05-08 03:47:33 +0000324 return 0;
325}
326
Reid Spencer2a2117c2007-04-01 07:25:33 +0000327std::string Intrinsic::getName(ID id, const Type **Tys, unsigned numTys) {
Chris Lattner71b8c982006-03-25 06:32:47 +0000328 assert(id < num_intrinsics && "Invalid intrinsic ID!");
329 const char * const Table[] = {
330 "not_intrinsic",
331#define GET_INTRINSIC_NAME_TABLE
332#include "llvm/Intrinsics.gen"
333#undef GET_INTRINSIC_NAME_TABLE
334 };
Reid Spencer2a2117c2007-04-01 07:25:33 +0000335 if (numTys == 0)
336 return Table[id];
337 std::string Result(Table[id]);
Mon P Wang2c839d42008-07-30 04:36:53 +0000338 for (unsigned i = 0; i < numTys; ++i) {
339 if (const PointerType* PTyp = dyn_cast<PointerType>(Tys[i])) {
340 Result += ".p" + llvm::utostr(PTyp->getAddressSpace()) +
341 MVT::getMVT(PTyp->getElementType()).getMVTString();
342 }
343 else if (Tys[i])
Duncan Sands13237ac2008-06-06 12:08:01 +0000344 Result += "." + MVT::getMVT(Tys[i]).getMVTString();
Mon P Wang2c839d42008-07-30 04:36:53 +0000345 }
Reid Spencer2a2117c2007-04-01 07:25:33 +0000346 return Result;
Chris Lattner71b8c982006-03-25 06:32:47 +0000347}
348
Reid Spencer2a2117c2007-04-01 07:25:33 +0000349const FunctionType *Intrinsic::getType(ID id, const Type **Tys,
Chris Lattner31f82df2007-06-05 23:49:06 +0000350 unsigned numTys) {
Jim Laskey2682ea62007-02-07 20:38:26 +0000351 const Type *ResultTy = NULL;
352 std::vector<const Type*> ArgTys;
Jim Laskey2682ea62007-02-07 20:38:26 +0000353 bool IsVarArg = false;
354
355#define GET_INTRINSIC_GENERATOR
356#include "llvm/Intrinsics.gen"
357#undef GET_INTRINSIC_GENERATOR
358
Reid Spencer26d9ff62007-04-09 06:11:23 +0000359 return FunctionType::get(ResultTy, ArgTys, IsVarArg);
Jim Laskey2682ea62007-02-07 20:38:26 +0000360}
361
Chris Lattner49b7ee12009-01-12 01:18:58 +0000362/// This defines the "Intrinsic::getAttributes(ID id)" method.
Duncan Sands38ef3a82007-12-03 20:06:50 +0000363#define GET_INTRINSIC_ATTRIBUTES
364#include "llvm/Intrinsics.gen"
365#undef GET_INTRINSIC_ATTRIBUTES
366
Reid Spencer2a2117c2007-04-01 07:25:33 +0000367Function *Intrinsic::getDeclaration(Module *M, ID id, const Type **Tys,
368 unsigned numTys) {
Duncan Sands38ef3a82007-12-03 20:06:50 +0000369 // There can never be multiple globals with the same name of different types,
370 // because intrinsics must be a specific type.
Duncan Sandsa8ff6ca2008-04-07 13:39:11 +0000371 return
Duncan Sands38ef3a82007-12-03 20:06:50 +0000372 cast<Function>(M->getOrInsertFunction(getName(id, Tys, numTys),
373 getType(id, Tys, numTys)));
Jim Laskey2682ea62007-02-07 20:38:26 +0000374}
375
Reid Spencerc49dd8d2004-07-17 23:50:19 +0000376// vim: sw=2 ai