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