should be easy enough to do for whole procedures you have to define the function to llvm anyway andFred wrote:I basically use any example I can find to make progress, but yes it's not straight forward. That said, the results are impressive as only one backend rules them all. I will try to find a way to keep inline ASM working, may be trought procedure compiled and linked in a separate way (so the procedure will need to be 100% ASM). I can't wait to see if there is any performance improvement on small code test
you just add LLVMAddFunctionAttr(*functionPtr,#LLVMExternalLinkage) or whatever the equivalent is in the c++ api
then collect the asm procedures spit them out the old pipeline to handle the preambles and returns, assemble
and make a static lib before verifying the module and running the jit.
so inline asm procedures could have the use of procedurereturn
Code: Select all
Procedure QF(*haystack,len,*needle,lenN)
!mov rax,[p.p_needle]
!movzx rax,byte [rax+7]
!mov r12, 0x0101010101010101
!imul r12, rax
!mov r8,[p.p_haystack]
!mov r9,[p.p_needle]
!whilelen2:
!cmp rcx, [p.v_len]
!jge wend2
;...
!jnz whilelen2
!mov rax,rcx
ProcedureReturn
!wend2:
ProcedureReturn -1
EndProcedure
Code: Select all
Procedure DefineFunction(*fn.FunctionProtos,Returntype.s="",bext=0,CallConvention=0,isVarArg=0)
Protected paramcount,ct,FunctionReturnType,Function
If *fn\functionPtr = 0
paramcount = ListSize(*fn\args())
Dim paramType.i(paramcount+1)
ForEach *fn\args()
If Not FindMapElement(types(),*fn\args()\type)
ty = LLVMGetTypeByName(llvmModule,*fn\args()\type)
If ty
paramType(ct) = ty
Else
error("undefined type" + *fn\args()\type)
EndIf
Else
paramType(ct)=types(*fn\args()\type)\ptr
EndIf
ct+1
Next
If Returntype <> ""
*fn\ReturnType = Returntype
EndIf
If paramcount
FunctionReturnType = LLVMFunctionType(types(*fn\ReturnType)\ptr,@paramType(0),paramcount,isVarArg)
Else
FunctionReturnType = LLVMFunctionType(types(*fn\ReturnType)\ptr,0,0,isVarArg)
EndIf
*fn\functionPtr = LLVMAddFunction(llvmModule,*fn\name,FunctionReturnType)
If bExt
LLVMAddFunctionAttr(*fn\functionPtr,#LLVMExternalLinkage);
EndIf
If CallConvention
LLVMAddFunctionAttr(*fn\functionPtr,CallConvention);
EndIf
ProcedureReturn *fn\functionPtr
EndIf
EndProcedure