⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chipdef.java

📁 一种将c高级语言转化给VHDL的编译器
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* * LA-CC 05-135 Trident 0.7.1Copyright NoticeCopyright 2006 (c) the Regents of the University of California.This Software was produced under a U.S. Government contract(W-7405-ENG-36) by Los Alamos National Laboratory, which is operatedby the University of California for the U.S. Department of Energy. TheU.S. Government is licensed to use, reproduce, and distribute thisSoftware. Permission is granted to the public to copy and use thisSoftware without charge, provided that this Notice and any statementof authorship are reproduced on all copies. Neither the Government northe University makes any warranty, express or implied, or assumes anyliability or responsibility for the user of this Software. */package fp.hardware;import java.util.*;import fp.flowgraph.*;import fp.hwdesc.Memory;import fp.hwdesc.memClasses.IndexMatch;/** This class saves information about the target FPGA and has several methods  *  for helping me to analyze hardware usage and limitations. *  * @author Kris Peterson */public class ChipDef{    private class ArrayToMemMap extends HashMap {      public ArrayToMemMap() {super();}        public void saveArray(ArrayToArrayInfoMap.ArrayInfo array, Memory block) {      super.put(array, block);    }    public void removeArray(ArrayToArrayInfoMap.ArrayInfo array) {      super.remove(array);    }    public Memory get(ArrayToArrayInfoMap.ArrayInfo array) {      return (Memory)super.get(array);    }        public int cost(BlockNode bNode) {      int cost = -9999;      for (Iterator memIt = values().iterator();     	   memIt.hasNext(); ) {	Memory block = (Memory)memIt.next();    	cost = Math.max(cost, block.cost(bNode, _arrToArrInfoMap));      }      return cost;    }      public int trueCost(BlockNode bNode) {      int cost = -9999;      for (Iterator memIt = values().iterator();     	   memIt.hasNext(); ) {	Memory block = (Memory)memIt.next();    	cost = Math.max(cost, block.trueCost(bNode, _arrToArrInfoMap));      }      return cost;    }    }    //logic parameters  /** amount of space on board for logic implementation   */  private int _sliceCnt;  /** percentage of board that can be used for logic instead of wiring, muxes,    *  or other   */  private float _percentUsage;     //memory block parameters:  /** list of data for all the memories on or in the chip or board   */  private ArrayList _memoryBlocks;     //logic availability info:  /** used to save the number of an operator that is available to be used (e.g.    *  there may be 4 multipliers)   */  private HashMap _opCntsAvailable;  /** the number of a given operator needed by the design (e.g. the design may    *  have 5 multiply operations and therefore needs 5 multipliers).   */  private HashMap _opCntsNeeded;  /** a list of all the operators used in the design   */  private ArrayList _opList;     private boolean _isDummyBoard;        /** these two variables are used to save usage of modules   */  private HashMap _opUseCntHM;  private HashMap _opUseListsHM;  private BlockNode _node;     /** default chip with 0 size?  how big should it be by default?   */  public ChipDef() {    this(0,0, null);    _isDummyBoard = false;  }       /** the Hardware analysis routine needs to schedule the board ignoring    *  hardware issues.     */  public ChipDef(boolean isDummyBoard) {    this(0,0, null);    _isDummyBoard = isDummyBoard;  }  public ChipDef(int sliceCnt, float percentUsage, boolean isDummyBoard,                 ArrayList memBlocks) {    this(sliceCnt, percentUsage, null);    _isDummyBoard = isDummyBoard;    _memoryBlocks = memBlocks;  }  /** langweilig   *    * @param sliceCnt measure of space on board available for logic   * @param percentUsage perecentage of sliceCnt that can be used for       *      logic instead of wiring or other   */  //private static IndexMatch Memory.matchTester; // = new IndexMatch();  public ChipDef(int sliceCnt, float percentUsage, ArrayList memBlocks) {    _isDummyBoard = false;    _sliceCnt = sliceCnt;    _percentUsage = percentUsage;    _opUseCntHM = new HashMap();    _opUseListsHM = new HashMap();    _memoryBlocks = memBlocks;    _arrToArrInfoMap = new ArrayToArrayInfoMap();    //Memory.matchTester = new IndexMatch();  }  public boolean isDummyBoard(){return _isDummyBoard;}  public void makeDummyBoard(){_isDummyBoard = true;}  public void unDummyBoard(){_isDummyBoard = false;}    /** the get and set methods are all self explanatory   *    * @return the sliceCnt   */  public int getSliceCnt() { return _sliceCnt;}  public float getPercentUsage() { return _percentUsage;}  public void setSliceCnt(int sliceCnt) { _sliceCnt = sliceCnt;}  public void setPercentUsage(float percentUsage) { _percentUsage=percentUsage;}    public ArrayList getMemoryBlockList() {    return _memoryBlocks;  }     private ArrayToArrayInfoMap _arrToArrInfoMap;  private ArrayToMemMap _arrayToBlockMap = new ArrayToMemMap();  private ArrayToMemMap _bestArrayToBlockMap = null;  private int _bestArrayAllocCost = -999;    /**    */  public Operator chooseStoreOp(Instruction inst) {    Operand array = AStore.getPrimalDestination(inst);    Memory mBlock = findMemoryBlock(array);    if(mBlock==null) return null;    return mBlock.getAStoreOp();  }  public Operator chooseLoadOp(Instruction inst) {    Operand array = ALoad.getPrimalSource(inst);    Memory mBlock = findMemoryBlock(array);    if(mBlock==null) return null;    return mBlock.getALoadOp();  }    /**  this method attempts to allocate the given array to the given memory.  */  public boolean allocate(Memory block,                           ArrayToArrayInfoMap.ArrayInfo array) {    if(_arrToArrInfoMap.arrayDoesntFit(block, array)) return false;    if(block.allocateArray(array, _arrToArrInfoMap)) {      _arrayToBlockMap.saveArray(array, block);      return true;    }    else      return false;  }  /**  This method calls the MemoryBlock method loadIndexes which 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 void loadDesign(BlockGraph bGraph) {    _arrToArrInfoMap.loadDesign(bGraph);  }    public void loadSchedule(BlockNode bNode) {    _arrToArrInfoMap.loadSchedule(bNode);  }    public void deAllocateArray(Memory block,                               ArrayToArrayInfoMap.ArrayInfo array) {    _arrayToBlockMap.removeArray(array);    _arrToArrInfoMap.addArrayBack(array.getVar());    block.deAllocateArray(array);  }    public void resetMemSpaceLeft() {    for (Iterator itsMem = _memoryBlocks.iterator(); itsMem.hasNext(); ) {      Memory memBlock = (Memory)itsMem.next();      memBlock.setMemSizeLeft();    }  }  public boolean arrayAllocate(BlockGraph bGraph) {    resetMemSpaceLeft();    //boolean hasntFailed = true;    while((_arrToArrInfoMap.size()>0)/* && (hasntFailed)*/) {      //hasntFailed = true;      ArrayList arrays = new ArrayList(_arrToArrInfoMap.returnRemainingArrs());      Collections.shuffle(arrays);      _arrToArrInfoMap.printRemainingArrays();            //for (Iterator arrs = _arrToArrInfoMap.returnRemainingArrs().iterator();       for (Iterator arrs = arrays.iterator();             arrs.hasNext(); ) {	ArrayToArrayInfoMap.ArrayInfo arrInfo = 	                            (ArrayToArrayInfoMap.ArrayInfo)arrs.next();                if(!checkIfEnoughRoom(arrInfo)) return false;	if(!memAllocate(arrInfo, bGraph))           arrInfo.tryCnt++;      }    }    return (_arrToArrInfoMap.returnRemainingArrs().size()<=0);  }    public boolean checkIfEnoughRoom(ArrayToArrayInfoMap.ArrayInfo array) {    for (Iterator itsMem = _memoryBlocks.iterator(); itsMem.hasNext(); ) {      Memory memBlock = (Memory)itsMem.next();      if(!_arrToArrInfoMap.arrayDoesntFit(memBlock, array)) return true;    }    return false;  }    public void resetRemainingArrays() {    _arrToArrInfoMap.resetRemainingArrays();  }  public void printRemainingArrays() {    _arrToArrInfoMap.printRemainingArrays();  }  /**  this method is for debugging.  It lets you see the contents of memory  */  public void displayMemsArrs() {    for (Iterator itsMem = _memoryBlocks.iterator(); itsMem.hasNext(); ) {      Memory memBlock = (Memory)itsMem.next();      System.out.println("memBlock " + memBlock.getChipName());      memBlock.displayMemContents(_arrToArrInfoMap);    }  }    public boolean memAllocate(ArrayToArrayInfoMap.ArrayInfo array,                              BlockGraph bGraph) {    ArrayList mems = new ArrayList(_memoryBlocks);    Collections.shuffle(mems);    boolean locFound = false;    for (Iterator itsMem = mems.iterator(); itsMem.hasNext()&&                                            !locFound; ) {    //for (Iterator itsMem = _memoryBlocks.iterator(); itsMem.hasNext(); ) {      Memory memBlock = (Memory)itsMem.next();      boolean didAllocate = allocate(memBlock, array);      int cost = cost(bGraph);      if(cost==9999) cost = _memoryBlocks.size();      if((didAllocate) && (cost-array.tryCnt<=0)) {        memBlock.subSpace(array.arraySize);	_arrToArrInfoMap.removeArray(array.var);	locFound = true;      }      else {        deAllocateArray(memBlock, array);	locFound = false;      }    }    return locFound;  }      /**  This method is used by AnalyzeHardware to decide, given a predefined

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -