mschedhash.java
来自「一种将c高级语言转化给VHDL的编译器」· Java 代码 · 共 1,684 行 · 第 1/5 页
JAVA
1,684 行
/*public Operand getNewStoreBlock(Operand op) { if(_op2StoreBlockVarMap.containsKey(op)) return (Operand)_op2StoreBlockVarMap.get(op); Operand newOp = null; if(op.isBlock()) newOp = Operand.nextBlock(op.getFullName()); else if(op.isBoolean()) newOp = Operand.nextBoolean(op.getFullName()); _op2StoreBlockVarMap.put(op, newOp); return newOp; }*/ } //end class SaveStoresNLoads /** * This nested class was created to perform analysis of whether an * instruction was scheduled so that there is space for loads and stores. */ private class LoadStoreObject { /*private class SaveLoads extends HashMap { public SaveLoads() { super(); } public int get(Operand op) { if(!containsKey(op)) return 999; return ((Integer)super.get(op)).intValue(); } public void put(Operand op, int iiCnt) { super.put(op, new Integer(iiCnt)); } public void putLoad(Operand op, int iiCnt) { put(op, Math.min(iiCnt, get(op))); } public void putLoads(Operand op, int iiCnt) { HashSet needTimes = new HashSet(); if(containsKey(op)) needTimes = (HashSet)super.get(op); else super.put(op, needTimes); needTimes.add(new Integer(iiCnt)); } public HashSet getLoads(Operand op) { return (HashSet)super.get(op); } } private class SaveStores extends HashMap { public SaveStores() { super(); } public int get(Operand op) { if(!containsKey(op)) return -999; return ((Integer)super.get(op)).intValue(); } public void put(Operand op, int iiCnt) { super.put(op, new Integer(iiCnt)); } public void putStore(Operand op, int iiCnt) { put(op, Math.max(iiCnt, get(op))); } }*/ /** to no the time necessary for a load and store, I create one of each */ private Instruction _loadInst; private Instruction _storeInst; /*private HashSet _alreadyAddedL = new HashSet(); private HashSet _alreadyAddedS = new HashSet(); private HashSet _alreadyAddedLUR = new HashSet(); private HashSet _alreadyAddedSUR = new HashSet(); private SaveLoads _loadsToAdd = new SaveLoads(); private SaveLoads _loadsToAddUR = new SaveLoads(); private SaveStores _storesToAdd = new SaveStores(); private HashMap _types = new HashMap(); private HashMap _stoptimes = new HashMap();*/ public LoadStoreObject() { //create dummy load and store instructions: Operand vartmp = Operand.newBlock("tmp1"); Operand vartmp2 = Operand.newBlock("tmp2"); _storeInst = Store.create(Operators.STORE, null, vartmp, vartmp2); //need to be able to see the selected library... _opSel.select(_storeInst); _loadInst = Load.create(Operators.LOAD, null, vartmp, vartmp2); _opSel.select(_loadInst); } /*private HashMap saveLsAndSsMap = new HashMap(); public void saveLoads(int iiCnt, HashSet inVars, MSchedInstObject cObj){ for (Iterator it1 = inVars.iterator(); it1.hasNext();) { Operand op = (Operand)it1.next(); _loadsToAdd.putLoad(op, iiCnt); _loadsToAddUR.putLoads(op, iiCnt); System.out.println("op " + op); if(saveLsAndSs) saveLsAndSsMap.put(op, new Boolean(true)); else saveLsAndSsMap.put(op, new Boolean(false)); Operand newOp = getNewLoadBlock(op); System.out.println("newOp " + newOp); cObj.replaceOperand(op, newOp); if(op.isBoolean()) { for (Iterator it = _node.getOutEdges().iterator(); it.hasNext();) { BlockEdge outEdge = (BlockEdge)it.next(); BooleanEquation eq = (BooleanEquation)outEdge.getPredicate().clone(); BooleanEquation neweq = eq.replaceBool((Bool)op, (Bool)newOp); outEdge.setPredicate(neweq); } } } } public void saveStores(int iiCnt, HashSet inVars, Type type, float stopTime, MSchedInstObject pObj){ for (Iterator it1 = inVars.iterator(); it1.hasNext();) { Operand op = (Operand)it1.next(); _storesToAdd.putStore(op, iiCnt); _types.put(op, type); _stoptimes.put(op, new Float(stopTime)); if(saveLsAndSs) saveLsAndSsMap.put(op, new Boolean(true)); else saveLsAndSsMap.put(op, new Boolean(false)); //Operand newOp = getNewStoreBlock(op); //pObj.replaceOperand(op, newOp); } }*/ /*public void addLoads(int ii) { for (Iterator it1 = _loadsToAdd.keySet().iterator(); it1.hasNext();) { Operand op = (Operand)it1.next(); if(!op.isPrimal()&&(!_alreadyAddedL.contains(op))) { Type type = (Type)_types.get(op); if(op.isBoolean()) type = Type.Bool; PrimalOperand input = getPrimal(op); Operand output = getNewLoadBlock(op); BooleanEquation trueBoolEq = new BooleanEquation(true); Instruction loadInst = Load.create(Operators.LOAD, type, output, input, trueBoolEq); _opSel.select(loadInst); MSchedInstObject loadInstObj = new MSchedInstObject(loadInst); //add((float)0, loadInstObj); loadInstObj._iiCnt=_loadsToAdd.get(op); scheduleInst(loadInstObj, 0, ii); System.out.println("scheduling load " + loadInst); if(((Boolean)saveLsAndSsMap.get(op)).booleanValue()) _kernalPredLsNSs.add(loadInst); _alreadyAddedL.add(op); } } } public void addStores(int ii) { for (Iterator it1 = _storesToAdd.keySet().iterator(); it1.hasNext();) { Operand op = (Operand)it1.next(); if(!op.isPrimal()&&(!_alreadyAddedS.contains(op))) { Type type = (Type)_types.get(op); if(op.isBoolean()) type = Type.Bool; float predStopTime = ((Float)_stoptimes.get(op)).floatValue(); PrimalOperand output = getPrimal(op); //Operand input = getNewStoreBlock(op); BooleanEquation trueBoolEq = new BooleanEquation(true); Instruction storeInst = Store.create(Operators.STORE, type, output, op, trueBoolEq); //output, input, trueBoolEq); _opSel.select(storeInst); MSchedInstObject storeInstObj = new MSchedInstObject(storeInst); CorrectStartTimes cPredStopTimeS = new CorrectStartTimes(_storeInst, _chipdef, !GlobalOptions.packInstructions); float cPredStopTime = cPredStopTimeS.getCorrectedStartTime(predStopTime); //add((float)cPredStopTime, storeInstObj); storeInstObj._iiCnt=_storesToAdd.get(op) + (int)((cPredStopTime-predStopTime)/ii); scheduleInst(storeInstObj, cPredStopTime, ii); if(((Boolean)saveLsAndSsMap.get(op)).booleanValue()) _kernalPredLsNSs.add(storeInst); _alreadyAddedS.add(op); } } } public void addUnrollLoads(int ii, float max, MSchedHash unrolledSched) { for (Iterator it1 = _loadsToAddUR.keySet().iterator(); it1.hasNext();) { Operand op = (Operand)it1.next(); if(!op.isPrimal()&&(!_alreadyAddedLUR.contains(op))) { HashSet times = _loadsToAddUR.getLoads(op); for (Iterator it = times.iterator(); it.hasNext();) { Integer time = (Integer)it.next(); float timefl = time.floatValue(); if(timefl == _loadsToAdd.get(op)) continue; Type type = (Type)_types.get(op); if(op.isBoolean()) type = Type.Bool; PrimalOperand input = getPrimal(op); Operand output = getNewLoadBlock(op); BooleanEquation trueBoolEq = new BooleanEquation(true); Instruction loadInst = Load.create(Operators.LOAD, type, output, input, trueBoolEq); _opSel.select(loadInst); MSchedInstObject loadInstObj = new MSchedInstObject(loadInst); loadInstObj._iiCnt=0; unrolledSched.scheduleInst(loadInstObj, timefl*ii, ii); } _alreadyAddedLUR.add(op); } } } public void addUnrollStores(int ii, float max, MSchedHash unrolledSched) { for (Iterator it1 = _storesToAdd.keySet().iterator(); it1.hasNext();) { Operand op = (Operand)it1.next(); if(!op.isPrimal()&&(!_alreadyAddedSUR.contains(op))) { for(float f= _storesToAdd.get(op)*ii+ii; f<max; f+=ii) { Type type = (Type)_types.get(op); float predStopTime = ((Float)_stoptimes.get(op)).floatValue(); PrimalOperand output = getPrimal(op); BooleanEquation trueBoolEq = new BooleanEquation(true); Instruction storeInst = Store.create(Operators.STORE, type, output, op, trueBoolEq); _opSel.select(storeInst); MSchedInstObject storeInstObj = new MSchedInstObject(storeInst); CorrectStartTimes cPredStopTimeS = new CorrectStartTimes(_storeInst, _chipdef, !GlobalOptions.packInstructions); float cPredStopTime = cPredStopTimeS.getCorrectedStartTime(predStopTime); //add((float)cPredStopTime, storeInstObj); storeInstObj._iiCnt=0; //float start = (int)((cPredStopTime-predStopTime)/ii); //if(start + f > max) continue; unrolledSched.scheduleInst(storeInstObj, cPredStopTime + f, ii); } _alreadyAddedSUR.add(op); } } }*/ /** these functions are used to find out how long a load or store using the choosen library would take */ public float getLoadTime() { return _loadInst.getRunLength(); } public float getStoreTime() { return _storeInst.getRunLength(); } /** check if the scheduled instruction was legaled legal spot */ public boolean testObsGenugZeitGibt(MSchedInstObject instObj, int ii) { return testObsGenugZeitGibt(instObj, ii, instObj.startTime); } /** check if potential schedule time for an instruction is legal */ public boolean testObsGenugZeitGibt(MSchedInstObject instObj, int ii, float startTime) { float storeStTime = startTime + instObj.getRunLength(); CorrectStartTimes corrStoreStTime = new CorrectStartTimes(_storeInst, _chipdef, !GlobalOptions.packInstructions); float corrStStTime = corrStoreStTime.getCorrectedStartTime(storeStTime); //if there is not enough time after the instruction is finished, for //a store to fit return false (though if the instruction has no //successors this test is unnecessary) if((corrStStTime + getStoreTime() > ii - 1)&&(!instObj.getNoSuccs())) { return false; } //if there is not enough time before the instruction for a load return //false (though if the instruction has no predecessors this test is //unnecessary) if((getLoadTime() > startTime)&&(!instObj.getNoPreds())) return false; //otherwise, alles klar! Kein problem! Nun, nach Hause mit dir! //that is, everything's cool. schedule it here, for all I care return true; } /** this method was written to test early on if a given ii will allow legal schedules. It doesn't use a start time for the instruction. It simply sees if it possible to fit, a load before it (if it has no parents) and a store after it (if it has no children). If the answer is no, we already know, this ii is too small, and stop trying to mod schedule the loop with this ii. FIX THIS? */ public boolean testIfSchedPossible(MSchedInstObject instObj, int ii) { float startTime = getLoadTime(); if(instObj.getNoPreds()) startTime = 0; CorrectStartTimes corrInstStTime = new CorrectStartTimes(instObj.inst, _chipdef, !GlobalOptions.packInstructions); float corrstartTime = corrInstStTime.getCorrectedStartTime(startTime);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?