@@ -48,7 +48,8 @@ void (*CustomErrorHandler)(const char *, LLVMValueRef, ErrorType,
48
48
void *) = nullptr ;
49
49
LLVMValueRef (*CustomAllocator)(LLVMBuilderRef, LLVMTypeRef,
50
50
/* Count*/ LLVMValueRef,
51
- /* Align*/ LLVMValueRef, uint8_t ) = nullptr;
51
+ /* Align*/ LLVMValueRef, uint8_t ,
52
+ LLVMValueRef *) = nullptr;
52
53
LLVMValueRef (*CustomDeallocator)(LLVMBuilderRef, LLVMValueRef) = nullptr;
53
54
void (*CustomRuntimeInactiveError)(LLVMBuilderRef, LLVMValueRef,
54
55
LLVMValueRef) = nullptr ;
@@ -91,10 +92,6 @@ Function *getOrInsertExponentialAllocator(Module &M, Function *newFunc,
91
92
CreateAllocation (B, RT, P, " tapemem" , &malloccall, nullptr )->getType ();
92
93
if (auto F = getFunctionFromCall (malloccall)) {
93
94
custom = F->getName () != " malloc" ;
94
- if (F->getName () == " julia.gc_alloc_obj" ||
95
- F->getName () == " jl_gc_alloc_typed" ||
96
- F->getName () == " ijl_gc_alloc_typed" )
97
- ZeroInit = false ;
98
95
}
99
96
allocType = cast<PointerType>(malloccall->getType ());
100
97
BB->eraseFromParent ();
@@ -173,7 +170,8 @@ Function *getOrInsertExponentialAllocator(Module &M, Function *newFunc,
173
170
next->getType (),
174
171
newFunc->getParent ()->getDataLayout ().getTypeAllocSizeInBits (RT) / 8 );
175
172
auto elSize = B.CreateUDiv (next, tsize, " " , /* isExact*/ true );
176
- gVal = CreateAllocation (B, RT, elSize, " " , nullptr , nullptr );
173
+ Instruction *SubZero = nullptr ;
174
+ gVal = CreateAllocation (B, RT, elSize, " " , nullptr , &SubZero);
177
175
178
176
gVal = B.CreatePointerCast (
179
177
gVal , PointerType::get (
@@ -187,6 +185,21 @@ Function *getOrInsertExponentialAllocator(Module &M, Function *newFunc,
187
185
margs[2 ]->getType ()};
188
186
auto memsetF = Intrinsic::getDeclaration (&M, Intrinsic::memcpy, tys);
189
187
B.CreateCall (memsetF, margs);
188
+ if (SubZero) {
189
+ ZeroInit = false ;
190
+ IRBuilder<> BB (SubZero);
191
+ Value *zeroSize = BB.CreateSub (next, prevSize);
192
+ Value *tmp = SubZero->getOperand (0 );
193
+
194
+ #if LLVM_VERSION_MAJOR > 7
195
+ tmp = BB.CreateInBoundsGEP (tmp->getType ()->getPointerElementType (), tmp,
196
+ prevSize);
197
+ #else
198
+ tmp = BB.CreateInBoundsGEP (tmp, prevSize);
199
+ #endif
200
+ SubZero->setOperand (0 , tmp);
201
+ SubZero->setOperand (2 , zeroSize);
202
+ }
190
203
}
191
204
192
205
if (ZeroInit) {
@@ -255,15 +268,21 @@ Value *CreateAllocation(IRBuilder<> &Builder, llvm::Type *T, Value *Count,
255
268
auto Align = ConstantInt::get (Count->getType (), AlignI);
256
269
CallInst *malloccall = nullptr ;
257
270
if (CustomAllocator) {
271
+ LLVMValueRef wzeromem = nullptr ;
258
272
res = unwrap (CustomAllocator (wrap (&Builder), wrap (T), wrap (Count),
259
- wrap (Align), isDefault));
273
+ wrap (Align), isDefault,
274
+ ZeroMem ? &wzeromem : nullptr ));
260
275
if (auto I = dyn_cast<Instruction>(res))
261
276
I->setName (Name);
262
277
263
278
malloccall = dyn_cast<CallInst>(res);
264
279
if (malloccall == nullptr ) {
265
280
malloccall = cast<CallInst>(cast<Instruction>(res)->getOperand (0 ));
266
281
}
282
+ if (ZeroMem) {
283
+ *ZeroMem = cast_or_null<Instruction>(unwrap (wzeromem));
284
+ ZeroMem = nullptr ;
285
+ }
267
286
} else {
268
287
if (Builder.GetInsertPoint () == Builder.GetInsertBlock ()->end ()) {
269
288
res = CallInst::CreateMalloc (Builder.GetInsertBlock (), Count->getType (),
@@ -324,11 +343,6 @@ Value *CreateAllocation(IRBuilder<> &Builder, llvm::Type *T, Value *Count,
324
343
if (caller) {
325
344
*caller = malloccall;
326
345
}
327
- if (auto F = getFunctionFromCall (malloccall))
328
- if (F->getName () == " julia.gc_alloc_obj" ||
329
- F->getName () == " jl_gc_alloc_typed" ||
330
- F->getName () == " ijl_gc_alloc_typed" )
331
- ZeroMem = nullptr ;
332
346
if (ZeroMem) {
333
347
auto PT = cast<PointerType>(malloccall->getType ());
334
348
Value *tozero = malloccall;
0 commit comments