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

Rename instruction relations #57

Merged
merged 3 commits into from
Oct 7, 2022
Merged
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
36 changes: 19 additions & 17 deletions FactGenerator/include/predicates.inc
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,18 @@ PREDICATE2(func, param_attr)
GROUP_END(function)

GROUP_BEGIN(instr)
PREDICATE(instr, to, instr_assigns_to)
PREDICATE(instr, flag, instr_flag)
PREDICATE(instr, next, next_instr)
PREDICATE(instr, bb_entry, instr_bb_entry)
PREDICATE(instr, func, instr_func)
PREDICATE(instr, pos, instr_pos)
PREDICATE(instr, unreachable, unreachable_instr)
PREDICATE2(instr, assigns_to)
PREDICATE2(instr, flag)
PREDICATE2(instr, successor)
PREDICATE2(instr, bb_entry)
PREDICATE2(instr, func)
PREDICATE2(instr, pos)
GROUP_END(instr)

GROUP_BEGIN(unreachable)
PREDICATE2(unreachable, instr)
GROUP_END(unreachable)

GROUP_BEGIN(add)
PREDICATE2(add, instr)
PREDICATEI(add, first_operand)
Expand Down Expand Up @@ -187,20 +190,19 @@ GROUP_END(xor_)

GROUP_BEGIN(ret)
PREDICATE2(ret, instr)
// TODO(#42):
PREDICATE(ret, instr_void, void_ret_instr)
// TODO(#42):
PREDICATE(ret, operand, ret_instr_value)
// Can't be named 'void', as that's a C++ keyword.
PREDICATEI(ret, void_)
PREDICATEI(ret, operand)
GROUP_END(ret)

GROUP_BEGIN(br)
PREDICATE2(br, instr)
PREDICATE(br, instr_cond, br_cond_instr)
PREDICATE(br, condition, br_cond_instr_condition)
PREDICATE(br, cond_iftrue, br_cond_instr_iftrue_label)
PREDICATE(br, cond_iffalse, br_cond_instr_iffalse_label)
PREDICATE(br, instr_uncond, br_uncond_instr)
PREDICATE(br, uncond_dest, br_uncond_instr_dest_label)
PREDICATEI(br, cond)
PREDICATEI(br, condition)
PREDICATEI(br, true_label)
PREDICATEI(br, false_label)
PREDICATEI(br, uncond)
PREDICATEI(br, uncond_label)
GROUP_END(br)

GROUP_BEGIN(switch_)
Expand Down
4 changes: 2 additions & 2 deletions FactGenerator/src/FactGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ auto FactGenerator::processModule(
if (!instr.getType()->isVoidTy()) {
refmode_t targetVar = refmode<llvm::Value>(instr);

writeFact(pred::instr::to, iref, targetVar);
writeFact(pred::instr::assigns_to, iref, targetVar);
recordVariable(targetVar, instr.getType());

// Save variables for the CPG
Expand All @@ -166,7 +166,7 @@ auto FactGenerator::processModule(
}

// Record successor instruction
if (prev_instr) writeFact(pred::instr::next, prev_iref, iref);
if (prev_instr) writeFact(pred::instr::successor, prev_iref, iref);

// Store the refmode of this instruction for next iteration
prev_iref = iref;
Expand Down
14 changes: 7 additions & 7 deletions FactGenerator/src/InstructionVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ void InstructionVisitor::visitReturnInst(const llvm::ReturnInst &RI) {
if (RI.getReturnValue()) { // with returned value
writeInstrOperand(pred::ret::operand, iref, RI.getReturnValue());
} else { // w/o returned value
gen.writeFact(pred::ret::instr_void, iref);
gen.writeFact(pred::ret::void_, iref);
}
}

Expand All @@ -224,18 +224,18 @@ void InstructionVisitor::visitBranchInst(const llvm::BranchInst &BI) {

if (BI.isConditional()) { // conditional branch
// br i1 <cond>, label <iftrue>, label <iffalse>
gen.writeFact(pred::br::instr_cond, iref);
gen.writeFact(pred::br::cond, iref);

// Condition Operand
writeInstrOperand(pred::br::condition, iref, BI.getCondition());

// 'iftrue' and 'iffalse' labels
writeInstrOperand(pred::br::cond_iftrue, iref, BI.getOperand(1));
writeInstrOperand(pred::br::cond_iffalse, iref, BI.getOperand(2));
writeInstrOperand(pred::br::true_label, iref, BI.getOperand(1));
writeInstrOperand(pred::br::false_label, iref, BI.getOperand(2));
} else { // unconditional branch
// br label <dest>
gen.writeFact(pred::br::instr_uncond, iref);
writeInstrOperand(pred::br::uncond_dest, iref, BI.getOperand(0));
gen.writeFact(pred::br::uncond, iref);
writeInstrOperand(pred::br::uncond_label, iref, BI.getOperand(0));
}
}

Expand Down Expand Up @@ -320,7 +320,7 @@ void InstructionVisitor::visitResumeInst(const llvm::ResumeInst &RI) {
}

void InstructionVisitor::visitUnreachableInst(const llvm::UnreachableInst &I) {
recordInstruction(pred::instr::unreachable, I);
recordInstruction(pred::unreachable::instr, I);
}

void InstructionVisitor::visitAllocaInst(const llvm::AllocaInst &AI) {
Expand Down
20 changes: 10 additions & 10 deletions datalog/export/debug-output-extended.dl
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,13 @@
.output block_predecessors (compress=true)
.output boolean_type (compress=true)
.output boolean_vector_type (compress=true)
.output br_cond_instr (compress=true)
.output br_cond_instr_condition (compress=true)
.output br_cond_instr_iffalse_label (compress=true)
.output br_cond_instr_iftrue_label (compress=true)
.output br_instr_cond (compress=true)
.output br_instr_condition (compress=true)
.output br_instr_false_label (compress=true)
.output br_instr_true_label (compress=true)
.output br_instr (compress=true)
.output br_uncond_instr (compress=true)
.output br_uncond_instr_dest_label (compress=true)
.output br_instr_uncond (compress=true)
.output br_instr_uncond_label (compress=true)
.output call_instr (compress=true)
.output call_instr_arg (compress=true)
.output call_instr_fn_operand (compress=true)
Expand Down Expand Up @@ -575,8 +575,8 @@
.output mul_instr_first_operand (compress=true)
.output mul_instr_second_operand (compress=true)
.output nallocs_by_pt_size (compress=true)
.output next_instr (compress=true)
.output next_instr_index (compress=true)
.output instr_successor (compress=true)
.output instr_successor_index (compress=true)
.output non_allocation (compress=true)
.output nonempty_ptr (compress=true)
.output nonempty_ptrs (compress=true)
Expand Down Expand Up @@ -673,7 +673,7 @@
.output resume_instr (compress=true)
.output resume_instr_operand (compress=true)
.output ret_instr (compress=true)
.output ret_instr_value (compress=true)
.output ret_instr_operand (compress=true)
.output schema_invalid_alias (compress=true)
.output schema_invalid_constant (compress=true)
.output schema_invalid_func (compress=true)
Expand Down Expand Up @@ -826,7 +826,7 @@
.output vector_type_has_component (compress=true)
.output vector_type_has_size (compress=true)
.output visibility (compress=true)
.output void_ret_instr (compress=true)
.output ret_instr_void_ (compress=true)
.output void_type (compress=true)
.output vtable (compress=true)
.output vtable_func (compress=true)
Expand Down
20 changes: 10 additions & 10 deletions datalog/export/debug-output.dl
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,13 @@
.output block_predecessors (compress=true)
.output boolean_type (compress=true)
.output boolean_vector_type (compress=true)
.output br_cond_instr (compress=true)
.output br_cond_instr_condition (compress=true)
.output br_cond_instr_iffalse_label (compress=true)
.output br_cond_instr_iftrue_label (compress=true)
.output br_instr_cond (compress=true)
.output br_instr_condition (compress=true)
.output br_instr_false_label (compress=true)
.output br_instr_true_label (compress=true)
.output br_instr (compress=true)
.output br_uncond_instr (compress=true)
.output br_uncond_instr_dest_label (compress=true)
.output br_instr_uncond (compress=true)
.output br_instr_uncond_label (compress=true)
.output call_instr (compress=true)
.output call_instr_arg (compress=true)
.output call_instr_fn_operand (compress=true)
Expand Down Expand Up @@ -575,8 +575,8 @@
.output mul_instr_first_operand (compress=true)
.output mul_instr_second_operand (compress=true)
.output nallocs_by_pt_size (compress=true)
.output next_instr (compress=true)
.output next_instr_index (compress=true)
.output instr_successor (compress=true)
.output instr_successor_index (compress=true)
.output non_allocation (compress=true)
.output nonempty_ptr (compress=true)
.output nonempty_ptrs (compress=true)
Expand Down Expand Up @@ -673,7 +673,7 @@
.output resume_instr (compress=true)
.output resume_instr_operand (compress=true)
.output ret_instr (compress=true)
.output ret_instr_value (compress=true)
.output ret_instr_operand (compress=true)
.output schema_invalid_alias (compress=true)
.output schema_invalid_constant (compress=true)
.output schema_invalid_func (compress=true)
Expand Down Expand Up @@ -826,7 +826,7 @@
.output vector_type_has_component (compress=true)
.output vector_type_has_size (compress=true)
.output visibility (compress=true)
.output void_ret_instr (compress=true)
.output ret_instr_void_ (compress=true)
.output void_type (compress=true)
.output vtable (compress=true)
.output vtable_func (compress=true)
Expand Down
2 changes: 1 addition & 1 deletion datalog/points-to/interprocedural.dl
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func_param_not_by_value(?callee, ?index, ?param) :-
.decl func_returns_value(?retValue: Operand, ?inFunction: Function)

func_returns_value(?retValue, ?inFunction) :-
ret_instr_value(?retInsn, ?retValue),
ret_instr_operand(?retInsn, ?retValue),
instr_func(?retInsn, ?inFunction).

.comp InterpAssignment {
Expand Down
10 changes: 5 additions & 5 deletions datalog/schema/basic-block.dl
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,23 @@ block_of_label(cat("block:", Label), Label) :-

block_first_instr(BB, First) :-
instr_block(First, BB),
!next_instr(_, First).
!instr_successor(_, First).

block_first_instr(BB2, First) :-
next_instr(Last, First),
instr_successor(Last, First),
instr_block(Last, BB1),
instr_block(First, BB2),
BB1 != BB2.

block_last_instr(BB1, Last) :-
next_instr(Last, First),
instr_successor(Last, First),
instr_block(Last, BB1),
instr_block(First, BB2),
BB1 != BB2.

block_last_instr(BB, Last) :-
instr_block(Last, BB),
!next_instr(Last, _).
!instr_successor(Last, _).


//------------------------------------------------------------------------------
Expand All @@ -69,7 +69,7 @@ block_last_instr(BB, Last) :-

schema_invalid_instr(Instr, __FILE__, __LINE__) :-
schema_sanity(),
next_instr(Instr, NextInstr),
instr_successor(Instr, NextInstr),
instr_block(Instr, BB1),
instr_block(NextInstr, BB2),
!terminator_instr(Instr),
Expand Down
48 changes: 24 additions & 24 deletions datalog/schema/br-instr.dl
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,30 @@
.type BrUncondInstruction = BrInstruction

.decl br_instr(instr:BrInstruction)
.decl br_cond_instr(instr:BrCondInstruction)
.decl br_uncond_instr(instr:BrUncondInstruction)
.decl br_instr_cond(instr:BrCondInstruction)
.decl br_instr_uncond(instr:BrUncondInstruction)


instr(v) :- br_instr(v).
terminator_instr(v) :- br_instr(v).
br_instr(v) :- br_cond_instr(v).
br_instr(v) :- br_uncond_instr(v).
br_instr(v) :- br_instr_cond(v).
br_instr(v) :- br_instr_uncond(v).


//-----------------------------
// Conditional branch
//-----------------------------

.decl br_cond_instr_condition(instr:Instruction, cond:Operand)
.decl br_cond_instr_iftrue_label(instr:Instruction, label:Variable)
.decl br_cond_instr_iffalse_label(instr:Instruction, label:Variable)
.decl br_instr_condition(instr:Instruction, cond:Operand)
.decl br_instr_true_label(instr:Instruction, label:Variable)
.decl br_instr_false_label(instr:Instruction, label:Variable)


//-----------------------------
// Unconditional branch
//-----------------------------

.decl br_uncond_instr_dest_label(instr:Instruction, label:Variable)
.decl br_instr_uncond_label(instr:Instruction, label:Variable)


//------------------------------------------------------------------------------
Expand All @@ -45,45 +45,45 @@ br_instr(v) :- br_uncond_instr(v).

schema_invalid_instr(Instr, __FILE__, __LINE__) :-
schema_sanity(),
br_cond_instr(Instr),
!br_cond_instr_condition(Instr, _).
br_instr_cond(Instr),
!br_instr_condition(Instr, _).

schema_invalid_instr(Instr, __FILE__, __LINE__) :-
schema_sanity(),
br_cond_instr(Instr),
br_cond_instr_condition(Instr, Cond),
br_instr_cond(Instr),
br_instr_condition(Instr, Cond),
operand_has_type(Cond, CondType),
!int1_type(CondType).

schema_invalid_instr(Instr, __FILE__, __LINE__) :-
schema_sanity(),
br_cond_instr(Instr),
!br_cond_instr_iftrue_label(Instr, _).
br_instr_cond(Instr),
!br_instr_true_label(Instr, _).

schema_invalid_instr(Instr, __FILE__, __LINE__) :-
schema_sanity(),
br_cond_instr(Instr),
!br_cond_instr_iffalse_label(Instr, _).
br_instr_cond(Instr),
!br_instr_false_label(Instr, _).

schema_invalid_instr(Instr, __FILE__, __LINE__) :-
schema_sanity(),
br_cond_instr(Instr),
br_cond_instr_iftrue_label(Instr, Label),
br_instr_cond(Instr),
br_instr_true_label(Instr, Label),
!variable_is_label(Label).

schema_invalid_instr(Instr, __FILE__, __LINE__) :-
schema_sanity(),
br_cond_instr(Instr),
br_cond_instr_iffalse_label(Instr, Label),
br_instr_cond(Instr),
br_instr_false_label(Instr, Label),
!variable_is_label(Label).

schema_invalid_instr(Instr, __FILE__, __LINE__) :-
schema_sanity(),
br_uncond_instr(Instr),
!br_uncond_instr_dest_label(Instr, _).
br_instr_uncond(Instr),
!br_instr_uncond_label(Instr, _).

schema_invalid_instr(Instr, __FILE__, __LINE__) :-
schema_sanity(),
br_uncond_instr(Instr),
br_uncond_instr_dest_label(Instr, Label),
br_instr_uncond(Instr),
br_instr_uncond_label(Instr, Label),
!variable_is_label(Label).
6 changes: 3 additions & 3 deletions datalog/schema/extractvalue-instr.dl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ instr(v) :- extractvalue_instr(v).
.decl extractvalue_instr_nindices(instr:ExtractValueInstruction, total:number)
.decl extractvalue_instr_index(instr:ExtractValueInstruction, i:number, idx:number)

next_instr_index(Instr, Index, Index + 1) :-
instr_successor_index(Instr, Index, Index + 1) :-
extractvalue_instr_index(Instr, Index, _).


Expand All @@ -35,12 +35,12 @@ extractvalue_instrterm_type(Instr, NextIndex, Type) :-
extractvalue_instrterm_type(Instr, Index, StructType),
extractvalue_instr_index(Instr, Index, IdxValue),
struct_type_field(StructType, IdxValue, Type),
next_instr_index(Instr, Index, NextIndex).
instr_successor_index(Instr, Index, NextIndex).

extractvalue_instrterm_type(Instr, NextIndex, Type) :-
extractvalue_instrterm_type(Instr, Index, ArrayType),
array_type_has_component(ArrayType, Type),
next_instr_index(Instr, Index, NextIndex).
instr_successor_index(Instr, Index, NextIndex).

extractvalue_instr_value_type(Instr, Type) :-
extractvalue_instr_nindices(Instr, Total),
Expand Down
Loading