📄 memoryblock.java
字号:
if((portTmp.typeCode == Port.DATA_READ_TYPE)|| (portTmp.typeCode == Port.DATA_RW_TYPE)) slowestPortLat = Math.max(slowestPortLat, portTmp.write_latency); } return slowestPortLat; } /** This method tries to pack an array into the same address location as others at that location. Returns true if successful and false if not. */ public boolean saveToPackedArrCollect(ArrayToArrayInfoMap.ArrayInfo array, ArrayToArrayInfoMap arrToArrInf) { for (Iterator packIt = getVarGroupingsPtr().iterator(); packIt.hasNext(); ) { HashSet pack = (HashSet)packIt.next(); if(!pack.iterator().hasNext()) continue; Operand arr1Op= (Operand)(pack.iterator().next()); ArrayToArrayInfoMap.ArrayInfo arr1 = arrToArrInf.get(arr1Op); long arr1Stop = arr1.getStop(); long arr1start = arr1.getStart(); if((arr1Stop == array.getStop())&& (arr1start == array.getStart())&& (Memory.matchTester.matches(array.getVar(), arr1.getVar()))) { pack.add(array.getVar()); return true; } } return false; } public boolean isInSamePack(Operand arr1, Operand arr2) { for (Iterator packIt = getVarGroupingsPtr().iterator(); packIt.hasNext(); ) { HashSet pack = (HashSet)packIt.next(); if(!pack.iterator().hasNext()) continue; if(pack.contains(arr1)&&pack.contains(arr2)) return true; } return false; } public boolean isInSamePack(Operand arr1, HashSet otherArrays) { for (Iterator packIt = otherArrays.iterator(); packIt.hasNext(); ) { Operand arr2 = (Operand)packIt.next(); if(arr2==null) continue; if(arr1==arr2) continue; if(isInSamePack(arr1, arr2)) return true; } return false; } /** This method tests if there are no arrays at this location and it is thus ok to place an array here */ public boolean noPackdArrAtLoc(ArrayToArrayInfoMap.ArrayInfo array, ArrayToArrayInfoMap arrToArrInf) { for (Iterator packIt = getVarGroupingsPtr().iterator(); packIt.hasNext(); ) { HashSet pack = (HashSet)packIt.next(); if(!pack.iterator().hasNext()) continue; Operand arr1Op= (Operand)(pack.iterator().next()); ArrayToArrayInfoMap.ArrayInfo arr1 = arrToArrInf.get(arr1Op); long arr1Stop = arr1.getStop(); long arr1start = arr1.getStart(); if(((arr1Stop == array.getStop())&& (arr1start == array.getStart()))|| ((arr1start<=array.getStart())&&(arr1Stop>=array.getStart()))|| ((arr1start<=array.getStop())&&(arr1Stop>=array.getStop()))) { return false; } } HashSet pack2 = new HashSet(); pack2.add(array.getVar()); if(pack2.size() > 0) _listOfArrayVarGroupings.add(pack2); return true; } public void resetPorts() { for(Iterator portIt = port.iterator(); portIt.hasNext(); ) { Port portTmp = (Port)portIt.next(); portTmp.resetPortUseCnter(); } } /** This method attempts to allocate an array to a given address location (which is saved in array, which is of type ArrayToArrayInfoMap.ArrayInfo, which holds the location information) */ public boolean allocateArray(ArrayToArrayInfoMap.ArrayInfo array, ArrayToArrayInfoMap arrToArrInf) { boolean locFound = false; _setOfArraysInMem.add(array); //if(GlobalOptions.slowestMem) return true; for (Iterator stopIt = _pseudoAddys.getStopAddys().iterator(); stopIt.hasNext() && !locFound; ) { long time = ((Long)stopIt.next()).longValue(); array.setStart(time+1); if(_pseudoAddys.isThereSpaceInWordToPack(array, this) && (( GlobalOptions.packArrays && saveToPackedArrCollect(array, arrToArrInf) ) || noPackdArrAtLoc(array, arrToArrInf) )) { _pseudoAddys.saveStop(array); locFound = true; } } return locFound; } public void deAllocateArray(ArrayToArrayInfoMap.ArrayInfo array) { _pseudoAddys.forgetStop(array); array.deAlloc(); _setOfArraysInMem.remove(array); HashSet varGroupings = (HashSet)getVarGroupingsPtr().clone(); for (Iterator packIt = varGroupings.iterator(); packIt.hasNext(); ) { HashSet pack = (HashSet)packIt.next(); if(((pack.size()<=1)&&(pack.contains(array.getVar())))/*|| (pack.size()<=1)*/) { getVarGroupingsPtr().remove(pack); } pack.remove(array.getVar()); } HashSet varGroupings2 = new HashSet(getVarGroupingsPtr()); for (Iterator packIt2 = getVarGroupingsPtr().iterator(); packIt2.hasNext(); ) { HashSet pack = (HashSet)packIt2.next(); if(pack.size()==0) { varGroupings2.remove(pack); } } setVarGroupingsPtr(varGroupings2); } /** This method uses the information from the GEP and ALoads and AStores which will be used to determine if arrays can be packed together */ public void loadIndexes(BlockGraph designBGraph) { Memory.matchTester.readIndex(designBGraph); } public int trueCost(BlockNode bNode, ArrayToArrayInfoMap arrToArrInf) { return costGeneric(bNode, arrToArrInf, PortUsageSplitter.TRUECOST); } public int cost(BlockNode bNode, ArrayToArrayInfoMap arrToArrInf) { return costGeneric(bNode, arrToArrInf, PortUsageSplitter.NORMCOST); } private int costGeneric(BlockNode bNode, ArrayToArrayInfoMap arrToArrInf, boolean trueCost) { resetPorts(); int lCost = 0; int sCost = 0; //int lCost = -1; //int sCost = -1; for (Iterator packIt = getVarGroupingsPtr().iterator(); packIt.hasNext(); ) { HashSet pack = (HashSet)packIt.next(); if(pack.size()==0) continue; if(!pack.iterator().hasNext()) continue; Operand arrp= (Operand)(pack.iterator().next()); ArrayToArrayInfoMap.ArrayInfo array = arrToArrInf.get(arrp); HashMap loadSched = array.getLoadCntSched(bNode); for(Iterator loadsIt = loadSched.keySet().iterator(); loadsIt.hasNext(); ) { Integer time = (Integer)loadsIt.next(); Integer cnt = (Integer)loadSched.get(time); //if(trueCost) lCost += _portUseSplit.addLoads(bNode, time.intValue(), cnt.intValue(), trueCost); //else // lCost += _portUseSplit.addLoadsCnt(time.intValue(), cnt.intValue()); } HashMap storeSched = array.getStoreCntSched(bNode); for(Iterator storesIt = storeSched.keySet().iterator(); storesIt.hasNext(); ) { Integer time = (Integer)storesIt.next(); Integer cnt = (Integer)storeSched.get(time); //if(trueCost) sCost += _portUseSplit.addStores(bNode, time.intValue(), cnt.intValue(), trueCost); //else // sCost += _portUseSplit.addStoresCnt(time.intValue(), cnt.intValue()); } } //System.out.println("lCost " + lCost); //System.out.println("sCost " + sCost); return Math.max(lCost, sCost); } public int addLoadTest(BlockNode bNode, int time, Operand array) { HashSet previousArrays = (HashSet)_saveArrLoadTimes.get(new Integer(time)); if((previousArrays == null)||(!(isInSamePack(array, previousArrays)))) { return _portUseSplit.addLoadTest(bNode, time, PortUsageSplitter.TRUECOST); } else //return _portUseSplit.addLoadTest(time); return _portUseSplit.getDataPortUseCnt(bNode, time, PortUsageSplitter.LOAD); } public int addLoadTestCnt(BlockNode bNode, int time, Operand array) { HashSet previousArrays = (HashSet)_saveArrLoadTimes.get(new Integer(time)); if((previousArrays == null)|| (!(isInSamePack(array, previousArrays)))) { return _portUseSplit.addLoadTest(bNode, time, PortUsageSplitter.NORMCOST); } else { //return _portUseSplit.addLoadTestCnt(time);/*System.out.println("isInSamePack(array, previousArrays) " + isInSamePack(array, previousArrays));System.out.println("array " + array);System.out.println("previousArrays " + previousArrays);System.out.println("matches");System.out.println("&&&&&&&&&&&&&&&&&&&&&&&&&");*/ return _portUseSplit.getDataPortUseCnt(bNode, time, PortUsageSplitter.LOAD); } } public int addLoad(BlockNode bNode, int time, Operand array) { HashSet previousArrays = (HashSet)_saveArrLoadTimes.get(new Integer(time)); if(previousArrays == null) { previousArrays = new HashSet(); previousArrays.add(array); _saveArrLoadTimes.put(new Integer(time), previousArrays); return _portUseSplit.addLoad(bNode, time, PortUsageSplitter.TRUECOST); } else if(isInSamePack(array, previousArrays)) return _portUseSplit.getDataPortUseCnt(bNode, time, PortUsageSplitter.LOAD); else { previousArrays.add(array); return _portUseSplit.addLoad(bNode, time, PortUsageSplitter.TRUECOST); } } public int addLoadCnt(BlockNode bNode, int time, Operand array) { HashSet previousArrays = (HashSet)_saveArrLoadTimes.get(new Integer(time)); if(previousArrays == null) { previousArrays = new HashSet(); previousArrays.add(array); _saveArrLoadTimes.put(new Integer(time), previousArrays); return _portUseSplit.addLoad(bNode, time, PortUsageSplitter.NORMCOST); } else if(isInSamePack(array, previousArrays)) return _portUseSplit.getDataPortUseCnt(bNode, time, PortUsageSplitter.LOAD); else { previousArrays.add(array); return _portUseSplit.addLoad(bNode, time, PortUsageSplitter.NORMCOST); } } public int subLoad(BlockNode bNode, int time, Operand array) { HashSet previousArrays = (HashSet)_saveArrLoadTimes.get(new Integer(time)); if((previousArrays == null)||(isInSamePack(array, previousArrays))) { return _portUseSplit.getDataPortUseCnt(bNode, time, PortUsageSplitter.LOAD); } else { if((previousArrays.size()==1)&&(previousArrays.contains(array))) _saveArrLoadTimes.remove(new Integer(time)); previousArrays.remove(array); return _portUseSplit.subLoad(bNode, time, PortUsageSplitter.TRUECOST); } } public int subLoadCnt(BlockNode bNode, int time, Operand array) { HashSet previousArrays = (HashSet)_saveArrLoadTimes.get(new Integer(time)); if((previousArrays == null)||(isInSamePack(array, previousArrays))) { return _portUseSplit.getDataPortUseCnt(bNode, time, PortUsageSplitter.LOAD); } else { if((previousArrays.size()==1)&&(previousArrays.contains(array))) _saveArrLoadTimes.remove(new Integer(time)); previousArrays.remove(array); return _portUseSplit.subLoad(bNode, time, PortUsageSplitter.NORMCOST); } } public int addStoreTest(BlockNode bNode, int time, Operand array) { HashSet previousArrays = (HashSet)_saveArrStoreTimes.get(new Integer(time)); if((previousArrays == null)||(!(isInSamePack(array, previousArrays)))) { return _portUseSplit.addStoreTest(bNode, time, PortUsageSplitter.TRUECOST); } else //return _portUseSplit.addStoreTest(time); return _portUseSplit.getDataPortUseCnt(bNode, time, PortUsageSplitter.STORE); } public int addStoreTestCnt(BlockNode bNode, int time, Operand array) { HashSet previousArrays = (HashSet)_saveArrStoreTimes.get(new Integer(time)); if((previousArrays == null)||(!(isInSamePack(array, previousArrays)))) { return _portUseSplit.addStoreTest(bNode, time, PortUsageSplitter.NORMCOST); } else { //return _portUseSplit.addStoreTestCnt(time); return _portUseSplit.getDataPortUseCnt(bNode, time, PortUsageSplitter.STORE); } } public int addStore(BlockNode bNode, int time, Operand array) { HashSet previousArrays = (HashSet)_saveArrStoreTimes.get(new Integer(time)); if(previousArrays == null) { previousArrays = new HashSet(); previousArrays.add(array); _saveArrStoreTimes.put(new Integer(time), previousArrays); return _portUseSplit.addStore(bNode, time, PortUsageSplitter.TRUECOST); } else if(isInSamePack(array, previousArrays)) return _portUseSplit.getDataPortUseCnt(bNode, time, PortUsageSplitter.STORE); else { previousArrays.add(array); return _portUseSplit.addStore(bNode, time, PortUsageSplitter.TRUECOST); } } public int addStoreCnt(BlockNode bNode, int time, Operand array) { HashSet previousArrays = (HashSet)_saveArrStoreTimes.get(new Integer(time)); if(previousArrays == null) { previousArrays = new HashSet(); previousArrays.add(array); _saveArrStoreTimes.put(new Integer(time), previousArrays); return _portUseSplit.addStore(bNode, time, PortUsageSplitter.NORMCOST); } else if(isInSamePack(array, previousArrays)) return _portUseSplit.getDataPortUseCnt(bNode, time, PortUsageSplitter.STORE); else { previousArrays.add(array); return _portUseSplit.addStore(bNode, time, PortUsageSplitter.NORMCOST); } } public int subStore(BlockNode bNode, int time, Operand array) { HashSet previousArrays = (HashSet)_saveArrStoreTimes.get(new Integer(time)); if((previousArrays == null)||(isInSamePack(array, previousArrays))) { return _portUseSplit.getDataPortUseCnt(bNode, time, PortUsageSplitter.STORE); } else { if((previousArrays.size()==1)&&(previousArrays.contains(array))) _saveArrStoreTimes.remove(new Integer(time)); previousArrays.remove(array); return _portUseSplit.subStore(bNode, time, PortUsageSplitter.TRUECOST); } } public int subStoreCnt(BlockNode bNode, int time, Operand array) { HashSet previousArrays = (HashSet)_saveArrStoreTimes.get(new Integer(time)); if((previousArrays == null)||(isInSamePack(array, previousArrays))) { return _portUseSplit.getDataPortUseCnt(bNode, time, PortUsageSplitter.STORE); } else { if((previousArrays.size()==1)&&(previousArrays.contains(array))) _saveArrStoreTimes.remove(new Integer(time)); previousArrays.remove(array); return _portUseSplit.subStore(bNode, time, PortUsageSplitter.NORMCOST); } } //I don't know if this should be used, but I commented it out, so I could use //Chip's definition of "toString." /* public String toString() { String retval = "MemoryBlock: \n"; retval = retval + " _name: " + _name + "\n"; /*retval = retval + " _isROM: " + _isROM + "\n"; retval = retval + " _onlyOneAddy: " + _onlyOneAddy + "\n"; retval = retval + " _wordSize: " + _wordSize + "\n"; retval = retval + " _initReadLatency: " + _initReadLatency + "\n"; retval = retval + " _normalReadLatency: " + _normalReadLatency + "\n"; retval = retval + " _initWriteLatency: " + _initWriteLatency + "\n"; retval = retval + " _normalWriteLatency: " + _normalWriteLatency + "\n"; retval = retval + " _memSize: " + _memSize + "\n"; retval = retval + " _numOfReadBus: " + _numOfReadBus + "\n"; retval = retval + " _numOfWriteBus: " + _numOfWriteBus + "\n"; retval = retval + " _addr: 0x"+Long.toHexString(_addr)+"\n"; return retval; }*/}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -