Skip to content
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

Un-nest proof hint events for arguments of functions/hooks #1140

Merged
merged 7 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
2 changes: 1 addition & 1 deletion include/kllvm/binary/ProofTraceParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ class llvm_rewrite_trace {

class proof_trace_parser {
public:
static constexpr uint32_t expected_version = 12U;
static constexpr uint32_t expected_version = 13U;

private:
bool verbose_;
Expand Down
8 changes: 6 additions & 2 deletions include/kllvm/codegen/CreateTerm.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,18 @@ class create_term {
std::set<kore_pattern *> static_terms_;

llvm::Value *alloc_arg(
kore_composite_pattern *pattern, int idx, bool is_hook_arg,
kore_composite_pattern *pattern, int idx,
std::string const &location_stack);
llvm::Value *create_hardcoded_hook(
std::string const &name, kore_composite_pattern *pattern,
std::vector<llvm::Value *> &args, std::string const &location_stack);
llvm::Value *create_hook(
kore_composite_pattern *hook_att, kore_composite_pattern *pattern,
std::string const &location_stack = "");
llvm::Value *create_function_call(
std::string const &name, kore_composite_pattern *pattern, bool sret,
bool tailcc, bool is_hook, std::string const &location_stack = "");
bool tailcc, bool is_hook, std::vector<llvm::Value *> &args,
std::string const &location_stack = "");
llvm::Value *not_injection_case(
kore_composite_pattern *constructor, llvm::Value *val,
std::string const &location_stack = "");
Expand Down
9 changes: 9 additions & 0 deletions include/kllvm/codegen/ProofEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,15 @@ class proof_event {
llvm::Value *val, kore_composite_sort *sort, bool is_hook_arg,
llvm::BasicBlock *current_block);

[[nodiscard]] llvm::BasicBlock *short_circuit_hook_argument(
llvm::Value *val, llvm::Value *short_circuit_cond, bool invert_cond,
kore_composite_sort *sort, llvm::BasicBlock *current_block);

[[nodiscard]] llvm::BasicBlock *short_circuit_hook_argument(
llvm::Value *val_first, llvm::Value *val_second, llvm::Value *select_cond,
kore_composite_sort *sort_first, kore_composite_sort *sort_second,
llvm::BasicBlock *current_block);

[[nodiscard]] llvm::BasicBlock *rewrite_event_pre(
kore_axiom_declaration const &axiom, uint64_t arity,
std::map<std::string, kore_variable_pattern *> vars,
Expand Down
219 changes: 145 additions & 74 deletions lib/codegen/CreateTerm.cpp

Large diffs are not rendered by default.

54 changes: 54 additions & 0 deletions lib/codegen/ProofEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,60 @@ llvm::BasicBlock *proof_event::argument(
return merge_block;
}

llvm::BasicBlock *proof_event::short_circuit_hook_argument(
llvm::Value *val, llvm::Value *short_circuit_cond, bool invert_cond,
kore_composite_sort *sort, llvm::BasicBlock *current_block) {
if (!proof_hint_instrumentation) {
return current_block;
}

auto *f = current_block->getParent();
auto *true_block = llvm::BasicBlock::Create(ctx_, "if_no_short_circ", f);
auto *merge_block = llvm::BasicBlock::Create(ctx_, "tail_short_circ", f);

if (invert_cond) {
short_circuit_cond = llvm::BinaryOperator::Create(
llvm::Instruction::Xor, short_circuit_cond,
llvm::ConstantInt::get(llvm::Type::getInt1Ty(ctx_), 1), "",
current_block);
}
llvm::BranchInst::Create(
true_block, merge_block, short_circuit_cond, current_block);

true_block = argument(val, sort, true, true_block);
llvm::BranchInst::Create(merge_block, true_block);

return merge_block;
}

llvm::BasicBlock *proof_event::short_circuit_hook_argument(
llvm::Value *val_first, llvm::Value *val_second, llvm::Value *select_cond,
kore_composite_sort *sort_first, kore_composite_sort *sort_second,
llvm::BasicBlock *current_block) {
if (!proof_hint_instrumentation) {
return current_block;
}

auto *f = current_block->getParent();
auto *first_block
= llvm::BasicBlock::Create(ctx_, "if_short_circ_select_first", f);
auto *second_block
= llvm::BasicBlock::Create(ctx_, "if_short_circ_select_second", f);
auto *merge_block
= llvm::BasicBlock::Create(ctx_, "tail_short_circ_select", f);

llvm::BranchInst::Create(
first_block, second_block, select_cond, current_block);

first_block = argument(val_first, sort_first, true, first_block);
llvm::BranchInst::Create(merge_block, first_block);

second_block = argument(val_second, sort_second, true, second_block);
llvm::BranchInst::Create(merge_block, second_block);

return merge_block;
}

/*
* Rewrite Events
*/
Expand Down
2 changes: 1 addition & 1 deletion runtime/util/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ block *construct_raw_term(void *subject, char const *sort, bool raw_value) {
}

void print_proof_hint_header(proof_trace_writer *writer) {
uint32_t version = 12;
uint32_t version = 13;
writer->proof_trace_header(version);
}
}
14 changes: 5 additions & 9 deletions test/output/add-rewrite/input.proof.debug.out.diff
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
version: 12
version: 13
hook: MAP.element Lbl'UndsPipe'-'-GT-Unds'{} ()
function: Lbl'UndsPipe'-'-GT-Unds'{} ()
arg: kore[\dv{SortKConfigVar{}}("$PGM")]
arg: kore[Lblstate'LParUndsCommUndsRParUnds'ADD-REWRITE-SYNTAX'Unds'State'Unds'Nat'Unds'Nat{}(Lbls'LParUndsRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat'Unds'Nat{}(Lbls'LParUndsRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat'Unds'Nat{}(Lblz'LParRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat{}())),Lblz'LParRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat{}())]
hook result: kore[Lbl'UndsPipe'-'-GT-Unds'{}(\dv{SortKConfigVar{}}("$PGM"),Lblstate'LParUndsCommUndsRParUnds'ADD-REWRITE-SYNTAX'Unds'State'Unds'Nat'Unds'Nat{}(Lbls'LParUndsRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat'Unds'Nat{}(Lbls'LParUndsRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat'Unds'Nat{}(Lblz'LParRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat{}())),Lblz'LParRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat{}()))]
hook: MAP.unit Lbl'Stop'Map{} ()
function: Lbl'Stop'Map{} ()
hook result: kore[Lbl'Stop'Map{}()]
hook: MAP.concat Lbl'Unds'Map'Unds'{} ()
function: Lbl'Unds'Map'Unds'{} ()
arg: kore[Lbl'Stop'Map{}()]
arg: kore[Lbl'UndsPipe'-'-GT-Unds'{}(\dv{SortKConfigVar{}}("$PGM"),Lblstate'LParUndsCommUndsRParUnds'ADD-REWRITE-SYNTAX'Unds'State'Unds'Nat'Unds'Nat{}(Lbls'LParUndsRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat'Unds'Nat{}(Lbls'LParUndsRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat'Unds'Nat{}(Lblz'LParRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat{}())),Lblz'LParRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat{}()))]
hook result: kore[Lbl'UndsPipe'-'-GT-Unds'{}(\dv{SortKConfigVar{}}("$PGM"),Lblstate'LParUndsCommUndsRParUnds'ADD-REWRITE-SYNTAX'Unds'State'Unds'Nat'Unds'Nat{}(Lbls'LParUndsRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat'Unds'Nat{}(Lbls'LParUndsRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat'Unds'Nat{}(Lblz'LParRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat{}())),Lblz'LParRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat{}()))]
Expand All @@ -18,12 +15,11 @@ rule: 111 1 [] []
function: LblinitKCell{} (0)
rule: 112 1 [] []
VarInit = kore[Lbl'UndsPipe'-'-GT-Unds'{}(\dv{SortKConfigVar{}}("$PGM"),Lblstate'LParUndsCommUndsRParUnds'ADD-REWRITE-SYNTAX'Unds'State'Unds'Nat'Unds'Nat{}(Lbls'LParUndsRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat'Unds'Nat{}(Lbls'LParUndsRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat'Unds'Nat{}(Lblz'LParRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat{}())),Lblz'LParRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat{}()))]
hook: MAP.lookup LblMap'Coln'lookup{} (0:0:0:0)
arg: kore[Lbl'UndsPipe'-'-GT-Unds'{}(\dv{SortKConfigVar{}}("$PGM"),Lblstate'LParUndsCommUndsRParUnds'ADD-REWRITE-SYNTAX'Unds'State'Unds'Nat'Unds'Nat{}(Lbls'LParUndsRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat'Unds'Nat{}(Lbls'LParUndsRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat'Unds'Nat{}(Lblz'LParRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat{}())),Lblz'LParRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat{}()))]
arg: kore[\dv{SortKConfigVar{}}("$PGM")]
hook result: kore[Lblstate'LParUndsCommUndsRParUnds'ADD-REWRITE-SYNTAX'Unds'State'Unds'Nat'Unds'Nat{}(Lbls'LParUndsRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat'Unds'Nat{}(Lbls'LParUndsRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat'Unds'Nat{}(Lblz'LParRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat{}())),Lblz'LParRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat{}())]
function: Lblproject'Coln'KItem{} (0:0)
hook: MAP.lookup LblMap'Coln'lookup{} (0:0:0:0)
function: LblMap'Coln'lookup{} (0:0:0:0)
arg: kore[Lbl'UndsPipe'-'-GT-Unds'{}(\dv{SortKConfigVar{}}("$PGM"),Lblstate'LParUndsCommUndsRParUnds'ADD-REWRITE-SYNTAX'Unds'State'Unds'Nat'Unds'Nat{}(Lbls'LParUndsRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat'Unds'Nat{}(Lbls'LParUndsRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat'Unds'Nat{}(Lblz'LParRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat{}())),Lblz'LParRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat{}()))]
arg: kore[\dv{SortKConfigVar{}}("$PGM")]
hook result: kore[Lblstate'LParUndsCommUndsRParUnds'ADD-REWRITE-SYNTAX'Unds'State'Unds'Nat'Unds'Nat{}(Lbls'LParUndsRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat'Unds'Nat{}(Lbls'LParUndsRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat'Unds'Nat{}(Lblz'LParRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat{}())),Lblz'LParRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat{}())]
rule: 153 1 [] []
VarK = kore[Lblstate'LParUndsCommUndsRParUnds'ADD-REWRITE-SYNTAX'Unds'State'Unds'Nat'Unds'Nat{}(Lbls'LParUndsRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat'Unds'Nat{}(Lbls'LParUndsRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat'Unds'Nat{}(Lblz'LParRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat{}())),Lblz'LParRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat{}())]
function: LblinitGeneratedCounterCell{} (1)
Expand Down
14 changes: 5 additions & 9 deletions test/output/add-rewrite/input.proof.out.diff
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
version: 12
version: 13
hook: MAP.element Lbl'UndsPipe'-'-GT-Unds'{} ()
function: Lbl'UndsPipe'-'-GT-Unds'{} ()
arg: kore[\dv{SortKConfigVar{}}("$PGM")]
arg: kore[Lblstate'LParUndsCommUndsRParUnds'ADD-REWRITE-SYNTAX'Unds'State'Unds'Nat'Unds'Nat{}(Lbls'LParUndsRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat'Unds'Nat{}(Lbls'LParUndsRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat'Unds'Nat{}(Lblz'LParRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat{}())),Lblz'LParRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat{}())]
hook result: kore[Lbl'UndsPipe'-'-GT-Unds'{}(\dv{SortKConfigVar{}}("$PGM"),Lblstate'LParUndsCommUndsRParUnds'ADD-REWRITE-SYNTAX'Unds'State'Unds'Nat'Unds'Nat{}(Lbls'LParUndsRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat'Unds'Nat{}(Lbls'LParUndsRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat'Unds'Nat{}(Lblz'LParRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat{}())),Lblz'LParRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat{}()))]
hook: MAP.unit Lbl'Stop'Map{} ()
function: Lbl'Stop'Map{} ()
hook result: kore[Lbl'Stop'Map{}()]
hook: MAP.concat Lbl'Unds'Map'Unds'{} ()
function: Lbl'Unds'Map'Unds'{} ()
arg: kore[Lbl'Stop'Map{}()]
arg: kore[Lbl'UndsPipe'-'-GT-Unds'{}(\dv{SortKConfigVar{}}("$PGM"),Lblstate'LParUndsCommUndsRParUnds'ADD-REWRITE-SYNTAX'Unds'State'Unds'Nat'Unds'Nat{}(Lbls'LParUndsRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat'Unds'Nat{}(Lbls'LParUndsRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat'Unds'Nat{}(Lblz'LParRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat{}())),Lblz'LParRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat{}()))]
hook result: kore[Lbl'UndsPipe'-'-GT-Unds'{}(\dv{SortKConfigVar{}}("$PGM"),Lblstate'LParUndsCommUndsRParUnds'ADD-REWRITE-SYNTAX'Unds'State'Unds'Nat'Unds'Nat{}(Lbls'LParUndsRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat'Unds'Nat{}(Lbls'LParUndsRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat'Unds'Nat{}(Lblz'LParRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat{}())),Lblz'LParRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat{}()))]
Expand All @@ -18,12 +15,11 @@ rule: 111 1
function: LblinitKCell{} (0)
rule: 112 1
VarInit = kore[Lbl'UndsPipe'-'-GT-Unds'{}(\dv{SortKConfigVar{}}("$PGM"),Lblstate'LParUndsCommUndsRParUnds'ADD-REWRITE-SYNTAX'Unds'State'Unds'Nat'Unds'Nat{}(Lbls'LParUndsRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat'Unds'Nat{}(Lbls'LParUndsRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat'Unds'Nat{}(Lblz'LParRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat{}())),Lblz'LParRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat{}()))]
hook: MAP.lookup LblMap'Coln'lookup{} (0:0:0:0)
arg: kore[Lbl'UndsPipe'-'-GT-Unds'{}(\dv{SortKConfigVar{}}("$PGM"),Lblstate'LParUndsCommUndsRParUnds'ADD-REWRITE-SYNTAX'Unds'State'Unds'Nat'Unds'Nat{}(Lbls'LParUndsRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat'Unds'Nat{}(Lbls'LParUndsRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat'Unds'Nat{}(Lblz'LParRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat{}())),Lblz'LParRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat{}()))]
arg: kore[\dv{SortKConfigVar{}}("$PGM")]
hook result: kore[Lblstate'LParUndsCommUndsRParUnds'ADD-REWRITE-SYNTAX'Unds'State'Unds'Nat'Unds'Nat{}(Lbls'LParUndsRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat'Unds'Nat{}(Lbls'LParUndsRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat'Unds'Nat{}(Lblz'LParRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat{}())),Lblz'LParRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat{}())]
function: Lblproject'Coln'KItem{} (0:0)
hook: MAP.lookup LblMap'Coln'lookup{} (0:0:0:0)
function: LblMap'Coln'lookup{} (0:0:0:0)
arg: kore[Lbl'UndsPipe'-'-GT-Unds'{}(\dv{SortKConfigVar{}}("$PGM"),Lblstate'LParUndsCommUndsRParUnds'ADD-REWRITE-SYNTAX'Unds'State'Unds'Nat'Unds'Nat{}(Lbls'LParUndsRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat'Unds'Nat{}(Lbls'LParUndsRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat'Unds'Nat{}(Lblz'LParRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat{}())),Lblz'LParRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat{}()))]
arg: kore[\dv{SortKConfigVar{}}("$PGM")]
hook result: kore[Lblstate'LParUndsCommUndsRParUnds'ADD-REWRITE-SYNTAX'Unds'State'Unds'Nat'Unds'Nat{}(Lbls'LParUndsRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat'Unds'Nat{}(Lbls'LParUndsRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat'Unds'Nat{}(Lblz'LParRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat{}())),Lblz'LParRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat{}())]
rule: 153 1
VarK = kore[Lblstate'LParUndsCommUndsRParUnds'ADD-REWRITE-SYNTAX'Unds'State'Unds'Nat'Unds'Nat{}(Lbls'LParUndsRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat'Unds'Nat{}(Lbls'LParUndsRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat'Unds'Nat{}(Lblz'LParRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat{}())),Lblz'LParRParUnds'ADD-REWRITE-SYNTAX'Unds'Nat{}())]
function: LblinitGeneratedCounterCell{} (1)
Expand Down
Loading
Loading