Chris Lattner | 28537df | 2002-05-07 18:07:59 +0000 | [diff] [blame] | 1 | //===-- Local.cpp - Functions to perform local transformations ------------===// |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 2 | // |
John Criswell | 482202a | 2003-10-20 19:43:21 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 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 | // |
John Criswell | 482202a | 2003-10-20 19:43:21 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
Chris Lattner | 28537df | 2002-05-07 18:07:59 +0000 | [diff] [blame] | 9 | // |
| 10 | // This family of functions perform various local transformations to the |
| 11 | // program. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "llvm/Transforms/Utils/Local.h" |
Chris Lattner | 2853a7e | 2004-01-12 18:35:03 +0000 | [diff] [blame] | 16 | #include "llvm/Constants.h" |
Chris Lattner | c13c7b9 | 2005-09-26 05:27:10 +0000 | [diff] [blame] | 17 | #include "llvm/DerivedTypes.h" |
Chris Lattner | 6b052f21 | 2004-01-12 19:56:36 +0000 | [diff] [blame] | 18 | #include "llvm/Instructions.h" |
Chris Lattner | ec941f7 | 2004-06-11 06:16:23 +0000 | [diff] [blame] | 19 | #include "llvm/Intrinsics.h" |
Chris Lattner | 479911f | 2005-10-27 16:34:00 +0000 | [diff] [blame] | 20 | #include "llvm/Analysis/ConstantFolding.h" |
Chris Lattner | c13c7b9 | 2005-09-26 05:27:10 +0000 | [diff] [blame] | 21 | #include "llvm/Support/GetElementPtrTypeIterator.h" |
| 22 | #include "llvm/Support/MathExtras.h" |
Alkis Evlogimenos | f68f40e | 2004-04-21 16:11:40 +0000 | [diff] [blame] | 23 | #include <cerrno> |
Brian Gaeke | 174633b | 2004-04-16 15:57:32 +0000 | [diff] [blame] | 24 | #include <cmath> |
Chris Lattner | 04efa4b | 2003-12-19 05:56:28 +0000 | [diff] [blame] | 25 | using namespace llvm; |
Brian Gaeke | 960707c | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 26 | |
Chris Lattner | 28537df | 2002-05-07 18:07:59 +0000 | [diff] [blame] | 27 | //===----------------------------------------------------------------------===// |
Misha Brukman | 373086d | 2003-05-20 21:01:22 +0000 | [diff] [blame] | 28 | // Local constant propagation... |
Chris Lattner | 28537df | 2002-05-07 18:07:59 +0000 | [diff] [blame] | 29 | // |
| 30 | |
Chris Lattner | 04efa4b | 2003-12-19 05:56:28 +0000 | [diff] [blame] | 31 | /// doConstantPropagation - If an instruction references constants, try to fold |
| 32 | /// them together... |
| 33 | /// |
| 34 | bool llvm::doConstantPropagation(BasicBlock::iterator &II) { |
Chris Lattner | fda72b1 | 2002-06-25 16:12:52 +0000 | [diff] [blame] | 35 | if (Constant *C = ConstantFoldInstruction(II)) { |
Chris Lattner | 28537df | 2002-05-07 18:07:59 +0000 | [diff] [blame] | 36 | // Replaces all of the uses of a variable with uses of the constant. |
Chris Lattner | fda72b1 | 2002-06-25 16:12:52 +0000 | [diff] [blame] | 37 | II->replaceAllUsesWith(C); |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 38 | |
Chris Lattner | 28537df | 2002-05-07 18:07:59 +0000 | [diff] [blame] | 39 | // Remove the instruction from the basic block... |
Chris Lattner | fda72b1 | 2002-06-25 16:12:52 +0000 | [diff] [blame] | 40 | II = II->getParent()->getInstList().erase(II); |
Chris Lattner | 28537df | 2002-05-07 18:07:59 +0000 | [diff] [blame] | 41 | return true; |
| 42 | } |
| 43 | |
| 44 | return false; |
| 45 | } |
| 46 | |
Chris Lattner | fc6c859 | 2004-01-12 18:25:22 +0000 | [diff] [blame] | 47 | /// ConstantFoldInstruction - Attempt to constant fold the specified |
| 48 | /// instruction. If successful, the constant result is returned, if not, null |
| 49 | /// is returned. Note that this function can only fail when attempting to fold |
| 50 | /// instructions like loads and stores, which have no constant expression form. |
| 51 | /// |
| 52 | Constant *llvm::ConstantFoldInstruction(Instruction *I) { |
| 53 | if (PHINode *PN = dyn_cast<PHINode>(I)) { |
| 54 | if (PN->getNumIncomingValues() == 0) |
| 55 | return Constant::getNullValue(PN->getType()); |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 56 | |
Chris Lattner | fc6c859 | 2004-01-12 18:25:22 +0000 | [diff] [blame] | 57 | Constant *Result = dyn_cast<Constant>(PN->getIncomingValue(0)); |
| 58 | if (Result == 0) return 0; |
| 59 | |
| 60 | // Handle PHI nodes specially here... |
| 61 | for (unsigned i = 1, e = PN->getNumIncomingValues(); i != e; ++i) |
| 62 | if (PN->getIncomingValue(i) != Result && PN->getIncomingValue(i) != PN) |
| 63 | return 0; // Not all the same incoming constants... |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 64 | |
Chris Lattner | fc6c859 | 2004-01-12 18:25:22 +0000 | [diff] [blame] | 65 | // If we reach here, all incoming values are the same constant. |
| 66 | return Result; |
Chris Lattner | ca52d04 | 2004-04-13 19:28:52 +0000 | [diff] [blame] | 67 | } else if (CallInst *CI = dyn_cast<CallInst>(I)) { |
| 68 | if (Function *F = CI->getCalledFunction()) |
| 69 | if (canConstantFoldCallTo(F)) { |
| 70 | std::vector<Constant*> Args; |
| 71 | for (unsigned i = 1, e = CI->getNumOperands(); i != e; ++i) |
| 72 | if (Constant *Op = dyn_cast<Constant>(CI->getOperand(i))) |
| 73 | Args.push_back(Op); |
| 74 | else |
| 75 | return 0; |
| 76 | return ConstantFoldCall(F, Args); |
| 77 | } |
| 78 | return 0; |
Chris Lattner | fc6c859 | 2004-01-12 18:25:22 +0000 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | Constant *Op0 = 0, *Op1 = 0; |
| 82 | switch (I->getNumOperands()) { |
| 83 | default: |
| 84 | case 2: |
| 85 | Op1 = dyn_cast<Constant>(I->getOperand(1)); |
| 86 | if (Op1 == 0) return 0; // Not a constant?, can't fold |
| 87 | case 1: |
| 88 | Op0 = dyn_cast<Constant>(I->getOperand(0)); |
| 89 | if (Op0 == 0) return 0; // Not a constant?, can't fold |
| 90 | break; |
| 91 | case 0: return 0; |
| 92 | } |
| 93 | |
Chris Lattner | 4299637 | 2004-01-12 19:10:58 +0000 | [diff] [blame] | 94 | if (isa<BinaryOperator>(I) || isa<ShiftInst>(I)) |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 95 | return ConstantExpr::get(I->getOpcode(), Op0, Op1); |
Chris Lattner | fc6c859 | 2004-01-12 18:25:22 +0000 | [diff] [blame] | 96 | |
| 97 | switch (I->getOpcode()) { |
| 98 | default: return 0; |
| 99 | case Instruction::Cast: |
| 100 | return ConstantExpr::getCast(Op0, I->getType()); |
Chris Lattner | cb015ee | 2004-03-12 05:53:03 +0000 | [diff] [blame] | 101 | case Instruction::Select: |
| 102 | if (Constant *Op2 = dyn_cast<Constant>(I->getOperand(2))) |
| 103 | return ConstantExpr::getSelect(Op0, Op1, Op2); |
| 104 | return 0; |
Robert Bocchino | 2300448 | 2006-01-10 19:05:34 +0000 | [diff] [blame] | 105 | case Instruction::ExtractElement: |
| 106 | return ConstantExpr::getExtractElement(Op0, Op1); |
Robert Bocchino | e6336a9 | 2006-01-17 20:07:07 +0000 | [diff] [blame^] | 107 | case Instruction::InsertElement: |
| 108 | if (Constant *Op2 = dyn_cast<Constant>(I->getOperand(2))) |
| 109 | return ConstantExpr::getInsertElement(Op0, Op1, Op2); |
Chris Lattner | fc6c859 | 2004-01-12 18:25:22 +0000 | [diff] [blame] | 110 | case Instruction::GetElementPtr: |
| 111 | std::vector<Constant*> IdxList; |
| 112 | IdxList.reserve(I->getNumOperands()-1); |
| 113 | if (Op1) IdxList.push_back(Op1); |
| 114 | for (unsigned i = 2, e = I->getNumOperands(); i != e; ++i) |
| 115 | if (Constant *C = dyn_cast<Constant>(I->getOperand(i))) |
| 116 | IdxList.push_back(C); |
| 117 | else |
| 118 | return 0; // Non-constant operand |
| 119 | return ConstantExpr::getGetElementPtr(Op0, IdxList); |
| 120 | } |
| 121 | } |
| 122 | |
Chris Lattner | 28537df | 2002-05-07 18:07:59 +0000 | [diff] [blame] | 123 | // ConstantFoldTerminator - If a terminator instruction is predicated on a |
| 124 | // constant value, convert it into an unconditional branch to the constant |
| 125 | // destination. |
| 126 | // |
Chris Lattner | 04efa4b | 2003-12-19 05:56:28 +0000 | [diff] [blame] | 127 | bool llvm::ConstantFoldTerminator(BasicBlock *BB) { |
Chris Lattner | 4b009ad | 2002-05-21 20:04:50 +0000 | [diff] [blame] | 128 | TerminatorInst *T = BB->getTerminator(); |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 129 | |
Chris Lattner | 28537df | 2002-05-07 18:07:59 +0000 | [diff] [blame] | 130 | // Branch - See if we are conditional jumping on constant |
| 131 | if (BranchInst *BI = dyn_cast<BranchInst>(T)) { |
| 132 | if (BI->isUnconditional()) return false; // Can't optimize uncond branch |
| 133 | BasicBlock *Dest1 = cast<BasicBlock>(BI->getOperand(0)); |
| 134 | BasicBlock *Dest2 = cast<BasicBlock>(BI->getOperand(1)); |
| 135 | |
| 136 | if (ConstantBool *Cond = dyn_cast<ConstantBool>(BI->getCondition())) { |
| 137 | // Are we branching on constant? |
| 138 | // YES. Change to unconditional branch... |
| 139 | BasicBlock *Destination = Cond->getValue() ? Dest1 : Dest2; |
| 140 | BasicBlock *OldDest = Cond->getValue() ? Dest2 : Dest1; |
| 141 | |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 142 | //cerr << "Function: " << T->getParent()->getParent() |
| 143 | // << "\nRemoving branch from " << T->getParent() |
Chris Lattner | 28537df | 2002-05-07 18:07:59 +0000 | [diff] [blame] | 144 | // << "\n\nTo: " << OldDest << endl; |
| 145 | |
| 146 | // Let the basic block know that we are letting go of it. Based on this, |
| 147 | // it will adjust it's PHI nodes. |
| 148 | assert(BI->getParent() && "Terminator not inserted in block!"); |
| 149 | OldDest->removePredecessor(BI->getParent()); |
| 150 | |
| 151 | // Set the unconditional destination, and change the insn to be an |
| 152 | // unconditional branch. |
| 153 | BI->setUnconditionalDest(Destination); |
Chris Lattner | 28537df | 2002-05-07 18:07:59 +0000 | [diff] [blame] | 154 | return true; |
Chris Lattner | 4b7e336 | 2003-08-17 19:34:55 +0000 | [diff] [blame] | 155 | } else if (Dest2 == Dest1) { // Conditional branch to same location? |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 156 | // This branch matches something like this: |
Chris Lattner | 28537df | 2002-05-07 18:07:59 +0000 | [diff] [blame] | 157 | // br bool %cond, label %Dest, label %Dest |
| 158 | // and changes it into: br label %Dest |
| 159 | |
| 160 | // Let the basic block know that we are letting go of one copy of it. |
| 161 | assert(BI->getParent() && "Terminator not inserted in block!"); |
| 162 | Dest1->removePredecessor(BI->getParent()); |
| 163 | |
| 164 | // Change a conditional branch to unconditional. |
| 165 | BI->setUnconditionalDest(Dest1); |
| 166 | return true; |
| 167 | } |
Chris Lattner | 821deee | 2003-08-17 20:21:14 +0000 | [diff] [blame] | 168 | } else if (SwitchInst *SI = dyn_cast<SwitchInst>(T)) { |
| 169 | // If we are switching on a constant, we can convert the switch into a |
| 170 | // single branch instruction! |
| 171 | ConstantInt *CI = dyn_cast<ConstantInt>(SI->getCondition()); |
| 172 | BasicBlock *TheOnlyDest = SI->getSuccessor(0); // The default dest |
Chris Lattner | c54d608 | 2003-08-23 23:18:19 +0000 | [diff] [blame] | 173 | BasicBlock *DefaultDest = TheOnlyDest; |
| 174 | assert(TheOnlyDest == SI->getDefaultDest() && |
| 175 | "Default destination is not successor #0?"); |
Chris Lattner | 031340a | 2003-08-17 19:41:53 +0000 | [diff] [blame] | 176 | |
Chris Lattner | 821deee | 2003-08-17 20:21:14 +0000 | [diff] [blame] | 177 | // Figure out which case it goes to... |
| 178 | for (unsigned i = 1, e = SI->getNumSuccessors(); i != e; ++i) { |
| 179 | // Found case matching a constant operand? |
| 180 | if (SI->getSuccessorValue(i) == CI) { |
| 181 | TheOnlyDest = SI->getSuccessor(i); |
| 182 | break; |
| 183 | } |
Chris Lattner | 031340a | 2003-08-17 19:41:53 +0000 | [diff] [blame] | 184 | |
Chris Lattner | c54d608 | 2003-08-23 23:18:19 +0000 | [diff] [blame] | 185 | // Check to see if this branch is going to the same place as the default |
| 186 | // dest. If so, eliminate it as an explicit compare. |
| 187 | if (SI->getSuccessor(i) == DefaultDest) { |
| 188 | // Remove this entry... |
| 189 | DefaultDest->removePredecessor(SI->getParent()); |
| 190 | SI->removeCase(i); |
| 191 | --i; --e; // Don't skip an entry... |
| 192 | continue; |
| 193 | } |
| 194 | |
Chris Lattner | 821deee | 2003-08-17 20:21:14 +0000 | [diff] [blame] | 195 | // Otherwise, check to see if the switch only branches to one destination. |
| 196 | // We do this by reseting "TheOnlyDest" to null when we find two non-equal |
| 197 | // destinations. |
| 198 | if (SI->getSuccessor(i) != TheOnlyDest) TheOnlyDest = 0; |
Chris Lattner | 031340a | 2003-08-17 19:41:53 +0000 | [diff] [blame] | 199 | } |
| 200 | |
Chris Lattner | 821deee | 2003-08-17 20:21:14 +0000 | [diff] [blame] | 201 | if (CI && !TheOnlyDest) { |
| 202 | // Branching on a constant, but not any of the cases, go to the default |
| 203 | // successor. |
| 204 | TheOnlyDest = SI->getDefaultDest(); |
| 205 | } |
| 206 | |
| 207 | // If we found a single destination that we can fold the switch into, do so |
| 208 | // now. |
| 209 | if (TheOnlyDest) { |
| 210 | // Insert the new branch.. |
| 211 | new BranchInst(TheOnlyDest, SI); |
| 212 | BasicBlock *BB = SI->getParent(); |
| 213 | |
| 214 | // Remove entries from PHI nodes which we no longer branch to... |
| 215 | for (unsigned i = 0, e = SI->getNumSuccessors(); i != e; ++i) { |
| 216 | // Found case matching a constant operand? |
| 217 | BasicBlock *Succ = SI->getSuccessor(i); |
| 218 | if (Succ == TheOnlyDest) |
| 219 | TheOnlyDest = 0; // Don't modify the first branch to TheOnlyDest |
| 220 | else |
| 221 | Succ->removePredecessor(BB); |
| 222 | } |
| 223 | |
| 224 | // Delete the old switch... |
| 225 | BB->getInstList().erase(SI); |
| 226 | return true; |
| 227 | } else if (SI->getNumSuccessors() == 2) { |
| 228 | // Otherwise, we can fold this switch into a conditional branch |
| 229 | // instruction if it has only one non-default destination. |
| 230 | Value *Cond = new SetCondInst(Instruction::SetEQ, SI->getCondition(), |
| 231 | SI->getSuccessorValue(1), "cond", SI); |
| 232 | // Insert the new branch... |
| 233 | new BranchInst(SI->getSuccessor(1), SI->getSuccessor(0), Cond, SI); |
| 234 | |
| 235 | // Delete the old switch... |
| 236 | SI->getParent()->getInstList().erase(SI); |
| 237 | return true; |
| 238 | } |
Chris Lattner | 28537df | 2002-05-07 18:07:59 +0000 | [diff] [blame] | 239 | } |
| 240 | return false; |
| 241 | } |
| 242 | |
Chris Lattner | c13c7b9 | 2005-09-26 05:27:10 +0000 | [diff] [blame] | 243 | /// ConstantFoldLoadThroughGEPConstantExpr - Given a constant and a |
| 244 | /// getelementptr constantexpr, return the constant value being addressed by the |
| 245 | /// constant expression, or null if something is funny and we can't decide. |
| 246 | Constant *llvm::ConstantFoldLoadThroughGEPConstantExpr(Constant *C, |
| 247 | ConstantExpr *CE) { |
| 248 | if (CE->getOperand(1) != Constant::getNullValue(CE->getOperand(1)->getType())) |
| 249 | return 0; // Do not allow stepping over the value! |
| 250 | |
| 251 | // Loop over all of the operands, tracking down which value we are |
| 252 | // addressing... |
| 253 | gep_type_iterator I = gep_type_begin(CE), E = gep_type_end(CE); |
| 254 | for (++I; I != E; ++I) |
| 255 | if (const StructType *STy = dyn_cast<StructType>(*I)) { |
| 256 | ConstantUInt *CU = cast<ConstantUInt>(I.getOperand()); |
| 257 | assert(CU->getValue() < STy->getNumElements() && |
| 258 | "Struct index out of range!"); |
| 259 | unsigned El = (unsigned)CU->getValue(); |
| 260 | if (ConstantStruct *CS = dyn_cast<ConstantStruct>(C)) { |
| 261 | C = CS->getOperand(El); |
| 262 | } else if (isa<ConstantAggregateZero>(C)) { |
| 263 | C = Constant::getNullValue(STy->getElementType(El)); |
| 264 | } else if (isa<UndefValue>(C)) { |
| 265 | C = UndefValue::get(STy->getElementType(El)); |
| 266 | } else { |
| 267 | return 0; |
| 268 | } |
| 269 | } else if (ConstantInt *CI = dyn_cast<ConstantInt>(I.getOperand())) { |
| 270 | const ArrayType *ATy = cast<ArrayType>(*I); |
| 271 | if ((uint64_t)CI->getRawValue() >= ATy->getNumElements()) return 0; |
| 272 | if (ConstantArray *CA = dyn_cast<ConstantArray>(C)) |
| 273 | C = CA->getOperand((unsigned)CI->getRawValue()); |
| 274 | else if (isa<ConstantAggregateZero>(C)) |
| 275 | C = Constant::getNullValue(ATy->getElementType()); |
| 276 | else if (isa<UndefValue>(C)) |
| 277 | C = UndefValue::get(ATy->getElementType()); |
| 278 | else |
| 279 | return 0; |
| 280 | } else { |
| 281 | return 0; |
| 282 | } |
| 283 | return C; |
| 284 | } |
Chris Lattner | 28537df | 2002-05-07 18:07:59 +0000 | [diff] [blame] | 285 | |
| 286 | |
| 287 | //===----------------------------------------------------------------------===// |
| 288 | // Local dead code elimination... |
| 289 | // |
| 290 | |
Chris Lattner | 04efa4b | 2003-12-19 05:56:28 +0000 | [diff] [blame] | 291 | bool llvm::isInstructionTriviallyDead(Instruction *I) { |
Chris Lattner | a36d525 | 2005-05-06 05:27:34 +0000 | [diff] [blame] | 292 | if (!I->use_empty() || isa<TerminatorInst>(I)) return false; |
Jeff Cohen | 5f4ef3c | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 293 | |
Chris Lattner | a36d525 | 2005-05-06 05:27:34 +0000 | [diff] [blame] | 294 | if (!I->mayWriteToMemory()) return true; |
| 295 | |
| 296 | if (CallInst *CI = dyn_cast<CallInst>(I)) |
| 297 | if (Function *F = CI->getCalledFunction()) |
| 298 | switch (F->getIntrinsicID()) { |
| 299 | default: break; |
Chris Lattner | a36d525 | 2005-05-06 05:27:34 +0000 | [diff] [blame] | 300 | case Intrinsic::returnaddress: |
| 301 | case Intrinsic::frameaddress: |
Chris Lattner | 5fba6e6 | 2006-01-13 21:31:54 +0000 | [diff] [blame] | 302 | case Intrinsic::stacksave: |
Reid Spencer | b4f9a6f | 2006-01-16 21:12:35 +0000 | [diff] [blame] | 303 | case Intrinsic::isunordered_f32: |
| 304 | case Intrinsic::isunordered_f64: |
Nate Begeman | 82049eb | 2006-01-14 01:25:24 +0000 | [diff] [blame] | 305 | case Intrinsic::bswap_i16: |
| 306 | case Intrinsic::bswap_i32: |
| 307 | case Intrinsic::bswap_i64: |
Reid Spencer | b4f9a6f | 2006-01-16 21:12:35 +0000 | [diff] [blame] | 308 | case Intrinsic::ctpop_i8: |
| 309 | case Intrinsic::ctpop_i16: |
| 310 | case Intrinsic::ctpop_i32: |
| 311 | case Intrinsic::ctpop_i64: |
| 312 | case Intrinsic::ctlz_i8: |
| 313 | case Intrinsic::ctlz_i16: |
| 314 | case Intrinsic::ctlz_i32: |
| 315 | case Intrinsic::ctlz_i64: |
| 316 | case Intrinsic::cttz_i8: |
| 317 | case Intrinsic::cttz_i16: |
| 318 | case Intrinsic::cttz_i32: |
| 319 | case Intrinsic::cttz_i64: |
| 320 | case Intrinsic::sqrt_f32: |
| 321 | case Intrinsic::sqrt_f64: |
Chris Lattner | a36d525 | 2005-05-06 05:27:34 +0000 | [diff] [blame] | 322 | return true; // These intrinsics have no side effects. |
| 323 | } |
| 324 | return false; |
Chris Lattner | 28537df | 2002-05-07 18:07:59 +0000 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | // dceInstruction - Inspect the instruction at *BBI and figure out if it's |
| 328 | // [trivially] dead. If so, remove the instruction and update the iterator |
| 329 | // to point to the instruction that immediately succeeded the original |
| 330 | // instruction. |
| 331 | // |
Chris Lattner | 04efa4b | 2003-12-19 05:56:28 +0000 | [diff] [blame] | 332 | bool llvm::dceInstruction(BasicBlock::iterator &BBI) { |
Chris Lattner | 28537df | 2002-05-07 18:07:59 +0000 | [diff] [blame] | 333 | // Look for un"used" definitions... |
Chris Lattner | fda72b1 | 2002-06-25 16:12:52 +0000 | [diff] [blame] | 334 | if (isInstructionTriviallyDead(BBI)) { |
| 335 | BBI = BBI->getParent()->getInstList().erase(BBI); // Bye bye |
Chris Lattner | 28537df | 2002-05-07 18:07:59 +0000 | [diff] [blame] | 336 | return true; |
| 337 | } |
| 338 | return false; |
| 339 | } |