📄 instructionlist.java
字号:
and return it; otherwise, just return the saved max value */ public float getMaxTime() { if((_minTime == 99999)||(_maxTime == -99999)) { for (Iterator vIt = this.keySet().iterator(); vIt.hasNext();) { Float time = (Float) vIt.next(); float timefl = time.floatValue(); _maxTime = Math.max(_maxTime, timefl); _minTime = Math.min(_minTime, timefl); } } return _maxTime; } /** if the min or max time is unknown, go through the schedule and find it, save and return it; otherwise, just return the saved min value */ public float getMinTime() { if((_minTime == 99999)||(_maxTime == -99999)) { for (Iterator vIt = this.keySet().iterator(); vIt.hasNext();) { Float time = (Float) vIt.next(); float timefl = time.floatValue(); _maxTime = Math.max(_maxTime, timefl); _minTime = Math.min(_minTime, timefl); } } return _minTime; } /** Since InstructionList extends HashMap but can be thought of as a list of instructions, I decided to support both "add" and "put" to use as I thought made most sense as I programmed. They both schedule a given InstructionObject at some given time. */ public void put(float time, InstructionObject element) { add(time, element); } public void add(float time, InstructionObject element) { //To correct corrupted floating point numbers, they are first rounded time = _roundTimes.roundTime(time); //a HashSet for the time is either found or created: Float timeFl = new Float(time); if(!this.containsKey(timeFl)) super.put(timeFl, new HashSet()); HashSet instsAtTime = (HashSet)super.get(timeFl); //if(!existsAlready(element.inst)) { //this object is added to the set of all objects _allInstsSet.add(element); //the object is added to the set for this time instsAtTime.add(element); //the min and max times are adjusted checkMinMaxTimes(time); //} } /** if there are multiple copies of the same instruction in the schedule, remove the duplicates */ public void removeDuplicateInsts() { for (Iterator vIt = ((HashSet)_allInstsSet.clone()).iterator(); vIt.hasNext();) { InstructionObject instObj = (InstructionObject) vIt.next(); //if an instruction exists more than once, remove it if(existsAlreadyCnt(instObj.inst) > 1) remove(instObj); } } /** count up how many copies of an instruction, i, exist */ public int existsAlreadyCnt(Instruction i) { //HashSet instsAtTime = getAllAtTime(time); int cnt = 0; //foreach instruction in the InstructionList: for (Iterator vIt = _allInstsSet.iterator(); vIt.hasNext();) { InstructionObject instObj = (InstructionObject) vIt.next(); Instruction inst = instObj.inst; //if the instructions are the same, increment a counter //(I used string compare, because often the instructions or their operands //may be different objects and a match may not be made) if(inst.toString().compareTo(i.toString())==0) { cnt++; } } return cnt; } /** This is unused, but it checks to see if instruction i is somewhere in the schedule. */ public boolean existsAlready(Instruction i) { //HashSet instsAtTime = getAllAtTime(time); for (Iterator vIt = _allInstsSet.iterator(); vIt.hasNext();) { InstructionObject instObj = (InstructionObject) vIt.next(); Instruction inst = instObj.inst; if(inst.toString().compareTo(i.toString())==0) { return true; } } return false; } /** remove all the instructionObjects associated with the instructions in Collection c. */ public void removeInsts(Collection c) { for (Iterator i = c.iterator(); i.hasNext();) { Instruction inst = (Instruction)i.next(); InstructionObject element = instToObjMap.get(inst); remove(element); } } public InstructionObject findInstObj(Instruction i) { return instToObjMap.get(i); } /** remove the instructionObject. This is a little difficult, since the time is unknown, where this instruction might be, which means, all times must be attempted. */ public void remove(InstructionObject element) { //foreach time attempt to remove element for (Iterator vIt = ((HashMap)this.clone()).keySet().iterator(); vIt.hasNext();) { Float execTimeFl = (Float) vIt.next(); float execTime = execTimeFl.floatValue(); HashSet iList = getAllAtTime(execTime); iList.remove(element); if(iList.size()==0) super.remove(execTimeFl); } //remove element from the set of all instructionObjects _allInstsSet.remove(element); } /** remove the instructionObject from the given time */ public void remove(float time, InstructionObject element) { //remove from the set of all instructions _allInstsSet.remove(element); //get the set for this time, and remove it from there time = _roundTimes.roundTime(time); Float timeFl = new Float(time); if(this.containsKey(timeFl)) { HashSet instsAtTime = (HashSet)super.get(timeFl); instsAtTime.remove(element); if(instsAtTime.size()==0) super.remove(timeFl); } } /** If you have a collection of instructions that you wish to add to InstructionList at the time saved in the Instruction than call this. It calls addAllInstsToTime, with the special flag -9999 for the exection time, which tells addAllInstsToTime to schedule the instructions at their saved execution times. */ public void addAllInsts(Collection c) { addAllInstsToTime(-9999, c); } /** import the instructions in collection c and place them in time slot "time", unless, time==-9999, in which case, add them to the time saved on the instruction. Also, as each instruction is added */ public void addAllInstsToTime(float time, Collection c) { //HashSet usedPredOperands = new HashSet(); for (Iterator i = c.iterator(); i.hasNext();) { Instruction inst = (Instruction)i.next(); //create a new instructionObject for this instruction InstructionObject instObj = newInstructionObject(); instObj.inst = inst; //schedule to "time" or to the instruction's save execTime if(time == -9999) this.add(inst.getExecTime(), instObj); else this.add(time, instObj); //save the operands used in a predicate by this instruction, both in the //object's used operand list, and in the private set of all predicate operands BooleanEquation pred = inst.getPredicate(); ArrayList operandList = new ArrayList(); if(pred != null) { operandList.addAll(pred.listBooleanOperands()); } instObj.listOfPredsUsed.addAll(operandList); _usedPredOperands.addAll(operandList); //calculate the maximum possible latency for a schedule, which is the sum //of latencies for all objects: _maxRunTime += Math.ceil(instObj.getRunLength()); } //knowing all the predicate operands, update which instructions define these //operands. for (Iterator it = c.iterator(); it.hasNext();) { Instruction inst = (Instruction)it.next(); InstructionObject instObj = instToObjMap.get(inst); instObj.updatePredLists(); } } public void addNewIns(Instruction i, Operand op) { InstructionObject instObj = instToObjMap.get(i); instObj.addIn(op); } public void addNewOuts(Instruction i, Operand op) { InstructionObject instObj = instToObjMap.get(i); instObj.addOut(op); } /** this is used to merge two InstructionLists. Take each set of instructions for each time in iList's schedule and add it to the same times in THIS's schedule */ public void addAll(InstructionList iList) { for (Iterator vIt = iList.keySet().iterator(); vIt.hasNext();) { Float time = (Float) vIt.next(); float timefl = time.floatValue(); addAllToTime(timefl, iList.getAllAtTime(timefl)); } } /** add all the instruction objects in collection c to the given time */ public void addAllToTime(float time, Collection c) { //_allInstsSet.addAll(c); time = _roundTimes.roundTime(time); //Float timeFl = new Float(time); //if(!this.containsKey(timeFl)) // super.put(timeFl, new HashSet()); //HashSet instsAtTime = (HashSet)super.get(timeFl); for (Iterator vIt = c.iterator(); vIt.hasNext();) { InstructionObject instObj = (InstructionObject) vIt.next(); add(time, instObj); } //instsAtTime.addAll(c); //checkMinMaxTimes(time); } /** get the set of instructions at a given time */ public HashSet getAllAtTime(float time) { time = _roundTimes.roundTime(time); Float timeFl = new Float(time); if(!this.containsKey(timeFl)) super.put(timeFl, new HashSet()); HashSet instsAtTime = (HashSet)super.get(timeFl); return instsAtTime; } /** get the set of all InstructionObjects */ public HashSet getInstSet() { return _allInstsSet; } public void resetSuccsList() { for (Iterator vIt = _allInstsSet.iterator(); vIt.hasNext();) { InstructionObject instObj = (InstructionObject) vIt.next(); instObj.resetSuccsList(); } } public void resetdfg() { _dfgI = null; } /** get a set of all instructions (instead of InstructionObjects like above) in the List */ public HashSet getInstructions() { HashSet instSet = new HashSet(); for (Iterator vIt = _allInstsSet.iterator(); vIt.hasNext();) { InstructionObject instObj = (InstructionObject) vIt.next(); Instruction inst = instObj.inst; instSet.add(inst); } return instSet; } /** After the schedule has been determined, the instruction times must be saved onto each instruction and then the list of scheduled instructions must be saved onto the associated hyperblock node. The old instructions are removed first, becuase during modulo scheduling new instructions have been created, which are not in the original list on the node. Rather than find out which these are and only add those, I just use the node methed, removeAllInstructions to delete the old list, and addInstructions, to add the newly created list. */ public void scheduleList(BlockNode node) { for (Iterator vIt = keySet().iterator(); vIt.hasNext();) { Float time = (Float) vIt.next(); float timefl = time.floatValue(); HashSet iList = getAllAtTime(timefl); for (Iterator vIt2 = iList.iterator(); vIt2.hasNext();) { InstructionObject instObj = (InstructionObject) vIt2.next(); Instruction inst = instObj.inst; inst.setExecTime(timefl); inst.setExecClkCnt((int)timefl); } } node.removeAllInstructions(); ArrayList schedList = new ArrayList(getInstructions()); //sort(schedList); node.addInstructions(schedList); } /** Since MSchedInstObject extends InstructionObject, when such an object is created in InstructionList by one of its methods, its to know what kind of instance to create. This method has been overwritten in MSchedHash, and so if called from InstructionList it will create an InstructionObject and if called from MSchedHash, a MSchedInstObject. */ public InstructionObject newInstructionObject() { return new InstructionObject(); } public InstructionObject newInstructionObject(Instruction i) { return new InstructionObject(i); } /** read in all instructions from a hyperblock node and put them in the appropriate schedule slot as saved already in each instruction */ public void readInList(BlockNode bNode) { _node = bNode; addAllInsts(bNode.getInstructions()); } /** Create a deep copy of THIS. The copy is performed by partialListCopy, who copies THIS between two given times and so listCopy uses the saved min and max times from THIS to call partialListCopy */ public InstructionList listCopy() { return partialListCopy(getMinTime(), getMaxTime()); } /** make a copy of the list between start and finish */ public InstructionList partialListCopy(float start, float finish) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -