blob: f83fe435cd0e2243695e97074e6a001d26353f2c [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"
Duncan Sands38ef3a82007-12-03 20:06:50 +000021#include "llvm/ADT/BitVector.h"
Gordon Henriksen71183b62007-12-10 03:18:06 +000022#include "llvm/ADT/DenseMap.h"
Chris Lattnerb392d302004-12-05 06:43:27 +000023#include "llvm/ADT/StringExtras.h"
Chris Lattner189d19f2003-11-21 20:23:48 +000024using namespace llvm;
Brian Gaeke960707c2003-11-11 22:41:34 +000025
Chris Lattnerf6c93e32005-01-30 00:09:23 +000026BasicBlock *ilist_traits<BasicBlock>::createSentinel() {
Gabor Greife9ecc682008-04-06 20:25:17 +000027 BasicBlock *Ret = BasicBlock::Create();
Chris Lattner184b2982002-09-08 18:59:35 +000028 // This should not be garbage monitored.
29 LeakDetector::removeGarbageObject(Ret);
30 return Ret;
Chris Lattner9ed7aef2002-09-06 21:33:15 +000031}
32
Chris Lattner113f4f42002-06-25 16:13:24 +000033iplist<BasicBlock> &ilist_traits<BasicBlock>::getList(Function *F) {
34 return F->getBasicBlockList();
35}
36
Chris Lattnerf6c93e32005-01-30 00:09:23 +000037Argument *ilist_traits<Argument>::createSentinel() {
Reid Spencer8d9336d2006-12-31 05:26:44 +000038 Argument *Ret = new Argument(Type::Int32Ty);
Chris Lattner184b2982002-09-08 18:59:35 +000039 // This should not be garbage monitored.
40 LeakDetector::removeGarbageObject(Ret);
41 return Ret;
Chris Lattner113f4f42002-06-25 16:13:24 +000042}
43
44iplist<Argument> &ilist_traits<Argument>::getList(Function *F) {
45 return F->getArgumentList();
46}
47
48// Explicit instantiations of SymbolTableListTraits since some of the methods
49// are not in the public header file...
Chris Lattnerb47aa542007-04-17 03:26:42 +000050template class SymbolTableListTraits<Argument, Function>;
51template class SymbolTableListTraits<BasicBlock, Function>;
Chris Lattner2f7c9632001-06-06 20:29:01 +000052
Chris Lattnerda975502001-09-10 07:58:01 +000053//===----------------------------------------------------------------------===//
Chris Lattnerd255ae22002-04-09 19:39:35 +000054// Argument Implementation
55//===----------------------------------------------------------------------===//
56
Misha Brukmanb1c93172005-04-21 23:48:37 +000057Argument::Argument(const Type *Ty, const std::string &Name, Function *Par)
Chris Lattner32ab6432007-02-12 05:18:08 +000058 : Value(Ty, Value::ArgumentVal) {
Chris Lattner9ed7aef2002-09-06 21:33:15 +000059 Parent = 0;
Chris Lattner184b2982002-09-08 18:59:35 +000060
61 // Make sure that we get added to a function
62 LeakDetector::addGarbageObject(this);
63
Chris Lattner9ed7aef2002-09-06 21:33:15 +000064 if (Par)
65 Par->getArgumentList().push_back(this);
Chris Lattner32ab6432007-02-12 05:18:08 +000066 setName(Name);
Chris Lattner9ed7aef2002-09-06 21:33:15 +000067}
68
Chris Lattner9ed7aef2002-09-06 21:33:15 +000069void Argument::setParent(Function *parent) {
Chris Lattner184b2982002-09-08 18:59:35 +000070 if (getParent())
71 LeakDetector::addGarbageObject(this);
Chris Lattner9ed7aef2002-09-06 21:33:15 +000072 Parent = parent;
Chris Lattner184b2982002-09-08 18:59:35 +000073 if (getParent())
74 LeakDetector::removeGarbageObject(this);
Chris Lattner9ed7aef2002-09-06 21:33:15 +000075}
76
Chris Lattnere30f09d2008-01-24 17:47:11 +000077/// getArgNo - Return the index of this formal argument in its containing
78/// function. For example in "void foo(int a, float b)" a is 0 and b is 1.
79unsigned Argument::getArgNo() const {
80 const Function *F = getParent();
81 assert(F && "Argument is not in a function");
82
83 Function::const_arg_iterator AI = F->arg_begin();
84 unsigned ArgIdx = 0;
85 for (; &*AI != this; ++AI)
86 ++ArgIdx;
87
88 return ArgIdx;
89}
90
91/// hasByValAttr - Return true if this argument has the byval attribute on it
92/// in its containing function.
93bool Argument::hasByValAttr() const {
94 if (!isa<PointerType>(getType())) return false;
Devang Patel4c758ea2008-09-25 21:00:45 +000095 return getParent()->paramHasAttr(getArgNo()+1, Attribute::ByVal);
Chris Lattnere30f09d2008-01-24 17:47:11 +000096}
97
98/// hasNoAliasAttr - Return true if this argument has the noalias attribute on
99/// it in its containing function.
100bool Argument::hasNoAliasAttr() const {
101 if (!isa<PointerType>(getType())) return false;
Devang Patel4c758ea2008-09-25 21:00:45 +0000102 return getParent()->paramHasAttr(getArgNo()+1, Attribute::NoAlias);
Chris Lattnere30f09d2008-01-24 17:47:11 +0000103}
104
Duncan Sandsdf128eb2008-12-31 18:08:59 +0000105/// hasNoCaptureAttr - Return true if this argument has the nocapture attribute
106/// on it in its containing function.
107bool Argument::hasNoCaptureAttr() const {
108 if (!isa<PointerType>(getType())) return false;
109 return getParent()->paramHasAttr(getArgNo()+1, Attribute::NoCapture);
110}
111
Owen Andersonc64dfb42008-02-17 23:22:28 +0000112/// hasSRetAttr - Return true if this argument has the sret attribute on
113/// it in its containing function.
114bool Argument::hasStructRetAttr() const {
115 if (!isa<PointerType>(getType())) return false;
Gabor Greif697e94c2008-05-15 10:04:30 +0000116 if (this != getParent()->arg_begin())
117 return false; // StructRet param must be first param
Devang Patel4c758ea2008-09-25 21:00:45 +0000118 return getParent()->paramHasAttr(1, Attribute::StructRet);
Owen Andersonc64dfb42008-02-17 23:22:28 +0000119}
120
Devang Patel4c758ea2008-09-25 21:00:45 +0000121/// addAttr - Add a Attribute to an argument
Devang Patelba3fa6c2008-09-23 23:03:40 +0000122void Argument::addAttr(Attributes attr) {
Devang Patel4c758ea2008-09-25 21:00:45 +0000123 getParent()->addAttribute(getArgNo() + 1, attr);
Gordon Henriksen2d9cc212008-04-28 17:37:06 +0000124}
Chris Lattnere30f09d2008-01-24 17:47:11 +0000125
Devang Patel4c758ea2008-09-25 21:00:45 +0000126/// removeAttr - Remove a Attribute from an argument
Devang Patelba3fa6c2008-09-23 23:03:40 +0000127void Argument::removeAttr(Attributes attr) {
Devang Patel4c758ea2008-09-25 21:00:45 +0000128 getParent()->removeAttribute(getArgNo() + 1, attr);
Duncan Sands66336db2008-07-08 09:41:30 +0000129}
Chris Lattnere30f09d2008-01-24 17:47:11 +0000130
131
Chris Lattnerd255ae22002-04-09 19:39:35 +0000132//===----------------------------------------------------------------------===//
Chris Lattner3e13b8c2008-01-02 23:42:30 +0000133// Helper Methods in Function
Reid Spencer019c8862007-04-09 15:01:12 +0000134//===----------------------------------------------------------------------===//
135
Chris Lattner3e13b8c2008-01-02 23:42:30 +0000136const FunctionType *Function::getFunctionType() const {
137 return cast<FunctionType>(getType()->getElementType());
Reid Spencer019c8862007-04-09 15:01:12 +0000138}
139
Chris Lattner3e13b8c2008-01-02 23:42:30 +0000140bool Function::isVarArg() const {
141 return getFunctionType()->isVarArg();
Reid Spencer019c8862007-04-09 15:01:12 +0000142}
143
Chris Lattner3e13b8c2008-01-02 23:42:30 +0000144const Type *Function::getReturnType() const {
145 return getFunctionType()->getReturnType();
Duncan Sands185eeac2007-11-25 14:10:56 +0000146}
147
Chris Lattner3e13b8c2008-01-02 23:42:30 +0000148void Function::removeFromParent() {
149 getParent()->getFunctionList().remove(this);
Duncan Sands185eeac2007-11-25 14:10:56 +0000150}
151
Chris Lattner3e13b8c2008-01-02 23:42:30 +0000152void Function::eraseFromParent() {
153 getParent()->getFunctionList().erase(this);
Reid Spencer019c8862007-04-09 15:01:12 +0000154}
155
Reid Spencer019c8862007-04-09 15:01:12 +0000156//===----------------------------------------------------------------------===//
Chris Lattner57698e22002-03-26 18:01:55 +0000157// Function Implementation
Chris Lattnerda975502001-09-10 07:58:01 +0000158//===----------------------------------------------------------------------===//
159
Chris Lattner379a8d22003-04-16 20:28:45 +0000160Function::Function(const FunctionType *Ty, LinkageTypes Linkage,
Chris Lattner6213ae02002-09-06 20:46:32 +0000161 const std::string &name, Module *ParentModule)
Christopher Lambedf07882007-12-17 01:12:55 +0000162 : GlobalValue(PointerType::getUnqual(Ty),
Chris Lattner8a923e72008-03-12 17:45:29 +0000163 Value::FunctionVal, 0, 0, Linkage, name) {
Reid Spencer3aaaa0b2007-02-05 20:47:22 +0000164 SymTab = new ValueSymbolTable();
Chris Lattner6213ae02002-09-06 20:46:32 +0000165
Devang Patel616f0e02008-02-20 22:36:03 +0000166 assert((getReturnType()->isFirstClassType() ||getReturnType() == Type::VoidTy
Devang Patel9fea0192008-02-21 22:24:17 +0000167 || isa<StructType>(getReturnType()))
Chris Lattner3ae303c2003-11-21 22:32:23 +0000168 && "LLVM functions cannot return aggregate values!");
169
Chris Lattnere2de9082007-08-18 06:14:52 +0000170 // If the function has arguments, mark them as lazily built.
171 if (Ty->getNumParams())
172 SubclassData = 1; // Set the "has lazy arguments" bit.
173
Chris Lattner184b2982002-09-08 18:59:35 +0000174 // Make sure that we get added to a function
175 LeakDetector::addGarbageObject(this);
176
Chris Lattner6213ae02002-09-06 20:46:32 +0000177 if (ParentModule)
178 ParentModule->getFunctionList().push_back(this);
Duncan Sandsa8ff6ca2008-04-07 13:39:11 +0000179
180 // Ensure intrinsics have the right parameter attributes.
181 if (unsigned IID = getIntrinsicID(true))
Devang Patel4c758ea2008-09-25 21:00:45 +0000182 setAttributes(Intrinsic::getAttributes(Intrinsic::ID(IID)));
Devang Pateld334a432008-09-02 20:51:15 +0000183
Chris Lattner2f7c9632001-06-06 20:29:01 +0000184}
185
Gordon Henriksen14a55692007-12-10 02:14:30 +0000186Function::~Function() {
187 dropAllReferences(); // After this it is safe to delete instructions.
Chris Lattner2f7c9632001-06-06 20:29:01 +0000188
Chris Lattner2f7c9632001-06-06 20:29:01 +0000189 // Delete all of the method arguments and unlink from symbol table...
Gordon Henriksen14a55692007-12-10 02:14:30 +0000190 ArgumentList.clear();
191 delete SymTab;
Reid Spencerc6a83842007-04-22 17:28:03 +0000192
Gordon Henriksend930f912008-08-17 18:44:35 +0000193 // Remove the function from the on-the-side GC table.
194 clearGC();
Chris Lattner2f7c9632001-06-06 20:29:01 +0000195}
196
Chris Lattnere2de9082007-08-18 06:14:52 +0000197void Function::BuildLazyArguments() const {
198 // Create the arguments vector, all arguments start out unnamed.
199 const FunctionType *FT = getFunctionType();
200 for (unsigned i = 0, e = FT->getNumParams(); i != e; ++i) {
201 assert(FT->getParamType(i) != Type::VoidTy &&
202 "Cannot have void typed arguments!");
203 ArgumentList.push_back(new Argument(FT->getParamType(i)));
204 }
205
206 // Clear the lazy arguments bit.
207 const_cast<Function*>(this)->SubclassData &= ~1;
208}
209
210size_t Function::arg_size() const {
211 return getFunctionType()->getNumParams();
212}
213bool Function::arg_empty() const {
214 return getFunctionType()->getNumParams() == 0;
215}
216
Chris Lattner4e8c4872002-03-23 22:51:58 +0000217void Function::setParent(Module *parent) {
Chris Lattner184b2982002-09-08 18:59:35 +0000218 if (getParent())
219 LeakDetector::addGarbageObject(this);
Chris Lattner2f7c9632001-06-06 20:29:01 +0000220 Parent = parent;
Chris Lattner184b2982002-09-08 18:59:35 +0000221 if (getParent())
222 LeakDetector::removeGarbageObject(this);
Chris Lattner2f7c9632001-06-06 20:29:01 +0000223}
224
Chris Lattner2f7c9632001-06-06 20:29:01 +0000225// dropAllReferences() - This function causes all the subinstructions to "let
226// go" of all references that they are maintaining. This allows one to
227// 'delete' a whole class at a time, even though there may be circular
228// references... first all references are dropped, and all use counts go to
Misha Brukmanfa100532003-10-10 17:54:14 +0000229// zero. Then everything is deleted for real. Note that no operations are
Misha Brukmanb1c93172005-04-21 23:48:37 +0000230// valid on an object that has "dropped all references", except operator
Chris Lattner2f7c9632001-06-06 20:29:01 +0000231// delete.
232//
Chris Lattner4e8c4872002-03-23 22:51:58 +0000233void Function::dropAllReferences() {
Chris Lattner113f4f42002-06-25 16:13:24 +0000234 for (iterator I = begin(), E = end(); I != E; ++I)
235 I->dropAllReferences();
Chris Lattnerc1b16512003-09-17 04:58:59 +0000236 BasicBlocks.clear(); // Delete all basic blocks...
Chris Lattner2f7c9632001-06-06 20:29:01 +0000237}
Chris Lattnerda975502001-09-10 07:58:01 +0000238
Devang Patel4c758ea2008-09-25 21:00:45 +0000239void Function::addAttribute(unsigned i, Attributes attr) {
240 AttrListPtr PAL = getAttributes();
Eric Christopher901b1a72008-05-16 20:39:43 +0000241 PAL = PAL.addAttr(i, attr);
Devang Patel4c758ea2008-09-25 21:00:45 +0000242 setAttributes(PAL);
Eric Christopher901b1a72008-05-16 20:39:43 +0000243}
244
Devang Patel4c758ea2008-09-25 21:00:45 +0000245void Function::removeAttribute(unsigned i, Attributes attr) {
246 AttrListPtr PAL = getAttributes();
Duncan Sands66336db2008-07-08 09:41:30 +0000247 PAL = PAL.removeAttr(i, attr);
Devang Patel4c758ea2008-09-25 21:00:45 +0000248 setAttributes(PAL);
Duncan Sands66336db2008-07-08 09:41:30 +0000249}
250
Gordon Henriksend930f912008-08-17 18:44:35 +0000251// Maintain the GC name for each function in an on-the-side table. This saves
252// allocating an additional word in Function for programs which do not use GC
253// (i.e., most programs) at the cost of increased overhead for clients which do
254// use GC.
255static DenseMap<const Function*,PooledStringPtr> *GCNames;
256static StringPool *GCNamePool;
Gordon Henriksen71183b62007-12-10 03:18:06 +0000257
Gordon Henriksend930f912008-08-17 18:44:35 +0000258bool Function::hasGC() const {
259 return GCNames && GCNames->count(this);
Gordon Henriksen71183b62007-12-10 03:18:06 +0000260}
261
Gordon Henriksend930f912008-08-17 18:44:35 +0000262const char *Function::getGC() const {
263 assert(hasGC() && "Function has no collector");
264 return *(*GCNames)[this];
Gordon Henriksen71183b62007-12-10 03:18:06 +0000265}
266
Gordon Henriksend930f912008-08-17 18:44:35 +0000267void Function::setGC(const char *Str) {
268 if (!GCNamePool)
269 GCNamePool = new StringPool();
270 if (!GCNames)
271 GCNames = new DenseMap<const Function*,PooledStringPtr>();
272 (*GCNames)[this] = GCNamePool->intern(Str);
Gordon Henriksen71183b62007-12-10 03:18:06 +0000273}
274
Gordon Henriksend930f912008-08-17 18:44:35 +0000275void Function::clearGC() {
276 if (GCNames) {
277 GCNames->erase(this);
278 if (GCNames->empty()) {
279 delete GCNames;
280 GCNames = 0;
281 if (GCNamePool->empty()) {
282 delete GCNamePool;
283 GCNamePool = 0;
Gordon Henriksen4b904b92007-12-10 03:35:18 +0000284 }
Gordon Henriksen71183b62007-12-10 03:18:06 +0000285 }
286 }
287}
288
Duncan Sandsdd7daee2008-05-26 19:58:59 +0000289/// copyAttributesFrom - copy all additional attributes (those not needed to
290/// create a Function) from the Function Src to this one.
291void Function::copyAttributesFrom(const GlobalValue *Src) {
292 assert(isa<Function>(Src) && "Expected a Function!");
293 GlobalValue::copyAttributesFrom(Src);
294 const Function *SrcF = cast<Function>(Src);
295 setCallingConv(SrcF->getCallingConv());
Devang Patel4c758ea2008-09-25 21:00:45 +0000296 setAttributes(SrcF->getAttributes());
Gordon Henriksend930f912008-08-17 18:44:35 +0000297 if (SrcF->hasGC())
298 setGC(SrcF->getGC());
299 else
300 clearGC();
Duncan Sandsdd7daee2008-05-26 19:58:59 +0000301}
302
Chris Lattnerbb346d02003-05-08 03:47:33 +0000303/// getIntrinsicID - This method returns the ID number of the specified
Brian Gaeke960707c2003-11-11 22:41:34 +0000304/// function, or Intrinsic::not_intrinsic if the function is not an
Misha Brukmanfa100532003-10-10 17:54:14 +0000305/// intrinsic, or if the pointer is null. This value is always defined to be
Chris Lattnerbb346d02003-05-08 03:47:33 +0000306/// zero to allow easy checking for whether a function is intrinsic or not. The
307/// particular intrinsic functions which correspond to this value are defined in
308/// llvm/Intrinsics.h.
309///
Reid Spencer9c2eec32007-04-16 06:54:34 +0000310unsigned Function::getIntrinsicID(bool noAssert) const {
Chris Lattner1e92e062007-02-15 19:17:16 +0000311 const ValueName *ValName = this->getValueName();
Reid Spencerc5f397a2007-04-16 07:08:44 +0000312 if (!ValName)
313 return 0;
Chris Lattner1e92e062007-02-15 19:17:16 +0000314 unsigned Len = ValName->getKeyLength();
315 const char *Name = ValName->getKeyData();
316
Reid Spencer78d71f12007-04-16 16:56:54 +0000317 if (Len < 5 || Name[4] != '.' || Name[0] != 'l' || Name[1] != 'l'
Reid Spencerb4f9a6f2006-01-16 21:12:35 +0000318 || Name[2] != 'v' || Name[3] != 'm')
Chris Lattnerbb346d02003-05-08 03:47:33 +0000319 return 0; // All intrinsics start with 'llvm.'
Chris Lattner3284ed72003-09-19 19:31:41 +0000320
Reid Spencer9c2eec32007-04-16 06:54:34 +0000321 assert((Len != 5 || noAssert) && "'llvm.' is an invalid intrinsic name!");
Misha Brukmanb1c93172005-04-21 23:48:37 +0000322
Chris Lattnerff4d4ee2006-03-09 20:35:01 +0000323#define GET_FUNCTION_RECOGNIZER
324#include "llvm/Intrinsics.gen"
325#undef GET_FUNCTION_RECOGNIZER
Reid Spencer9c2eec32007-04-16 06:54:34 +0000326 assert(noAssert && "Invalid LLVM intrinsic name");
Chris Lattnerbb346d02003-05-08 03:47:33 +0000327 return 0;
328}
329
Reid Spencer2a2117c2007-04-01 07:25:33 +0000330std::string Intrinsic::getName(ID id, const Type **Tys, unsigned numTys) {
Chris Lattner71b8c982006-03-25 06:32:47 +0000331 assert(id < num_intrinsics && "Invalid intrinsic ID!");
332 const char * const Table[] = {
333 "not_intrinsic",
334#define GET_INTRINSIC_NAME_TABLE
335#include "llvm/Intrinsics.gen"
336#undef GET_INTRINSIC_NAME_TABLE
337 };
Reid Spencer2a2117c2007-04-01 07:25:33 +0000338 if (numTys == 0)
339 return Table[id];
340 std::string Result(Table[id]);
Mon P Wang2c839d42008-07-30 04:36:53 +0000341 for (unsigned i = 0; i < numTys; ++i) {
342 if (const PointerType* PTyp = dyn_cast<PointerType>(Tys[i])) {
343 Result += ".p" + llvm::utostr(PTyp->getAddressSpace()) +
344 MVT::getMVT(PTyp->getElementType()).getMVTString();
345 }
346 else if (Tys[i])
Duncan Sands13237ac2008-06-06 12:08:01 +0000347 Result += "." + MVT::getMVT(Tys[i]).getMVTString();
Mon P Wang2c839d42008-07-30 04:36:53 +0000348 }
Reid Spencer2a2117c2007-04-01 07:25:33 +0000349 return Result;
Chris Lattner71b8c982006-03-25 06:32:47 +0000350}
351
Reid Spencer2a2117c2007-04-01 07:25:33 +0000352const FunctionType *Intrinsic::getType(ID id, const Type **Tys,
Chris Lattner31f82df2007-06-05 23:49:06 +0000353 unsigned numTys) {
Jim Laskey2682ea62007-02-07 20:38:26 +0000354 const Type *ResultTy = NULL;
355 std::vector<const Type*> ArgTys;
Jim Laskey2682ea62007-02-07 20:38:26 +0000356 bool IsVarArg = false;
357
358#define GET_INTRINSIC_GENERATOR
359#include "llvm/Intrinsics.gen"
360#undef GET_INTRINSIC_GENERATOR
361
Reid Spencer26d9ff62007-04-09 06:11:23 +0000362 return FunctionType::get(ResultTy, ArgTys, IsVarArg);
Jim Laskey2682ea62007-02-07 20:38:26 +0000363}
364
Devang Patel4c758ea2008-09-25 21:00:45 +0000365AttrListPtr Intrinsic::getAttributes(ID id) {
366 Attributes Attr = Attribute::None;
Duncan Sands38ef3a82007-12-03 20:06:50 +0000367
368#define GET_INTRINSIC_ATTRIBUTES
369#include "llvm/Intrinsics.gen"
370#undef GET_INTRINSIC_ATTRIBUTES
371
372 // Intrinsics cannot throw exceptions.
Devang Patel4c758ea2008-09-25 21:00:45 +0000373 Attr |= Attribute::NoUnwind;
Duncan Sands38ef3a82007-12-03 20:06:50 +0000374
Devang Patela05633e2008-09-26 22:53:05 +0000375 AttributeWithIndex PAWI = AttributeWithIndex::get(~0, Attr);
Devang Patel4c758ea2008-09-25 21:00:45 +0000376 return AttrListPtr::get(&PAWI, 1);
Duncan Sands38ef3a82007-12-03 20:06:50 +0000377}
378
Reid Spencer2a2117c2007-04-01 07:25:33 +0000379Function *Intrinsic::getDeclaration(Module *M, ID id, const Type **Tys,
380 unsigned numTys) {
Duncan Sands38ef3a82007-12-03 20:06:50 +0000381 // There can never be multiple globals with the same name of different types,
382 // because intrinsics must be a specific type.
Duncan Sandsa8ff6ca2008-04-07 13:39:11 +0000383 return
Duncan Sands38ef3a82007-12-03 20:06:50 +0000384 cast<Function>(M->getOrInsertFunction(getName(id, Tys, numTys),
385 getType(id, Tys, numTys)));
Jim Laskey2682ea62007-02-07 20:38:26 +0000386}
387
Reid Spencerc49dd8d2004-07-17 23:50:19 +0000388// vim: sw=2 ai