Skip to content

Commit

Permalink
Cache now working, but speeds things down :(
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@996 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Peter Aronsson committed Jul 28, 2003
1 parent 39059ef commit c82491e
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 47 deletions.
2 changes: 1 addition & 1 deletion modeq/Makefile.in
Expand Up @@ -16,7 +16,7 @@ SHELL = /bin/sh
CC = gcc
CFLAGS =
RMLHOME = @rmlhome@
RML = @rmlc_bin@ -g
RML = @rmlc_bin@ -Wc,-O3
RMLINC = -I$(RMLHOME)/include/plain
MYRML = ./myrmlc

Expand Down
2 changes: 1 addition & 1 deletion modeq/absyn_builder/Makefile.in
Expand Up @@ -16,7 +16,7 @@ PARSE_LIBP = -L$(PARSE_HOME)/src
INCP = $(ANTLR_INCP) $(PARSE_INCP) $(RML_INCP)
LIBP = $(ANTLR_LIBP) $(PARSE_LIBP)

CFLAGS = $(INCP) -g -Wall
CFLAGS = $(INCP) -O3 -Wall
CXXFLAGS = $(CFLAGS)
LINKFLAGS = $(LIBP)

Expand Down
4 changes: 2 additions & 2 deletions modeq/inst.rml
Expand Up @@ -435,13 +435,13 @@ relation inst_class_in: (Env, Mod, Prefix, Connect.Sets, ClassInf.State,
inst_classdef(env,mods,pre,csets,ci_state,d,r,prot,inst_dims
,impl,packimpl)
=> (l,env', csets', ci_state', tys) &
clock() => t2 &
(* clock() => t2 &
real_sub(t2,t1) => time &
real_gt(time,1.5) => b &
real_string time =>timestr &
Util.string_append_list(["inst_class_in ", n, ": ", timestr, "\n" ]) => s1 &
Dump.select_string(b,s1,"") => str &
print str &
print str &*)
Prefix.print_prefix_str pre => prestr &
string_append(prestr, " : ") => prestr' &
string_append(prestr', n) => prestr'' &
Expand Down
45 changes: 25 additions & 20 deletions modeq/lookup.rml
Expand Up @@ -155,18 +155,16 @@ end

relation lookup_class: (Env.Env, Absyn.Path, bool) => (SCode.Class, Env.Env) =


(*
rule (* Try to find the class in the cache *)
(* rule (* Try to find the class in the cache *)
Env.get_env_path(env) => envpath &
Absyn.opt_path_string(envpath) => envpathstr &
Absyn.path_string(path) => pathstr &
Cache.get_class(envpathstr,pathstr) => (c,env) &
Cache.get_class(envpathstr,pathstr) => (c,env) (*&
print "Got cached class: " & print pathstr &
print "\n"
print "\n"*)
----------------------------------------
lookup_class(env,path,_) => (c,env)
*)
lookup_class(env,path,_) => (c,env)*)


rule Debug.fprint ("lotr","TRIES lookup_class(1)\n") &
Debug.fcall ("lotr",Dump.print_path,path) &
Expand All @@ -180,8 +178,8 @@ relation lookup_class: (Env.Env, Absyn.Path, bool) => (SCode.Class, Env.Env) =
Print.print_buf "in envpath:" &
Env.print_env_path env' &
Print.print_buf "\n:" *)
(*
& Env.get_env_path(env') => envpath &

(* & Env.get_env_path(env') => envpath &
Absyn.opt_path_string(envpath) => envpathstr &
Absyn.path_string(path) => pathstr &
Cache.add_class(c,env',envpathstr,pathstr) => ()*)
Expand All @@ -193,8 +191,8 @@ relation lookup_class: (Env.Env, Absyn.Path, bool) => (SCode.Class, Env.Env) =
=> (c, env') &
Debug.fprint ("lotr","IN lookup_class(2)\n") &
Debug.fcall ("lotr",Dump.print_path,path) &
Debug.fprint ("lotr",")\n") (*&
Env.get_env_path(env') => envpath &
Debug.fprint ("lotr",")\n")
(* & Env.get_env_path(env') => envpath &
Absyn.opt_path_string(envpath) => envpathstr &
Absyn.path_string(path) => pathstr &
Cache.add_class(c,env',envpathstr,pathstr) => ()*)
Expand All @@ -206,12 +204,11 @@ relation lookup_class: (Env.Env, Absyn.Path, bool) => (SCode.Class, Env.Env) =
=> (c, env') &
Debug.fprint ("lotr","IN lookup_class(3)\n") &
Debug.fcall ("lotr",Dump.print_path,path) &
Debug.fprint ("lotr",")\n") (*&
Env.get_env_path(env') => envpath &
Debug.fprint ("lotr",")\n")
(* & Env.get_env_path(env') => envpath &
Absyn.opt_path_string(envpath) => envpathstr &
Absyn.path_string(path) => pathstr &
Cache.add_class(c,env',envpathstr,pathstr) => ()
*)
Cache.add_class(c,env',envpathstr,pathstr) => ()*)
----------------------------------------------------------
lookup_class(env, path, _) => (c, env')

Expand All @@ -228,11 +225,11 @@ relation lookup_class: (Env.Env, Absyn.Path, bool) => (SCode.Class, Env.Env) =

Debug.fprint ("lotr","IN lookup_class(4)\n") &
Debug.fcall ("lotr",Dump.print_path,path) &
Debug.fprint ("lotr",")\n") (*&
Env.get_env_path(env') => envpath &
Debug.fprint ("lotr",")\n")
(* & Env.get_env_path(env') => envpath &
Absyn.opt_path_string(envpath) => envpathstr &
Absyn.path_string(path) => pathstr &
Cache.add_class(c,env',envpathstr,pathstr) => ()*)
Cache.add_class(c,env',envpathstr,pathstr) => () *)
--------------------------------------
lookup_class(env, p as Absyn.QUALIFIED(pack,path),msgflag)
=> (c', env''')
Expand All @@ -257,8 +254,8 @@ rule Debug.fprint ("lotr","TRIES lookup_class(5)\n") &

Debug.fprint ("lotr","IN lookup_class(5)\n") &
Debug.fcall ("lotr",Dump.print_path,path) &
Debug.fprint ("lotr",")\n") (*&
Env.get_env_path(env5) => envpath &
Debug.fprint ("lotr",")\n")
(* & Env.get_env_path(env5) => envpath &
Absyn.opt_path_string(envpath) => envpathstr &
Absyn.path_string(path) => pathstr &
Cache.add_class(c',env5,envpathstr,pathstr) => ()*)
Expand Down Expand Up @@ -975,6 +972,14 @@ end
**)
relation lookup_class_in_class: (Env.Env, SCode.Class, Absyn.Path, bool)
=> (SCode.Class, Env.Env) =

(* Look in cache *)
(*rule Env.get_env_path(env) => envpath &
Absyn.opt_path_string(envpath) => envpathstr &
Absyn.path_string(path) => pathstr &
Cache.get_class(envpathstr,pathstr) => (c,env)
----------------------------------------------
lookup_class_in_class (env, _,path,_) => (c, env)*)

rule lookup_class_in_env(env,classname,true) => (c as SCode.CLASS(_,_,true,_,_) ,env')
(* true means here encapsulated *)
Expand Down
45 changes: 22 additions & 23 deletions modeq/runtime/cacheimpl.cpp
Expand Up @@ -28,23 +28,10 @@ extern "C"
for (it = classCache->begin(); it != classCache->end(); ++it) {
for (it2 = it->second->begin(); it2 != it->second->end(); ++it2) {
size+=2;
refSet.insert((int*)it2->second->cl); // A set, because references should only be given once
refSet.insert((int*)it2->second->env); // to the callback function
rml_user_gc_callback(state,(void**)&it2->second->cl,1);
rml_user_gc_callback(state,(void**)&it2->second->env,1);
}
}
set<int*>::iterator it3;
int refSize=0;
int** refVector = new int*[refSet.size()];
for (it3=refSet.begin(); it3 != refSet.end(); it3++) {
if (!RML_HDRISFORWARD(RML_GETHDR(*it3))) {
refVector[refSize++]=(int*)RML_UNTAGPTR((void*)*it3); // references should be untagged when calling gc.
} else {
//cerr << "Ignoring HDRFORWARD root" << endl;
}
}
// std::cerr << "making callback" << endl;
rml_user_gc_callback(state,(void**)refVector,refSet.size());
delete refVector;
}
// std::cerr << "leaving user_gc" << endl;
}
Expand All @@ -68,16 +55,22 @@ extern "C"
cerr << "Cache is not initialized\n";
RML_TAILCALLK(rmlFC);
}
if (classCache->find(className) == classCache->end()) {
Cache::iterator it = classCache->find(className);
if (it == classCache->end()) {
//cerr << "Did not find " << className << "hash table.\n";
(*classCache)[className] = new CacheItem();
}
ClassItem *newItem = new ClassItem;
newItem->cl = cl;
newItem->env = env;
//cerr << "Adding refs: " << cl << " " << env << endl;
(*(*classCache)[className])[scope] = newItem;
// cerr << "Added class " << className << " to cache.\n" << endl ;
else if (it->second->size() == 1 && it->second->begin()->second->cl != cl)
// Only add class if different.
{
cerr << "Different, adding second class." << endl;
ClassItem *newItem = new ClassItem;
newItem->cl = cl;
newItem->env = env;
//cerr << "Adding refs: " << cl << " " << env << endl;
(*(*classCache)[className])[scope] = newItem;
// cerr << "Added class " << className << " to cache.\n" << endl ;
}
RML_TAILCALLK(rmlSC);
}
RML_END_LABEL
Expand Down Expand Up @@ -108,6 +101,12 @@ extern "C"
//cerr << "class " << className << " not found in cache\n";
RML_TAILCALLK(rmlFC);
} else {
if (it->second->size() == 1) {
ClassItem *item=it2->second;
rmlA0=item->cl;
rmlA1=item->env;
RML_TAILCALLK(rmlSC);
}
it2=(it->second->find(scope));
if (it2 == it->second->end()) {
RML_TAILCALLK(rmlFC);
Expand All @@ -116,7 +115,7 @@ extern "C"
ClassItem *item=it2->second;
rmlA0=item->cl;
rmlA1=item->env;
cerr << "Found class " << className << " in cache.\n";
// cerr << "Found class " << className << " in cache.\n";
RML_TAILCALLK(rmlSC);
}
}
Expand Down

0 comments on commit c82491e

Please sign in to comment.