Skip to content

Commit 404da70

Browse files
carnavalvtjnash
authored andcommitted
use memset to zero the temp roots of the gcframe (#16909)
1 parent 9a2c144 commit 404da70

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/llvm-gcroot.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ class JuliaGCAllocator {
4242
JuliaGCAllocator(CallInst *ptlsStates, Type *T_pjlvalue, MDNode *tbaa) :
4343
F(*ptlsStates->getParent()->getParent()),
4444
M(*F.getParent()),
45+
T_int1(Type::getInt1Ty(F.getContext())),
46+
T_int8(Type::getInt8Ty(F.getContext())),
4547
T_int32(Type::getInt32Ty(F.getContext())),
4648
T_int64(Type::getInt64Ty(F.getContext())),
4749
V_null(Constant::getNullValue(T_pjlvalue)),
@@ -69,6 +71,8 @@ class JuliaGCAllocator {
6971
private:
7072
Function &F;
7173
Module &M;
74+
Type *const T_int1;
75+
Type *const T_int8;
7276
Type *const T_int32;
7377
Type *const T_int64;
7478
Value *const V_null;
@@ -784,13 +788,16 @@ void allocate_frame()
784788
}
785789
else {
786790
// Initialize the slots for temporary variables to NULL
787-
for (unsigned i = 0; i < maxDepth; i++) {
788-
Instruction *argTempi = GetElementPtrInst::Create(LLVM37_param(NULL) tempSlot, ArrayRef<Value*>(ConstantInt::get(T_int32, i)));
789-
argTempi->insertAfter(last_gcframe_inst);
790-
StoreInst *store = new StoreInst(V_null, argTempi);
791-
store->setMetadata(llvm::LLVMContext::MD_tbaa, tbaa_gcframe);
792-
store->insertAfter(argTempi);
793-
last_gcframe_inst = store;
791+
if (maxDepth > 0) {
792+
BitCastInst *tempSlot_i8 = new BitCastInst(tempSlot, PointerType::get(T_int8, 0), "", last_gcframe_inst);
793+
CallInst *zeroing =
794+
CallInst::Create(Intrinsic::getDeclaration(&M, Intrinsic::memset, {tempSlot_i8->getType(), T_int32}),
795+
{tempSlot_i8, ConstantInt::get(T_int8, 0),
796+
ConstantInt::get(T_int32, sizeof(jl_value_t*)*maxDepth),
797+
ConstantInt::get(T_int32, 0), ConstantInt::get(T_int1, 0)});
798+
zeroing->setMetadata(llvm::LLVMContext::MD_tbaa, tbaa_gcframe);
799+
zeroing->insertAfter(tempSlot_i8);
800+
last_gcframe_inst = zeroing;
794801
}
795802

796803
gcframe->setOperand(0, ConstantInt::get(T_int32, 2 + argSpaceSize + maxDepth)); // fix up the size of the gc frame

0 commit comments

Comments
 (0)