comparison gen/passes/SimplifyDRuntimeCalls.cpp @ 1554:d6e8d5db259f

LLVMContext changes up to r77366
author Benjamin Kramer <benny.kra@gmail.com>
date Thu, 30 Jul 2009 15:25:10 +0200
parents f55ca8a1598c
children 8d086d552909
comparison
equal deleted inserted replaced
1553:f55ca8a1598c 1554:d6e8d5db259f
72 Caller = CI->getParent()->getParent(); 72 Caller = CI->getParent()->getParent();
73 this->Changed = &Changed; 73 this->Changed = &Changed;
74 this->TD = &TD; 74 this->TD = &TD;
75 this->AA = &AA; 75 this->AA = &AA;
76 if (CI->getCalledFunction()) 76 if (CI->getCalledFunction())
77 Context = CI->getCalledFunction()->getContext(); 77 Context = &CI->getCalledFunction()->getContext();
78 return CallOptimizer(CI->getCalledFunction(), CI, B); 78 return CallOptimizer(CI->getCalledFunction(), CI, B);
79 } 79 }
80 }; 80 };
81 } // End anonymous namespace. 81 } // End anonymous namespace.
82 82
93 Intrinsic::ID IID = Intrinsic::memcpy; 93 Intrinsic::ID IID = Intrinsic::memcpy;
94 const Type *Tys[1]; 94 const Type *Tys[1];
95 Tys[0] = Len->getType(); 95 Tys[0] = Len->getType();
96 Value *MemCpy = Intrinsic::getDeclaration(M, IID, Tys, 1); 96 Value *MemCpy = Intrinsic::getDeclaration(M, IID, Tys, 1);
97 return B.CreateCall4(MemCpy, CastToCStr(Dst, B), CastToCStr(Src, B), Len, 97 return B.CreateCall4(MemCpy, CastToCStr(Dst, B), CastToCStr(Src, B), Len,
98 Context->getConstantInt(Type::Int32Ty, Align)); 98 ConstantInt::get(Type::Int32Ty, Align));
99 } 99 }
100 100
101 //===----------------------------------------------------------------------===// 101 //===----------------------------------------------------------------------===//
102 // Miscellaneous LibCall Optimizations 102 // Miscellaneous LibCall Optimizations
103 //===----------------------------------------------------------------------===// 103 //===----------------------------------------------------------------------===//
179 return 0; 179 return 0;
180 180
181 APInt Quot, Rem; 181 APInt Quot, Rem;
182 APInt::udivrem(OldInt->getValue(), NewInt->getValue(), Quot, Rem); 182 APInt::udivrem(OldInt->getValue(), NewInt->getValue(), Quot, Rem);
183 if (Rem == 0) 183 if (Rem == 0)
184 return B.CreateMul(OldLen, Context->getConstantInt(Quot)); 184 return B.CreateMul(OldLen, ConstantInt::get(*Context, Quot));
185 } 185 }
186 return 0; 186 return 0;
187 } 187 }
188 }; 188 };
189 189
200 if (!Cmp->isEquality()) 200 if (!Cmp->isEquality())
201 continue; 201 continue;
202 Constant* C = 0; 202 Constant* C = 0;
203 if ((C = dyn_cast<Constant>(Cmp->getOperand(0))) 203 if ((C = dyn_cast<Constant>(Cmp->getOperand(0)))
204 || (C = dyn_cast<Constant>(Cmp->getOperand(1)))) { 204 || (C = dyn_cast<Constant>(Cmp->getOperand(1)))) {
205 Value* Result = Context->getConstantInt(Type::Int1Ty, !Cmp->isTrueWhenEqual()); 205 Value* Result = ConstantInt::get(Type::Int1Ty, !Cmp->isTrueWhenEqual());
206 Cmp->replaceAllUsesWith(Result); 206 Cmp->replaceAllUsesWith(Result);
207 // Don't delete the comparison because there may be an 207 // Don't delete the comparison because there may be an
208 // iterator to it. Instead, set the operands to constants 208 // iterator to it. Instead, set the operands to constants
209 // and let dead code elimination clean it up later. 209 // and let dead code elimination clean it up later.
210 // (It doesn't matter that this changes the value of the 210 // (It doesn't matter that this changes the value of the
357 357
358 return EverChanged; 358 return EverChanged;
359 } 359 }
360 360
361 bool SimplifyDRuntimeCalls::runOnce(Function &F, const TargetData& TD, AliasAnalysis& AA) { 361 bool SimplifyDRuntimeCalls::runOnce(Function &F, const TargetData& TD, AliasAnalysis& AA) {
362 IRBuilder<> Builder(*Context); 362 IRBuilder<> Builder(F.getContext());
363 363
364 bool Changed = false; 364 bool Changed = false;
365 for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB) { 365 for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB) {
366 for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ) { 366 for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ) {
367 // Ignore non-calls. 367 // Ignore non-calls.
368 CallInst *CI = dyn_cast<CallInst>(I++); 368 CallInst *CI = dyn_cast<CallInst>(I++);