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" |
| 20 | #include "llvm/Support/CallSite.h" |
| 21 | using namespace llvm; |
| 22 | |
Chris Lattner | f7b6d31 | 2005-05-06 20:26:43 +0000 | [diff] [blame] | 23 | unsigned CallSite::getCallingConv() const { |
| 24 | if (CallInst *CI = dyn_cast<CallInst>(I)) |
| 25 | return CI->getCallingConv(); |
| 26 | else |
| 27 | return cast<InvokeInst>(I)->getCallingConv(); |
| 28 | } |
| 29 | void CallSite::setCallingConv(unsigned CC) { |
| 30 | if (CallInst *CI = dyn_cast<CallInst>(I)) |
| 31 | CI->setCallingConv(CC); |
| 32 | else |
| 33 | cast<InvokeInst>(I)->setCallingConv(CC); |
| 34 | } |
| 35 | |
| 36 | |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 37 | //===----------------------------------------------------------------------===// |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 38 | // TerminatorInst Class |
| 39 | //===----------------------------------------------------------------------===// |
| 40 | |
| 41 | TerminatorInst::TerminatorInst(Instruction::TermOps iType, |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 42 | Use *Ops, unsigned NumOps, Instruction *IB) |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 43 | : Instruction(Type::VoidTy, iType, Ops, NumOps, "", IB) { |
| 44 | } |
| 45 | |
| 46 | TerminatorInst::TerminatorInst(Instruction::TermOps iType, |
| 47 | Use *Ops, unsigned NumOps, BasicBlock *IAE) |
| 48 | : Instruction(Type::VoidTy, iType, Ops, NumOps, "", IAE) { |
| 49 | } |
| 50 | |
| 51 | |
| 52 | |
| 53 | //===----------------------------------------------------------------------===// |
| 54 | // PHINode Class |
| 55 | //===----------------------------------------------------------------------===// |
| 56 | |
| 57 | PHINode::PHINode(const PHINode &PN) |
| 58 | : Instruction(PN.getType(), Instruction::PHI, |
| 59 | new Use[PN.getNumOperands()], PN.getNumOperands()), |
| 60 | ReservedSpace(PN.getNumOperands()) { |
| 61 | Use *OL = OperandList; |
| 62 | for (unsigned i = 0, e = PN.getNumOperands(); i != e; i+=2) { |
| 63 | OL[i].init(PN.getOperand(i), this); |
| 64 | OL[i+1].init(PN.getOperand(i+1), this); |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | PHINode::~PHINode() { |
| 69 | delete [] OperandList; |
| 70 | } |
| 71 | |
| 72 | // removeIncomingValue - Remove an incoming value. This is useful if a |
| 73 | // predecessor basic block is deleted. |
| 74 | Value *PHINode::removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty) { |
| 75 | unsigned NumOps = getNumOperands(); |
| 76 | Use *OL = OperandList; |
| 77 | assert(Idx*2 < NumOps && "BB not in PHI node!"); |
| 78 | Value *Removed = OL[Idx*2]; |
| 79 | |
| 80 | // Move everything after this operand down. |
| 81 | // |
| 82 | // FIXME: we could just swap with the end of the list, then erase. However, |
| 83 | // client might not expect this to happen. The code as it is thrashes the |
| 84 | // use/def lists, which is kinda lame. |
| 85 | for (unsigned i = (Idx+1)*2; i != NumOps; i += 2) { |
| 86 | OL[i-2] = OL[i]; |
| 87 | OL[i-2+1] = OL[i+1]; |
| 88 | } |
| 89 | |
| 90 | // Nuke the last value. |
| 91 | OL[NumOps-2].set(0); |
| 92 | OL[NumOps-2+1].set(0); |
| 93 | NumOperands = NumOps-2; |
| 94 | |
| 95 | // If the PHI node is dead, because it has zero entries, nuke it now. |
| 96 | if (NumOps == 2 && DeletePHIIfEmpty) { |
| 97 | // If anyone is using this PHI, make them use a dummy value instead... |
| 98 | replaceAllUsesWith(UndefValue::get(getType())); |
| 99 | eraseFromParent(); |
| 100 | } |
| 101 | return Removed; |
| 102 | } |
| 103 | |
| 104 | /// resizeOperands - resize operands - This adjusts the length of the operands |
| 105 | /// list according to the following behavior: |
| 106 | /// 1. If NumOps == 0, grow the operand list in response to a push_back style |
| 107 | /// of operation. This grows the number of ops by 1.5 times. |
| 108 | /// 2. If NumOps > NumOperands, reserve space for NumOps operands. |
| 109 | /// 3. If NumOps == NumOperands, trim the reserved space. |
| 110 | /// |
| 111 | void PHINode::resizeOperands(unsigned NumOps) { |
| 112 | if (NumOps == 0) { |
| 113 | NumOps = (getNumOperands())*3/2; |
| 114 | if (NumOps < 4) NumOps = 4; // 4 op PHI nodes are VERY common. |
| 115 | } else if (NumOps*2 > NumOperands) { |
| 116 | // No resize needed. |
| 117 | if (ReservedSpace >= NumOps) return; |
| 118 | } else if (NumOps == NumOperands) { |
| 119 | if (ReservedSpace == NumOps) return; |
| 120 | } else { |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 121 | return; |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | ReservedSpace = NumOps; |
| 125 | Use *NewOps = new Use[NumOps]; |
| 126 | Use *OldOps = OperandList; |
| 127 | for (unsigned i = 0, e = getNumOperands(); i != e; ++i) { |
| 128 | NewOps[i].init(OldOps[i], this); |
| 129 | OldOps[i].set(0); |
| 130 | } |
| 131 | delete [] OldOps; |
| 132 | OperandList = NewOps; |
| 133 | } |
| 134 | |
Nate Begeman | b392321 | 2005-08-04 23:24:19 +0000 | [diff] [blame] | 135 | /// hasConstantValue - If the specified PHI node always merges together the same |
| 136 | /// value, return the value, otherwise return null. |
| 137 | /// |
Chris Lattner | 1d8b248 | 2005-08-05 00:49:06 +0000 | [diff] [blame] | 138 | Value *PHINode::hasConstantValue(bool AllowNonDominatingInstruction) const { |
Nate Begeman | b392321 | 2005-08-04 23:24:19 +0000 | [diff] [blame] | 139 | // If the PHI node only has one incoming value, eliminate the PHI node... |
| 140 | if (getNumIncomingValues() == 1) |
Chris Lattner | 6e709c1 | 2005-08-05 15:37:31 +0000 | [diff] [blame] | 141 | if (getIncomingValue(0) != this) // not X = phi X |
| 142 | return getIncomingValue(0); |
| 143 | else |
| 144 | return UndefValue::get(getType()); // Self cycle is dead. |
| 145 | |
Nate Begeman | b392321 | 2005-08-04 23:24:19 +0000 | [diff] [blame] | 146 | // Otherwise if all of the incoming values are the same for the PHI, replace |
| 147 | // the PHI node with the incoming value. |
| 148 | // |
| 149 | Value *InVal = 0; |
Chris Lattner | bcd8d2c | 2005-08-05 01:00:58 +0000 | [diff] [blame] | 150 | bool HasUndefInput = false; |
Nate Begeman | b392321 | 2005-08-04 23:24:19 +0000 | [diff] [blame] | 151 | for (unsigned i = 0, e = getNumIncomingValues(); i != e; ++i) |
Chris Lattner | bcd8d2c | 2005-08-05 01:00:58 +0000 | [diff] [blame] | 152 | if (isa<UndefValue>(getIncomingValue(i))) |
| 153 | HasUndefInput = true; |
| 154 | else if (getIncomingValue(i) != this) // Not the PHI node itself... |
Nate Begeman | b392321 | 2005-08-04 23:24:19 +0000 | [diff] [blame] | 155 | if (InVal && getIncomingValue(i) != InVal) |
| 156 | return 0; // Not the same, bail out. |
| 157 | else |
| 158 | InVal = getIncomingValue(i); |
| 159 | |
| 160 | // The only case that could cause InVal to be null is if we have a PHI node |
| 161 | // that only has entries for itself. In this case, there is no entry into the |
| 162 | // loop, so kill the PHI. |
| 163 | // |
| 164 | if (InVal == 0) InVal = UndefValue::get(getType()); |
| 165 | |
Chris Lattner | bcd8d2c | 2005-08-05 01:00:58 +0000 | [diff] [blame] | 166 | // If we have a PHI node like phi(X, undef, X), where X is defined by some |
| 167 | // instruction, we cannot always return X as the result of the PHI node. Only |
| 168 | // do this if X is not an instruction (thus it must dominate the PHI block), |
| 169 | // or if the client is prepared to deal with this possibility. |
| 170 | if (HasUndefInput && !AllowNonDominatingInstruction) |
| 171 | if (Instruction *IV = dyn_cast<Instruction>(InVal)) |
| 172 | // If it's in the entry block, it dominates everything. |
Chris Lattner | 37774af | 2005-08-05 01:03:27 +0000 | [diff] [blame] | 173 | if (IV->getParent() != &IV->getParent()->getParent()->front() || |
| 174 | isa<InvokeInst>(IV)) |
Chris Lattner | bcd8d2c | 2005-08-05 01:00:58 +0000 | [diff] [blame] | 175 | return 0; // Cannot guarantee that InVal dominates this PHINode. |
| 176 | |
Nate Begeman | b392321 | 2005-08-04 23:24:19 +0000 | [diff] [blame] | 177 | // All of the incoming values are the same, return the value now. |
| 178 | return InVal; |
| 179 | } |
| 180 | |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 181 | |
| 182 | //===----------------------------------------------------------------------===// |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 183 | // CallInst Implementation |
| 184 | //===----------------------------------------------------------------------===// |
| 185 | |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 186 | CallInst::~CallInst() { |
| 187 | delete [] OperandList; |
| 188 | } |
| 189 | |
| 190 | void CallInst::init(Value *Func, const std::vector<Value*> &Params) { |
| 191 | NumOperands = Params.size()+1; |
| 192 | Use *OL = OperandList = new Use[Params.size()+1]; |
| 193 | OL[0].init(Func, this); |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 194 | |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 195 | const FunctionType *FTy = |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 196 | cast<FunctionType>(cast<PointerType>(Func->getType())->getElementType()); |
| 197 | |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 198 | assert((Params.size() == FTy->getNumParams() || |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 199 | (FTy->isVarArg() && Params.size() > FTy->getNumParams())) && |
| 200 | "Calling a function with bad signature"); |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 201 | for (unsigned i = 0, e = Params.size(); i != e; ++i) |
| 202 | OL[i+1].init(Params[i], this); |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 203 | } |
| 204 | |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 205 | void CallInst::init(Value *Func, Value *Actual1, Value *Actual2) { |
| 206 | NumOperands = 3; |
| 207 | Use *OL = OperandList = new Use[3]; |
| 208 | OL[0].init(Func, this); |
| 209 | OL[1].init(Actual1, this); |
| 210 | OL[2].init(Actual2, this); |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 211 | |
| 212 | const FunctionType *FTy = |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 213 | cast<FunctionType>(cast<PointerType>(Func->getType())->getElementType()); |
| 214 | |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 215 | assert((FTy->getNumParams() == 2 || |
| 216 | (FTy->isVarArg() && FTy->getNumParams() == 0)) && |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 217 | "Calling a function with bad signature"); |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 218 | } |
| 219 | |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 220 | void CallInst::init(Value *Func, Value *Actual) { |
| 221 | NumOperands = 2; |
| 222 | Use *OL = OperandList = new Use[2]; |
| 223 | OL[0].init(Func, this); |
| 224 | OL[1].init(Actual, this); |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 225 | |
| 226 | const FunctionType *FTy = |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 227 | cast<FunctionType>(cast<PointerType>(Func->getType())->getElementType()); |
| 228 | |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 229 | assert((FTy->getNumParams() == 1 || |
| 230 | (FTy->isVarArg() && FTy->getNumParams() == 0)) && |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 231 | "Calling a function with bad signature"); |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 232 | } |
| 233 | |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 234 | void CallInst::init(Value *Func) { |
| 235 | NumOperands = 1; |
| 236 | Use *OL = OperandList = new Use[1]; |
| 237 | OL[0].init(Func, this); |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 238 | |
| 239 | const FunctionType *MTy = |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 240 | cast<FunctionType>(cast<PointerType>(Func->getType())->getElementType()); |
| 241 | |
| 242 | assert(MTy->getNumParams() == 0 && "Calling a function with bad signature"); |
| 243 | } |
| 244 | |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 245 | CallInst::CallInst(Value *Func, const std::vector<Value*> &Params, |
| 246 | const std::string &Name, Instruction *InsertBefore) |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 247 | : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType()) |
| 248 | ->getElementType())->getReturnType(), |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 249 | Instruction::Call, 0, 0, Name, InsertBefore) { |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 250 | init(Func, Params); |
| 251 | } |
| 252 | |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 253 | CallInst::CallInst(Value *Func, const std::vector<Value*> &Params, |
| 254 | const std::string &Name, BasicBlock *InsertAtEnd) |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 255 | : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType()) |
| 256 | ->getElementType())->getReturnType(), |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 257 | Instruction::Call, 0, 0, Name, InsertAtEnd) { |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 258 | init(Func, Params); |
| 259 | } |
| 260 | |
| 261 | CallInst::CallInst(Value *Func, Value *Actual1, Value *Actual2, |
| 262 | const std::string &Name, Instruction *InsertBefore) |
| 263 | : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType()) |
| 264 | ->getElementType())->getReturnType(), |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 265 | Instruction::Call, 0, 0, Name, InsertBefore) { |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 266 | init(Func, Actual1, Actual2); |
| 267 | } |
| 268 | |
| 269 | CallInst::CallInst(Value *Func, Value *Actual1, Value *Actual2, |
| 270 | const std::string &Name, BasicBlock *InsertAtEnd) |
| 271 | : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType()) |
| 272 | ->getElementType())->getReturnType(), |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 273 | Instruction::Call, 0, 0, Name, InsertAtEnd) { |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 274 | init(Func, Actual1, Actual2); |
| 275 | } |
| 276 | |
| 277 | CallInst::CallInst(Value *Func, Value* Actual, const std::string &Name, |
| 278 | Instruction *InsertBefore) |
| 279 | : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType()) |
| 280 | ->getElementType())->getReturnType(), |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 281 | Instruction::Call, 0, 0, Name, InsertBefore) { |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 282 | init(Func, Actual); |
| 283 | } |
| 284 | |
| 285 | CallInst::CallInst(Value *Func, Value* Actual, const std::string &Name, |
| 286 | BasicBlock *InsertAtEnd) |
| 287 | : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType()) |
| 288 | ->getElementType())->getReturnType(), |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 289 | Instruction::Call, 0, 0, Name, InsertAtEnd) { |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 290 | init(Func, Actual); |
| 291 | } |
| 292 | |
| 293 | CallInst::CallInst(Value *Func, const std::string &Name, |
| 294 | Instruction *InsertBefore) |
| 295 | : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType()) |
| 296 | ->getElementType())->getReturnType(), |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 297 | Instruction::Call, 0, 0, Name, InsertBefore) { |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 298 | init(Func); |
| 299 | } |
| 300 | |
| 301 | CallInst::CallInst(Value *Func, const std::string &Name, |
| 302 | BasicBlock *InsertAtEnd) |
| 303 | : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType()) |
| 304 | ->getElementType())->getReturnType(), |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 305 | Instruction::Call, 0, 0, Name, InsertAtEnd) { |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 306 | init(Func); |
| 307 | } |
| 308 | |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 309 | CallInst::CallInst(const CallInst &CI) |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 310 | : Instruction(CI.getType(), Instruction::Call, new Use[CI.getNumOperands()], |
| 311 | CI.getNumOperands()) { |
Chris Lattner | f7b6d31 | 2005-05-06 20:26:43 +0000 | [diff] [blame] | 312 | SubclassData = CI.SubclassData; |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 313 | Use *OL = OperandList; |
| 314 | Use *InOL = CI.OperandList; |
| 315 | for (unsigned i = 0, e = CI.getNumOperands(); i != e; ++i) |
| 316 | OL[i].init(InOL[i], this); |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 317 | } |
| 318 | |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 319 | |
| 320 | //===----------------------------------------------------------------------===// |
| 321 | // InvokeInst Implementation |
| 322 | //===----------------------------------------------------------------------===// |
| 323 | |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 324 | InvokeInst::~InvokeInst() { |
| 325 | delete [] OperandList; |
| 326 | } |
| 327 | |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 328 | void InvokeInst::init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException, |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 329 | const std::vector<Value*> &Params) { |
| 330 | NumOperands = 3+Params.size(); |
| 331 | Use *OL = OperandList = new Use[3+Params.size()]; |
| 332 | OL[0].init(Fn, this); |
| 333 | OL[1].init(IfNormal, this); |
| 334 | OL[2].init(IfException, this); |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 335 | const FunctionType *FTy = |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 336 | cast<FunctionType>(cast<PointerType>(Fn->getType())->getElementType()); |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 337 | |
| 338 | assert((Params.size() == FTy->getNumParams()) || |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 339 | (FTy->isVarArg() && Params.size() > FTy->getNumParams()) && |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 340 | "Calling a function with bad signature"); |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 341 | |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 342 | for (unsigned i = 0, e = Params.size(); i != e; i++) |
| 343 | OL[i+3].init(Params[i], this); |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | InvokeInst::InvokeInst(Value *Fn, BasicBlock *IfNormal, |
| 347 | BasicBlock *IfException, |
| 348 | const std::vector<Value*> &Params, |
| 349 | const std::string &Name, Instruction *InsertBefore) |
| 350 | : TerminatorInst(cast<FunctionType>(cast<PointerType>(Fn->getType()) |
| 351 | ->getElementType())->getReturnType(), |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 352 | Instruction::Invoke, 0, 0, Name, InsertBefore) { |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 353 | init(Fn, IfNormal, IfException, Params); |
| 354 | } |
| 355 | |
| 356 | InvokeInst::InvokeInst(Value *Fn, BasicBlock *IfNormal, |
| 357 | BasicBlock *IfException, |
| 358 | const std::vector<Value*> &Params, |
| 359 | const std::string &Name, BasicBlock *InsertAtEnd) |
| 360 | : TerminatorInst(cast<FunctionType>(cast<PointerType>(Fn->getType()) |
| 361 | ->getElementType())->getReturnType(), |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 362 | Instruction::Invoke, 0, 0, Name, InsertAtEnd) { |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 363 | init(Fn, IfNormal, IfException, Params); |
| 364 | } |
| 365 | |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 366 | InvokeInst::InvokeInst(const InvokeInst &II) |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 367 | : TerminatorInst(II.getType(), Instruction::Invoke, |
| 368 | new Use[II.getNumOperands()], II.getNumOperands()) { |
Chris Lattner | f7b6d31 | 2005-05-06 20:26:43 +0000 | [diff] [blame] | 369 | SubclassData = II.SubclassData; |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 370 | Use *OL = OperandList, *InOL = II.OperandList; |
| 371 | for (unsigned i = 0, e = II.getNumOperands(); i != e; ++i) |
| 372 | OL[i].init(InOL[i], this); |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 373 | } |
| 374 | |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 375 | BasicBlock *InvokeInst::getSuccessorV(unsigned idx) const { |
| 376 | return getSuccessor(idx); |
| 377 | } |
| 378 | unsigned InvokeInst::getNumSuccessorsV() const { |
| 379 | return getNumSuccessors(); |
| 380 | } |
| 381 | void InvokeInst::setSuccessorV(unsigned idx, BasicBlock *B) { |
| 382 | return setSuccessor(idx, B); |
| 383 | } |
| 384 | |
| 385 | |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 386 | //===----------------------------------------------------------------------===// |
| 387 | // ReturnInst Implementation |
| 388 | //===----------------------------------------------------------------------===// |
| 389 | |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 390 | void ReturnInst::init(Value *retVal) { |
| 391 | if (retVal && retVal->getType() != Type::VoidTy) { |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 392 | assert(!isa<BasicBlock>(retVal) && |
Alkis Evlogimenos | 531e901 | 2004-11-17 21:02:25 +0000 | [diff] [blame] | 393 | "Cannot return basic block. Probably using the incorrect ctor"); |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 394 | NumOperands = 1; |
| 395 | RetVal.init(retVal, this); |
Alkis Evlogimenos | 531e901 | 2004-11-17 21:02:25 +0000 | [diff] [blame] | 396 | } |
| 397 | } |
| 398 | |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 399 | unsigned ReturnInst::getNumSuccessorsV() const { |
| 400 | return getNumSuccessors(); |
| 401 | } |
| 402 | |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 403 | // Out-of-line ReturnInst method, put here so the C++ compiler can choose to |
| 404 | // emit the vtable for the class in this translation unit. |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 405 | void ReturnInst::setSuccessorV(unsigned idx, BasicBlock *NewSucc) { |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 406 | assert(0 && "ReturnInst has no successors!"); |
| 407 | } |
| 408 | |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 409 | BasicBlock *ReturnInst::getSuccessorV(unsigned idx) const { |
| 410 | assert(0 && "ReturnInst has no successors!"); |
| 411 | abort(); |
| 412 | return 0; |
| 413 | } |
| 414 | |
| 415 | |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 416 | //===----------------------------------------------------------------------===// |
| 417 | // UnwindInst Implementation |
| 418 | //===----------------------------------------------------------------------===// |
| 419 | |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 420 | unsigned UnwindInst::getNumSuccessorsV() const { |
| 421 | return getNumSuccessors(); |
| 422 | } |
| 423 | |
| 424 | void UnwindInst::setSuccessorV(unsigned idx, BasicBlock *NewSucc) { |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 425 | assert(0 && "UnwindInst has no successors!"); |
| 426 | } |
| 427 | |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 428 | BasicBlock *UnwindInst::getSuccessorV(unsigned idx) const { |
| 429 | assert(0 && "UnwindInst has no successors!"); |
| 430 | abort(); |
| 431 | return 0; |
| 432 | } |
| 433 | |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 434 | //===----------------------------------------------------------------------===// |
Chris Lattner | 5e0b9f2 | 2004-10-16 18:08:06 +0000 | [diff] [blame] | 435 | // UnreachableInst Implementation |
| 436 | //===----------------------------------------------------------------------===// |
| 437 | |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 438 | unsigned UnreachableInst::getNumSuccessorsV() const { |
| 439 | return getNumSuccessors(); |
| 440 | } |
| 441 | |
| 442 | void UnreachableInst::setSuccessorV(unsigned idx, BasicBlock *NewSucc) { |
| 443 | assert(0 && "UnwindInst has no successors!"); |
| 444 | } |
| 445 | |
| 446 | BasicBlock *UnreachableInst::getSuccessorV(unsigned idx) const { |
| 447 | assert(0 && "UnwindInst has no successors!"); |
| 448 | abort(); |
| 449 | return 0; |
Chris Lattner | 5e0b9f2 | 2004-10-16 18:08:06 +0000 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | //===----------------------------------------------------------------------===// |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 453 | // BranchInst Implementation |
| 454 | //===----------------------------------------------------------------------===// |
| 455 | |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 456 | void BranchInst::AssertOK() { |
| 457 | if (isConditional()) |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 458 | assert(getCondition()->getType() == Type::BoolTy && |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 459 | "May only branch on boolean predicates!"); |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 460 | } |
| 461 | |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 462 | BranchInst::BranchInst(const BranchInst &BI) : |
| 463 | TerminatorInst(Instruction::Br, Ops, BI.getNumOperands()) { |
| 464 | OperandList[0].init(BI.getOperand(0), this); |
| 465 | if (BI.getNumOperands() != 1) { |
| 466 | assert(BI.getNumOperands() == 3 && "BR can have 1 or 3 operands!"); |
| 467 | OperandList[1].init(BI.getOperand(1), this); |
| 468 | OperandList[2].init(BI.getOperand(2), this); |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 469 | } |
| 470 | } |
| 471 | |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 472 | BasicBlock *BranchInst::getSuccessorV(unsigned idx) const { |
| 473 | return getSuccessor(idx); |
| 474 | } |
| 475 | unsigned BranchInst::getNumSuccessorsV() const { |
| 476 | return getNumSuccessors(); |
| 477 | } |
| 478 | void BranchInst::setSuccessorV(unsigned idx, BasicBlock *B) { |
| 479 | setSuccessor(idx, B); |
| 480 | } |
| 481 | |
| 482 | |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 483 | //===----------------------------------------------------------------------===// |
| 484 | // AllocationInst Implementation |
| 485 | //===----------------------------------------------------------------------===// |
| 486 | |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 487 | static Value *getAISize(Value *Amt) { |
| 488 | if (!Amt) |
| 489 | Amt = ConstantUInt::get(Type::UIntTy, 1); |
| 490 | else |
| 491 | assert(Amt->getType() == Type::UIntTy && |
| 492 | "Malloc/Allocation array size != UIntTy!"); |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 493 | return Amt; |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 494 | } |
| 495 | |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 496 | AllocationInst::AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, |
Nate Begeman | 848622f | 2005-11-05 09:21:28 +0000 | [diff] [blame] | 497 | unsigned Align, const std::string &Name, |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 498 | Instruction *InsertBefore) |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 499 | : UnaryInstruction(PointerType::get(Ty), iTy, getAISize(ArraySize), |
Nate Begeman | 848622f | 2005-11-05 09:21:28 +0000 | [diff] [blame] | 500 | Name, InsertBefore), Alignment(Align) { |
Chris Lattner | 79b8c79 | 2005-11-05 21:57:54 +0000 | [diff] [blame] | 501 | assert((Align & (Align-1)) == 0 && "Alignment is not a power of 2!"); |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 502 | assert(Ty != Type::VoidTy && "Cannot allocate void!"); |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 503 | } |
| 504 | |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 505 | AllocationInst::AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, |
Nate Begeman | 848622f | 2005-11-05 09:21:28 +0000 | [diff] [blame] | 506 | unsigned Align, const std::string &Name, |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 507 | BasicBlock *InsertAtEnd) |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 508 | : UnaryInstruction(PointerType::get(Ty), iTy, getAISize(ArraySize), |
Nate Begeman | 848622f | 2005-11-05 09:21:28 +0000 | [diff] [blame] | 509 | Name, InsertAtEnd), Alignment(Align) { |
Chris Lattner | 79b8c79 | 2005-11-05 21:57:54 +0000 | [diff] [blame] | 510 | assert((Align & (Align-1)) == 0 && "Alignment is not a power of 2!"); |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 511 | assert(Ty != Type::VoidTy && "Cannot allocate void!"); |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 512 | } |
| 513 | |
| 514 | bool AllocationInst::isArrayAllocation() const { |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 515 | if (ConstantUInt *CUI = dyn_cast<ConstantUInt>(getOperand(0))) |
| 516 | return CUI->getValue() != 1; |
| 517 | return true; |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 518 | } |
| 519 | |
| 520 | const Type *AllocationInst::getAllocatedType() const { |
| 521 | return getType()->getElementType(); |
| 522 | } |
| 523 | |
| 524 | AllocaInst::AllocaInst(const AllocaInst &AI) |
| 525 | : AllocationInst(AI.getType()->getElementType(), (Value*)AI.getOperand(0), |
Nate Begeman | 848622f | 2005-11-05 09:21:28 +0000 | [diff] [blame] | 526 | Instruction::Alloca, AI.getAlignment()) { |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 527 | } |
| 528 | |
| 529 | MallocInst::MallocInst(const MallocInst &MI) |
| 530 | : AllocationInst(MI.getType()->getElementType(), (Value*)MI.getOperand(0), |
Nate Begeman | 848622f | 2005-11-05 09:21:28 +0000 | [diff] [blame] | 531 | Instruction::Malloc, MI.getAlignment()) { |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 532 | } |
| 533 | |
| 534 | //===----------------------------------------------------------------------===// |
| 535 | // FreeInst Implementation |
| 536 | //===----------------------------------------------------------------------===// |
| 537 | |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 538 | void FreeInst::AssertOK() { |
| 539 | assert(isa<PointerType>(getOperand(0)->getType()) && |
| 540 | "Can not free something of nonpointer type!"); |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 541 | } |
| 542 | |
| 543 | FreeInst::FreeInst(Value *Ptr, Instruction *InsertBefore) |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 544 | : UnaryInstruction(Type::VoidTy, Free, Ptr, "", InsertBefore) { |
| 545 | AssertOK(); |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 546 | } |
| 547 | |
| 548 | FreeInst::FreeInst(Value *Ptr, BasicBlock *InsertAtEnd) |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 549 | : UnaryInstruction(Type::VoidTy, Free, Ptr, "", InsertAtEnd) { |
| 550 | AssertOK(); |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 551 | } |
| 552 | |
| 553 | |
| 554 | //===----------------------------------------------------------------------===// |
| 555 | // LoadInst Implementation |
| 556 | //===----------------------------------------------------------------------===// |
| 557 | |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 558 | void LoadInst::AssertOK() { |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 559 | assert(isa<PointerType>(getOperand(0)->getType()) && |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 560 | "Ptr must have pointer type."); |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 561 | } |
| 562 | |
| 563 | LoadInst::LoadInst(Value *Ptr, const std::string &Name, Instruction *InsertBef) |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 564 | : UnaryInstruction(cast<PointerType>(Ptr->getType())->getElementType(), |
Chris Lattner | df57a02 | 2005-02-05 01:38:38 +0000 | [diff] [blame] | 565 | Load, Ptr, Name, InsertBef) { |
| 566 | setVolatile(false); |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 567 | AssertOK(); |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 568 | } |
| 569 | |
| 570 | LoadInst::LoadInst(Value *Ptr, const std::string &Name, BasicBlock *InsertAE) |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 571 | : UnaryInstruction(cast<PointerType>(Ptr->getType())->getElementType(), |
Chris Lattner | df57a02 | 2005-02-05 01:38:38 +0000 | [diff] [blame] | 572 | Load, Ptr, Name, InsertAE) { |
| 573 | setVolatile(false); |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 574 | AssertOK(); |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 575 | } |
| 576 | |
| 577 | LoadInst::LoadInst(Value *Ptr, const std::string &Name, bool isVolatile, |
| 578 | Instruction *InsertBef) |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 579 | : UnaryInstruction(cast<PointerType>(Ptr->getType())->getElementType(), |
Chris Lattner | df57a02 | 2005-02-05 01:38:38 +0000 | [diff] [blame] | 580 | Load, Ptr, Name, InsertBef) { |
| 581 | setVolatile(isVolatile); |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 582 | AssertOK(); |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 583 | } |
| 584 | |
| 585 | LoadInst::LoadInst(Value *Ptr, const std::string &Name, bool isVolatile, |
| 586 | BasicBlock *InsertAE) |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 587 | : UnaryInstruction(cast<PointerType>(Ptr->getType())->getElementType(), |
Chris Lattner | df57a02 | 2005-02-05 01:38:38 +0000 | [diff] [blame] | 588 | Load, Ptr, Name, InsertAE) { |
| 589 | setVolatile(isVolatile); |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 590 | AssertOK(); |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 591 | } |
| 592 | |
| 593 | |
| 594 | //===----------------------------------------------------------------------===// |
| 595 | // StoreInst Implementation |
| 596 | //===----------------------------------------------------------------------===// |
| 597 | |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 598 | void StoreInst::AssertOK() { |
| 599 | assert(isa<PointerType>(getOperand(1)->getType()) && |
| 600 | "Ptr must have pointer type!"); |
| 601 | assert(getOperand(0)->getType() == |
| 602 | cast<PointerType>(getOperand(1)->getType())->getElementType() |
Alkis Evlogimenos | 079fbde | 2004-08-06 14:33:37 +0000 | [diff] [blame] | 603 | && "Ptr must be a pointer to Val type!"); |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 604 | } |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 605 | |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 606 | |
| 607 | StoreInst::StoreInst(Value *val, Value *addr, Instruction *InsertBefore) |
Chris Lattner | df57a02 | 2005-02-05 01:38:38 +0000 | [diff] [blame] | 608 | : Instruction(Type::VoidTy, Store, Ops, 2, "", InsertBefore) { |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 609 | Ops[0].init(val, this); |
| 610 | Ops[1].init(addr, this); |
Chris Lattner | df57a02 | 2005-02-05 01:38:38 +0000 | [diff] [blame] | 611 | setVolatile(false); |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 612 | AssertOK(); |
| 613 | } |
| 614 | |
| 615 | StoreInst::StoreInst(Value *val, Value *addr, BasicBlock *InsertAtEnd) |
Chris Lattner | df57a02 | 2005-02-05 01:38:38 +0000 | [diff] [blame] | 616 | : Instruction(Type::VoidTy, Store, Ops, 2, "", InsertAtEnd) { |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 617 | Ops[0].init(val, this); |
| 618 | Ops[1].init(addr, this); |
Chris Lattner | df57a02 | 2005-02-05 01:38:38 +0000 | [diff] [blame] | 619 | setVolatile(false); |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 620 | AssertOK(); |
| 621 | } |
| 622 | |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 623 | StoreInst::StoreInst(Value *val, Value *addr, bool isVolatile, |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 624 | Instruction *InsertBefore) |
Chris Lattner | df57a02 | 2005-02-05 01:38:38 +0000 | [diff] [blame] | 625 | : Instruction(Type::VoidTy, Store, Ops, 2, "", InsertBefore) { |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 626 | Ops[0].init(val, this); |
| 627 | Ops[1].init(addr, this); |
Chris Lattner | df57a02 | 2005-02-05 01:38:38 +0000 | [diff] [blame] | 628 | setVolatile(isVolatile); |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 629 | AssertOK(); |
| 630 | } |
| 631 | |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 632 | StoreInst::StoreInst(Value *val, Value *addr, bool isVolatile, |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 633 | BasicBlock *InsertAtEnd) |
Chris Lattner | df57a02 | 2005-02-05 01:38:38 +0000 | [diff] [blame] | 634 | : Instruction(Type::VoidTy, Store, Ops, 2, "", InsertAtEnd) { |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 635 | Ops[0].init(val, this); |
| 636 | Ops[1].init(addr, this); |
Chris Lattner | df57a02 | 2005-02-05 01:38:38 +0000 | [diff] [blame] | 637 | setVolatile(isVolatile); |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 638 | AssertOK(); |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 639 | } |
| 640 | |
| 641 | //===----------------------------------------------------------------------===// |
| 642 | // GetElementPtrInst Implementation |
| 643 | //===----------------------------------------------------------------------===// |
| 644 | |
| 645 | // checkType - Simple wrapper function to give a better assertion failure |
| 646 | // message on bad indexes for a gep instruction. |
| 647 | // |
| 648 | static inline const Type *checkType(const Type *Ty) { |
| 649 | assert(Ty && "Invalid indices for type!"); |
| 650 | return Ty; |
| 651 | } |
| 652 | |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 653 | void GetElementPtrInst::init(Value *Ptr, const std::vector<Value*> &Idx) { |
| 654 | NumOperands = 1+Idx.size(); |
| 655 | Use *OL = OperandList = new Use[NumOperands]; |
| 656 | OL[0].init(Ptr, this); |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 657 | |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 658 | for (unsigned i = 0, e = Idx.size(); i != e; ++i) |
| 659 | OL[i+1].init(Idx[i], this); |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 660 | } |
| 661 | |
| 662 | void GetElementPtrInst::init(Value *Ptr, Value *Idx0, Value *Idx1) { |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 663 | NumOperands = 3; |
| 664 | Use *OL = OperandList = new Use[3]; |
| 665 | OL[0].init(Ptr, this); |
| 666 | OL[1].init(Idx0, this); |
| 667 | OL[2].init(Idx1, this); |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 668 | } |
| 669 | |
Chris Lattner | 8298120 | 2005-05-03 05:43:30 +0000 | [diff] [blame] | 670 | void GetElementPtrInst::init(Value *Ptr, Value *Idx) { |
| 671 | NumOperands = 2; |
| 672 | Use *OL = OperandList = new Use[2]; |
| 673 | OL[0].init(Ptr, this); |
| 674 | OL[1].init(Idx, this); |
| 675 | } |
| 676 | |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 677 | GetElementPtrInst::GetElementPtrInst(Value *Ptr, const std::vector<Value*> &Idx, |
Misha Brukman | 96eb878 | 2005-03-16 05:42:00 +0000 | [diff] [blame] | 678 | const std::string &Name, Instruction *InBe) |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 679 | : Instruction(PointerType::get(checkType(getIndexedType(Ptr->getType(), |
| 680 | Idx, true))), |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 681 | GetElementPtr, 0, 0, Name, InBe) { |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 682 | init(Ptr, Idx); |
| 683 | } |
| 684 | |
| 685 | GetElementPtrInst::GetElementPtrInst(Value *Ptr, const std::vector<Value*> &Idx, |
Misha Brukman | 96eb878 | 2005-03-16 05:42:00 +0000 | [diff] [blame] | 686 | const std::string &Name, BasicBlock *IAE) |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 687 | : Instruction(PointerType::get(checkType(getIndexedType(Ptr->getType(), |
| 688 | Idx, true))), |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 689 | GetElementPtr, 0, 0, Name, IAE) { |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 690 | init(Ptr, Idx); |
| 691 | } |
| 692 | |
Chris Lattner | 8298120 | 2005-05-03 05:43:30 +0000 | [diff] [blame] | 693 | GetElementPtrInst::GetElementPtrInst(Value *Ptr, Value *Idx, |
| 694 | const std::string &Name, Instruction *InBe) |
| 695 | : Instruction(PointerType::get(checkType(getIndexedType(Ptr->getType(),Idx))), |
| 696 | GetElementPtr, 0, 0, Name, InBe) { |
| 697 | init(Ptr, Idx); |
| 698 | } |
| 699 | |
| 700 | GetElementPtrInst::GetElementPtrInst(Value *Ptr, Value *Idx, |
| 701 | const std::string &Name, BasicBlock *IAE) |
| 702 | : Instruction(PointerType::get(checkType(getIndexedType(Ptr->getType(),Idx))), |
| 703 | GetElementPtr, 0, 0, Name, IAE) { |
| 704 | init(Ptr, Idx); |
| 705 | } |
| 706 | |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 707 | GetElementPtrInst::GetElementPtrInst(Value *Ptr, Value *Idx0, Value *Idx1, |
| 708 | const std::string &Name, Instruction *InBe) |
| 709 | : Instruction(PointerType::get(checkType(getIndexedType(Ptr->getType(), |
| 710 | Idx0, Idx1, true))), |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 711 | GetElementPtr, 0, 0, Name, InBe) { |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 712 | init(Ptr, Idx0, Idx1); |
| 713 | } |
| 714 | |
| 715 | GetElementPtrInst::GetElementPtrInst(Value *Ptr, Value *Idx0, Value *Idx1, |
Misha Brukman | 96eb878 | 2005-03-16 05:42:00 +0000 | [diff] [blame] | 716 | const std::string &Name, BasicBlock *IAE) |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 717 | : Instruction(PointerType::get(checkType(getIndexedType(Ptr->getType(), |
| 718 | Idx0, Idx1, true))), |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 719 | GetElementPtr, 0, 0, Name, IAE) { |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 720 | init(Ptr, Idx0, Idx1); |
| 721 | } |
| 722 | |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 723 | GetElementPtrInst::~GetElementPtrInst() { |
| 724 | delete[] OperandList; |
| 725 | } |
| 726 | |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 727 | // getIndexedType - Returns the type of the element that would be loaded with |
| 728 | // a load instruction with the specified parameters. |
| 729 | // |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 730 | // 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] | 731 | // pointer type. |
| 732 | // |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 733 | const Type* GetElementPtrInst::getIndexedType(const Type *Ptr, |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 734 | const std::vector<Value*> &Idx, |
| 735 | bool AllowCompositeLeaf) { |
| 736 | if (!isa<PointerType>(Ptr)) return 0; // Type isn't a pointer type! |
| 737 | |
| 738 | // Handle the special case of the empty set index set... |
| 739 | if (Idx.empty()) |
| 740 | if (AllowCompositeLeaf || |
| 741 | cast<PointerType>(Ptr)->getElementType()->isFirstClassType()) |
| 742 | return cast<PointerType>(Ptr)->getElementType(); |
| 743 | else |
| 744 | return 0; |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 745 | |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 746 | unsigned CurIdx = 0; |
| 747 | while (const CompositeType *CT = dyn_cast<CompositeType>(Ptr)) { |
| 748 | if (Idx.size() == CurIdx) { |
| 749 | if (AllowCompositeLeaf || CT->isFirstClassType()) return Ptr; |
| 750 | return 0; // Can't load a whole structure or array!?!? |
| 751 | } |
| 752 | |
| 753 | Value *Index = Idx[CurIdx++]; |
| 754 | if (isa<PointerType>(CT) && CurIdx != 1) |
| 755 | return 0; // Can only index into pointer types at the first index! |
| 756 | if (!CT->indexValid(Index)) return 0; |
| 757 | Ptr = CT->getTypeAtIndex(Index); |
| 758 | |
| 759 | // If the new type forwards to another type, then it is in the middle |
| 760 | // of being refined to another type (and hence, may have dropped all |
| 761 | // references to what it was using before). So, use the new forwarded |
| 762 | // type. |
| 763 | if (const Type * Ty = Ptr->getForwardedType()) { |
| 764 | Ptr = Ty; |
| 765 | } |
| 766 | } |
| 767 | return CurIdx == Idx.size() ? Ptr : 0; |
| 768 | } |
| 769 | |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 770 | const Type* GetElementPtrInst::getIndexedType(const Type *Ptr, |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 771 | Value *Idx0, Value *Idx1, |
| 772 | bool AllowCompositeLeaf) { |
| 773 | const PointerType *PTy = dyn_cast<PointerType>(Ptr); |
| 774 | if (!PTy) return 0; // Type isn't a pointer type! |
| 775 | |
| 776 | // Check the pointer index. |
| 777 | if (!PTy->indexValid(Idx0)) return 0; |
| 778 | |
| 779 | const CompositeType *CT = dyn_cast<CompositeType>(PTy->getElementType()); |
| 780 | if (!CT || !CT->indexValid(Idx1)) return 0; |
| 781 | |
| 782 | const Type *ElTy = CT->getTypeAtIndex(Idx1); |
| 783 | if (AllowCompositeLeaf || ElTy->isFirstClassType()) |
| 784 | return ElTy; |
| 785 | return 0; |
| 786 | } |
| 787 | |
Chris Lattner | 8298120 | 2005-05-03 05:43:30 +0000 | [diff] [blame] | 788 | const Type* GetElementPtrInst::getIndexedType(const Type *Ptr, Value *Idx) { |
| 789 | const PointerType *PTy = dyn_cast<PointerType>(Ptr); |
| 790 | if (!PTy) return 0; // Type isn't a pointer type! |
| 791 | |
| 792 | // Check the pointer index. |
| 793 | if (!PTy->indexValid(Idx)) return 0; |
| 794 | |
Chris Lattner | c223333 | 2005-05-03 16:44:45 +0000 | [diff] [blame] | 795 | return PTy->getElementType(); |
Chris Lattner | 8298120 | 2005-05-03 05:43:30 +0000 | [diff] [blame] | 796 | } |
| 797 | |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 798 | //===----------------------------------------------------------------------===// |
Robert Bocchino | 2300448 | 2006-01-10 19:05:34 +0000 | [diff] [blame] | 799 | // ExtractElementInst Implementation |
| 800 | //===----------------------------------------------------------------------===// |
| 801 | |
| 802 | ExtractElementInst::ExtractElementInst(Value *Val, Value *Index, |
Chris Lattner | bbe0a42 | 2006-04-08 01:18:18 +0000 | [diff] [blame] | 803 | const std::string &Name, |
| 804 | Instruction *InsertBef) |
Robert Bocchino | 2300448 | 2006-01-10 19:05:34 +0000 | [diff] [blame] | 805 | : Instruction(cast<PackedType>(Val->getType())->getElementType(), |
| 806 | ExtractElement, Ops, 2, Name, InsertBef) { |
Chris Lattner | 54865b3 | 2006-04-08 04:05:48 +0000 | [diff] [blame] | 807 | assert(isValidOperands(Val, Index) && |
| 808 | "Invalid extractelement instruction operands!"); |
Robert Bocchino | 2300448 | 2006-01-10 19:05:34 +0000 | [diff] [blame] | 809 | Ops[0].init(Val, this); |
| 810 | Ops[1].init(Index, this); |
| 811 | } |
| 812 | |
| 813 | ExtractElementInst::ExtractElementInst(Value *Val, Value *Index, |
Chris Lattner | bbe0a42 | 2006-04-08 01:18:18 +0000 | [diff] [blame] | 814 | const std::string &Name, |
| 815 | BasicBlock *InsertAE) |
Robert Bocchino | 2300448 | 2006-01-10 19:05:34 +0000 | [diff] [blame] | 816 | : Instruction(cast<PackedType>(Val->getType())->getElementType(), |
| 817 | ExtractElement, Ops, 2, Name, InsertAE) { |
Chris Lattner | 54865b3 | 2006-04-08 04:05:48 +0000 | [diff] [blame] | 818 | assert(isValidOperands(Val, Index) && |
| 819 | "Invalid extractelement instruction operands!"); |
| 820 | |
Robert Bocchino | 2300448 | 2006-01-10 19:05:34 +0000 | [diff] [blame] | 821 | Ops[0].init(Val, this); |
| 822 | Ops[1].init(Index, this); |
| 823 | } |
| 824 | |
Chris Lattner | 54865b3 | 2006-04-08 04:05:48 +0000 | [diff] [blame] | 825 | bool ExtractElementInst::isValidOperands(const Value *Val, const Value *Index) { |
| 826 | if (!isa<PackedType>(Val->getType()) || Index->getType() != Type::UIntTy) |
| 827 | return false; |
| 828 | return true; |
| 829 | } |
| 830 | |
| 831 | |
Robert Bocchino | 2300448 | 2006-01-10 19:05:34 +0000 | [diff] [blame] | 832 | //===----------------------------------------------------------------------===// |
Robert Bocchino | ca27f03 | 2006-01-17 20:07:22 +0000 | [diff] [blame] | 833 | // InsertElementInst Implementation |
| 834 | //===----------------------------------------------------------------------===// |
| 835 | |
Chris Lattner | 54865b3 | 2006-04-08 04:05:48 +0000 | [diff] [blame] | 836 | InsertElementInst::InsertElementInst(Value *Vec, Value *Elt, Value *Index, |
Chris Lattner | bbe0a42 | 2006-04-08 01:18:18 +0000 | [diff] [blame] | 837 | const std::string &Name, |
| 838 | Instruction *InsertBef) |
Chris Lattner | 54865b3 | 2006-04-08 04:05:48 +0000 | [diff] [blame] | 839 | : Instruction(Vec->getType(), InsertElement, Ops, 3, Name, InsertBef) { |
| 840 | assert(isValidOperands(Vec, Elt, Index) && |
| 841 | "Invalid insertelement instruction operands!"); |
| 842 | Ops[0].init(Vec, this); |
Robert Bocchino | ca27f03 | 2006-01-17 20:07:22 +0000 | [diff] [blame] | 843 | Ops[1].init(Elt, this); |
| 844 | Ops[2].init(Index, this); |
| 845 | } |
| 846 | |
Chris Lattner | 54865b3 | 2006-04-08 04:05:48 +0000 | [diff] [blame] | 847 | InsertElementInst::InsertElementInst(Value *Vec, Value *Elt, Value *Index, |
Chris Lattner | bbe0a42 | 2006-04-08 01:18:18 +0000 | [diff] [blame] | 848 | const std::string &Name, |
| 849 | BasicBlock *InsertAE) |
Chris Lattner | 54865b3 | 2006-04-08 04:05:48 +0000 | [diff] [blame] | 850 | : Instruction(Vec->getType(), InsertElement, Ops, 3, Name, InsertAE) { |
| 851 | assert(isValidOperands(Vec, Elt, Index) && |
| 852 | "Invalid insertelement instruction operands!"); |
| 853 | |
| 854 | Ops[0].init(Vec, this); |
Robert Bocchino | ca27f03 | 2006-01-17 20:07:22 +0000 | [diff] [blame] | 855 | Ops[1].init(Elt, this); |
| 856 | Ops[2].init(Index, this); |
| 857 | } |
| 858 | |
Chris Lattner | 54865b3 | 2006-04-08 04:05:48 +0000 | [diff] [blame] | 859 | bool InsertElementInst::isValidOperands(const Value *Vec, const Value *Elt, |
| 860 | const Value *Index) { |
| 861 | if (!isa<PackedType>(Vec->getType())) |
| 862 | return false; // First operand of insertelement must be packed type. |
| 863 | |
| 864 | if (Elt->getType() != cast<PackedType>(Vec->getType())->getElementType()) |
| 865 | return false;// Second operand of insertelement must be packed element type. |
| 866 | |
| 867 | if (Index->getType() != Type::UIntTy) |
| 868 | return false; // Third operand of insertelement must be uint. |
| 869 | return true; |
| 870 | } |
| 871 | |
| 872 | |
Robert Bocchino | ca27f03 | 2006-01-17 20:07:22 +0000 | [diff] [blame] | 873 | //===----------------------------------------------------------------------===// |
Chris Lattner | bbe0a42 | 2006-04-08 01:18:18 +0000 | [diff] [blame] | 874 | // ShuffleVectorInst Implementation |
| 875 | //===----------------------------------------------------------------------===// |
| 876 | |
| 877 | ShuffleVectorInst::ShuffleVectorInst(Value *V1, Value *V2, Value *Mask, |
| 878 | const std::string &Name, |
| 879 | Instruction *InsertBefore) |
| 880 | : Instruction(V1->getType(), ShuffleVector, Ops, 3, Name, InsertBefore) { |
| 881 | assert(isValidOperands(V1, V2, Mask) && |
| 882 | "Invalid shuffle vector instruction operands!"); |
| 883 | Ops[0].init(V1, this); |
| 884 | Ops[1].init(V2, this); |
| 885 | Ops[2].init(Mask, this); |
| 886 | } |
| 887 | |
| 888 | ShuffleVectorInst::ShuffleVectorInst(Value *V1, Value *V2, Value *Mask, |
| 889 | const std::string &Name, |
| 890 | BasicBlock *InsertAtEnd) |
| 891 | : Instruction(V1->getType(), ShuffleVector, Ops, 3, Name, InsertAtEnd) { |
| 892 | assert(isValidOperands(V1, V2, Mask) && |
| 893 | "Invalid shuffle vector instruction operands!"); |
| 894 | |
| 895 | Ops[0].init(V1, this); |
| 896 | Ops[1].init(V2, this); |
| 897 | Ops[2].init(Mask, this); |
| 898 | } |
| 899 | |
| 900 | bool ShuffleVectorInst::isValidOperands(const Value *V1, const Value *V2, |
| 901 | const Value *Mask) { |
| 902 | if (!isa<PackedType>(V1->getType())) return false; |
| 903 | if (V1->getType() != V2->getType()) return false; |
| 904 | if (!isa<PackedType>(Mask->getType()) || |
| 905 | cast<PackedType>(Mask->getType())->getElementType() != Type::UIntTy || |
| 906 | cast<PackedType>(Mask->getType())->getNumElements() != |
| 907 | cast<PackedType>(V1->getType())->getNumElements()) |
| 908 | return false; |
| 909 | return true; |
| 910 | } |
| 911 | |
| 912 | |
| 913 | //===----------------------------------------------------------------------===// |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 914 | // BinaryOperator Class |
| 915 | //===----------------------------------------------------------------------===// |
| 916 | |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 917 | void BinaryOperator::init(BinaryOps iType) |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 918 | { |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 919 | Value *LHS = getOperand(0), *RHS = getOperand(1); |
| 920 | assert(LHS->getType() == RHS->getType() && |
| 921 | "Binary operator operand types must match!"); |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 922 | #ifndef NDEBUG |
| 923 | switch (iType) { |
| 924 | case Add: case Sub: |
| 925 | case Mul: case Div: |
| 926 | case Rem: |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 927 | assert(getType() == LHS->getType() && |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 928 | "Arithmetic operation should return same type as operands!"); |
Chris Lattner | dca56cb | 2005-12-21 18:22:19 +0000 | [diff] [blame] | 929 | assert((getType()->isInteger() || getType()->isFloatingPoint() || |
| 930 | isa<PackedType>(getType())) && |
Brian Gaeke | 0220904 | 2004-08-20 06:00:58 +0000 | [diff] [blame] | 931 | "Tried to create an arithmetic operation on a non-arithmetic type!"); |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 932 | break; |
| 933 | case And: case Or: |
| 934 | case Xor: |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 935 | assert(getType() == LHS->getType() && |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 936 | "Logical operation should return same type as operands!"); |
Chris Lattner | dca56cb | 2005-12-21 18:22:19 +0000 | [diff] [blame] | 937 | assert((getType()->isIntegral() || |
| 938 | (isa<PackedType>(getType()) && |
| 939 | cast<PackedType>(getType())->getElementType()->isIntegral())) && |
Misha Brukman | 3852f65 | 2005-01-27 06:46:38 +0000 | [diff] [blame] | 940 | "Tried to create a logical operation on a non-integral type!"); |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 941 | break; |
| 942 | case SetLT: case SetGT: case SetLE: |
| 943 | case SetGE: case SetEQ: case SetNE: |
| 944 | assert(getType() == Type::BoolTy && "Setcc must return bool!"); |
| 945 | default: |
| 946 | break; |
| 947 | } |
| 948 | #endif |
| 949 | } |
| 950 | |
| 951 | BinaryOperator *BinaryOperator::create(BinaryOps Op, Value *S1, Value *S2, |
Misha Brukman | 96eb878 | 2005-03-16 05:42:00 +0000 | [diff] [blame] | 952 | const std::string &Name, |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 953 | Instruction *InsertBefore) { |
| 954 | assert(S1->getType() == S2->getType() && |
| 955 | "Cannot create binary operator with two operands of differing type!"); |
| 956 | switch (Op) { |
| 957 | // Binary comparison operators... |
| 958 | case SetLT: case SetGT: case SetLE: |
| 959 | case SetGE: case SetEQ: case SetNE: |
| 960 | return new SetCondInst(Op, S1, S2, Name, InsertBefore); |
| 961 | |
| 962 | default: |
| 963 | return new BinaryOperator(Op, S1, S2, S1->getType(), Name, InsertBefore); |
| 964 | } |
| 965 | } |
| 966 | |
| 967 | BinaryOperator *BinaryOperator::create(BinaryOps Op, Value *S1, Value *S2, |
Misha Brukman | 96eb878 | 2005-03-16 05:42:00 +0000 | [diff] [blame] | 968 | const std::string &Name, |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 969 | BasicBlock *InsertAtEnd) { |
| 970 | BinaryOperator *Res = create(Op, S1, S2, Name); |
| 971 | InsertAtEnd->getInstList().push_back(Res); |
| 972 | return Res; |
| 973 | } |
| 974 | |
| 975 | BinaryOperator *BinaryOperator::createNeg(Value *Op, const std::string &Name, |
| 976 | Instruction *InsertBefore) { |
| 977 | if (!Op->getType()->isFloatingPoint()) |
| 978 | return new BinaryOperator(Instruction::Sub, |
| 979 | Constant::getNullValue(Op->getType()), Op, |
| 980 | Op->getType(), Name, InsertBefore); |
| 981 | else |
| 982 | return new BinaryOperator(Instruction::Sub, |
| 983 | ConstantFP::get(Op->getType(), -0.0), Op, |
| 984 | Op->getType(), Name, InsertBefore); |
| 985 | } |
| 986 | |
| 987 | BinaryOperator *BinaryOperator::createNeg(Value *Op, const std::string &Name, |
| 988 | BasicBlock *InsertAtEnd) { |
| 989 | if (!Op->getType()->isFloatingPoint()) |
| 990 | return new BinaryOperator(Instruction::Sub, |
| 991 | Constant::getNullValue(Op->getType()), Op, |
| 992 | Op->getType(), Name, InsertAtEnd); |
| 993 | else |
| 994 | return new BinaryOperator(Instruction::Sub, |
| 995 | ConstantFP::get(Op->getType(), -0.0), Op, |
| 996 | Op->getType(), Name, InsertAtEnd); |
| 997 | } |
| 998 | |
| 999 | BinaryOperator *BinaryOperator::createNot(Value *Op, const std::string &Name, |
| 1000 | Instruction *InsertBefore) { |
Chris Lattner | e8e7ac4 | 2006-03-25 21:54:21 +0000 | [diff] [blame] | 1001 | Constant *C; |
| 1002 | if (const PackedType *PTy = dyn_cast<PackedType>(Op->getType())) { |
| 1003 | C = ConstantIntegral::getAllOnesValue(PTy->getElementType()); |
| 1004 | C = ConstantPacked::get(std::vector<Constant*>(PTy->getNumElements(), C)); |
| 1005 | } else { |
| 1006 | C = ConstantIntegral::getAllOnesValue(Op->getType()); |
| 1007 | } |
| 1008 | |
| 1009 | return new BinaryOperator(Instruction::Xor, Op, C, |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 1010 | Op->getType(), Name, InsertBefore); |
| 1011 | } |
| 1012 | |
| 1013 | BinaryOperator *BinaryOperator::createNot(Value *Op, const std::string &Name, |
| 1014 | BasicBlock *InsertAtEnd) { |
Chris Lattner | dca56cb | 2005-12-21 18:22:19 +0000 | [diff] [blame] | 1015 | Constant *AllOnes; |
| 1016 | if (const PackedType *PTy = dyn_cast<PackedType>(Op->getType())) { |
| 1017 | // Create a vector of all ones values. |
| 1018 | Constant *Elt = ConstantIntegral::getAllOnesValue(PTy->getElementType()); |
| 1019 | AllOnes = |
| 1020 | ConstantPacked::get(std::vector<Constant*>(PTy->getNumElements(), Elt)); |
| 1021 | } else { |
| 1022 | AllOnes = ConstantIntegral::getAllOnesValue(Op->getType()); |
| 1023 | } |
| 1024 | |
| 1025 | return new BinaryOperator(Instruction::Xor, Op, AllOnes, |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 1026 | Op->getType(), Name, InsertAtEnd); |
| 1027 | } |
| 1028 | |
| 1029 | |
| 1030 | // isConstantAllOnes - Helper function for several functions below |
| 1031 | static inline bool isConstantAllOnes(const Value *V) { |
| 1032 | return isa<ConstantIntegral>(V) &&cast<ConstantIntegral>(V)->isAllOnesValue(); |
| 1033 | } |
| 1034 | |
| 1035 | bool BinaryOperator::isNeg(const Value *V) { |
| 1036 | if (const BinaryOperator *Bop = dyn_cast<BinaryOperator>(V)) |
| 1037 | if (Bop->getOpcode() == Instruction::Sub) |
| 1038 | if (!V->getType()->isFloatingPoint()) |
| 1039 | return Bop->getOperand(0) == Constant::getNullValue(Bop->getType()); |
| 1040 | else |
| 1041 | return Bop->getOperand(0) == ConstantFP::get(Bop->getType(), -0.0); |
| 1042 | return false; |
| 1043 | } |
| 1044 | |
| 1045 | bool BinaryOperator::isNot(const Value *V) { |
| 1046 | if (const BinaryOperator *Bop = dyn_cast<BinaryOperator>(V)) |
| 1047 | return (Bop->getOpcode() == Instruction::Xor && |
| 1048 | (isConstantAllOnes(Bop->getOperand(1)) || |
| 1049 | isConstantAllOnes(Bop->getOperand(0)))); |
| 1050 | return false; |
| 1051 | } |
| 1052 | |
Chris Lattner | 2c7d177 | 2005-04-24 07:28:37 +0000 | [diff] [blame] | 1053 | Value *BinaryOperator::getNegArgument(Value *BinOp) { |
| 1054 | assert(isNeg(BinOp) && "getNegArgument from non-'neg' instruction!"); |
| 1055 | return cast<BinaryOperator>(BinOp)->getOperand(1); |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 1056 | } |
| 1057 | |
Chris Lattner | 2c7d177 | 2005-04-24 07:28:37 +0000 | [diff] [blame] | 1058 | const Value *BinaryOperator::getNegArgument(const Value *BinOp) { |
| 1059 | return getNegArgument(const_cast<Value*>(BinOp)); |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 1060 | } |
| 1061 | |
Chris Lattner | 2c7d177 | 2005-04-24 07:28:37 +0000 | [diff] [blame] | 1062 | Value *BinaryOperator::getNotArgument(Value *BinOp) { |
| 1063 | assert(isNot(BinOp) && "getNotArgument on non-'not' instruction!"); |
| 1064 | BinaryOperator *BO = cast<BinaryOperator>(BinOp); |
| 1065 | Value *Op0 = BO->getOperand(0); |
| 1066 | Value *Op1 = BO->getOperand(1); |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 1067 | if (isConstantAllOnes(Op0)) return Op1; |
| 1068 | |
| 1069 | assert(isConstantAllOnes(Op1)); |
| 1070 | return Op0; |
| 1071 | } |
| 1072 | |
Chris Lattner | 2c7d177 | 2005-04-24 07:28:37 +0000 | [diff] [blame] | 1073 | const Value *BinaryOperator::getNotArgument(const Value *BinOp) { |
| 1074 | return getNotArgument(const_cast<Value*>(BinOp)); |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 1075 | } |
| 1076 | |
| 1077 | |
| 1078 | // swapOperands - Exchange the two operands to this instruction. This |
| 1079 | // instruction is safe to use on any binary instruction and does not |
| 1080 | // modify the semantics of the instruction. If the instruction is |
| 1081 | // order dependent (SetLT f.e.) the opcode is changed. |
| 1082 | // |
| 1083 | bool BinaryOperator::swapOperands() { |
| 1084 | if (isCommutative()) |
| 1085 | ; // If the instruction is commutative, it is safe to swap the operands |
| 1086 | else if (SetCondInst *SCI = dyn_cast<SetCondInst>(this)) |
| 1087 | /// FIXME: SetCC instructions shouldn't all have different opcodes. |
| 1088 | setOpcode(SCI->getSwappedCondition()); |
| 1089 | else |
| 1090 | return true; // Can't commute operands |
| 1091 | |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 1092 | std::swap(Ops[0], Ops[1]); |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 1093 | return false; |
| 1094 | } |
| 1095 | |
| 1096 | |
| 1097 | //===----------------------------------------------------------------------===// |
| 1098 | // SetCondInst Class |
| 1099 | //===----------------------------------------------------------------------===// |
| 1100 | |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 1101 | SetCondInst::SetCondInst(BinaryOps Opcode, Value *S1, Value *S2, |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 1102 | const std::string &Name, Instruction *InsertBefore) |
| 1103 | : BinaryOperator(Opcode, S1, S2, Type::BoolTy, Name, InsertBefore) { |
| 1104 | |
| 1105 | // Make sure it's a valid type... getInverseCondition will assert out if not. |
| 1106 | assert(getInverseCondition(Opcode)); |
| 1107 | } |
| 1108 | |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 1109 | SetCondInst::SetCondInst(BinaryOps Opcode, Value *S1, Value *S2, |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 1110 | const std::string &Name, BasicBlock *InsertAtEnd) |
| 1111 | : BinaryOperator(Opcode, S1, S2, Type::BoolTy, Name, InsertAtEnd) { |
| 1112 | |
| 1113 | // Make sure it's a valid type... getInverseCondition will assert out if not. |
| 1114 | assert(getInverseCondition(Opcode)); |
| 1115 | } |
| 1116 | |
| 1117 | // getInverseCondition - Return the inverse of the current condition opcode. |
| 1118 | // For example seteq -> setne, setgt -> setle, setlt -> setge, etc... |
| 1119 | // |
| 1120 | Instruction::BinaryOps SetCondInst::getInverseCondition(BinaryOps Opcode) { |
| 1121 | switch (Opcode) { |
| 1122 | default: |
| 1123 | assert(0 && "Unknown setcc opcode!"); |
| 1124 | case SetEQ: return SetNE; |
| 1125 | case SetNE: return SetEQ; |
| 1126 | case SetGT: return SetLE; |
| 1127 | case SetLT: return SetGE; |
| 1128 | case SetGE: return SetLT; |
| 1129 | case SetLE: return SetGT; |
| 1130 | } |
| 1131 | } |
| 1132 | |
| 1133 | // getSwappedCondition - Return the condition opcode that would be the result |
| 1134 | // of exchanging the two operands of the setcc instruction without changing |
| 1135 | // the result produced. Thus, seteq->seteq, setle->setge, setlt->setgt, etc. |
| 1136 | // |
| 1137 | Instruction::BinaryOps SetCondInst::getSwappedCondition(BinaryOps Opcode) { |
| 1138 | switch (Opcode) { |
| 1139 | default: assert(0 && "Unknown setcc instruction!"); |
| 1140 | case SetEQ: case SetNE: return Opcode; |
| 1141 | case SetGT: return SetLT; |
| 1142 | case SetLT: return SetGT; |
| 1143 | case SetGE: return SetLE; |
| 1144 | case SetLE: return SetGE; |
| 1145 | } |
| 1146 | } |
| 1147 | |
| 1148 | //===----------------------------------------------------------------------===// |
| 1149 | // SwitchInst Implementation |
| 1150 | //===----------------------------------------------------------------------===// |
| 1151 | |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 1152 | void SwitchInst::init(Value *Value, BasicBlock *Default, unsigned NumCases) { |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 1153 | assert(Value && Default); |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 1154 | ReservedSpace = 2+NumCases*2; |
| 1155 | NumOperands = 2; |
| 1156 | OperandList = new Use[ReservedSpace]; |
| 1157 | |
| 1158 | OperandList[0].init(Value, this); |
| 1159 | OperandList[1].init(Default, this); |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 1160 | } |
| 1161 | |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 1162 | SwitchInst::SwitchInst(const SwitchInst &SI) |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 1163 | : TerminatorInst(Instruction::Switch, new Use[SI.getNumOperands()], |
| 1164 | SI.getNumOperands()) { |
| 1165 | Use *OL = OperandList, *InOL = SI.OperandList; |
| 1166 | for (unsigned i = 0, E = SI.getNumOperands(); i != E; i+=2) { |
| 1167 | OL[i].init(InOL[i], this); |
| 1168 | OL[i+1].init(InOL[i+1], this); |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 1169 | } |
| 1170 | } |
| 1171 | |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 1172 | SwitchInst::~SwitchInst() { |
| 1173 | delete [] OperandList; |
| 1174 | } |
| 1175 | |
| 1176 | |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 1177 | /// addCase - Add an entry to the switch instruction... |
| 1178 | /// |
Chris Lattner | 47ac187 | 2005-02-24 05:32:09 +0000 | [diff] [blame] | 1179 | void SwitchInst::addCase(ConstantInt *OnVal, BasicBlock *Dest) { |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 1180 | unsigned OpNo = NumOperands; |
| 1181 | if (OpNo+2 > ReservedSpace) |
| 1182 | resizeOperands(0); // Get more space! |
| 1183 | // Initialize some new operands. |
Chris Lattner | f711f8d | 2005-01-29 01:05:12 +0000 | [diff] [blame] | 1184 | assert(OpNo+1 < ReservedSpace && "Growing didn't work!"); |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 1185 | NumOperands = OpNo+2; |
| 1186 | OperandList[OpNo].init(OnVal, this); |
| 1187 | OperandList[OpNo+1].init(Dest, this); |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 1188 | } |
| 1189 | |
| 1190 | /// removeCase - This method removes the specified successor from the switch |
| 1191 | /// instruction. Note that this cannot be used to remove the default |
| 1192 | /// destination (successor #0). |
| 1193 | /// |
| 1194 | void SwitchInst::removeCase(unsigned idx) { |
| 1195 | assert(idx != 0 && "Cannot remove the default case!"); |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 1196 | assert(idx*2 < getNumOperands() && "Successor index out of range!!!"); |
| 1197 | |
| 1198 | unsigned NumOps = getNumOperands(); |
| 1199 | Use *OL = OperandList; |
| 1200 | |
| 1201 | // Move everything after this operand down. |
| 1202 | // |
| 1203 | // FIXME: we could just swap with the end of the list, then erase. However, |
| 1204 | // client might not expect this to happen. The code as it is thrashes the |
| 1205 | // use/def lists, which is kinda lame. |
| 1206 | for (unsigned i = (idx+1)*2; i != NumOps; i += 2) { |
| 1207 | OL[i-2] = OL[i]; |
| 1208 | OL[i-2+1] = OL[i+1]; |
| 1209 | } |
| 1210 | |
| 1211 | // Nuke the last value. |
| 1212 | OL[NumOps-2].set(0); |
| 1213 | OL[NumOps-2+1].set(0); |
| 1214 | NumOperands = NumOps-2; |
| 1215 | } |
| 1216 | |
| 1217 | /// resizeOperands - resize operands - This adjusts the length of the operands |
| 1218 | /// list according to the following behavior: |
| 1219 | /// 1. If NumOps == 0, grow the operand list in response to a push_back style |
| 1220 | /// of operation. This grows the number of ops by 1.5 times. |
| 1221 | /// 2. If NumOps > NumOperands, reserve space for NumOps operands. |
| 1222 | /// 3. If NumOps == NumOperands, trim the reserved space. |
| 1223 | /// |
| 1224 | void SwitchInst::resizeOperands(unsigned NumOps) { |
| 1225 | if (NumOps == 0) { |
Chris Lattner | f711f8d | 2005-01-29 01:05:12 +0000 | [diff] [blame] | 1226 | NumOps = getNumOperands()/2*6; |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 1227 | } else if (NumOps*2 > NumOperands) { |
| 1228 | // No resize needed. |
| 1229 | if (ReservedSpace >= NumOps) return; |
| 1230 | } else if (NumOps == NumOperands) { |
| 1231 | if (ReservedSpace == NumOps) return; |
| 1232 | } else { |
Chris Lattner | f711f8d | 2005-01-29 01:05:12 +0000 | [diff] [blame] | 1233 | return; |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 1234 | } |
| 1235 | |
| 1236 | ReservedSpace = NumOps; |
| 1237 | Use *NewOps = new Use[NumOps]; |
| 1238 | Use *OldOps = OperandList; |
| 1239 | for (unsigned i = 0, e = getNumOperands(); i != e; ++i) { |
| 1240 | NewOps[i].init(OldOps[i], this); |
| 1241 | OldOps[i].set(0); |
| 1242 | } |
| 1243 | delete [] OldOps; |
| 1244 | OperandList = NewOps; |
| 1245 | } |
| 1246 | |
| 1247 | |
| 1248 | BasicBlock *SwitchInst::getSuccessorV(unsigned idx) const { |
| 1249 | return getSuccessor(idx); |
| 1250 | } |
| 1251 | unsigned SwitchInst::getNumSuccessorsV() const { |
| 1252 | return getNumSuccessors(); |
| 1253 | } |
| 1254 | void SwitchInst::setSuccessorV(unsigned idx, BasicBlock *B) { |
| 1255 | setSuccessor(idx, B); |
Alkis Evlogimenos | 93a7c06 | 2004-07-29 12:33:25 +0000 | [diff] [blame] | 1256 | } |
Chris Lattner | f22be93 | 2004-10-15 23:52:53 +0000 | [diff] [blame] | 1257 | |
| 1258 | |
| 1259 | // Define these methods here so vtables don't get emitted into every translation |
| 1260 | // unit that uses these classes. |
| 1261 | |
| 1262 | GetElementPtrInst *GetElementPtrInst::clone() const { |
| 1263 | return new GetElementPtrInst(*this); |
| 1264 | } |
| 1265 | |
| 1266 | BinaryOperator *BinaryOperator::clone() const { |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 1267 | return create(getOpcode(), Ops[0], Ops[1]); |
Chris Lattner | f22be93 | 2004-10-15 23:52:53 +0000 | [diff] [blame] | 1268 | } |
| 1269 | |
| 1270 | MallocInst *MallocInst::clone() const { return new MallocInst(*this); } |
| 1271 | AllocaInst *AllocaInst::clone() const { return new AllocaInst(*this); } |
Chris Lattner | afdb3de | 2005-01-29 00:35:16 +0000 | [diff] [blame] | 1272 | FreeInst *FreeInst::clone() const { return new FreeInst(getOperand(0)); } |
Chris Lattner | f22be93 | 2004-10-15 23:52:53 +0000 | [diff] [blame] | 1273 | LoadInst *LoadInst::clone() const { return new LoadInst(*this); } |
| 1274 | StoreInst *StoreInst::clone() const { return new StoreInst(*this); } |
| 1275 | CastInst *CastInst::clone() const { return new CastInst(*this); } |
| 1276 | CallInst *CallInst::clone() const { return new CallInst(*this); } |
| 1277 | ShiftInst *ShiftInst::clone() const { return new ShiftInst(*this); } |
| 1278 | SelectInst *SelectInst::clone() const { return new SelectInst(*this); } |
Chris Lattner | f22be93 | 2004-10-15 23:52:53 +0000 | [diff] [blame] | 1279 | VAArgInst *VAArgInst::clone() const { return new VAArgInst(*this); } |
Chris Lattner | bbe0a42 | 2006-04-08 01:18:18 +0000 | [diff] [blame] | 1280 | ExtractElementInst *ExtractElementInst::clone() const { |
| 1281 | return new ExtractElementInst(*this); |
| 1282 | } |
| 1283 | InsertElementInst *InsertElementInst::clone() const { |
| 1284 | return new InsertElementInst(*this); |
| 1285 | } |
| 1286 | ShuffleVectorInst *ShuffleVectorInst::clone() const { |
| 1287 | return new ShuffleVectorInst(*this); |
| 1288 | } |
Chris Lattner | f22be93 | 2004-10-15 23:52:53 +0000 | [diff] [blame] | 1289 | PHINode *PHINode::clone() const { return new PHINode(*this); } |
| 1290 | ReturnInst *ReturnInst::clone() const { return new ReturnInst(*this); } |
| 1291 | BranchInst *BranchInst::clone() const { return new BranchInst(*this); } |
| 1292 | SwitchInst *SwitchInst::clone() const { return new SwitchInst(*this); } |
| 1293 | InvokeInst *InvokeInst::clone() const { return new InvokeInst(*this); } |
| 1294 | UnwindInst *UnwindInst::clone() const { return new UnwindInst(); } |
Chris Lattner | 5e0b9f2 | 2004-10-16 18:08:06 +0000 | [diff] [blame] | 1295 | UnreachableInst *UnreachableInst::clone() const { return new UnreachableInst();} |