@@ -213,15 +213,14 @@ void DtoArrayAssign(Loc& loc, DValue *array, DValue *value, int op)
213
213
assert (t->nextOf ());
214
214
Type *elemType = t->nextOf ()->toBasetype ();
215
215
216
- LLFunction* fn = LLVM_D_GetRuntimeFunction (loc, gIR ->module , op == TOKconstruct ? " _d_arrayctor" : " _d_arrayassign" );
217
216
LLValue* args[] = {
218
217
DtoTypeInfoOf (elemType),
219
- DtoAggrPaint (DtoSlice (value), fn-> getFunctionType ()-> getParamType ( 1 )),
220
- DtoAggrPaint (DtoSlice (array), fn-> getFunctionType ()-> getParamType ( 2 ))
218
+ DtoAggrPaint (DtoSlice (value), DtoType (Type::tvoid-> arrayOf () )),
219
+ DtoAggrPaint (DtoSlice (array), DtoType (Type::tvoid-> arrayOf () ))
221
220
};
222
221
223
- LLCallSite call = gIR -> CreateCallOrInvoke (fn, args, " .array " );
224
- call. setCallingConv (llvm::CallingConv::C );
222
+ LLVM_D_CallRuntimeFunction (loc, (op == TOKconstruct) ? " _d_arrayctor " : " _d_arrayassign " ,
223
+ args, " .array " );
225
224
}
226
225
227
226
// If op is TOKconstruct, does construction of an array;
@@ -237,16 +236,15 @@ void DtoArraySetAssign(Loc& loc, DValue *array, DValue *value, int op)
237
236
LLValue *ptr = DtoArrayPtr (array);
238
237
LLValue *len = DtoArrayLen (array);
239
238
240
- LLFunction* fn = LLVM_D_GetRuntimeFunction (loc, gIR ->module , op == TOKconstruct ? " _d_arraysetctor" : " _d_arraysetassign" );
241
239
LLValue* args[] = {
242
240
DtoBitCast (ptr, getVoidPtrType ()),
243
241
DtoBitCast (makeLValue (loc, value), getVoidPtrType ()),
244
242
len,
245
243
DtoTypeInfoOf (array->type ->toBasetype ()->nextOf ()->toBasetype ())
246
244
};
247
245
248
- LLCallSite call = gIR -> CreateCallOrInvoke (fn, args, " .newptr " );
249
- call. setCallingConv (llvm::CallingConv::C );
246
+ LLVM_D_CallRuntimeFunction (loc, (op == TOKconstruct) ? " _d_arraysetctor " : " _d_arraysetassign " ,
247
+ args, " .newptr " );
250
248
}
251
249
252
250
// ////////////////////////////////////////////////////////////////////////////////////////
@@ -510,8 +508,8 @@ static void copySlice(Loc& loc, LLValue* dstarr, LLValue* sz1, LLValue* srcarr,
510
508
{
511
509
if (global.params .useAssert || gIR ->emitArrayBoundsChecks ())
512
510
{
513
- LLValue* fn = LLVM_D_GetRuntimeFunction (loc, gIR -> module , " _d_array_slice_copy " ) ;
514
- gIR -> CreateCallOrInvoke4 (fn, dstarr, sz1, srcarr, sz2 );
511
+ LLValue* args[] = { dstarr, sz1, srcarr, sz2 } ;
512
+ LLVM_D_CallRuntimeFunction (loc, " _d_array_slice_copy " , args );
515
513
}
516
514
else
517
515
{
@@ -624,10 +622,9 @@ DSliceValue* DtoNewDynArray(Loc& loc, Type* arrayType, DValue* dim, bool default
624
622
const char * fnname = defaultInit ?
625
623
(zeroInit ? " _d_newarrayT" : " _d_newarrayiT" ) :
626
624
" _d_newarrayU" ;
627
- LLFunction* fn = LLVM_D_GetRuntimeFunction (loc, gIR ->module , fnname);
628
625
629
- // call allocator
630
- LLValue* newArray = gIR -> CreateCallOrInvoke2 (fn, arrayTypeInfo, arrayLen , " .gc_mem" ). getInstruction ( );
626
+ LLValue* args[] = { arrayTypeInfo, arrayLen };
627
+ LLValue* newArray = LLVM_D_CallRuntimeFunction (loc, fnname, args , " .gc_mem" );
631
628
632
629
return getSlice (arrayType, newArray);
633
630
}
@@ -653,9 +650,7 @@ DSliceValue* DtoNewMulDimDynArray(Loc& loc, Type* arrayType, DValue** dims, size
653
650
654
651
const char * fnname = zeroInit ? " _d_newarraymT" : " _d_newarraymiT" ;
655
652
656
- LLFunction* fn = LLVM_D_GetRuntimeFunction (loc, gIR ->module , fnname);
657
-
658
- std::vector<LLValue*> args;
653
+ llvm::SmallVector<llvm::Value*,4 > args;
659
654
args.reserve (ndims+2 );
660
655
args.push_back (arrayTypeInfo);
661
656
args.push_back (DtoConstSize_t (ndims));
@@ -665,7 +660,7 @@ DSliceValue* DtoNewMulDimDynArray(Loc& loc, Type* arrayType, DValue** dims, size
665
660
args.push_back (dims[i]->getRVal ());
666
661
667
662
// call allocator
668
- LLValue* newptr = gIR -> CreateCallOrInvoke (fn, args, " .gc_mem" ). getInstruction ( );
663
+ LLValue* newptr = LLVM_D_CallRuntimeFunction (loc, fnname, args, " .gc_mem" );
669
664
670
665
IF_LOG Logger::cout () << " final ptr = " << *newptr << ' \n ' ;
671
666
@@ -687,14 +682,13 @@ DSliceValue* DtoResizeDynArray(Loc& loc, Type* arrayType, DValue* array, LLValue
687
682
bool zeroInit = arrayType->toBasetype ()->nextOf ()->isZeroInit ();
688
683
689
684
// call runtime
690
- LLFunction* fn = LLVM_D_GetRuntimeFunction (loc, gIR ->module , zeroInit ? " _d_arraysetlengthT" : " _d_arraysetlengthiT" );
691
-
685
+ const char * fnname = zeroInit ? " _d_arraysetlengthT" : " _d_arraysetlengthiT" ;
692
686
LLValue* args[] = {
693
687
DtoTypeInfoOf (arrayType),
694
688
newdim,
695
- DtoBitCast (array->getLVal (), fn-> getFunctionType ()->getParamType ( 2 ))
689
+ DtoBitCast (array->getLVal (), DtoType (Type::tvoid-> arrayOf ()->pointerTo () ))
696
690
};
697
- LLValue* newArray = gIR -> CreateCallOrInvoke (fn, args, " .gc_mem" ). getInstruction ( );
691
+ LLValue* newArray = LLVM_D_CallRuntimeFunction (loc, fnname, args, " .gc_mem" );
698
692
699
693
return getSlice (arrayType, newArray);
700
694
}
@@ -714,14 +708,13 @@ void DtoCatAssignElement(Loc& loc, Type* arrayType, DValue* array, Expression* e
714
708
// otherwise a ~= a[$-i] won't work correctly
715
709
DValue *expVal = toElem (exp );
716
710
717
- LLFunction* fn = LLVM_D_GetRuntimeFunction (loc, gIR ->module , " _d_arrayappendcTX" );
718
711
LLValue* args[] = {
719
712
DtoTypeInfoOf (arrayType),
720
- DtoBitCast (array->getLVal (), fn-> getFunctionType ()->getParamType ( 1 )),
713
+ DtoBitCast (array->getLVal (), DtoType (Type::tint8-> arrayOf ()->pointerTo () )),
721
714
DtoConstSize_t (1 )
722
715
};
716
+ LLValue* appendedArray = LLVM_D_CallRuntimeFunction (loc, " _d_arrayappendcTX" , args, " .appendedArray" );
723
717
724
- LLValue* appendedArray = gIR ->CreateCallOrInvoke (fn, args, " .appendedArray" ).getInstruction ();
725
718
appendedArray = DtoAggrPaint (appendedArray, DtoType (arrayType));
726
719
727
720
LLValue* val = DtoArrayPtr (array);
@@ -739,19 +732,18 @@ DSliceValue* DtoCatAssignArray(Loc& loc, DValue* arr, Expression* exp)
739
732
Type *arrayType = arr->getType ();
740
733
741
734
// Prepare arguments
742
- LLFunction* fn = LLVM_D_GetRuntimeFunction (loc, gIR ->module , " _d_arrayappendT" );
743
735
LLSmallVector<LLValue*,3 > args;
744
736
// TypeInfo ti
745
737
args.push_back (DtoTypeInfoOf (arrayType));
746
738
// byte[] *px
747
- args.push_back (DtoBitCast (arr->getLVal (), fn-> getFunctionType ()->getParamType ( 1 )));
739
+ args.push_back (DtoBitCast (arr->getLVal (), DtoType (Type::tint8-> arrayOf ()->pointerTo () )));
748
740
// byte[] y
749
741
LLValue *y = DtoSlice (toElem (exp ));
750
- y = DtoAggrPaint (y, fn-> getFunctionType ()-> getParamType ( 2 ));
742
+ y = DtoAggrPaint (y, DtoType (Type::tint8-> arrayOf () ));
751
743
args.push_back (y);
752
744
753
745
// Call _d_arrayappendT
754
- LLValue* newArray = gIR -> CreateCallOrInvoke (fn, args, " .appendedArray" ). getInstruction ( );
746
+ LLValue* newArray = LLVM_D_CallRuntimeFunction (loc, " _d_arrayappendT " , args, " .appendedArray" );
755
747
756
748
return getSlice (arrayType, newArray);
757
749
}
@@ -765,10 +757,11 @@ DSliceValue* DtoCatArrays(Loc& loc, Type* arrayType, Expression* exp1, Expressio
765
757
766
758
std::vector<LLValue*> args;
767
759
LLFunction* fn = 0 ;
760
+ const char * fname = NULL ;
768
761
769
762
if (exp1->op == TOKcat)
770
763
{ // handle multiple concat
771
- fn = LLVM_D_GetRuntimeFunction (loc, gIR -> module , " _d_arraycatnT" ) ;
764
+ fname = " _d_arraycatnT" ;
772
765
773
766
args.push_back (DtoSlicePtr (toElem (exp2 )));
774
767
CatExp *ce = static_cast <CatExp*>(exp1);
@@ -788,21 +781,21 @@ DSliceValue* DtoCatArrays(Loc& loc, Type* arrayType, Expression* exp1, Expressio
788
781
}
789
782
else
790
783
{
791
- fn = LLVM_D_GetRuntimeFunction (loc, gIR -> module , " _d_arraycatT" ) ;
784
+ fname = " _d_arraycatT" ;
792
785
793
786
// TypeInfo ti
794
787
args.push_back (DtoTypeInfoOf (arrayType));
795
788
// byte[] x
796
789
LLValue *val = DtoLoad (DtoSlicePtr (toElem (exp1)));
797
- val = DtoAggrPaint (val, fn-> getFunctionType ()-> getParamType ( 1 ));
790
+ val = DtoAggrPaint (val, DtoType (Type::tint8-> arrayOf () ));
798
791
args.push_back (val);
799
792
// byte[] y
800
793
val = DtoLoad (DtoSlicePtr (toElem (exp2 )));
801
- val = DtoAggrPaint (val, fn-> getFunctionType ()-> getParamType ( 2 ));
794
+ val = DtoAggrPaint (val, DtoType (Type::tint8-> arrayOf () ));
802
795
args.push_back (val);
803
796
}
804
797
805
- LLValue *newArray = gIR -> CreateCallOrInvoke (fn, args, " .appendedArray" ). getInstruction ( );
798
+ LLValue *newArray = LLVM_D_CallRuntimeFunction (loc, fname, args, " .appendedArray" );
806
799
return getSlice (arrayType, newArray);
807
800
}
808
801
@@ -815,15 +808,16 @@ DSliceValue* DtoAppendDChar(Loc& loc, DValue* arr, Expression* exp, const char *
815
808
816
809
// Prepare arguments
817
810
LLFunction* fn = LLVM_D_GetRuntimeFunction (loc, gIR ->module , func);
811
+ unsigned arg_offset = fn->hasStructRetAttr () ? 1 : 0 ; // argument numbering offset due to sret
818
812
LLValue* args[] = {
819
813
// ref string x
820
- DtoBitCast (arr->getLVal (), fn->getFunctionType ()->getParamType (0 )),
814
+ DtoBitCast (arr->getLVal (), fn->getFunctionType ()->getParamType (arg_offset + 0 )),
821
815
// dchar c
822
- DtoBitCast (valueToAppend->getRVal (), fn->getFunctionType ()->getParamType (1 ))
816
+ DtoBitCast (valueToAppend->getRVal (), fn->getFunctionType ()->getParamType (arg_offset + 1 ))
823
817
};
824
818
825
819
// Call function
826
- LLValue* newArray = gIR -> CreateCallOrInvoke (fn, args, " .appendedArray" ). getInstruction ( );
820
+ LLValue* newArray = LLVM_D_CallRuntimeFunction (loc, func, args, " .appendedArray" );
827
821
828
822
return getSlice (arrayType, newArray);
829
823
}
@@ -853,6 +847,7 @@ static LLValue* DtoArrayEqCmp_impl(Loc& loc, const char* func, DValue* l, DValue
853
847
IF_LOG Logger::println (" comparing arrays" );
854
848
LLFunction* fn = LLVM_D_GetRuntimeFunction (loc, gIR ->module , func);
855
849
assert (fn);
850
+ unsigned arg_offset = fn->hasStructRetAttr () ? 1 : 0 ; // argument numbering offset due to sret
856
851
857
852
// find common dynamic array type
858
853
Type* commonType = l->getType ()->toBasetype ()->nextOf ()->arrayOf ();
@@ -862,7 +857,7 @@ static LLValue* DtoArrayEqCmp_impl(Loc& loc, const char* func, DValue* l, DValue
862
857
l = DtoCastArray (loc, l, commonType);
863
858
r = DtoCastArray (loc, r, commonType);
864
859
865
- LLSmallVector<LLValue*, 3 > args;
860
+ LLSmallVector<LLValue*, 4 > args;
866
861
867
862
// get values, reinterpret cast to void[]
868
863
args.push_back (DtoAggrPaint (l->getRVal (), DtoArrayType (LLType::getInt8Ty (gIR ->context ()))));
@@ -872,10 +867,10 @@ static LLValue* DtoArrayEqCmp_impl(Loc& loc, const char* func, DValue* l, DValue
872
867
if (useti) {
873
868
Type* t = l->getType ();
874
869
LLValue* tival = DtoTypeInfoOf (t);
875
- args.push_back (DtoBitCast (tival, fn->getFunctionType ()->getParamType (2 )));
870
+ args.push_back (DtoBitCast (tival, fn->getFunctionType ()->getParamType (arg_offset + 2 )));
876
871
}
877
872
878
- LLCallSite call = gIR -> CreateCallOrInvoke (fn , args);
873
+ LLCallSite call = LLVM_D_CallRuntimeFunction (loc, func , args);
879
874
880
875
return call.getInstruction ();
881
876
}
@@ -933,8 +928,7 @@ LLValue* DtoArrayCastLength(Loc& loc, LLValue* len, LLType* elemty, LLType* newe
933
928
LLConstantInt::get (DtoSize_t (), nsz, false )
934
929
};
935
930
936
- LLFunction* fn = LLVM_D_GetRuntimeFunction (loc, gIR ->module , " _d_array_cast_len" );
937
- return gIR ->CreateCallOrInvoke (fn, args).getInstruction ();
931
+ return LLVM_D_CallRuntimeFunction (loc, " _d_array_cast_len" , args);
938
932
}
939
933
940
934
// ////////////////////////////////////////////////////////////////////////////////////////
@@ -1182,8 +1176,7 @@ void DtoArrayBoundsCheck(Loc& loc, DValue* arr, DValue* index, DValue* lowerBoun
1182
1176
args.push_back (c);
1183
1177
1184
1178
// call
1185
- llvm::Function* errorfn = LLVM_D_GetRuntimeFunction (loc, gIR ->module , " _d_arraybounds" );
1186
- gIR ->CreateCallOrInvoke (errorfn, args);
1179
+ LLVM_D_CallRuntimeFunction (loc, " _d_arraybounds" , args);
1187
1180
1188
1181
// the function does not return
1189
1182
gIR ->ir ->CreateUnreachable ();
0 commit comments