Search in sources :

Example 1 with BeginAtomic

use of com.dat3m.dartagnan.program.event.lang.svcomp.BeginAtomic in project Dat3M by hernanponcedeleon.

the class AtomicAsLock method run.

private void run(MemoryObject address, Thread thread) {
    Label end;
    if (thread.getExit() instanceof Label) {
        end = (Label) thread.getExit();
    } else {
        end = newLabel("__VERIFIER_atomic_thread_end");
        thread.getExit().setSuccessor(end);
        thread.updateExit(end);
    }
    Register register = thread.newRegister(ARCH_PRECISION);
    for (Event predecessor = thread.getEntry(); predecessor != null; ) {
        Event event = predecessor.getSuccessor();
        boolean begin = event instanceof BeginAtomic;
        if (begin || event instanceof EndAtomic) {
            Event load = EventFactory.newLoad(register, address, null);
            Event check = EventFactory.newJump(new Atom(register, NEQ, begin ? IValue.ZERO : IValue.ONE), end);
            Event store = EventFactory.newStore(address, begin ? IValue.ONE : IValue.ZERO, null);
            load.setOId(event.getOId());
            check.setOId(event.getOId());
            store.setOId(event.getOId());
            load.addFilters(Tag.C11.LOCK, Tag.RMW);
            check.addFilters(Tag.C11.LOCK, Tag.RMW);
            store.addFilters(Tag.C11.LOCK, Tag.RMW);
            predecessor.setSuccessor(load);
            load.setSuccessor(check);
            check.setSuccessor(store);
            store.setSuccessor(event.getSuccessor());
            predecessor = store;
        } else {
            predecessor = event;
        }
    }
}
Also used : EndAtomic(com.dat3m.dartagnan.program.event.lang.svcomp.EndAtomic) Register(com.dat3m.dartagnan.program.Register) BeginAtomic(com.dat3m.dartagnan.program.event.lang.svcomp.BeginAtomic) Label(com.dat3m.dartagnan.program.event.core.Label) EventFactory.newLabel(com.dat3m.dartagnan.program.event.EventFactory.newLabel) Event(com.dat3m.dartagnan.program.event.core.Event) Atom(com.dat3m.dartagnan.expression.Atom)

Example 2 with BeginAtomic

use of com.dat3m.dartagnan.program.event.lang.svcomp.BeginAtomic in project Dat3M by hernanponcedeleon.

the class ExecutionModel method extractEventsFromModel.

// ========================== Internal methods  =========================
private void extractEventsFromModel() {
    // TODO(TH): We might also want to extract events such as inline assertions
    // and whether they were violated or not.
    int id = 0;
    eventList.clear();
    threadList.clear();
    threadEventsMap.clear();
    atomicBlocksMap.clear();
    // This one can probably be constant and need not be rebuilt!
    addressInitMap.clear();
    addressWritesMap.clear();
    addressReadsMap.clear();
    writeReadsMap.clear();
    fenceMap.clear();
    eventMap.clear();
    addrDepMap.clear();
    dataDepMap.clear();
    ctrlDepMap.clear();
    List<Thread> threadList = new ArrayList<>(getProgram().getThreads());
    List<Integer> threadEndIndexList = new ArrayList<>(threadList.size());
    Map<Thread, List<List<Integer>>> atomicBlockRangesMap = new HashMap<>();
    for (Thread thread : threadList) {
        initDepTracking();
        List<List<Integer>> atomicBlockRanges = atomicBlockRangesMap.computeIfAbsent(thread, key -> new ArrayList<>());
        Event e = thread.getEntry();
        int atomicBegin = -1;
        int localId = 0;
        do {
            if (!e.wasExecuted(model)) {
                e = e.getSuccessor();
                continue;
            }
            if (eventFilter.filter(e)) {
                addEvent(e, id++, localId++);
            }
            trackDependencies(e);
            // ===== Atomic blocks =====
            if (e instanceof BeginAtomic) {
                atomicBegin = id;
            } else if (e instanceof EndAtomic) {
                Preconditions.checkState(atomicBegin != -1, "EndAtomic without matching BeginAtomic in model");
                atomicBlockRanges.add(ImmutableList.of(atomicBegin, id));
                atomicBegin = -1;
            }
            if (e instanceof CondJump) {
                CondJump jump = (CondJump) e;
                if (jump.didJump(model, context)) {
                    e = jump.getLabel();
                    continue;
                }
            }
            e = e.getSuccessor();
        } while (e != null);
        // We have a BeginAtomic without EndAtomic since the program terminated within the block
        if (atomicBegin != -1) {
            atomicBlockRanges.add(ImmutableList.of(atomicBegin, id));
        }
        // -----------
        threadEndIndexList.add(id);
    }
    // Get sublists for all threads
    int start = 0;
    for (int i = 0; i < threadList.size(); i++) {
        Thread thread = threadList.get(i);
        int end = threadEndIndexList.get(i);
        if (start != end) {
            this.threadList.add(thread);
            threadEventsMap.put(thread, Collections.unmodifiableList(eventList.subList(start, end)));
            atomicBlocksMap.put(thread, new ArrayList<>());
            for (List<Integer> aRange : atomicBlockRangesMap.get(thread)) {
                atomicBlocksMap.get(thread).add(eventList.subList(aRange.get(0), aRange.get(1)));
            }
        }
        start = end;
    }
}
Also used : EndAtomic(com.dat3m.dartagnan.program.event.lang.svcomp.EndAtomic) Thread(com.dat3m.dartagnan.program.Thread) BigInteger(java.math.BigInteger) BeginAtomic(com.dat3m.dartagnan.program.event.lang.svcomp.BeginAtomic) ImmutableList(com.google.common.collect.ImmutableList)

Aggregations

BeginAtomic (com.dat3m.dartagnan.program.event.lang.svcomp.BeginAtomic)2 EndAtomic (com.dat3m.dartagnan.program.event.lang.svcomp.EndAtomic)2 Atom (com.dat3m.dartagnan.expression.Atom)1 Register (com.dat3m.dartagnan.program.Register)1 Thread (com.dat3m.dartagnan.program.Thread)1 EventFactory.newLabel (com.dat3m.dartagnan.program.event.EventFactory.newLabel)1 Event (com.dat3m.dartagnan.program.event.core.Event)1 Label (com.dat3m.dartagnan.program.event.core.Label)1 ImmutableList (com.google.common.collect.ImmutableList)1 BigInteger (java.math.BigInteger)1