Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# REQUIRES: skip-snippy-model-mixin
# RUN: llvm-snippy %s -mtriple=riscv64 --model-plugin=None -num-instrs=10 \
# RUN: --init-regs-in-elf \
# RUN: --dump-initial-registers-yaml=%t.initial-regs.yaml
# RUN: FileCheck %s --input-file=%t.initial-regs.yaml

# RUN: llvm-snippy %s -mtriple=riscv64 --model-plugin=None -num-instrs=10 \
# RUN: --initial-regs-yaml=%t.initial-regs.yaml \
# RUN: --dump-initial-registers-yaml=%t.reloaded-regs.yaml
# RUN: diff %t.initial-regs.yaml %t.reloaded-regs.yaml

# RUN: not llvm-snippy %s -mtriple=riscv64 --model-plugin=None -num-instrs=10 \
# RUN: --dump-initial-registers-yaml=%t.initial-regs.yaml/invalid 2>&1 \
# RUN: | FileCheck %s --check-prefix=ERROR

# CHECK: registers:
# CHECK-NEXT: - [ X0, 0x0000000000000000 ]
# CHECK: - [ X31, 0x{{([[:xdigit:]]{16})}} ]
# ERROR: error: Register dump error:

include:
- "../../Inputs/sections.yaml"

histogram:
- [ADD, 1]
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ struct IRegisterState {
virtual void loadFromYamlFile(StringRef, WarningsT &,
const SnippyTarget *Tgt = nullptr) = 0;
virtual void saveAsYAMLFile(raw_ostream &) const = 0;
void saveAsYAMLFile(StringRef YamlPath) const;

virtual bool operator==(const IRegisterState &) const = 0;
bool operator!=(const IRegisterState &Another) const {
Expand Down
10 changes: 10 additions & 0 deletions llvm/tools/llvm-snippy/lib/FlowGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,16 @@ GeneratorResult FlowGenerator::generate(LLVMState &State,

} else {

if (auto &YamlPath = PassCfg.RegistersConfig.InitialStateOutputYaml;
!YamlPath.empty()) {
auto *EntryFunc =
MainModule.getModule().getFunction(ProgramCfg.EntryPointName);
assert(EntryFunc);
auto &ST = State.getSubtargetImpl(*EntryFunc);
auto &RegState = ProgContext.getInitialRegisterState(ST);
RegState.saveAsYAMLFile(YamlPath);
}

snippy::warn(WarningName::NoModelExec, State.getCtx(),
"Skipping snippet execution on the model",
"model was set to 'None'.");
Expand Down
10 changes: 1 addition & 9 deletions llvm/tools/llvm-snippy/lib/Generator/Interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,15 +331,7 @@ void Interpreter::dumpRegsAsYAML(const IRegisterState &Regs, raw_ostream &OS) {
}

void Interpreter::dumpRegs(const IRegisterState &Regs, StringRef YamlPath) {
if (YamlPath.empty())
return;

std::error_code EC;
raw_fd_ostream File(YamlPath, EC);
if (EC)
snippy::fatal(formatv("Register dump error: {0}", EC.message()));

dumpRegsAsYAML(Regs, File);
Regs.saveAsYAMLFile(YamlPath);
}

void Interpreter::dumpOneRange(NamedMemoryRange Range,
Expand Down
15 changes: 15 additions & 0 deletions llvm/tools/llvm-snippy/lib/Simulator/Simulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,25 @@

#include "snippy/Simulator/Simulator.h"

#include "snippy/Support/Error.h"

#include "llvm/Support/FormatVariadic.h"
#include "llvm/Support/YAMLTraits.h"

namespace llvm {

void snippy::IRegisterState::saveAsYAMLFile(StringRef YamlPath) const {
if (YamlPath.empty())
return;

std::error_code EC;
raw_fd_ostream File(YamlPath, EC);
if (EC)
snippy::fatal(formatv("Register dump error: {0}", EC.message()));

saveAsYAMLFile(File);
}

namespace {

struct RegionKey {
Expand Down