Chris Lattner | 44d2c35 | 2003-10-13 03:32:08 +0000 | [diff] [blame] | 1 | //===-- Function.cpp - Implement the Global object classes ----------------===// |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 2 | // |
John Criswell | 482202a | 2003-10-20 19:43:21 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | f3ebc3f | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 7 | // |
John Criswell | 482202a | 2003-10-20 19:43:21 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 9 | // |
Chandler Carruth | ef860a2 | 2013-01-02 09:10:48 +0000 | [diff] [blame] | 10 | // This file implements the Function class for the IR library. |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 14 | #include "llvm/IR/Function.h" |
Michael Ilseman | 516d703 | 2013-03-01 18:48:54 +0000 | [diff] [blame] | 15 | #include "LLVMContextImpl.h" |
Chris Lattner | 113f4f4 | 2002-06-25 16:13:24 +0000 | [diff] [blame] | 16 | #include "SymbolTableListTraitsImpl.h" |
Gordon Henriksen | 71183b6 | 2007-12-10 03:18:06 +0000 | [diff] [blame] | 17 | #include "llvm/ADT/DenseMap.h" |
Rafael Espindola | 2050af8 | 2011-05-16 03:05:33 +0000 | [diff] [blame] | 18 | #include "llvm/ADT/STLExtras.h" |
Chris Lattner | b392d30 | 2004-12-05 06:43:27 +0000 | [diff] [blame] | 19 | #include "llvm/ADT/StringExtras.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 20 | #include "llvm/CodeGen/ValueTypes.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 21 | #include "llvm/IR/DerivedTypes.h" |
Chandler Carruth | 8394857 | 2014-03-04 10:30:26 +0000 | [diff] [blame^] | 22 | #include "llvm/IR/InstIterator.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 23 | #include "llvm/IR/IntrinsicInst.h" |
| 24 | #include "llvm/IR/LLVMContext.h" |
| 25 | #include "llvm/IR/Module.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 26 | #include "llvm/Support/CallSite.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 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" |
Chris Lattner | 189d19f | 2003-11-21 20:23:48 +0000 | [diff] [blame] | 32 | using namespace llvm; |
Brian Gaeke | 960707c | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 33 | |
Chris Lattner | 113f4f4 | 2002-06-25 16:13:24 +0000 | [diff] [blame] | 34 | // Explicit instantiations of SymbolTableListTraits since some of the methods |
| 35 | // are not in the public header file... |
John McCall | 086bb4e | 2009-12-19 00:55:12 +0000 | [diff] [blame] | 36 | template class llvm::SymbolTableListTraits<Argument, Function>; |
| 37 | template class llvm::SymbolTableListTraits<BasicBlock, Function>; |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 38 | |
Chris Lattner | da97550 | 2001-09-10 07:58:01 +0000 | [diff] [blame] | 39 | //===----------------------------------------------------------------------===// |
Chris Lattner | d255ae2 | 2002-04-09 19:39:35 +0000 | [diff] [blame] | 40 | // Argument Implementation |
| 41 | //===----------------------------------------------------------------------===// |
| 42 | |
David Blaikie | a379b181 | 2011-12-20 02:50:00 +0000 | [diff] [blame] | 43 | void Argument::anchor() { } |
| 44 | |
Chris Lattner | 229907c | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 45 | Argument::Argument(Type *Ty, const Twine &Name, Function *Par) |
Chris Lattner | 32ab643 | 2007-02-12 05:18:08 +0000 | [diff] [blame] | 46 | : Value(Ty, Value::ArgumentVal) { |
Chris Lattner | 9ed7aef | 2002-09-06 21:33:15 +0000 | [diff] [blame] | 47 | Parent = 0; |
Chris Lattner | 184b298 | 2002-09-08 18:59:35 +0000 | [diff] [blame] | 48 | |
| 49 | // Make sure that we get added to a function |
| 50 | LeakDetector::addGarbageObject(this); |
| 51 | |
Chris Lattner | 9ed7aef | 2002-09-06 21:33:15 +0000 | [diff] [blame] | 52 | if (Par) |
| 53 | Par->getArgumentList().push_back(this); |
Chris Lattner | 32ab643 | 2007-02-12 05:18:08 +0000 | [diff] [blame] | 54 | setName(Name); |
Chris Lattner | 9ed7aef | 2002-09-06 21:33:15 +0000 | [diff] [blame] | 55 | } |
| 56 | |
Chris Lattner | 9ed7aef | 2002-09-06 21:33:15 +0000 | [diff] [blame] | 57 | void Argument::setParent(Function *parent) { |
Chris Lattner | 184b298 | 2002-09-08 18:59:35 +0000 | [diff] [blame] | 58 | if (getParent()) |
| 59 | LeakDetector::addGarbageObject(this); |
Chris Lattner | 9ed7aef | 2002-09-06 21:33:15 +0000 | [diff] [blame] | 60 | Parent = parent; |
Chris Lattner | 184b298 | 2002-09-08 18:59:35 +0000 | [diff] [blame] | 61 | if (getParent()) |
| 62 | LeakDetector::removeGarbageObject(this); |
Chris Lattner | 9ed7aef | 2002-09-06 21:33:15 +0000 | [diff] [blame] | 63 | } |
| 64 | |
Chris Lattner | e30f09d | 2008-01-24 17:47:11 +0000 | [diff] [blame] | 65 | /// getArgNo - Return the index of this formal argument in its containing |
Michael Ilseman | acdb76d | 2012-12-17 20:37:55 +0000 | [diff] [blame] | 66 | /// function. For example in "void foo(int a, float b)" a is 0 and b is 1. |
Chris Lattner | e30f09d | 2008-01-24 17:47:11 +0000 | [diff] [blame] | 67 | unsigned Argument::getArgNo() const { |
| 68 | const Function *F = getParent(); |
| 69 | assert(F && "Argument is not in a function"); |
Michael Ilseman | acdb76d | 2012-12-17 20:37:55 +0000 | [diff] [blame] | 70 | |
Chris Lattner | e30f09d | 2008-01-24 17:47:11 +0000 | [diff] [blame] | 71 | Function::const_arg_iterator AI = F->arg_begin(); |
| 72 | unsigned ArgIdx = 0; |
| 73 | for (; &*AI != this; ++AI) |
| 74 | ++ArgIdx; |
| 75 | |
| 76 | return ArgIdx; |
| 77 | } |
| 78 | |
| 79 | /// hasByValAttr - Return true if this argument has the byval attribute on it |
| 80 | /// in its containing function. |
| 81 | bool Argument::hasByValAttr() const { |
Duncan Sands | 19d0b47 | 2010-02-16 11:11:14 +0000 | [diff] [blame] | 82 | if (!getType()->isPointerTy()) return false; |
Bill Wendling | 94dcaf8 | 2012-12-30 12:45:13 +0000 | [diff] [blame] | 83 | return getParent()->getAttributes(). |
| 84 | hasAttribute(getArgNo()+1, Attribute::ByVal); |
Chris Lattner | e30f09d | 2008-01-24 17:47:11 +0000 | [diff] [blame] | 85 | } |
| 86 | |
Reid Kleckner | a534a38 | 2013-12-19 02:14:12 +0000 | [diff] [blame] | 87 | /// \brief Return true if this argument has the inalloca attribute on it in |
| 88 | /// its containing function. |
| 89 | bool Argument::hasInAllocaAttr() const { |
| 90 | if (!getType()->isPointerTy()) return false; |
| 91 | return getParent()->getAttributes(). |
| 92 | hasAttribute(getArgNo()+1, Attribute::InAlloca); |
| 93 | } |
| 94 | |
Reid Kleckner | 436c42e | 2014-01-17 23:58:17 +0000 | [diff] [blame] | 95 | bool Argument::hasByValOrInAllocaAttr() const { |
| 96 | if (!getType()->isPointerTy()) return false; |
| 97 | AttributeSet Attrs = getParent()->getAttributes(); |
| 98 | return Attrs.hasAttribute(getArgNo() + 1, Attribute::ByVal) || |
| 99 | Attrs.hasAttribute(getArgNo() + 1, Attribute::InAlloca); |
| 100 | } |
| 101 | |
Chris Lattner | 4d37d99 | 2011-05-22 23:57:23 +0000 | [diff] [blame] | 102 | unsigned Argument::getParamAlignment() const { |
| 103 | assert(getType()->isPointerTy() && "Only pointers have alignments"); |
| 104 | return getParent()->getParamAlignment(getArgNo()+1); |
Michael Ilseman | acdb76d | 2012-12-17 20:37:55 +0000 | [diff] [blame] | 105 | |
Chris Lattner | 4d37d99 | 2011-05-22 23:57:23 +0000 | [diff] [blame] | 106 | } |
| 107 | |
Duncan Sands | 5d96f3f | 2009-12-11 08:36:17 +0000 | [diff] [blame] | 108 | /// hasNestAttr - Return true if this argument has the nest attribute on |
| 109 | /// it in its containing function. |
| 110 | bool Argument::hasNestAttr() const { |
Duncan Sands | 19d0b47 | 2010-02-16 11:11:14 +0000 | [diff] [blame] | 111 | if (!getType()->isPointerTy()) return false; |
Bill Wendling | 94dcaf8 | 2012-12-30 12:45:13 +0000 | [diff] [blame] | 112 | return getParent()->getAttributes(). |
| 113 | hasAttribute(getArgNo()+1, Attribute::Nest); |
Duncan Sands | 5d96f3f | 2009-12-11 08:36:17 +0000 | [diff] [blame] | 114 | } |
| 115 | |
Chris Lattner | e30f09d | 2008-01-24 17:47:11 +0000 | [diff] [blame] | 116 | /// hasNoAliasAttr - Return true if this argument has the noalias attribute on |
| 117 | /// it in its containing function. |
| 118 | bool Argument::hasNoAliasAttr() const { |
Duncan Sands | 19d0b47 | 2010-02-16 11:11:14 +0000 | [diff] [blame] | 119 | if (!getType()->isPointerTy()) return false; |
Bill Wendling | 94dcaf8 | 2012-12-30 12:45:13 +0000 | [diff] [blame] | 120 | return getParent()->getAttributes(). |
| 121 | hasAttribute(getArgNo()+1, Attribute::NoAlias); |
Chris Lattner | e30f09d | 2008-01-24 17:47:11 +0000 | [diff] [blame] | 122 | } |
| 123 | |
Duncan Sands | df128eb | 2008-12-31 18:08:59 +0000 | [diff] [blame] | 124 | /// hasNoCaptureAttr - Return true if this argument has the nocapture attribute |
| 125 | /// on it in its containing function. |
| 126 | bool Argument::hasNoCaptureAttr() const { |
Duncan Sands | 19d0b47 | 2010-02-16 11:11:14 +0000 | [diff] [blame] | 127 | if (!getType()->isPointerTy()) return false; |
Bill Wendling | 94dcaf8 | 2012-12-30 12:45:13 +0000 | [diff] [blame] | 128 | return getParent()->getAttributes(). |
| 129 | hasAttribute(getArgNo()+1, Attribute::NoCapture); |
Duncan Sands | df128eb | 2008-12-31 18:08:59 +0000 | [diff] [blame] | 130 | } |
| 131 | |
Owen Anderson | c64dfb4 | 2008-02-17 23:22:28 +0000 | [diff] [blame] | 132 | /// hasSRetAttr - Return true if this argument has the sret attribute on |
| 133 | /// it in its containing function. |
| 134 | bool Argument::hasStructRetAttr() const { |
Duncan Sands | 19d0b47 | 2010-02-16 11:11:14 +0000 | [diff] [blame] | 135 | if (!getType()->isPointerTy()) return false; |
Gabor Greif | 697e94c | 2008-05-15 10:04:30 +0000 | [diff] [blame] | 136 | if (this != getParent()->arg_begin()) |
| 137 | return false; // StructRet param must be first param |
Bill Wendling | 94dcaf8 | 2012-12-30 12:45:13 +0000 | [diff] [blame] | 138 | return getParent()->getAttributes(). |
| 139 | hasAttribute(1, Attribute::StructRet); |
Owen Anderson | c64dfb4 | 2008-02-17 23:22:28 +0000 | [diff] [blame] | 140 | } |
| 141 | |
Stephen Lin | b8bd232 | 2013-04-20 05:14:40 +0000 | [diff] [blame] | 142 | /// hasReturnedAttr - Return true if this argument has the returned attribute on |
| 143 | /// it in its containing function. |
| 144 | bool Argument::hasReturnedAttr() const { |
| 145 | return getParent()->getAttributes(). |
| 146 | hasAttribute(getArgNo()+1, Attribute::Returned); |
| 147 | } |
| 148 | |
Nick Lewycky | c2ec072 | 2013-07-06 00:29:58 +0000 | [diff] [blame] | 149 | /// Return true if this argument has the readonly or readnone attribute on it |
| 150 | /// in its containing function. |
| 151 | bool Argument::onlyReadsMemory() const { |
| 152 | return getParent()->getAttributes(). |
| 153 | hasAttribute(getArgNo()+1, Attribute::ReadOnly) || |
| 154 | getParent()->getAttributes(). |
| 155 | hasAttribute(getArgNo()+1, Attribute::ReadNone); |
| 156 | } |
| 157 | |
Bill Wendling | 49bc76c | 2013-01-23 06:14:59 +0000 | [diff] [blame] | 158 | /// addAttr - Add attributes to an argument. |
| 159 | void Argument::addAttr(AttributeSet AS) { |
Bill Wendling | efbbbfd | 2013-02-21 19:46:51 +0000 | [diff] [blame] | 160 | assert(AS.getNumSlots() <= 1 && |
Bill Wendling | 1c20ff0 | 2013-02-20 23:04:11 +0000 | [diff] [blame] | 161 | "Trying to add more than one attribute set to an argument!"); |
| 162 | AttrBuilder B(AS, AS.getSlotIndex(0)); |
| 163 | getParent()->addAttributes(getArgNo() + 1, |
| 164 | AttributeSet::get(Parent->getContext(), |
| 165 | getArgNo() + 1, B)); |
Gordon Henriksen | 2d9cc21 | 2008-04-28 17:37:06 +0000 | [diff] [blame] | 166 | } |
Chris Lattner | e30f09d | 2008-01-24 17:47:11 +0000 | [diff] [blame] | 167 | |
Bill Wendling | 49bc76c | 2013-01-23 06:14:59 +0000 | [diff] [blame] | 168 | /// removeAttr - Remove attributes from an argument. |
| 169 | void Argument::removeAttr(AttributeSet AS) { |
Bill Wendling | efbbbfd | 2013-02-21 19:46:51 +0000 | [diff] [blame] | 170 | assert(AS.getNumSlots() <= 1 && |
Bill Wendling | 1c20ff0 | 2013-02-20 23:04:11 +0000 | [diff] [blame] | 171 | "Trying to remove more than one attribute set from an argument!"); |
| 172 | AttrBuilder B(AS, AS.getSlotIndex(0)); |
| 173 | getParent()->removeAttributes(getArgNo() + 1, |
| 174 | AttributeSet::get(Parent->getContext(), |
| 175 | getArgNo() + 1, B)); |
Duncan Sands | 66336db | 2008-07-08 09:41:30 +0000 | [diff] [blame] | 176 | } |
Chris Lattner | e30f09d | 2008-01-24 17:47:11 +0000 | [diff] [blame] | 177 | |
Chris Lattner | d255ae2 | 2002-04-09 19:39:35 +0000 | [diff] [blame] | 178 | //===----------------------------------------------------------------------===// |
Chris Lattner | 3e13b8c | 2008-01-02 23:42:30 +0000 | [diff] [blame] | 179 | // Helper Methods in Function |
Reid Spencer | 019c886 | 2007-04-09 15:01:12 +0000 | [diff] [blame] | 180 | //===----------------------------------------------------------------------===// |
| 181 | |
Owen Anderson | 47db941 | 2009-07-22 00:24:57 +0000 | [diff] [blame] | 182 | LLVMContext &Function::getContext() const { |
| 183 | return getType()->getContext(); |
Owen Anderson | 0a2c458 | 2009-07-02 18:03:58 +0000 | [diff] [blame] | 184 | } |
| 185 | |
Chris Lattner | b1ed91f | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 186 | FunctionType *Function::getFunctionType() const { |
Chris Lattner | 3e13b8c | 2008-01-02 23:42:30 +0000 | [diff] [blame] | 187 | return cast<FunctionType>(getType()->getElementType()); |
Reid Spencer | 019c886 | 2007-04-09 15:01:12 +0000 | [diff] [blame] | 188 | } |
| 189 | |
Chris Lattner | 3e13b8c | 2008-01-02 23:42:30 +0000 | [diff] [blame] | 190 | bool Function::isVarArg() const { |
| 191 | return getFunctionType()->isVarArg(); |
Reid Spencer | 019c886 | 2007-04-09 15:01:12 +0000 | [diff] [blame] | 192 | } |
| 193 | |
Chris Lattner | b1ed91f | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 194 | Type *Function::getReturnType() const { |
Chris Lattner | 3e13b8c | 2008-01-02 23:42:30 +0000 | [diff] [blame] | 195 | return getFunctionType()->getReturnType(); |
Duncan Sands | 185eeac | 2007-11-25 14:10:56 +0000 | [diff] [blame] | 196 | } |
| 197 | |
Chris Lattner | 3e13b8c | 2008-01-02 23:42:30 +0000 | [diff] [blame] | 198 | void Function::removeFromParent() { |
| 199 | getParent()->getFunctionList().remove(this); |
Duncan Sands | 185eeac | 2007-11-25 14:10:56 +0000 | [diff] [blame] | 200 | } |
| 201 | |
Chris Lattner | 3e13b8c | 2008-01-02 23:42:30 +0000 | [diff] [blame] | 202 | void Function::eraseFromParent() { |
| 203 | getParent()->getFunctionList().erase(this); |
Reid Spencer | 019c886 | 2007-04-09 15:01:12 +0000 | [diff] [blame] | 204 | } |
| 205 | |
Reid Spencer | 019c886 | 2007-04-09 15:01:12 +0000 | [diff] [blame] | 206 | //===----------------------------------------------------------------------===// |
Chris Lattner | 57698e2 | 2002-03-26 18:01:55 +0000 | [diff] [blame] | 207 | // Function Implementation |
Chris Lattner | da97550 | 2001-09-10 07:58:01 +0000 | [diff] [blame] | 208 | //===----------------------------------------------------------------------===// |
| 209 | |
Chris Lattner | 229907c | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 210 | Function::Function(FunctionType *Ty, LinkageTypes Linkage, |
Daniel Dunbar | 4975db6 | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 211 | const Twine &name, Module *ParentModule) |
Michael Ilseman | acdb76d | 2012-12-17 20:37:55 +0000 | [diff] [blame] | 212 | : GlobalValue(PointerType::getUnqual(Ty), |
Chris Lattner | 8a923e7 | 2008-03-12 17:45:29 +0000 | [diff] [blame] | 213 | Value::FunctionVal, 0, 0, Linkage, name) { |
Chris Lattner | 654695b | 2009-01-05 07:58:59 +0000 | [diff] [blame] | 214 | assert(FunctionType::isValidReturnType(getReturnType()) && |
Chris Lattner | b1ed91f | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 215 | "invalid return type"); |
Reid Spencer | 3aaaa0b | 2007-02-05 20:47:22 +0000 | [diff] [blame] | 216 | SymTab = new ValueSymbolTable(); |
Chris Lattner | 6213ae0 | 2002-09-06 20:46:32 +0000 | [diff] [blame] | 217 | |
Chris Lattner | e2de908 | 2007-08-18 06:14:52 +0000 | [diff] [blame] | 218 | // If the function has arguments, mark them as lazily built. |
| 219 | if (Ty->getNumParams()) |
Chris Lattner | b9c8651 | 2009-12-29 02:14:09 +0000 | [diff] [blame] | 220 | setValueSubclassData(1); // Set the "has lazy arguments" bit. |
Michael Ilseman | acdb76d | 2012-12-17 20:37:55 +0000 | [diff] [blame] | 221 | |
Chris Lattner | 184b298 | 2002-09-08 18:59:35 +0000 | [diff] [blame] | 222 | // Make sure that we get added to a function |
| 223 | LeakDetector::addGarbageObject(this); |
| 224 | |
Chris Lattner | 6213ae0 | 2002-09-06 20:46:32 +0000 | [diff] [blame] | 225 | if (ParentModule) |
| 226 | ParentModule->getFunctionList().push_back(this); |
Duncan Sands | a8ff6ca | 2008-04-07 13:39:11 +0000 | [diff] [blame] | 227 | |
| 228 | // Ensure intrinsics have the right parameter attributes. |
Dale Johannesen | b842d52 | 2009-02-05 01:49:45 +0000 | [diff] [blame] | 229 | if (unsigned IID = getIntrinsicID()) |
Bill Wendling | d079a44 | 2012-10-15 04:46:55 +0000 | [diff] [blame] | 230 | setAttributes(Intrinsic::getAttributes(getContext(), Intrinsic::ID(IID))); |
Devang Patel | d334a43 | 2008-09-02 20:51:15 +0000 | [diff] [blame] | 231 | |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 232 | } |
| 233 | |
Gordon Henriksen | 14a5569 | 2007-12-10 02:14:30 +0000 | [diff] [blame] | 234 | Function::~Function() { |
| 235 | dropAllReferences(); // After this it is safe to delete instructions. |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 236 | |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 237 | // Delete all of the method arguments and unlink from symbol table... |
Gordon Henriksen | 14a5569 | 2007-12-10 02:14:30 +0000 | [diff] [blame] | 238 | ArgumentList.clear(); |
| 239 | delete SymTab; |
Reid Spencer | c6a8384 | 2007-04-22 17:28:03 +0000 | [diff] [blame] | 240 | |
Gordon Henriksen | d930f91 | 2008-08-17 18:44:35 +0000 | [diff] [blame] | 241 | // Remove the function from the on-the-side GC table. |
| 242 | clearGC(); |
Michael Ilseman | 516d703 | 2013-03-01 18:48:54 +0000 | [diff] [blame] | 243 | |
| 244 | // Remove the intrinsicID from the Cache. |
Chris Lattner | f83a664 | 2013-03-20 21:04:53 +0000 | [diff] [blame] | 245 | if (getValueName() && isIntrinsic()) |
Michael Ilseman | 516d703 | 2013-03-01 18:48:54 +0000 | [diff] [blame] | 246 | getContext().pImpl->IntrinsicIDCache.erase(this); |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 247 | } |
| 248 | |
Chris Lattner | e2de908 | 2007-08-18 06:14:52 +0000 | [diff] [blame] | 249 | void Function::BuildLazyArguments() const { |
| 250 | // Create the arguments vector, all arguments start out unnamed. |
Chris Lattner | 229907c | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 251 | FunctionType *FT = getFunctionType(); |
Chris Lattner | e2de908 | 2007-08-18 06:14:52 +0000 | [diff] [blame] | 252 | for (unsigned i = 0, e = FT->getNumParams(); i != e; ++i) { |
Benjamin Kramer | ccce8ba | 2010-01-05 13:12:22 +0000 | [diff] [blame] | 253 | assert(!FT->getParamType(i)->isVoidTy() && |
Chris Lattner | e2de908 | 2007-08-18 06:14:52 +0000 | [diff] [blame] | 254 | "Cannot have void typed arguments!"); |
| 255 | ArgumentList.push_back(new Argument(FT->getParamType(i))); |
| 256 | } |
Michael Ilseman | acdb76d | 2012-12-17 20:37:55 +0000 | [diff] [blame] | 257 | |
Chris Lattner | e2de908 | 2007-08-18 06:14:52 +0000 | [diff] [blame] | 258 | // Clear the lazy arguments bit. |
Chris Lattner | b9c8651 | 2009-12-29 02:14:09 +0000 | [diff] [blame] | 259 | unsigned SDC = getSubclassDataFromValue(); |
| 260 | const_cast<Function*>(this)->setValueSubclassData(SDC &= ~1); |
Chris Lattner | e2de908 | 2007-08-18 06:14:52 +0000 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | size_t Function::arg_size() const { |
| 264 | return getFunctionType()->getNumParams(); |
| 265 | } |
| 266 | bool Function::arg_empty() const { |
| 267 | return getFunctionType()->getNumParams() == 0; |
| 268 | } |
| 269 | |
Chris Lattner | 4e8c487 | 2002-03-23 22:51:58 +0000 | [diff] [blame] | 270 | void Function::setParent(Module *parent) { |
Chris Lattner | 184b298 | 2002-09-08 18:59:35 +0000 | [diff] [blame] | 271 | if (getParent()) |
| 272 | LeakDetector::addGarbageObject(this); |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 273 | Parent = parent; |
Chris Lattner | 184b298 | 2002-09-08 18:59:35 +0000 | [diff] [blame] | 274 | if (getParent()) |
| 275 | LeakDetector::removeGarbageObject(this); |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 276 | } |
| 277 | |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 278 | // dropAllReferences() - This function causes all the subinstructions to "let |
| 279 | // go" of all references that they are maintaining. This allows one to |
| 280 | // 'delete' a whole class at a time, even though there may be circular |
| 281 | // references... first all references are dropped, and all use counts go to |
Misha Brukman | fa10053 | 2003-10-10 17:54:14 +0000 | [diff] [blame] | 282 | // zero. Then everything is deleted for real. Note that no operations are |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 283 | // valid on an object that has "dropped all references", except operator |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 284 | // delete. |
| 285 | // |
Chris Lattner | 4e8c487 | 2002-03-23 22:51:58 +0000 | [diff] [blame] | 286 | void Function::dropAllReferences() { |
Chris Lattner | 113f4f4 | 2002-06-25 16:13:24 +0000 | [diff] [blame] | 287 | for (iterator I = begin(), E = end(); I != E; ++I) |
| 288 | I->dropAllReferences(); |
Michael Ilseman | acdb76d | 2012-12-17 20:37:55 +0000 | [diff] [blame] | 289 | |
Dan Gohman | f844b3b | 2010-12-07 19:56:51 +0000 | [diff] [blame] | 290 | // Delete all basic blocks. They are now unused, except possibly by |
| 291 | // blockaddresses, but BasicBlock's destructor takes care of those. |
| 292 | while (!BasicBlocks.empty()) |
| 293 | BasicBlocks.begin()->eraseFromParent(); |
Peter Collingbourne | 3fa50f9 | 2013-09-16 01:08:15 +0000 | [diff] [blame] | 294 | |
| 295 | // Prefix data is stored in a side table. |
| 296 | setPrefixData(0); |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 297 | } |
Chris Lattner | da97550 | 2001-09-10 07:58:01 +0000 | [diff] [blame] | 298 | |
Bill Wendling | c0e2a1f | 2013-01-23 00:20:53 +0000 | [diff] [blame] | 299 | void Function::addAttribute(unsigned i, Attribute::AttrKind attr) { |
Bill Wendling | e94d843 | 2012-12-07 23:16:57 +0000 | [diff] [blame] | 300 | AttributeSet PAL = getAttributes(); |
Bill Wendling | c0e2a1f | 2013-01-23 00:20:53 +0000 | [diff] [blame] | 301 | PAL = PAL.addAttribute(getContext(), i, attr); |
Devang Patel | 4c758ea | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 302 | setAttributes(PAL); |
Eric Christopher | 901b1a7 | 2008-05-16 20:39:43 +0000 | [diff] [blame] | 303 | } |
| 304 | |
Bill Wendling | c0e2a1f | 2013-01-23 00:20:53 +0000 | [diff] [blame] | 305 | void Function::addAttributes(unsigned i, AttributeSet attrs) { |
Bill Wendling | e94d843 | 2012-12-07 23:16:57 +0000 | [diff] [blame] | 306 | AttributeSet PAL = getAttributes(); |
Bill Wendling | c0e2a1f | 2013-01-23 00:20:53 +0000 | [diff] [blame] | 307 | PAL = PAL.addAttributes(getContext(), i, attrs); |
| 308 | setAttributes(PAL); |
| 309 | } |
| 310 | |
Bill Wendling | 430fa9b | 2013-01-23 00:45:55 +0000 | [diff] [blame] | 311 | void Function::removeAttributes(unsigned i, AttributeSet attrs) { |
Bill Wendling | c0e2a1f | 2013-01-23 00:20:53 +0000 | [diff] [blame] | 312 | AttributeSet PAL = getAttributes(); |
Bill Wendling | 430fa9b | 2013-01-23 00:45:55 +0000 | [diff] [blame] | 313 | PAL = PAL.removeAttributes(getContext(), i, attrs); |
Devang Patel | 4c758ea | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 314 | setAttributes(PAL); |
Duncan Sands | 66336db | 2008-07-08 09:41:30 +0000 | [diff] [blame] | 315 | } |
| 316 | |
Gordon Henriksen | d930f91 | 2008-08-17 18:44:35 +0000 | [diff] [blame] | 317 | // Maintain the GC name for each function in an on-the-side table. This saves |
| 318 | // allocating an additional word in Function for programs which do not use GC |
| 319 | // (i.e., most programs) at the cost of increased overhead for clients which do |
| 320 | // use GC. |
Owen Anderson | ed14e76 | 2009-06-17 23:49:06 +0000 | [diff] [blame] | 321 | static DenseMap<const Function*,PooledStringPtr> *GCNames; |
| 322 | static StringPool *GCNamePool; |
Owen Anderson | 7f1ef67 | 2009-06-18 20:56:48 +0000 | [diff] [blame] | 323 | static ManagedStatic<sys::SmartRWMutex<true> > GCLock; |
Gordon Henriksen | 71183b6 | 2007-12-10 03:18:06 +0000 | [diff] [blame] | 324 | |
Gordon Henriksen | d930f91 | 2008-08-17 18:44:35 +0000 | [diff] [blame] | 325 | bool Function::hasGC() const { |
Owen Anderson | 5c96ef7 | 2009-07-07 18:33:04 +0000 | [diff] [blame] | 326 | sys::SmartScopedReader<true> Reader(*GCLock); |
Owen Anderson | 7f1ef67 | 2009-06-18 20:56:48 +0000 | [diff] [blame] | 327 | return GCNames && GCNames->count(this); |
Gordon Henriksen | 71183b6 | 2007-12-10 03:18:06 +0000 | [diff] [blame] | 328 | } |
| 329 | |
Gordon Henriksen | d930f91 | 2008-08-17 18:44:35 +0000 | [diff] [blame] | 330 | const char *Function::getGC() const { |
| 331 | assert(hasGC() && "Function has no collector"); |
Owen Anderson | 5c96ef7 | 2009-07-07 18:33:04 +0000 | [diff] [blame] | 332 | sys::SmartScopedReader<true> Reader(*GCLock); |
Owen Anderson | 7f1ef67 | 2009-06-18 20:56:48 +0000 | [diff] [blame] | 333 | return *(*GCNames)[this]; |
Gordon Henriksen | 71183b6 | 2007-12-10 03:18:06 +0000 | [diff] [blame] | 334 | } |
| 335 | |
Gordon Henriksen | d930f91 | 2008-08-17 18:44:35 +0000 | [diff] [blame] | 336 | void Function::setGC(const char *Str) { |
Owen Anderson | 5c96ef7 | 2009-07-07 18:33:04 +0000 | [diff] [blame] | 337 | sys::SmartScopedWriter<true> Writer(*GCLock); |
Owen Anderson | ed14e76 | 2009-06-17 23:49:06 +0000 | [diff] [blame] | 338 | if (!GCNamePool) |
| 339 | GCNamePool = new StringPool(); |
| 340 | if (!GCNames) |
| 341 | GCNames = new DenseMap<const Function*,PooledStringPtr>(); |
| 342 | (*GCNames)[this] = GCNamePool->intern(Str); |
Gordon Henriksen | 71183b6 | 2007-12-10 03:18:06 +0000 | [diff] [blame] | 343 | } |
| 344 | |
Gordon Henriksen | d930f91 | 2008-08-17 18:44:35 +0000 | [diff] [blame] | 345 | void Function::clearGC() { |
Owen Anderson | 5c96ef7 | 2009-07-07 18:33:04 +0000 | [diff] [blame] | 346 | sys::SmartScopedWriter<true> Writer(*GCLock); |
Owen Anderson | ed14e76 | 2009-06-17 23:49:06 +0000 | [diff] [blame] | 347 | if (GCNames) { |
Gordon Henriksen | d930f91 | 2008-08-17 18:44:35 +0000 | [diff] [blame] | 348 | GCNames->erase(this); |
Owen Anderson | ed14e76 | 2009-06-17 23:49:06 +0000 | [diff] [blame] | 349 | if (GCNames->empty()) { |
| 350 | delete GCNames; |
| 351 | GCNames = 0; |
| 352 | if (GCNamePool->empty()) { |
| 353 | delete GCNamePool; |
| 354 | GCNamePool = 0; |
| 355 | } |
| 356 | } |
| 357 | } |
Gordon Henriksen | 71183b6 | 2007-12-10 03:18:06 +0000 | [diff] [blame] | 358 | } |
| 359 | |
Duncan Sands | dd7daee | 2008-05-26 19:58:59 +0000 | [diff] [blame] | 360 | /// copyAttributesFrom - copy all additional attributes (those not needed to |
| 361 | /// create a Function) from the Function Src to this one. |
| 362 | void Function::copyAttributesFrom(const GlobalValue *Src) { |
| 363 | assert(isa<Function>(Src) && "Expected a Function!"); |
| 364 | GlobalValue::copyAttributesFrom(Src); |
| 365 | const Function *SrcF = cast<Function>(Src); |
| 366 | setCallingConv(SrcF->getCallingConv()); |
Devang Patel | 4c758ea | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 367 | setAttributes(SrcF->getAttributes()); |
Gordon Henriksen | d930f91 | 2008-08-17 18:44:35 +0000 | [diff] [blame] | 368 | if (SrcF->hasGC()) |
| 369 | setGC(SrcF->getGC()); |
| 370 | else |
| 371 | clearGC(); |
Peter Collingbourne | 3fa50f9 | 2013-09-16 01:08:15 +0000 | [diff] [blame] | 372 | if (SrcF->hasPrefixData()) |
| 373 | setPrefixData(SrcF->getPrefixData()); |
| 374 | else |
| 375 | setPrefixData(0); |
Duncan Sands | dd7daee | 2008-05-26 19:58:59 +0000 | [diff] [blame] | 376 | } |
| 377 | |
Chris Lattner | bb346d0 | 2003-05-08 03:47:33 +0000 | [diff] [blame] | 378 | /// getIntrinsicID - This method returns the ID number of the specified |
Brian Gaeke | 960707c | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 379 | /// function, or Intrinsic::not_intrinsic if the function is not an |
Misha Brukman | fa10053 | 2003-10-10 17:54:14 +0000 | [diff] [blame] | 380 | /// intrinsic, or if the pointer is null. This value is always defined to be |
Chris Lattner | bb346d0 | 2003-05-08 03:47:33 +0000 | [diff] [blame] | 381 | /// zero to allow easy checking for whether a function is intrinsic or not. The |
| 382 | /// particular intrinsic functions which correspond to this value are defined in |
Michael Ilseman | 516d703 | 2013-03-01 18:48:54 +0000 | [diff] [blame] | 383 | /// llvm/Intrinsics.h. Results are cached in the LLVM context, subsequent |
| 384 | /// requests for the same ID return results much faster from the cache. |
Chris Lattner | bb346d0 | 2003-05-08 03:47:33 +0000 | [diff] [blame] | 385 | /// |
Dale Johannesen | b842d52 | 2009-02-05 01:49:45 +0000 | [diff] [blame] | 386 | unsigned Function::getIntrinsicID() const { |
Chris Lattner | 1e92e06 | 2007-02-15 19:17:16 +0000 | [diff] [blame] | 387 | const ValueName *ValName = this->getValueName(); |
Michael Ilseman | b99f80d | 2012-12-19 23:17:20 +0000 | [diff] [blame] | 388 | if (!ValName || !isIntrinsic()) |
Reid Spencer | c5f397a | 2007-04-16 07:08:44 +0000 | [diff] [blame] | 389 | return 0; |
Michael Ilseman | 516d703 | 2013-03-01 18:48:54 +0000 | [diff] [blame] | 390 | |
| 391 | LLVMContextImpl::IntrinsicIDCacheTy &IntrinsicIDCache = |
| 392 | getContext().pImpl->IntrinsicIDCache; |
Chris Lattner | f83a664 | 2013-03-20 21:04:53 +0000 | [diff] [blame] | 393 | if (!IntrinsicIDCache.count(this)) { |
Michael Ilseman | 516d703 | 2013-03-01 18:48:54 +0000 | [diff] [blame] | 394 | unsigned Id = lookupIntrinsicID(); |
| 395 | IntrinsicIDCache[this]=Id; |
| 396 | return Id; |
| 397 | } |
| 398 | return IntrinsicIDCache[this]; |
| 399 | } |
| 400 | |
| 401 | /// This private method does the actual lookup of an intrinsic ID when the query |
| 402 | /// could not be answered from the cache. |
| 403 | unsigned Function::lookupIntrinsicID() const { |
| 404 | const ValueName *ValName = this->getValueName(); |
Chris Lattner | 1e92e06 | 2007-02-15 19:17:16 +0000 | [diff] [blame] | 405 | unsigned Len = ValName->getKeyLength(); |
| 406 | const char *Name = ValName->getKeyData(); |
Michael Ilseman | acdb76d | 2012-12-17 20:37:55 +0000 | [diff] [blame] | 407 | |
Chris Lattner | ff4d4ee | 2006-03-09 20:35:01 +0000 | [diff] [blame] | 408 | #define GET_FUNCTION_RECOGNIZER |
Chandler Carruth | db25c6c | 2013-01-02 12:09:16 +0000 | [diff] [blame] | 409 | #include "llvm/IR/Intrinsics.gen" |
Chris Lattner | ff4d4ee | 2006-03-09 20:35:01 +0000 | [diff] [blame] | 410 | #undef GET_FUNCTION_RECOGNIZER |
Michael Ilseman | 516d703 | 2013-03-01 18:48:54 +0000 | [diff] [blame] | 411 | |
Chris Lattner | bb346d0 | 2003-05-08 03:47:33 +0000 | [diff] [blame] | 412 | return 0; |
| 413 | } |
| 414 | |
Benjamin Kramer | e6e1933 | 2011-07-14 17:45:39 +0000 | [diff] [blame] | 415 | std::string Intrinsic::getName(ID id, ArrayRef<Type*> Tys) { |
Chris Lattner | 71b8c98 | 2006-03-25 06:32:47 +0000 | [diff] [blame] | 416 | assert(id < num_intrinsics && "Invalid intrinsic ID!"); |
Chris Lattner | f5ba041 | 2011-04-25 22:14:33 +0000 | [diff] [blame] | 417 | static const char * const Table[] = { |
Chris Lattner | 71b8c98 | 2006-03-25 06:32:47 +0000 | [diff] [blame] | 418 | "not_intrinsic", |
| 419 | #define GET_INTRINSIC_NAME_TABLE |
Chandler Carruth | db25c6c | 2013-01-02 12:09:16 +0000 | [diff] [blame] | 420 | #include "llvm/IR/Intrinsics.gen" |
Chris Lattner | 71b8c98 | 2006-03-25 06:32:47 +0000 | [diff] [blame] | 421 | #undef GET_INTRINSIC_NAME_TABLE |
| 422 | }; |
Benjamin Kramer | e6e1933 | 2011-07-14 17:45:39 +0000 | [diff] [blame] | 423 | if (Tys.empty()) |
Reid Spencer | 2a2117c | 2007-04-01 07:25:33 +0000 | [diff] [blame] | 424 | return Table[id]; |
| 425 | std::string Result(Table[id]); |
Benjamin Kramer | e6e1933 | 2011-07-14 17:45:39 +0000 | [diff] [blame] | 426 | for (unsigned i = 0; i < Tys.size(); ++i) { |
Chris Lattner | 229907c | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 427 | if (PointerType* PTyp = dyn_cast<PointerType>(Tys[i])) { |
Michael Ilseman | acdb76d | 2012-12-17 20:37:55 +0000 | [diff] [blame] | 428 | Result += ".p" + llvm::utostr(PTyp->getAddressSpace()) + |
Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 429 | EVT::getEVT(PTyp->getElementType()).getEVTString(); |
Mon P Wang | 2c839d4 | 2008-07-30 04:36:53 +0000 | [diff] [blame] | 430 | } |
| 431 | else if (Tys[i]) |
Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 432 | Result += "." + EVT::getEVT(Tys[i]).getEVTString(); |
Mon P Wang | 2c839d4 | 2008-07-30 04:36:53 +0000 | [diff] [blame] | 433 | } |
Reid Spencer | 2a2117c | 2007-04-01 07:25:33 +0000 | [diff] [blame] | 434 | return Result; |
Chris Lattner | 71b8c98 | 2006-03-25 06:32:47 +0000 | [diff] [blame] | 435 | } |
| 436 | |
Chris Lattner | 7f0e7ba | 2012-05-16 06:34:44 +0000 | [diff] [blame] | 437 | |
Chris Lattner | f39c278 | 2012-05-27 18:28:35 +0000 | [diff] [blame] | 438 | /// IIT_Info - These are enumerators that describe the entries returned by the |
| 439 | /// getIntrinsicInfoTableEntries function. |
| 440 | /// |
| 441 | /// NOTE: This must be kept in synch with the copy in TblGen/IntrinsicEmitter! |
| 442 | enum IIT_Info { |
| 443 | // Common values should be encoded with 0-15. |
| 444 | IIT_Done = 0, |
| 445 | IIT_I1 = 1, |
| 446 | IIT_I8 = 2, |
| 447 | IIT_I16 = 3, |
| 448 | IIT_I32 = 4, |
| 449 | IIT_I64 = 5, |
Michael Ilseman | 6c6d715 | 2013-01-11 01:45:05 +0000 | [diff] [blame] | 450 | IIT_F16 = 6, |
| 451 | IIT_F32 = 7, |
| 452 | IIT_F64 = 8, |
| 453 | IIT_V2 = 9, |
| 454 | IIT_V4 = 10, |
| 455 | IIT_V8 = 11, |
| 456 | IIT_V16 = 12, |
| 457 | IIT_V32 = 13, |
Chris Lattner | f39c278 | 2012-05-27 18:28:35 +0000 | [diff] [blame] | 458 | IIT_PTR = 14, |
| 459 | IIT_ARG = 15, |
Michael Ilseman | acdb76d | 2012-12-17 20:37:55 +0000 | [diff] [blame] | 460 | |
Chris Lattner | f39c278 | 2012-05-27 18:28:35 +0000 | [diff] [blame] | 461 | // Values from 16+ are only encodable with the inefficient encoding. |
Michael Ilseman | 6c6d715 | 2013-01-11 01:45:05 +0000 | [diff] [blame] | 462 | IIT_MMX = 16, |
| 463 | IIT_METADATA = 17, |
| 464 | IIT_EMPTYSTRUCT = 18, |
| 465 | IIT_STRUCT2 = 19, |
| 466 | IIT_STRUCT3 = 20, |
| 467 | IIT_STRUCT4 = 21, |
| 468 | IIT_STRUCT5 = 22, |
| 469 | IIT_EXTEND_VEC_ARG = 23, |
| 470 | IIT_TRUNC_VEC_ARG = 24, |
Jiangning Liu | 63dc840 | 2013-09-24 02:47:27 +0000 | [diff] [blame] | 471 | IIT_ANYPTR = 25, |
Andrew Trick | a2efd99 | 2013-10-31 17:18:11 +0000 | [diff] [blame] | 472 | IIT_V1 = 26, |
| 473 | IIT_VARARG = 27 |
Chris Lattner | f39c278 | 2012-05-27 18:28:35 +0000 | [diff] [blame] | 474 | }; |
| 475 | |
| 476 | |
| 477 | static void DecodeIITType(unsigned &NextElt, ArrayRef<unsigned char> Infos, |
| 478 | SmallVectorImpl<Intrinsic::IITDescriptor> &OutputTable) { |
Chris Lattner | a57c797 | 2012-05-17 05:13:57 +0000 | [diff] [blame] | 479 | IIT_Info Info = IIT_Info(Infos[NextElt++]); |
Chris Lattner | 3e34a7b | 2012-05-17 05:03:24 +0000 | [diff] [blame] | 480 | unsigned StructElts = 2; |
Chris Lattner | f39c278 | 2012-05-27 18:28:35 +0000 | [diff] [blame] | 481 | using namespace Intrinsic; |
Michael Ilseman | acdb76d | 2012-12-17 20:37:55 +0000 | [diff] [blame] | 482 | |
Chris Lattner | a57c797 | 2012-05-17 05:13:57 +0000 | [diff] [blame] | 483 | switch (Info) { |
Chris Lattner | f39c278 | 2012-05-27 18:28:35 +0000 | [diff] [blame] | 484 | case IIT_Done: |
| 485 | OutputTable.push_back(IITDescriptor::get(IITDescriptor::Void, 0)); |
| 486 | return; |
Andrew Trick | a2efd99 | 2013-10-31 17:18:11 +0000 | [diff] [blame] | 487 | case IIT_VARARG: |
| 488 | OutputTable.push_back(IITDescriptor::get(IITDescriptor::VarArg, 0)); |
| 489 | return; |
Chris Lattner | f39c278 | 2012-05-27 18:28:35 +0000 | [diff] [blame] | 490 | case IIT_MMX: |
| 491 | OutputTable.push_back(IITDescriptor::get(IITDescriptor::MMX, 0)); |
| 492 | return; |
| 493 | case IIT_METADATA: |
| 494 | OutputTable.push_back(IITDescriptor::get(IITDescriptor::Metadata, 0)); |
| 495 | return; |
Michael Ilseman | 6c6d715 | 2013-01-11 01:45:05 +0000 | [diff] [blame] | 496 | case IIT_F16: |
| 497 | OutputTable.push_back(IITDescriptor::get(IITDescriptor::Half, 0)); |
| 498 | return; |
Chris Lattner | f39c278 | 2012-05-27 18:28:35 +0000 | [diff] [blame] | 499 | case IIT_F32: |
| 500 | OutputTable.push_back(IITDescriptor::get(IITDescriptor::Float, 0)); |
| 501 | return; |
| 502 | case IIT_F64: |
| 503 | OutputTable.push_back(IITDescriptor::get(IITDescriptor::Double, 0)); |
| 504 | return; |
| 505 | case IIT_I1: |
| 506 | OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 1)); |
| 507 | return; |
| 508 | case IIT_I8: |
| 509 | OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 8)); |
| 510 | return; |
| 511 | case IIT_I16: |
| 512 | OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer,16)); |
| 513 | return; |
| 514 | case IIT_I32: |
| 515 | OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 32)); |
| 516 | return; |
| 517 | case IIT_I64: |
| 518 | OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 64)); |
| 519 | return; |
Jiangning Liu | 63dc840 | 2013-09-24 02:47:27 +0000 | [diff] [blame] | 520 | case IIT_V1: |
| 521 | OutputTable.push_back(IITDescriptor::get(IITDescriptor::Vector, 1)); |
| 522 | DecodeIITType(NextElt, Infos, OutputTable); |
| 523 | return; |
Chris Lattner | 827b253 | 2012-05-17 04:30:58 +0000 | [diff] [blame] | 524 | case IIT_V2: |
Chris Lattner | f39c278 | 2012-05-27 18:28:35 +0000 | [diff] [blame] | 525 | OutputTable.push_back(IITDescriptor::get(IITDescriptor::Vector, 2)); |
| 526 | DecodeIITType(NextElt, Infos, OutputTable); |
| 527 | return; |
Chris Lattner | 827b253 | 2012-05-17 04:30:58 +0000 | [diff] [blame] | 528 | case IIT_V4: |
Chris Lattner | f39c278 | 2012-05-27 18:28:35 +0000 | [diff] [blame] | 529 | OutputTable.push_back(IITDescriptor::get(IITDescriptor::Vector, 4)); |
| 530 | DecodeIITType(NextElt, Infos, OutputTable); |
| 531 | return; |
Chris Lattner | 827b253 | 2012-05-17 04:30:58 +0000 | [diff] [blame] | 532 | case IIT_V8: |
Chris Lattner | f39c278 | 2012-05-27 18:28:35 +0000 | [diff] [blame] | 533 | OutputTable.push_back(IITDescriptor::get(IITDescriptor::Vector, 8)); |
| 534 | DecodeIITType(NextElt, Infos, OutputTable); |
| 535 | return; |
Chris Lattner | 827b253 | 2012-05-17 04:30:58 +0000 | [diff] [blame] | 536 | case IIT_V16: |
Chris Lattner | f39c278 | 2012-05-27 18:28:35 +0000 | [diff] [blame] | 537 | OutputTable.push_back(IITDescriptor::get(IITDescriptor::Vector, 16)); |
| 538 | DecodeIITType(NextElt, Infos, OutputTable); |
| 539 | return; |
Chris Lattner | 3e34a7b | 2012-05-17 05:03:24 +0000 | [diff] [blame] | 540 | case IIT_V32: |
Chris Lattner | f39c278 | 2012-05-27 18:28:35 +0000 | [diff] [blame] | 541 | OutputTable.push_back(IITDescriptor::get(IITDescriptor::Vector, 32)); |
| 542 | DecodeIITType(NextElt, Infos, OutputTable); |
| 543 | return; |
Chris Lattner | 4f18aa8 | 2012-05-23 05:19:18 +0000 | [diff] [blame] | 544 | case IIT_PTR: |
Chris Lattner | f39c278 | 2012-05-27 18:28:35 +0000 | [diff] [blame] | 545 | OutputTable.push_back(IITDescriptor::get(IITDescriptor::Pointer, 0)); |
| 546 | DecodeIITType(NextElt, Infos, OutputTable); |
| 547 | return; |
Chris Lattner | 4f18aa8 | 2012-05-23 05:19:18 +0000 | [diff] [blame] | 548 | case IIT_ANYPTR: { // [ANYPTR addrspace, subtype] |
Michael Ilseman | acdb76d | 2012-12-17 20:37:55 +0000 | [diff] [blame] | 549 | OutputTable.push_back(IITDescriptor::get(IITDescriptor::Pointer, |
Chris Lattner | f39c278 | 2012-05-27 18:28:35 +0000 | [diff] [blame] | 550 | Infos[NextElt++])); |
| 551 | DecodeIITType(NextElt, Infos, OutputTable); |
| 552 | return; |
Pete Cooper | 243efd7 | 2012-05-21 23:21:28 +0000 | [diff] [blame] | 553 | } |
Chris Lattner | f39c278 | 2012-05-27 18:28:35 +0000 | [diff] [blame] | 554 | case IIT_ARG: { |
| 555 | unsigned ArgInfo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]); |
| 556 | OutputTable.push_back(IITDescriptor::get(IITDescriptor::Argument, ArgInfo)); |
| 557 | return; |
| 558 | } |
| 559 | case IIT_EXTEND_VEC_ARG: { |
| 560 | unsigned ArgInfo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]); |
| 561 | OutputTable.push_back(IITDescriptor::get(IITDescriptor::ExtendVecArgument, |
| 562 | ArgInfo)); |
| 563 | return; |
| 564 | } |
Chris Lattner | 3e34a7b | 2012-05-17 05:03:24 +0000 | [diff] [blame] | 565 | case IIT_TRUNC_VEC_ARG: { |
Chris Lattner | f39c278 | 2012-05-27 18:28:35 +0000 | [diff] [blame] | 566 | unsigned ArgInfo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]); |
| 567 | OutputTable.push_back(IITDescriptor::get(IITDescriptor::TruncVecArgument, |
| 568 | ArgInfo)); |
| 569 | return; |
Chris Lattner | 3e34a7b | 2012-05-17 05:03:24 +0000 | [diff] [blame] | 570 | } |
Chris Lattner | f39c278 | 2012-05-27 18:28:35 +0000 | [diff] [blame] | 571 | case IIT_EMPTYSTRUCT: |
| 572 | OutputTable.push_back(IITDescriptor::get(IITDescriptor::Struct, 0)); |
| 573 | return; |
Chris Lattner | 3e34a7b | 2012-05-17 05:03:24 +0000 | [diff] [blame] | 574 | case IIT_STRUCT5: ++StructElts; // FALL THROUGH. |
| 575 | case IIT_STRUCT4: ++StructElts; // FALL THROUGH. |
| 576 | case IIT_STRUCT3: ++StructElts; // FALL THROUGH. |
| 577 | case IIT_STRUCT2: { |
Chris Lattner | f39c278 | 2012-05-27 18:28:35 +0000 | [diff] [blame] | 578 | OutputTable.push_back(IITDescriptor::get(IITDescriptor::Struct,StructElts)); |
| 579 | |
Chris Lattner | 3e34a7b | 2012-05-17 05:03:24 +0000 | [diff] [blame] | 580 | for (unsigned i = 0; i != StructElts; ++i) |
Chris Lattner | f39c278 | 2012-05-27 18:28:35 +0000 | [diff] [blame] | 581 | DecodeIITType(NextElt, Infos, OutputTable); |
| 582 | return; |
Chris Lattner | 827b253 | 2012-05-17 04:30:58 +0000 | [diff] [blame] | 583 | } |
Chris Lattner | 7f0e7ba | 2012-05-16 06:34:44 +0000 | [diff] [blame] | 584 | } |
| 585 | llvm_unreachable("unhandled"); |
| 586 | } |
Chris Lattner | 7f0e7ba | 2012-05-16 06:34:44 +0000 | [diff] [blame] | 587 | |
Chris Lattner | f39c278 | 2012-05-27 18:28:35 +0000 | [diff] [blame] | 588 | |
| 589 | #define GET_INTRINSIC_GENERATOR_GLOBAL |
Chandler Carruth | db25c6c | 2013-01-02 12:09:16 +0000 | [diff] [blame] | 590 | #include "llvm/IR/Intrinsics.gen" |
Chris Lattner | f39c278 | 2012-05-27 18:28:35 +0000 | [diff] [blame] | 591 | #undef GET_INTRINSIC_GENERATOR_GLOBAL |
| 592 | |
Michael Ilseman | acdb76d | 2012-12-17 20:37:55 +0000 | [diff] [blame] | 593 | void Intrinsic::getIntrinsicInfoTableEntries(ID id, |
Chris Lattner | f39c278 | 2012-05-27 18:28:35 +0000 | [diff] [blame] | 594 | SmallVectorImpl<IITDescriptor> &T){ |
Chris Lattner | 7f0e7ba | 2012-05-16 06:34:44 +0000 | [diff] [blame] | 595 | // Check to see if the intrinsic's type was expressible by the table. |
| 596 | unsigned TableVal = IIT_Table[id-1]; |
Michael Ilseman | acdb76d | 2012-12-17 20:37:55 +0000 | [diff] [blame] | 597 | |
Chris Lattner | a3b0f52 | 2012-05-17 15:55:41 +0000 | [diff] [blame] | 598 | // Decode the TableVal into an array of IITValues. |
| 599 | SmallVector<unsigned char, 8> IITValues; |
| 600 | ArrayRef<unsigned char> IITEntries; |
| 601 | unsigned NextElt = 0; |
| 602 | if ((TableVal >> 31) != 0) { |
| 603 | // This is an offset into the IIT_LongEncodingTable. |
| 604 | IITEntries = IIT_LongEncodingTable; |
Michael Ilseman | acdb76d | 2012-12-17 20:37:55 +0000 | [diff] [blame] | 605 | |
Chris Lattner | a3b0f52 | 2012-05-17 15:55:41 +0000 | [diff] [blame] | 606 | // Strip sentinel bit. |
| 607 | NextElt = (TableVal << 1) >> 1; |
| 608 | } else { |
Chris Lattner | f39c278 | 2012-05-27 18:28:35 +0000 | [diff] [blame] | 609 | // Decode the TableVal into an array of IITValues. If the entry was encoded |
| 610 | // into a single word in the table itself, decode it now. |
Chris Lattner | a57c797 | 2012-05-17 05:13:57 +0000 | [diff] [blame] | 611 | do { |
| 612 | IITValues.push_back(TableVal & 0xF); |
| 613 | TableVal >>= 4; |
| 614 | } while (TableVal); |
Michael Ilseman | acdb76d | 2012-12-17 20:37:55 +0000 | [diff] [blame] | 615 | |
Chris Lattner | a3b0f52 | 2012-05-17 15:55:41 +0000 | [diff] [blame] | 616 | IITEntries = IITValues; |
| 617 | NextElt = 0; |
Chris Lattner | 7f0e7ba | 2012-05-16 06:34:44 +0000 | [diff] [blame] | 618 | } |
Chris Lattner | f39c278 | 2012-05-27 18:28:35 +0000 | [diff] [blame] | 619 | |
| 620 | // Okay, decode the table into the output vector of IITDescriptors. |
| 621 | DecodeIITType(NextElt, IITEntries, T); |
| 622 | while (NextElt != IITEntries.size() && IITEntries[NextElt] != 0) |
| 623 | DecodeIITType(NextElt, IITEntries, T); |
| 624 | } |
| 625 | |
| 626 | |
| 627 | static Type *DecodeFixedType(ArrayRef<Intrinsic::IITDescriptor> &Infos, |
| 628 | ArrayRef<Type*> Tys, LLVMContext &Context) { |
| 629 | using namespace Intrinsic; |
| 630 | IITDescriptor D = Infos.front(); |
| 631 | Infos = Infos.slice(1); |
Michael Ilseman | acdb76d | 2012-12-17 20:37:55 +0000 | [diff] [blame] | 632 | |
Chris Lattner | f39c278 | 2012-05-27 18:28:35 +0000 | [diff] [blame] | 633 | switch (D.Kind) { |
| 634 | case IITDescriptor::Void: return Type::getVoidTy(Context); |
Andrew Trick | a2efd99 | 2013-10-31 17:18:11 +0000 | [diff] [blame] | 635 | case IITDescriptor::VarArg: return Type::getVoidTy(Context); |
Chris Lattner | f39c278 | 2012-05-27 18:28:35 +0000 | [diff] [blame] | 636 | case IITDescriptor::MMX: return Type::getX86_MMXTy(Context); |
| 637 | case IITDescriptor::Metadata: return Type::getMetadataTy(Context); |
Michael Ilseman | 6c6d715 | 2013-01-11 01:45:05 +0000 | [diff] [blame] | 638 | case IITDescriptor::Half: return Type::getHalfTy(Context); |
Chris Lattner | f39c278 | 2012-05-27 18:28:35 +0000 | [diff] [blame] | 639 | case IITDescriptor::Float: return Type::getFloatTy(Context); |
| 640 | case IITDescriptor::Double: return Type::getDoubleTy(Context); |
Michael Ilseman | acdb76d | 2012-12-17 20:37:55 +0000 | [diff] [blame] | 641 | |
Chris Lattner | f39c278 | 2012-05-27 18:28:35 +0000 | [diff] [blame] | 642 | case IITDescriptor::Integer: |
| 643 | return IntegerType::get(Context, D.Integer_Width); |
| 644 | case IITDescriptor::Vector: |
| 645 | return VectorType::get(DecodeFixedType(Infos, Tys, Context),D.Vector_Width); |
| 646 | case IITDescriptor::Pointer: |
| 647 | return PointerType::get(DecodeFixedType(Infos, Tys, Context), |
| 648 | D.Pointer_AddressSpace); |
| 649 | case IITDescriptor::Struct: { |
| 650 | Type *Elts[5]; |
| 651 | assert(D.Struct_NumElements <= 5 && "Can't handle this yet"); |
| 652 | for (unsigned i = 0, e = D.Struct_NumElements; i != e; ++i) |
| 653 | Elts[i] = DecodeFixedType(Infos, Tys, Context); |
| 654 | return StructType::get(Context, ArrayRef<Type*>(Elts,D.Struct_NumElements)); |
| 655 | } |
| 656 | |
| 657 | case IITDescriptor::Argument: |
| 658 | return Tys[D.getArgumentNumber()]; |
| 659 | case IITDescriptor::ExtendVecArgument: |
| 660 | return VectorType::getExtendedElementVectorType(cast<VectorType>( |
| 661 | Tys[D.getArgumentNumber()])); |
Michael Ilseman | acdb76d | 2012-12-17 20:37:55 +0000 | [diff] [blame] | 662 | |
Chris Lattner | f39c278 | 2012-05-27 18:28:35 +0000 | [diff] [blame] | 663 | case IITDescriptor::TruncVecArgument: |
| 664 | return VectorType::getTruncatedElementVectorType(cast<VectorType>( |
| 665 | Tys[D.getArgumentNumber()])); |
| 666 | } |
| 667 | llvm_unreachable("unhandled"); |
| 668 | } |
| 669 | |
| 670 | |
| 671 | |
| 672 | FunctionType *Intrinsic::getType(LLVMContext &Context, |
| 673 | ID id, ArrayRef<Type*> Tys) { |
| 674 | SmallVector<IITDescriptor, 8> Table; |
| 675 | getIntrinsicInfoTableEntries(id, Table); |
Michael Ilseman | acdb76d | 2012-12-17 20:37:55 +0000 | [diff] [blame] | 676 | |
Chris Lattner | f39c278 | 2012-05-27 18:28:35 +0000 | [diff] [blame] | 677 | ArrayRef<IITDescriptor> TableRef = Table; |
| 678 | Type *ResultTy = DecodeFixedType(TableRef, Tys, Context); |
Michael Ilseman | acdb76d | 2012-12-17 20:37:55 +0000 | [diff] [blame] | 679 | |
Chris Lattner | a3b0f52 | 2012-05-17 15:55:41 +0000 | [diff] [blame] | 680 | SmallVector<Type*, 8> ArgTys; |
Chris Lattner | f39c278 | 2012-05-27 18:28:35 +0000 | [diff] [blame] | 681 | while (!TableRef.empty()) |
| 682 | ArgTys.push_back(DecodeFixedType(TableRef, Tys, Context)); |
Jim Laskey | 2682ea6 | 2007-02-07 20:38:26 +0000 | [diff] [blame] | 683 | |
Michael Ilseman | acdb76d | 2012-12-17 20:37:55 +0000 | [diff] [blame] | 684 | return FunctionType::get(ResultTy, ArgTys, false); |
Jim Laskey | 2682ea6 | 2007-02-07 20:38:26 +0000 | [diff] [blame] | 685 | } |
| 686 | |
Mon P Wang | b402493 | 2009-02-24 23:17:49 +0000 | [diff] [blame] | 687 | bool Intrinsic::isOverloaded(ID id) { |
Mon P Wang | b402493 | 2009-02-24 23:17:49 +0000 | [diff] [blame] | 688 | #define GET_INTRINSIC_OVERLOAD_TABLE |
Chandler Carruth | db25c6c | 2013-01-02 12:09:16 +0000 | [diff] [blame] | 689 | #include "llvm/IR/Intrinsics.gen" |
Mon P Wang | b402493 | 2009-02-24 23:17:49 +0000 | [diff] [blame] | 690 | #undef GET_INTRINSIC_OVERLOAD_TABLE |
Mon P Wang | b402493 | 2009-02-24 23:17:49 +0000 | [diff] [blame] | 691 | } |
| 692 | |
Chris Lattner | 49b7ee1 | 2009-01-12 01:18:58 +0000 | [diff] [blame] | 693 | /// This defines the "Intrinsic::getAttributes(ID id)" method. |
Duncan Sands | 38ef3a8 | 2007-12-03 20:06:50 +0000 | [diff] [blame] | 694 | #define GET_INTRINSIC_ATTRIBUTES |
Chandler Carruth | db25c6c | 2013-01-02 12:09:16 +0000 | [diff] [blame] | 695 | #include "llvm/IR/Intrinsics.gen" |
Duncan Sands | 38ef3a8 | 2007-12-03 20:06:50 +0000 | [diff] [blame] | 696 | #undef GET_INTRINSIC_ATTRIBUTES |
| 697 | |
Benjamin Kramer | e6e1933 | 2011-07-14 17:45:39 +0000 | [diff] [blame] | 698 | Function *Intrinsic::getDeclaration(Module *M, ID id, ArrayRef<Type*> Tys) { |
Duncan Sands | 38ef3a8 | 2007-12-03 20:06:50 +0000 | [diff] [blame] | 699 | // There can never be multiple globals with the same name of different types, |
| 700 | // because intrinsics must be a specific type. |
Duncan Sands | a8ff6ca | 2008-04-07 13:39:11 +0000 | [diff] [blame] | 701 | return |
Benjamin Kramer | e6e1933 | 2011-07-14 17:45:39 +0000 | [diff] [blame] | 702 | cast<Function>(M->getOrInsertFunction(getName(id, Tys), |
| 703 | getType(M->getContext(), id, Tys))); |
Jim Laskey | 2682ea6 | 2007-02-07 20:38:26 +0000 | [diff] [blame] | 704 | } |
| 705 | |
Dale Johannesen | b842d52 | 2009-02-05 01:49:45 +0000 | [diff] [blame] | 706 | // This defines the "Intrinsic::getIntrinsicForGCCBuiltin()" method. |
| 707 | #define GET_LLVM_INTRINSIC_FOR_GCC_BUILTIN |
Chandler Carruth | db25c6c | 2013-01-02 12:09:16 +0000 | [diff] [blame] | 708 | #include "llvm/IR/Intrinsics.gen" |
Dale Johannesen | b842d52 | 2009-02-05 01:49:45 +0000 | [diff] [blame] | 709 | #undef GET_LLVM_INTRINSIC_FOR_GCC_BUILTIN |
| 710 | |
Gabor Greif | 161cb04 | 2010-03-23 14:40:20 +0000 | [diff] [blame] | 711 | /// hasAddressTaken - returns true if there are any uses of this function |
| 712 | /// other than direct calls or invokes to it. |
Gabor Greif | a2fbc0a | 2010-03-24 13:21:49 +0000 | [diff] [blame] | 713 | bool Function::hasAddressTaken(const User* *PutOffender) const { |
Gabor Greif | c78d720 | 2010-03-25 23:06:16 +0000 | [diff] [blame] | 714 | for (Value::const_use_iterator I = use_begin(), E = use_end(); I != E; ++I) { |
Gabor Greif | a2fbc0a | 2010-03-24 13:21:49 +0000 | [diff] [blame] | 715 | const User *U = *I; |
Jay Foad | ca0c499 | 2012-05-12 08:30:16 +0000 | [diff] [blame] | 716 | if (isa<BlockAddress>(U)) |
| 717 | continue; |
Gabor Greif | a2fbc0a | 2010-03-24 13:21:49 +0000 | [diff] [blame] | 718 | if (!isa<CallInst>(U) && !isa<InvokeInst>(U)) |
| 719 | return PutOffender ? (*PutOffender = U, true) : true; |
Gabor Greif | 5d5db53 | 2010-04-01 08:21:08 +0000 | [diff] [blame] | 720 | ImmutableCallSite CS(cast<Instruction>(U)); |
Gabor Greif | a2fbc0a | 2010-03-24 13:21:49 +0000 | [diff] [blame] | 721 | if (!CS.isCallee(I)) |
| 722 | return PutOffender ? (*PutOffender = U, true) : true; |
Jay Foad | 557169d | 2009-06-10 08:41:11 +0000 | [diff] [blame] | 723 | } |
| 724 | return false; |
| 725 | } |
| 726 | |
Eli Friedman | 1923a33 | 2011-10-20 05:23:42 +0000 | [diff] [blame] | 727 | bool Function::isDefTriviallyDead() const { |
| 728 | // Check the linkage |
| 729 | if (!hasLinkOnceLinkage() && !hasLocalLinkage() && |
| 730 | !hasAvailableExternallyLinkage()) |
| 731 | return false; |
| 732 | |
| 733 | // Check if the function is used by anything other than a blockaddress. |
| 734 | for (Value::const_use_iterator I = use_begin(), E = use_end(); I != E; ++I) |
| 735 | if (!isa<BlockAddress>(*I)) |
| 736 | return false; |
| 737 | |
| 738 | return true; |
| 739 | } |
| 740 | |
Bill Wendling | 63a4ea1 | 2011-10-17 18:43:40 +0000 | [diff] [blame] | 741 | /// callsFunctionThatReturnsTwice - Return true if the function has a call to |
| 742 | /// setjmp or other function that gcc recognizes as "returning twice". |
| 743 | bool Function::callsFunctionThatReturnsTwice() const { |
| 744 | for (const_inst_iterator |
| 745 | I = inst_begin(this), E = inst_end(this); I != E; ++I) { |
Mark Seaborn | 8271118 | 2014-01-14 04:20:01 +0000 | [diff] [blame] | 746 | ImmutableCallSite CS(&*I); |
| 747 | if (CS && CS.hasFnAttr(Attribute::ReturnsTwice)) |
Bill Wendling | 63a4ea1 | 2011-10-17 18:43:40 +0000 | [diff] [blame] | 748 | return true; |
| 749 | } |
| 750 | |
| 751 | return false; |
| 752 | } |
Peter Collingbourne | 3fa50f9 | 2013-09-16 01:08:15 +0000 | [diff] [blame] | 753 | |
| 754 | Constant *Function::getPrefixData() const { |
| 755 | assert(hasPrefixData()); |
| 756 | const LLVMContextImpl::PrefixDataMapTy &PDMap = |
| 757 | getContext().pImpl->PrefixDataMap; |
| 758 | assert(PDMap.find(this) != PDMap.end()); |
| 759 | return cast<Constant>(PDMap.find(this)->second->getReturnValue()); |
| 760 | } |
| 761 | |
| 762 | void Function::setPrefixData(Constant *PrefixData) { |
| 763 | if (!PrefixData && !hasPrefixData()) |
| 764 | return; |
| 765 | |
| 766 | unsigned SCData = getSubclassDataFromValue(); |
| 767 | LLVMContextImpl::PrefixDataMapTy &PDMap = getContext().pImpl->PrefixDataMap; |
| 768 | ReturnInst *&PDHolder = PDMap[this]; |
| 769 | if (PrefixData) { |
| 770 | if (PDHolder) |
| 771 | PDHolder->setOperand(0, PrefixData); |
| 772 | else |
| 773 | PDHolder = ReturnInst::Create(getContext(), PrefixData); |
| 774 | SCData |= 2; |
| 775 | } else { |
| 776 | delete PDHolder; |
| 777 | PDMap.erase(this); |
| 778 | SCData &= ~2; |
| 779 | } |
| 780 | setValueSubclassData(SCData); |
| 781 | } |