Search in sources :

Example 1 with AccessCostInfo

use of com.jopdesign.wcet.analysis.cache.ObjectCacheAnalysis.AccessCostInfo in project jop by jop-devel.

the class ObjectCacheAnalysis method addObjectCacheCostEdges.

/**
 * @param segment
 * @param usedRefs
 * @param costModel
 * @param ipetSolver
 * @return
 */
private ObjectCacheIPETModel addObjectCacheCostEdges(Segment segment, LocalPointsToResult usedRefs, ObjectCacheCostModel costModel, IPETSolver<SuperGraphEdge> ipetSolver) {
    final AccessCostInfo accessCostInfo = extractAccessesAndCosts(segment, usedRefs, costModel);
    ObjectCacheIPETModel model = new ObjectCacheIPETModel();
    model.accessCostInfo = accessCostInfo;
    /* cache cost edges (bypass/always miss) */
    model.staticCostEdges = addFixedCostEdges(segment.getEdges(), ipetSolver, new MiscUtils.F1<SuperGraphEdge, Long>() {

        @Override
        public Long apply(SuperGraphEdge v) {
            return accessCostInfo.getStaticCost(v.getTarget());
        }
    }, KEY + "_static", 0);
    /* cache cost edges (miss once) */
    /* for references */
    model.refMissEdges = addPersistenceSegmentConstraints(segment, accessCostInfo.getRefAccesses(segment), ipetSolver, MiscUtils.<SuperGraphEdge, Long>const1(costModel.getReplaceLineCost()), KEY + "_ref");
    /* and for blocks */
    model.blockMissEdges = addPersistenceSegmentConstraints(segment, accessCostInfo.getBlockAccesses(segment), ipetSolver, MiscUtils.<SuperGraphEdge, Long>const1(costModel.getLoadCacheBlockCost()), KEY + "_block");
    return model;
}
Also used : AccessCostInfo(com.jopdesign.wcet.analysis.cache.ObjectCacheAnalysis.AccessCostInfo) SuperGraphEdge(com.jopdesign.common.code.SuperGraph.SuperGraphEdge) F1(com.jopdesign.common.misc.MiscUtils.F1)

Example 2 with AccessCostInfo

use of com.jopdesign.wcet.analysis.cache.ObjectCacheAnalysis.AccessCostInfo in project jop by jop-devel.

the class ObjectCacheAnalysis method extractAccessesAndCosts.

/**
 * Traverse vertex set.
 * <p>Add vertex to access set of referenced addresses
 * For references whose type cannot be fully resolved, add a
 * cost of 1.</p>
 * <p>FIXME: We should deal with subtyping (or better use storage based alias-analysis)</p>
 *
 * @param nodes
 * @param usedRefs the results of the local points-to analysis, or {@code null} for always miss costs
 * @param costModel
 */
private AccessCostInfo extractAccessesAndCosts(Iterable<SuperGraphNode> nodes, LocalPointsToResult usedRefs, ObjectCacheCostModel costModel) {
    AccessCostInfo aci = new AccessCostInfo();
    for (SuperGraphNode node : nodes) {
        /* Compute cost for basic block */
        BasicBlock bb = node.getCFGNode().getBasicBlock();
        if (bb == null)
            continue;
        long bypassCost = 0;
        long alwaysMissCost = 0;
        CallString cs = node.getContextCFG().getCallString();
        for (InstructionHandle ih : bb.getInstructions()) {
            String handleType = getHandleType(project, node.getCfg(), ih);
            if (handleType == null)
                continue;
            /* No getfield/handle access */
            int fieldIndex = getFieldIndex(project, node.getCfg(), ih);
            int blockIndex = getBlockIndex(fieldIndex);
            if (fieldIndex > this.maxCachedFieldIndex) {
                bypassCost += costModel.getFieldAccessCostBypass();
                continue;
            }
            BoundedSet<SymbolicAddress> refs = null;
            if (usedRefs != null) {
                if (!usedRefs.containsKey(ih)) {
                    usedRefs = null;
                    WCETTool.logger.error("No DFA results for: " + ih.getInstruction() + " with field " + ((FieldInstruction) ih.getInstruction()).getFieldName(bb.cpg()));
                } else {
                    refs = usedRefs.get(ih, cs);
                    if (refs.isSaturated())
                        refs = null;
                }
            }
            if (refs == null) {
                alwaysMissCost += costModel.getReplaceLineCost() + costModel.getLoadCacheBlockCost();
            } else {
                for (SymbolicAddress ref : refs.getSet()) {
                    aci.addRefAccess(ref, node);
                    aci.addBlockAccess(ref.accessArray(blockIndex), node);
                    // Handle getfield_long / getfield_double
                    if (getCachedType(project, node.getCfg(), ih) == Type.LONG || getCachedType(project, node.getCfg(), ih) == Type.DOUBLE) {
                        if (blockIndex + 1 > this.maxCachedFieldIndex) {
                            bypassCost += costModel.getFieldAccessCostBypass();
                        } else {
                            aci.addBlockAccess(ref.accessArray(blockIndex + 1), node);
                        }
                    }
                }
            }
        }
        aci.putBypassCost(node, bypassCost);
        aci.putStaticCost(node, bypassCost + alwaysMissCost);
    }
    return aci;
}
Also used : AccessCostInfo(com.jopdesign.wcet.analysis.cache.ObjectCacheAnalysis.AccessCostInfo) BasicBlock(com.jopdesign.common.code.BasicBlock) SuperGraphNode(com.jopdesign.common.code.SuperGraph.SuperGraphNode) CallString(com.jopdesign.common.code.CallString) FieldInstruction(org.apache.bcel.generic.FieldInstruction) SymbolicAddress(com.jopdesign.dfa.analyses.SymbolicAddress) InstructionHandle(org.apache.bcel.generic.InstructionHandle) CallString(com.jopdesign.common.code.CallString)

Example 3 with AccessCostInfo

use of com.jopdesign.wcet.analysis.cache.ObjectCacheAnalysis.AccessCostInfo in project jop by jop-devel.

the class ObjectCacheAnalysis method addMissOnceCost.

/**
 * Add miss once cost: for each method cache persistence segment, add maximum miss cost to the segment entries
 * @param segment
 * @param ipetSolver
 * @param checks
 * @throws LpSolveException
 * @throws InvalidFlowFactException
 */
@Override
public Set<SuperGraphEdge> addMissOnceCost(Segment segment, IPETSolver<SuperGraphEdge> ipetSolver, EnumSet<PersistenceCheck> checks) throws InvalidFlowFactException, LpSolveException {
    Set<SuperGraphEdge> missCostEdges = new HashSet<SuperGraphEdge>();
    Set<SuperGraphNode> alwaysMissNodes = new HashSet<SuperGraphNode>();
    Collection<Segment> cover = findPersistenceSegmentCover(segment, EnumSet.allOf(PersistenceCheck.class), false, alwaysMissNodes);
    int tag = 0;
    for (Segment persistenceSegment : cover) {
        tag++;
        /* Compute cost for persistence segment */
        HashSet<SymbolicAddress> usedSetOut = new HashSet<SymbolicAddress>();
        ObjectCacheCost cost = computeCacheCost(persistenceSegment, getUsedRefs(persistenceSegment), objectCache.getCostModel(), usedSetOut);
        WCETTool.logger.info("O$-addMissOnceCost: " + cost.toString());
        F1<SuperGraphEdge, Long> costModel = MiscUtils.const1(cost.getCost());
        Set<SuperGraphEdge> costEdges = addFixedCostEdges(persistenceSegment.getEntryEdges(), ipetSolver, costModel, KEY + "_miss_once", tag);
        missCostEdges.addAll(costEdges);
    }
    AccessCostInfo alwaysMissAccessInfo = extractAccessesAndCosts(alwaysMissNodes, null, objectCache.getCostModel());
    missCostEdges.addAll(addStaticCost(segment, alwaysMissAccessInfo, ipetSolver));
    return missCostEdges;
}
Also used : ObjectCacheCost(com.jopdesign.wcet.jop.ObjectCache.ObjectCacheCost) Segment(com.jopdesign.common.code.Segment) AccessCostInfo(com.jopdesign.wcet.analysis.cache.ObjectCacheAnalysis.AccessCostInfo) SuperGraphEdge(com.jopdesign.common.code.SuperGraph.SuperGraphEdge) SuperGraphNode(com.jopdesign.common.code.SuperGraph.SuperGraphNode) SymbolicAddress(com.jopdesign.dfa.analyses.SymbolicAddress) HashSet(java.util.HashSet)

Example 4 with AccessCostInfo

use of com.jopdesign.wcet.analysis.cache.ObjectCacheAnalysis.AccessCostInfo in project jop by jop-devel.

the class ObjectCacheAnalysis method addMissOnceConstraints.

/**
 * Add miss once constraints for all subsegments in the persistence cover of the given segment
 * @param segment
 * @param ipetSolver
 * @return
 * @throws LpSolveException
 * @throws InvalidFlowFactException
 */
@Override
public Set<SuperGraphEdge> addMissOnceConstraints(Segment segment, IPETSolver<SuperGraphEdge> ipetSolver) throws InvalidFlowFactException, LpSolveException {
    Set<SuperGraphEdge> missEdges = new HashSet<SuperGraphEdge>();
    Set<SuperGraphNode> alwaysMissNodes = new HashSet<SuperGraphNode>();
    Collection<Segment> cover = findPersistenceSegmentCover(segment, EnumSet.allOf(PersistenceCheck.class), false, alwaysMissNodes);
    int segmentCounter = 0;
    for (Segment persistenceSegment : cover) {
        /* we need to distinguish edges which are shared between persistence segments */
        String key = KEY + "_" + (++segmentCounter);
        LocalPointsToResult usedRefs = getUsedRefs(persistenceSegment);
        /* Compute worst-case cost */
        HashSet<SymbolicAddress> usedObjectsSet = new HashSet<SymbolicAddress>();
        ObjectCacheIPETModel ocim = addObjectCacheCostEdges(persistenceSegment, usedRefs, objectCache.getCostModel(), ipetSolver);
        missEdges.addAll(ocim.staticCostEdges);
        missEdges.addAll(ocim.refMissEdges);
        missEdges.addAll(ocim.blockMissEdges);
    }
    AccessCostInfo alwaysMissAccessInfo = extractAccessesAndCosts(alwaysMissNodes, null, objectCache.getCostModel());
    missEdges.addAll(addStaticCost(segment, alwaysMissAccessInfo, ipetSolver));
    return missEdges;
}
Also used : CallString(com.jopdesign.common.code.CallString) Segment(com.jopdesign.common.code.Segment) AccessCostInfo(com.jopdesign.wcet.analysis.cache.ObjectCacheAnalysis.AccessCostInfo) SuperGraphEdge(com.jopdesign.common.code.SuperGraph.SuperGraphEdge) SuperGraphNode(com.jopdesign.common.code.SuperGraph.SuperGraphNode) SymbolicAddress(com.jopdesign.dfa.analyses.SymbolicAddress) HashSet(java.util.HashSet)

Aggregations

AccessCostInfo (com.jopdesign.wcet.analysis.cache.ObjectCacheAnalysis.AccessCostInfo)4 SuperGraphEdge (com.jopdesign.common.code.SuperGraph.SuperGraphEdge)3 SuperGraphNode (com.jopdesign.common.code.SuperGraph.SuperGraphNode)3 SymbolicAddress (com.jopdesign.dfa.analyses.SymbolicAddress)3 CallString (com.jopdesign.common.code.CallString)2 Segment (com.jopdesign.common.code.Segment)2 HashSet (java.util.HashSet)2 BasicBlock (com.jopdesign.common.code.BasicBlock)1 F1 (com.jopdesign.common.misc.MiscUtils.F1)1 ObjectCacheCost (com.jopdesign.wcet.jop.ObjectCache.ObjectCacheCost)1 FieldInstruction (org.apache.bcel.generic.FieldInstruction)1 InstructionHandle (org.apache.bcel.generic.InstructionHandle)1