Dan Gohman | e378495 | 2007-08-27 16:11:48 +0000 | [diff] [blame] | 1 | //===- RaiseAllocations.cpp - Convert @malloc & @free calls to insts ------===// |
Misha Brukman | fd93908 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 2 | // |
John Criswell | b576c94 | 2003-10-20 19:43:21 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 4ee451d | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Misha Brukman | fd93908 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 7 | // |
John Criswell | b576c94 | 2003-10-20 19:43:21 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
Chris Lattner | ade686e | 2002-05-07 19:02:48 +0000 | [diff] [blame] | 9 | // |
Chris Lattner | 65e96e5 | 2002-05-07 19:04:39 +0000 | [diff] [blame] | 10 | // This file defines the RaiseAllocations pass which convert malloc and free |
| 11 | // calls to malloc and free instructions. |
Chris Lattner | ade686e | 2002-05-07 19:02:48 +0000 | [diff] [blame] | 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
Chris Lattner | 86453c5 | 2006-12-19 22:09:18 +0000 | [diff] [blame] | 15 | #define DEBUG_TYPE "raiseallocs" |
Chris Lattner | 2dbfa03 | 2003-09-01 03:14:56 +0000 | [diff] [blame] | 16 | #include "llvm/Transforms/IPO.h" |
Chris Lattner | eb12cd6 | 2003-12-07 01:42:08 +0000 | [diff] [blame] | 17 | #include "llvm/Constants.h" |
Chris Lattner | ade686e | 2002-05-07 19:02:48 +0000 | [diff] [blame] | 18 | #include "llvm/DerivedTypes.h" |
Chris Lattner | eb12cd6 | 2003-12-07 01:42:08 +0000 | [diff] [blame] | 19 | #include "llvm/Module.h" |
Misha Brukman | 47b14a4 | 2004-07-29 17:30:56 +0000 | [diff] [blame] | 20 | #include "llvm/Instructions.h" |
Chris Lattner | ade686e | 2002-05-07 19:02:48 +0000 | [diff] [blame] | 21 | #include "llvm/Pass.h" |
Chris Lattner | 2dbfa03 | 2003-09-01 03:14:56 +0000 | [diff] [blame] | 22 | #include "llvm/Support/CallSite.h" |
Reid Spencer | 9133fe2 | 2007-02-05 23:32:05 +0000 | [diff] [blame] | 23 | #include "llvm/Support/Compiler.h" |
Reid Spencer | 551ccae | 2004-09-01 22:55:40 +0000 | [diff] [blame] | 24 | #include "llvm/ADT/Statistic.h" |
Jeff Cohen | ca5183d | 2007-03-05 00:00:42 +0000 | [diff] [blame] | 25 | #include <algorithm> |
Chris Lattner | 1e2385b | 2003-11-21 21:54:22 +0000 | [diff] [blame] | 26 | using namespace llvm; |
Brian Gaeke | d0fde30 | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 27 | |
Chris Lattner | 86453c5 | 2006-12-19 22:09:18 +0000 | [diff] [blame] | 28 | STATISTIC(NumRaised, "Number of allocations raised"); |
Chris Lattner | ade686e | 2002-05-07 19:02:48 +0000 | [diff] [blame] | 29 | |
Chris Lattner | 86453c5 | 2006-12-19 22:09:18 +0000 | [diff] [blame] | 30 | namespace { |
Dan Gohman | e378495 | 2007-08-27 16:11:48 +0000 | [diff] [blame] | 31 | // RaiseAllocations - Turn @malloc and @free calls into the appropriate |
Chris Lattner | a92f696 | 2002-10-01 22:38:41 +0000 | [diff] [blame] | 32 | // instruction. |
Chris Lattner | ade686e | 2002-05-07 19:02:48 +0000 | [diff] [blame] | 33 | // |
Reid Spencer | 9133fe2 | 2007-02-05 23:32:05 +0000 | [diff] [blame] | 34 | class VISIBILITY_HIDDEN RaiseAllocations : public ModulePass { |
Chris Lattner | a92f696 | 2002-10-01 22:38:41 +0000 | [diff] [blame] | 35 | Function *MallocFunc; // Functions in the module we are processing |
| 36 | Function *FreeFunc; // Initialized by doPassInitializationVirt |
| 37 | public: |
Nick Lewycky | ecd94c8 | 2007-05-06 13:37:16 +0000 | [diff] [blame] | 38 | static char ID; // Pass identification, replacement for typeid |
Devang Patel | 794fd75 | 2007-05-01 21:15:47 +0000 | [diff] [blame] | 39 | RaiseAllocations() |
Dan Gohman | ae73dc1 | 2008-09-04 17:05:41 +0000 | [diff] [blame] | 40 | : ModulePass(&ID), MallocFunc(0), FreeFunc(0) {} |
Misha Brukman | fd93908 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 41 | |
Chris Lattner | a92f696 | 2002-10-01 22:38:41 +0000 | [diff] [blame] | 42 | // doPassInitialization - For the raise allocations pass, this finds a |
| 43 | // declaration for malloc and free if they exist. |
| 44 | // |
Chris Lattner | 2dbfa03 | 2003-09-01 03:14:56 +0000 | [diff] [blame] | 45 | void doInitialization(Module &M); |
Misha Brukman | fd93908 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 46 | |
Chris Lattner | 2dbfa03 | 2003-09-01 03:14:56 +0000 | [diff] [blame] | 47 | // run - This method does the actual work of converting instructions over. |
Chris Lattner | a92f696 | 2002-10-01 22:38:41 +0000 | [diff] [blame] | 48 | // |
Chris Lattner | b12914b | 2004-09-20 04:48:05 +0000 | [diff] [blame] | 49 | bool runOnModule(Module &M); |
Chris Lattner | a92f696 | 2002-10-01 22:38:41 +0000 | [diff] [blame] | 50 | }; |
Chris Lattner | ade686e | 2002-05-07 19:02:48 +0000 | [diff] [blame] | 51 | } // end anonymous namespace |
| 52 | |
Dan Gohman | 844731a | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 53 | char RaiseAllocations::ID = 0; |
| 54 | static RegisterPass<RaiseAllocations> |
| 55 | X("raiseallocs", "Raise allocations from calls to instructions"); |
Chris Lattner | ade686e | 2002-05-07 19:02:48 +0000 | [diff] [blame] | 56 | |
| 57 | // createRaiseAllocationsPass - The interface to this file... |
Chris Lattner | b12914b | 2004-09-20 04:48:05 +0000 | [diff] [blame] | 58 | ModulePass *llvm::createRaiseAllocationsPass() { |
Chris Lattner | ade686e | 2002-05-07 19:02:48 +0000 | [diff] [blame] | 59 | return new RaiseAllocations(); |
| 60 | } |
| 61 | |
| 62 | |
Chris Lattner | 2dbfa03 | 2003-09-01 03:14:56 +0000 | [diff] [blame] | 63 | // If the module has a symbol table, they might be referring to the malloc and |
| 64 | // free functions. If this is the case, grab the method pointers that the |
| 65 | // module is using. |
| 66 | // |
Dan Gohman | e378495 | 2007-08-27 16:11:48 +0000 | [diff] [blame] | 67 | // Lookup @malloc and @free in the symbol table, for later use. If they don't |
Chris Lattner | 2dbfa03 | 2003-09-01 03:14:56 +0000 | [diff] [blame] | 68 | // exist, or are not external, we do not worry about converting calls to that |
| 69 | // function into the appropriate instruction. |
| 70 | // |
| 71 | void RaiseAllocations::doInitialization(Module &M) { |
Chris Lattner | ade686e | 2002-05-07 19:02:48 +0000 | [diff] [blame] | 72 | |
Chris Lattner | 0b5909e | 2002-07-18 00:18:01 +0000 | [diff] [blame] | 73 | // Get Malloc and free prototypes if they exist! |
Reid Spencer | ef9b9a7 | 2007-02-05 20:47:22 +0000 | [diff] [blame] | 74 | MallocFunc = M.getFunction("malloc"); |
| 75 | if (MallocFunc) { |
| 76 | const FunctionType* TyWeHave = MallocFunc->getFunctionType(); |
Chris Lattner | ade686e | 2002-05-07 19:02:48 +0000 | [diff] [blame] | 77 | |
Reid Spencer | ef9b9a7 | 2007-02-05 20:47:22 +0000 | [diff] [blame] | 78 | // Get the expected prototype for malloc |
| 79 | const FunctionType *Malloc1Type = |
Christopher Lamb | 43ad6b3 | 2007-12-17 01:12:55 +0000 | [diff] [blame] | 80 | FunctionType::get(PointerType::getUnqual(Type::Int8Ty), |
Reid Spencer | ef9b9a7 | 2007-02-05 20:47:22 +0000 | [diff] [blame] | 81 | std::vector<const Type*>(1, Type::Int64Ty), false); |
| 82 | |
| 83 | // Chck to see if we got the expected malloc |
| 84 | if (TyWeHave != Malloc1Type) { |
Dan Gohman | a119de8 | 2009-06-14 23:30:43 +0000 | [diff] [blame^] | 85 | // Check to see if the prototype is wrong, giving us i8*(i32) * malloc |
Reid Spencer | ef9b9a7 | 2007-02-05 20:47:22 +0000 | [diff] [blame] | 86 | // This handles the common declaration of: 'void *malloc(unsigned);' |
| 87 | const FunctionType *Malloc2Type = |
Christopher Lamb | 43ad6b3 | 2007-12-17 01:12:55 +0000 | [diff] [blame] | 88 | FunctionType::get(PointerType::getUnqual(Type::Int8Ty), |
Reid Spencer | ef9b9a7 | 2007-02-05 20:47:22 +0000 | [diff] [blame] | 89 | std::vector<const Type*>(1, Type::Int32Ty), false); |
| 90 | if (TyWeHave != Malloc2Type) { |
| 91 | // Check to see if the prototype is missing, giving us |
Dan Gohman | a119de8 | 2009-06-14 23:30:43 +0000 | [diff] [blame^] | 92 | // i8*(...) * malloc |
Reid Spencer | ef9b9a7 | 2007-02-05 20:47:22 +0000 | [diff] [blame] | 93 | // This handles the common declaration of: 'void *malloc();' |
| 94 | const FunctionType *Malloc3Type = |
Christopher Lamb | 43ad6b3 | 2007-12-17 01:12:55 +0000 | [diff] [blame] | 95 | FunctionType::get(PointerType::getUnqual(Type::Int8Ty), |
Reid Spencer | ef9b9a7 | 2007-02-05 20:47:22 +0000 | [diff] [blame] | 96 | std::vector<const Type*>(), true); |
| 97 | if (TyWeHave != Malloc3Type) |
| 98 | // Give up |
| 99 | MallocFunc = 0; |
| 100 | } |
| 101 | } |
Chris Lattner | 0b5909e | 2002-07-18 00:18:01 +0000 | [diff] [blame] | 102 | } |
| 103 | |
Reid Spencer | ef9b9a7 | 2007-02-05 20:47:22 +0000 | [diff] [blame] | 104 | FreeFunc = M.getFunction("free"); |
| 105 | if (FreeFunc) { |
| 106 | const FunctionType* TyWeHave = FreeFunc->getFunctionType(); |
| 107 | |
| 108 | // Get the expected prototype for void free(i8*) |
| 109 | const FunctionType *Free1Type = FunctionType::get(Type::VoidTy, |
Christopher Lamb | 43ad6b3 | 2007-12-17 01:12:55 +0000 | [diff] [blame] | 110 | std::vector<const Type*>(1, PointerType::getUnqual(Type::Int8Ty)), false); |
Chris Lattner | 47e0f3a | 2002-05-24 20:29:18 +0000 | [diff] [blame] | 111 | |
Reid Spencer | ef9b9a7 | 2007-02-05 20:47:22 +0000 | [diff] [blame] | 112 | if (TyWeHave != Free1Type) { |
| 113 | // Check to see if the prototype was forgotten, giving us |
| 114 | // void (...) * free |
| 115 | // This handles the common forward declaration of: 'void free();' |
| 116 | const FunctionType* Free2Type = FunctionType::get(Type::VoidTy, |
| 117 | std::vector<const Type*>(),true); |
Chris Lattner | 47e0f3a | 2002-05-24 20:29:18 +0000 | [diff] [blame] | 118 | |
Reid Spencer | ef9b9a7 | 2007-02-05 20:47:22 +0000 | [diff] [blame] | 119 | if (TyWeHave != Free2Type) { |
| 120 | // One last try, check to see if we can find free as |
| 121 | // int (...)* free. This handles the case where NOTHING was declared. |
| 122 | const FunctionType* Free3Type = FunctionType::get(Type::Int32Ty, |
| 123 | std::vector<const Type*>(),true); |
| 124 | |
| 125 | if (TyWeHave != Free3Type) { |
| 126 | // Give up. |
| 127 | FreeFunc = 0; |
| 128 | } |
| 129 | } |
| 130 | } |
Chris Lattner | 1f28e8c | 2003-08-11 15:05:08 +0000 | [diff] [blame] | 131 | } |
| 132 | |
Chris Lattner | ade686e | 2002-05-07 19:02:48 +0000 | [diff] [blame] | 133 | // Don't mess with locally defined versions of these functions... |
Reid Spencer | 5cbf985 | 2007-01-30 20:08:39 +0000 | [diff] [blame] | 134 | if (MallocFunc && !MallocFunc->isDeclaration()) MallocFunc = 0; |
| 135 | if (FreeFunc && !FreeFunc->isDeclaration()) FreeFunc = 0; |
Chris Lattner | ade686e | 2002-05-07 19:02:48 +0000 | [diff] [blame] | 136 | } |
| 137 | |
Chris Lattner | 2dbfa03 | 2003-09-01 03:14:56 +0000 | [diff] [blame] | 138 | // run - Transform calls into instructions... |
Chris Lattner | ade686e | 2002-05-07 19:02:48 +0000 | [diff] [blame] | 139 | // |
Chris Lattner | b12914b | 2004-09-20 04:48:05 +0000 | [diff] [blame] | 140 | bool RaiseAllocations::runOnModule(Module &M) { |
Chris Lattner | 2dbfa03 | 2003-09-01 03:14:56 +0000 | [diff] [blame] | 141 | // Find the malloc/free prototypes... |
| 142 | doInitialization(M); |
| 143 | |
Chris Lattner | ade686e | 2002-05-07 19:02:48 +0000 | [diff] [blame] | 144 | bool Changed = false; |
Chris Lattner | ade686e | 2002-05-07 19:02:48 +0000 | [diff] [blame] | 145 | |
Chris Lattner | 2dbfa03 | 2003-09-01 03:14:56 +0000 | [diff] [blame] | 146 | // First, process all of the malloc calls... |
| 147 | if (MallocFunc) { |
| 148 | std::vector<User*> Users(MallocFunc->use_begin(), MallocFunc->use_end()); |
Chris Lattner | eb12cd6 | 2003-12-07 01:42:08 +0000 | [diff] [blame] | 149 | std::vector<Value*> EqPointers; // Values equal to MallocFunc |
Chris Lattner | 2dbfa03 | 2003-09-01 03:14:56 +0000 | [diff] [blame] | 150 | while (!Users.empty()) { |
Chris Lattner | eb12cd6 | 2003-12-07 01:42:08 +0000 | [diff] [blame] | 151 | User *U = Users.back(); |
| 152 | Users.pop_back(); |
| 153 | |
| 154 | if (Instruction *I = dyn_cast<Instruction>(U)) { |
Chris Lattner | 2dbfa03 | 2003-09-01 03:14:56 +0000 | [diff] [blame] | 155 | CallSite CS = CallSite::get(I); |
Dan Gohman | cb406c2 | 2007-10-03 19:26:29 +0000 | [diff] [blame] | 156 | if (CS.getInstruction() && !CS.arg_empty() && |
Chris Lattner | eb12cd6 | 2003-12-07 01:42:08 +0000 | [diff] [blame] | 157 | (CS.getCalledFunction() == MallocFunc || |
| 158 | std::find(EqPointers.begin(), EqPointers.end(), |
| 159 | CS.getCalledValue()) != EqPointers.end())) { |
Misha Brukman | fd93908 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 160 | |
Chris Lattner | 2dbfa03 | 2003-09-01 03:14:56 +0000 | [diff] [blame] | 161 | Value *Source = *CS.arg_begin(); |
Misha Brukman | fd93908 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 162 | |
Chris Lattner | 2dbfa03 | 2003-09-01 03:14:56 +0000 | [diff] [blame] | 163 | // If no prototype was provided for malloc, we may need to cast the |
| 164 | // source size. |
Reid Spencer | c5b206b | 2006-12-31 05:48:39 +0000 | [diff] [blame] | 165 | if (Source->getType() != Type::Int32Ty) |
Reid Spencer | 3da59db | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 166 | Source = |
Gabor Greif | 7cbd8a3 | 2008-05-16 19:29:10 +0000 | [diff] [blame] | 167 | CastInst::CreateIntegerCast(Source, Type::Int32Ty, false/*ZExt*/, |
Reid Spencer | 7b06bd5 | 2006-12-13 00:50:17 +0000 | [diff] [blame] | 168 | "MallocAmtCast", I); |
Misha Brukman | fd93908 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 169 | |
Chris Lattner | 046800a | 2007-02-11 01:08:35 +0000 | [diff] [blame] | 170 | MallocInst *MI = new MallocInst(Type::Int8Ty, Source, "", I); |
| 171 | MI->takeName(I); |
Chris Lattner | 2dbfa03 | 2003-09-01 03:14:56 +0000 | [diff] [blame] | 172 | I->replaceAllUsesWith(MI); |
Chris Lattner | cc83834 | 2003-09-16 19:42:21 +0000 | [diff] [blame] | 173 | |
| 174 | // If the old instruction was an invoke, add an unconditional branch |
| 175 | // before the invoke, which will become the new terminator. |
| 176 | if (InvokeInst *II = dyn_cast<InvokeInst>(I)) |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 177 | BranchInst::Create(II->getNormalDest(), I); |
Chris Lattner | cc83834 | 2003-09-16 19:42:21 +0000 | [diff] [blame] | 178 | |
| 179 | // Delete the old call site |
Dan Gohman | 1adec83 | 2008-06-21 22:08:46 +0000 | [diff] [blame] | 180 | I->eraseFromParent(); |
Chris Lattner | 2dbfa03 | 2003-09-01 03:14:56 +0000 | [diff] [blame] | 181 | Changed = true; |
| 182 | ++NumRaised; |
| 183 | } |
Reid Spencer | 518310c | 2004-07-18 00:44:37 +0000 | [diff] [blame] | 184 | } else if (GlobalValue *GV = dyn_cast<GlobalValue>(U)) { |
| 185 | Users.insert(Users.end(), GV->use_begin(), GV->use_end()); |
| 186 | EqPointers.push_back(GV); |
Chris Lattner | eb12cd6 | 2003-12-07 01:42:08 +0000 | [diff] [blame] | 187 | } else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(U)) { |
Reid Spencer | 3da59db | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 188 | if (CE->isCast()) { |
Chris Lattner | eb12cd6 | 2003-12-07 01:42:08 +0000 | [diff] [blame] | 189 | Users.insert(Users.end(), CE->use_begin(), CE->use_end()); |
| 190 | EqPointers.push_back(CE); |
| 191 | } |
Chris Lattner | ade686e | 2002-05-07 19:02:48 +0000 | [diff] [blame] | 192 | } |
Chris Lattner | 2dbfa03 | 2003-09-01 03:14:56 +0000 | [diff] [blame] | 193 | } |
| 194 | } |
| 195 | |
| 196 | // Next, process all free calls... |
| 197 | if (FreeFunc) { |
| 198 | std::vector<User*> Users(FreeFunc->use_begin(), FreeFunc->use_end()); |
Chris Lattner | eb12cd6 | 2003-12-07 01:42:08 +0000 | [diff] [blame] | 199 | std::vector<Value*> EqPointers; // Values equal to FreeFunc |
Chris Lattner | 2dbfa03 | 2003-09-01 03:14:56 +0000 | [diff] [blame] | 200 | |
| 201 | while (!Users.empty()) { |
Chris Lattner | eb12cd6 | 2003-12-07 01:42:08 +0000 | [diff] [blame] | 202 | User *U = Users.back(); |
| 203 | Users.pop_back(); |
| 204 | |
| 205 | if (Instruction *I = dyn_cast<Instruction>(U)) { |
Devang Patel | 8445832 | 2007-10-17 20:12:58 +0000 | [diff] [blame] | 206 | if (isa<InvokeInst>(I)) |
| 207 | continue; |
Chris Lattner | 2dbfa03 | 2003-09-01 03:14:56 +0000 | [diff] [blame] | 208 | CallSite CS = CallSite::get(I); |
Dan Gohman | cb406c2 | 2007-10-03 19:26:29 +0000 | [diff] [blame] | 209 | if (CS.getInstruction() && !CS.arg_empty() && |
Chris Lattner | eb12cd6 | 2003-12-07 01:42:08 +0000 | [diff] [blame] | 210 | (CS.getCalledFunction() == FreeFunc || |
| 211 | std::find(EqPointers.begin(), EqPointers.end(), |
| 212 | CS.getCalledValue()) != EqPointers.end())) { |
Misha Brukman | fd93908 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 213 | |
Chris Lattner | 2dbfa03 | 2003-09-01 03:14:56 +0000 | [diff] [blame] | 214 | // If no prototype was provided for free, we may need to cast the |
| 215 | // source pointer. This should be really uncommon, but it's necessary |
Chris Lattner | da895d6 | 2005-02-27 06:18:25 +0000 | [diff] [blame] | 216 | // just in case we are dealing with weird code like this: |
Chris Lattner | 2dbfa03 | 2003-09-01 03:14:56 +0000 | [diff] [blame] | 217 | // free((long)ptr); |
| 218 | // |
| 219 | Value *Source = *CS.arg_begin(); |
| 220 | if (!isa<PointerType>(Source->getType())) |
Christopher Lamb | 43ad6b3 | 2007-12-17 01:12:55 +0000 | [diff] [blame] | 221 | Source = new IntToPtrInst(Source, |
| 222 | PointerType::getUnqual(Type::Int8Ty), |
Reid Spencer | 7b06bd5 | 2006-12-13 00:50:17 +0000 | [diff] [blame] | 223 | "FreePtrCast", I); |
Chris Lattner | 2dbfa03 | 2003-09-01 03:14:56 +0000 | [diff] [blame] | 224 | new FreeInst(Source, I); |
Chris Lattner | cc83834 | 2003-09-16 19:42:21 +0000 | [diff] [blame] | 225 | |
| 226 | // If the old instruction was an invoke, add an unconditional branch |
| 227 | // before the invoke, which will become the new terminator. |
| 228 | if (InvokeInst *II = dyn_cast<InvokeInst>(I)) |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 229 | BranchInst::Create(II->getNormalDest(), I); |
Chris Lattner | cc83834 | 2003-09-16 19:42:21 +0000 | [diff] [blame] | 230 | |
| 231 | // Delete the old call site |
Chris Lattner | 52f20f8 | 2004-11-09 05:10:56 +0000 | [diff] [blame] | 232 | if (I->getType() != Type::VoidTy) |
| 233 | I->replaceAllUsesWith(UndefValue::get(I->getType())); |
| 234 | I->eraseFromParent(); |
Chris Lattner | 2dbfa03 | 2003-09-01 03:14:56 +0000 | [diff] [blame] | 235 | Changed = true; |
| 236 | ++NumRaised; |
| 237 | } |
Reid Spencer | 518310c | 2004-07-18 00:44:37 +0000 | [diff] [blame] | 238 | } else if (GlobalValue *GV = dyn_cast<GlobalValue>(U)) { |
| 239 | Users.insert(Users.end(), GV->use_begin(), GV->use_end()); |
| 240 | EqPointers.push_back(GV); |
Chris Lattner | eb12cd6 | 2003-12-07 01:42:08 +0000 | [diff] [blame] | 241 | } else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(U)) { |
Reid Spencer | 3da59db | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 242 | if (CE->isCast()) { |
Chris Lattner | eb12cd6 | 2003-12-07 01:42:08 +0000 | [diff] [blame] | 243 | Users.insert(Users.end(), CE->use_begin(), CE->use_end()); |
| 244 | EqPointers.push_back(CE); |
| 245 | } |
Chris Lattner | 2dbfa03 | 2003-09-01 03:14:56 +0000 | [diff] [blame] | 246 | } |
Chris Lattner | ade686e | 2002-05-07 19:02:48 +0000 | [diff] [blame] | 247 | } |
Chris Lattner | ade686e | 2002-05-07 19:02:48 +0000 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | return Changed; |
| 251 | } |