Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 1 | //===-- Instructions.cpp - Implement the LLVM instructions ----------------===// |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 2 | // |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file was developed by the LLVM research group and is distributed under |
| 6 | // the University of Illinois Open Source License. See LICENSE.TXT for details. |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 7 | // |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 10 | // This file implements all of the non-inline methods for the LLVM instruction |
| 11 | // classes. |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "llvm/BasicBlock.h" |
| 16 | #include "llvm/Constants.h" |
| 17 | #include "llvm/DerivedTypes.h" |
| 18 | #include "llvm/Function.h" |
| 19 | #include "llvm/Instructions.h" |
Reid Spencer | ce38beb | 2007-04-09 18:00:57 +0000 | [diff] [blame] | 20 | #include "llvm/ParameterAttributes.h" |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 21 | #include "llvm/Support/CallSite.h" |
Reid Spencer | 0286bc1 | 2007-02-28 22:00:54 +0000 | [diff] [blame] | 22 | #include "llvm/Support/ConstantRange.h" |
Christopher Lamb | 8448570 | 2007-04-22 19:24:39 +0000 | [diff] [blame] | 23 | #include "llvm/Support/MathExtras.h" |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 24 | using namespace llvm; |
| 25 | |
Chris Lattner | f7b6d31 | 2005-05-06 20:26:43 +0000 | [diff] [blame] | 26 | unsigned CallSite::getCallingConv() const { |
| 27 | if (CallInst *CI = dyn_cast<CallInst>(I)) |
| 28 | return CI->getCallingConv(); |
| 29 | else |
| 30 | return cast<InvokeInst>(I)->getCallingConv(); |
| 31 | } |
| 32 | void CallSite::setCallingConv(unsigned CC) { |
| 33 | if (CallInst *CI = dyn_cast<CallInst>(I)) |
| 34 | CI->setCallingConv(CC); |
| 35 | else |
| 36 | cast<InvokeInst>(I)->setCallingConv(CC); |
| 37 | } |
Duncan Sands | ad0ea2d | 2007-11-27 13:23:08 +0000 | [diff] [blame] | 38 | const ParamAttrsList* CallSite::getParamAttrs() const { |
| 39 | if (CallInst *CI = dyn_cast<CallInst>(I)) |
| 40 | return CI->getParamAttrs(); |
| 41 | else |
| 42 | return cast<InvokeInst>(I)->getParamAttrs(); |
| 43 | } |
| 44 | void CallSite::setParamAttrs(const ParamAttrsList *PAL) { |
| 45 | if (CallInst *CI = dyn_cast<CallInst>(I)) |
| 46 | CI->setParamAttrs(PAL); |
| 47 | else |
| 48 | cast<InvokeInst>(I)->setParamAttrs(PAL); |
| 49 | } |
Duncan Sands | 5208d1a | 2007-11-28 17:07:01 +0000 | [diff] [blame] | 50 | bool CallSite::paramHasAttr(uint16_t i, ParameterAttributes attr) const { |
| 51 | if (CallInst *CI = dyn_cast<CallInst>(I)) |
| 52 | return CI->paramHasAttr(i, attr); |
| 53 | else |
| 54 | return cast<InvokeInst>(I)->paramHasAttr(i, attr); |
| 55 | } |
Duncan Sands | 38ef3a8 | 2007-12-03 20:06:50 +0000 | [diff] [blame^] | 56 | bool CallSite::doesNotAccessMemory() const { |
| 57 | if (CallInst *CI = dyn_cast<CallInst>(I)) |
| 58 | return CI->doesNotAccessMemory(); |
| 59 | else |
| 60 | return cast<InvokeInst>(I)->doesNotAccessMemory(); |
| 61 | } |
| 62 | bool CallSite::onlyReadsMemory() const { |
| 63 | if (CallInst *CI = dyn_cast<CallInst>(I)) |
| 64 | return CI->onlyReadsMemory(); |
| 65 | else |
| 66 | return cast<InvokeInst>(I)->onlyReadsMemory(); |
| 67 | } |
Chris Lattner | f7b6d31 | 2005-05-06 20:26:43 +0000 | [diff] [blame] | 68 | |
Chris Lattner | 1c12a88 | 2006-06-21 16:53:47 +0000 | [diff] [blame] | 69 | |
| 70 | |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 71 | //===----------------------------------------------------------------------===// |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 72 | // TerminatorInst Class |
| 73 | //===----------------------------------------------------------------------===// |
| 74 | |
Chris Lattner | 1c12a88 | 2006-06-21 16:53:47 +0000 | [diff] [blame] | 75 | // Out of line virtual method, so the vtable, etc has a home. |
| 76 | TerminatorInst::~TerminatorInst() { |
| 77 | } |
| 78 | |
| 79 | // Out of line virtual method, so the vtable, etc has a home. |
| 80 | UnaryInstruction::~UnaryInstruction() { |
| 81 | } |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 82 | |
| 83 | |
| 84 | //===----------------------------------------------------------------------===// |
| 85 | // PHINode Class |
| 86 | //===----------------------------------------------------------------------===// |
| 87 | |
| 88 | PHINode::PHINode(const PHINode &PN) |
| 89 | : Instruction(PN.getType(), Instruction::PHI, |
| 90 | new Use[PN.getNumOperands()], PN.getNumOperands()), |
| 91 | ReservedSpace(PN.getNumOperands()) { |
| 92 | Use *OL = OperandList; |
| 93 | for (unsigned i = 0, e = PN.getNumOperands(); i != e; i+=2) { |
| 94 | OL[i].init(PN.getOperand(i), this); |
| 95 | OL[i+1].init(PN.getOperand(i+1), this); |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | PHINode::~PHINode() { |
| 100 | delete [] OperandList; |
| 101 | } |
| 102 | |
| 103 | // removeIncomingValue - Remove an incoming value. This is useful if a |
| 104 | // predecessor basic block is deleted. |
| 105 | Value *PHINode::removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty) { |
| 106 | unsigned NumOps = getNumOperands(); |
| 107 | Use *OL = OperandList; |
| 108 | assert(Idx*2 < NumOps && "BB not in PHI node!"); |
| 109 | Value *Removed = OL[Idx*2]; |
| 110 | |
| 111 | // Move everything after this operand down. |
| 112 | // |
| 113 | // FIXME: we could just swap with the end of the list, then erase. However, |
| 114 | // client might not expect this to happen. The code as it is thrashes the |
| 115 | // use/def lists, which is kinda lame. |
| 116 | for (unsigned i = (Idx+1)*2; i != NumOps; i += 2) { |
| 117 | OL[i-2] = OL[i]; |
| 118 | OL[i-2+1] = OL[i+1]; |
| 119 | } |
| 120 | |
| 121 | // Nuke the last value. |
| 122 | OL[NumOps-2].set(0); |
| 123 | OL[NumOps-2+1].set(0); |
| 124 | NumOperands = NumOps-2; |
| 125 | |
| 126 | // If the PHI node is dead, because it has zero entries, nuke it now. |
| 127 | if (NumOps == 2 && DeletePHIIfEmpty) { |
| 128 | // If anyone is using this PHI, make them use a dummy value instead... |
| 129 | replaceAllUsesWith(UndefValue::get(getType())); |
| 130 | eraseFromParent(); |
| 131 | } |
| 132 | return Removed; |
| 133 | } |
| 134 | |
| 135 | /// resizeOperands - resize operands - This adjusts the length of the operands |
| 136 | /// list according to the following behavior: |
| 137 | /// 1. If NumOps == 0, grow the operand list in response to a push_back style |
| 138 | /// of operation. This grows the number of ops by 1.5 times. |
| 139 | /// 2. If NumOps > NumOperands, reserve space for NumOps operands. |
| 140 | /// 3. If NumOps == NumOperands, trim the reserved space. |
| 141 | /// |
| 142 | void PHINode::resizeOperands(unsigned NumOps) { |
| 143 | if (NumOps == 0) { |
| 144 | NumOps = (getNumOperands())*3/2; |
| 145 | if (NumOps < 4) NumOps = 4; // 4 op PHI nodes are VERY common. |
| 146 | } else if (NumOps*2 > NumOperands) { |
| 147 | // No resize needed. |
| 148 | if (ReservedSpace >= NumOps) return; |
| 149 | } else if (NumOps == NumOperands) { |
| 150 | if (ReservedSpace == NumOps) return; |
| 151 | } else { |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 152 | return; |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | ReservedSpace = NumOps; |
| 156 | Use *NewOps = new Use[NumOps]; |
| 157 | Use *OldOps = OperandList; |
| 158 | for (unsigned i = 0, e = getNumOperands(); i != e; ++i) { |
| 159 | NewOps[i].init(OldOps[i], this); |
| 160 | OldOps[i].set(0); |
| 161 | } |
| 162 | delete [] OldOps; |
| 163 | OperandList = NewOps; |
| 164 | } |
| 165 | |
Nate Begeman | b392321 | 2005-08-04 23:24:19 +0000 | [diff] [blame] | 166 | /// hasConstantValue - If the specified PHI node always merges together the same |
| 167 | /// value, return the value, otherwise return null. |
| 168 | /// |
Chris Lattner | 1d8b248 | 2005-08-05 00:49:06 +0000 | [diff] [blame] | 169 | Value *PHINode::hasConstantValue(bool AllowNonDominatingInstruction) const { |
Nate Begeman | b392321 | 2005-08-04 23:24:19 +0000 | [diff] [blame] | 170 | // If the PHI node only has one incoming value, eliminate the PHI node... |
| 171 | if (getNumIncomingValues() == 1) |
Chris Lattner | 6e709c1 | 2005-08-05 15:37:31 +0000 | [diff] [blame] | 172 | if (getIncomingValue(0) != this) // not X = phi X |
| 173 | return getIncomingValue(0); |
| 174 | else |
| 175 | return UndefValue::get(getType()); // Self cycle is dead. |
| 176 | |
Nate Begeman | b392321 | 2005-08-04 23:24:19 +0000 | [diff] [blame] | 177 | // Otherwise if all of the incoming values are the same for the PHI, replace |
| 178 | // the PHI node with the incoming value. |
| 179 | // |
| 180 | Value *InVal = 0; |
Chris Lattner | bcd8d2c | 2005-08-05 01:00:58 +0000 | [diff] [blame] | 181 | bool HasUndefInput = false; |
Nate Begeman | b392321 | 2005-08-04 23:24:19 +0000 | [diff] [blame] | 182 | for (unsigned i = 0, e = getNumIncomingValues(); i != e; ++i) |
Chris Lattner | bcd8d2c | 2005-08-05 01:00:58 +0000 | [diff] [blame] | 183 | if (isa<UndefValue>(getIncomingValue(i))) |
| 184 | HasUndefInput = true; |
| 185 | else if (getIncomingValue(i) != this) // Not the PHI node itself... |
Nate Begeman | b392321 | 2005-08-04 23:24:19 +0000 | [diff] [blame] | 186 | if (InVal && getIncomingValue(i) != InVal) |
| 187 | return 0; // Not the same, bail out. |
| 188 | else |
| 189 | InVal = getIncomingValue(i); |
| 190 | |
| 191 | // The only case that could cause InVal to be null is if we have a PHI node |
| 192 | // that only has entries for itself. In this case, there is no entry into the |
| 193 | // loop, so kill the PHI. |
| 194 | // |
| 195 | if (InVal == 0) InVal = UndefValue::get(getType()); |
| 196 | |
Chris Lattner | bcd8d2c | 2005-08-05 01:00:58 +0000 | [diff] [blame] | 197 | // If we have a PHI node like phi(X, undef, X), where X is defined by some |
| 198 | // instruction, we cannot always return X as the result of the PHI node. Only |
| 199 | // do this if X is not an instruction (thus it must dominate the PHI block), |
| 200 | // or if the client is prepared to deal with this possibility. |
| 201 | if (HasUndefInput && !AllowNonDominatingInstruction) |
| 202 | if (Instruction *IV = dyn_cast<Instruction>(InVal)) |
| 203 | // If it's in the entry block, it dominates everything. |
Dan Gohman | dcb291f | 2007-03-22 16:38:57 +0000 | [diff] [blame] | 204 | if (IV->getParent() != &IV->getParent()->getParent()->getEntryBlock() || |
Chris Lattner | 37774af | 2005-08-05 01:03:27 +0000 | [diff] [blame] | 205 | isa<InvokeInst>(IV)) |
Chris Lattner | bcd8d2c | 2005-08-05 01:00:58 +0000 | [diff] [blame] | 206 | return 0; // Cannot guarantee that InVal dominates this PHINode. |
| 207 | |
Nate Begeman | b392321 | 2005-08-04 23:24:19 +0000 | [diff] [blame] | 208 | // All of the incoming values are the same, return the value now. |
| 209 | return InVal; |
| 210 | } |
| 211 | |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 212 | |
| 213 | //===----------------------------------------------------------------------===// |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 214 | // CallInst Implementation |
| 215 | //===----------------------------------------------------------------------===// |
| 216 | |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 217 | CallInst::~CallInst() { |
| 218 | delete [] OperandList; |
Reid Spencer | c6a8384 | 2007-04-22 17:28:03 +0000 | [diff] [blame] | 219 | if (ParamAttrs) |
| 220 | ParamAttrs->dropRef(); |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 221 | } |
| 222 | |
Chris Lattner | 054ba2c | 2007-02-13 00:58:44 +0000 | [diff] [blame] | 223 | void CallInst::init(Value *Func, Value* const *Params, unsigned NumParams) { |
Reid Spencer | 019c886 | 2007-04-09 15:01:12 +0000 | [diff] [blame] | 224 | ParamAttrs = 0; |
Chris Lattner | 054ba2c | 2007-02-13 00:58:44 +0000 | [diff] [blame] | 225 | NumOperands = NumParams+1; |
| 226 | Use *OL = OperandList = new Use[NumParams+1]; |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 227 | OL[0].init(Func, this); |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 228 | |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 229 | const FunctionType *FTy = |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 230 | cast<FunctionType>(cast<PointerType>(Func->getType())->getElementType()); |
Chris Lattner | f14c76c | 2007-02-01 04:59:37 +0000 | [diff] [blame] | 231 | FTy = FTy; // silence warning. |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 232 | |
Chris Lattner | 054ba2c | 2007-02-13 00:58:44 +0000 | [diff] [blame] | 233 | assert((NumParams == FTy->getNumParams() || |
| 234 | (FTy->isVarArg() && NumParams > FTy->getNumParams())) && |
Chris Lattner | 667a056 | 2006-05-03 00:48:22 +0000 | [diff] [blame] | 235 | "Calling a function with bad signature!"); |
Chris Lattner | 054ba2c | 2007-02-13 00:58:44 +0000 | [diff] [blame] | 236 | for (unsigned i = 0; i != NumParams; ++i) { |
Chris Lattner | 667a056 | 2006-05-03 00:48:22 +0000 | [diff] [blame] | 237 | assert((i >= FTy->getNumParams() || |
| 238 | FTy->getParamType(i) == Params[i]->getType()) && |
| 239 | "Calling a function with a bad signature!"); |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 240 | OL[i+1].init(Params[i], this); |
Chris Lattner | 667a056 | 2006-05-03 00:48:22 +0000 | [diff] [blame] | 241 | } |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 242 | } |
| 243 | |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 244 | void CallInst::init(Value *Func, Value *Actual1, Value *Actual2) { |
Reid Spencer | 019c886 | 2007-04-09 15:01:12 +0000 | [diff] [blame] | 245 | ParamAttrs = 0; |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 246 | NumOperands = 3; |
| 247 | Use *OL = OperandList = new Use[3]; |
| 248 | OL[0].init(Func, this); |
| 249 | OL[1].init(Actual1, this); |
| 250 | OL[2].init(Actual2, this); |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 251 | |
| 252 | const FunctionType *FTy = |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 253 | cast<FunctionType>(cast<PointerType>(Func->getType())->getElementType()); |
Chris Lattner | f14c76c | 2007-02-01 04:59:37 +0000 | [diff] [blame] | 254 | FTy = FTy; // silence warning. |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 255 | |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 256 | assert((FTy->getNumParams() == 2 || |
Chris Lattner | 667a056 | 2006-05-03 00:48:22 +0000 | [diff] [blame] | 257 | (FTy->isVarArg() && FTy->getNumParams() < 2)) && |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 258 | "Calling a function with bad signature"); |
Chris Lattner | 667a056 | 2006-05-03 00:48:22 +0000 | [diff] [blame] | 259 | assert((0 >= FTy->getNumParams() || |
| 260 | FTy->getParamType(0) == Actual1->getType()) && |
| 261 | "Calling a function with a bad signature!"); |
| 262 | assert((1 >= FTy->getNumParams() || |
| 263 | FTy->getParamType(1) == Actual2->getType()) && |
| 264 | "Calling a function with a bad signature!"); |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 265 | } |
| 266 | |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 267 | void CallInst::init(Value *Func, Value *Actual) { |
Reid Spencer | 019c886 | 2007-04-09 15:01:12 +0000 | [diff] [blame] | 268 | ParamAttrs = 0; |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 269 | NumOperands = 2; |
| 270 | Use *OL = OperandList = new Use[2]; |
| 271 | OL[0].init(Func, this); |
| 272 | OL[1].init(Actual, this); |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 273 | |
| 274 | const FunctionType *FTy = |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 275 | cast<FunctionType>(cast<PointerType>(Func->getType())->getElementType()); |
Chris Lattner | f14c76c | 2007-02-01 04:59:37 +0000 | [diff] [blame] | 276 | FTy = FTy; // silence warning. |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 277 | |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 278 | assert((FTy->getNumParams() == 1 || |
| 279 | (FTy->isVarArg() && FTy->getNumParams() == 0)) && |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 280 | "Calling a function with bad signature"); |
Chris Lattner | 667a056 | 2006-05-03 00:48:22 +0000 | [diff] [blame] | 281 | assert((0 == FTy->getNumParams() || |
| 282 | FTy->getParamType(0) == Actual->getType()) && |
| 283 | "Calling a function with a bad signature!"); |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 284 | } |
| 285 | |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 286 | void CallInst::init(Value *Func) { |
Reid Spencer | 019c886 | 2007-04-09 15:01:12 +0000 | [diff] [blame] | 287 | ParamAttrs = 0; |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 288 | NumOperands = 1; |
| 289 | Use *OL = OperandList = new Use[1]; |
| 290 | OL[0].init(Func, this); |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 291 | |
Chris Lattner | f14c76c | 2007-02-01 04:59:37 +0000 | [diff] [blame] | 292 | const FunctionType *FTy = |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 293 | cast<FunctionType>(cast<PointerType>(Func->getType())->getElementType()); |
Chris Lattner | f14c76c | 2007-02-01 04:59:37 +0000 | [diff] [blame] | 294 | FTy = FTy; // silence warning. |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 295 | |
Chris Lattner | f14c76c | 2007-02-01 04:59:37 +0000 | [diff] [blame] | 296 | assert(FTy->getNumParams() == 0 && "Calling a function with bad signature"); |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 297 | } |
| 298 | |
David Greene | 17a5dfe | 2007-08-01 03:43:44 +0000 | [diff] [blame] | 299 | #if 0 |
| 300 | // Leave for llvm-gcc |
Chris Lattner | b5fcc28 | 2007-02-13 01:04:01 +0000 | [diff] [blame] | 301 | CallInst::CallInst(Value *Func, Value* const *Args, unsigned NumArgs, |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 302 | const std::string &Name, BasicBlock *InsertAtEnd) |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 303 | : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType()) |
David Greene | 17a5dfe | 2007-08-01 03:43:44 +0000 | [diff] [blame] | 304 | ->getElementType())->getReturnType(), |
Chris Lattner | 2195fc4 | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 305 | Instruction::Call, 0, 0, InsertAtEnd) { |
Chris Lattner | b5fcc28 | 2007-02-13 01:04:01 +0000 | [diff] [blame] | 306 | init(Func, Args, NumArgs); |
Chris Lattner | 2195fc4 | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 307 | setName(Name); |
Chris Lattner | b5fcc28 | 2007-02-13 01:04:01 +0000 | [diff] [blame] | 308 | } |
| 309 | CallInst::CallInst(Value *Func, Value* const *Args, unsigned NumArgs, |
| 310 | const std::string &Name, Instruction *InsertBefore) |
David Greene | 17a5dfe | 2007-08-01 03:43:44 +0000 | [diff] [blame] | 311 | : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType()) |
| 312 | ->getElementType())->getReturnType(), |
| 313 | Instruction::Call, 0, 0, InsertBefore) { |
Chris Lattner | b5fcc28 | 2007-02-13 01:04:01 +0000 | [diff] [blame] | 314 | init(Func, Args, NumArgs); |
Chris Lattner | 2195fc4 | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 315 | setName(Name); |
Chris Lattner | b5fcc28 | 2007-02-13 01:04:01 +0000 | [diff] [blame] | 316 | } |
| 317 | |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 318 | CallInst::CallInst(Value *Func, Value *Actual1, Value *Actual2, |
| 319 | const std::string &Name, Instruction *InsertBefore) |
| 320 | : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType()) |
| 321 | ->getElementType())->getReturnType(), |
Chris Lattner | 2195fc4 | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 322 | Instruction::Call, 0, 0, InsertBefore) { |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 323 | init(Func, Actual1, Actual2); |
Chris Lattner | 2195fc4 | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 324 | setName(Name); |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | CallInst::CallInst(Value *Func, Value *Actual1, Value *Actual2, |
| 328 | const std::string &Name, BasicBlock *InsertAtEnd) |
| 329 | : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType()) |
| 330 | ->getElementType())->getReturnType(), |
Chris Lattner | 2195fc4 | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 331 | Instruction::Call, 0, 0, InsertAtEnd) { |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 332 | init(Func, Actual1, Actual2); |
Chris Lattner | 2195fc4 | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 333 | setName(Name); |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 334 | } |
David Greene | 17a5dfe | 2007-08-01 03:43:44 +0000 | [diff] [blame] | 335 | #endif |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 336 | CallInst::CallInst(Value *Func, Value* Actual, const std::string &Name, |
Chris Lattner | 2195fc4 | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 337 | Instruction *InsertBefore) |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 338 | : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType()) |
| 339 | ->getElementType())->getReturnType(), |
Chris Lattner | 2195fc4 | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 340 | Instruction::Call, 0, 0, InsertBefore) { |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 341 | init(Func, Actual); |
Chris Lattner | 2195fc4 | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 342 | setName(Name); |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | CallInst::CallInst(Value *Func, Value* Actual, const std::string &Name, |
| 346 | BasicBlock *InsertAtEnd) |
| 347 | : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType()) |
| 348 | ->getElementType())->getReturnType(), |
Chris Lattner | 2195fc4 | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 349 | Instruction::Call, 0, 0, InsertAtEnd) { |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 350 | init(Func, Actual); |
Chris Lattner | 2195fc4 | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 351 | setName(Name); |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 352 | } |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 353 | CallInst::CallInst(Value *Func, const std::string &Name, |
| 354 | Instruction *InsertBefore) |
| 355 | : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType()) |
| 356 | ->getElementType())->getReturnType(), |
Chris Lattner | 2195fc4 | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 357 | Instruction::Call, 0, 0, InsertBefore) { |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 358 | init(Func); |
Chris Lattner | 2195fc4 | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 359 | setName(Name); |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | CallInst::CallInst(Value *Func, const std::string &Name, |
| 363 | BasicBlock *InsertAtEnd) |
| 364 | : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType()) |
| 365 | ->getElementType())->getReturnType(), |
Chris Lattner | 2195fc4 | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 366 | Instruction::Call, 0, 0, InsertAtEnd) { |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 367 | init(Func); |
Chris Lattner | 2195fc4 | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 368 | setName(Name); |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 369 | } |
| 370 | |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 371 | CallInst::CallInst(const CallInst &CI) |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 372 | : Instruction(CI.getType(), Instruction::Call, new Use[CI.getNumOperands()], |
Duncan Sands | ad0ea2d | 2007-11-27 13:23:08 +0000 | [diff] [blame] | 373 | CI.getNumOperands()), |
| 374 | ParamAttrs(0) { |
| 375 | setParamAttrs(CI.getParamAttrs()); |
Chris Lattner | f7b6d31 | 2005-05-06 20:26:43 +0000 | [diff] [blame] | 376 | SubclassData = CI.SubclassData; |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 377 | Use *OL = OperandList; |
| 378 | Use *InOL = CI.OperandList; |
| 379 | for (unsigned i = 0, e = CI.getNumOperands(); i != e; ++i) |
| 380 | OL[i].init(InOL[i], this); |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 381 | } |
| 382 | |
Duncan Sands | ad0ea2d | 2007-11-27 13:23:08 +0000 | [diff] [blame] | 383 | void CallInst::setParamAttrs(const ParamAttrsList *newAttrs) { |
| 384 | if (ParamAttrs == newAttrs) |
| 385 | return; |
| 386 | |
Reid Spencer | c6a8384 | 2007-04-22 17:28:03 +0000 | [diff] [blame] | 387 | if (ParamAttrs) |
| 388 | ParamAttrs->dropRef(); |
| 389 | |
| 390 | if (newAttrs) |
| 391 | newAttrs->addRef(); |
| 392 | |
| 393 | ParamAttrs = newAttrs; |
| 394 | } |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 395 | |
Duncan Sands | 5208d1a | 2007-11-28 17:07:01 +0000 | [diff] [blame] | 396 | bool CallInst::paramHasAttr(uint16_t i, ParameterAttributes attr) const { |
| 397 | if (ParamAttrs && ParamAttrs->paramHasAttr(i, attr)) |
| 398 | return true; |
Duncan Sands | 8dfcd59 | 2007-11-29 08:30:15 +0000 | [diff] [blame] | 399 | if (const Function *F = getCalledFunction()) |
| 400 | return F->paramHasAttr(i, attr); |
| 401 | return false; |
Duncan Sands | ad0ea2d | 2007-11-27 13:23:08 +0000 | [diff] [blame] | 402 | } |
| 403 | |
Duncan Sands | 5208d1a | 2007-11-28 17:07:01 +0000 | [diff] [blame] | 404 | |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 405 | //===----------------------------------------------------------------------===// |
| 406 | // InvokeInst Implementation |
| 407 | //===----------------------------------------------------------------------===// |
| 408 | |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 409 | InvokeInst::~InvokeInst() { |
| 410 | delete [] OperandList; |
Reid Spencer | c6a8384 | 2007-04-22 17:28:03 +0000 | [diff] [blame] | 411 | if (ParamAttrs) |
| 412 | ParamAttrs->dropRef(); |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 413 | } |
| 414 | |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 415 | void InvokeInst::init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException, |
Chris Lattner | b5fcc28 | 2007-02-13 01:04:01 +0000 | [diff] [blame] | 416 | Value* const *Args, unsigned NumArgs) { |
Reid Spencer | ce38beb | 2007-04-09 18:00:57 +0000 | [diff] [blame] | 417 | ParamAttrs = 0; |
Chris Lattner | b5fcc28 | 2007-02-13 01:04:01 +0000 | [diff] [blame] | 418 | NumOperands = 3+NumArgs; |
| 419 | Use *OL = OperandList = new Use[3+NumArgs]; |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 420 | OL[0].init(Fn, this); |
| 421 | OL[1].init(IfNormal, this); |
| 422 | OL[2].init(IfException, this); |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 423 | const FunctionType *FTy = |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 424 | cast<FunctionType>(cast<PointerType>(Fn->getType())->getElementType()); |
Chris Lattner | f14c76c | 2007-02-01 04:59:37 +0000 | [diff] [blame] | 425 | FTy = FTy; // silence warning. |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 426 | |
Chris Lattner | b5fcc28 | 2007-02-13 01:04:01 +0000 | [diff] [blame] | 427 | assert((NumArgs == FTy->getNumParams()) || |
| 428 | (FTy->isVarArg() && NumArgs > FTy->getNumParams()) && |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 429 | "Calling a function with bad signature"); |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 430 | |
Chris Lattner | b5fcc28 | 2007-02-13 01:04:01 +0000 | [diff] [blame] | 431 | for (unsigned i = 0, e = NumArgs; i != e; i++) { |
Chris Lattner | 667a056 | 2006-05-03 00:48:22 +0000 | [diff] [blame] | 432 | assert((i >= FTy->getNumParams() || |
Chris Lattner | b5fcc28 | 2007-02-13 01:04:01 +0000 | [diff] [blame] | 433 | FTy->getParamType(i) == Args[i]->getType()) && |
Chris Lattner | 667a056 | 2006-05-03 00:48:22 +0000 | [diff] [blame] | 434 | "Invoking a function with a bad signature!"); |
| 435 | |
Chris Lattner | b5fcc28 | 2007-02-13 01:04:01 +0000 | [diff] [blame] | 436 | OL[i+3].init(Args[i], this); |
Chris Lattner | 667a056 | 2006-05-03 00:48:22 +0000 | [diff] [blame] | 437 | } |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 438 | } |
| 439 | |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 440 | InvokeInst::InvokeInst(const InvokeInst &II) |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 441 | : TerminatorInst(II.getType(), Instruction::Invoke, |
Duncan Sands | ad0ea2d | 2007-11-27 13:23:08 +0000 | [diff] [blame] | 442 | new Use[II.getNumOperands()], II.getNumOperands()), |
| 443 | ParamAttrs(0) { |
| 444 | setParamAttrs(II.getParamAttrs()); |
Chris Lattner | f7b6d31 | 2005-05-06 20:26:43 +0000 | [diff] [blame] | 445 | SubclassData = II.SubclassData; |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 446 | Use *OL = OperandList, *InOL = II.OperandList; |
| 447 | for (unsigned i = 0, e = II.getNumOperands(); i != e; ++i) |
| 448 | OL[i].init(InOL[i], this); |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 449 | } |
| 450 | |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 451 | BasicBlock *InvokeInst::getSuccessorV(unsigned idx) const { |
| 452 | return getSuccessor(idx); |
| 453 | } |
| 454 | unsigned InvokeInst::getNumSuccessorsV() const { |
| 455 | return getNumSuccessors(); |
| 456 | } |
| 457 | void InvokeInst::setSuccessorV(unsigned idx, BasicBlock *B) { |
| 458 | return setSuccessor(idx, B); |
| 459 | } |
| 460 | |
Duncan Sands | ad0ea2d | 2007-11-27 13:23:08 +0000 | [diff] [blame] | 461 | void InvokeInst::setParamAttrs(const ParamAttrsList *newAttrs) { |
| 462 | if (ParamAttrs == newAttrs) |
| 463 | return; |
| 464 | |
Reid Spencer | c6a8384 | 2007-04-22 17:28:03 +0000 | [diff] [blame] | 465 | if (ParamAttrs) |
| 466 | ParamAttrs->dropRef(); |
| 467 | |
| 468 | if (newAttrs) |
| 469 | newAttrs->addRef(); |
| 470 | |
| 471 | ParamAttrs = newAttrs; |
| 472 | } |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 473 | |
Duncan Sands | 5208d1a | 2007-11-28 17:07:01 +0000 | [diff] [blame] | 474 | bool InvokeInst::paramHasAttr(uint16_t i, ParameterAttributes attr) const { |
| 475 | if (ParamAttrs && ParamAttrs->paramHasAttr(i, attr)) |
| 476 | return true; |
Duncan Sands | 8dfcd59 | 2007-11-29 08:30:15 +0000 | [diff] [blame] | 477 | if (const Function *F = getCalledFunction()) |
| 478 | return F->paramHasAttr(i, attr); |
| 479 | return false; |
Duncan Sands | ad0ea2d | 2007-11-27 13:23:08 +0000 | [diff] [blame] | 480 | } |
| 481 | |
Duncan Sands | 5208d1a | 2007-11-28 17:07:01 +0000 | [diff] [blame] | 482 | |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 483 | //===----------------------------------------------------------------------===// |
| 484 | // ReturnInst Implementation |
| 485 | //===----------------------------------------------------------------------===// |
| 486 | |
Chris Lattner | 2195fc4 | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 487 | ReturnInst::ReturnInst(const ReturnInst &RI) |
| 488 | : TerminatorInst(Type::VoidTy, Instruction::Ret, |
| 489 | &RetVal, RI.getNumOperands()) { |
| 490 | if (RI.getNumOperands()) |
| 491 | RetVal.init(RI.RetVal, this); |
| 492 | } |
| 493 | |
| 494 | ReturnInst::ReturnInst(Value *retVal, Instruction *InsertBefore) |
| 495 | : TerminatorInst(Type::VoidTy, Instruction::Ret, &RetVal, 0, InsertBefore) { |
| 496 | init(retVal); |
| 497 | } |
| 498 | ReturnInst::ReturnInst(Value *retVal, BasicBlock *InsertAtEnd) |
| 499 | : TerminatorInst(Type::VoidTy, Instruction::Ret, &RetVal, 0, InsertAtEnd) { |
| 500 | init(retVal); |
| 501 | } |
| 502 | ReturnInst::ReturnInst(BasicBlock *InsertAtEnd) |
| 503 | : TerminatorInst(Type::VoidTy, Instruction::Ret, &RetVal, 0, InsertAtEnd) { |
| 504 | } |
| 505 | |
| 506 | |
| 507 | |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 508 | void ReturnInst::init(Value *retVal) { |
| 509 | if (retVal && retVal->getType() != Type::VoidTy) { |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 510 | assert(!isa<BasicBlock>(retVal) && |
Alkis Evlogimenos | 531e901 | 2004-11-17 21:02:25 +0000 | [diff] [blame] | 511 | "Cannot return basic block. Probably using the incorrect ctor"); |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 512 | NumOperands = 1; |
| 513 | RetVal.init(retVal, this); |
Alkis Evlogimenos | 531e901 | 2004-11-17 21:02:25 +0000 | [diff] [blame] | 514 | } |
| 515 | } |
| 516 | |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 517 | unsigned ReturnInst::getNumSuccessorsV() const { |
| 518 | return getNumSuccessors(); |
| 519 | } |
| 520 | |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 521 | // Out-of-line ReturnInst method, put here so the C++ compiler can choose to |
| 522 | // emit the vtable for the class in this translation unit. |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 523 | void ReturnInst::setSuccessorV(unsigned idx, BasicBlock *NewSucc) { |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 524 | assert(0 && "ReturnInst has no successors!"); |
| 525 | } |
| 526 | |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 527 | BasicBlock *ReturnInst::getSuccessorV(unsigned idx) const { |
| 528 | assert(0 && "ReturnInst has no successors!"); |
| 529 | abort(); |
| 530 | return 0; |
| 531 | } |
| 532 | |
| 533 | |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 534 | //===----------------------------------------------------------------------===// |
| 535 | // UnwindInst Implementation |
| 536 | //===----------------------------------------------------------------------===// |
| 537 | |
Chris Lattner | 2195fc4 | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 538 | UnwindInst::UnwindInst(Instruction *InsertBefore) |
| 539 | : TerminatorInst(Type::VoidTy, Instruction::Unwind, 0, 0, InsertBefore) { |
| 540 | } |
| 541 | UnwindInst::UnwindInst(BasicBlock *InsertAtEnd) |
| 542 | : TerminatorInst(Type::VoidTy, Instruction::Unwind, 0, 0, InsertAtEnd) { |
| 543 | } |
| 544 | |
| 545 | |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 546 | unsigned UnwindInst::getNumSuccessorsV() const { |
| 547 | return getNumSuccessors(); |
| 548 | } |
| 549 | |
| 550 | void UnwindInst::setSuccessorV(unsigned idx, BasicBlock *NewSucc) { |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 551 | assert(0 && "UnwindInst has no successors!"); |
| 552 | } |
| 553 | |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 554 | BasicBlock *UnwindInst::getSuccessorV(unsigned idx) const { |
| 555 | assert(0 && "UnwindInst has no successors!"); |
| 556 | abort(); |
| 557 | return 0; |
| 558 | } |
| 559 | |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 560 | //===----------------------------------------------------------------------===// |
Chris Lattner | 5e0b9f2 | 2004-10-16 18:08:06 +0000 | [diff] [blame] | 561 | // UnreachableInst Implementation |
| 562 | //===----------------------------------------------------------------------===// |
| 563 | |
Chris Lattner | 2195fc4 | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 564 | UnreachableInst::UnreachableInst(Instruction *InsertBefore) |
| 565 | : TerminatorInst(Type::VoidTy, Instruction::Unreachable, 0, 0, InsertBefore) { |
| 566 | } |
| 567 | UnreachableInst::UnreachableInst(BasicBlock *InsertAtEnd) |
| 568 | : TerminatorInst(Type::VoidTy, Instruction::Unreachable, 0, 0, InsertAtEnd) { |
| 569 | } |
| 570 | |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 571 | unsigned UnreachableInst::getNumSuccessorsV() const { |
| 572 | return getNumSuccessors(); |
| 573 | } |
| 574 | |
| 575 | void UnreachableInst::setSuccessorV(unsigned idx, BasicBlock *NewSucc) { |
| 576 | assert(0 && "UnwindInst has no successors!"); |
| 577 | } |
| 578 | |
| 579 | BasicBlock *UnreachableInst::getSuccessorV(unsigned idx) const { |
| 580 | assert(0 && "UnwindInst has no successors!"); |
| 581 | abort(); |
| 582 | return 0; |
Chris Lattner | 5e0b9f2 | 2004-10-16 18:08:06 +0000 | [diff] [blame] | 583 | } |
| 584 | |
| 585 | //===----------------------------------------------------------------------===// |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 586 | // BranchInst Implementation |
| 587 | //===----------------------------------------------------------------------===// |
| 588 | |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 589 | void BranchInst::AssertOK() { |
| 590 | if (isConditional()) |
Reid Spencer | 542964f | 2007-01-11 18:21:29 +0000 | [diff] [blame] | 591 | assert(getCondition()->getType() == Type::Int1Ty && |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 592 | "May only branch on boolean predicates!"); |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 593 | } |
| 594 | |
Chris Lattner | 2195fc4 | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 595 | BranchInst::BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore) |
| 596 | : TerminatorInst(Type::VoidTy, Instruction::Br, Ops, 1, InsertBefore) { |
| 597 | assert(IfTrue != 0 && "Branch destination may not be null!"); |
| 598 | Ops[0].init(reinterpret_cast<Value*>(IfTrue), this); |
| 599 | } |
| 600 | BranchInst::BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond, |
| 601 | Instruction *InsertBefore) |
| 602 | : TerminatorInst(Type::VoidTy, Instruction::Br, Ops, 3, InsertBefore) { |
| 603 | Ops[0].init(reinterpret_cast<Value*>(IfTrue), this); |
| 604 | Ops[1].init(reinterpret_cast<Value*>(IfFalse), this); |
| 605 | Ops[2].init(Cond, this); |
| 606 | #ifndef NDEBUG |
| 607 | AssertOK(); |
| 608 | #endif |
| 609 | } |
| 610 | |
| 611 | BranchInst::BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd) |
| 612 | : TerminatorInst(Type::VoidTy, Instruction::Br, Ops, 1, InsertAtEnd) { |
| 613 | assert(IfTrue != 0 && "Branch destination may not be null!"); |
| 614 | Ops[0].init(reinterpret_cast<Value*>(IfTrue), this); |
| 615 | } |
| 616 | |
| 617 | BranchInst::BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond, |
| 618 | BasicBlock *InsertAtEnd) |
| 619 | : TerminatorInst(Type::VoidTy, Instruction::Br, Ops, 3, InsertAtEnd) { |
| 620 | Ops[0].init(reinterpret_cast<Value*>(IfTrue), this); |
| 621 | Ops[1].init(reinterpret_cast<Value*>(IfFalse), this); |
| 622 | Ops[2].init(Cond, this); |
| 623 | #ifndef NDEBUG |
| 624 | AssertOK(); |
| 625 | #endif |
| 626 | } |
| 627 | |
| 628 | |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 629 | BranchInst::BranchInst(const BranchInst &BI) : |
Chris Lattner | 2195fc4 | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 630 | TerminatorInst(Type::VoidTy, Instruction::Br, Ops, BI.getNumOperands()) { |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 631 | OperandList[0].init(BI.getOperand(0), this); |
| 632 | if (BI.getNumOperands() != 1) { |
| 633 | assert(BI.getNumOperands() == 3 && "BR can have 1 or 3 operands!"); |
| 634 | OperandList[1].init(BI.getOperand(1), this); |
| 635 | OperandList[2].init(BI.getOperand(2), this); |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 636 | } |
| 637 | } |
| 638 | |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 639 | BasicBlock *BranchInst::getSuccessorV(unsigned idx) const { |
| 640 | return getSuccessor(idx); |
| 641 | } |
| 642 | unsigned BranchInst::getNumSuccessorsV() const { |
| 643 | return getNumSuccessors(); |
| 644 | } |
| 645 | void BranchInst::setSuccessorV(unsigned idx, BasicBlock *B) { |
| 646 | setSuccessor(idx, B); |
| 647 | } |
| 648 | |
| 649 | |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 650 | //===----------------------------------------------------------------------===// |
| 651 | // AllocationInst Implementation |
| 652 | //===----------------------------------------------------------------------===// |
| 653 | |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 654 | static Value *getAISize(Value *Amt) { |
| 655 | if (!Amt) |
Reid Spencer | 8d9336d | 2006-12-31 05:26:44 +0000 | [diff] [blame] | 656 | Amt = ConstantInt::get(Type::Int32Ty, 1); |
Chris Lattner | bb7ff66 | 2006-05-10 04:32:43 +0000 | [diff] [blame] | 657 | else { |
| 658 | assert(!isa<BasicBlock>(Amt) && |
Chris Lattner | 9b6ec77 | 2007-10-18 16:10:48 +0000 | [diff] [blame] | 659 | "Passed basic block into allocation size parameter! Use other ctor"); |
Reid Spencer | 8d9336d | 2006-12-31 05:26:44 +0000 | [diff] [blame] | 660 | assert(Amt->getType() == Type::Int32Ty && |
Reid Spencer | 7e16e23 | 2007-01-26 06:30:34 +0000 | [diff] [blame] | 661 | "Malloc/Allocation array size is not a 32-bit integer!"); |
Chris Lattner | bb7ff66 | 2006-05-10 04:32:43 +0000 | [diff] [blame] | 662 | } |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 663 | return Amt; |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 664 | } |
| 665 | |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 666 | AllocationInst::AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, |
Nate Begeman | 848622f | 2005-11-05 09:21:28 +0000 | [diff] [blame] | 667 | unsigned Align, const std::string &Name, |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 668 | Instruction *InsertBefore) |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 669 | : UnaryInstruction(PointerType::get(Ty), iTy, getAISize(ArraySize), |
Chris Lattner | 2195fc4 | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 670 | InsertBefore), Alignment(Align) { |
Chris Lattner | 79b8c79 | 2005-11-05 21:57:54 +0000 | [diff] [blame] | 671 | assert((Align & (Align-1)) == 0 && "Alignment is not a power of 2!"); |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 672 | assert(Ty != Type::VoidTy && "Cannot allocate void!"); |
Chris Lattner | 0f04816 | 2007-02-13 07:54:42 +0000 | [diff] [blame] | 673 | setName(Name); |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 674 | } |
| 675 | |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 676 | AllocationInst::AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, |
Nate Begeman | 848622f | 2005-11-05 09:21:28 +0000 | [diff] [blame] | 677 | unsigned Align, const std::string &Name, |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 678 | BasicBlock *InsertAtEnd) |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 679 | : UnaryInstruction(PointerType::get(Ty), iTy, getAISize(ArraySize), |
Chris Lattner | 2195fc4 | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 680 | InsertAtEnd), Alignment(Align) { |
Chris Lattner | 79b8c79 | 2005-11-05 21:57:54 +0000 | [diff] [blame] | 681 | assert((Align & (Align-1)) == 0 && "Alignment is not a power of 2!"); |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 682 | assert(Ty != Type::VoidTy && "Cannot allocate void!"); |
Chris Lattner | 0f04816 | 2007-02-13 07:54:42 +0000 | [diff] [blame] | 683 | setName(Name); |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 684 | } |
| 685 | |
Chris Lattner | 1c12a88 | 2006-06-21 16:53:47 +0000 | [diff] [blame] | 686 | // Out of line virtual method, so the vtable, etc has a home. |
| 687 | AllocationInst::~AllocationInst() { |
| 688 | } |
| 689 | |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 690 | bool AllocationInst::isArrayAllocation() const { |
Reid Spencer | a9e6e31 | 2007-03-01 20:27:41 +0000 | [diff] [blame] | 691 | if (ConstantInt *CI = dyn_cast<ConstantInt>(getOperand(0))) |
| 692 | return CI->getZExtValue() != 1; |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 693 | return true; |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 694 | } |
| 695 | |
| 696 | const Type *AllocationInst::getAllocatedType() const { |
| 697 | return getType()->getElementType(); |
| 698 | } |
| 699 | |
| 700 | AllocaInst::AllocaInst(const AllocaInst &AI) |
| 701 | : AllocationInst(AI.getType()->getElementType(), (Value*)AI.getOperand(0), |
Nate Begeman | 848622f | 2005-11-05 09:21:28 +0000 | [diff] [blame] | 702 | Instruction::Alloca, AI.getAlignment()) { |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 703 | } |
| 704 | |
| 705 | MallocInst::MallocInst(const MallocInst &MI) |
| 706 | : AllocationInst(MI.getType()->getElementType(), (Value*)MI.getOperand(0), |
Nate Begeman | 848622f | 2005-11-05 09:21:28 +0000 | [diff] [blame] | 707 | Instruction::Malloc, MI.getAlignment()) { |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 708 | } |
| 709 | |
| 710 | //===----------------------------------------------------------------------===// |
| 711 | // FreeInst Implementation |
| 712 | //===----------------------------------------------------------------------===// |
| 713 | |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 714 | void FreeInst::AssertOK() { |
| 715 | assert(isa<PointerType>(getOperand(0)->getType()) && |
| 716 | "Can not free something of nonpointer type!"); |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 717 | } |
| 718 | |
| 719 | FreeInst::FreeInst(Value *Ptr, Instruction *InsertBefore) |
Chris Lattner | 2195fc4 | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 720 | : UnaryInstruction(Type::VoidTy, Free, Ptr, InsertBefore) { |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 721 | AssertOK(); |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 722 | } |
| 723 | |
| 724 | FreeInst::FreeInst(Value *Ptr, BasicBlock *InsertAtEnd) |
Chris Lattner | 2195fc4 | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 725 | : UnaryInstruction(Type::VoidTy, Free, Ptr, InsertAtEnd) { |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 726 | AssertOK(); |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 727 | } |
| 728 | |
| 729 | |
| 730 | //===----------------------------------------------------------------------===// |
| 731 | // LoadInst Implementation |
| 732 | //===----------------------------------------------------------------------===// |
| 733 | |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 734 | void LoadInst::AssertOK() { |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 735 | assert(isa<PointerType>(getOperand(0)->getType()) && |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 736 | "Ptr must have pointer type."); |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 737 | } |
| 738 | |
| 739 | LoadInst::LoadInst(Value *Ptr, const std::string &Name, Instruction *InsertBef) |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 740 | : UnaryInstruction(cast<PointerType>(Ptr->getType())->getElementType(), |
Chris Lattner | 2195fc4 | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 741 | Load, Ptr, InsertBef) { |
Chris Lattner | df57a02 | 2005-02-05 01:38:38 +0000 | [diff] [blame] | 742 | setVolatile(false); |
Christopher Lamb | 8448570 | 2007-04-22 19:24:39 +0000 | [diff] [blame] | 743 | setAlignment(0); |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 744 | AssertOK(); |
Chris Lattner | 0f04816 | 2007-02-13 07:54:42 +0000 | [diff] [blame] | 745 | setName(Name); |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 746 | } |
| 747 | |
| 748 | LoadInst::LoadInst(Value *Ptr, const std::string &Name, BasicBlock *InsertAE) |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 749 | : UnaryInstruction(cast<PointerType>(Ptr->getType())->getElementType(), |
Chris Lattner | 2195fc4 | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 750 | Load, Ptr, InsertAE) { |
Chris Lattner | df57a02 | 2005-02-05 01:38:38 +0000 | [diff] [blame] | 751 | setVolatile(false); |
Christopher Lamb | 8448570 | 2007-04-22 19:24:39 +0000 | [diff] [blame] | 752 | setAlignment(0); |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 753 | AssertOK(); |
Chris Lattner | 0f04816 | 2007-02-13 07:54:42 +0000 | [diff] [blame] | 754 | setName(Name); |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 755 | } |
| 756 | |
| 757 | LoadInst::LoadInst(Value *Ptr, const std::string &Name, bool isVolatile, |
| 758 | Instruction *InsertBef) |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 759 | : UnaryInstruction(cast<PointerType>(Ptr->getType())->getElementType(), |
Chris Lattner | 2195fc4 | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 760 | Load, Ptr, InsertBef) { |
Chris Lattner | df57a02 | 2005-02-05 01:38:38 +0000 | [diff] [blame] | 761 | setVolatile(isVolatile); |
Christopher Lamb | 8448570 | 2007-04-22 19:24:39 +0000 | [diff] [blame] | 762 | setAlignment(0); |
| 763 | AssertOK(); |
| 764 | setName(Name); |
| 765 | } |
| 766 | |
| 767 | LoadInst::LoadInst(Value *Ptr, const std::string &Name, bool isVolatile, |
| 768 | unsigned Align, Instruction *InsertBef) |
| 769 | : UnaryInstruction(cast<PointerType>(Ptr->getType())->getElementType(), |
| 770 | Load, Ptr, InsertBef) { |
| 771 | setVolatile(isVolatile); |
| 772 | setAlignment(Align); |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 773 | AssertOK(); |
Chris Lattner | 0f04816 | 2007-02-13 07:54:42 +0000 | [diff] [blame] | 774 | setName(Name); |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 775 | } |
| 776 | |
Dan Gohman | 6865928 | 2007-07-18 20:51:11 +0000 | [diff] [blame] | 777 | LoadInst::LoadInst(Value *Ptr, const std::string &Name, bool isVolatile, |
| 778 | unsigned Align, BasicBlock *InsertAE) |
| 779 | : UnaryInstruction(cast<PointerType>(Ptr->getType())->getElementType(), |
| 780 | Load, Ptr, InsertAE) { |
| 781 | setVolatile(isVolatile); |
| 782 | setAlignment(Align); |
| 783 | AssertOK(); |
| 784 | setName(Name); |
| 785 | } |
| 786 | |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 787 | LoadInst::LoadInst(Value *Ptr, const std::string &Name, bool isVolatile, |
| 788 | BasicBlock *InsertAE) |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 789 | : UnaryInstruction(cast<PointerType>(Ptr->getType())->getElementType(), |
Chris Lattner | 2195fc4 | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 790 | Load, Ptr, InsertAE) { |
Chris Lattner | 0f04816 | 2007-02-13 07:54:42 +0000 | [diff] [blame] | 791 | setVolatile(isVolatile); |
Christopher Lamb | 8448570 | 2007-04-22 19:24:39 +0000 | [diff] [blame] | 792 | setAlignment(0); |
Chris Lattner | 0f04816 | 2007-02-13 07:54:42 +0000 | [diff] [blame] | 793 | AssertOK(); |
| 794 | setName(Name); |
| 795 | } |
| 796 | |
| 797 | |
| 798 | |
| 799 | LoadInst::LoadInst(Value *Ptr, const char *Name, Instruction *InsertBef) |
Chris Lattner | 2195fc4 | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 800 | : UnaryInstruction(cast<PointerType>(Ptr->getType())->getElementType(), |
| 801 | Load, Ptr, InsertBef) { |
Chris Lattner | 0f04816 | 2007-02-13 07:54:42 +0000 | [diff] [blame] | 802 | setVolatile(false); |
Christopher Lamb | 8448570 | 2007-04-22 19:24:39 +0000 | [diff] [blame] | 803 | setAlignment(0); |
Chris Lattner | 0f04816 | 2007-02-13 07:54:42 +0000 | [diff] [blame] | 804 | AssertOK(); |
Chris Lattner | 2195fc4 | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 805 | if (Name && Name[0]) setName(Name); |
Chris Lattner | 0f04816 | 2007-02-13 07:54:42 +0000 | [diff] [blame] | 806 | } |
| 807 | |
| 808 | LoadInst::LoadInst(Value *Ptr, const char *Name, BasicBlock *InsertAE) |
Chris Lattner | 2195fc4 | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 809 | : UnaryInstruction(cast<PointerType>(Ptr->getType())->getElementType(), |
| 810 | Load, Ptr, InsertAE) { |
Chris Lattner | 0f04816 | 2007-02-13 07:54:42 +0000 | [diff] [blame] | 811 | setVolatile(false); |
Christopher Lamb | 8448570 | 2007-04-22 19:24:39 +0000 | [diff] [blame] | 812 | setAlignment(0); |
Chris Lattner | 0f04816 | 2007-02-13 07:54:42 +0000 | [diff] [blame] | 813 | AssertOK(); |
Chris Lattner | 2195fc4 | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 814 | if (Name && Name[0]) setName(Name); |
Chris Lattner | 0f04816 | 2007-02-13 07:54:42 +0000 | [diff] [blame] | 815 | } |
| 816 | |
| 817 | LoadInst::LoadInst(Value *Ptr, const char *Name, bool isVolatile, |
| 818 | Instruction *InsertBef) |
| 819 | : UnaryInstruction(cast<PointerType>(Ptr->getType())->getElementType(), |
Chris Lattner | 2195fc4 | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 820 | Load, Ptr, InsertBef) { |
Chris Lattner | 0f04816 | 2007-02-13 07:54:42 +0000 | [diff] [blame] | 821 | setVolatile(isVolatile); |
Christopher Lamb | 8448570 | 2007-04-22 19:24:39 +0000 | [diff] [blame] | 822 | setAlignment(0); |
Chris Lattner | 0f04816 | 2007-02-13 07:54:42 +0000 | [diff] [blame] | 823 | AssertOK(); |
Chris Lattner | 2195fc4 | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 824 | if (Name && Name[0]) setName(Name); |
Chris Lattner | 0f04816 | 2007-02-13 07:54:42 +0000 | [diff] [blame] | 825 | } |
| 826 | |
| 827 | LoadInst::LoadInst(Value *Ptr, const char *Name, bool isVolatile, |
| 828 | BasicBlock *InsertAE) |
Chris Lattner | 2195fc4 | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 829 | : UnaryInstruction(cast<PointerType>(Ptr->getType())->getElementType(), |
| 830 | Load, Ptr, InsertAE) { |
Chris Lattner | df57a02 | 2005-02-05 01:38:38 +0000 | [diff] [blame] | 831 | setVolatile(isVolatile); |
Christopher Lamb | 8448570 | 2007-04-22 19:24:39 +0000 | [diff] [blame] | 832 | setAlignment(0); |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 833 | AssertOK(); |
Chris Lattner | 2195fc4 | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 834 | if (Name && Name[0]) setName(Name); |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 835 | } |
| 836 | |
Christopher Lamb | 8448570 | 2007-04-22 19:24:39 +0000 | [diff] [blame] | 837 | void LoadInst::setAlignment(unsigned Align) { |
| 838 | assert((Align & (Align-1)) == 0 && "Alignment is not a power of 2!"); |
| 839 | SubclassData = (SubclassData & 1) | ((Log2_32(Align)+1)<<1); |
| 840 | } |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 841 | |
| 842 | //===----------------------------------------------------------------------===// |
| 843 | // StoreInst Implementation |
| 844 | //===----------------------------------------------------------------------===// |
| 845 | |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 846 | void StoreInst::AssertOK() { |
| 847 | assert(isa<PointerType>(getOperand(1)->getType()) && |
| 848 | "Ptr must have pointer type!"); |
| 849 | assert(getOperand(0)->getType() == |
| 850 | cast<PointerType>(getOperand(1)->getType())->getElementType() |
Alkis Evlogimenos | 079fbde | 2004-08-06 14:33:37 +0000 | [diff] [blame] | 851 | && "Ptr must be a pointer to Val type!"); |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 852 | } |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 853 | |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 854 | |
| 855 | StoreInst::StoreInst(Value *val, Value *addr, Instruction *InsertBefore) |
Chris Lattner | 2195fc4 | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 856 | : Instruction(Type::VoidTy, Store, Ops, 2, InsertBefore) { |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 857 | Ops[0].init(val, this); |
| 858 | Ops[1].init(addr, this); |
Chris Lattner | df57a02 | 2005-02-05 01:38:38 +0000 | [diff] [blame] | 859 | setVolatile(false); |
Christopher Lamb | 8448570 | 2007-04-22 19:24:39 +0000 | [diff] [blame] | 860 | setAlignment(0); |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 861 | AssertOK(); |
| 862 | } |
| 863 | |
| 864 | StoreInst::StoreInst(Value *val, Value *addr, BasicBlock *InsertAtEnd) |
Chris Lattner | 2195fc4 | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 865 | : Instruction(Type::VoidTy, Store, Ops, 2, InsertAtEnd) { |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 866 | Ops[0].init(val, this); |
| 867 | Ops[1].init(addr, this); |
Chris Lattner | df57a02 | 2005-02-05 01:38:38 +0000 | [diff] [blame] | 868 | setVolatile(false); |
Christopher Lamb | 8448570 | 2007-04-22 19:24:39 +0000 | [diff] [blame] | 869 | setAlignment(0); |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 870 | AssertOK(); |
| 871 | } |
| 872 | |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 873 | StoreInst::StoreInst(Value *val, Value *addr, bool isVolatile, |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 874 | Instruction *InsertBefore) |
Chris Lattner | 2195fc4 | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 875 | : Instruction(Type::VoidTy, Store, Ops, 2, InsertBefore) { |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 876 | Ops[0].init(val, this); |
| 877 | Ops[1].init(addr, this); |
Chris Lattner | df57a02 | 2005-02-05 01:38:38 +0000 | [diff] [blame] | 878 | setVolatile(isVolatile); |
Christopher Lamb | 8448570 | 2007-04-22 19:24:39 +0000 | [diff] [blame] | 879 | setAlignment(0); |
| 880 | AssertOK(); |
| 881 | } |
| 882 | |
| 883 | StoreInst::StoreInst(Value *val, Value *addr, bool isVolatile, |
| 884 | unsigned Align, Instruction *InsertBefore) |
| 885 | : Instruction(Type::VoidTy, Store, Ops, 2, InsertBefore) { |
| 886 | Ops[0].init(val, this); |
| 887 | Ops[1].init(addr, this); |
| 888 | setVolatile(isVolatile); |
| 889 | setAlignment(Align); |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 890 | AssertOK(); |
| 891 | } |
| 892 | |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 893 | StoreInst::StoreInst(Value *val, Value *addr, bool isVolatile, |
Dan Gohman | 6865928 | 2007-07-18 20:51:11 +0000 | [diff] [blame] | 894 | unsigned Align, BasicBlock *InsertAtEnd) |
| 895 | : Instruction(Type::VoidTy, Store, Ops, 2, InsertAtEnd) { |
| 896 | Ops[0].init(val, this); |
| 897 | Ops[1].init(addr, this); |
| 898 | setVolatile(isVolatile); |
| 899 | setAlignment(Align); |
| 900 | AssertOK(); |
| 901 | } |
| 902 | |
| 903 | StoreInst::StoreInst(Value *val, Value *addr, bool isVolatile, |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 904 | BasicBlock *InsertAtEnd) |
Chris Lattner | 2195fc4 | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 905 | : Instruction(Type::VoidTy, Store, Ops, 2, InsertAtEnd) { |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 906 | Ops[0].init(val, this); |
| 907 | Ops[1].init(addr, this); |
Chris Lattner | df57a02 | 2005-02-05 01:38:38 +0000 | [diff] [blame] | 908 | setVolatile(isVolatile); |
Christopher Lamb | 8448570 | 2007-04-22 19:24:39 +0000 | [diff] [blame] | 909 | setAlignment(0); |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 910 | AssertOK(); |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 911 | } |
| 912 | |
Christopher Lamb | 8448570 | 2007-04-22 19:24:39 +0000 | [diff] [blame] | 913 | void StoreInst::setAlignment(unsigned Align) { |
| 914 | assert((Align & (Align-1)) == 0 && "Alignment is not a power of 2!"); |
| 915 | SubclassData = (SubclassData & 1) | ((Log2_32(Align)+1)<<1); |
| 916 | } |
| 917 | |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 918 | //===----------------------------------------------------------------------===// |
| 919 | // GetElementPtrInst Implementation |
| 920 | //===----------------------------------------------------------------------===// |
| 921 | |
Chris Lattner | 79807c3d | 2007-01-31 19:47:18 +0000 | [diff] [blame] | 922 | void GetElementPtrInst::init(Value *Ptr, Value* const *Idx, unsigned NumIdx) { |
| 923 | NumOperands = 1+NumIdx; |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 924 | Use *OL = OperandList = new Use[NumOperands]; |
| 925 | OL[0].init(Ptr, this); |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 926 | |
Chris Lattner | 79807c3d | 2007-01-31 19:47:18 +0000 | [diff] [blame] | 927 | for (unsigned i = 0; i != NumIdx; ++i) |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 928 | OL[i+1].init(Idx[i], this); |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 929 | } |
| 930 | |
Chris Lattner | 8298120 | 2005-05-03 05:43:30 +0000 | [diff] [blame] | 931 | void GetElementPtrInst::init(Value *Ptr, Value *Idx) { |
| 932 | NumOperands = 2; |
| 933 | Use *OL = OperandList = new Use[2]; |
| 934 | OL[0].init(Ptr, this); |
| 935 | OL[1].init(Idx, this); |
| 936 | } |
| 937 | |
Chris Lattner | 8298120 | 2005-05-03 05:43:30 +0000 | [diff] [blame] | 938 | GetElementPtrInst::GetElementPtrInst(Value *Ptr, Value *Idx, |
| 939 | const std::string &Name, Instruction *InBe) |
Chris Lattner | 2195fc4 | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 940 | : Instruction(PointerType::get(checkType(getIndexedType(Ptr->getType(),Idx))), |
| 941 | GetElementPtr, 0, 0, InBe) { |
Chris Lattner | 8298120 | 2005-05-03 05:43:30 +0000 | [diff] [blame] | 942 | init(Ptr, Idx); |
Chris Lattner | 2195fc4 | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 943 | setName(Name); |
Chris Lattner | 8298120 | 2005-05-03 05:43:30 +0000 | [diff] [blame] | 944 | } |
| 945 | |
| 946 | GetElementPtrInst::GetElementPtrInst(Value *Ptr, Value *Idx, |
| 947 | const std::string &Name, BasicBlock *IAE) |
Chris Lattner | 2195fc4 | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 948 | : Instruction(PointerType::get(checkType(getIndexedType(Ptr->getType(),Idx))), |
| 949 | GetElementPtr, 0, 0, IAE) { |
Chris Lattner | 8298120 | 2005-05-03 05:43:30 +0000 | [diff] [blame] | 950 | init(Ptr, Idx); |
Chris Lattner | 2195fc4 | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 951 | setName(Name); |
Chris Lattner | 8298120 | 2005-05-03 05:43:30 +0000 | [diff] [blame] | 952 | } |
| 953 | |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 954 | GetElementPtrInst::~GetElementPtrInst() { |
| 955 | delete[] OperandList; |
| 956 | } |
| 957 | |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 958 | // getIndexedType - Returns the type of the element that would be loaded with |
| 959 | // a load instruction with the specified parameters. |
| 960 | // |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 961 | // A null type is returned if the indices are invalid for the specified |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 962 | // pointer type. |
| 963 | // |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 964 | const Type* GetElementPtrInst::getIndexedType(const Type *Ptr, |
Chris Lattner | 302116a | 2007-01-31 04:40:28 +0000 | [diff] [blame] | 965 | Value* const *Idxs, |
| 966 | unsigned NumIdx, |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 967 | bool AllowCompositeLeaf) { |
| 968 | if (!isa<PointerType>(Ptr)) return 0; // Type isn't a pointer type! |
| 969 | |
| 970 | // Handle the special case of the empty set index set... |
Chris Lattner | 302116a | 2007-01-31 04:40:28 +0000 | [diff] [blame] | 971 | if (NumIdx == 0) |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 972 | if (AllowCompositeLeaf || |
| 973 | cast<PointerType>(Ptr)->getElementType()->isFirstClassType()) |
| 974 | return cast<PointerType>(Ptr)->getElementType(); |
| 975 | else |
| 976 | return 0; |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 977 | |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 978 | unsigned CurIdx = 0; |
| 979 | while (const CompositeType *CT = dyn_cast<CompositeType>(Ptr)) { |
Chris Lattner | 302116a | 2007-01-31 04:40:28 +0000 | [diff] [blame] | 980 | if (NumIdx == CurIdx) { |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 981 | if (AllowCompositeLeaf || CT->isFirstClassType()) return Ptr; |
| 982 | return 0; // Can't load a whole structure or array!?!? |
| 983 | } |
| 984 | |
Chris Lattner | 302116a | 2007-01-31 04:40:28 +0000 | [diff] [blame] | 985 | Value *Index = Idxs[CurIdx++]; |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 986 | if (isa<PointerType>(CT) && CurIdx != 1) |
| 987 | return 0; // Can only index into pointer types at the first index! |
| 988 | if (!CT->indexValid(Index)) return 0; |
| 989 | Ptr = CT->getTypeAtIndex(Index); |
| 990 | |
| 991 | // If the new type forwards to another type, then it is in the middle |
| 992 | // of being refined to another type (and hence, may have dropped all |
| 993 | // references to what it was using before). So, use the new forwarded |
| 994 | // type. |
| 995 | if (const Type * Ty = Ptr->getForwardedType()) { |
| 996 | Ptr = Ty; |
| 997 | } |
| 998 | } |
Chris Lattner | 302116a | 2007-01-31 04:40:28 +0000 | [diff] [blame] | 999 | return CurIdx == NumIdx ? Ptr : 0; |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 1000 | } |
| 1001 | |
Chris Lattner | 8298120 | 2005-05-03 05:43:30 +0000 | [diff] [blame] | 1002 | const Type* GetElementPtrInst::getIndexedType(const Type *Ptr, Value *Idx) { |
| 1003 | const PointerType *PTy = dyn_cast<PointerType>(Ptr); |
| 1004 | if (!PTy) return 0; // Type isn't a pointer type! |
| 1005 | |
| 1006 | // Check the pointer index. |
| 1007 | if (!PTy->indexValid(Idx)) return 0; |
| 1008 | |
Chris Lattner | c223333 | 2005-05-03 16:44:45 +0000 | [diff] [blame] | 1009 | return PTy->getElementType(); |
Chris Lattner | 8298120 | 2005-05-03 05:43:30 +0000 | [diff] [blame] | 1010 | } |
| 1011 | |
Chris Lattner | 45f1557 | 2007-04-14 00:12:57 +0000 | [diff] [blame] | 1012 | |
| 1013 | /// hasAllZeroIndices - Return true if all of the indices of this GEP are |
| 1014 | /// zeros. If so, the result pointer and the first operand have the same |
| 1015 | /// value, just potentially different types. |
| 1016 | bool GetElementPtrInst::hasAllZeroIndices() const { |
| 1017 | for (unsigned i = 1, e = getNumOperands(); i != e; ++i) { |
| 1018 | if (ConstantInt *CI = dyn_cast<ConstantInt>(getOperand(i))) { |
| 1019 | if (!CI->isZero()) return false; |
| 1020 | } else { |
| 1021 | return false; |
| 1022 | } |
| 1023 | } |
| 1024 | return true; |
| 1025 | } |
| 1026 | |
Chris Lattner | 2705829 | 2007-04-27 20:35:56 +0000 | [diff] [blame] | 1027 | /// hasAllConstantIndices - Return true if all of the indices of this GEP are |
| 1028 | /// constant integers. If so, the result pointer and the first operand have |
| 1029 | /// a constant offset between them. |
| 1030 | bool GetElementPtrInst::hasAllConstantIndices() const { |
| 1031 | for (unsigned i = 1, e = getNumOperands(); i != e; ++i) { |
| 1032 | if (!isa<ConstantInt>(getOperand(i))) |
| 1033 | return false; |
| 1034 | } |
| 1035 | return true; |
| 1036 | } |
| 1037 | |
Chris Lattner | 45f1557 | 2007-04-14 00:12:57 +0000 | [diff] [blame] | 1038 | |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 1039 | //===----------------------------------------------------------------------===// |
Robert Bocchino | 2300448 | 2006-01-10 19:05:34 +0000 | [diff] [blame] | 1040 | // ExtractElementInst Implementation |
| 1041 | //===----------------------------------------------------------------------===// |
| 1042 | |
| 1043 | ExtractElementInst::ExtractElementInst(Value *Val, Value *Index, |
Chris Lattner | bbe0a42 | 2006-04-08 01:18:18 +0000 | [diff] [blame] | 1044 | const std::string &Name, |
| 1045 | Instruction *InsertBef) |
Reid Spencer | d84d35b | 2007-02-15 02:26:10 +0000 | [diff] [blame] | 1046 | : Instruction(cast<VectorType>(Val->getType())->getElementType(), |
Chris Lattner | 2195fc4 | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 1047 | ExtractElement, Ops, 2, InsertBef) { |
Chris Lattner | 54865b3 | 2006-04-08 04:05:48 +0000 | [diff] [blame] | 1048 | assert(isValidOperands(Val, Index) && |
| 1049 | "Invalid extractelement instruction operands!"); |
Robert Bocchino | 2300448 | 2006-01-10 19:05:34 +0000 | [diff] [blame] | 1050 | Ops[0].init(Val, this); |
| 1051 | Ops[1].init(Index, this); |
Chris Lattner | 2195fc4 | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 1052 | setName(Name); |
Robert Bocchino | 2300448 | 2006-01-10 19:05:34 +0000 | [diff] [blame] | 1053 | } |
| 1054 | |
Chris Lattner | 65511ff | 2006-10-05 06:24:58 +0000 | [diff] [blame] | 1055 | ExtractElementInst::ExtractElementInst(Value *Val, unsigned IndexV, |
| 1056 | const std::string &Name, |
| 1057 | Instruction *InsertBef) |
Reid Spencer | d84d35b | 2007-02-15 02:26:10 +0000 | [diff] [blame] | 1058 | : Instruction(cast<VectorType>(Val->getType())->getElementType(), |
Chris Lattner | 2195fc4 | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 1059 | ExtractElement, Ops, 2, InsertBef) { |
Reid Spencer | 8d9336d | 2006-12-31 05:26:44 +0000 | [diff] [blame] | 1060 | Constant *Index = ConstantInt::get(Type::Int32Ty, IndexV); |
Chris Lattner | 65511ff | 2006-10-05 06:24:58 +0000 | [diff] [blame] | 1061 | assert(isValidOperands(Val, Index) && |
| 1062 | "Invalid extractelement instruction operands!"); |
| 1063 | Ops[0].init(Val, this); |
| 1064 | Ops[1].init(Index, this); |
Chris Lattner | 2195fc4 | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 1065 | setName(Name); |
Chris Lattner | 65511ff | 2006-10-05 06:24:58 +0000 | [diff] [blame] | 1066 | } |
| 1067 | |
| 1068 | |
Robert Bocchino | 2300448 | 2006-01-10 19:05:34 +0000 | [diff] [blame] | 1069 | ExtractElementInst::ExtractElementInst(Value *Val, Value *Index, |
Chris Lattner | bbe0a42 | 2006-04-08 01:18:18 +0000 | [diff] [blame] | 1070 | const std::string &Name, |
| 1071 | BasicBlock *InsertAE) |
Reid Spencer | d84d35b | 2007-02-15 02:26:10 +0000 | [diff] [blame] | 1072 | : Instruction(cast<VectorType>(Val->getType())->getElementType(), |
Chris Lattner | 2195fc4 | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 1073 | ExtractElement, Ops, 2, InsertAE) { |
Chris Lattner | 54865b3 | 2006-04-08 04:05:48 +0000 | [diff] [blame] | 1074 | assert(isValidOperands(Val, Index) && |
| 1075 | "Invalid extractelement instruction operands!"); |
| 1076 | |
Robert Bocchino | 2300448 | 2006-01-10 19:05:34 +0000 | [diff] [blame] | 1077 | Ops[0].init(Val, this); |
| 1078 | Ops[1].init(Index, this); |
Chris Lattner | 2195fc4 | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 1079 | setName(Name); |
Robert Bocchino | 2300448 | 2006-01-10 19:05:34 +0000 | [diff] [blame] | 1080 | } |
| 1081 | |
Chris Lattner | 65511ff | 2006-10-05 06:24:58 +0000 | [diff] [blame] | 1082 | ExtractElementInst::ExtractElementInst(Value *Val, unsigned IndexV, |
| 1083 | const std::string &Name, |
| 1084 | BasicBlock *InsertAE) |
Reid Spencer | d84d35b | 2007-02-15 02:26:10 +0000 | [diff] [blame] | 1085 | : Instruction(cast<VectorType>(Val->getType())->getElementType(), |
Chris Lattner | 2195fc4 | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 1086 | ExtractElement, Ops, 2, InsertAE) { |
Reid Spencer | 8d9336d | 2006-12-31 05:26:44 +0000 | [diff] [blame] | 1087 | Constant *Index = ConstantInt::get(Type::Int32Ty, IndexV); |
Chris Lattner | 65511ff | 2006-10-05 06:24:58 +0000 | [diff] [blame] | 1088 | assert(isValidOperands(Val, Index) && |
| 1089 | "Invalid extractelement instruction operands!"); |
| 1090 | |
| 1091 | Ops[0].init(Val, this); |
| 1092 | Ops[1].init(Index, this); |
Chris Lattner | 2195fc4 | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 1093 | setName(Name); |
Chris Lattner | 65511ff | 2006-10-05 06:24:58 +0000 | [diff] [blame] | 1094 | } |
| 1095 | |
| 1096 | |
Chris Lattner | 54865b3 | 2006-04-08 04:05:48 +0000 | [diff] [blame] | 1097 | bool ExtractElementInst::isValidOperands(const Value *Val, const Value *Index) { |
Reid Spencer | d84d35b | 2007-02-15 02:26:10 +0000 | [diff] [blame] | 1098 | if (!isa<VectorType>(Val->getType()) || Index->getType() != Type::Int32Ty) |
Chris Lattner | 54865b3 | 2006-04-08 04:05:48 +0000 | [diff] [blame] | 1099 | return false; |
| 1100 | return true; |
| 1101 | } |
| 1102 | |
| 1103 | |
Robert Bocchino | 2300448 | 2006-01-10 19:05:34 +0000 | [diff] [blame] | 1104 | //===----------------------------------------------------------------------===// |
Robert Bocchino | ca27f03 | 2006-01-17 20:07:22 +0000 | [diff] [blame] | 1105 | // InsertElementInst Implementation |
| 1106 | //===----------------------------------------------------------------------===// |
| 1107 | |
Chris Lattner | 0875d94 | 2006-04-14 22:20:32 +0000 | [diff] [blame] | 1108 | InsertElementInst::InsertElementInst(const InsertElementInst &IE) |
| 1109 | : Instruction(IE.getType(), InsertElement, Ops, 3) { |
| 1110 | Ops[0].init(IE.Ops[0], this); |
| 1111 | Ops[1].init(IE.Ops[1], this); |
| 1112 | Ops[2].init(IE.Ops[2], this); |
| 1113 | } |
Chris Lattner | 54865b3 | 2006-04-08 04:05:48 +0000 | [diff] [blame] | 1114 | InsertElementInst::InsertElementInst(Value *Vec, Value *Elt, Value *Index, |
Chris Lattner | bbe0a42 | 2006-04-08 01:18:18 +0000 | [diff] [blame] | 1115 | const std::string &Name, |
| 1116 | Instruction *InsertBef) |
Chris Lattner | 2195fc4 | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 1117 | : Instruction(Vec->getType(), InsertElement, Ops, 3, InsertBef) { |
Chris Lattner | 54865b3 | 2006-04-08 04:05:48 +0000 | [diff] [blame] | 1118 | assert(isValidOperands(Vec, Elt, Index) && |
| 1119 | "Invalid insertelement instruction operands!"); |
| 1120 | Ops[0].init(Vec, this); |
Robert Bocchino | ca27f03 | 2006-01-17 20:07:22 +0000 | [diff] [blame] | 1121 | Ops[1].init(Elt, this); |
| 1122 | Ops[2].init(Index, this); |
Chris Lattner | 2195fc4 | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 1123 | setName(Name); |
Robert Bocchino | ca27f03 | 2006-01-17 20:07:22 +0000 | [diff] [blame] | 1124 | } |
| 1125 | |
Chris Lattner | 65511ff | 2006-10-05 06:24:58 +0000 | [diff] [blame] | 1126 | InsertElementInst::InsertElementInst(Value *Vec, Value *Elt, unsigned IndexV, |
| 1127 | const std::string &Name, |
| 1128 | Instruction *InsertBef) |
Chris Lattner | 2195fc4 | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 1129 | : Instruction(Vec->getType(), InsertElement, Ops, 3, InsertBef) { |
Reid Spencer | 8d9336d | 2006-12-31 05:26:44 +0000 | [diff] [blame] | 1130 | Constant *Index = ConstantInt::get(Type::Int32Ty, IndexV); |
Chris Lattner | 65511ff | 2006-10-05 06:24:58 +0000 | [diff] [blame] | 1131 | assert(isValidOperands(Vec, Elt, Index) && |
| 1132 | "Invalid insertelement instruction operands!"); |
| 1133 | Ops[0].init(Vec, this); |
| 1134 | Ops[1].init(Elt, this); |
| 1135 | Ops[2].init(Index, this); |
Chris Lattner | 2195fc4 | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 1136 | setName(Name); |
Chris Lattner | 65511ff | 2006-10-05 06:24:58 +0000 | [diff] [blame] | 1137 | } |
| 1138 | |
| 1139 | |
Chris Lattner | 54865b3 | 2006-04-08 04:05:48 +0000 | [diff] [blame] | 1140 | InsertElementInst::InsertElementInst(Value *Vec, Value *Elt, Value *Index, |
Chris Lattner | bbe0a42 | 2006-04-08 01:18:18 +0000 | [diff] [blame] | 1141 | const std::string &Name, |
| 1142 | BasicBlock *InsertAE) |
Chris Lattner | 2195fc4 | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 1143 | : Instruction(Vec->getType(), InsertElement, Ops, 3, InsertAE) { |
Chris Lattner | 54865b3 | 2006-04-08 04:05:48 +0000 | [diff] [blame] | 1144 | assert(isValidOperands(Vec, Elt, Index) && |
| 1145 | "Invalid insertelement instruction operands!"); |
| 1146 | |
| 1147 | Ops[0].init(Vec, this); |
Robert Bocchino | ca27f03 | 2006-01-17 20:07:22 +0000 | [diff] [blame] | 1148 | Ops[1].init(Elt, this); |
| 1149 | Ops[2].init(Index, this); |
Chris Lattner | 2195fc4 | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 1150 | setName(Name); |
Robert Bocchino | ca27f03 | 2006-01-17 20:07:22 +0000 | [diff] [blame] | 1151 | } |
| 1152 | |
Chris Lattner | 65511ff | 2006-10-05 06:24:58 +0000 | [diff] [blame] | 1153 | InsertElementInst::InsertElementInst(Value *Vec, Value *Elt, unsigned IndexV, |
| 1154 | const std::string &Name, |
| 1155 | BasicBlock *InsertAE) |
Chris Lattner | 2195fc4 | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 1156 | : Instruction(Vec->getType(), InsertElement, Ops, 3, InsertAE) { |
Reid Spencer | 8d9336d | 2006-12-31 05:26:44 +0000 | [diff] [blame] | 1157 | Constant *Index = ConstantInt::get(Type::Int32Ty, IndexV); |
Chris Lattner | 65511ff | 2006-10-05 06:24:58 +0000 | [diff] [blame] | 1158 | assert(isValidOperands(Vec, Elt, Index) && |
| 1159 | "Invalid insertelement instruction operands!"); |
| 1160 | |
| 1161 | Ops[0].init(Vec, this); |
| 1162 | Ops[1].init(Elt, this); |
| 1163 | Ops[2].init(Index, this); |
Chris Lattner | 2195fc4 | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 1164 | setName(Name); |
Chris Lattner | 65511ff | 2006-10-05 06:24:58 +0000 | [diff] [blame] | 1165 | } |
| 1166 | |
Chris Lattner | 54865b3 | 2006-04-08 04:05:48 +0000 | [diff] [blame] | 1167 | bool InsertElementInst::isValidOperands(const Value *Vec, const Value *Elt, |
| 1168 | const Value *Index) { |
Reid Spencer | d84d35b | 2007-02-15 02:26:10 +0000 | [diff] [blame] | 1169 | if (!isa<VectorType>(Vec->getType())) |
Reid Spencer | 09575ba | 2007-02-15 03:39:18 +0000 | [diff] [blame] | 1170 | return false; // First operand of insertelement must be vector type. |
Chris Lattner | 54865b3 | 2006-04-08 04:05:48 +0000 | [diff] [blame] | 1171 | |
Reid Spencer | d84d35b | 2007-02-15 02:26:10 +0000 | [diff] [blame] | 1172 | if (Elt->getType() != cast<VectorType>(Vec->getType())->getElementType()) |
Dan Gohman | fead797 | 2007-05-11 21:43:24 +0000 | [diff] [blame] | 1173 | return false;// Second operand of insertelement must be vector element type. |
Chris Lattner | 54865b3 | 2006-04-08 04:05:48 +0000 | [diff] [blame] | 1174 | |
Reid Spencer | 8d9336d | 2006-12-31 05:26:44 +0000 | [diff] [blame] | 1175 | if (Index->getType() != Type::Int32Ty) |
Chris Lattner | 54865b3 | 2006-04-08 04:05:48 +0000 | [diff] [blame] | 1176 | return false; // Third operand of insertelement must be uint. |
| 1177 | return true; |
| 1178 | } |
| 1179 | |
| 1180 | |
Robert Bocchino | ca27f03 | 2006-01-17 20:07:22 +0000 | [diff] [blame] | 1181 | //===----------------------------------------------------------------------===// |
Chris Lattner | bbe0a42 | 2006-04-08 01:18:18 +0000 | [diff] [blame] | 1182 | // ShuffleVectorInst Implementation |
| 1183 | //===----------------------------------------------------------------------===// |
| 1184 | |
Chris Lattner | 0875d94 | 2006-04-14 22:20:32 +0000 | [diff] [blame] | 1185 | ShuffleVectorInst::ShuffleVectorInst(const ShuffleVectorInst &SV) |
| 1186 | : Instruction(SV.getType(), ShuffleVector, Ops, 3) { |
| 1187 | Ops[0].init(SV.Ops[0], this); |
| 1188 | Ops[1].init(SV.Ops[1], this); |
| 1189 | Ops[2].init(SV.Ops[2], this); |
| 1190 | } |
| 1191 | |
Chris Lattner | bbe0a42 | 2006-04-08 01:18:18 +0000 | [diff] [blame] | 1192 | ShuffleVectorInst::ShuffleVectorInst(Value *V1, Value *V2, Value *Mask, |
| 1193 | const std::string &Name, |
| 1194 | Instruction *InsertBefore) |
Chris Lattner | 2195fc4 | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 1195 | : Instruction(V1->getType(), ShuffleVector, Ops, 3, InsertBefore) { |
Chris Lattner | bbe0a42 | 2006-04-08 01:18:18 +0000 | [diff] [blame] | 1196 | assert(isValidOperands(V1, V2, Mask) && |
| 1197 | "Invalid shuffle vector instruction operands!"); |
| 1198 | Ops[0].init(V1, this); |
| 1199 | Ops[1].init(V2, this); |
| 1200 | Ops[2].init(Mask, this); |
Chris Lattner | 2195fc4 | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 1201 | setName(Name); |
Chris Lattner | bbe0a42 | 2006-04-08 01:18:18 +0000 | [diff] [blame] | 1202 | } |
| 1203 | |
| 1204 | ShuffleVectorInst::ShuffleVectorInst(Value *V1, Value *V2, Value *Mask, |
| 1205 | const std::string &Name, |
| 1206 | BasicBlock *InsertAtEnd) |
Chris Lattner | 2195fc4 | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 1207 | : Instruction(V1->getType(), ShuffleVector, Ops, 3, InsertAtEnd) { |
Chris Lattner | bbe0a42 | 2006-04-08 01:18:18 +0000 | [diff] [blame] | 1208 | assert(isValidOperands(V1, V2, Mask) && |
| 1209 | "Invalid shuffle vector instruction operands!"); |
| 1210 | |
| 1211 | Ops[0].init(V1, this); |
| 1212 | Ops[1].init(V2, this); |
| 1213 | Ops[2].init(Mask, this); |
Chris Lattner | 2195fc4 | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 1214 | setName(Name); |
Chris Lattner | bbe0a42 | 2006-04-08 01:18:18 +0000 | [diff] [blame] | 1215 | } |
| 1216 | |
| 1217 | bool ShuffleVectorInst::isValidOperands(const Value *V1, const Value *V2, |
| 1218 | const Value *Mask) { |
Reid Spencer | d84d35b | 2007-02-15 02:26:10 +0000 | [diff] [blame] | 1219 | if (!isa<VectorType>(V1->getType())) return false; |
Chris Lattner | bbe0a42 | 2006-04-08 01:18:18 +0000 | [diff] [blame] | 1220 | if (V1->getType() != V2->getType()) return false; |
Reid Spencer | d84d35b | 2007-02-15 02:26:10 +0000 | [diff] [blame] | 1221 | if (!isa<VectorType>(Mask->getType()) || |
| 1222 | cast<VectorType>(Mask->getType())->getElementType() != Type::Int32Ty || |
| 1223 | cast<VectorType>(Mask->getType())->getNumElements() != |
| 1224 | cast<VectorType>(V1->getType())->getNumElements()) |
Chris Lattner | bbe0a42 | 2006-04-08 01:18:18 +0000 | [diff] [blame] | 1225 | return false; |
| 1226 | return true; |
| 1227 | } |
| 1228 | |
| 1229 | |
| 1230 | //===----------------------------------------------------------------------===// |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 1231 | // BinaryOperator Class |
| 1232 | //===----------------------------------------------------------------------===// |
| 1233 | |
Chris Lattner | 2195fc4 | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 1234 | BinaryOperator::BinaryOperator(BinaryOps iType, Value *S1, Value *S2, |
| 1235 | const Type *Ty, const std::string &Name, |
| 1236 | Instruction *InsertBefore) |
| 1237 | : Instruction(Ty, iType, Ops, 2, InsertBefore) { |
| 1238 | Ops[0].init(S1, this); |
| 1239 | Ops[1].init(S2, this); |
| 1240 | init(iType); |
| 1241 | setName(Name); |
| 1242 | } |
| 1243 | |
| 1244 | BinaryOperator::BinaryOperator(BinaryOps iType, Value *S1, Value *S2, |
| 1245 | const Type *Ty, const std::string &Name, |
| 1246 | BasicBlock *InsertAtEnd) |
| 1247 | : Instruction(Ty, iType, Ops, 2, InsertAtEnd) { |
| 1248 | Ops[0].init(S1, this); |
| 1249 | Ops[1].init(S2, this); |
| 1250 | init(iType); |
| 1251 | setName(Name); |
| 1252 | } |
| 1253 | |
| 1254 | |
| 1255 | void BinaryOperator::init(BinaryOps iType) { |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 1256 | Value *LHS = getOperand(0), *RHS = getOperand(1); |
Chris Lattner | f14c76c | 2007-02-01 04:59:37 +0000 | [diff] [blame] | 1257 | LHS = LHS; RHS = RHS; // Silence warnings. |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 1258 | assert(LHS->getType() == RHS->getType() && |
| 1259 | "Binary operator operand types must match!"); |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 1260 | #ifndef NDEBUG |
| 1261 | switch (iType) { |
| 1262 | case Add: case Sub: |
Reid Spencer | 7e80b0b | 2006-10-26 06:15:43 +0000 | [diff] [blame] | 1263 | case Mul: |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 1264 | assert(getType() == LHS->getType() && |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 1265 | "Arithmetic operation should return same type as operands!"); |
Chris Lattner | 03c4953 | 2007-01-15 02:27:26 +0000 | [diff] [blame] | 1266 | assert((getType()->isInteger() || getType()->isFloatingPoint() || |
Reid Spencer | d84d35b | 2007-02-15 02:26:10 +0000 | [diff] [blame] | 1267 | isa<VectorType>(getType())) && |
Brian Gaeke | 0220904 | 2004-08-20 06:00:58 +0000 | [diff] [blame] | 1268 | "Tried to create an arithmetic operation on a non-arithmetic type!"); |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 1269 | break; |
Reid Spencer | 7e80b0b | 2006-10-26 06:15:43 +0000 | [diff] [blame] | 1270 | case UDiv: |
| 1271 | case SDiv: |
| 1272 | assert(getType() == LHS->getType() && |
| 1273 | "Arithmetic operation should return same type as operands!"); |
Reid Spencer | d84d35b | 2007-02-15 02:26:10 +0000 | [diff] [blame] | 1274 | assert((getType()->isInteger() || (isa<VectorType>(getType()) && |
| 1275 | cast<VectorType>(getType())->getElementType()->isInteger())) && |
Reid Spencer | 7e80b0b | 2006-10-26 06:15:43 +0000 | [diff] [blame] | 1276 | "Incorrect operand type (not integer) for S/UDIV"); |
| 1277 | break; |
| 1278 | case FDiv: |
| 1279 | assert(getType() == LHS->getType() && |
| 1280 | "Arithmetic operation should return same type as operands!"); |
Reid Spencer | d84d35b | 2007-02-15 02:26:10 +0000 | [diff] [blame] | 1281 | assert((getType()->isFloatingPoint() || (isa<VectorType>(getType()) && |
| 1282 | cast<VectorType>(getType())->getElementType()->isFloatingPoint())) |
Reid Spencer | 7e80b0b | 2006-10-26 06:15:43 +0000 | [diff] [blame] | 1283 | && "Incorrect operand type (not floating point) for FDIV"); |
| 1284 | break; |
Reid Spencer | 7eb55b3 | 2006-11-02 01:53:59 +0000 | [diff] [blame] | 1285 | case URem: |
| 1286 | case SRem: |
| 1287 | assert(getType() == LHS->getType() && |
| 1288 | "Arithmetic operation should return same type as operands!"); |
Reid Spencer | d84d35b | 2007-02-15 02:26:10 +0000 | [diff] [blame] | 1289 | assert((getType()->isInteger() || (isa<VectorType>(getType()) && |
| 1290 | cast<VectorType>(getType())->getElementType()->isInteger())) && |
Reid Spencer | 7eb55b3 | 2006-11-02 01:53:59 +0000 | [diff] [blame] | 1291 | "Incorrect operand type (not integer) for S/UREM"); |
| 1292 | break; |
| 1293 | case FRem: |
| 1294 | assert(getType() == LHS->getType() && |
| 1295 | "Arithmetic operation should return same type as operands!"); |
Reid Spencer | d84d35b | 2007-02-15 02:26:10 +0000 | [diff] [blame] | 1296 | assert((getType()->isFloatingPoint() || (isa<VectorType>(getType()) && |
| 1297 | cast<VectorType>(getType())->getElementType()->isFloatingPoint())) |
Reid Spencer | 7eb55b3 | 2006-11-02 01:53:59 +0000 | [diff] [blame] | 1298 | && "Incorrect operand type (not floating point) for FREM"); |
| 1299 | break; |
Reid Spencer | 2341c22 | 2007-02-02 02:16:23 +0000 | [diff] [blame] | 1300 | case Shl: |
| 1301 | case LShr: |
| 1302 | case AShr: |
| 1303 | assert(getType() == LHS->getType() && |
| 1304 | "Shift operation should return same type as operands!"); |
| 1305 | assert(getType()->isInteger() && |
| 1306 | "Shift operation requires integer operands"); |
| 1307 | break; |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 1308 | case And: case Or: |
| 1309 | case Xor: |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 1310 | assert(getType() == LHS->getType() && |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 1311 | "Logical operation should return same type as operands!"); |
Chris Lattner | 03c4953 | 2007-01-15 02:27:26 +0000 | [diff] [blame] | 1312 | assert((getType()->isInteger() || |
Reid Spencer | d84d35b | 2007-02-15 02:26:10 +0000 | [diff] [blame] | 1313 | (isa<VectorType>(getType()) && |
| 1314 | cast<VectorType>(getType())->getElementType()->isInteger())) && |
Misha Brukman | 3852f65 | 2005-01-27 06:46:38 +0000 | [diff] [blame] | 1315 | "Tried to create a logical operation on a non-integral type!"); |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 1316 | break; |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 1317 | default: |
| 1318 | break; |
| 1319 | } |
| 1320 | #endif |
| 1321 | } |
| 1322 | |
| 1323 | BinaryOperator *BinaryOperator::create(BinaryOps Op, Value *S1, Value *S2, |
Misha Brukman | 96eb878 | 2005-03-16 05:42:00 +0000 | [diff] [blame] | 1324 | const std::string &Name, |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 1325 | Instruction *InsertBefore) { |
| 1326 | assert(S1->getType() == S2->getType() && |
| 1327 | "Cannot create binary operator with two operands of differing type!"); |
Reid Spencer | 266e42b | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 1328 | return new BinaryOperator(Op, S1, S2, S1->getType(), Name, InsertBefore); |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 1329 | } |
| 1330 | |
| 1331 | BinaryOperator *BinaryOperator::create(BinaryOps Op, Value *S1, Value *S2, |
Misha Brukman | 96eb878 | 2005-03-16 05:42:00 +0000 | [diff] [blame] | 1332 | const std::string &Name, |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 1333 | BasicBlock *InsertAtEnd) { |
| 1334 | BinaryOperator *Res = create(Op, S1, S2, Name); |
| 1335 | InsertAtEnd->getInstList().push_back(Res); |
| 1336 | return Res; |
| 1337 | } |
| 1338 | |
| 1339 | BinaryOperator *BinaryOperator::createNeg(Value *Op, const std::string &Name, |
| 1340 | Instruction *InsertBefore) { |
Reid Spencer | 2eadb53 | 2007-01-21 00:29:26 +0000 | [diff] [blame] | 1341 | Value *zero = ConstantExpr::getZeroValueForNegationExpr(Op->getType()); |
| 1342 | return new BinaryOperator(Instruction::Sub, |
| 1343 | zero, Op, |
| 1344 | Op->getType(), Name, InsertBefore); |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 1345 | } |
| 1346 | |
| 1347 | BinaryOperator *BinaryOperator::createNeg(Value *Op, const std::string &Name, |
| 1348 | BasicBlock *InsertAtEnd) { |
Reid Spencer | 2eadb53 | 2007-01-21 00:29:26 +0000 | [diff] [blame] | 1349 | Value *zero = ConstantExpr::getZeroValueForNegationExpr(Op->getType()); |
| 1350 | return new BinaryOperator(Instruction::Sub, |
| 1351 | zero, Op, |
| 1352 | Op->getType(), Name, InsertAtEnd); |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 1353 | } |
| 1354 | |
| 1355 | BinaryOperator *BinaryOperator::createNot(Value *Op, const std::string &Name, |
| 1356 | Instruction *InsertBefore) { |
Chris Lattner | e8e7ac4 | 2006-03-25 21:54:21 +0000 | [diff] [blame] | 1357 | Constant *C; |
Reid Spencer | d84d35b | 2007-02-15 02:26:10 +0000 | [diff] [blame] | 1358 | if (const VectorType *PTy = dyn_cast<VectorType>(Op->getType())) { |
Zhou Sheng | 75b871f | 2007-01-11 12:24:14 +0000 | [diff] [blame] | 1359 | C = ConstantInt::getAllOnesValue(PTy->getElementType()); |
Reid Spencer | d84d35b | 2007-02-15 02:26:10 +0000 | [diff] [blame] | 1360 | C = ConstantVector::get(std::vector<Constant*>(PTy->getNumElements(), C)); |
Chris Lattner | e8e7ac4 | 2006-03-25 21:54:21 +0000 | [diff] [blame] | 1361 | } else { |
Zhou Sheng | 75b871f | 2007-01-11 12:24:14 +0000 | [diff] [blame] | 1362 | C = ConstantInt::getAllOnesValue(Op->getType()); |
Chris Lattner | e8e7ac4 | 2006-03-25 21:54:21 +0000 | [diff] [blame] | 1363 | } |
| 1364 | |
| 1365 | return new BinaryOperator(Instruction::Xor, Op, C, |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 1366 | Op->getType(), Name, InsertBefore); |
| 1367 | } |
| 1368 | |
| 1369 | BinaryOperator *BinaryOperator::createNot(Value *Op, const std::string &Name, |
| 1370 | BasicBlock *InsertAtEnd) { |
Chris Lattner | dca56cb | 2005-12-21 18:22:19 +0000 | [diff] [blame] | 1371 | Constant *AllOnes; |
Reid Spencer | d84d35b | 2007-02-15 02:26:10 +0000 | [diff] [blame] | 1372 | if (const VectorType *PTy = dyn_cast<VectorType>(Op->getType())) { |
Chris Lattner | dca56cb | 2005-12-21 18:22:19 +0000 | [diff] [blame] | 1373 | // Create a vector of all ones values. |
Zhou Sheng | 75b871f | 2007-01-11 12:24:14 +0000 | [diff] [blame] | 1374 | Constant *Elt = ConstantInt::getAllOnesValue(PTy->getElementType()); |
Chris Lattner | dca56cb | 2005-12-21 18:22:19 +0000 | [diff] [blame] | 1375 | AllOnes = |
Reid Spencer | d84d35b | 2007-02-15 02:26:10 +0000 | [diff] [blame] | 1376 | ConstantVector::get(std::vector<Constant*>(PTy->getNumElements(), Elt)); |
Chris Lattner | dca56cb | 2005-12-21 18:22:19 +0000 | [diff] [blame] | 1377 | } else { |
Zhou Sheng | 75b871f | 2007-01-11 12:24:14 +0000 | [diff] [blame] | 1378 | AllOnes = ConstantInt::getAllOnesValue(Op->getType()); |
Chris Lattner | dca56cb | 2005-12-21 18:22:19 +0000 | [diff] [blame] | 1379 | } |
| 1380 | |
| 1381 | return new BinaryOperator(Instruction::Xor, Op, AllOnes, |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 1382 | Op->getType(), Name, InsertAtEnd); |
| 1383 | } |
| 1384 | |
| 1385 | |
| 1386 | // isConstantAllOnes - Helper function for several functions below |
| 1387 | static inline bool isConstantAllOnes(const Value *V) { |
Chris Lattner | 1edec38 | 2007-06-15 06:04:24 +0000 | [diff] [blame] | 1388 | if (const ConstantInt *CI = dyn_cast<ConstantInt>(V)) |
| 1389 | return CI->isAllOnesValue(); |
| 1390 | if (const ConstantVector *CV = dyn_cast<ConstantVector>(V)) |
| 1391 | return CV->isAllOnesValue(); |
| 1392 | return false; |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 1393 | } |
| 1394 | |
| 1395 | bool BinaryOperator::isNeg(const Value *V) { |
| 1396 | if (const BinaryOperator *Bop = dyn_cast<BinaryOperator>(V)) |
| 1397 | if (Bop->getOpcode() == Instruction::Sub) |
Reid Spencer | 2eadb53 | 2007-01-21 00:29:26 +0000 | [diff] [blame] | 1398 | return Bop->getOperand(0) == |
| 1399 | ConstantExpr::getZeroValueForNegationExpr(Bop->getType()); |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 1400 | return false; |
| 1401 | } |
| 1402 | |
| 1403 | bool BinaryOperator::isNot(const Value *V) { |
| 1404 | if (const BinaryOperator *Bop = dyn_cast<BinaryOperator>(V)) |
| 1405 | return (Bop->getOpcode() == Instruction::Xor && |
| 1406 | (isConstantAllOnes(Bop->getOperand(1)) || |
| 1407 | isConstantAllOnes(Bop->getOperand(0)))); |
| 1408 | return false; |
| 1409 | } |
| 1410 | |
Chris Lattner | 2c7d177 | 2005-04-24 07:28:37 +0000 | [diff] [blame] | 1411 | Value *BinaryOperator::getNegArgument(Value *BinOp) { |
| 1412 | assert(isNeg(BinOp) && "getNegArgument from non-'neg' instruction!"); |
| 1413 | return cast<BinaryOperator>(BinOp)->getOperand(1); |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 1414 | } |
| 1415 | |
Chris Lattner | 2c7d177 | 2005-04-24 07:28:37 +0000 | [diff] [blame] | 1416 | const Value *BinaryOperator::getNegArgument(const Value *BinOp) { |
| 1417 | return getNegArgument(const_cast<Value*>(BinOp)); |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 1418 | } |
| 1419 | |
Chris Lattner | 2c7d177 | 2005-04-24 07:28:37 +0000 | [diff] [blame] | 1420 | Value *BinaryOperator::getNotArgument(Value *BinOp) { |
| 1421 | assert(isNot(BinOp) && "getNotArgument on non-'not' instruction!"); |
| 1422 | BinaryOperator *BO = cast<BinaryOperator>(BinOp); |
| 1423 | Value *Op0 = BO->getOperand(0); |
| 1424 | Value *Op1 = BO->getOperand(1); |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 1425 | if (isConstantAllOnes(Op0)) return Op1; |
| 1426 | |
| 1427 | assert(isConstantAllOnes(Op1)); |
| 1428 | return Op0; |
| 1429 | } |
| 1430 | |
Chris Lattner | 2c7d177 | 2005-04-24 07:28:37 +0000 | [diff] [blame] | 1431 | const Value *BinaryOperator::getNotArgument(const Value *BinOp) { |
| 1432 | return getNotArgument(const_cast<Value*>(BinOp)); |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 1433 | } |
| 1434 | |
| 1435 | |
| 1436 | // swapOperands - Exchange the two operands to this instruction. This |
| 1437 | // instruction is safe to use on any binary instruction and does not |
| 1438 | // modify the semantics of the instruction. If the instruction is |
| 1439 | // order dependent (SetLT f.e.) the opcode is changed. |
| 1440 | // |
| 1441 | bool BinaryOperator::swapOperands() { |
Reid Spencer | 266e42b | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 1442 | if (!isCommutative()) |
| 1443 | return true; // Can't commute operands |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 1444 | std::swap(Ops[0], Ops[1]); |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 1445 | return false; |
| 1446 | } |
| 1447 | |
Chris Lattner | b0b8ddd | 2006-09-18 04:54:57 +0000 | [diff] [blame] | 1448 | //===----------------------------------------------------------------------===// |
| 1449 | // CastInst Class |
| 1450 | //===----------------------------------------------------------------------===// |
| 1451 | |
Reid Spencer | 6c38f0b | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 1452 | // Just determine if this cast only deals with integral->integral conversion. |
| 1453 | bool CastInst::isIntegerCast() const { |
| 1454 | switch (getOpcode()) { |
| 1455 | default: return false; |
| 1456 | case Instruction::ZExt: |
| 1457 | case Instruction::SExt: |
| 1458 | case Instruction::Trunc: |
| 1459 | return true; |
| 1460 | case Instruction::BitCast: |
Chris Lattner | 03c4953 | 2007-01-15 02:27:26 +0000 | [diff] [blame] | 1461 | return getOperand(0)->getType()->isInteger() && getType()->isInteger(); |
Reid Spencer | 6c38f0b | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 1462 | } |
Chris Lattner | b0b8ddd | 2006-09-18 04:54:57 +0000 | [diff] [blame] | 1463 | } |
| 1464 | |
Reid Spencer | 6c38f0b | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 1465 | bool CastInst::isLosslessCast() const { |
| 1466 | // Only BitCast can be lossless, exit fast if we're not BitCast |
| 1467 | if (getOpcode() != Instruction::BitCast) |
| 1468 | return false; |
| 1469 | |
| 1470 | // Identity cast is always lossless |
| 1471 | const Type* SrcTy = getOperand(0)->getType(); |
| 1472 | const Type* DstTy = getType(); |
| 1473 | if (SrcTy == DstTy) |
| 1474 | return true; |
| 1475 | |
Reid Spencer | 8d9336d | 2006-12-31 05:26:44 +0000 | [diff] [blame] | 1476 | // Pointer to pointer is always lossless. |
| 1477 | if (isa<PointerType>(SrcTy)) |
| 1478 | return isa<PointerType>(DstTy); |
Reid Spencer | 6c38f0b | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 1479 | return false; // Other types have no identity values |
| 1480 | } |
| 1481 | |
| 1482 | /// This function determines if the CastInst does not require any bits to be |
| 1483 | /// changed in order to effect the cast. Essentially, it identifies cases where |
| 1484 | /// no code gen is necessary for the cast, hence the name no-op cast. For |
| 1485 | /// example, the following are all no-op casts: |
| 1486 | /// # bitcast uint %X, int |
| 1487 | /// # bitcast uint* %x, sbyte* |
Dan Gohman | fead797 | 2007-05-11 21:43:24 +0000 | [diff] [blame] | 1488 | /// # bitcast vector< 2 x int > %x, vector< 4 x short> |
Reid Spencer | 6c38f0b | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 1489 | /// # ptrtoint uint* %x, uint ; on 32-bit plaforms only |
| 1490 | /// @brief Determine if a cast is a no-op. |
| 1491 | bool CastInst::isNoopCast(const Type *IntPtrTy) const { |
| 1492 | switch (getOpcode()) { |
| 1493 | default: |
| 1494 | assert(!"Invalid CastOp"); |
| 1495 | case Instruction::Trunc: |
| 1496 | case Instruction::ZExt: |
| 1497 | case Instruction::SExt: |
| 1498 | case Instruction::FPTrunc: |
| 1499 | case Instruction::FPExt: |
| 1500 | case Instruction::UIToFP: |
| 1501 | case Instruction::SIToFP: |
| 1502 | case Instruction::FPToUI: |
| 1503 | case Instruction::FPToSI: |
| 1504 | return false; // These always modify bits |
| 1505 | case Instruction::BitCast: |
| 1506 | return true; // BitCast never modifies bits. |
| 1507 | case Instruction::PtrToInt: |
| 1508 | return IntPtrTy->getPrimitiveSizeInBits() == |
| 1509 | getType()->getPrimitiveSizeInBits(); |
| 1510 | case Instruction::IntToPtr: |
| 1511 | return IntPtrTy->getPrimitiveSizeInBits() == |
| 1512 | getOperand(0)->getType()->getPrimitiveSizeInBits(); |
| 1513 | } |
| 1514 | } |
| 1515 | |
| 1516 | /// This function determines if a pair of casts can be eliminated and what |
| 1517 | /// opcode should be used in the elimination. This assumes that there are two |
| 1518 | /// instructions like this: |
| 1519 | /// * %F = firstOpcode SrcTy %x to MidTy |
| 1520 | /// * %S = secondOpcode MidTy %F to DstTy |
| 1521 | /// The function returns a resultOpcode so these two casts can be replaced with: |
| 1522 | /// * %Replacement = resultOpcode %SrcTy %x to DstTy |
| 1523 | /// If no such cast is permited, the function returns 0. |
| 1524 | unsigned CastInst::isEliminableCastPair( |
| 1525 | Instruction::CastOps firstOp, Instruction::CastOps secondOp, |
| 1526 | const Type *SrcTy, const Type *MidTy, const Type *DstTy, const Type *IntPtrTy) |
| 1527 | { |
| 1528 | // Define the 144 possibilities for these two cast instructions. The values |
| 1529 | // in this matrix determine what to do in a given situation and select the |
| 1530 | // case in the switch below. The rows correspond to firstOp, the columns |
| 1531 | // correspond to secondOp. In looking at the table below, keep in mind |
| 1532 | // the following cast properties: |
| 1533 | // |
| 1534 | // Size Compare Source Destination |
| 1535 | // Operator Src ? Size Type Sign Type Sign |
| 1536 | // -------- ------------ ------------------- --------------------- |
| 1537 | // TRUNC > Integer Any Integral Any |
| 1538 | // ZEXT < Integral Unsigned Integer Any |
| 1539 | // SEXT < Integral Signed Integer Any |
| 1540 | // FPTOUI n/a FloatPt n/a Integral Unsigned |
| 1541 | // FPTOSI n/a FloatPt n/a Integral Signed |
| 1542 | // UITOFP n/a Integral Unsigned FloatPt n/a |
| 1543 | // SITOFP n/a Integral Signed FloatPt n/a |
| 1544 | // FPTRUNC > FloatPt n/a FloatPt n/a |
| 1545 | // FPEXT < FloatPt n/a FloatPt n/a |
| 1546 | // PTRTOINT n/a Pointer n/a Integral Unsigned |
| 1547 | // INTTOPTR n/a Integral Unsigned Pointer n/a |
| 1548 | // BITCONVERT = FirstClass n/a FirstClass n/a |
Chris Lattner | 6f6b497 | 2006-12-05 23:43:59 +0000 | [diff] [blame] | 1549 | // |
| 1550 | // NOTE: some transforms are safe, but we consider them to be non-profitable. |
| 1551 | // For example, we could merge "fptoui double to uint" + "zext uint to ulong", |
| 1552 | // into "fptoui double to ulong", but this loses information about the range |
| 1553 | // of the produced value (we no longer know the top-part is all zeros). |
| 1554 | // Further this conversion is often much more expensive for typical hardware, |
| 1555 | // and causes issues when building libgcc. We disallow fptosi+sext for the |
| 1556 | // same reason. |
Reid Spencer | 6c38f0b | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 1557 | const unsigned numCastOps = |
| 1558 | Instruction::CastOpsEnd - Instruction::CastOpsBegin; |
| 1559 | static const uint8_t CastResults[numCastOps][numCastOps] = { |
| 1560 | // T F F U S F F P I B -+ |
| 1561 | // R Z S P P I I T P 2 N T | |
| 1562 | // U E E 2 2 2 2 R E I T C +- secondOp |
| 1563 | // N X X U S F F N X N 2 V | |
| 1564 | // C T T I I P P C T T P T -+ |
| 1565 | { 1, 0, 0,99,99, 0, 0,99,99,99, 0, 3 }, // Trunc -+ |
| 1566 | { 8, 1, 9,99,99, 2, 0,99,99,99, 2, 3 }, // ZExt | |
| 1567 | { 8, 0, 1,99,99, 0, 2,99,99,99, 0, 3 }, // SExt | |
Chris Lattner | 6f6b497 | 2006-12-05 23:43:59 +0000 | [diff] [blame] | 1568 | { 0, 0, 0,99,99, 0, 0,99,99,99, 0, 3 }, // FPToUI | |
| 1569 | { 0, 0, 0,99,99, 0, 0,99,99,99, 0, 3 }, // FPToSI | |
Reid Spencer | 6c38f0b | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 1570 | { 99,99,99, 0, 0,99,99, 0, 0,99,99, 4 }, // UIToFP +- firstOp |
| 1571 | { 99,99,99, 0, 0,99,99, 0, 0,99,99, 4 }, // SIToFP | |
| 1572 | { 99,99,99, 0, 0,99,99, 1, 0,99,99, 4 }, // FPTrunc | |
| 1573 | { 99,99,99, 2, 2,99,99,10, 2,99,99, 4 }, // FPExt | |
| 1574 | { 1, 0, 0,99,99, 0, 0,99,99,99, 7, 3 }, // PtrToInt | |
| 1575 | { 99,99,99,99,99,99,99,99,99,13,99,12 }, // IntToPtr | |
| 1576 | { 5, 5, 5, 6, 6, 5, 5, 6, 6,11, 5, 1 }, // BitCast -+ |
| 1577 | }; |
| 1578 | |
| 1579 | int ElimCase = CastResults[firstOp-Instruction::CastOpsBegin] |
| 1580 | [secondOp-Instruction::CastOpsBegin]; |
| 1581 | switch (ElimCase) { |
| 1582 | case 0: |
| 1583 | // categorically disallowed |
| 1584 | return 0; |
| 1585 | case 1: |
| 1586 | // allowed, use first cast's opcode |
| 1587 | return firstOp; |
| 1588 | case 2: |
| 1589 | // allowed, use second cast's opcode |
| 1590 | return secondOp; |
| 1591 | case 3: |
| 1592 | // no-op cast in second op implies firstOp as long as the DestTy |
| 1593 | // is integer |
Chris Lattner | 03c4953 | 2007-01-15 02:27:26 +0000 | [diff] [blame] | 1594 | if (DstTy->isInteger()) |
Reid Spencer | 6c38f0b | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 1595 | return firstOp; |
| 1596 | return 0; |
| 1597 | case 4: |
| 1598 | // no-op cast in second op implies firstOp as long as the DestTy |
| 1599 | // is floating point |
| 1600 | if (DstTy->isFloatingPoint()) |
| 1601 | return firstOp; |
| 1602 | return 0; |
| 1603 | case 5: |
| 1604 | // no-op cast in first op implies secondOp as long as the SrcTy |
| 1605 | // is an integer |
Chris Lattner | 03c4953 | 2007-01-15 02:27:26 +0000 | [diff] [blame] | 1606 | if (SrcTy->isInteger()) |
Reid Spencer | 6c38f0b | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 1607 | return secondOp; |
| 1608 | return 0; |
| 1609 | case 6: |
| 1610 | // no-op cast in first op implies secondOp as long as the SrcTy |
| 1611 | // is a floating point |
| 1612 | if (SrcTy->isFloatingPoint()) |
| 1613 | return secondOp; |
| 1614 | return 0; |
| 1615 | case 7: { |
| 1616 | // ptrtoint, inttoptr -> bitcast (ptr -> ptr) if int size is >= ptr size |
| 1617 | unsigned PtrSize = IntPtrTy->getPrimitiveSizeInBits(); |
| 1618 | unsigned MidSize = MidTy->getPrimitiveSizeInBits(); |
| 1619 | if (MidSize >= PtrSize) |
| 1620 | return Instruction::BitCast; |
| 1621 | return 0; |
| 1622 | } |
| 1623 | case 8: { |
| 1624 | // ext, trunc -> bitcast, if the SrcTy and DstTy are same size |
| 1625 | // ext, trunc -> ext, if sizeof(SrcTy) < sizeof(DstTy) |
| 1626 | // ext, trunc -> trunc, if sizeof(SrcTy) > sizeof(DstTy) |
| 1627 | unsigned SrcSize = SrcTy->getPrimitiveSizeInBits(); |
| 1628 | unsigned DstSize = DstTy->getPrimitiveSizeInBits(); |
| 1629 | if (SrcSize == DstSize) |
| 1630 | return Instruction::BitCast; |
| 1631 | else if (SrcSize < DstSize) |
| 1632 | return firstOp; |
| 1633 | return secondOp; |
| 1634 | } |
| 1635 | case 9: // zext, sext -> zext, because sext can't sign extend after zext |
| 1636 | return Instruction::ZExt; |
| 1637 | case 10: |
| 1638 | // fpext followed by ftrunc is allowed if the bit size returned to is |
| 1639 | // the same as the original, in which case its just a bitcast |
| 1640 | if (SrcTy == DstTy) |
| 1641 | return Instruction::BitCast; |
| 1642 | return 0; // If the types are not the same we can't eliminate it. |
| 1643 | case 11: |
| 1644 | // bitcast followed by ptrtoint is allowed as long as the bitcast |
| 1645 | // is a pointer to pointer cast. |
| 1646 | if (isa<PointerType>(SrcTy) && isa<PointerType>(MidTy)) |
| 1647 | return secondOp; |
| 1648 | return 0; |
| 1649 | case 12: |
| 1650 | // inttoptr, bitcast -> intptr if bitcast is a ptr to ptr cast |
| 1651 | if (isa<PointerType>(MidTy) && isa<PointerType>(DstTy)) |
| 1652 | return firstOp; |
| 1653 | return 0; |
| 1654 | case 13: { |
| 1655 | // inttoptr, ptrtoint -> bitcast if SrcSize<=PtrSize and SrcSize==DstSize |
| 1656 | unsigned PtrSize = IntPtrTy->getPrimitiveSizeInBits(); |
| 1657 | unsigned SrcSize = SrcTy->getPrimitiveSizeInBits(); |
| 1658 | unsigned DstSize = DstTy->getPrimitiveSizeInBits(); |
| 1659 | if (SrcSize <= PtrSize && SrcSize == DstSize) |
| 1660 | return Instruction::BitCast; |
| 1661 | return 0; |
| 1662 | } |
| 1663 | case 99: |
| 1664 | // cast combination can't happen (error in input). This is for all cases |
| 1665 | // where the MidTy is not the same for the two cast instructions. |
| 1666 | assert(!"Invalid Cast Combination"); |
| 1667 | return 0; |
| 1668 | default: |
| 1669 | assert(!"Error in CastResults table!!!"); |
| 1670 | return 0; |
| 1671 | } |
| 1672 | return 0; |
| 1673 | } |
| 1674 | |
| 1675 | CastInst *CastInst::create(Instruction::CastOps op, Value *S, const Type *Ty, |
| 1676 | const std::string &Name, Instruction *InsertBefore) { |
| 1677 | // Construct and return the appropriate CastInst subclass |
| 1678 | switch (op) { |
| 1679 | case Trunc: return new TruncInst (S, Ty, Name, InsertBefore); |
| 1680 | case ZExt: return new ZExtInst (S, Ty, Name, InsertBefore); |
| 1681 | case SExt: return new SExtInst (S, Ty, Name, InsertBefore); |
| 1682 | case FPTrunc: return new FPTruncInst (S, Ty, Name, InsertBefore); |
| 1683 | case FPExt: return new FPExtInst (S, Ty, Name, InsertBefore); |
| 1684 | case UIToFP: return new UIToFPInst (S, Ty, Name, InsertBefore); |
| 1685 | case SIToFP: return new SIToFPInst (S, Ty, Name, InsertBefore); |
| 1686 | case FPToUI: return new FPToUIInst (S, Ty, Name, InsertBefore); |
| 1687 | case FPToSI: return new FPToSIInst (S, Ty, Name, InsertBefore); |
| 1688 | case PtrToInt: return new PtrToIntInst (S, Ty, Name, InsertBefore); |
| 1689 | case IntToPtr: return new IntToPtrInst (S, Ty, Name, InsertBefore); |
| 1690 | case BitCast: return new BitCastInst (S, Ty, Name, InsertBefore); |
| 1691 | default: |
| 1692 | assert(!"Invalid opcode provided"); |
| 1693 | } |
| 1694 | return 0; |
| 1695 | } |
| 1696 | |
| 1697 | CastInst *CastInst::create(Instruction::CastOps op, Value *S, const Type *Ty, |
| 1698 | const std::string &Name, BasicBlock *InsertAtEnd) { |
| 1699 | // Construct and return the appropriate CastInst subclass |
| 1700 | switch (op) { |
| 1701 | case Trunc: return new TruncInst (S, Ty, Name, InsertAtEnd); |
| 1702 | case ZExt: return new ZExtInst (S, Ty, Name, InsertAtEnd); |
| 1703 | case SExt: return new SExtInst (S, Ty, Name, InsertAtEnd); |
| 1704 | case FPTrunc: return new FPTruncInst (S, Ty, Name, InsertAtEnd); |
| 1705 | case FPExt: return new FPExtInst (S, Ty, Name, InsertAtEnd); |
| 1706 | case UIToFP: return new UIToFPInst (S, Ty, Name, InsertAtEnd); |
| 1707 | case SIToFP: return new SIToFPInst (S, Ty, Name, InsertAtEnd); |
| 1708 | case FPToUI: return new FPToUIInst (S, Ty, Name, InsertAtEnd); |
| 1709 | case FPToSI: return new FPToSIInst (S, Ty, Name, InsertAtEnd); |
| 1710 | case PtrToInt: return new PtrToIntInst (S, Ty, Name, InsertAtEnd); |
| 1711 | case IntToPtr: return new IntToPtrInst (S, Ty, Name, InsertAtEnd); |
| 1712 | case BitCast: return new BitCastInst (S, Ty, Name, InsertAtEnd); |
| 1713 | default: |
| 1714 | assert(!"Invalid opcode provided"); |
| 1715 | } |
| 1716 | return 0; |
| 1717 | } |
| 1718 | |
Reid Spencer | 5c14088 | 2006-12-04 20:17:56 +0000 | [diff] [blame] | 1719 | CastInst *CastInst::createZExtOrBitCast(Value *S, const Type *Ty, |
| 1720 | const std::string &Name, |
| 1721 | Instruction *InsertBefore) { |
| 1722 | if (S->getType()->getPrimitiveSizeInBits() == Ty->getPrimitiveSizeInBits()) |
| 1723 | return create(Instruction::BitCast, S, Ty, Name, InsertBefore); |
| 1724 | return create(Instruction::ZExt, S, Ty, Name, InsertBefore); |
| 1725 | } |
| 1726 | |
| 1727 | CastInst *CastInst::createZExtOrBitCast(Value *S, const Type *Ty, |
| 1728 | const std::string &Name, |
| 1729 | BasicBlock *InsertAtEnd) { |
| 1730 | if (S->getType()->getPrimitiveSizeInBits() == Ty->getPrimitiveSizeInBits()) |
| 1731 | return create(Instruction::BitCast, S, Ty, Name, InsertAtEnd); |
| 1732 | return create(Instruction::ZExt, S, Ty, Name, InsertAtEnd); |
| 1733 | } |
| 1734 | |
| 1735 | CastInst *CastInst::createSExtOrBitCast(Value *S, const Type *Ty, |
| 1736 | const std::string &Name, |
| 1737 | Instruction *InsertBefore) { |
| 1738 | if (S->getType()->getPrimitiveSizeInBits() == Ty->getPrimitiveSizeInBits()) |
| 1739 | return create(Instruction::BitCast, S, Ty, Name, InsertBefore); |
| 1740 | return create(Instruction::SExt, S, Ty, Name, InsertBefore); |
| 1741 | } |
| 1742 | |
| 1743 | CastInst *CastInst::createSExtOrBitCast(Value *S, const Type *Ty, |
| 1744 | const std::string &Name, |
| 1745 | BasicBlock *InsertAtEnd) { |
| 1746 | if (S->getType()->getPrimitiveSizeInBits() == Ty->getPrimitiveSizeInBits()) |
| 1747 | return create(Instruction::BitCast, S, Ty, Name, InsertAtEnd); |
| 1748 | return create(Instruction::SExt, S, Ty, Name, InsertAtEnd); |
| 1749 | } |
| 1750 | |
| 1751 | CastInst *CastInst::createTruncOrBitCast(Value *S, const Type *Ty, |
| 1752 | const std::string &Name, |
| 1753 | Instruction *InsertBefore) { |
| 1754 | if (S->getType()->getPrimitiveSizeInBits() == Ty->getPrimitiveSizeInBits()) |
| 1755 | return create(Instruction::BitCast, S, Ty, Name, InsertBefore); |
| 1756 | return create(Instruction::Trunc, S, Ty, Name, InsertBefore); |
| 1757 | } |
| 1758 | |
| 1759 | CastInst *CastInst::createTruncOrBitCast(Value *S, const Type *Ty, |
| 1760 | const std::string &Name, |
| 1761 | BasicBlock *InsertAtEnd) { |
| 1762 | if (S->getType()->getPrimitiveSizeInBits() == Ty->getPrimitiveSizeInBits()) |
| 1763 | return create(Instruction::BitCast, S, Ty, Name, InsertAtEnd); |
| 1764 | return create(Instruction::Trunc, S, Ty, Name, InsertAtEnd); |
| 1765 | } |
| 1766 | |
Reid Spencer | d5a3f0d | 2006-12-05 03:28:26 +0000 | [diff] [blame] | 1767 | CastInst *CastInst::createPointerCast(Value *S, const Type *Ty, |
| 1768 | const std::string &Name, |
| 1769 | BasicBlock *InsertAtEnd) { |
| 1770 | assert(isa<PointerType>(S->getType()) && "Invalid cast"); |
Chris Lattner | 03c4953 | 2007-01-15 02:27:26 +0000 | [diff] [blame] | 1771 | assert((Ty->isInteger() || isa<PointerType>(Ty)) && |
Reid Spencer | d5a3f0d | 2006-12-05 03:28:26 +0000 | [diff] [blame] | 1772 | "Invalid cast"); |
| 1773 | |
Chris Lattner | 03c4953 | 2007-01-15 02:27:26 +0000 | [diff] [blame] | 1774 | if (Ty->isInteger()) |
Reid Spencer | d5a3f0d | 2006-12-05 03:28:26 +0000 | [diff] [blame] | 1775 | return create(Instruction::PtrToInt, S, Ty, Name, InsertAtEnd); |
| 1776 | return create(Instruction::BitCast, S, Ty, Name, InsertAtEnd); |
| 1777 | } |
| 1778 | |
| 1779 | /// @brief Create a BitCast or a PtrToInt cast instruction |
| 1780 | CastInst *CastInst::createPointerCast(Value *S, const Type *Ty, |
| 1781 | const std::string &Name, |
| 1782 | Instruction *InsertBefore) { |
| 1783 | assert(isa<PointerType>(S->getType()) && "Invalid cast"); |
Chris Lattner | 03c4953 | 2007-01-15 02:27:26 +0000 | [diff] [blame] | 1784 | assert((Ty->isInteger() || isa<PointerType>(Ty)) && |
Reid Spencer | d5a3f0d | 2006-12-05 03:28:26 +0000 | [diff] [blame] | 1785 | "Invalid cast"); |
| 1786 | |
Chris Lattner | 03c4953 | 2007-01-15 02:27:26 +0000 | [diff] [blame] | 1787 | if (Ty->isInteger()) |
Reid Spencer | d5a3f0d | 2006-12-05 03:28:26 +0000 | [diff] [blame] | 1788 | return create(Instruction::PtrToInt, S, Ty, Name, InsertBefore); |
| 1789 | return create(Instruction::BitCast, S, Ty, Name, InsertBefore); |
| 1790 | } |
| 1791 | |
Reid Spencer | 7e93347 | 2006-12-12 00:49:44 +0000 | [diff] [blame] | 1792 | CastInst *CastInst::createIntegerCast(Value *C, const Type *Ty, |
| 1793 | bool isSigned, const std::string &Name, |
| 1794 | Instruction *InsertBefore) { |
Chris Lattner | 03c4953 | 2007-01-15 02:27:26 +0000 | [diff] [blame] | 1795 | assert(C->getType()->isInteger() && Ty->isInteger() && "Invalid cast"); |
Reid Spencer | 7e93347 | 2006-12-12 00:49:44 +0000 | [diff] [blame] | 1796 | unsigned SrcBits = C->getType()->getPrimitiveSizeInBits(); |
| 1797 | unsigned DstBits = Ty->getPrimitiveSizeInBits(); |
| 1798 | Instruction::CastOps opcode = |
| 1799 | (SrcBits == DstBits ? Instruction::BitCast : |
| 1800 | (SrcBits > DstBits ? Instruction::Trunc : |
| 1801 | (isSigned ? Instruction::SExt : Instruction::ZExt))); |
| 1802 | return create(opcode, C, Ty, Name, InsertBefore); |
| 1803 | } |
| 1804 | |
| 1805 | CastInst *CastInst::createIntegerCast(Value *C, const Type *Ty, |
| 1806 | bool isSigned, const std::string &Name, |
| 1807 | BasicBlock *InsertAtEnd) { |
Chris Lattner | 03c4953 | 2007-01-15 02:27:26 +0000 | [diff] [blame] | 1808 | assert(C->getType()->isInteger() && Ty->isInteger() && "Invalid cast"); |
Reid Spencer | 7e93347 | 2006-12-12 00:49:44 +0000 | [diff] [blame] | 1809 | unsigned SrcBits = C->getType()->getPrimitiveSizeInBits(); |
| 1810 | unsigned DstBits = Ty->getPrimitiveSizeInBits(); |
| 1811 | Instruction::CastOps opcode = |
| 1812 | (SrcBits == DstBits ? Instruction::BitCast : |
| 1813 | (SrcBits > DstBits ? Instruction::Trunc : |
| 1814 | (isSigned ? Instruction::SExt : Instruction::ZExt))); |
| 1815 | return create(opcode, C, Ty, Name, InsertAtEnd); |
| 1816 | } |
| 1817 | |
| 1818 | CastInst *CastInst::createFPCast(Value *C, const Type *Ty, |
| 1819 | const std::string &Name, |
| 1820 | Instruction *InsertBefore) { |
| 1821 | assert(C->getType()->isFloatingPoint() && Ty->isFloatingPoint() && |
| 1822 | "Invalid cast"); |
| 1823 | unsigned SrcBits = C->getType()->getPrimitiveSizeInBits(); |
| 1824 | unsigned DstBits = Ty->getPrimitiveSizeInBits(); |
| 1825 | Instruction::CastOps opcode = |
| 1826 | (SrcBits == DstBits ? Instruction::BitCast : |
| 1827 | (SrcBits > DstBits ? Instruction::FPTrunc : Instruction::FPExt)); |
| 1828 | return create(opcode, C, Ty, Name, InsertBefore); |
| 1829 | } |
| 1830 | |
| 1831 | CastInst *CastInst::createFPCast(Value *C, const Type *Ty, |
| 1832 | const std::string &Name, |
| 1833 | BasicBlock *InsertAtEnd) { |
| 1834 | assert(C->getType()->isFloatingPoint() && Ty->isFloatingPoint() && |
| 1835 | "Invalid cast"); |
| 1836 | unsigned SrcBits = C->getType()->getPrimitiveSizeInBits(); |
| 1837 | unsigned DstBits = Ty->getPrimitiveSizeInBits(); |
| 1838 | Instruction::CastOps opcode = |
| 1839 | (SrcBits == DstBits ? Instruction::BitCast : |
| 1840 | (SrcBits > DstBits ? Instruction::FPTrunc : Instruction::FPExt)); |
| 1841 | return create(opcode, C, Ty, Name, InsertAtEnd); |
| 1842 | } |
| 1843 | |
Reid Spencer | 6c38f0b | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 1844 | // Provide a way to get a "cast" where the cast opcode is inferred from the |
| 1845 | // types and size of the operand. This, basically, is a parallel of the |
Reid Spencer | 00e5e0e | 2007-01-17 02:46:11 +0000 | [diff] [blame] | 1846 | // logic in the castIsValid function below. This axiom should hold: |
| 1847 | // castIsValid( getCastOpcode(Val, Ty), Val, Ty) |
| 1848 | // should not assert in castIsValid. In other words, this produces a "correct" |
Reid Spencer | 6c38f0b | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 1849 | // casting opcode for the arguments passed to it. |
| 1850 | Instruction::CastOps |
Reid Spencer | c4dacf2 | 2006-12-04 02:43:42 +0000 | [diff] [blame] | 1851 | CastInst::getCastOpcode( |
| 1852 | const Value *Src, bool SrcIsSigned, const Type *DestTy, bool DestIsSigned) { |
Reid Spencer | 6c38f0b | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 1853 | // Get the bit sizes, we'll need these |
| 1854 | const Type *SrcTy = Src->getType(); |
Dan Gohman | fead797 | 2007-05-11 21:43:24 +0000 | [diff] [blame] | 1855 | unsigned SrcBits = SrcTy->getPrimitiveSizeInBits(); // 0 for ptr/vector |
| 1856 | unsigned DestBits = DestTy->getPrimitiveSizeInBits(); // 0 for ptr/vector |
Reid Spencer | 6c38f0b | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 1857 | |
| 1858 | // Run through the possibilities ... |
Chris Lattner | 03c4953 | 2007-01-15 02:27:26 +0000 | [diff] [blame] | 1859 | if (DestTy->isInteger()) { // Casting to integral |
| 1860 | if (SrcTy->isInteger()) { // Casting from integral |
Reid Spencer | 6c38f0b | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 1861 | if (DestBits < SrcBits) |
| 1862 | return Trunc; // int -> smaller int |
| 1863 | else if (DestBits > SrcBits) { // its an extension |
Reid Spencer | c4dacf2 | 2006-12-04 02:43:42 +0000 | [diff] [blame] | 1864 | if (SrcIsSigned) |
Reid Spencer | 6c38f0b | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 1865 | return SExt; // signed -> SEXT |
| 1866 | else |
| 1867 | return ZExt; // unsigned -> ZEXT |
| 1868 | } else { |
| 1869 | return BitCast; // Same size, No-op cast |
| 1870 | } |
| 1871 | } else if (SrcTy->isFloatingPoint()) { // Casting from floating pt |
Reid Spencer | c4dacf2 | 2006-12-04 02:43:42 +0000 | [diff] [blame] | 1872 | if (DestIsSigned) |
Reid Spencer | 6c38f0b | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 1873 | return FPToSI; // FP -> sint |
| 1874 | else |
| 1875 | return FPToUI; // FP -> uint |
Reid Spencer | d84d35b | 2007-02-15 02:26:10 +0000 | [diff] [blame] | 1876 | } else if (const VectorType *PTy = dyn_cast<VectorType>(SrcTy)) { |
Reid Spencer | 6c38f0b | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 1877 | assert(DestBits == PTy->getBitWidth() && |
Dan Gohman | fead797 | 2007-05-11 21:43:24 +0000 | [diff] [blame] | 1878 | "Casting vector to integer of different width"); |
Reid Spencer | 6c38f0b | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 1879 | return BitCast; // Same size, no-op cast |
| 1880 | } else { |
| 1881 | assert(isa<PointerType>(SrcTy) && |
| 1882 | "Casting from a value that is not first-class type"); |
| 1883 | return PtrToInt; // ptr -> int |
| 1884 | } |
| 1885 | } else if (DestTy->isFloatingPoint()) { // Casting to floating pt |
Chris Lattner | 03c4953 | 2007-01-15 02:27:26 +0000 | [diff] [blame] | 1886 | if (SrcTy->isInteger()) { // Casting from integral |
Reid Spencer | c4dacf2 | 2006-12-04 02:43:42 +0000 | [diff] [blame] | 1887 | if (SrcIsSigned) |
Reid Spencer | 6c38f0b | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 1888 | return SIToFP; // sint -> FP |
| 1889 | else |
| 1890 | return UIToFP; // uint -> FP |
| 1891 | } else if (SrcTy->isFloatingPoint()) { // Casting from floating pt |
| 1892 | if (DestBits < SrcBits) { |
| 1893 | return FPTrunc; // FP -> smaller FP |
| 1894 | } else if (DestBits > SrcBits) { |
| 1895 | return FPExt; // FP -> larger FP |
| 1896 | } else { |
| 1897 | return BitCast; // same size, no-op cast |
| 1898 | } |
Reid Spencer | d84d35b | 2007-02-15 02:26:10 +0000 | [diff] [blame] | 1899 | } else if (const VectorType *PTy = dyn_cast<VectorType>(SrcTy)) { |
Reid Spencer | 6c38f0b | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 1900 | assert(DestBits == PTy->getBitWidth() && |
Dan Gohman | fead797 | 2007-05-11 21:43:24 +0000 | [diff] [blame] | 1901 | "Casting vector to floating point of different width"); |
Reid Spencer | 6c38f0b | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 1902 | return BitCast; // same size, no-op cast |
| 1903 | } else { |
| 1904 | assert(0 && "Casting pointer or non-first class to float"); |
| 1905 | } |
Reid Spencer | d84d35b | 2007-02-15 02:26:10 +0000 | [diff] [blame] | 1906 | } else if (const VectorType *DestPTy = dyn_cast<VectorType>(DestTy)) { |
| 1907 | if (const VectorType *SrcPTy = dyn_cast<VectorType>(SrcTy)) { |
Reid Spencer | 6c38f0b | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 1908 | assert(DestPTy->getBitWidth() == SrcPTy->getBitWidth() && |
Dan Gohman | fead797 | 2007-05-11 21:43:24 +0000 | [diff] [blame] | 1909 | "Casting vector to vector of different widths"); |
| 1910 | return BitCast; // vector -> vector |
Reid Spencer | 6c38f0b | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 1911 | } else if (DestPTy->getBitWidth() == SrcBits) { |
Dan Gohman | fead797 | 2007-05-11 21:43:24 +0000 | [diff] [blame] | 1912 | return BitCast; // float/int -> vector |
Reid Spencer | 6c38f0b | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 1913 | } else { |
Dan Gohman | fead797 | 2007-05-11 21:43:24 +0000 | [diff] [blame] | 1914 | assert(!"Illegal cast to vector (wrong type or size)"); |
Reid Spencer | 6c38f0b | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 1915 | } |
| 1916 | } else if (isa<PointerType>(DestTy)) { |
| 1917 | if (isa<PointerType>(SrcTy)) { |
| 1918 | return BitCast; // ptr -> ptr |
Chris Lattner | 03c4953 | 2007-01-15 02:27:26 +0000 | [diff] [blame] | 1919 | } else if (SrcTy->isInteger()) { |
Reid Spencer | 6c38f0b | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 1920 | return IntToPtr; // int -> ptr |
| 1921 | } else { |
| 1922 | assert(!"Casting pointer to other than pointer or int"); |
| 1923 | } |
| 1924 | } else { |
| 1925 | assert(!"Casting to type that is not first-class"); |
| 1926 | } |
| 1927 | |
| 1928 | // If we fall through to here we probably hit an assertion cast above |
| 1929 | // and assertions are not turned on. Anything we return is an error, so |
| 1930 | // BitCast is as good a choice as any. |
| 1931 | return BitCast; |
| 1932 | } |
| 1933 | |
| 1934 | //===----------------------------------------------------------------------===// |
| 1935 | // CastInst SubClass Constructors |
| 1936 | //===----------------------------------------------------------------------===// |
| 1937 | |
| 1938 | /// Check that the construction parameters for a CastInst are correct. This |
| 1939 | /// could be broken out into the separate constructors but it is useful to have |
| 1940 | /// it in one place and to eliminate the redundant code for getting the sizes |
| 1941 | /// of the types involved. |
Reid Spencer | 00e5e0e | 2007-01-17 02:46:11 +0000 | [diff] [blame] | 1942 | bool |
| 1943 | CastInst::castIsValid(Instruction::CastOps op, Value *S, const Type *DstTy) { |
Reid Spencer | 6c38f0b | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 1944 | |
| 1945 | // Check for type sanity on the arguments |
| 1946 | const Type *SrcTy = S->getType(); |
| 1947 | if (!SrcTy->isFirstClassType() || !DstTy->isFirstClassType()) |
| 1948 | return false; |
| 1949 | |
| 1950 | // Get the size of the types in bits, we'll need this later |
| 1951 | unsigned SrcBitSize = SrcTy->getPrimitiveSizeInBits(); |
| 1952 | unsigned DstBitSize = DstTy->getPrimitiveSizeInBits(); |
| 1953 | |
| 1954 | // Switch on the opcode provided |
| 1955 | switch (op) { |
| 1956 | default: return false; // This is an input error |
| 1957 | case Instruction::Trunc: |
Chris Lattner | 03c4953 | 2007-01-15 02:27:26 +0000 | [diff] [blame] | 1958 | return SrcTy->isInteger() && DstTy->isInteger()&& SrcBitSize > DstBitSize; |
Reid Spencer | 6c38f0b | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 1959 | case Instruction::ZExt: |
Chris Lattner | 03c4953 | 2007-01-15 02:27:26 +0000 | [diff] [blame] | 1960 | return SrcTy->isInteger() && DstTy->isInteger()&& SrcBitSize < DstBitSize; |
Reid Spencer | 6c38f0b | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 1961 | case Instruction::SExt: |
Chris Lattner | 03c4953 | 2007-01-15 02:27:26 +0000 | [diff] [blame] | 1962 | return SrcTy->isInteger() && DstTy->isInteger()&& SrcBitSize < DstBitSize; |
Reid Spencer | 6c38f0b | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 1963 | case Instruction::FPTrunc: |
| 1964 | return SrcTy->isFloatingPoint() && DstTy->isFloatingPoint() && |
| 1965 | SrcBitSize > DstBitSize; |
| 1966 | case Instruction::FPExt: |
| 1967 | return SrcTy->isFloatingPoint() && DstTy->isFloatingPoint() && |
| 1968 | SrcBitSize < DstBitSize; |
| 1969 | case Instruction::UIToFP: |
Reid Spencer | 6c38f0b | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 1970 | case Instruction::SIToFP: |
Nate Begeman | d4d45c2 | 2007-11-17 03:58:34 +0000 | [diff] [blame] | 1971 | if (const VectorType *SVTy = dyn_cast<VectorType>(SrcTy)) { |
| 1972 | if (const VectorType *DVTy = dyn_cast<VectorType>(DstTy)) { |
| 1973 | return SVTy->getElementType()->isInteger() && |
| 1974 | DVTy->getElementType()->isFloatingPoint() && |
| 1975 | SVTy->getNumElements() == DVTy->getNumElements(); |
| 1976 | } |
| 1977 | } |
Chris Lattner | 03c4953 | 2007-01-15 02:27:26 +0000 | [diff] [blame] | 1978 | return SrcTy->isInteger() && DstTy->isFloatingPoint(); |
Reid Spencer | 6c38f0b | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 1979 | case Instruction::FPToUI: |
Reid Spencer | 6c38f0b | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 1980 | case Instruction::FPToSI: |
Nate Begeman | d4d45c2 | 2007-11-17 03:58:34 +0000 | [diff] [blame] | 1981 | if (const VectorType *SVTy = dyn_cast<VectorType>(SrcTy)) { |
| 1982 | if (const VectorType *DVTy = dyn_cast<VectorType>(DstTy)) { |
| 1983 | return SVTy->getElementType()->isFloatingPoint() && |
| 1984 | DVTy->getElementType()->isInteger() && |
| 1985 | SVTy->getNumElements() == DVTy->getNumElements(); |
| 1986 | } |
| 1987 | } |
Chris Lattner | 03c4953 | 2007-01-15 02:27:26 +0000 | [diff] [blame] | 1988 | return SrcTy->isFloatingPoint() && DstTy->isInteger(); |
Reid Spencer | 6c38f0b | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 1989 | case Instruction::PtrToInt: |
Chris Lattner | 03c4953 | 2007-01-15 02:27:26 +0000 | [diff] [blame] | 1990 | return isa<PointerType>(SrcTy) && DstTy->isInteger(); |
Reid Spencer | 6c38f0b | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 1991 | case Instruction::IntToPtr: |
Chris Lattner | 03c4953 | 2007-01-15 02:27:26 +0000 | [diff] [blame] | 1992 | return SrcTy->isInteger() && isa<PointerType>(DstTy); |
Reid Spencer | 6c38f0b | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 1993 | case Instruction::BitCast: |
| 1994 | // BitCast implies a no-op cast of type only. No bits change. |
| 1995 | // However, you can't cast pointers to anything but pointers. |
| 1996 | if (isa<PointerType>(SrcTy) != isa<PointerType>(DstTy)) |
| 1997 | return false; |
| 1998 | |
| 1999 | // Now we know we're not dealing with a pointer/non-poiner mismatch. In all |
| 2000 | // these cases, the cast is okay if the source and destination bit widths |
| 2001 | // are identical. |
| 2002 | return SrcBitSize == DstBitSize; |
| 2003 | } |
| 2004 | } |
| 2005 | |
| 2006 | TruncInst::TruncInst( |
| 2007 | Value *S, const Type *Ty, const std::string &Name, Instruction *InsertBefore |
| 2008 | ) : CastInst(Ty, Trunc, S, Name, InsertBefore) { |
Reid Spencer | 00e5e0e | 2007-01-17 02:46:11 +0000 | [diff] [blame] | 2009 | assert(castIsValid(getOpcode(), S, Ty) && "Illegal Trunc"); |
Reid Spencer | 6c38f0b | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 2010 | } |
| 2011 | |
| 2012 | TruncInst::TruncInst( |
| 2013 | Value *S, const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd |
| 2014 | ) : CastInst(Ty, Trunc, S, Name, InsertAtEnd) { |
Reid Spencer | 00e5e0e | 2007-01-17 02:46:11 +0000 | [diff] [blame] | 2015 | assert(castIsValid(getOpcode(), S, Ty) && "Illegal Trunc"); |
Reid Spencer | 6c38f0b | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 2016 | } |
| 2017 | |
| 2018 | ZExtInst::ZExtInst( |
| 2019 | Value *S, const Type *Ty, const std::string &Name, Instruction *InsertBefore |
| 2020 | ) : CastInst(Ty, ZExt, S, Name, InsertBefore) { |
Reid Spencer | 00e5e0e | 2007-01-17 02:46:11 +0000 | [diff] [blame] | 2021 | assert(castIsValid(getOpcode(), S, Ty) && "Illegal ZExt"); |
Reid Spencer | 6c38f0b | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 2022 | } |
| 2023 | |
| 2024 | ZExtInst::ZExtInst( |
| 2025 | Value *S, const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd |
| 2026 | ) : CastInst(Ty, ZExt, S, Name, InsertAtEnd) { |
Reid Spencer | 00e5e0e | 2007-01-17 02:46:11 +0000 | [diff] [blame] | 2027 | assert(castIsValid(getOpcode(), S, Ty) && "Illegal ZExt"); |
Reid Spencer | 6c38f0b | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 2028 | } |
| 2029 | SExtInst::SExtInst( |
| 2030 | Value *S, const Type *Ty, const std::string &Name, Instruction *InsertBefore |
| 2031 | ) : CastInst(Ty, SExt, S, Name, InsertBefore) { |
Reid Spencer | 00e5e0e | 2007-01-17 02:46:11 +0000 | [diff] [blame] | 2032 | assert(castIsValid(getOpcode(), S, Ty) && "Illegal SExt"); |
Reid Spencer | 6c38f0b | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 2033 | } |
| 2034 | |
Jeff Cohen | cc08c83 | 2006-12-02 02:22:01 +0000 | [diff] [blame] | 2035 | SExtInst::SExtInst( |
Reid Spencer | 6c38f0b | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 2036 | Value *S, const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd |
| 2037 | ) : CastInst(Ty, SExt, S, Name, InsertAtEnd) { |
Reid Spencer | 00e5e0e | 2007-01-17 02:46:11 +0000 | [diff] [blame] | 2038 | assert(castIsValid(getOpcode(), S, Ty) && "Illegal SExt"); |
Reid Spencer | 6c38f0b | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 2039 | } |
| 2040 | |
| 2041 | FPTruncInst::FPTruncInst( |
| 2042 | Value *S, const Type *Ty, const std::string &Name, Instruction *InsertBefore |
| 2043 | ) : CastInst(Ty, FPTrunc, S, Name, InsertBefore) { |
Reid Spencer | 00e5e0e | 2007-01-17 02:46:11 +0000 | [diff] [blame] | 2044 | assert(castIsValid(getOpcode(), S, Ty) && "Illegal FPTrunc"); |
Reid Spencer | 6c38f0b | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 2045 | } |
| 2046 | |
| 2047 | FPTruncInst::FPTruncInst( |
| 2048 | Value *S, const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd |
| 2049 | ) : CastInst(Ty, FPTrunc, S, Name, InsertAtEnd) { |
Reid Spencer | 00e5e0e | 2007-01-17 02:46:11 +0000 | [diff] [blame] | 2050 | assert(castIsValid(getOpcode(), S, Ty) && "Illegal FPTrunc"); |
Reid Spencer | 6c38f0b | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 2051 | } |
| 2052 | |
| 2053 | FPExtInst::FPExtInst( |
| 2054 | Value *S, const Type *Ty, const std::string &Name, Instruction *InsertBefore |
| 2055 | ) : CastInst(Ty, FPExt, S, Name, InsertBefore) { |
Reid Spencer | 00e5e0e | 2007-01-17 02:46:11 +0000 | [diff] [blame] | 2056 | assert(castIsValid(getOpcode(), S, Ty) && "Illegal FPExt"); |
Reid Spencer | 6c38f0b | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 2057 | } |
| 2058 | |
| 2059 | FPExtInst::FPExtInst( |
| 2060 | Value *S, const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd |
| 2061 | ) : CastInst(Ty, FPExt, S, Name, InsertAtEnd) { |
Reid Spencer | 00e5e0e | 2007-01-17 02:46:11 +0000 | [diff] [blame] | 2062 | assert(castIsValid(getOpcode(), S, Ty) && "Illegal FPExt"); |
Reid Spencer | 6c38f0b | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 2063 | } |
| 2064 | |
| 2065 | UIToFPInst::UIToFPInst( |
| 2066 | Value *S, const Type *Ty, const std::string &Name, Instruction *InsertBefore |
| 2067 | ) : CastInst(Ty, UIToFP, S, Name, InsertBefore) { |
Reid Spencer | 00e5e0e | 2007-01-17 02:46:11 +0000 | [diff] [blame] | 2068 | assert(castIsValid(getOpcode(), S, Ty) && "Illegal UIToFP"); |
Reid Spencer | 6c38f0b | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 2069 | } |
| 2070 | |
| 2071 | UIToFPInst::UIToFPInst( |
| 2072 | Value *S, const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd |
| 2073 | ) : CastInst(Ty, UIToFP, S, Name, InsertAtEnd) { |
Reid Spencer | 00e5e0e | 2007-01-17 02:46:11 +0000 | [diff] [blame] | 2074 | assert(castIsValid(getOpcode(), S, Ty) && "Illegal UIToFP"); |
Reid Spencer | 6c38f0b | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 2075 | } |
| 2076 | |
| 2077 | SIToFPInst::SIToFPInst( |
| 2078 | Value *S, const Type *Ty, const std::string &Name, Instruction *InsertBefore |
| 2079 | ) : CastInst(Ty, SIToFP, S, Name, InsertBefore) { |
Reid Spencer | 00e5e0e | 2007-01-17 02:46:11 +0000 | [diff] [blame] | 2080 | assert(castIsValid(getOpcode(), S, Ty) && "Illegal SIToFP"); |
Reid Spencer | 6c38f0b | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 2081 | } |
| 2082 | |
| 2083 | SIToFPInst::SIToFPInst( |
| 2084 | Value *S, const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd |
| 2085 | ) : CastInst(Ty, SIToFP, S, Name, InsertAtEnd) { |
Reid Spencer | 00e5e0e | 2007-01-17 02:46:11 +0000 | [diff] [blame] | 2086 | assert(castIsValid(getOpcode(), S, Ty) && "Illegal SIToFP"); |
Reid Spencer | 6c38f0b | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 2087 | } |
| 2088 | |
| 2089 | FPToUIInst::FPToUIInst( |
| 2090 | Value *S, const Type *Ty, const std::string &Name, Instruction *InsertBefore |
| 2091 | ) : CastInst(Ty, FPToUI, S, Name, InsertBefore) { |
Reid Spencer | 00e5e0e | 2007-01-17 02:46:11 +0000 | [diff] [blame] | 2092 | assert(castIsValid(getOpcode(), S, Ty) && "Illegal FPToUI"); |
Reid Spencer | 6c38f0b | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 2093 | } |
| 2094 | |
| 2095 | FPToUIInst::FPToUIInst( |
| 2096 | Value *S, const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd |
| 2097 | ) : CastInst(Ty, FPToUI, S, Name, InsertAtEnd) { |
Reid Spencer | 00e5e0e | 2007-01-17 02:46:11 +0000 | [diff] [blame] | 2098 | assert(castIsValid(getOpcode(), S, Ty) && "Illegal FPToUI"); |
Reid Spencer | 6c38f0b | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 2099 | } |
| 2100 | |
| 2101 | FPToSIInst::FPToSIInst( |
| 2102 | Value *S, const Type *Ty, const std::string &Name, Instruction *InsertBefore |
| 2103 | ) : CastInst(Ty, FPToSI, S, Name, InsertBefore) { |
Reid Spencer | 00e5e0e | 2007-01-17 02:46:11 +0000 | [diff] [blame] | 2104 | assert(castIsValid(getOpcode(), S, Ty) && "Illegal FPToSI"); |
Reid Spencer | 6c38f0b | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 2105 | } |
| 2106 | |
| 2107 | FPToSIInst::FPToSIInst( |
| 2108 | Value *S, const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd |
| 2109 | ) : CastInst(Ty, FPToSI, S, Name, InsertAtEnd) { |
Reid Spencer | 00e5e0e | 2007-01-17 02:46:11 +0000 | [diff] [blame] | 2110 | assert(castIsValid(getOpcode(), S, Ty) && "Illegal FPToSI"); |
Reid Spencer | 6c38f0b | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 2111 | } |
| 2112 | |
| 2113 | PtrToIntInst::PtrToIntInst( |
| 2114 | Value *S, const Type *Ty, const std::string &Name, Instruction *InsertBefore |
| 2115 | ) : CastInst(Ty, PtrToInt, S, Name, InsertBefore) { |
Reid Spencer | 00e5e0e | 2007-01-17 02:46:11 +0000 | [diff] [blame] | 2116 | assert(castIsValid(getOpcode(), S, Ty) && "Illegal PtrToInt"); |
Reid Spencer | 6c38f0b | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 2117 | } |
| 2118 | |
| 2119 | PtrToIntInst::PtrToIntInst( |
| 2120 | Value *S, const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd |
| 2121 | ) : CastInst(Ty, PtrToInt, S, Name, InsertAtEnd) { |
Reid Spencer | 00e5e0e | 2007-01-17 02:46:11 +0000 | [diff] [blame] | 2122 | assert(castIsValid(getOpcode(), S, Ty) && "Illegal PtrToInt"); |
Reid Spencer | 6c38f0b | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 2123 | } |
| 2124 | |
| 2125 | IntToPtrInst::IntToPtrInst( |
| 2126 | Value *S, const Type *Ty, const std::string &Name, Instruction *InsertBefore |
| 2127 | ) : CastInst(Ty, IntToPtr, S, Name, InsertBefore) { |
Reid Spencer | 00e5e0e | 2007-01-17 02:46:11 +0000 | [diff] [blame] | 2128 | assert(castIsValid(getOpcode(), S, Ty) && "Illegal IntToPtr"); |
Reid Spencer | 6c38f0b | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 2129 | } |
| 2130 | |
| 2131 | IntToPtrInst::IntToPtrInst( |
| 2132 | Value *S, const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd |
| 2133 | ) : CastInst(Ty, IntToPtr, S, Name, InsertAtEnd) { |
Reid Spencer | 00e5e0e | 2007-01-17 02:46:11 +0000 | [diff] [blame] | 2134 | assert(castIsValid(getOpcode(), S, Ty) && "Illegal IntToPtr"); |
Reid Spencer | 6c38f0b | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 2135 | } |
| 2136 | |
| 2137 | BitCastInst::BitCastInst( |
| 2138 | Value *S, const Type *Ty, const std::string &Name, Instruction *InsertBefore |
| 2139 | ) : CastInst(Ty, BitCast, S, Name, InsertBefore) { |
Reid Spencer | 00e5e0e | 2007-01-17 02:46:11 +0000 | [diff] [blame] | 2140 | assert(castIsValid(getOpcode(), S, Ty) && "Illegal BitCast"); |
Reid Spencer | 6c38f0b | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 2141 | } |
| 2142 | |
| 2143 | BitCastInst::BitCastInst( |
| 2144 | Value *S, const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd |
| 2145 | ) : CastInst(Ty, BitCast, S, Name, InsertAtEnd) { |
Reid Spencer | 00e5e0e | 2007-01-17 02:46:11 +0000 | [diff] [blame] | 2146 | assert(castIsValid(getOpcode(), S, Ty) && "Illegal BitCast"); |
Reid Spencer | 6c38f0b | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 2147 | } |
Chris Lattner | f16dc00 | 2006-09-17 19:29:56 +0000 | [diff] [blame] | 2148 | |
| 2149 | //===----------------------------------------------------------------------===// |
Reid Spencer | d9436b6 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 2150 | // CmpInst Classes |
| 2151 | //===----------------------------------------------------------------------===// |
| 2152 | |
| 2153 | CmpInst::CmpInst(OtherOps op, unsigned short predicate, Value *LHS, Value *RHS, |
| 2154 | const std::string &Name, Instruction *InsertBefore) |
Chris Lattner | 2195fc4 | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 2155 | : Instruction(Type::Int1Ty, op, Ops, 2, InsertBefore) { |
Reid Spencer | d9436b6 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 2156 | Ops[0].init(LHS, this); |
| 2157 | Ops[1].init(RHS, this); |
| 2158 | SubclassData = predicate; |
Reid Spencer | 871a9ea | 2007-04-11 13:04:48 +0000 | [diff] [blame] | 2159 | setName(Name); |
Reid Spencer | d9436b6 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 2160 | if (op == Instruction::ICmp) { |
| 2161 | assert(predicate >= ICmpInst::FIRST_ICMP_PREDICATE && |
| 2162 | predicate <= ICmpInst::LAST_ICMP_PREDICATE && |
| 2163 | "Invalid ICmp predicate value"); |
| 2164 | const Type* Op0Ty = getOperand(0)->getType(); |
| 2165 | const Type* Op1Ty = getOperand(1)->getType(); |
| 2166 | assert(Op0Ty == Op1Ty && |
| 2167 | "Both operands to ICmp instruction are not of the same type!"); |
| 2168 | // Check that the operands are the right type |
Reid Spencer | 2eadb53 | 2007-01-21 00:29:26 +0000 | [diff] [blame] | 2169 | assert((Op0Ty->isInteger() || isa<PointerType>(Op0Ty)) && |
Reid Spencer | d9436b6 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 2170 | "Invalid operand types for ICmp instruction"); |
| 2171 | return; |
| 2172 | } |
| 2173 | assert(op == Instruction::FCmp && "Invalid CmpInst opcode"); |
| 2174 | assert(predicate <= FCmpInst::LAST_FCMP_PREDICATE && |
| 2175 | "Invalid FCmp predicate value"); |
| 2176 | const Type* Op0Ty = getOperand(0)->getType(); |
| 2177 | const Type* Op1Ty = getOperand(1)->getType(); |
| 2178 | assert(Op0Ty == Op1Ty && |
| 2179 | "Both operands to FCmp instruction are not of the same type!"); |
| 2180 | // Check that the operands are the right type |
Reid Spencer | 2eadb53 | 2007-01-21 00:29:26 +0000 | [diff] [blame] | 2181 | assert(Op0Ty->isFloatingPoint() && |
Reid Spencer | d9436b6 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 2182 | "Invalid operand types for FCmp instruction"); |
| 2183 | } |
| 2184 | |
| 2185 | CmpInst::CmpInst(OtherOps op, unsigned short predicate, Value *LHS, Value *RHS, |
| 2186 | const std::string &Name, BasicBlock *InsertAtEnd) |
Chris Lattner | 2195fc4 | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 2187 | : Instruction(Type::Int1Ty, op, Ops, 2, InsertAtEnd) { |
Reid Spencer | d9436b6 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 2188 | Ops[0].init(LHS, this); |
| 2189 | Ops[1].init(RHS, this); |
| 2190 | SubclassData = predicate; |
Reid Spencer | 871a9ea | 2007-04-11 13:04:48 +0000 | [diff] [blame] | 2191 | setName(Name); |
Reid Spencer | d9436b6 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 2192 | if (op == Instruction::ICmp) { |
| 2193 | assert(predicate >= ICmpInst::FIRST_ICMP_PREDICATE && |
| 2194 | predicate <= ICmpInst::LAST_ICMP_PREDICATE && |
| 2195 | "Invalid ICmp predicate value"); |
| 2196 | |
| 2197 | const Type* Op0Ty = getOperand(0)->getType(); |
| 2198 | const Type* Op1Ty = getOperand(1)->getType(); |
| 2199 | assert(Op0Ty == Op1Ty && |
| 2200 | "Both operands to ICmp instruction are not of the same type!"); |
| 2201 | // Check that the operands are the right type |
Reid Spencer | 2eadb53 | 2007-01-21 00:29:26 +0000 | [diff] [blame] | 2202 | assert(Op0Ty->isInteger() || isa<PointerType>(Op0Ty) && |
Reid Spencer | d9436b6 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 2203 | "Invalid operand types for ICmp instruction"); |
| 2204 | return; |
| 2205 | } |
| 2206 | assert(op == Instruction::FCmp && "Invalid CmpInst opcode"); |
| 2207 | assert(predicate <= FCmpInst::LAST_FCMP_PREDICATE && |
| 2208 | "Invalid FCmp predicate value"); |
| 2209 | const Type* Op0Ty = getOperand(0)->getType(); |
| 2210 | const Type* Op1Ty = getOperand(1)->getType(); |
| 2211 | assert(Op0Ty == Op1Ty && |
| 2212 | "Both operands to FCmp instruction are not of the same type!"); |
| 2213 | // Check that the operands are the right type |
Reid Spencer | 2eadb53 | 2007-01-21 00:29:26 +0000 | [diff] [blame] | 2214 | assert(Op0Ty->isFloatingPoint() && |
Reid Spencer | d9436b6 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 2215 | "Invalid operand types for FCmp instruction"); |
| 2216 | } |
| 2217 | |
| 2218 | CmpInst * |
| 2219 | CmpInst::create(OtherOps Op, unsigned short predicate, Value *S1, Value *S2, |
| 2220 | const std::string &Name, Instruction *InsertBefore) { |
| 2221 | if (Op == Instruction::ICmp) { |
| 2222 | return new ICmpInst(ICmpInst::Predicate(predicate), S1, S2, Name, |
| 2223 | InsertBefore); |
| 2224 | } |
| 2225 | return new FCmpInst(FCmpInst::Predicate(predicate), S1, S2, Name, |
| 2226 | InsertBefore); |
| 2227 | } |
| 2228 | |
| 2229 | CmpInst * |
| 2230 | CmpInst::create(OtherOps Op, unsigned short predicate, Value *S1, Value *S2, |
| 2231 | const std::string &Name, BasicBlock *InsertAtEnd) { |
| 2232 | if (Op == Instruction::ICmp) { |
| 2233 | return new ICmpInst(ICmpInst::Predicate(predicate), S1, S2, Name, |
| 2234 | InsertAtEnd); |
| 2235 | } |
| 2236 | return new FCmpInst(FCmpInst::Predicate(predicate), S1, S2, Name, |
| 2237 | InsertAtEnd); |
| 2238 | } |
| 2239 | |
| 2240 | void CmpInst::swapOperands() { |
| 2241 | if (ICmpInst *IC = dyn_cast<ICmpInst>(this)) |
| 2242 | IC->swapOperands(); |
| 2243 | else |
| 2244 | cast<FCmpInst>(this)->swapOperands(); |
| 2245 | } |
| 2246 | |
| 2247 | bool CmpInst::isCommutative() { |
| 2248 | if (ICmpInst *IC = dyn_cast<ICmpInst>(this)) |
| 2249 | return IC->isCommutative(); |
| 2250 | return cast<FCmpInst>(this)->isCommutative(); |
| 2251 | } |
| 2252 | |
| 2253 | bool CmpInst::isEquality() { |
| 2254 | if (ICmpInst *IC = dyn_cast<ICmpInst>(this)) |
| 2255 | return IC->isEquality(); |
| 2256 | return cast<FCmpInst>(this)->isEquality(); |
| 2257 | } |
| 2258 | |
| 2259 | |
| 2260 | ICmpInst::Predicate ICmpInst::getInversePredicate(Predicate pred) { |
| 2261 | switch (pred) { |
| 2262 | default: |
| 2263 | assert(!"Unknown icmp predicate!"); |
| 2264 | case ICMP_EQ: return ICMP_NE; |
| 2265 | case ICMP_NE: return ICMP_EQ; |
| 2266 | case ICMP_UGT: return ICMP_ULE; |
| 2267 | case ICMP_ULT: return ICMP_UGE; |
| 2268 | case ICMP_UGE: return ICMP_ULT; |
| 2269 | case ICMP_ULE: return ICMP_UGT; |
| 2270 | case ICMP_SGT: return ICMP_SLE; |
| 2271 | case ICMP_SLT: return ICMP_SGE; |
| 2272 | case ICMP_SGE: return ICMP_SLT; |
| 2273 | case ICMP_SLE: return ICMP_SGT; |
| 2274 | } |
| 2275 | } |
| 2276 | |
| 2277 | ICmpInst::Predicate ICmpInst::getSwappedPredicate(Predicate pred) { |
| 2278 | switch (pred) { |
Reid Spencer | 266e42b | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 2279 | default: assert(! "Unknown icmp predicate!"); |
Reid Spencer | d9436b6 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 2280 | case ICMP_EQ: case ICMP_NE: |
| 2281 | return pred; |
| 2282 | case ICMP_SGT: return ICMP_SLT; |
| 2283 | case ICMP_SLT: return ICMP_SGT; |
| 2284 | case ICMP_SGE: return ICMP_SLE; |
| 2285 | case ICMP_SLE: return ICMP_SGE; |
| 2286 | case ICMP_UGT: return ICMP_ULT; |
| 2287 | case ICMP_ULT: return ICMP_UGT; |
| 2288 | case ICMP_UGE: return ICMP_ULE; |
| 2289 | case ICMP_ULE: return ICMP_UGE; |
| 2290 | } |
| 2291 | } |
| 2292 | |
Reid Spencer | 266e42b | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 2293 | ICmpInst::Predicate ICmpInst::getSignedPredicate(Predicate pred) { |
| 2294 | switch (pred) { |
| 2295 | default: assert(! "Unknown icmp predicate!"); |
| 2296 | case ICMP_EQ: case ICMP_NE: |
| 2297 | case ICMP_SGT: case ICMP_SLT: case ICMP_SGE: case ICMP_SLE: |
| 2298 | return pred; |
| 2299 | case ICMP_UGT: return ICMP_SGT; |
| 2300 | case ICMP_ULT: return ICMP_SLT; |
| 2301 | case ICMP_UGE: return ICMP_SGE; |
| 2302 | case ICMP_ULE: return ICMP_SLE; |
| 2303 | } |
| 2304 | } |
| 2305 | |
| 2306 | bool ICmpInst::isSignedPredicate(Predicate pred) { |
| 2307 | switch (pred) { |
| 2308 | default: assert(! "Unknown icmp predicate!"); |
| 2309 | case ICMP_SGT: case ICMP_SLT: case ICMP_SGE: case ICMP_SLE: |
| 2310 | return true; |
| 2311 | case ICMP_EQ: case ICMP_NE: case ICMP_UGT: case ICMP_ULT: |
| 2312 | case ICMP_UGE: case ICMP_ULE: |
| 2313 | return false; |
| 2314 | } |
| 2315 | } |
| 2316 | |
Reid Spencer | 0286bc1 | 2007-02-28 22:00:54 +0000 | [diff] [blame] | 2317 | /// Initialize a set of values that all satisfy the condition with C. |
| 2318 | /// |
| 2319 | ConstantRange |
| 2320 | ICmpInst::makeConstantRange(Predicate pred, const APInt &C) { |
| 2321 | APInt Lower(C); |
| 2322 | APInt Upper(C); |
| 2323 | uint32_t BitWidth = C.getBitWidth(); |
| 2324 | switch (pred) { |
| 2325 | default: assert(0 && "Invalid ICmp opcode to ConstantRange ctor!"); |
| 2326 | case ICmpInst::ICMP_EQ: Upper++; break; |
| 2327 | case ICmpInst::ICMP_NE: Lower++; break; |
| 2328 | case ICmpInst::ICMP_ULT: Lower = APInt::getMinValue(BitWidth); break; |
| 2329 | case ICmpInst::ICMP_SLT: Lower = APInt::getSignedMinValue(BitWidth); break; |
| 2330 | case ICmpInst::ICMP_UGT: |
| 2331 | Lower++; Upper = APInt::getMinValue(BitWidth); // Min = Next(Max) |
| 2332 | break; |
| 2333 | case ICmpInst::ICMP_SGT: |
| 2334 | Lower++; Upper = APInt::getSignedMinValue(BitWidth); // Min = Next(Max) |
| 2335 | break; |
| 2336 | case ICmpInst::ICMP_ULE: |
| 2337 | Lower = APInt::getMinValue(BitWidth); Upper++; |
| 2338 | break; |
| 2339 | case ICmpInst::ICMP_SLE: |
| 2340 | Lower = APInt::getSignedMinValue(BitWidth); Upper++; |
| 2341 | break; |
| 2342 | case ICmpInst::ICMP_UGE: |
| 2343 | Upper = APInt::getMinValue(BitWidth); // Min = Next(Max) |
| 2344 | break; |
| 2345 | case ICmpInst::ICMP_SGE: |
| 2346 | Upper = APInt::getSignedMinValue(BitWidth); // Min = Next(Max) |
| 2347 | break; |
| 2348 | } |
| 2349 | return ConstantRange(Lower, Upper); |
| 2350 | } |
| 2351 | |
Reid Spencer | d9436b6 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 2352 | FCmpInst::Predicate FCmpInst::getInversePredicate(Predicate pred) { |
| 2353 | switch (pred) { |
| 2354 | default: |
| 2355 | assert(!"Unknown icmp predicate!"); |
| 2356 | case FCMP_OEQ: return FCMP_UNE; |
| 2357 | case FCMP_ONE: return FCMP_UEQ; |
| 2358 | case FCMP_OGT: return FCMP_ULE; |
| 2359 | case FCMP_OLT: return FCMP_UGE; |
| 2360 | case FCMP_OGE: return FCMP_ULT; |
| 2361 | case FCMP_OLE: return FCMP_UGT; |
| 2362 | case FCMP_UEQ: return FCMP_ONE; |
| 2363 | case FCMP_UNE: return FCMP_OEQ; |
| 2364 | case FCMP_UGT: return FCMP_OLE; |
| 2365 | case FCMP_ULT: return FCMP_OGE; |
| 2366 | case FCMP_UGE: return FCMP_OLT; |
| 2367 | case FCMP_ULE: return FCMP_OGT; |
| 2368 | case FCMP_ORD: return FCMP_UNO; |
| 2369 | case FCMP_UNO: return FCMP_ORD; |
| 2370 | case FCMP_TRUE: return FCMP_FALSE; |
| 2371 | case FCMP_FALSE: return FCMP_TRUE; |
| 2372 | } |
| 2373 | } |
| 2374 | |
| 2375 | FCmpInst::Predicate FCmpInst::getSwappedPredicate(Predicate pred) { |
| 2376 | switch (pred) { |
Reid Spencer | 266e42b | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 2377 | default: assert(!"Unknown fcmp predicate!"); |
Reid Spencer | d9436b6 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 2378 | case FCMP_FALSE: case FCMP_TRUE: |
| 2379 | case FCMP_OEQ: case FCMP_ONE: |
| 2380 | case FCMP_UEQ: case FCMP_UNE: |
| 2381 | case FCMP_ORD: case FCMP_UNO: |
| 2382 | return pred; |
| 2383 | case FCMP_OGT: return FCMP_OLT; |
| 2384 | case FCMP_OLT: return FCMP_OGT; |
| 2385 | case FCMP_OGE: return FCMP_OLE; |
| 2386 | case FCMP_OLE: return FCMP_OGE; |
| 2387 | case FCMP_UGT: return FCMP_ULT; |
| 2388 | case FCMP_ULT: return FCMP_UGT; |
| 2389 | case FCMP_UGE: return FCMP_ULE; |
| 2390 | case FCMP_ULE: return FCMP_UGE; |
| 2391 | } |
| 2392 | } |
| 2393 | |
Reid Spencer | 266e42b | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 2394 | bool CmpInst::isUnsigned(unsigned short predicate) { |
| 2395 | switch (predicate) { |
| 2396 | default: return false; |
| 2397 | case ICmpInst::ICMP_ULT: case ICmpInst::ICMP_ULE: case ICmpInst::ICMP_UGT: |
| 2398 | case ICmpInst::ICMP_UGE: return true; |
| 2399 | } |
| 2400 | } |
| 2401 | |
| 2402 | bool CmpInst::isSigned(unsigned short predicate){ |
| 2403 | switch (predicate) { |
| 2404 | default: return false; |
| 2405 | case ICmpInst::ICMP_SLT: case ICmpInst::ICMP_SLE: case ICmpInst::ICMP_SGT: |
| 2406 | case ICmpInst::ICMP_SGE: return true; |
| 2407 | } |
| 2408 | } |
| 2409 | |
| 2410 | bool CmpInst::isOrdered(unsigned short predicate) { |
| 2411 | switch (predicate) { |
| 2412 | default: return false; |
| 2413 | case FCmpInst::FCMP_OEQ: case FCmpInst::FCMP_ONE: case FCmpInst::FCMP_OGT: |
| 2414 | case FCmpInst::FCMP_OLT: case FCmpInst::FCMP_OGE: case FCmpInst::FCMP_OLE: |
| 2415 | case FCmpInst::FCMP_ORD: return true; |
| 2416 | } |
| 2417 | } |
| 2418 | |
| 2419 | bool CmpInst::isUnordered(unsigned short predicate) { |
| 2420 | switch (predicate) { |
| 2421 | default: return false; |
| 2422 | case FCmpInst::FCMP_UEQ: case FCmpInst::FCMP_UNE: case FCmpInst::FCMP_UGT: |
| 2423 | case FCmpInst::FCMP_ULT: case FCmpInst::FCMP_UGE: case FCmpInst::FCMP_ULE: |
| 2424 | case FCmpInst::FCMP_UNO: return true; |
| 2425 | } |
| 2426 | } |
| 2427 | |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 2428 | //===----------------------------------------------------------------------===// |
| 2429 | // SwitchInst Implementation |
| 2430 | //===----------------------------------------------------------------------===// |
| 2431 | |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 2432 | void SwitchInst::init(Value *Value, BasicBlock *Default, unsigned NumCases) { |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 2433 | assert(Value && Default); |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 2434 | ReservedSpace = 2+NumCases*2; |
| 2435 | NumOperands = 2; |
| 2436 | OperandList = new Use[ReservedSpace]; |
| 2437 | |
| 2438 | OperandList[0].init(Value, this); |
| 2439 | OperandList[1].init(Default, this); |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 2440 | } |
| 2441 | |
Chris Lattner | 2195fc4 | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 2442 | /// SwitchInst ctor - Create a new switch instruction, specifying a value to |
| 2443 | /// switch on and a default destination. The number of additional cases can |
| 2444 | /// be specified here to make memory allocation more efficient. This |
| 2445 | /// constructor can also autoinsert before another instruction. |
| 2446 | SwitchInst::SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases, |
| 2447 | Instruction *InsertBefore) |
| 2448 | : TerminatorInst(Type::VoidTy, Instruction::Switch, 0, 0, InsertBefore) { |
| 2449 | init(Value, Default, NumCases); |
| 2450 | } |
| 2451 | |
| 2452 | /// SwitchInst ctor - Create a new switch instruction, specifying a value to |
| 2453 | /// switch on and a default destination. The number of additional cases can |
| 2454 | /// be specified here to make memory allocation more efficient. This |
| 2455 | /// constructor also autoinserts at the end of the specified BasicBlock. |
| 2456 | SwitchInst::SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases, |
| 2457 | BasicBlock *InsertAtEnd) |
| 2458 | : TerminatorInst(Type::VoidTy, Instruction::Switch, 0, 0, InsertAtEnd) { |
| 2459 | init(Value, Default, NumCases); |
| 2460 | } |
| 2461 | |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 2462 | SwitchInst::SwitchInst(const SwitchInst &SI) |
Chris Lattner | 2195fc4 | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 2463 | : TerminatorInst(Type::VoidTy, Instruction::Switch, |
| 2464 | new Use[SI.getNumOperands()], SI.getNumOperands()) { |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 2465 | Use *OL = OperandList, *InOL = SI.OperandList; |
| 2466 | for (unsigned i = 0, E = SI.getNumOperands(); i != E; i+=2) { |
| 2467 | OL[i].init(InOL[i], this); |
| 2468 | OL[i+1].init(InOL[i+1], this); |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 2469 | } |
| 2470 | } |
| 2471 | |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 2472 | SwitchInst::~SwitchInst() { |
| 2473 | delete [] OperandList; |
| 2474 | } |
| 2475 | |
| 2476 | |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 2477 | /// addCase - Add an entry to the switch instruction... |
| 2478 | /// |
Chris Lattner | 47ac187 | 2005-02-24 05:32:09 +0000 | [diff] [blame] | 2479 | void SwitchInst::addCase(ConstantInt *OnVal, BasicBlock *Dest) { |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 2480 | unsigned OpNo = NumOperands; |
| 2481 | if (OpNo+2 > ReservedSpace) |
| 2482 | resizeOperands(0); // Get more space! |
| 2483 | // Initialize some new operands. |
Chris Lattner | f711f8d | 2005-01-29 01:05:12 +0000 | [diff] [blame] | 2484 | assert(OpNo+1 < ReservedSpace && "Growing didn't work!"); |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 2485 | NumOperands = OpNo+2; |
| 2486 | OperandList[OpNo].init(OnVal, this); |
| 2487 | OperandList[OpNo+1].init(Dest, this); |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 2488 | } |
| 2489 | |
| 2490 | /// removeCase - This method removes the specified successor from the switch |
| 2491 | /// instruction. Note that this cannot be used to remove the default |
| 2492 | /// destination (successor #0). |
| 2493 | /// |
| 2494 | void SwitchInst::removeCase(unsigned idx) { |
| 2495 | assert(idx != 0 && "Cannot remove the default case!"); |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 2496 | assert(idx*2 < getNumOperands() && "Successor index out of range!!!"); |
| 2497 | |
| 2498 | unsigned NumOps = getNumOperands(); |
| 2499 | Use *OL = OperandList; |
| 2500 | |
| 2501 | // Move everything after this operand down. |
| 2502 | // |
| 2503 | // FIXME: we could just swap with the end of the list, then erase. However, |
| 2504 | // client might not expect this to happen. The code as it is thrashes the |
| 2505 | // use/def lists, which is kinda lame. |
| 2506 | for (unsigned i = (idx+1)*2; i != NumOps; i += 2) { |
| 2507 | OL[i-2] = OL[i]; |
| 2508 | OL[i-2+1] = OL[i+1]; |
| 2509 | } |
| 2510 | |
| 2511 | // Nuke the last value. |
| 2512 | OL[NumOps-2].set(0); |
| 2513 | OL[NumOps-2+1].set(0); |
| 2514 | NumOperands = NumOps-2; |
| 2515 | } |
| 2516 | |
| 2517 | /// resizeOperands - resize operands - This adjusts the length of the operands |
| 2518 | /// list according to the following behavior: |
| 2519 | /// 1. If NumOps == 0, grow the operand list in response to a push_back style |
| 2520 | /// of operation. This grows the number of ops by 1.5 times. |
| 2521 | /// 2. If NumOps > NumOperands, reserve space for NumOps operands. |
| 2522 | /// 3. If NumOps == NumOperands, trim the reserved space. |
| 2523 | /// |
| 2524 | void SwitchInst::resizeOperands(unsigned NumOps) { |
| 2525 | if (NumOps == 0) { |
Chris Lattner | f711f8d | 2005-01-29 01:05:12 +0000 | [diff] [blame] | 2526 | NumOps = getNumOperands()/2*6; |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 2527 | } else if (NumOps*2 > NumOperands) { |
| 2528 | // No resize needed. |
| 2529 | if (ReservedSpace >= NumOps) return; |
| 2530 | } else if (NumOps == NumOperands) { |
| 2531 | if (ReservedSpace == NumOps) return; |
| 2532 | } else { |
Chris Lattner | f711f8d | 2005-01-29 01:05:12 +0000 | [diff] [blame] | 2533 | return; |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 2534 | } |
| 2535 | |
| 2536 | ReservedSpace = NumOps; |
| 2537 | Use *NewOps = new Use[NumOps]; |
| 2538 | Use *OldOps = OperandList; |
| 2539 | for (unsigned i = 0, e = getNumOperands(); i != e; ++i) { |
| 2540 | NewOps[i].init(OldOps[i], this); |
| 2541 | OldOps[i].set(0); |
| 2542 | } |
| 2543 | delete [] OldOps; |
| 2544 | OperandList = NewOps; |
| 2545 | } |
| 2546 | |
| 2547 | |
| 2548 | BasicBlock *SwitchInst::getSuccessorV(unsigned idx) const { |
| 2549 | return getSuccessor(idx); |
| 2550 | } |
| 2551 | unsigned SwitchInst::getNumSuccessorsV() const { |
| 2552 | return getNumSuccessors(); |
| 2553 | } |
| 2554 | void SwitchInst::setSuccessorV(unsigned idx, BasicBlock *B) { |
| 2555 | setSuccessor(idx, B); |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 2556 | } |
Chris Lattner | f22be93 | 2004-10-15 23:52:53 +0000 | [diff] [blame] | 2557 | |
| 2558 | |
| 2559 | // Define these methods here so vtables don't get emitted into every translation |
| 2560 | // unit that uses these classes. |
| 2561 | |
| 2562 | GetElementPtrInst *GetElementPtrInst::clone() const { |
| 2563 | return new GetElementPtrInst(*this); |
| 2564 | } |
| 2565 | |
| 2566 | BinaryOperator *BinaryOperator::clone() const { |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 2567 | return create(getOpcode(), Ops[0], Ops[1]); |
Chris Lattner | f22be93 | 2004-10-15 23:52:53 +0000 | [diff] [blame] | 2568 | } |
| 2569 | |
Chris Lattner | 0b490b0 | 2007-08-24 20:48:18 +0000 | [diff] [blame] | 2570 | FCmpInst* FCmpInst::clone() const { |
| 2571 | return new FCmpInst(getPredicate(), Ops[0], Ops[1]); |
| 2572 | } |
| 2573 | ICmpInst* ICmpInst::clone() const { |
| 2574 | return new ICmpInst(getPredicate(), Ops[0], Ops[1]); |
Reid Spencer | d9436b6 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 2575 | } |
| 2576 | |
Reid Spencer | 6c38f0b | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 2577 | MallocInst *MallocInst::clone() const { return new MallocInst(*this); } |
| 2578 | AllocaInst *AllocaInst::clone() const { return new AllocaInst(*this); } |
| 2579 | FreeInst *FreeInst::clone() const { return new FreeInst(getOperand(0)); } |
| 2580 | LoadInst *LoadInst::clone() const { return new LoadInst(*this); } |
| 2581 | StoreInst *StoreInst::clone() const { return new StoreInst(*this); } |
| 2582 | CastInst *TruncInst::clone() const { return new TruncInst(*this); } |
| 2583 | CastInst *ZExtInst::clone() const { return new ZExtInst(*this); } |
| 2584 | CastInst *SExtInst::clone() const { return new SExtInst(*this); } |
| 2585 | CastInst *FPTruncInst::clone() const { return new FPTruncInst(*this); } |
| 2586 | CastInst *FPExtInst::clone() const { return new FPExtInst(*this); } |
| 2587 | CastInst *UIToFPInst::clone() const { return new UIToFPInst(*this); } |
| 2588 | CastInst *SIToFPInst::clone() const { return new SIToFPInst(*this); } |
| 2589 | CastInst *FPToUIInst::clone() const { return new FPToUIInst(*this); } |
| 2590 | CastInst *FPToSIInst::clone() const { return new FPToSIInst(*this); } |
| 2591 | CastInst *PtrToIntInst::clone() const { return new PtrToIntInst(*this); } |
| 2592 | CastInst *IntToPtrInst::clone() const { return new IntToPtrInst(*this); } |
| 2593 | CastInst *BitCastInst::clone() const { return new BitCastInst(*this); } |
| 2594 | CallInst *CallInst::clone() const { return new CallInst(*this); } |
Reid Spencer | 6c38f0b | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 2595 | SelectInst *SelectInst::clone() const { return new SelectInst(*this); } |
| 2596 | VAArgInst *VAArgInst::clone() const { return new VAArgInst(*this); } |
| 2597 | |
Chris Lattner | bbe0a42 | 2006-04-08 01:18:18 +0000 | [diff] [blame] | 2598 | ExtractElementInst *ExtractElementInst::clone() const { |
| 2599 | return new ExtractElementInst(*this); |
| 2600 | } |
| 2601 | InsertElementInst *InsertElementInst::clone() const { |
| 2602 | return new InsertElementInst(*this); |
| 2603 | } |
| 2604 | ShuffleVectorInst *ShuffleVectorInst::clone() const { |
| 2605 | return new ShuffleVectorInst(*this); |
| 2606 | } |
Chris Lattner | f22be93 | 2004-10-15 23:52:53 +0000 | [diff] [blame] | 2607 | PHINode *PHINode::clone() const { return new PHINode(*this); } |
| 2608 | ReturnInst *ReturnInst::clone() const { return new ReturnInst(*this); } |
| 2609 | BranchInst *BranchInst::clone() const { return new BranchInst(*this); } |
| 2610 | SwitchInst *SwitchInst::clone() const { return new SwitchInst(*this); } |
| 2611 | InvokeInst *InvokeInst::clone() const { return new InvokeInst(*this); } |
| 2612 | UnwindInst *UnwindInst::clone() const { return new UnwindInst(); } |
Chris Lattner | 5e0b9f2 | 2004-10-16 18:08:06 +0000 | [diff] [blame] | 2613 | UnreachableInst *UnreachableInst::clone() const { return new UnreachableInst();} |