Search in sources :

Example 6 with Relation

use of com.dat3m.dartagnan.wmm.relation.Relation in project Dat3M by hernanponcedeleon.

the class VisitorRelation method visitExprCartesian.

@Override
public Relation visitExprCartesian(CatParser.ExprCartesianContext ctx) {
    boolean orig = base.recursiveDef;
    base.recursiveDef = false;
    FilterAbstract filter1 = ctx.e1.accept(base.filterVisitor);
    FilterAbstract filter2 = ctx.e2.accept(base.filterVisitor);
    Relation relation = base.relationRepository.getRelation(RelCartesian.class, filter1, filter2);
    base.recursiveDef = orig;
    return relation;
}
Also used : RecursiveRelation(com.dat3m.dartagnan.wmm.relation.RecursiveRelation) Relation(com.dat3m.dartagnan.wmm.relation.Relation) FilterAbstract(com.dat3m.dartagnan.program.filter.FilterAbstract)

Example 7 with Relation

use of com.dat3m.dartagnan.wmm.relation.Relation in project Dat3M by hernanponcedeleon.

the class ExecutionGraph method getOrCreateGraphFromRelation.

private RelationGraph getOrCreateGraphFromRelation(Relation rel) {
    if (relationGraphMap.containsKey(rel)) {
        return relationGraphMap.get(rel);
    }
    RelationGraph graph;
    Class<?> relClass = rel.getClass();
    // ===== Filter special relations ======
    if (SPECIAL_RELS.contains(rel.getName())) {
        switch(rel.getName()) {
            case CTRL:
                graph = new CtrlDepGraph();
                break;
            case DATA:
                graph = new DataDepGraph();
                break;
            case ADDR:
                graph = new AddrDepGraph();
                break;
            case CRIT:
                graph = new RcuGraph();
                break;
            default:
                throw new UnsupportedOperationException(rel.getName() + " is marked as special relation but has associated graph.");
        }
    } else if (relClass == RelRf.class) {
        graph = new ReadFromGraph();
    } else if (relClass == RelLoc.class) {
        graph = new LocationGraph();
    } else if (relClass == RelPo.class) {
        graph = new ProgramOrderGraph();
    } else if (relClass == RelCo.class) {
        graph = new CoherenceGraph();
    } else if (rel.isRecursiveRelation()) {
        RecursiveGraph recGraph = new RecursiveGraph();
        recGraph.setName(rel.getName() + "_rec");
        relationGraphMap.put(rel, recGraph);
        recGraph.setConcreteGraph(getOrCreateGraphFromRelation(rel.getInner()));
        return recGraph;
    } else if (rel.isUnaryRelation()) {
        Relation innerRelation = rel.getInner();
        RelationGraph innerGraph = getOrCreateGraphFromRelation(innerRelation);
        // A safety check because recursion might have computed this RelationGraph already
        if (relationGraphMap.containsKey(rel)) {
            return relationGraphMap.get(rel);
        }
        if (relClass == RelInverse.class) {
            graph = new InverseGraph(innerGraph);
        } else if (relClass == RelTrans.class) {
            graph = new TransitiveGraph(innerGraph);
        } else if (relClass == RelRangeIdentity.class) {
            graph = new RangeIdentityGraph(innerGraph);
        } else if (relClass == RelTransRef.class) {
            // FIXME: This is very, very sketchy and instead of doing this
            // a WmmProcessor should run that transforms the wmm accordingly.
            RelTrans relTrans = new RelTrans(innerRelation);
            RelationGraph transGraph = getOrCreateGraphFromRelation(relTrans);
            graph = new ReflexiveClosureGraph(transGraph);
        } else {
            throw new UnsupportedOperationException(relClass.toString() + " has no associated graph yet.");
        }
    } else if (rel.isBinaryRelation()) {
        RelationGraph first = getOrCreateGraphFromRelation(rel.getFirst());
        RelationGraph second = getOrCreateGraphFromRelation(rel.getSecond());
        // A safety check because recursion might have computed this RelationGraph already
        if (relationGraphMap.containsKey(rel)) {
            return relationGraphMap.get(rel);
        }
        if (relClass == RelUnion.class) {
            graph = new UnionGraph(first, second);
        } else if (relClass == RelIntersection.class) {
            graph = new IntersectionGraph(first, second);
        } else if (relClass == RelComposition.class) {
            graph = new CompositionGraph(first, second);
        } else if (relClass == RelMinus.class) {
            graph = new DifferenceGraph(first, second);
        } else {
            throw new UnsupportedOperationException(relClass.toString() + " has no associated graph yet.");
        }
    } else if (rel.isStaticRelation()) {
        if (relClass == RelCartesian.class) {
            RelCartesian cartRel = (RelCartesian) rel;
            SetPredicate lhs = getOrCreateSetFromFilter(cartRel.getFirstFilter());
            SetPredicate rhs = getOrCreateSetFromFilter(cartRel.getSecondFilter());
            graph = new CartesianGraph(lhs, rhs);
        } else if (relClass == RelRMW.class) {
            graph = new RMWGraph();
        } else if (relClass == RelExt.class) {
            graph = new ExternalGraph();
        } else if (relClass == RelInt.class) {
            graph = new InternalGraph();
        } else if (relClass == RelFencerel.class) {
            graph = new FenceGraph(((RelFencerel) rel).getFenceName());
        } else if (relClass == RelSetIdentity.class) {
            SetPredicate set = getOrCreateSetFromFilter(((RelSetIdentity) rel).getFilter());
            graph = new SetIdentityGraph(set);
        } else if (relClass == RelId.class) {
            graph = new IdentityGraph();
        } else if (relClass == RelEmpty.class) {
            graph = new EmptyGraph();
        } else {
            // This is a fallback for all unimplemented static graphs
            graph = new StaticDefaultWMMGraph(rel);
        }
    } else {
        throw new UnsupportedOperationException(relClass.toString() + " has no associated graph yet.");
    }
    graph.setName(rel.getName());
    relationGraphMap.put(rel, graph);
    return graph;
}
Also used : IdentityGraph(com.dat3m.dartagnan.solver.caat.predicates.relationGraphs.base.IdentityGraph) RelRMW(com.dat3m.dartagnan.wmm.relation.base.RelRMW) Relation(com.dat3m.dartagnan.wmm.relation.Relation) SetPredicate(com.dat3m.dartagnan.solver.caat.predicates.sets.SetPredicate) RelComposition(com.dat3m.dartagnan.wmm.relation.binary.RelComposition) RelTransRef(com.dat3m.dartagnan.wmm.relation.unary.RelTransRef) RelationGraph(com.dat3m.dartagnan.solver.caat.predicates.relationGraphs.RelationGraph) RelUnion(com.dat3m.dartagnan.wmm.relation.binary.RelUnion) RelTrans(com.dat3m.dartagnan.wmm.relation.unary.RelTrans) EmptyGraph(com.dat3m.dartagnan.solver.caat.predicates.relationGraphs.base.EmptyGraph) RelRf(com.dat3m.dartagnan.wmm.relation.base.memory.RelRf)

Example 8 with Relation

use of com.dat3m.dartagnan.wmm.relation.Relation in project Dat3M by hernanponcedeleon.

the class Refiner method permuteAndConvert.

// Changes a reasoning <literal> based on a given permutation <perm> and translates the result
// into a BooleanFormula for Refinement.
private BooleanFormula permuteAndConvert(CoreLiteral literal, Function<Event, Event> perm, SolverContext context) {
    BooleanFormulaManager bmgr = context.getFormulaManager().getBooleanFormulaManager();
    BooleanFormula enc;
    if (literal instanceof ExecLiteral) {
        ExecLiteral lit = (ExecLiteral) literal;
        enc = perm.apply(lit.getData()).exec();
    } else if (literal instanceof AddressLiteral) {
        AddressLiteral loc = (AddressLiteral) literal;
        MemEvent e1 = (MemEvent) perm.apply(loc.getFirst());
        MemEvent e2 = (MemEvent) perm.apply(loc.getSecond());
        enc = generalEqual(e1.getMemAddressExpr(), e2.getMemAddressExpr(), context);
    } else if (literal instanceof RelLiteral) {
        RelLiteral lit = (RelLiteral) literal;
        Relation rel = task.getMemoryModel().getRelationRepository().getRelation(lit.getName());
        enc = rel.getSMTVar(perm.apply(lit.getData().getFirst()), perm.apply(lit.getData().getSecond()), context);
    } else {
        throw new IllegalArgumentException("CoreLiteral " + literal.toString() + " is not supported");
    }
    return literal.isNegative() ? bmgr.not(enc) : enc;
}
Also used : ExecLiteral(com.dat3m.dartagnan.solver.caat4wmm.coreReasoning.ExecLiteral) Relation(com.dat3m.dartagnan.wmm.relation.Relation) BooleanFormulaManager(org.sosy_lab.java_smt.api.BooleanFormulaManager) MemEvent(com.dat3m.dartagnan.program.event.core.MemEvent) AddressLiteral(com.dat3m.dartagnan.solver.caat4wmm.coreReasoning.AddressLiteral) RelLiteral(com.dat3m.dartagnan.solver.caat4wmm.coreReasoning.RelLiteral) BooleanFormula(org.sosy_lab.java_smt.api.BooleanFormula)

Example 9 with Relation

use of com.dat3m.dartagnan.wmm.relation.Relation in project Dat3M by hernanponcedeleon.

the class RelationAnalysis method run.

private void run(VerificationTask task, Context context) {
    // Init data context so that each relation is able to compute its may/must sets.
    Wmm memoryModel = task.getMemoryModel();
    for (Axiom ax : memoryModel.getAxioms()) {
        ax.getRelation().updateRecursiveGroupId(ax.getRelation().getRecursiveGroupId());
    }
    for (RecursiveGroup recursiveGroup : memoryModel.getRecursiveGroups()) {
        recursiveGroup.setDoRecurse();
    }
    // ------------------------------------------------
    for (String relName : Wmm.BASE_RELATIONS) {
        memoryModel.getRelationRepository().getRelation(relName).initializeRelationAnalysis(task, context);
    }
    for (Relation rel : memoryModel.getRelationRepository().getRelations()) {
        rel.initializeRelationAnalysis(task, context);
    }
    for (Axiom ax : memoryModel.getAxioms()) {
        ax.initializeRelationAnalysis(task, context);
    }
    // ------------------------------------------------
    for (String relName : Wmm.BASE_RELATIONS) {
        Relation baseRel = memoryModel.getRelationRepository().getRelation(relName);
        baseRel.getMaxTupleSet();
        baseRel.getMinTupleSet();
    }
    for (RecursiveGroup recursiveGroup : memoryModel.getRecursiveGroups()) {
        recursiveGroup.initMaxTupleSets();
        recursiveGroup.initMinTupleSets();
    }
    for (Axiom ax : memoryModel.getAxioms()) {
        ax.getRelation().getMaxTupleSet();
        ax.getRelation().getMinTupleSet();
    }
}
Also used : Relation(com.dat3m.dartagnan.wmm.relation.Relation) RecursiveGroup(com.dat3m.dartagnan.wmm.utils.RecursiveGroup) Wmm(com.dat3m.dartagnan.wmm.Wmm) Axiom(com.dat3m.dartagnan.wmm.axiom.Axiom)

Example 10 with Relation

use of com.dat3m.dartagnan.wmm.relation.Relation in project Dat3M by hernanponcedeleon.

the class RecursiveGroup method updateEncodeTupleSets.

public void updateEncodeTupleSets() {
    Map<Relation, Integer> encodeSetSizes = new HashMap<>();
    for (Relation relation : relations) {
        encodeSetSizes.put(relation, 0);
    }
    boolean changed = true;
    while (changed) {
        changed = false;
        for (RecursiveRelation relation : relations) {
            relation.setDoRecurse();
            relation.addEncodeTupleSet(relation.getEncodeTupleSet());
            int newSize = relation.getEncodeTupleSet().size();
            if (newSize != encodeSetSizes.get(relation)) {
                encodeSetSizes.put(relation, newSize);
                changed = true;
            }
        }
    }
}
Also used : RecursiveRelation(com.dat3m.dartagnan.wmm.relation.RecursiveRelation) Relation(com.dat3m.dartagnan.wmm.relation.Relation) RecursiveRelation(com.dat3m.dartagnan.wmm.relation.RecursiveRelation)

Aggregations

Relation (com.dat3m.dartagnan.wmm.relation.Relation)15 RecursiveRelation (com.dat3m.dartagnan.wmm.relation.RecursiveRelation)9 ParsingException (com.dat3m.dartagnan.exception.ParsingException)3 FilterAbstract (com.dat3m.dartagnan.program.filter.FilterAbstract)3 RelationGraph (com.dat3m.dartagnan.solver.caat.predicates.relationGraphs.RelationGraph)2 Wmm (com.dat3m.dartagnan.wmm.Wmm)2 Axiom (com.dat3m.dartagnan.wmm.axiom.Axiom)2 RelComposition (com.dat3m.dartagnan.wmm.relation.binary.RelComposition)2 RelUnion (com.dat3m.dartagnan.wmm.relation.binary.RelUnion)2 RelationRepository (com.dat3m.dartagnan.wmm.utils.RelationRepository)2 CatParser (com.dat3m.dartagnan.parsers.CatParser)1 Event (com.dat3m.dartagnan.program.event.core.Event)1 MemEvent (com.dat3m.dartagnan.program.event.core.MemEvent)1 AcyclicityConstraint (com.dat3m.dartagnan.solver.caat.constraints.AcyclicityConstraint)1 Constraint (com.dat3m.dartagnan.solver.caat.constraints.Constraint)1 EmptinessConstraint (com.dat3m.dartagnan.solver.caat.constraints.EmptinessConstraint)1 IrreflexivityConstraint (com.dat3m.dartagnan.solver.caat.constraints.IrreflexivityConstraint)1 Edge (com.dat3m.dartagnan.solver.caat.predicates.relationGraphs.Edge)1 EmptyGraph (com.dat3m.dartagnan.solver.caat.predicates.relationGraphs.base.EmptyGraph)1 IdentityGraph (com.dat3m.dartagnan.solver.caat.predicates.relationGraphs.base.IdentityGraph)1