summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIulian Dragos <jaguarul@gmail.com>2004-06-22 16:17:52 +0000
committerIulian Dragos <jaguarul@gmail.com>2004-06-22 16:17:52 +0000
commit12f31726de3c6a2fcf9af225a959ee0e3d9d70ab (patch)
treeb267bc0169368867c8b8bf347e69d98d19fe57ee
parentbf6a12295f396caa6ee8ff7d0e5f015c92d14b79 (diff)
downloadscala-12f31726de3c6a2fcf9af225a959ee0e3d9d70ab.tar.gz
scala-12f31726de3c6a2fcf9af225a959ee0e3d9d70ab.tar.bz2
scala-12f31726de3c6a2fcf9af225a959ee0e3d9d70ab.zip
fix in call graph, to take into account calls t...
fix in call graph, to take into account calls to generic methods
-rw-r--r--sources/scala/tools/scalac/wholeprog/Inline.scala40
-rw-r--r--sources/scala/tools/scalac/wholeprog/MonomorphicCS.scala37
2 files changed, 64 insertions, 13 deletions
diff --git a/sources/scala/tools/scalac/wholeprog/Inline.scala b/sources/scala/tools/scalac/wholeprog/Inline.scala
index b21617d069..05b8bf69ff 100644
--- a/sources/scala/tools/scalac/wholeprog/Inline.scala
+++ b/sources/scala/tools/scalac/wholeprog/Inline.scala
@@ -28,17 +28,35 @@ class InlineMethods(sites: List[Tuple3[GNode[Symbol, MethodNode], GNode[Symbol,
var inlines: int = 0;
var inlinedThis: Symbol = null;
+ var inMain = false;
override def transform(tree: Tree): Tree = {
tree match {
case Tree$Apply(fun, args) => {
- val s = sites.find( tuple => tree == tuple._3.t);
+// if (inMain)
+// Console.println("main " + fun);
+ val s = sites.find( tuple => tree eq tuple._3.t);
s match {
case Some(Tuple3(cl, ce, s)) => expand(tree, cl, ce)
case _ => super.transform(tree);
}
}
+ case Tree$ClassDef(_, name, _, _, _, _) => {
+ //Console.println("Enter class " + name.toString());
+ super.transform(tree);
+ }
+
+ case Tree$DefDef(_, name, _, _, _, _) => {
+ //Console.println("Enter method " + name.toString());
+ if (name.toString().equals("main"))
+ inMain = true;
+ else
+ inMain = false;
+ super.transform(tree);
+ }
+
+
case _ => super.transform(tree);
}
}
@@ -56,7 +74,7 @@ class InlineMethods(sites: List[Tuple3[GNode[Symbol, MethodNode], GNode[Symbol,
assert(args.length == vparams(0).length,
"Call site has different nr. of arguments than def " + fun.symbol());
- res(0) = makeThisDef(fun);
+ res(0) = makeThisDef(fun); // was: makeThisDef(fun);
var i: int = 1;
while (i < res.length) {
// duplicate the formal parameter of the method and create a symbol for this def
@@ -76,7 +94,8 @@ class InlineMethods(sites: List[Tuple3[GNode[Symbol, MethodNode], GNode[Symbol,
subst += arg.symbol() -> sym;
// set the initial value to the actual parameter
- arg.rhs = args(i - 1).duplicate();
+// arg.rhs = args(i - 1).duplicate();
+ arg.rhs = (new InlineMethods(sites, global)).transform(args(i-1));
arg.setSymbol(sym);
arg.rhs.setType(sym.getType());
@@ -90,22 +109,25 @@ class InlineMethods(sites: List[Tuple3[GNode[Symbol, MethodNode], GNode[Symbol,
def makeThisDef(fun: Tree): Tree = {
val Tree$Select(qualifier, selector) = fun;
-// val tpe = make.TypeTerm(fun.pos);
val sym = caller.info.method.newVariable(fun.pos, 0, Name.fromString("inthis"));
-// sym.setType(qualifier.getType().singleDeref()); // it was .singleDeref() but unneded?
+
sym.setType(callee.info.classz.getType());
Logger.log("[inthis] Set type to " + sym.getType());
-// val t = make.ValDef(fun.pos, 0, Name.fromString("inthis"), tpe, qualifier.duplicate());
- val t = gen.ValDef(sym, qualifier.duplicate());
+ val t = gen.ValDef(sym, (new InlineMethods(sites, global)).transform(qualifier)); // was: qualifier.duplicate());
-// tpe.setType(qualifier.getType().deconst());
-// t.setSymbol(sym);
inlinedThis = sym;
t
}
+ Logger.log("Trying to inline at " +
+ caller.info.classz.name + "." +
+ caller.info.method.name + " [" + Position.toString(tree.pos) + "] with " +
+ callee.info.classz.name + "." +
+ callee.info.method.name);
+
+
val locals = createLocals(tree, callee.info.code);
val updater = new UpdateAccesses(subst, caller.info.method);
val newRhs = updater.transform(rhs.duplicate());
diff --git a/sources/scala/tools/scalac/wholeprog/MonomorphicCS.scala b/sources/scala/tools/scalac/wholeprog/MonomorphicCS.scala
index d4b40c884b..f803d85642 100644
--- a/sources/scala/tools/scalac/wholeprog/MonomorphicCS.scala
+++ b/sources/scala/tools/scalac/wholeprog/MonomorphicCS.scala
@@ -98,6 +98,10 @@ class MonomorphicCallSites(globall: scalac_Global, application: Set[Symbol]) {
if (canInline(caller, callee))
inlinable = new Tuple3(caller, callee, e.info.site) :: inlinable;
+ else
+ Logger.log("[monomorphiccs] skipped monomorphic call site " +
+ SymbolPrinter.fullName(caller.info.method) + " -> " +
+ SymbolPrinter.fullName(callee.info.method));
}
def canInline(caller: CallGraphNode, callee: CallGraphNode): boolean =
@@ -131,12 +135,15 @@ class MonomorphicCallSites(globall: scalac_Global, application: Set[Symbol]) {
if (mcs.length == 1) {
inlineCallSite(mcs.head);
-// Console.println("Monomorphic call-site: " + mcs.head.from + " " + mcs.head.to);
+// Console.println("Monomorphic call-site: " +
+// SymbolPrinter.fullName(mcs.head.from) + " " +
+// SymbolPrinter.fullName(mcs.head.to));
logStatistics(mcs.head);
nr = nr + 1;
}
});
});
+
Console.println("[end Monomorphic call site identification]");
Console.println("We identified " + nr + " monomorphic call-sites. ("
@@ -146,6 +153,8 @@ class MonomorphicCallSites(globall: scalac_Global, application: Set[Symbol]) {
if (global.args.Xinline.value) {
Console.println("[start inlining]");
+// inlinable.foreach( (t) => Console.println("inline callsite " + t._3.t));
+
doInline(inlinable);
Console.println("[end inlining]");
}
@@ -189,7 +198,10 @@ class MonomorphicCallSites(globall: scalac_Global, application: Set[Symbol]) {
// test for instantiation
targets.foreach( (t) => if ( !isInstatiated(callGraph.getNode(t.to).info.classz) ) {
callGraph.removeEdge(t);
- Logger.log("[RTA] Removed edge to " + SymbolPrinter.fullName(t.to));
+ Logger.log("[RTA] Removed edge " +
+ SymbolPrinter.fullName(t.from) + " -> " +
+ SymbolPrinter.fullName(t.to));
+
});
}
});
@@ -256,6 +268,7 @@ class MonomorphicCallSites(globall: scalac_Global, application: Set[Symbol]) {
val methSym = tree.symbol();
cg.addNode(new CallGraphNode(methSym, new MethodNode(methSym, methSym.enclClass(), tree)));
+ Logger.log("[callgraph] Created node " + SymbolPrinter.fullName(methSym));
}
case _ => ;
@@ -292,10 +305,26 @@ class MonomorphicCallSites(globall: scalac_Global, application: Set[Symbol]) {
case Tree$Apply(fun, args) => {
if (enclMethod != null) {
- val targetMeth = fun.symbol();
+
+ var targetMeth = fun.symbol();
+ var callsiteTree = tree;
+
+ if (targetMeth == null)
+ fun match {
+ case Tree$TypeApply(innerFun, args) => {
+ targetMeth = innerFun.symbol();
+ callsiteTree = innerFun;
+ //Console.println("Hopla, a type apply for " + innerFun);
+ }
+ case _ => ;
+ }
+
+ if (targetMeth == null)
+ Console.println("Null symbol for method " + tree);
+
//assert(targetMeth != null, "Null target method for " + tree);
if (targetMeth != null)
- createEdges(targetMeth, tree);
+ createEdges(targetMeth, callsiteTree);
// else
// Console.println("Null symbol: " + tree);
// fun match {