-
Notifications
You must be signed in to change notification settings - Fork 17
[snippy] Dump initial registers without model #421
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| # 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: test -s %t.initial-regs.yaml | ||
|
|
||
| include: | ||
| - "Inputs/sections.yaml" | ||
|
|
||
| histogram: | ||
| - [ADD, 1] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -318,6 +318,12 @@ class SnippyProgramContext final { | |
| const IRegisterState & | ||
| getInitialRegisterState(const TargetSubtargetInfo &ST) const; | ||
|
|
||
| void dumpInitialRegisterState(StringRef YamlPath) const; | ||
| void dumpInitialRegisterState(StringRef YamlPath, | ||
| const TargetSubtargetInfo &ST) const; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd also separate concerns here. Let's separate fetching this state and dumping it. So in FlowGenerator you can do: auto &RegState = ProgramCtx.getInitialRegisterState(ST);
RegState.saveAsYAMLFile(PassCfg.RegistersConfig.InitialStateOutputYaml); |
||
|
|
||
| const IRegisterState &getInitialRegisterState() const; | ||
|
|
||
| bool hasProgramStateSaveSpace() const { return PGSK.get(); } | ||
| const auto &getProgramStateSaveSpace() const { return *PGSK; } | ||
| auto &getProgramStateSaveSpace() { return *PGSK; } | ||
|
|
@@ -364,6 +370,8 @@ class SnippyProgramContext final { | |
| std::unique_ptr<MemoryManager> MemManager; | ||
| std::unique_ptr<SMCManagerT> SMCManager; | ||
|
|
||
| const TargetSubtargetInfo *InitialStateSubtarget = nullptr; | ||
|
|
||
| constexpr static auto SmallStringDefaultSize = 16; | ||
|
|
||
| std::optional<SectionDesc> ROMSection; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -504,6 +504,9 @@ GeneratorResult FlowGenerator::generate(LLVMState &State, | |
|
|
||
| } else { | ||
|
|
||
| ProgContext.dumpInitialRegisterState( | ||
| PassCfg.RegistersConfig.InitialStateOutputYaml); | ||
|
|
||
|
Comment on lines
+507
to
+509
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There on the call site you can get the subtarget |
||
| snippy::warn(WarningName::NoModelExec, State.getCtx(), | ||
| "Skipping snippet execution on the model", | ||
| "model was set to 'None'."); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -285,6 +285,38 @@ const IRegisterState &SnippyProgramContext::getInitialRegisterState( | |
| return *InitialMachineState; | ||
| } | ||
|
|
||
| void SnippyProgramContext::dumpInitialRegisterState( | ||
| StringRef YamlPath, const TargetSubtargetInfo &ST) const { | ||
| if (YamlPath.empty()) | ||
| return; | ||
|
|
||
| std::error_code EC; | ||
| raw_fd_ostream File(YamlPath, EC); | ||
| if (EC) | ||
| snippy::fatal(State->getCtx(), "Failed to dump initial registers", | ||
| "cannot open file \"" + Twine(YamlPath) + | ||
| "\": " + EC.message()); | ||
|
|
||
| getInitialRegisterState(ST).saveAsYAMLFile(File); | ||
| } | ||
|
|
||
| void SnippyProgramContext::dumpInitialRegisterState(StringRef YamlPath) const { | ||
| if (YamlPath.empty()) | ||
| return; | ||
|
|
||
| assert( | ||
| InitialStateSubtarget && | ||
| "Initial register state requested before target context initialization"); | ||
| dumpInitialRegisterState(YamlPath, *InitialStateSubtarget); | ||
| } | ||
|
|
||
| const IRegisterState &SnippyProgramContext::getInitialRegisterState() const { | ||
| assert(InitialStateSubtarget && | ||
| "Initial register state requested before target context " | ||
| "initialization"); | ||
| return getInitialRegisterState(*InitialStateSubtarget); | ||
| } | ||
|
|
||
| SnippyProgramContext::SnippyProgramContext(LLVMState &State, | ||
| RegisterGenerator &RegGen, | ||
| std::vector<RegPool> Pools, | ||
|
|
@@ -318,6 +350,7 @@ void SnippyProgramContext::createTargetContext(const Config &Cfg, | |
| const TargetSubtargetInfo &STI, | ||
| const RegPoolWrapper &RP) { | ||
| assert(!TargetContext && "Double context insertion"); | ||
| InitialStateSubtarget = &STI; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't like this new member and it's usage |
||
| TargetContext = | ||
| State->getSnippyTarget().createTargetContext(*State, Cfg, &STI, RP); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hence this overload is redundant