Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keepalive take 2 #1352

Merged
merged 3 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/daScript/simulate/debug_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace das
#endif

#ifndef DAS_ENABLE_KEEPALIVE
#define DAS_ENABLE_KEEPALIVE 0
#define DAS_ENABLE_KEEPALIVE 1
#endif

enum Type : int32_t {
Expand Down
8 changes: 4 additions & 4 deletions include/daScript/simulate/runtime_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -429,13 +429,13 @@ namespace das
};

template <>
struct SimNodeKeepAlive_ForGoodArray1<0> : public SimNode_ForBase {
SimNodeKeepAlive_ForGoodArray1 ( const LineInfo & at ) : SimNode_ForBase(at) {}
struct SimNodeKeepAlive_ForGoodArray1<0> : public SimNode_ForGoodArray1<0> {
SimNodeKeepAlive_ForGoodArray1 ( const LineInfo & at ) : SimNode_ForGoodArray1<0>(at) {}
};

template <>
struct SimNodeKeepAlive_ForGoodArray1<1> : public SimNode_ForBase {
SimNodeKeepAlive_ForGoodArray1 ( const LineInfo & at ) : SimNode_ForBase(at) {}
struct SimNodeKeepAlive_ForGoodArray1<1> : public SimNode_ForGoodArray1<1> {
SimNodeKeepAlive_ForGoodArray1 ( const LineInfo & at ) : SimNode_ForGoodArray1<1>(at) {}
DAS_EVAL_ABI virtual vec4f eval ( Context & context ) override {
DAS_PROFILE_NODE
Array * __restrict pha;
Expand Down
2 changes: 1 addition & 1 deletion include/daScript/simulate/runtime_range.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ namespace das
// FOR RANGE KEEPALIVE
//////////////////

#if DAS_DEBUGGER
#if DAS_ENABLE_KEEPALIVE

template <typename TRange>
struct SimNodeKeepAlive_ForRange : SimNode_ForRange<TRange> {
Expand Down
4 changes: 4 additions & 0 deletions include/daScript/simulate/simulate.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ namespace das
virtual bool rtti_node_isInstrument() const { return false; }
virtual bool rtti_node_isInstrumentFunction() const { return false; }
virtual bool rtti_node_isJit() const { return false; }
virtual bool rtti_node_isKeepAlive() const { return false; }
virtual bool rtti_node_isCallBase() const { return false; }
protected:
virtual ~SimNode() {}
};
Expand Down Expand Up @@ -988,6 +990,7 @@ __forceinline void profileNode ( SimNode * node ) {

struct SimNode_KeepAlive : SimNode {
SimNode_KeepAlive ( const LineInfo & at, SimNode * res ) : SimNode(at), value(res) {}
virtual bool rtti_node_isKeepAlive() const override { return true; }
virtual SimNode * visit ( SimVisitor & vis ) override;
#define EVAL_NODE(TYPE,CTYPE)\
virtual CTYPE eval##TYPE ( Context & context ) override { \
Expand All @@ -1008,6 +1011,7 @@ __forceinline void profileNode ( SimNode * node ) {
// FUNCTION CALL
struct SimNode_CallBase : SimNode {
SimNode_CallBase ( const LineInfo & at ) : SimNode(at) {}
virtual bool rtti_node_isCallBase() const override { return true; }
virtual SimNode * copyNode ( Context & context, NodeAllocator * code ) override;
void visitCall ( SimVisitor & vis );
__forceinline void evalArgs ( Context & context, vec4f * argValues ) {
Expand Down
104 changes: 53 additions & 51 deletions src/ast/ast_simulate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,23 +114,33 @@ namespace das

// common for move and copy

SimNode_CallBase * getCallBase ( SimNode * node ) {
if ( node->rtti_node_isKeepAlive() ) {
SimNode_KeepAlive * ka = static_cast<SimNode_KeepAlive *>(node);
node = ka->value;
}
DAS_ASSERTF(node->rtti_node_isCallBase(),"we are calling getCallBase on a node, which is not a call base node."
"we should not be here, script compiler should have caught this during compilation.");
return static_cast<SimNode_CallBase *>(node);
}

SimNode * makeLocalCMResMove (const LineInfo & at, Context & context, uint32_t offset, const ExpressionPtr & rE ) {
const auto & rightType = *rE->type;
// now, call with CMRES
if ( rE->rtti_isCall() ) {
auto cll = static_pointer_cast<ExprCall>(rE);
if ( cll->allowCmresSkip() ) {
SimNode_CallBase * right = (SimNode_CallBase *) rE->simulate(context);
right->cmresEval = context.code->makeNode<SimNode_GetCMResOfs>(rE->at, offset);
auto right = rE->simulate(context);
getCallBase(right)->cmresEval = context.code->makeNode<SimNode_GetCMResOfs>(rE->at, offset);
return right;
}
}
// now, invoke with CMRES
if ( rE->rtti_isInvoke() ) {
auto cll = static_pointer_cast<ExprInvoke>(rE);
if ( cll->allowCmresSkip() ) {
SimNode_CallBase * right = (SimNode_CallBase *) rE->simulate(context);
right->cmresEval = context.code->makeNode<SimNode_GetCMResOfs>(rE->at, offset);
auto * right = rE->simulate(context);
getCallBase(right)->cmresEval = context.code->makeNode<SimNode_GetCMResOfs>(rE->at, offset);
return right;
}
}
Expand All @@ -155,18 +165,16 @@ namespace das
if ( rE->rtti_isCall() ) {
auto cll = static_pointer_cast<ExprCall>(rE);
if ( cll->allowCmresSkip() ) {
SimNode_CallBase * rightC = (SimNode_CallBase *) right;
rightC->cmresEval = context.code->makeNode<SimNode_GetCMResOfs>(rE->at, offset);
return rightC;
getCallBase(right)->cmresEval = context.code->makeNode<SimNode_GetCMResOfs>(rE->at, offset);
return right;
}
}
// now, invoke with CMRES
if ( rE->rtti_isInvoke() ) {
auto cll = static_pointer_cast<ExprInvoke>(rE);
if ( cll->allowCmresSkip() ) {
SimNode_CallBase * rightC = (SimNode_CallBase *) right;
rightC->cmresEval = context.code->makeNode<SimNode_GetCMResOfs>(rE->at, offset);
return rightC;
getCallBase(right)->cmresEval = context.code->makeNode<SimNode_GetCMResOfs>(rE->at, offset);
return right;
}
}
// wo standard path
Expand All @@ -192,17 +200,17 @@ namespace das
if ( rE->rtti_isCall() ) {
auto cll = static_pointer_cast<ExprCall>(rE);
if ( cll->allowCmresSkip() ) {
SimNode_CallBase * right = (SimNode_CallBase *) rE->simulate(context);
right->cmresEval = context.code->makeNode<SimNode_GetLocalRefOff>(rE->at, stackTop, offset);
auto right = rE->simulate(context);
getCallBase(right)->cmresEval = context.code->makeNode<SimNode_GetLocalRefOff>(rE->at, stackTop, offset);
return right;
}
}
// now, invoke with CMRES
if ( rE->rtti_isInvoke() ) {
auto cll = static_pointer_cast<ExprInvoke>(rE);
if ( cll->allowCmresSkip() ) {
SimNode_CallBase * right = (SimNode_CallBase *) rE->simulate(context);
right->cmresEval = context.code->makeNode<SimNode_GetLocalRefOff>(rE->at, stackTop, offset);
auto right = rE->simulate(context);
getCallBase(right)->cmresEval = context.code->makeNode<SimNode_GetLocalRefOff>(rE->at, stackTop, offset);
return right;
}
}
Expand All @@ -227,18 +235,16 @@ namespace das
if ( rE->rtti_isCall() ) {
auto cll = static_pointer_cast<ExprCall>(rE);
if ( cll->allowCmresSkip() ) {
SimNode_CallBase * rightC = (SimNode_CallBase *) right;
rightC->cmresEval = context.code->makeNode<SimNode_GetLocalRefOff>(rE->at, stackTop, offset);
return rightC;
getCallBase(right)->cmresEval = context.code->makeNode<SimNode_GetLocalRefOff>(rE->at, stackTop, offset);
return right;
}
}
// now, invoke with CMRES
if ( rE->rtti_isInvoke() ) {
auto cll = static_pointer_cast<ExprInvoke>(rE);
if ( cll->allowCmresSkip() ) {
SimNode_CallBase * rightC = (SimNode_CallBase *) right;
rightC->cmresEval = context.code->makeNode<SimNode_GetLocalRefOff>(rE->at, stackTop, offset);
return rightC;
getCallBase(right)->cmresEval = context.code->makeNode<SimNode_GetLocalRefOff>(rE->at, stackTop, offset);
return right;
}
}
// wo standard path
Expand All @@ -264,17 +270,17 @@ namespace das
if ( rE->rtti_isCall() ) {
auto cll = static_pointer_cast<ExprCall>(rE);
if ( cll->allowCmresSkip() ) {
SimNode_CallBase * right = (SimNode_CallBase *) rE->simulate(context);
right->cmresEval = context.code->makeNode<SimNode_GetLocal>(rE->at, stackTop);
auto right = rE->simulate(context);
getCallBase(right)->cmresEval = context.code->makeNode<SimNode_GetLocal>(rE->at, stackTop);
return right;
}
}
// now, invoke with CMRES
if ( rE->rtti_isInvoke() ) {
auto cll = static_pointer_cast<ExprInvoke>(rE);
if ( cll->allowCmresSkip() ) {
SimNode_CallBase * right = (SimNode_CallBase *) rE->simulate(context);
right->cmresEval = context.code->makeNode<SimNode_GetLocal>(rE->at, stackTop);
auto right = rE->simulate(context);
getCallBase(right)->cmresEval = context.code->makeNode<SimNode_GetLocal>(rE->at, stackTop);
return right;
}
}
Expand All @@ -298,17 +304,17 @@ namespace das
if ( rE->rtti_isCall() ) {
auto cll = static_pointer_cast<ExprCall>(rE);
if ( cll->allowCmresSkip() ) {
SimNode_CallBase * right = (SimNode_CallBase *) rE->simulate(context);
right->cmresEval = context.code->makeNode<SimNode_GetLocal>(rE->at, stackTop);
auto right = rE->simulate(context);
getCallBase(right)->cmresEval = context.code->makeNode<SimNode_GetLocal>(rE->at, stackTop);
return right;
}
}
// now, invoke with CMRES
if ( rE->rtti_isInvoke() ) {
auto cll = static_pointer_cast<ExprInvoke>(rE);
if ( cll->allowCmresSkip() ) {
SimNode_CallBase * right = (SimNode_CallBase *) rE->simulate(context);
right->cmresEval = context.code->makeNode<SimNode_GetLocal>(rE->at, stackTop);
auto right = rE->simulate(context);
getCallBase(right)->cmresEval = context.code->makeNode<SimNode_GetLocal>(rE->at, stackTop);
return right;
}
}
Expand Down Expand Up @@ -340,17 +346,17 @@ namespace das
if ( rE->rtti_isCall() ) {
auto cll = static_pointer_cast<ExprCall>(rE);
if ( cll->allowCmresSkip() ) {
SimNode_CallBase * right = (SimNode_CallBase *) rE->simulate(context);
right->cmresEval = lE->simulate(context);
auto right = rE->simulate(context);
getCallBase(right)->cmresEval = lE->simulate(context);
return right;
}
}
// now, invoke with CMRES
if ( rE->rtti_isInvoke() ) {
auto cll = static_pointer_cast<ExprInvoke>(rE);
if ( cll->allowCmresSkip() ) {
SimNode_CallBase * right = (SimNode_CallBase *) rE->simulate(context);
right->cmresEval = lE->simulate(context);
auto right = rE->simulate(context);
getCallBase(right)->cmresEval = lE->simulate(context);
return right;
}
}
Expand Down Expand Up @@ -378,17 +384,17 @@ namespace das
if ( rE->rtti_isCall() ) {
auto cll = static_pointer_cast<ExprCall>(rE);
if ( cll->allowCmresSkip() ) {
SimNode_CallBase * right = (SimNode_CallBase *) rE->simulate(context);
right->cmresEval = lE->simulate(context);
auto right = rE->simulate(context);
getCallBase(right)->cmresEval = lE->simulate(context);
return right;
}
}
// now, invoke with CMRES
if ( rE->rtti_isInvoke() ) {
auto cll = static_pointer_cast<ExprInvoke>(rE);
if ( cll->allowCmresSkip() ) {
SimNode_CallBase * right = (SimNode_CallBase *) rE->simulate(context);
right->cmresEval = lE->simulate(context);
auto right = rE->simulate(context);
getCallBase(right)->cmresEval = lE->simulate(context);
return right;
}
}
Expand All @@ -413,14 +419,12 @@ namespace das
}

SimNode * Function::makeSimNode ( Context & context, const vector<ExpressionPtr> & ) {
{
if ( copyOnReturn || moveOnReturn ) {
return context.code->makeNodeUnrollAny<SimNode_CallAndCopyOrMove>(int(arguments.size()), at);
} else if ( fastCall ) {
return context.code->makeNodeUnrollAny<SimNode_FastCall>(int(arguments.size()), at);
} else {
return context.code->makeNodeUnrollAny<SimNode_Call>(int(arguments.size()), at);
}
if ( copyOnReturn || moveOnReturn ) {
return context.code->makeNodeUnrollAny<SimNode_CallAndCopyOrMove>(int(arguments.size()), at);
} else if ( fastCall ) {
return context.code->makeNodeUnrollAny<SimNode_FastCall>(int(arguments.size()), at);
} else {
return context.code->makeNodeUnrollAny<SimNode_Call>(int(arguments.size()), at);
}
}

Expand Down Expand Up @@ -2465,8 +2469,7 @@ namespace das
} else if ( returnInBlock ) {
if ( returnCallCMRES ) {
DAS_VERIFYF(simSubE, "internal error. can't be zero");
SimNode_CallBase * simRet = (SimNode_CallBase *) simSubE;
simRet->cmresEval = context.code->makeNode<SimNode_GetBlockCMResOfs>(at,0,stackTop);
getCallBase(simSubE)->cmresEval = context.code->makeNode<SimNode_GetBlockCMResOfs>(at,0,stackTop);
return context.code->makeNode<SimNode_Return>(at, simSubE);
} else if ( takeOverRightStack ) {
DAS_VERIFYF(simSubE, "internal error. can't be zero");
Expand All @@ -2484,8 +2487,7 @@ namespace das
} else if ( subexpr ) {
if ( returnCallCMRES ) {
DAS_VERIFYF(simSubE, "internal error. can't be zero");
SimNode_CallBase * simRet = (SimNode_CallBase *) simSubE;
simRet->cmresEval = context.code->makeNode<SimNode_GetCMResOfs>(at,0);
getCallBase(simSubE)->cmresEval = context.code->makeNode<SimNode_GetCMResOfs>(at,0);
return context.code->makeNode<SimNode_Return>(at, simSubE);
} else if ( returnCMRES ) {
// ReturnLocalCMRes
Expand Down Expand Up @@ -2962,13 +2964,13 @@ namespace das
varExpr->variable = var;
varExpr->local = local;
varExpr->type = make_smart<TypeDecl>(*var->type);
SimNode_CallBase * retN = nullptr; // it has to be CALL with CMRES
SimNode * retN = nullptr; // it has to be CALL with CMRES
const auto & rE = var->init;
if ( rE->rtti_isCall() ) {
auto cll = static_pointer_cast<ExprCall>(rE);
if ( cll->allowCmresSkip() ) {
retN = (SimNode_CallBase *) rE->simulate(context);
retN->cmresEval = varExpr->simulate(context);
retN = rE->simulate(context);
getCallBase(retN)->cmresEval = varExpr->simulate(context);
}
}
if ( !retN ) {
Expand Down
Loading