Search in sources :

Example 26 with Thread

use of com.dat3m.dartagnan.program.Thread in project Dat3M by hernanponcedeleon.

the class Dependency method process.

private void process(Thread thread, ExecutionAnalysis exec) {
    Map<Event, Set<Writer>> jumps = new HashMap<>();
    Set<Writer> state = new HashSet<>();
    for (Register register : thread.getRegisters()) {
        state.add(new Writer(register, null));
    }
    for (Event event : thread.getEvents()) {
        // merge with incoming jumps
        Set<Writer> j = jumps.remove(event);
        if (j != null) {
            state.addAll(j);
        }
        // collecting dependencies, mixing 'data' and 'addr'
        Set<Register> registers = new HashSet<>();
        if (event instanceof RegReaderData) {
            registers.addAll(((RegReaderData) event).getDataRegs());
        }
        if (event instanceof MemEvent) {
            registers.addAll(((MemEvent) event).getAddress().getRegs());
        }
        if (!registers.isEmpty()) {
            Map<Register, State> result = new HashMap<>();
            for (Register register : registers) {
                if (register.getThreadId() == Register.NO_THREAD) {
                    continue;
                }
                State writers;
                if (register.getThreadId() != event.getThread().getId()) {
                    writers = finalWriters.get(register);
                    checkArgument(writers != null, "Helper thread %s should be listed after their creator thread %s.", thread.getId(), register.getThreadId());
                    if (writers.may.size() != 1) {
                        logger.warn("Writers {} for inter-thread register {} read by event {} of thread {}", writers.may, register, event, thread.getId());
                    }
                } else {
                    writers = process(state, register, exec);
                    if (!writers.initialized) {
                        logger.warn("Uninitialized register {} read by event {} of thread {}", register, event, thread.getId());
                    }
                }
                result.put(register, writers);
            }
            map.put(event, result);
        }
        // update state, if changed by event
        if (event instanceof RegWriter) {
            Register register = ((RegWriter) event).getResultRegister();
            if (event.cfImpliesExec()) {
                state.removeIf(e -> e.register.equals(register));
            }
            state.add(new Writer(register, event));
        }
        // copy state, if branching
        if (event instanceof CondJump) {
            jumps.computeIfAbsent(((CondJump) event).getLabel(), k -> new HashSet<>()).addAll(state);
            if (((CondJump) event).isGoto()) {
                state.clear();
            }
        }
    }
    if (!jumps.isEmpty()) {
        logger.warn("Thread {} contains jumps to removed labels {}", thread.getId(), jumps.keySet());
        for (Set<Writer> j : jumps.values()) {
            state.addAll(j);
        }
    }
    for (Register register : thread.getRegisters()) {
        finalWriters.put(register, process(state, register, exec));
    }
}
Also used : Options(org.sosy_lab.common.configuration.Options) java.util(java.util) Configuration(org.sosy_lab.common.configuration.Configuration) IntStream.range(java.util.stream.IntStream.range) Thread(com.dat3m.dartagnan.program.Thread) Collectors(java.util.stream.Collectors) MemEvent(com.dat3m.dartagnan.program.event.core.MemEvent) Context(com.dat3m.dartagnan.verification.Context) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Collectors.toList(java.util.stream.Collectors.toList) Logger(org.apache.logging.log4j.Logger) Verify.verify(com.google.common.base.Verify.verify) Program(com.dat3m.dartagnan.program.Program) Event(com.dat3m.dartagnan.program.event.core.Event) RegReaderData(com.dat3m.dartagnan.program.event.core.utils.RegReaderData) Register(com.dat3m.dartagnan.program.Register) RegWriter(com.dat3m.dartagnan.program.event.core.utils.RegWriter) CondJump(com.dat3m.dartagnan.program.event.core.CondJump) LogManager(org.apache.logging.log4j.LogManager) InvalidConfigurationException(org.sosy_lab.common.configuration.InvalidConfigurationException) CondJump(com.dat3m.dartagnan.program.event.core.CondJump) Register(com.dat3m.dartagnan.program.Register) MemEvent(com.dat3m.dartagnan.program.event.core.MemEvent) RegWriter(com.dat3m.dartagnan.program.event.core.utils.RegWriter) RegReaderData(com.dat3m.dartagnan.program.event.core.utils.RegReaderData) MemEvent(com.dat3m.dartagnan.program.event.core.MemEvent) Event(com.dat3m.dartagnan.program.event.core.Event) RegWriter(com.dat3m.dartagnan.program.event.core.utils.RegWriter)

Example 27 with Thread

use of com.dat3m.dartagnan.program.Thread in project Dat3M by hernanponcedeleon.

the class ProgramBuilder method build.

public Program build() {
    Program program = new Program(memory, format);
    buildInitThreads();
    for (Thread thread : threads.values()) {
        addChild(thread.getId(), getOrCreateLabel("END_OF_T" + thread.getId()));
        validateLabels(thread);
        program.add(thread);
        thread.setProgram(program);
    }
    program.setAss(ass);
    program.setAssFilter(assFilter);
    return program;
}
Also used : Program(com.dat3m.dartagnan.program.Program) Thread(com.dat3m.dartagnan.program.Thread)

Example 28 with Thread

use of com.dat3m.dartagnan.program.Thread in project Dat3M by hernanponcedeleon.

the class ProgramBuilder method getOrCreateRegister.

public Register getOrCreateRegister(int threadId, String name, int precision) {
    initThread(threadId);
    Thread thread = threads.get(threadId);
    if (name == null) {
        return thread.newRegister(precision);
    }
    Register register = thread.getRegister(name);
    if (register == null) {
        return thread.newRegister(name, precision);
    }
    return register;
}
Also used : Register(com.dat3m.dartagnan.program.Register) Thread(com.dat3m.dartagnan.program.Thread)

Example 29 with Thread

use of com.dat3m.dartagnan.program.Thread in project Dat3M by hernanponcedeleon.

the class ProgramBuilder method initThread.

public void initThread(String name, int id) {
    if (!threads.containsKey(id)) {
        Skip threadEntry = EventFactory.newSkip();
        threadEntry.setOId(lastOrigId++);
        threads.putIfAbsent(id, new Thread(name, id, threadEntry));
    }
}
Also used : Skip(com.dat3m.dartagnan.program.event.core.Skip) Thread(com.dat3m.dartagnan.program.Thread)

Example 30 with Thread

use of com.dat3m.dartagnan.program.Thread in project Dat3M by hernanponcedeleon.

the class ProgramBuilder method buildInitThreads.

private void buildInitThreads() {
    int nextThreadId = nextThreadId();
    for (MemoryObject a : memory.getObjects()) {
        for (int i = 0; i < a.size(); i++) {
            Event e = EventFactory.newInit(a, i);
            Thread thread = new Thread(nextThreadId, e);
            threads.put(nextThreadId, thread);
            nextThreadId++;
        }
    }
}
Also used : MemoryObject(com.dat3m.dartagnan.program.memory.MemoryObject) Event(com.dat3m.dartagnan.program.event.core.Event) Thread(com.dat3m.dartagnan.program.Thread)

Aggregations

Thread (com.dat3m.dartagnan.program.Thread)48 Event (com.dat3m.dartagnan.program.event.core.Event)27 Tuple (com.dat3m.dartagnan.wmm.utils.Tuple)13 TupleSet (com.dat3m.dartagnan.wmm.utils.TupleSet)11 LogManager (org.apache.logging.log4j.LogManager)10 Logger (org.apache.logging.log4j.Logger)10 BooleanFormula (org.sosy_lab.java_smt.api.BooleanFormula)9 BooleanFormulaManager (org.sosy_lab.java_smt.api.BooleanFormulaManager)9 Program (com.dat3m.dartagnan.program.Program)8 Tag (com.dat3m.dartagnan.program.event.Tag)8 Configuration (org.sosy_lab.common.configuration.Configuration)8 InvalidConfigurationException (org.sosy_lab.common.configuration.InvalidConfigurationException)8 MemEvent (com.dat3m.dartagnan.program.event.core.MemEvent)7 Collectors (java.util.stream.Collectors)7 Context (com.dat3m.dartagnan.verification.Context)6 Preconditions (com.google.common.base.Preconditions)6 FilterBasic (com.dat3m.dartagnan.program.filter.FilterBasic)5 Options (org.sosy_lab.common.configuration.Options)5 Utils.generalEqual (com.dat3m.dartagnan.expression.utils.Utils.generalEqual)4 RegWriter (com.dat3m.dartagnan.program.event.core.utils.RegWriter)4