- removed OP_TAIL.
The amount of support code for this minor optimization was quite large and this stood in the way of streamlining the VM's calling convention, so it was preferable to remove it before moving on.
This commit is contained in:
parent
4e0c5cf16c
commit
629d329f22
9 changed files with 12 additions and 219 deletions
|
|
@ -5449,18 +5449,6 @@ FxRandom::~FxRandom()
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
PPrototype *FxRandom::ReturnProto()
|
||||
{
|
||||
EmitTail = true;
|
||||
return FxExpression::ReturnProto();
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
FxExpression *FxRandom::Resolve(FCompileContext &ctx)
|
||||
{
|
||||
CHECKRESOLVED();
|
||||
|
|
@ -5506,23 +5494,13 @@ ExpEmit FxRandom::Emit(VMFunctionBuilder *build)
|
|||
assert(min && max);
|
||||
callfunc = ((PSymbolVMFunction *)sym)->Function;
|
||||
|
||||
if (build->FramePointer.Fixed) EmitTail = false; // do not tail call if the stack is in use
|
||||
int opcode = (EmitTail ? OP_TAIL_K : OP_CALL_K);
|
||||
|
||||
EmitterArray emitters;
|
||||
|
||||
emitters.AddParameterPointerConst(rng);
|
||||
emitters.AddParameter(build, min);
|
||||
emitters.AddParameter(build, max);
|
||||
int count = emitters.EmitParameters(build);
|
||||
build->Emit(opcode, build->GetConstantAddress(callfunc), count, 1);
|
||||
|
||||
if (EmitTail)
|
||||
{
|
||||
ExpEmit call;
|
||||
call.Final = true;
|
||||
return call;
|
||||
}
|
||||
build->Emit(OP_CALL_K, build->GetConstantAddress(callfunc), count, 1);
|
||||
|
||||
ExpEmit out(build, REGT_INT);
|
||||
build->Emit(OP_RESULT, 0, REGT_INT, out.RegNum);
|
||||
|
|
@ -5747,22 +5725,12 @@ ExpEmit FxFRandom::Emit(VMFunctionBuilder *build)
|
|||
assert(min && max);
|
||||
callfunc = ((PSymbolVMFunction *)sym)->Function;
|
||||
|
||||
if (build->FramePointer.Fixed) EmitTail = false; // do not tail call if the stack is in use
|
||||
int opcode = (EmitTail ? OP_TAIL_K : OP_CALL_K);
|
||||
|
||||
EmitterArray emitters;
|
||||
emitters.AddParameterPointerConst(rng);
|
||||
emitters.AddParameter(build, min);
|
||||
emitters.AddParameter(build, max);
|
||||
int count = emitters.EmitParameters(build);
|
||||
build->Emit(opcode, build->GetConstantAddress(callfunc), count, 1);
|
||||
|
||||
if (EmitTail)
|
||||
{
|
||||
ExpEmit call;
|
||||
call.Final = true;
|
||||
return call;
|
||||
}
|
||||
build->Emit(OP_CALL_K, build->GetConstantAddress(callfunc), count, 1);
|
||||
|
||||
ExpEmit out(build, REGT_FLOAT);
|
||||
build->Emit(OP_RESULT, 0, REGT_FLOAT, out.RegNum);
|
||||
|
|
@ -5778,7 +5746,6 @@ ExpEmit FxFRandom::Emit(VMFunctionBuilder *build)
|
|||
FxRandom2::FxRandom2(FRandom *r, FxExpression *m, const FScriptPosition &pos, bool nowarn)
|
||||
: FxExpression(EFX_Random2, pos)
|
||||
{
|
||||
EmitTail = false;
|
||||
rng = r;
|
||||
if (m) mask = new FxIntCast(m, nowarn);
|
||||
else mask = new FxConstant(-1, pos);
|
||||
|
|
@ -5802,18 +5769,6 @@ FxRandom2::~FxRandom2()
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
PPrototype *FxRandom2::ReturnProto()
|
||||
{
|
||||
EmitTail = true;
|
||||
return FxExpression::ReturnProto();
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
FxExpression *FxRandom2::Resolve(FCompileContext &ctx)
|
||||
{
|
||||
CHECKRESOLVED();
|
||||
|
|
@ -5851,22 +5806,12 @@ ExpEmit FxRandom2::Emit(VMFunctionBuilder *build)
|
|||
assert(((PSymbolVMFunction *)sym)->Function != nullptr);
|
||||
callfunc = ((PSymbolVMFunction *)sym)->Function;
|
||||
|
||||
if (build->FramePointer.Fixed) EmitTail = false; // do not tail call if the stack is in use
|
||||
int opcode = (EmitTail ? OP_TAIL_K : OP_CALL_K);
|
||||
|
||||
EmitterArray emitters;
|
||||
|
||||
emitters.AddParameterPointerConst(rng);
|
||||
emitters.AddParameter(build, mask);
|
||||
int count = emitters.EmitParameters(build);
|
||||
build->Emit(opcode, build->GetConstantAddress(callfunc), count, 1);
|
||||
|
||||
if (EmitTail)
|
||||
{
|
||||
ExpEmit call;
|
||||
call.Final = true;
|
||||
return call;
|
||||
}
|
||||
build->Emit(OP_CALL_K, build->GetConstantAddress(callfunc), count, 1);
|
||||
|
||||
ExpEmit out(build, REGT_INT);
|
||||
build->Emit(OP_RESULT, 0, REGT_INT, out.RegNum);
|
||||
|
|
@ -5881,7 +5826,6 @@ ExpEmit FxRandom2::Emit(VMFunctionBuilder *build)
|
|||
FxRandomSeed::FxRandomSeed(FRandom * r, FxExpression *s, const FScriptPosition &pos, bool nowarn)
|
||||
: FxExpression(EFX_Random, pos)
|
||||
{
|
||||
EmitTail = false;
|
||||
seed = new FxIntCast(s, nowarn);
|
||||
rng = r;
|
||||
ValueType = TypeVoid;
|
||||
|
|
@ -5937,18 +5881,14 @@ ExpEmit FxRandomSeed::Emit(VMFunctionBuilder *build)
|
|||
assert(((PSymbolVMFunction *)sym)->Function != nullptr);
|
||||
callfunc = ((PSymbolVMFunction *)sym)->Function;
|
||||
|
||||
if (build->FramePointer.Fixed) EmitTail = false; // do not tail call if the stack is in use
|
||||
int opcode = (EmitTail ? OP_TAIL_K : OP_CALL_K);
|
||||
|
||||
EmitterArray emitters;
|
||||
|
||||
emitters.AddParameterPointerConst(rng);
|
||||
emitters.AddParameter(build, seed);
|
||||
int count = emitters.EmitParameters(build);
|
||||
build->Emit(opcode, build->GetConstantAddress(callfunc), count, 0);
|
||||
build->Emit(OP_CALL_K, build->GetConstantAddress(callfunc), count, 0);
|
||||
|
||||
ExpEmit call;
|
||||
if (EmitTail) call.Final = true;
|
||||
return call;
|
||||
}
|
||||
|
||||
|
|
@ -6636,7 +6576,6 @@ FxClassDefaults::FxClassDefaults(FxExpression *X, const FScriptPosition &pos)
|
|||
: FxExpression(EFX_ClassDefaults, pos)
|
||||
{
|
||||
obj = X;
|
||||
EmitTail = false;
|
||||
}
|
||||
|
||||
FxClassDefaults::~FxClassDefaults()
|
||||
|
|
@ -8508,7 +8447,6 @@ FxActionSpecialCall::FxActionSpecialCall(FxExpression *self, int special, FArgum
|
|||
{
|
||||
ArgList.Push(new FxConstant(0, ScriptPosition));
|
||||
}
|
||||
EmitTail = false;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
|
|
@ -8528,18 +8466,6 @@ FxActionSpecialCall::~FxActionSpecialCall()
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
PPrototype *FxActionSpecialCall::ReturnProto()
|
||||
{
|
||||
EmitTail = true;
|
||||
return FxExpression::ReturnProto();
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
FxExpression *FxActionSpecialCall::Resolve(FCompileContext& ctx)
|
||||
{
|
||||
CHECKRESOLVED();
|
||||
|
|
@ -8664,16 +8590,8 @@ ExpEmit FxActionSpecialCall::Emit(VMFunctionBuilder *build)
|
|||
ArgList.DeleteAndClear();
|
||||
ArgList.ShrinkToFit();
|
||||
|
||||
if (build->FramePointer.Fixed) EmitTail = false; // do not tail call if the stack is in use
|
||||
int count = emitters.EmitParameters(build);
|
||||
selfemit.Free(build);
|
||||
if (EmitTail)
|
||||
{
|
||||
build->Emit(OP_TAIL_K, build->GetConstantAddress(callfunc), count, 0);
|
||||
ExpEmit call;
|
||||
call.Final = true;
|
||||
return call;
|
||||
}
|
||||
|
||||
ExpEmit dest(build, REGT_INT);
|
||||
build->Emit(OP_CALL_K, build->GetConstantAddress(callfunc), count, 1);
|
||||
|
|
@ -8717,7 +8635,7 @@ PPrototype *FxVMFunctionCall::ReturnProto()
|
|||
{
|
||||
if (hasStringArgs)
|
||||
return FxExpression::ReturnProto();
|
||||
EmitTail = true;
|
||||
|
||||
return Function->Variants[0].Proto;
|
||||
}
|
||||
|
||||
|
|
@ -9068,12 +8986,10 @@ ExpEmit FxVMFunctionCall::Emit(VMFunctionBuilder *build)
|
|||
assert(build->Registers[REGT_POINTER].GetMostUsed() >= build->NumImplicits);
|
||||
int count = 0;
|
||||
|
||||
if (build->FramePointer.Fixed) EmitTail = false; // do not tail call if the stack is in use
|
||||
|
||||
if (count == 1)
|
||||
{
|
||||
ExpEmit reg;
|
||||
if (CheckEmitCast(build, EmitTail, reg))
|
||||
if (CheckEmitCast(build, false, reg))
|
||||
{
|
||||
ArgList.DeleteAndClear();
|
||||
ArgList.ShrinkToFit();
|
||||
|
|
@ -9166,14 +9082,7 @@ ExpEmit FxVMFunctionCall::Emit(VMFunctionBuilder *build)
|
|||
{
|
||||
int funcaddr = build->GetConstantAddress(vmfunc);
|
||||
// Emit the call
|
||||
if (EmitTail)
|
||||
{ // Tail call
|
||||
build->Emit(OP_TAIL_K, funcaddr, count, 0);
|
||||
ExpEmit call;
|
||||
call.Final = true;
|
||||
return call;
|
||||
}
|
||||
else if (vmfunc->Proto->ReturnTypes.Size() > 0)
|
||||
if (vmfunc->Proto->ReturnTypes.Size() > 0)
|
||||
{ // Call, expecting one result
|
||||
build->Emit(OP_CALL_K, funcaddr, count, MAX(1, AssignCount));
|
||||
goto handlereturns;
|
||||
|
|
@ -9189,14 +9098,7 @@ ExpEmit FxVMFunctionCall::Emit(VMFunctionBuilder *build)
|
|||
ExpEmit funcreg(build, REGT_POINTER);
|
||||
|
||||
build->Emit(OP_VTBL, funcreg.RegNum, selfemit.RegNum, vmfunc->VirtualIndex);
|
||||
if (EmitTail)
|
||||
{ // Tail call
|
||||
build->Emit(OP_TAIL, funcreg.RegNum, count, 0);
|
||||
ExpEmit call;
|
||||
call.Final = true;
|
||||
return call;
|
||||
}
|
||||
else if (vmfunc->Proto->ReturnTypes.Size() > 0)
|
||||
if (vmfunc->Proto->ReturnTypes.Size() > 0)
|
||||
{ // Call, expecting one result
|
||||
build->Emit(OP_CALL, funcreg.RegNum, count, MAX(1, AssignCount));
|
||||
goto handlereturns;
|
||||
|
|
|
|||
|
|
@ -404,7 +404,6 @@ public:
|
|||
class FxClassDefaults : public FxExpression
|
||||
{
|
||||
FxExpression *obj;
|
||||
bool EmitTail;
|
||||
|
||||
public:
|
||||
FxClassDefaults(FxExpression *, const FScriptPosition &);
|
||||
|
|
@ -1257,7 +1256,6 @@ public:
|
|||
class FxRandom : public FxExpression
|
||||
{
|
||||
protected:
|
||||
bool EmitTail = false;
|
||||
FRandom *rng;
|
||||
FxExpression *min, *max;
|
||||
|
||||
|
|
@ -1267,7 +1265,6 @@ public:
|
|||
FxRandom(FRandom *, FxExpression *mi, FxExpression *ma, const FScriptPosition &pos, bool nowarn);
|
||||
~FxRandom();
|
||||
FxExpression *Resolve(FCompileContext&);
|
||||
PPrototype *ReturnProto();
|
||||
ExpEmit Emit(VMFunctionBuilder *build);
|
||||
};
|
||||
|
||||
|
|
@ -1313,7 +1310,6 @@ public:
|
|||
|
||||
class FxRandom2 : public FxExpression
|
||||
{
|
||||
bool EmitTail;
|
||||
FRandom * rng;
|
||||
FxExpression *mask;
|
||||
|
||||
|
|
@ -1322,7 +1318,6 @@ public:
|
|||
FxRandom2(FRandom *, FxExpression *m, const FScriptPosition &pos, bool nowarn);
|
||||
~FxRandom2();
|
||||
FxExpression *Resolve(FCompileContext&);
|
||||
PPrototype *ReturnProto();
|
||||
ExpEmit Emit(VMFunctionBuilder *build);
|
||||
};
|
||||
|
||||
|
|
@ -1336,7 +1331,6 @@ public:
|
|||
class FxRandomSeed : public FxExpression
|
||||
{
|
||||
protected:
|
||||
bool EmitTail;
|
||||
FRandom *rng;
|
||||
FxExpression *seed;
|
||||
|
||||
|
|
@ -1583,7 +1577,6 @@ public:
|
|||
class FxActionSpecialCall : public FxExpression
|
||||
{
|
||||
int Special;
|
||||
bool EmitTail;
|
||||
FxExpression *Self;
|
||||
FArgumentList ArgList;
|
||||
|
||||
|
|
@ -1592,7 +1585,6 @@ public:
|
|||
FxActionSpecialCall(FxExpression *self, int special, FArgumentList &args, const FScriptPosition &pos);
|
||||
~FxActionSpecialCall();
|
||||
FxExpression *Resolve(FCompileContext&);
|
||||
PPrototype *ReturnProto();
|
||||
ExpEmit Emit(VMFunctionBuilder *build);
|
||||
};
|
||||
|
||||
|
|
@ -1752,7 +1744,6 @@ class FxVMFunctionCall : public FxExpression
|
|||
{
|
||||
friend class FxMultiAssign;
|
||||
|
||||
bool EmitTail = false;
|
||||
bool NoVirtual;
|
||||
bool hasStringArgs = false;
|
||||
FxExpression *Self;
|
||||
|
|
|
|||
|
|
@ -606,7 +606,7 @@ size_t VMFunctionBuilder::Emit(int opcode, int opa, int opb, int opc)
|
|||
emit.Free(this);
|
||||
}
|
||||
|
||||
if (opcode == OP_CALL || opcode == OP_CALL_K || opcode == OP_TAIL || opcode == OP_TAIL_K)
|
||||
if (opcode == OP_CALL || opcode == OP_CALL_K)
|
||||
{
|
||||
ParamChange(-opb);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -330,7 +330,6 @@ void VMDisasm(FILE *out, const VMOP *code, int codesize, const VMScriptFunction
|
|||
break;
|
||||
|
||||
case OP_CALL_K:
|
||||
case OP_TAIL_K:
|
||||
{
|
||||
callfunc = (VMFunction *)func->KonstA[code[i].a].o;
|
||||
col = printf_wrapper(out, "[%p],%d", callfunc, code[i].b);
|
||||
|
|
@ -524,7 +523,7 @@ void VMDisasm(FILE *out, const VMOP *code, int codesize, const VMScriptFunction
|
|||
{
|
||||
printf_wrapper(out, ",%d\n", code[++i].i24);
|
||||
}
|
||||
else if (code[i].op == OP_CALL_K || code[i].op == OP_TAIL_K)
|
||||
else if (code[i].op == OP_CALL_K)
|
||||
{
|
||||
printf_wrapper(out, " [%s]\n", callfunc->PrintableName.GetChars());
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue