1 //===-- Function.cpp - Implement the Global object classes ----------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the Function class for the IR library.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/IR/Function.h"
15 #include "LLVMContextImpl.h"
16 #include "SymbolTableListTraitsImpl.h"
17 #include "llvm/ADT/DenseMap.h"
18 #include "llvm/ADT/STLExtras.h"
19 #include "llvm/ADT/StringExtras.h"
20 #include "llvm/CodeGen/ValueTypes.h"
21 #include "llvm/IR/DerivedTypes.h"
22 #include "llvm/IR/IntrinsicInst.h"
23 #include "llvm/IR/LLVMContext.h"
24 #include "llvm/IR/Module.h"
25 #include "llvm/Support/CallSite.h"
26 #include "llvm/Support/InstIterator.h"
27 #include "llvm/Support/LeakDetector.h"
28 #include "llvm/Support/ManagedStatic.h"
29 #include "llvm/Support/RWMutex.h"
30 #include "llvm/Support/StringPool.h"
31 #include "llvm/Support/Threading.h"
34 // Explicit instantiations of SymbolTableListTraits since some of the methods
35 // are not in the public header file...
36 template class llvm::SymbolTableListTraits<Argument, Function>;
37 template class llvm::SymbolTableListTraits<BasicBlock, Function>;
39 //===----------------------------------------------------------------------===//
40 // Argument Implementation
41 //===----------------------------------------------------------------------===//
43 void Argument::anchor() { }
45 Argument::Argument(Type *Ty, const Twine &Name, Function *Par)
46 : Value(Ty, Value::ArgumentVal) {
49 // Make sure that we get added to a function
50 LeakDetector::addGarbageObject(this);
53 Par->getArgumentList().push_back(this);
57 void Argument::setParent(Function *parent) {
59 LeakDetector::addGarbageObject(this);
62 LeakDetector::removeGarbageObject(this);
65 /// getArgNo - Return the index of this formal argument in its containing
66 /// function. For example in "void foo(int a, float b)" a is 0 and b is 1.
67 unsigned Argument::getArgNo() const {
68 const Function *F = getParent();
69 assert(F && "Argument is not in a function");
71 Function::const_arg_iterator AI = F->arg_begin();
73 for (; &*AI != this; ++AI)
79 /// hasByValAttr - Return true if this argument has the byval attribute on it
80 /// in its containing function.
81 bool Argument::hasByValAttr() const {
82 if (!getType()->isPointerTy()) return false;
83 return getParent()->getAttributes().
84 hasAttribute(getArgNo()+1, Attribute::ByVal);
87 unsigned Argument::getParamAlignment() const {
88 assert(getType()->isPointerTy() && "Only pointers have alignments");
89 return getParent()->getParamAlignment(getArgNo()+1);
93 /// hasNestAttr - Return true if this argument has the nest attribute on
94 /// it in its containing function.
95 bool Argument::hasNestAttr() const {
96 if (!getType()->isPointerTy()) return false;
97 return getParent()->getAttributes().
98 hasAttribute(getArgNo()+1, Attribute::Nest);
101 /// hasNoAliasAttr - Return true if this argument has the noalias attribute on
102 /// it in its containing function.
103 bool Argument::hasNoAliasAttr() const {
104 if (!getType()->isPointerTy()) return false;
105 return getParent()->getAttributes().
106 hasAttribute(getArgNo()+1, Attribute::NoAlias);
109 /// hasNoCaptureAttr - Return true if this argument has the nocapture attribute
110 /// on it in its containing function.
111 bool Argument::hasNoCaptureAttr() const {
112 if (!getType()->isPointerTy()) return false;
113 return getParent()->getAttributes().
114 hasAttribute(getArgNo()+1, Attribute::NoCapture);
117 /// hasSRetAttr - Return true if this argument has the sret attribute on
118 /// it in its containing function.
119 bool Argument::hasStructRetAttr() const {
120 if (!getType()->isPointerTy()) return false;
121 if (this != getParent()->arg_begin())
122 return false; // StructRet param must be first param
123 return getParent()->getAttributes().
124 hasAttribute(1, Attribute::StructRet);
127 /// hasReturnedAttr - Return true if this argument has the returned attribute on
128 /// it in its containing function.
129 bool Argument::hasReturnedAttr() const {
130 return getParent()->getAttributes().
131 hasAttribute(getArgNo()+1, Attribute::Returned);
134 /// Return true if this argument has the readonly or readnone attribute on it
135 /// in its containing function.
136 bool Argument::onlyReadsMemory() const {
137 return getParent()->getAttributes().
138 hasAttribute(getArgNo()+1, Attribute::ReadOnly) ||
139 getParent()->getAttributes().
140 hasAttribute(getArgNo()+1, Attribute::ReadNone);
143 /// addAttr - Add attributes to an argument.
144 void Argument::addAttr(AttributeSet AS) {
145 assert(AS.getNumSlots() <= 1 &&
146 "Trying to add more than one attribute set to an argument!");
147 AttrBuilder B(AS, AS.getSlotIndex(0));
148 getParent()->addAttributes(getArgNo() + 1,
149 AttributeSet::get(Parent->getContext(),
153 /// removeAttr - Remove attributes from an argument.
154 void Argument::removeAttr(AttributeSet AS) {
155 assert(AS.getNumSlots() <= 1 &&
156 "Trying to remove more than one attribute set from an argument!");
157 AttrBuilder B(AS, AS.getSlotIndex(0));
158 getParent()->removeAttributes(getArgNo() + 1,
159 AttributeSet::get(Parent->getContext(),
163 //===----------------------------------------------------------------------===//
164 // Helper Methods in Function
165 //===----------------------------------------------------------------------===//
167 LLVMContext &Function::getContext() const {
168 return getType()->getContext();
171 FunctionType *Function::getFunctionType() const {
172 return cast<FunctionType>(getType()->getElementType());
175 bool Function::isVarArg() const {
176 return getFunctionType()->isVarArg();
179 Type *Function::getReturnType() const {
180 return getFunctionType()->getReturnType();
183 void Function::removeFromParent() {
184 getParent()->getFunctionList().remove(this);
187 void Function::eraseFromParent() {
188 getParent()->getFunctionList().erase(this);
191 //===----------------------------------------------------------------------===//
192 // Function Implementation
193 //===----------------------------------------------------------------------===//
195 Function::Function(FunctionType *Ty, LinkageTypes Linkage,
196 const Twine &name, Module *ParentModule)
197 : GlobalValue(PointerType::getUnqual(Ty),
198 Value::FunctionVal, 0, 0, Linkage, name) {
199 assert(FunctionType::isValidReturnType(getReturnType()) &&
200 "invalid return type");
201 SymTab = new ValueSymbolTable();
203 // If the function has arguments, mark them as lazily built.
204 if (Ty->getNumParams())
205 setValueSubclassData(1); // Set the "has lazy arguments" bit.
207 // Make sure that we get added to a function
208 LeakDetector::addGarbageObject(this);
211 ParentModule->getFunctionList().push_back(this);
213 // Ensure intrinsics have the right parameter attributes.
214 if (unsigned IID = getIntrinsicID())
215 setAttributes(Intrinsic::getAttributes(getContext(), Intrinsic::ID(IID)));
219 Function::~Function() {
220 dropAllReferences(); // After this it is safe to delete instructions.
222 // Delete all of the method arguments and unlink from symbol table...
223 ArgumentList.clear();
226 // Remove the function from the on-the-side GC table.
229 // Remove the intrinsicID from the Cache.
230 if (getValueName() && isIntrinsic())
231 getContext().pImpl->IntrinsicIDCache.erase(this);
234 void Function::BuildLazyArguments() const {
235 // Create the arguments vector, all arguments start out unnamed.
236 FunctionType *FT = getFunctionType();
237 for (unsigned i = 0, e = FT->getNumParams(); i != e; ++i) {
238 assert(!FT->getParamType(i)->isVoidTy() &&
239 "Cannot have void typed arguments!");
240 ArgumentList.push_back(new Argument(FT->getParamType(i)));
243 // Clear the lazy arguments bit.
244 unsigned SDC = getSubclassDataFromValue();
245 const_cast<Function*>(this)->setValueSubclassData(SDC &= ~1);
248 size_t Function::arg_size() const {
249 return getFunctionType()->getNumParams();
251 bool Function::arg_empty() const {
252 return getFunctionType()->getNumParams() == 0;
255 void Function::setParent(Module *parent) {
257 LeakDetector::addGarbageObject(this);
260 LeakDetector::removeGarbageObject(this);
263 // dropAllReferences() - This function causes all the subinstructions to "let
264 // go" of all references that they are maintaining. This allows one to
265 // 'delete' a whole class at a time, even though there may be circular
266 // references... first all references are dropped, and all use counts go to
267 // zero. Then everything is deleted for real. Note that no operations are
268 // valid on an object that has "dropped all references", except operator
271 void Function::dropAllReferences() {
272 for (iterator I = begin(), E = end(); I != E; ++I)
273 I->dropAllReferences();
275 // Delete all basic blocks. They are now unused, except possibly by
276 // blockaddresses, but BasicBlock's destructor takes care of those.
277 while (!BasicBlocks.empty())
278 BasicBlocks.begin()->eraseFromParent();
280 // Prefix data is stored in a side table.
284 void Function::addAttribute(unsigned i, Attribute::AttrKind attr) {
285 AttributeSet PAL = getAttributes();
286 PAL = PAL.addAttribute(getContext(), i, attr);
290 void Function::addAttributes(unsigned i, AttributeSet attrs) {
291 AttributeSet PAL = getAttributes();
292 PAL = PAL.addAttributes(getContext(), i, attrs);
296 void Function::removeAttributes(unsigned i, AttributeSet attrs) {
297 AttributeSet PAL = getAttributes();
298 PAL = PAL.removeAttributes(getContext(), i, attrs);
302 // Maintain the GC name for each function in an on-the-side table. This saves
303 // allocating an additional word in Function for programs which do not use GC
304 // (i.e., most programs) at the cost of increased overhead for clients which do
306 static DenseMap<const Function*,PooledStringPtr> *GCNames;
307 static StringPool *GCNamePool;
308 static ManagedStatic<sys::SmartRWMutex<true> > GCLock;
310 bool Function::hasGC() const {
311 sys::SmartScopedReader<true> Reader(*GCLock);
312 return GCNames && GCNames->count(this);
315 const char *Function::getGC() const {
316 assert(hasGC() && "Function has no collector");
317 sys::SmartScopedReader<true> Reader(*GCLock);
318 return *(*GCNames)[this];
321 void Function::setGC(const char *Str) {
322 sys::SmartScopedWriter<true> Writer(*GCLock);
324 GCNamePool = new StringPool();
326 GCNames = new DenseMap<const Function*,PooledStringPtr>();
327 (*GCNames)[this] = GCNamePool->intern(Str);
330 void Function::clearGC() {
331 sys::SmartScopedWriter<true> Writer(*GCLock);
333 GCNames->erase(this);
334 if (GCNames->empty()) {
337 if (GCNamePool->empty()) {
345 /// copyAttributesFrom - copy all additional attributes (those not needed to
346 /// create a Function) from the Function Src to this one.
347 void Function::copyAttributesFrom(const GlobalValue *Src) {
348 assert(isa<Function>(Src) && "Expected a Function!");
349 GlobalValue::copyAttributesFrom(Src);
350 const Function *SrcF = cast<Function>(Src);
351 setCallingConv(SrcF->getCallingConv());
352 setAttributes(SrcF->getAttributes());
354 setGC(SrcF->getGC());
357 if (SrcF->hasPrefixData())
358 setPrefixData(SrcF->getPrefixData());
363 /// getIntrinsicID - This method returns the ID number of the specified
364 /// function, or Intrinsic::not_intrinsic if the function is not an
365 /// intrinsic, or if the pointer is null. This value is always defined to be
366 /// zero to allow easy checking for whether a function is intrinsic or not. The
367 /// particular intrinsic functions which correspond to this value are defined in
368 /// llvm/Intrinsics.h. Results are cached in the LLVM context, subsequent
369 /// requests for the same ID return results much faster from the cache.
371 unsigned Function::getIntrinsicID() const {
372 const ValueName *ValName = this->getValueName();
373 if (!ValName || !isIntrinsic())
376 LLVMContextImpl::IntrinsicIDCacheTy &IntrinsicIDCache =
377 getContext().pImpl->IntrinsicIDCache;
378 if (!IntrinsicIDCache.count(this)) {
379 unsigned Id = lookupIntrinsicID();
380 IntrinsicIDCache[this]=Id;
383 return IntrinsicIDCache[this];
386 /// This private method does the actual lookup of an intrinsic ID when the query
387 /// could not be answered from the cache.
388 unsigned Function::lookupIntrinsicID() const {
389 const ValueName *ValName = this->getValueName();
390 unsigned Len = ValName->getKeyLength();
391 const char *Name = ValName->getKeyData();
393 #define GET_FUNCTION_RECOGNIZER
394 #include "llvm/IR/Intrinsics.gen"
395 #undef GET_FUNCTION_RECOGNIZER
400 std::string Intrinsic::getName(ID id, ArrayRef<Type*> Tys) {
401 assert(id < num_intrinsics && "Invalid intrinsic ID!");
402 static const char * const Table[] = {
404 #define GET_INTRINSIC_NAME_TABLE
405 #include "llvm/IR/Intrinsics.gen"
406 #undef GET_INTRINSIC_NAME_TABLE
410 std::string Result(Table[id]);
411 for (unsigned i = 0; i < Tys.size(); ++i) {
412 if (PointerType* PTyp = dyn_cast<PointerType>(Tys[i])) {
413 Result += ".p" + llvm::utostr(PTyp->getAddressSpace()) +
414 EVT::getEVT(PTyp->getElementType()).getEVTString();
417 Result += "." + EVT::getEVT(Tys[i]).getEVTString();
423 /// IIT_Info - These are enumerators that describe the entries returned by the
424 /// getIntrinsicInfoTableEntries function.
426 /// NOTE: This must be kept in synch with the copy in TblGen/IntrinsicEmitter!
428 // Common values should be encoded with 0-15.
446 // Values from 16+ are only encodable with the inefficient encoding.
449 IIT_EMPTYSTRUCT = 18,
454 IIT_EXTEND_VEC_ARG = 23,
455 IIT_TRUNC_VEC_ARG = 24,
462 static void DecodeIITType(unsigned &NextElt, ArrayRef<unsigned char> Infos,
463 SmallVectorImpl<Intrinsic::IITDescriptor> &OutputTable) {
464 IIT_Info Info = IIT_Info(Infos[NextElt++]);
465 unsigned StructElts = 2;
466 using namespace Intrinsic;
470 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Void, 0));
473 OutputTable.push_back(IITDescriptor::get(IITDescriptor::VarArg, 0));
476 OutputTable.push_back(IITDescriptor::get(IITDescriptor::MMX, 0));
479 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Metadata, 0));
482 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Half, 0));
485 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Float, 0));
488 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Double, 0));
491 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 1));
494 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 8));
497 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer,16));
500 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 32));
503 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 64));
506 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Vector, 1));
507 DecodeIITType(NextElt, Infos, OutputTable);
510 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Vector, 2));
511 DecodeIITType(NextElt, Infos, OutputTable);
514 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Vector, 4));
515 DecodeIITType(NextElt, Infos, OutputTable);
518 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Vector, 8));
519 DecodeIITType(NextElt, Infos, OutputTable);
522 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Vector, 16));
523 DecodeIITType(NextElt, Infos, OutputTable);
526 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Vector, 32));
527 DecodeIITType(NextElt, Infos, OutputTable);
530 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Pointer, 0));
531 DecodeIITType(NextElt, Infos, OutputTable);
533 case IIT_ANYPTR: { // [ANYPTR addrspace, subtype]
534 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Pointer,
536 DecodeIITType(NextElt, Infos, OutputTable);
540 unsigned ArgInfo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
541 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Argument, ArgInfo));
544 case IIT_EXTEND_VEC_ARG: {
545 unsigned ArgInfo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
546 OutputTable.push_back(IITDescriptor::get(IITDescriptor::ExtendVecArgument,
550 case IIT_TRUNC_VEC_ARG: {
551 unsigned ArgInfo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
552 OutputTable.push_back(IITDescriptor::get(IITDescriptor::TruncVecArgument,
556 case IIT_EMPTYSTRUCT:
557 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Struct, 0));
559 case IIT_STRUCT5: ++StructElts; // FALL THROUGH.
560 case IIT_STRUCT4: ++StructElts; // FALL THROUGH.
561 case IIT_STRUCT3: ++StructElts; // FALL THROUGH.
563 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Struct,StructElts));
565 for (unsigned i = 0; i != StructElts; ++i)
566 DecodeIITType(NextElt, Infos, OutputTable);
570 llvm_unreachable("unhandled");
574 #define GET_INTRINSIC_GENERATOR_GLOBAL
575 #include "llvm/IR/Intrinsics.gen"
576 #undef GET_INTRINSIC_GENERATOR_GLOBAL
578 void Intrinsic::getIntrinsicInfoTableEntries(ID id,
579 SmallVectorImpl<IITDescriptor> &T){
580 // Check to see if the intrinsic's type was expressible by the table.
581 unsigned TableVal = IIT_Table[id-1];
583 // Decode the TableVal into an array of IITValues.
584 SmallVector<unsigned char, 8> IITValues;
585 ArrayRef<unsigned char> IITEntries;
586 unsigned NextElt = 0;
587 if ((TableVal >> 31) != 0) {
588 // This is an offset into the IIT_LongEncodingTable.
589 IITEntries = IIT_LongEncodingTable;
591 // Strip sentinel bit.
592 NextElt = (TableVal << 1) >> 1;
594 // Decode the TableVal into an array of IITValues. If the entry was encoded
595 // into a single word in the table itself, decode it now.
597 IITValues.push_back(TableVal & 0xF);
601 IITEntries = IITValues;
605 // Okay, decode the table into the output vector of IITDescriptors.
606 DecodeIITType(NextElt, IITEntries, T);
607 while (NextElt != IITEntries.size() && IITEntries[NextElt] != 0)
608 DecodeIITType(NextElt, IITEntries, T);
612 static Type *DecodeFixedType(ArrayRef<Intrinsic::IITDescriptor> &Infos,
613 ArrayRef<Type*> Tys, LLVMContext &Context) {
614 using namespace Intrinsic;
615 IITDescriptor D = Infos.front();
616 Infos = Infos.slice(1);
619 case IITDescriptor::Void: return Type::getVoidTy(Context);
620 case IITDescriptor::VarArg: return Type::getVoidTy(Context);
621 case IITDescriptor::MMX: return Type::getX86_MMXTy(Context);
622 case IITDescriptor::Metadata: return Type::getMetadataTy(Context);
623 case IITDescriptor::Half: return Type::getHalfTy(Context);
624 case IITDescriptor::Float: return Type::getFloatTy(Context);
625 case IITDescriptor::Double: return Type::getDoubleTy(Context);
627 case IITDescriptor::Integer:
628 return IntegerType::get(Context, D.Integer_Width);
629 case IITDescriptor::Vector:
630 return VectorType::get(DecodeFixedType(Infos, Tys, Context),D.Vector_Width);
631 case IITDescriptor::Pointer:
632 return PointerType::get(DecodeFixedType(Infos, Tys, Context),
633 D.Pointer_AddressSpace);
634 case IITDescriptor::Struct: {
636 assert(D.Struct_NumElements <= 5 && "Can't handle this yet");
637 for (unsigned i = 0, e = D.Struct_NumElements; i != e; ++i)
638 Elts[i] = DecodeFixedType(Infos, Tys, Context);
639 return StructType::get(Context, ArrayRef<Type*>(Elts,D.Struct_NumElements));
642 case IITDescriptor::Argument:
643 return Tys[D.getArgumentNumber()];
644 case IITDescriptor::ExtendVecArgument:
645 return VectorType::getExtendedElementVectorType(cast<VectorType>(
646 Tys[D.getArgumentNumber()]));
648 case IITDescriptor::TruncVecArgument:
649 return VectorType::getTruncatedElementVectorType(cast<VectorType>(
650 Tys[D.getArgumentNumber()]));
652 llvm_unreachable("unhandled");
657 FunctionType *Intrinsic::getType(LLVMContext &Context,
658 ID id, ArrayRef<Type*> Tys) {
659 SmallVector<IITDescriptor, 8> Table;
660 getIntrinsicInfoTableEntries(id, Table);
662 ArrayRef<IITDescriptor> TableRef = Table;
663 Type *ResultTy = DecodeFixedType(TableRef, Tys, Context);
665 SmallVector<Type*, 8> ArgTys;
666 while (!TableRef.empty())
667 ArgTys.push_back(DecodeFixedType(TableRef, Tys, Context));
669 return FunctionType::get(ResultTy, ArgTys, false);
672 bool Intrinsic::isOverloaded(ID id) {
673 #define GET_INTRINSIC_OVERLOAD_TABLE
674 #include "llvm/IR/Intrinsics.gen"
675 #undef GET_INTRINSIC_OVERLOAD_TABLE
678 /// This defines the "Intrinsic::getAttributes(ID id)" method.
679 #define GET_INTRINSIC_ATTRIBUTES
680 #include "llvm/IR/Intrinsics.gen"
681 #undef GET_INTRINSIC_ATTRIBUTES
683 Function *Intrinsic::getDeclaration(Module *M, ID id, ArrayRef<Type*> Tys) {
684 // There can never be multiple globals with the same name of different types,
685 // because intrinsics must be a specific type.
687 cast<Function>(M->getOrInsertFunction(getName(id, Tys),
688 getType(M->getContext(), id, Tys)));
691 // This defines the "Intrinsic::getIntrinsicForGCCBuiltin()" method.
692 #define GET_LLVM_INTRINSIC_FOR_GCC_BUILTIN
693 #include "llvm/IR/Intrinsics.gen"
694 #undef GET_LLVM_INTRINSIC_FOR_GCC_BUILTIN
696 /// hasAddressTaken - returns true if there are any uses of this function
697 /// other than direct calls or invokes to it.
698 bool Function::hasAddressTaken(const User* *PutOffender) const {
699 for (Value::const_use_iterator I = use_begin(), E = use_end(); I != E; ++I) {
701 if (isa<BlockAddress>(U))
703 if (!isa<CallInst>(U) && !isa<InvokeInst>(U))
704 return PutOffender ? (*PutOffender = U, true) : true;
705 ImmutableCallSite CS(cast<Instruction>(U));
707 return PutOffender ? (*PutOffender = U, true) : true;
712 bool Function::isDefTriviallyDead() const {
714 if (!hasLinkOnceLinkage() && !hasLocalLinkage() &&
715 !hasAvailableExternallyLinkage())
718 // Check if the function is used by anything other than a blockaddress.
719 for (Value::const_use_iterator I = use_begin(), E = use_end(); I != E; ++I)
720 if (!isa<BlockAddress>(*I))
726 /// callsFunctionThatReturnsTwice - Return true if the function has a call to
727 /// setjmp or other function that gcc recognizes as "returning twice".
728 bool Function::callsFunctionThatReturnsTwice() const {
729 for (const_inst_iterator
730 I = inst_begin(this), E = inst_end(this); I != E; ++I) {
731 const CallInst* callInst = dyn_cast<CallInst>(&*I);
734 if (callInst->canReturnTwice())
741 Constant *Function::getPrefixData() const {
742 assert(hasPrefixData());
743 const LLVMContextImpl::PrefixDataMapTy &PDMap =
744 getContext().pImpl->PrefixDataMap;
745 assert(PDMap.find(this) != PDMap.end());
746 return cast<Constant>(PDMap.find(this)->second->getReturnValue());
749 void Function::setPrefixData(Constant *PrefixData) {
750 if (!PrefixData && !hasPrefixData())
753 unsigned SCData = getSubclassDataFromValue();
754 LLVMContextImpl::PrefixDataMapTy &PDMap = getContext().pImpl->PrefixDataMap;
755 ReturnInst *&PDHolder = PDMap[this];
758 PDHolder->setOperand(0, PrefixData);
760 PDHolder = ReturnInst::Create(getContext(), PrefixData);
767 setValueSubclassData(SCData);