fix global variable on compiler (move it to LOCALS).

This commit is contained in:
Vítor Santos Costa 2012-02-06 15:11:50 +00:00
parent 597a63cc12
commit c98e42f545
10 changed files with 1541 additions and 1536 deletions

View File

@ -2129,13 +2129,6 @@ c_head(Term t, compiler_struct *cglobs)
c_args(t, 0, cglobs); c_args(t, 0, cglobs);
} }
/* number of permanent variables in the clause */
#ifdef BEAM
int nperm;
#else
static int nperm;
#endif
inline static int inline static int
usesvar(compiler_vm_op ic) usesvar(compiler_vm_op ic)
@ -2233,7 +2226,7 @@ AssignPerm(PInstr *pc, compiler_struct *cglobs)
#ifdef BEAM #ifdef BEAM
if (EAM) { if (EAM) {
if (v->NoOfVE == Unassigned || v->KindOfVE!=PermVar) { if (v->NoOfVE == Unassigned || v->KindOfVE!=PermVar) {
v->NoOfVE = PermVar | (nperm++); v->NoOfVE = PermVar | (LOCAL_nperm++);
v->KindOfVE = PermVar; v->KindOfVE = PermVar;
v->FlagsOfVE |= PermFlag; v->FlagsOfVE |= PermFlag;
} }
@ -2245,7 +2238,7 @@ AssignPerm(PInstr *pc, compiler_struct *cglobs)
* * || (v->FlagsOfVE & NonVoid && !(v->FlagsOfVE & * * || (v->FlagsOfVE & NonVoid && !(v->FlagsOfVE &
* * OnHeadFlag)) * * OnHeadFlag))
*/ ) { */ ) {
v->NoOfVE = PermVar | (nperm++); v->NoOfVE = PermVar | (LOCAL_nperm++);
v->KindOfVE = PermVar; v->KindOfVE = PermVar;
v->FlagsOfVE |= PermFlag; v->FlagsOfVE |= PermFlag;
} else { } else {
@ -2253,23 +2246,23 @@ AssignPerm(PInstr *pc, compiler_struct *cglobs)
} }
} }
} else if (pc->op == empty_call_op) { } else if (pc->op == empty_call_op) {
pc->rnd2 = nperm; pc->rnd2 = LOCAL_nperm;
} else if (pc->op == call_op || pc->op == either_op || pc->op == orelse_op || pc->op == push_or_op) { } else if (pc->op == call_op || pc->op == either_op || pc->op == orelse_op || pc->op == push_or_op) {
#ifdef LOCALISE_VOIDS #ifdef LOCALISE_VOIDS
EnvTmps = (EnvTmp *)(pc->ops.opseqt[1]); EnvTmps = (EnvTmp *)(pc->ops.opseqt[1]);
while (EnvTmps) { while (EnvTmps) {
Ventry *v = EnvTmps->Var; Ventry *v = EnvTmps->Var;
v->NoOfVE = PermVar | (nperm++); v->NoOfVE = PermVar | (LOCAL_nperm++);
v->KindOfVE = PermVar; v->KindOfVE = PermVar;
v->FlagsOfVE |= (PermFlag|SafeVar); v->FlagsOfVE |= (PermFlag|SafeVar);
EnvTmps = EnvTmps->Next; EnvTmps = EnvTmps->Next;
} }
#endif #endif
pc->rnd2 = nperm; pc->rnd2 = LOCAL_nperm;
} else if (pc->op == cut_op || } else if (pc->op == cut_op ||
pc->op == cutexit_op || pc->op == cutexit_op ||
pc->op == commit_b_op) { pc->op == commit_b_op) {
pc->rnd2 = nperm; pc->rnd2 = LOCAL_nperm;
} }
opc = pc; opc = pc;
pc = npc; pc = npc;
@ -2417,9 +2410,9 @@ CheckUnsafe(PInstr *pc, compiler_struct *cglobs)
int pending = 0; int pending = 0;
/* say that all variables are yet to initialise */ /* say that all variables are yet to initialise */
CELL *vstat = init_bvarray(nperm, cglobs); CELL *vstat = init_bvarray(LOCAL_nperm, cglobs);
UnsafeEntry *UnsafeStack = UnsafeEntry *UnsafeStack =
(UnsafeEntry *) Yap_AllocCMem(nperm * sizeof(UnsafeEntry), &cglobs->cint); (UnsafeEntry *) Yap_AllocCMem(LOCAL_nperm * sizeof(UnsafeEntry), &cglobs->cint);
/* keep a copy of previous cglobs->cint.cpc and CodeStart */ /* keep a copy of previous cglobs->cint.cpc and CodeStart */
PInstr *opc = cglobs->cint.cpc; PInstr *opc = cglobs->cint.cpc;
PInstr *OldCodeStart = cglobs->cint.CodeStart; PInstr *OldCodeStart = cglobs->cint.CodeStart;
@ -2476,7 +2469,7 @@ CheckUnsafe(PInstr *pc, compiler_struct *cglobs)
add_bvarray_op(pc, vstat, pc->rnd2, cglobs); add_bvarray_op(pc, vstat, pc->rnd2, cglobs);
break; break;
case pushpop_or_op: case pushpop_or_op:
reset_bvmap(vstat, nperm, cglobs); reset_bvmap(vstat, LOCAL_nperm, cglobs);
goto reset_safe_map; goto reset_safe_map;
case orelse_op: case orelse_op:
Yap_emit(label_op, ++cglobs->labelno, Zero, &cglobs->cint); Yap_emit(label_op, ++cglobs->labelno, Zero, &cglobs->cint);
@ -2484,7 +2477,7 @@ CheckUnsafe(PInstr *pc, compiler_struct *cglobs)
add_bvarray_op(pc, vstat, pc->rnd2, cglobs); add_bvarray_op(pc, vstat, pc->rnd2, cglobs);
break; break;
case pop_or_op: case pop_or_op:
pop_bvmap(vstat, nperm, cglobs); pop_bvmap(vstat, LOCAL_nperm, cglobs);
goto reset_safe_map; goto reset_safe_map;
break; break;
case empty_call_op: case empty_call_op:
@ -2791,14 +2784,14 @@ c_layout(compiler_struct *cglobs)
#else #else
if (cglobs->needs_env) { if (cglobs->needs_env) {
#endif #endif
nperm = 0; LOCAL_nperm = 0;
AssignPerm(cglobs->cint.CodeStart, cglobs); AssignPerm(cglobs->cint.CodeStart, cglobs);
#ifdef DEBUG #ifdef DEBUG
cglobs->pbvars = 0; cglobs->pbvars = 0;
#endif #endif
CheckUnsafe(cglobs->cint.CodeStart, cglobs); CheckUnsafe(cglobs->cint.CodeStart, cglobs);
#ifdef DEBUG #ifdef DEBUG
if (cglobs->pbvars != nperm) { if (cglobs->pbvars != LOCAL_nperm) {
CACHE_REGS CACHE_REGS
LOCAL_Error_TYPE = INTERNAL_COMPILER_ERROR; LOCAL_Error_TYPE = INTERNAL_COMPILER_ERROR;
LOCAL_Error_Term = TermNil; LOCAL_Error_Term = TermNil;
@ -2867,7 +2860,7 @@ c_layout(compiler_struct *cglobs)
cglobs->cint.cpc->op = nop_op; cglobs->cint.cpc->op = nop_op;
else else
#endif /* TABLING */ #endif /* TABLING */
if (cglobs->goalno == 1 && !cglobs->or_found && nperm == 0) if (cglobs->goalno == 1 && !cglobs->or_found && LOCAL_nperm == 0)
cglobs->cint.cpc->op = nop_op; cglobs->cint.cpc->op = nop_op;
#ifdef TABLING #ifdef TABLING
UNLOCK(cglobs->cint.CurrentPred->PELock); UNLOCK(cglobs->cint.CurrentPred->PELock);

View File

@ -207,6 +207,9 @@
#define LOCAL_CMemFirstBlockSz LOCAL->CMemFirstBlockSz_ #define LOCAL_CMemFirstBlockSz LOCAL->CMemFirstBlockSz_
#define REMOTE_CMemFirstBlockSz(wid) REMOTE(wid)->CMemFirstBlockSz_ #define REMOTE_CMemFirstBlockSz(wid) REMOTE(wid)->CMemFirstBlockSz_
#define LOCAL_nperm LOCAL->nperm_
#define REMOTE_nperm(wid) REMOTE(wid)->nperm_
#define LOCAL_LabelFirstArray LOCAL->LabelFirstArray_ #define LOCAL_LabelFirstArray LOCAL->LabelFirstArray_
#define REMOTE_LabelFirstArray(wid) REMOTE(wid)->LabelFirstArray_ #define REMOTE_LabelFirstArray(wid) REMOTE(wid)->LabelFirstArray_
#define LOCAL_LabelFirstArraySz LOCAL->LabelFirstArraySz_ #define LOCAL_LabelFirstArraySz LOCAL->LabelFirstArraySz_

View File

@ -114,6 +114,8 @@ typedef struct worker_local {
struct mem_blk* CMemFirstBlock_; struct mem_blk* CMemFirstBlock_;
UInt CMemFirstBlockSz_; UInt CMemFirstBlockSz_;
int nperm_;
Int* LabelFirstArray_; Int* LabelFirstArray_;
UInt LabelFirstArraySz_; UInt LabelFirstArraySz_;

View File

@ -114,6 +114,8 @@ static void InitWorker(int wid) {
REMOTE_CMemFirstBlock(wid) = NULL; REMOTE_CMemFirstBlock(wid) = NULL;
REMOTE_CMemFirstBlockSz(wid) = 0L; REMOTE_CMemFirstBlockSz(wid) = 0L;
REMOTE_nperm(wid) = 0L;
REMOTE_LabelFirstArray(wid) = NULL; REMOTE_LabelFirstArray(wid) = NULL;
REMOTE_LabelFirstArraySz(wid) = 0L; REMOTE_LabelFirstArraySz(wid) = 0L;

View File

@ -118,6 +118,8 @@ static void RestoreWorker(int wid USES_REGS) {
#ifdef THREADS #ifdef THREADS
#endif /* THREADS */ #endif /* THREADS */

View File

@ -121,6 +121,9 @@ int AllowRestart =FALSE
struct mem_blk* CMemFirstBlock =NULL struct mem_blk* CMemFirstBlock =NULL
UInt CMemFirstBlockSz =0L UInt CMemFirstBlockSz =0L
// Variable used by the compiler to store number of permanent vars in a clause
int nperm =0L
// Thread Local Area for Labels // Thread Local Area for Labels
Int* LabelFirstArray =NULL Int* LabelFirstArray =NULL
UInt LabelFirstArraySz =0L UInt LabelFirstArraySz =0L