Mercurial > projects > ldc
comparison gen/passes/SimplifyDRuntimeCalls.cpp @ 1545:7fcb72d518f6
More factory methods moved to LLVMContext
author | Benjamin Kramer <benny.kra@gmail.com> |
---|---|
date | Wed, 15 Jul 2009 18:09:41 +0200 |
parents | 61f12f4651b5 |
children | ed0feda76820 |
comparison
equal
deleted
inserted
replaced
1544:8863cf7236e6 | 1545:7fcb72d518f6 |
---|---|
44 protected: | 44 protected: |
45 Function *Caller; | 45 Function *Caller; |
46 bool* Changed; | 46 bool* Changed; |
47 const TargetData *TD; | 47 const TargetData *TD; |
48 AliasAnalysis *AA; | 48 AliasAnalysis *AA; |
49 LLVMContext *Context; | |
49 | 50 |
50 /// CastToCStr - Return V if it is an i8*, otherwise cast it to i8*. | 51 /// CastToCStr - Return V if it is an i8*, otherwise cast it to i8*. |
51 Value *CastToCStr(Value *V, IRBuilder<> &B); | 52 Value *CastToCStr(Value *V, IRBuilder<> &B); |
52 | 53 |
53 /// EmitMemCpy - Emit a call to the memcpy function to the builder. This | 54 /// EmitMemCpy - Emit a call to the memcpy function to the builder. This |
69 AliasAnalysis& AA, IRBuilder<> &B) { | 70 AliasAnalysis& AA, IRBuilder<> &B) { |
70 Caller = CI->getParent()->getParent(); | 71 Caller = CI->getParent()->getParent(); |
71 this->Changed = &Changed; | 72 this->Changed = &Changed; |
72 this->TD = &TD; | 73 this->TD = &TD; |
73 this->AA = &AA; | 74 this->AA = &AA; |
75 if (CI->getCalledFunction()) | |
76 Context = CI->getCalledFunction()->getContext(); | |
74 return CallOptimizer(CI->getCalledFunction(), CI, B); | 77 return CallOptimizer(CI->getCalledFunction(), CI, B); |
75 } | 78 } |
76 }; | 79 }; |
77 } // End anonymous namespace. | 80 } // End anonymous namespace. |
78 | 81 |
89 Intrinsic::ID IID = Intrinsic::memcpy; | 92 Intrinsic::ID IID = Intrinsic::memcpy; |
90 const Type *Tys[1]; | 93 const Type *Tys[1]; |
91 Tys[0] = Len->getType(); | 94 Tys[0] = Len->getType(); |
92 Value *MemCpy = Intrinsic::getDeclaration(M, IID, Tys, 1); | 95 Value *MemCpy = Intrinsic::getDeclaration(M, IID, Tys, 1); |
93 return B.CreateCall4(MemCpy, CastToCStr(Dst, B), CastToCStr(Src, B), Len, | 96 return B.CreateCall4(MemCpy, CastToCStr(Dst, B), CastToCStr(Src, B), Len, |
94 ConstantInt::get(Type::Int32Ty, Align)); | 97 Context->getConstantInt(Type::Int32Ty, Align)); |
95 } | 98 } |
96 | 99 |
97 //===----------------------------------------------------------------------===// | 100 //===----------------------------------------------------------------------===// |
98 // Miscellaneous LibCall Optimizations | 101 // Miscellaneous LibCall Optimizations |
99 //===----------------------------------------------------------------------===// | 102 //===----------------------------------------------------------------------===// |
175 return 0; | 178 return 0; |
176 | 179 |
177 APInt Quot, Rem; | 180 APInt Quot, Rem; |
178 APInt::udivrem(OldInt->getValue(), NewInt->getValue(), Quot, Rem); | 181 APInt::udivrem(OldInt->getValue(), NewInt->getValue(), Quot, Rem); |
179 if (Rem == 0) | 182 if (Rem == 0) |
180 return B.CreateMul(OldLen, ConstantInt::get(Quot)); | 183 return B.CreateMul(OldLen, Context->getConstantInt(Quot)); |
181 } | 184 } |
182 return 0; | 185 return 0; |
183 } | 186 } |
184 }; | 187 }; |
185 | 188 |
196 if (!Cmp->isEquality()) | 199 if (!Cmp->isEquality()) |
197 continue; | 200 continue; |
198 Constant* C = 0; | 201 Constant* C = 0; |
199 if ((C = dyn_cast<Constant>(Cmp->getOperand(0))) | 202 if ((C = dyn_cast<Constant>(Cmp->getOperand(0))) |
200 || (C = dyn_cast<Constant>(Cmp->getOperand(1)))) { | 203 || (C = dyn_cast<Constant>(Cmp->getOperand(1)))) { |
201 Value* Result = ConstantInt::get(Type::Int1Ty, !Cmp->isTrueWhenEqual()); | 204 Value* Result = Context->getConstantInt(Type::Int1Ty, !Cmp->isTrueWhenEqual()); |
202 Cmp->replaceAllUsesWith(Result); | 205 Cmp->replaceAllUsesWith(Result); |
203 // Don't delete the comparison because there may be an | 206 // Don't delete the comparison because there may be an |
204 // iterator to it. Instead, set the operands to constants | 207 // iterator to it. Instead, set the operands to constants |
205 // and let dead code elimination clean it up later. | 208 // and let dead code elimination clean it up later. |
206 // (It doesn't matter that this changes the value of the | 209 // (It doesn't matter that this changes the value of the |