mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-19 10:29:18 +02:00
* WebAssembly: optimized the number of nested blocks inside the invoke helper
This commit is contained in:
parent
7b67378206
commit
f3ded5e82e
@ -6143,11 +6143,35 @@ implementation
|
|||||||
var
|
var
|
||||||
exesym: TExeSymbol;
|
exesym: TExeSymbol;
|
||||||
objsym: TObjSymbol;
|
objsym: TObjSymbol;
|
||||||
i: Integer;
|
i, j, TypIdx: Integer;
|
||||||
|
IndirectFunctionTableMap: array of Integer;
|
||||||
|
InvokableTypeIndices: array of Integer;
|
||||||
begin
|
begin
|
||||||
exesym:=TExeSymbol(ExeSymbolList.Find('fpc_wasm_invoke_helper'));
|
exesym:=TExeSymbol(ExeSymbolList.Find('fpc_wasm_invoke_helper'));
|
||||||
if not Assigned(exesym) then
|
if not Assigned(exesym) then
|
||||||
exit;
|
exit;
|
||||||
|
|
||||||
|
SetLength(IndirectFunctionTableMap, Length(FIndirectFunctionTable));
|
||||||
|
SetLength(InvokableTypeIndices, 1);
|
||||||
|
InvokableTypeIndices[0] := -1;
|
||||||
|
for i:=1 to Length(FIndirectFunctionTable)-1 do
|
||||||
|
begin
|
||||||
|
IndirectFunctionTableMap[i]:=0;
|
||||||
|
TypIdx := FuncIdx2TypeIdx(FIndirectFunctionTable[i].FuncIdx);
|
||||||
|
for j := 1 to Length(InvokableTypeIndices)-1 do
|
||||||
|
if InvokableTypeIndices[j]=TypIdx then
|
||||||
|
begin
|
||||||
|
IndirectFunctionTableMap[i]:=j;
|
||||||
|
break;
|
||||||
|
end;
|
||||||
|
if IndirectFunctionTableMap[i]=0 then
|
||||||
|
begin
|
||||||
|
SetLength(InvokableTypeIndices,Length(InvokableTypeIndices)+1);
|
||||||
|
InvokableTypeIndices[High(InvokableTypeIndices)]:=TypIdx;
|
||||||
|
IndirectFunctionTableMap[i]:=High(InvokableTypeIndices);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
objsym:=exesym.ObjSymbol;
|
objsym:=exesym.ObjSymbol;
|
||||||
Sec:=objsym.objsection;
|
Sec:=objsym.objsection;
|
||||||
Sec.Size:=0;
|
Sec.Size:=0;
|
||||||
@ -6156,7 +6180,7 @@ implementation
|
|||||||
{ locals }
|
{ locals }
|
||||||
Sec.writeUInt8($00);
|
Sec.writeUInt8($00);
|
||||||
|
|
||||||
for i:=1 to Length(FIndirectFunctionTable)-1 do
|
for i:=1 to Length(InvokableTypeIndices)-1 do
|
||||||
{ block }
|
{ block }
|
||||||
Sec.writeUInt16BE($0240);
|
Sec.writeUInt16BE($0240);
|
||||||
|
|
||||||
@ -6168,18 +6192,18 @@ implementation
|
|||||||
Sec.writeUInt8($0E);
|
Sec.writeUInt8($0E);
|
||||||
WriteUleb(Sec,Length(FIndirectFunctionTable));
|
WriteUleb(Sec,Length(FIndirectFunctionTable));
|
||||||
for i:=0 to Length(FIndirectFunctionTable)-1 do
|
for i:=0 to Length(FIndirectFunctionTable)-1 do
|
||||||
WriteUleb(Sec,i);
|
WriteUleb(Sec,IndirectFunctionTableMap[i]);
|
||||||
Sec.writeUInt8($00);
|
Sec.writeUInt8($00);
|
||||||
{ end }
|
{ end }
|
||||||
Sec.writeUInt8($0B);
|
Sec.writeUInt8($0B);
|
||||||
{ unreachable }
|
{ unreachable }
|
||||||
Sec.writeUInt8($00);
|
Sec.writeUInt8($00);
|
||||||
|
|
||||||
for i:=1 to Length(FIndirectFunctionTable)-1 do
|
for i:=1 to Length(InvokableTypeIndices)-1 do
|
||||||
begin
|
begin
|
||||||
{ end }
|
{ end }
|
||||||
Sec.writeUInt8($0B);
|
Sec.writeUInt8($0B);
|
||||||
InvokeFuncType(FuncIdx2TypeIdx(FIndirectFunctionTable[i].FuncIdx));
|
InvokeFuncType(InvokableTypeIndices[i]);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ end }
|
{ end }
|
||||||
|
Loading…
Reference in New Issue
Block a user