Example #1
0
 byte[] nullAdaptClass(final InputStream is, final String name) throws Exception {
   JavaClass jc = new ClassParser(is, name + ".class").parse();
   ClassGen cg = new ClassGen(jc);
   String cName = cg.getClassName();
   ConstantPoolGen cp = cg.getConstantPool();
   Method[] ms = cg.getMethods();
   for (int j = 0; j < ms.length; ++j) {
     MethodGen mg = new MethodGen(ms[j], cg.getClassName(), cp);
     boolean lv = ms[j].getLocalVariableTable() == null;
     boolean ln = ms[j].getLineNumberTable() == null;
     if (lv) {
       mg.removeLocalVariables();
     }
     if (ln) {
       mg.removeLineNumbers();
     }
     mg.stripAttributes(skipDebug);
     InstructionList il = mg.getInstructionList();
     if (il != null) {
       InstructionHandle ih = il.getStart();
       while (ih != null) {
         ih = ih.getNext();
       }
       if (compute) {
         mg.setMaxStack();
         mg.setMaxLocals();
       }
     }
     cg.replaceMethod(ms[j], mg.getMethod());
   }
   return cg.getJavaClass().getBytes();
 }
Example #2
0
  /** Instrument the specified method to replace mapped calls. */
  public void instrument_method(Method m, MethodGen mg) {

    // Loop through each instruction, making substitutions
    InstructionList il = mg.getInstructionList();
    for (InstructionHandle ih = il.getStart(); ih != null; ) {
      if (debug_instrument_inst.enabled()) {
        debug_instrument_inst.log("instrumenting instruction %s%n", ih);
        // ih.getInstruction().toString(pool.getConstantPool()));
      }
      InstructionList new_il = null;

      // Remember the next instruction to process
      InstructionHandle next_ih = ih.getNext();

      // Get the translation for this instruction (if any)
      new_il = xform_inst(mg, ih.getInstruction());
      if (debug_instrument_inst.enabled()) debug_instrument_inst.log("  new inst: %s%n", new_il);

      // If this instruction was modified, replace it with the new
      // instruction list. If this instruction was the target of any
      // jumps or line numbers , replace them with the first
      // instruction in the new list
      replace_instructions(il, ih, new_il);

      ih = next_ih;
    }
  }
Example #3
0
  CFG createCFG(String className) throws ClassNotFoundException {
    CFG cfg = new CFG();
    JavaClass jc = Repository.lookupClass(className);
    ClassGen cg = new ClassGen(jc);
    ConstantPoolGen cpg = cg.getConstantPool();
    for (Method m : cg.getMethods()) {
      MethodGen mg = new MethodGen(m, cg.getClassName(), cpg);
      InstructionList il = mg.getInstructionList();
      InstructionHandle[] handles = il.getInstructionHandles();
      int prev = 0;
      for (InstructionHandle ih : handles) {
        int position = ih.getPosition();
        cfg.addNode(position, m, jc);
        Instruction inst = ih.getInstruction();

        boolean br = inst.getName().contains("if") || inst.getName().contains("goto");
        boolean ret = inst.getName().contains("return");
        boolean stat = inst.getName().contains("invokestatic");
        int len = inst.getLength();

        if (stat) {
          int index = inst.toString(true).indexOf(" ");
          String name = inst.toString(true).substring(index + 1);
          int tar = Integer.valueOf(name);
          INVOKESTATIC inv = new INVOKESTATIC(tar);
          name = inv.getMethodName(cpg);

          Method m2 = null;
          Method[] tm = cg.getMethods();
          for (int i = 0; i < tm.length; i++) {
            if (tm[i].getName().equals(name)) {
              m2 = tm[i];
            }
          }
          cfg.addEdge(position, m, jc, 0, m2, jc);
          cfg.addEdge(-1, m2, jc, position + len, m, jc);
        }

        if (!ret && !stat) {
          cfg.addEdge(position, position + len, m, jc);
        }
        if (br) {
          cfg.addEdge(position, position + len, m, jc);
          IF_ICMPGE comp = new IF_ICMPGE(ih);
          String name = comp.getTarget().toString(false);
          int index = name.indexOf(">");
          name = name.substring(index + 2);
          int tar = Integer.valueOf(name);
          cfg.addEdge(position, tar, m, jc);
        }
        if (ret) {
          cfg.addEdge(position, -1, m, jc);
        }

        prev = position;
      }
      System.out.println(cfg.toString());
    }
    return cfg;
  }
 public boolean addNote(Display note, NotePosition position) {
   if (repeatList.isEmpty()) {
     this.note = note;
     this.position = position;
     return true;
   } else {
     return repeatList.addNote(note, position);
   }
 }
Example #5
0
  /**
   * Convenience method.
   *
   * <p>Add an empty constructor to this class that does nothing but calling super().
   *
   * @param access rights for constructor
   */
  public void addEmptyConstructor(int access_flags) {
    InstructionList il = new InstructionList();
    il.append(InstructionConstants.THIS); // Push `this'
    il.append(new INVOKESPECIAL(cp.addMethodref(super_class_name, "<init>", "()V")));
    il.append(InstructionConstants.RETURN);

    MethodGen mg =
        new MethodGen(access_flags, Type.VOID, Type.NO_ARGS, null, "<init>", class_name, il, cp);
    mg.setMaxStack(1);
    addMethod(mg.getMethod());
  }
Example #6
0
  private void createMethod(Element method) throws IllegalXMLVMException {
    il = new InstructionList();
    instructionHandlerManager = new InstructionHandlerManager(il);
    String methodName = method.getAttributeValue("name");

    Element signature = method.getChild("signature", nsXMLVM);
    Type retType = collectReturnType(signature);
    Type[] argTypes = collectArgumentTypes(signature);
    short accessFlags = getAccessFlags(method);

    if (methodName.equals(
        ".cctor")) // Same concept, different names in .net/JVM.  Note we are doing init of statics
                   // for a class
    {
      System.out.println("Changed name to clinit");
      methodName = "<clinit>";
      accessFlags = 0x8; // static
    }

    MethodGen m =
        new MethodGen(
            accessFlags, retType, argTypes, null, methodName, fullQualifiedClassName, il, _cp);
    Element code = method.getChild("code", nsXMLVM);
    createCode(code);
    instructionHandlerManager.checkConsistency();
    m.setMaxLocals();
    m.setMaxStack();
    _cg.addMethod(m.getMethod());
    il.dispose();
  }
  private void translateInstruction(IInstruction instruction) {
    // nothing to do if this is not an instance of Instruction
    if (!(instruction instanceof Instruction)) {
      m_ilOut.addInstruction(instruction);
      return;
    }

    translateInstruction((Instruction) instruction);
  }
 public Ftile createFtile(FtileFactory factory) {
   Ftile tmp = factory.decorateOut(repeatList.createFtile(factory), endInlinkRendering);
   tmp = factory.createWhile(swimlane, tmp, test, yes, out, afterEndwhile, color);
   if (note != null) {
     tmp = new FtileWithNoteOpale(tmp, note, position, skinParam, false);
   }
   // tmp = factory.decorateOut(tmp, afterEndwhile);
   return tmp;
 }
Example #9
0
  public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final InstructionList il = methodGen.getInstructionList();

    _left.translate(classGen, methodGen);
    _right.translate(classGen, methodGen);

    switch (_op) {
      case PLUS:
        il.append(_type.ADD());
        break;
      case MINUS:
        il.append(_type.SUB());
        break;
      case TIMES:
        il.append(_type.MUL());
        break;
      case DIV:
        il.append(_type.DIV());
        break;
      case MOD:
        il.append(_type.REM());
        break;
      default:
        ErrorMsg msg = new ErrorMsg(ErrorMsg.ILLEGAL_BINARY_OP_ERR, this);
        getParser().reportError(Constants.ERROR, msg);
    }
  }
Example #10
0
 private void createCode(Element code) throws IllegalXMLVMException {
   List<Element> instructions = code.getChildren();
   for (Element inst : instructions) {
     String name = inst.getName();
     String opcMethodName =
         "createInstruction" + name.substring(0, 1).toUpperCase() + name.substring(1);
     Class appClazz;
     Method opcMeth;
     Class[] paramTypes = {Element.class};
     Object[] params = {inst};
     appClazz = this.getClass();
     Object newInstr = null;
     try {
       opcMeth = appClazz.getMethod(opcMethodName, paramTypes);
       newInstr = opcMeth.invoke(this, params);
     } catch (NoSuchMethodException ex) {
       throw new IllegalXMLVMException(
           "Illegal instruction 1, unable to find method "
               + opcMethodName
               + " for '"
               + name
               + "'");
     } catch (InvocationTargetException ex) {
       ex.printStackTrace();
       throw new IllegalXMLVMException("Illegal instruction 2 '" + name + "'");
     } catch (IllegalAccessException ex) {
       throw new IllegalXMLVMException("Illegal instruction 3 '" + name + "'");
     }
     if (newInstr != null) {
       InstructionHandle ih = null;
       if (newInstr instanceof BranchInstruction) ih = il.append((BranchInstruction) newInstr);
       else if (newInstr instanceof CompoundInstruction)
         ih = il.append((CompoundInstruction) newInstr);
       else if (newInstr instanceof Instruction) ih = il.append((Instruction) newInstr);
       instructionHandlerManager.registerInstructionHandle(ih);
     }
   }
 }
Example #11
0
  /**
   * Replace instruction ih in list il with the instructions in new_il. If new_il is null, do
   * nothing
   */
  protected static void replace_instructions(
      InstructionList il, InstructionHandle ih, InstructionList new_il) {

    if ((new_il == null) || new_il.isEmpty()) return;

    // If there is only one new instruction, just replace it in the handle
    if (new_il.getLength() == 1) {
      ih.setInstruction(new_il.getEnd().getInstruction());
      return;
    }

    // Get the start and end instruction of the new instructions
    InstructionHandle new_end = new_il.getEnd();
    InstructionHandle new_start = il.insert(ih, new_il);

    // Move all of the branches from the old instruction to the new start
    il.redirectBranches(ih, new_start);

    // Move other targets to the new instuctions.
    if (ih.hasTargeters()) {
      for (InstructionTargeter it : ih.getTargeters()) {
        if (it instanceof LineNumberGen) {
          it.updateTarget(ih, new_start);
        } else if (it instanceof LocalVariableGen) {
          it.updateTarget(ih, new_end);
        } else if (it instanceof CodeExceptionGen) {
          CodeExceptionGen exc = (CodeExceptionGen) it;
          if (exc.getStartPC() == ih) exc.updateTarget(ih, new_start);
          else if (exc.getEndPC() == ih) exc.updateTarget(ih, new_end);
          else if (exc.getHandlerPC() == ih) exc.setHandlerPC(new_start);
          else System.out.printf("Malformed CodeException: %s%n", exc);
        } else {
          System.out.printf("unexpected target %s%n", it);
        }
      }
    }

    // Remove the old handle.  There should be no targeters left to it.
    try {
      il.delete(ih);
    } catch (Exception e) {
      throw new Error("Can't delete instruction", e);
    }
  }
Example #12
0
 byte[] counterAdaptClass(final InputStream is, final String name) throws Exception {
   JavaClass jc = new ClassParser(is, name + ".class").parse();
   ClassGen cg = new ClassGen(jc);
   String cName = cg.getClassName();
   ConstantPoolGen cp = cg.getConstantPool();
   if (!cg.isInterface()) {
     FieldGen fg = new FieldGen(ACC_PUBLIC, Type.getType("I"), "_counter", cp);
     cg.addField(fg.getField());
   }
   Method[] ms = cg.getMethods();
   for (int j = 0; j < ms.length; ++j) {
     MethodGen mg = new MethodGen(ms[j], cg.getClassName(), cp);
     if (!mg.getName().equals("<init>") && !mg.isStatic() && !mg.isAbstract() && !mg.isNative()) {
       if (mg.getInstructionList() != null) {
         InstructionList il = new InstructionList();
         il.append(new ALOAD(0));
         il.append(new ALOAD(0));
         il.append(new GETFIELD(cp.addFieldref(name, "_counter", "I")));
         il.append(new ICONST(1));
         il.append(new IADD());
         il.append(new PUTFIELD(cp.addFieldref(name, "_counter", "I")));
         mg.getInstructionList().insert(il);
         mg.setMaxStack(Math.max(mg.getMaxStack(), 2));
         boolean lv = ms[j].getLocalVariableTable() == null;
         boolean ln = ms[j].getLineNumberTable() == null;
         if (lv) {
           mg.removeLocalVariables();
         }
         if (ln) {
           mg.removeLineNumbers();
         }
         cg.replaceMethod(ms[j], mg.getMethod());
       }
     }
   }
   return cg.getJavaClass().getBytes();
 }
  /**
   * Translates the generic instruction <code>instruction</code> into an architecture-specific one.
   * The generated instruction(s) are added to the <code>m_ilOut</code> instruction list.
   *
   * @param instruction The instruction to translate
   */
  private void translateInstruction(Instruction instruction) {
    Intrinsic intrinsic = getIntrinsicForInstruction(instruction);
    if (intrinsic == null) {
      LOGGER.debug(
          StringUtil.concat(
              "No intrinsic found for the instruction ", instruction.getInstructionName()));
      m_ilOut.addInstruction(instruction);
      return;
    }

    // get the source operands, i.e., the instruction arguments
    IOperand[] rgSourceOps = instruction.getOperands();
    IOperand opSourceOutput = rgSourceOps[rgSourceOps.length - 1];

    // get the destination operands, i.e., the arguments of the architecture-specific intrinsic
    Argument[] rgDestArgs = null;
    if (intrinsic.getArguments() != null)
      rgDestArgs = Arguments.parseArguments(intrinsic.getArguments());
    else {
      LOGGER.debug(
          StringUtil.concat(
              "No arguments were defined for the intrinsic ",
              intrinsic.getBaseName(),
              ". Assuming generic arguments."));
      rgDestArgs = InstructionListTranslator.createGenericArguments(rgSourceOps.length);
    }

    // check whether the number of arguments of the instruction and the intrinsic to be generated
    // match
    // the source instruction always has a result operand (the last instruction argument); in the
    // intrinsic
    // the result might be merged into one of the operands, so there might be one argument less
    if (rgSourceOps.length != rgDestArgs.length && rgSourceOps.length - 1 != rgDestArgs.length) {
      LOGGER.error(
          StringUtil.concat(
              "The arguments for the instruction ",
              instruction.toString(),
              " mapped to the intrinsic ",
              intrinsic.getBaseName(),
              " don't match"));
      return;
    }

    boolean bIntrinsicHasSharedResult = rgSourceOps.length - 1 == rgDestArgs.length;
    int nOutputArgDestIndex = InstructionListTranslator.getOutputArgumentIndex(rgDestArgs);

    int[] rgPermSourceToDest = new int[rgSourceOps.length];
    int[] rgPermDestToSource = new int[rgDestArgs.length];
    InstructionListTranslator.getArgumentPermutations(
        intrinsic, rgSourceOps, rgDestArgs, rgPermSourceToDest, rgPermDestToSource);

    if (!bIntrinsicHasSharedResult) {
      // the intrinsic to generate has a distinct output operand

      // if possible, swap commutative operands if that helps saving MOVs
      rgSourceOps =
          InstructionListTranslator.compatibilizeCommutatives(
              intrinsic,
              rgSourceOps,
              rgDestArgs,
              rgPermSourceToDest,
              rgPermDestToSource,
              nOutputArgDestIndex,
              bIntrinsicHasSharedResult);
    } else {
      // the intrinsic to generate has an operand which is used for shared input and output,
      // i.e., upon completion of the instruction, the shared operand is overwritten with the result

      if (opSourceOutput.equals(rgSourceOps[rgPermDestToSource[nOutputArgDestIndex]])) {
        // the argument of the instruction corresponding to the shared intrinsic operand
        // is the same as the instruction's result argument
      } else {
        if (rgSourceOps[rgSourceOps.length - 1] instanceof IOperand.IRegisterOperand) {
          // if possible, swap commutative operands if that helps saving MOVs
          rgSourceOps =
              InstructionListTranslator.compatibilizeCommutatives(
                  intrinsic,
                  rgSourceOps,
                  rgDestArgs,
                  rgPermSourceToDest,
                  rgPermDestToSource,
                  nOutputArgDestIndex,
                  bIntrinsicHasSharedResult);
        }
      }
    }

    createInstructions(
        instruction,
        intrinsic,
        rgSourceOps,
        rgDestArgs,
        rgPermSourceToDest,
        rgPermDestToSource,
        nOutputArgDestIndex,
        bIntrinsicHasSharedResult);
  }
 public void add(Instruction ins) {
   repeatList.add(ins);
 }
 public Instruction getLast() {
   return repeatList.getLast();
 }
 public Set<Swimlane> getSwimlanes() {
   return repeatList.getSwimlanes();
 }
 public static InstructionList translate(
     CodeGeneratorSharedObjects data, IInstruction instruction, Specifier specDatatype) {
   InstructionList ilIn = new InstructionList();
   ilIn.addInstruction(instruction);
   return InstructionListTranslator.translate(data, ilIn, specDatatype, null);
 }
Example #18
0
 public Swimlane getSwimlaneIn() {
   return list.getSwimlaneIn();
 }
Example #19
0
  /**
   * Transforms invoke instructions that match the specified list for this class to call the
   * specified static call instead.
   */
  private InstructionList xform_inst(MethodGen mg, Instruction inst) {

    switch (inst.getOpcode()) {
      case Constants.INVOKESTATIC:
        {
          InstructionList il = new InstructionList();
          INVOKESTATIC is = (INVOKESTATIC) inst;
          String cname = is.getClassName(pgen);
          String mname = is.getMethodName(pgen);
          Type[] args = is.getArgumentTypes(pgen);
          MethodDef orig = new MethodDef(cname + "." + mname, args);
          MethodInfo call = method_map.get(orig);
          if (call != null) {
            call.cnt++;
            String classname = call.method_class;
            String methodname = mname;
            debug_map.log(
                "%s.%s: Replacing method %s.%s (%s) with %s.%s%n",
                mg.getClassName(),
                mg.getName(),
                cname,
                mname,
                UtilMDE.join(args, ", "),
                classname,
                methodname);
            il.append(
                ifact.createInvoke(
                    classname, methodname, is.getReturnType(pgen), args, Constants.INVOKESTATIC));
          }
          return (il);
        }

      case Constants.INVOKEVIRTUAL:
        {
          InstructionList il = new InstructionList();
          INVOKEVIRTUAL iv = (INVOKEVIRTUAL) inst;
          String cname = iv.getClassName(pgen);
          String mname = iv.getMethodName(pgen);
          Type[] args = iv.getArgumentTypes(pgen);
          Type instance_type = iv.getReferenceType(pgen);
          Type[] new_args = BCELUtil.insert_type(instance_type, args);
          MethodDef orig = new MethodDef(cname + "." + mname, args);
          if (debug_class) System.out.printf("looking for %s in map %s%n", orig, method_map);
          MethodInfo call = method_map.get(orig);
          if (call != null) {
            call.cnt++;
            String classname = call.method_class;
            String methodname = mname;
            debug_map.log(
                "Replacing method %s.%s (%s) with %s.%s%n",
                cname, mname, ArraysMDE.toString(args), classname, methodname);
            il.append(
                ifact.createInvoke(
                    classname,
                    methodname,
                    iv.getReturnType(pgen),
                    new_args,
                    Constants.INVOKESTATIC));
          }
          return (il);
        }

      default:
        return (null);
    }
  }
Example #20
0
  @Test
  public void testMonacoWithInstructions() {
    String osmFile = "files/monaco.osm.gz";
    String graphFile = "target/graph-monaco";
    String vehicle = "FOOT";
    String importVehicles = "FOOT";
    String weightCalcStr = "shortest";

    try {
      // make sure we are using fresh graphhopper files with correct vehicle
      Helper.removeDir(new File(graphFile));
      GraphHopper hopper =
          new GraphHopper()
              .setInMemory(true)
              .setOSMFile(osmFile)
              .disableCHShortcuts()
              .setGraphHopperLocation(graphFile)
              .setEncodingManager(new EncodingManager(importVehicles))
              .importOrLoad();

      Graph g = hopper.getGraph();
      GHResponse rsp =
          hopper.route(
              new GHRequest(43.727687, 7.418737, 43.74958, 7.436566)
                  .setAlgorithm("astar")
                  .setVehicle(vehicle)
                  .setWeighting(weightCalcStr));

      assertEquals(3437.6, rsp.getDistance(), .1);
      assertEquals(87, rsp.getPoints().getSize());

      InstructionList il = rsp.getInstructions();
      assertEquals(13, il.size());
      Translation tr = trMap.getWithFallBack(Locale.US);
      List<String> iList = il.createDescription(tr);
      // TODO roundabout fine tuning -> enter + leave roundabout (+ two rounabouts -> is it
      // necessary if we do not leave the street?)
      assertEquals("Continue onto Avenue des Guelfes", iList.get(0));
      assertEquals("Turn slight left onto Avenue des Papalins", iList.get(1));
      assertEquals("Turn sharp right onto Quai Jean-Charles Rey", iList.get(2));
      assertEquals("Turn left onto road", iList.get(3));
      assertEquals("Turn right onto Avenue Albert II", iList.get(4));

      List<Double> dists = il.createDistances();
      assertEquals(11, dists.get(0), 1);
      assertEquals(289, dists.get(1), 1);
      assertEquals(10, dists.get(2), 1);
      assertEquals(43, dists.get(3), 1);
      assertEquals(122, dists.get(4), 1);
      assertEquals(447, dists.get(5), 1);

      List<Long> times = il.createMillis();
      assertEquals(7, times.get(0) / 1000);
      assertEquals(207, times.get(1) / 1000);
      assertEquals(7, times.get(2) / 1000);
      assertEquals(30, times.get(3) / 1000);
      assertEquals(87, times.get(4) / 1000);
      assertEquals(321, times.get(5) / 1000);

      List<GPXEntry> list = rsp.getInstructions().createGPXList();
      assertEquals(123, list.size());
      final long lastEntryMillis = list.get(list.size() - 1).getMillis();
      final long totalResponseMillis = rsp.getMillis();
      assertEquals(totalResponseMillis, lastEntryMillis);

    } catch (Exception ex) {
      throw new RuntimeException("cannot handle osm file " + osmFile, ex);
    } finally {
      Helper.removeDir(new File(graphFile));
    }
  }
Example #21
0
 public LinkRendering getInLinkRendering() {
   return list.getInLinkRendering();
 }
Example #22
0
 public boolean kill() {
   return list.kill();
 }
Example #23
0
 public Ftile createFtile(FtileFactory factory) {
   return list.createFtile(factory);
 }
Example #24
0
 public Swimlane getSwimlaneOut() {
   return list.getSwimlaneOut();
 }
  /**
   * Creates the architecture-specific instructions to implement the generic instruction <code>
   * instruction</code> for the intrinsic <code>intrinsic</code>.
   *
   * @param instruction The generic instruction
   * @param intrinsic The intrinsic corresponding to <code>instruction</code>
   * @param rgSourceOps The array of operands of the generic instruction
   * @param rgDestArgs The array of intrinsic arguments
   * @param rgPermSourceToDest The argument permutation source &rarr; destination (where source is
   *     the generic instruction, destination is the target architecture specific instruction)
   * @param rgPermDestToSource The argument permutation destination &rarr; source (where source is
   *     the generic instruction, destination is the target architecture specific instruction)
   * @param nOutputArgDestIndex The index of the output argument in the array of intrinsic
   *     arguments, <code>rgDestArgs</code>
   * @param bIntrinsicHasSharedResult <code>true</code> iff the intrinsic requires that an argument
   *     is a shared in/out
   */
  private void createInstructions(
      Instruction instruction,
      Intrinsic intrinsic,
      IOperand[] rgSourceOps,
      Argument[] rgDestArgs,
      int[] rgPermSourceToDest,
      int[] rgPermDestToSource,
      int nOutputArgDestIndex,
      boolean bIntrinsicHasSharedResult) {
    // maps operands to substitute operands within the actual generated computation instruction
    Map<IOperand, IOperand> mapSubstitutions = new HashMap<>();

    IOperand[] rgDestOps = new IOperand[rgDestArgs.length];
    IOperand opSourceOutput = rgSourceOps[rgSourceOps.length - 1];

    boolean bHasNonCompatibleResultOperand = false;
    IOperand opTmpResultOperand = null;

    if (bIntrinsicHasSharedResult) {
      // find the operand which, in the intrinsic, is both input and output
      IOperand opShared = rgSourceOps[rgPermDestToSource[nOutputArgDestIndex]];

      // if the respective input and the output arguments are different, move the value of the input
      // to the result
      // the result will then be overwritten by the intrinsic
      if (!opSourceOutput.equals(opShared)) {
        IOperand opOut = opSourceOutput;
        boolean bIsOneOfNonSharedInputArgsResult =
            InstructionListTranslator.getIndexOfNonSharedInputArgsResult(rgSourceOps, opShared)
                != -1;
        if (!(opSourceOutput instanceof IOperand.IRegisterOperand)
            || bIsOneOfNonSharedInputArgsResult) {
          bHasNonCompatibleResultOperand = true;
          opTmpResultOperand = new IOperand.PseudoRegister(TypeRegisterType.SIMD);
          opOut = opTmpResultOperand;
        }

        // opOut can replace both opShared (the input operand, which in the architecture-specific
        // intrinsic
        // is also an output argument) and opOut (the operand, to which the result is written)
        mapSubstitutions.put(opShared, opOut);
        if (!bIsOneOfNonSharedInputArgsResult) mapSubstitutions.put(opSourceOutput, opOut);

        Instruction instrNewMov =
            new Instruction(
                getMovFpr(opShared instanceof IOperand.Address, opShared), opShared, opOut);
        instrNewMov.setParameterAssignment(instruction.getParameterAssignment());
        translateInstruction(instrNewMov);
      }
    }

    // gather operands and issue move instructions for non-compatible operands
    for (int i = 0; i < rgSourceOps.length; i++) {
      if (rgPermSourceToDest[i] != UNDEFINED) {
        boolean bIsResultOperand = i == rgSourceOps.length - 1;

        IOperand opSubstitute = mapSubstitutions.get(rgSourceOps[i]);
        if (opSubstitute != null) {
          // if already a non-compatible result operand has been found,
          // substitute the corresponding operand with the temporary one

          rgDestOps[rgPermSourceToDest[i]] = opSubstitute;
        } else {
          boolean bIsCompatible = isCompatible(rgSourceOps[i], rgDestArgs[rgPermSourceToDest[i]]);
          rgDestOps[rgPermSourceToDest[i]] =
              bIsCompatible ? rgSourceOps[i] : new IOperand.PseudoRegister(TypeRegisterType.SIMD);

          if (!bIsCompatible) {
            if (bIsResultOperand) {
              // this is the result operand
              // move instruction will be generated after issuing the main instruction

              bHasNonCompatibleResultOperand = true;
              opTmpResultOperand = rgDestOps[rgPermSourceToDest[i]];
            } else {
              // mov arg_i, tmp
              mapSubstitutions.put(rgSourceOps[i], rgDestOps[rgPermSourceToDest[i]]);

              Instruction instrNewMov =
                  new Instruction(
                      getMovFpr(rgSourceOps[i] instanceof IOperand.Address, rgSourceOps[i]),
                      rgSourceOps[i],
                      rgDestOps[rgPermSourceToDest[i]]);
              instrNewMov.setParameterAssignment(instruction.getParameterAssignment());

              translateInstruction(instrNewMov);
            }
          }
        }
      }
    }

    // add the main instruction
    ////
    // if (instruction.getIntrinsicBaseName ().equals (TypeBaseIntrinsicEnum.DIVIDE.value ()))
    // {
    //	IOperand.PseudoRegister opTmp = new IOperand.PseudoRegister (TypeRegisterType.SIMD);
    //	m_ilOut.addInstruction (new Instruction ("vrcpps", rgDestOps[0], opTmp));
    //	m_ilOut.addInstruction (new Instruction ("vmulps", rgDestOps[1], opTmp, rgDestOps[2]));
    // }
    // else
    ////
    String strInstruction = intrinsic.getName();

    boolean bIsLoad =
        intrinsic.getBaseName().equals(TypeBaseIntrinsicEnum.LOAD_FPR_ALIGNED.value());
    boolean bIsStore =
        intrinsic.getBaseName().equals(TypeBaseIntrinsicEnum.STORE_FPR_ALIGNED.value());
    if (bIsLoad || bIsStore) {
      Intrinsic i =
          m_data
              .getArchitectureDescription()
              .getIntrinsic(getMovFpr(bIsLoad, rgDestOps).value(), m_specDatatype);
      if (i != null) strInstruction = i.getName();
    }

    Instruction instrNew = new Instruction(strInstruction, instruction.getIntrinsic(), rgDestOps);
    instrNew.setParameterAssignment(instruction.getParameterAssignment());
    m_ilOut.addInstruction(instrNew);

    // add a move-result instruction if needed
    if (bHasNonCompatibleResultOperand) {
      // mov tmp, result
      Instruction instrNewMov =
          new Instruction(
              getMovFpr(opTmpResultOperand instanceof IOperand.Address, opTmpResultOperand),
              opTmpResultOperand,
              rgSourceOps[rgSourceOps.length - 1]);
      instrNewMov.setParameterAssignment(instruction.getParameterAssignment());
      translateInstruction(instrNewMov);
    }
  }
Example #26
0
 /** Remove this instruction from the list it is part of */
 public final void remove() {
   if (list != null) list.remove(this);
 }
 public InstructionSearcher2(ClassGen cg, Method m, InstructionList il) {
   index = -1;
   this.cp = cg.getConstantPool();
   this.classGen = cg;
   this.instructions = il.getInstructions();
 }
 public final boolean kill() {
   return repeatList.kill();
 }
Example #29
0
 public void add(Instruction other) {
   list.add(other);
 }
Example #30
0
 public Set<Swimlane> getSwimlanes() {
   return list.getSwimlanes();
 }