The essence of the pass is that it transforms

new java.lang.StringBuffer();

into

new gnu.gcj.runtime.StringBuffer();

My first attempt is to insert my pass immediatly after pass_build_ssa. I am trying to do the first part of transform with this code:

.
.
.
tree stmt = bsi_stmt (bsi);
tc = TREE_CODE(stmt);
if (MODIFY_EXPR == tc) {
  tree rhs = TREE_OPERAND(stmt, 1);
  tc = TREE_CODE(rhs);
  if (CALL_EXPR == tc) {
    tree fn = TREE_OPERAND(rhs, 0);
    tc = TREE_CODE(fn);
    if (ADDR_EXPR == tc) {
      tree ddd = TREE_OPERAND(fn, 0);
      tc = TREE_CODE(ddd);
      if (FUNCTION_DECL == tc) {
        tree id = DECL_NAME(ddd);
        tc = TREE_CODE(id);
        const char *name = IDENTIFIER_POINTER(id);
        if (name && 0 == strcmp(name, "_Jv_AllocObjectNoFinalizer")) {
          tree args = TREE_OPERAND(rhs, 1);
          tc = TREE_CODE(args);
          tree arg1 = TREE_VALUE(args);
          tc = TREE_CODE(arg1);
          tree tch = TREE_CHAIN(args);
          if (!tch && ADDR_EXPR == tc) {
            tree jj = TREE_OPERAND(arg1, 0);
            tc = TREE_CODE(jj);
            if (VAR_DECL == tc) {
              tree jjid = DECL_NAME(jj);
              const char *jjname = IDENTIFIER_POINTER(jjid);
              if (jjname && 0 == strcmp(jjname,
                                        "java.lang.StringBuffer.class")) {
                tree jjtype = TREE_TYPE(jj);
                tree id = get_identifier ("gnu.gcj.runtime.StringBuffer");
                tree cls = resolve_and_layout(id, NULL);
                tree overridden = build_class_ref(TREE_TYPE(cls));
                java_mark_addressable (TREE_OPERAND (overridden, 0));
                TREE_VALUE(args) = overridden;
              }
            }
          }
        }
      }
    }
  }
}
.
.
.

The tree dumps show that the call to _Jv_AllocObjectNoFinalizer is being transformed in the desired manner, but I am getting an ICE in compute_may_aliases(). Because the gnu.gcj.runtime.StringBuffer.class var has not been properly initialized (missing var_ann). This annotation is added by one of the passes previous to pass_build_ssa.

I am starting to think that even if I figure out how to add the proper annotations to my new var, that this will be very brittle and there will be an unending series of similar problems.

Q: Is this type of rewriting possible or advisable at this point in the compilation process?

I could move the transformation to a point much earlier (perhaps in the java front end) but that might make it much more difficult to analyze the control flow to see if the optimization is possible.

Opinions?

Thanks,

David Daney


Reply via email to