Mercurial > projects > ldc
comparison gen/passes/GarbageCollect2Stack.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 | 6364e09628fd |
children | a326f145a57b |
comparison
equal
deleted
inserted
replaced
1544:8863cf7236e6 | 1545:7fcb72d518f6 |
---|---|
55 | 55 |
56 //===----------------------------------------------------------------------===// | 56 //===----------------------------------------------------------------------===// |
57 // Helper functions | 57 // Helper functions |
58 //===----------------------------------------------------------------------===// | 58 //===----------------------------------------------------------------------===// |
59 | 59 |
60 void EmitMemSet(IRBuilder<>& B, Value* Dst, Value* Val, Value* Len, | 60 void EmitMemSet(LLVMContext& Context, IRBuilder<>& B, Value* Dst, Value* Val, |
61 const Analysis& A) { | 61 Value* Len, const Analysis& A) { |
62 Dst = B.CreateBitCast(Dst, PointerType::getUnqual(Type::Int8Ty)); | 62 Dst = B.CreateBitCast(Dst, PointerType::getUnqual(Type::Int8Ty)); |
63 | 63 |
64 Module *M = B.GetInsertBlock()->getParent()->getParent(); | 64 Module *M = B.GetInsertBlock()->getParent()->getParent(); |
65 const Type* Tys[1]; | 65 const Type* Tys[1]; |
66 Tys[0] = Len->getType(); | 66 Tys[0] = Len->getType(); |
67 Function *MemSet = Intrinsic::getDeclaration(M, Intrinsic::memset, Tys, 1); | 67 Function *MemSet = Intrinsic::getDeclaration(M, Intrinsic::memset, Tys, 1); |
68 Value *Align = ConstantInt::get(Type::Int32Ty, 1); | 68 Value *Align = Context.getConstantInt(Type::Int32Ty, 1); |
69 | 69 |
70 CallSite CS = B.CreateCall4(MemSet, Dst, Val, Len, Align); | 70 CallSite CS = B.CreateCall4(MemSet, Dst, Val, Len, Align); |
71 if (A.CGNode) | 71 if (A.CGNode) |
72 A.CGNode->addCalledFunction(CS, A.CG->getOrInsertFunction(MemSet)); | 72 A.CGNode->addCalledFunction(CS, A.CG->getOrInsertFunction(MemSet)); |
73 } | 73 } |
74 | 74 |
75 static void EmitMemZero(IRBuilder<>& B, Value* Dst, Value* Len, | 75 static void EmitMemZero(LLVMContext& Context, IRBuilder<>& B, Value* Dst, |
76 const Analysis& A) { | 76 Value* Len, const Analysis& A) { |
77 EmitMemSet(B, Dst, ConstantInt::get(Type::Int8Ty, 0), Len, A); | 77 EmitMemSet(Context, B, Dst, Context.getConstantInt(Type::Int8Ty, 0), Len, A); |
78 } | 78 } |
79 | 79 |
80 | 80 |
81 //===----------------------------------------------------------------------===// | 81 //===----------------------------------------------------------------------===// |
82 // Helpers for specific types of GC calls. | 82 // Helpers for specific types of GC calls. |
176 AllocaInst* alloca = Builder.CreateAlloca(Ty, count, ".nongc_mem"); // FIXME: align? | 176 AllocaInst* alloca = Builder.CreateAlloca(Ty, count, ".nongc_mem"); // FIXME: align? |
177 | 177 |
178 if (Initialized) { | 178 if (Initialized) { |
179 // For now, only zero-init is supported. | 179 // For now, only zero-init is supported. |
180 uint64_t size = A.TD.getTypeStoreSize(Ty); | 180 uint64_t size = A.TD.getTypeStoreSize(Ty); |
181 Value* TypeSize = ConstantInt::get(arrSize->getType(), size); | 181 Value* TypeSize = Context->getConstantInt(arrSize->getType(), size); |
182 // Use the original B to put initialization at the | 182 // Use the original B to put initialization at the |
183 // allocation site. | 183 // allocation site. |
184 Value* Size = B.CreateMul(TypeSize, arrSize); | 184 Value* Size = B.CreateMul(TypeSize, arrSize); |
185 EmitMemZero(B, alloca, Size, A); | 185 EmitMemZero(*Context, B, alloca, Size, A); |
186 } | 186 } |
187 | 187 |
188 return alloca; | 188 return alloca; |
189 } | 189 } |
190 }; | 190 }; |