Skip to content

Commit

Permalink
Rename call, invoke instruction relations
Browse files Browse the repository at this point in the history
Remove redundant facts about direct vs. indirect calls
  • Loading branch information
langston-barrett committed Oct 7, 2022
1 parent fdace3d commit ac93f02
Show file tree
Hide file tree
Showing 10 changed files with 112 additions and 134 deletions.
36 changes: 15 additions & 21 deletions FactGenerator/include/predicates.inc
Original file line number Diff line number Diff line change
Expand Up @@ -228,17 +228,14 @@ GROUP_END(resume)

GROUP_BEGIN(invoke)
PREDICATE2(invoke, instr)
// TODO(#42): Rename for consistency
PREDICATE(invoke, instr_direct, direct_invoke_instr)
PREDICATE(invoke, instr_indirect, indirect_invoke_instr)
PREDICATE(invoke, function, invoke_instr_fn_operand)
PREDICATE(invoke, arg, invoke_instr_arg)
PREDICATE(invoke, calling_conv, invoke_instr_with_calling_convention)
PREDICATE(invoke, return_attr, invoke_instr_with_return_attr)
PREDICATE(invoke, param_attr, invoke_instr_with_param_attr)
PREDICATE(invoke, fn_attr, invoke_instr_with_fn_attr)
PREDICATE(invoke, normal_label, invoke_instr_normal_label)
PREDICATE(invoke, exc_label, invoke_instr_exception_label)
PREDICATEI(invoke, func_operand)
PREDICATEI(invoke, arg)
PREDICATEI(invoke, calling_conv)
PREDICATEI(invoke, return_attr)
PREDICATEI(invoke, param_attr)
PREDICATEI(invoke, fn_attr)
PREDICATEI(invoke, normal_label)
PREDICATEI(invoke, exception_label)
GROUP_END(invoke)

// Vector Operations
Expand Down Expand Up @@ -452,16 +449,13 @@ GROUP_END(va_arg)

GROUP_BEGIN(call)
PREDICATE2(call, instr)
// TODO(#42):
PREDICATE(call, instr_direct, direct_call_instr)
PREDICATE(call, instr_indirect, indirect_call_instr)
PREDICATE(call, function, call_instr_fn_operand)
PREDICATE(call, arg, call_instr_arg)
PREDICATE(call, calling_conv, call_instr_with_calling_convention)
PREDICATE(call, return_attr, call_instr_with_return_attr)
PREDICATE(call, param_attr, call_instr_with_param_attr)
PREDICATE(call, fn_attr, call_instr_with_fn_attr)
PREDICATE(call, tail, call_instr_is_tail_opt)
PREDICATEI(call, func_operand)
PREDICATEI(call, arg)
PREDICATEI(call, calling_conv)
PREDICATEI(call, return_attr)
PREDICATEI(call, param_attr)
PREDICATEI(call, fn_attr)
PREDICATEI(call, is_tail_opt)
GROUP_END(call)

GROUP_BEGIN(landingpad)
Expand Down
24 changes: 4 additions & 20 deletions FactGenerator/src/InstructionVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,26 +276,21 @@ void InstructionVisitor::visitIndirectBrInst(const llvm::IndirectBrInst &IBR) {
void InstructionVisitor::visitInvokeInst(const llvm::InvokeInst &II) {
refmode_t iref = recordInstruction(pred::invoke::instr, II);

gen.writeFact(
II.getCalledFunction() ? pred::invoke::instr_direct
: pred::invoke::instr_indirect,
iref);

#if LLVM_VERSION_MAJOR > 12
const llvm::Value *invokeOp = II.getCalledOperand();
#else
const llvm::Value *invokeOp = II.getCalledValue();
#endif

// invoke instruction function (also records type)
writeInstrOperand(pred::invoke::function, iref, invokeOp);
writeInstrOperand(pred::invoke::func_operand, iref, invokeOp);

// actual args
for (unsigned op = 0; op < II.getNumArgOperands(); ++op)
writeInstrOperand(pred::invoke::arg, iref, II.getArgOperand(op), op);

writeInstrOperand(pred::invoke::normal_label, iref, II.getNormalDest());
writeInstrOperand(pred::invoke::exc_label, iref, II.getUnwindDest());
writeInstrOperand(pred::invoke::exception_label, iref, II.getUnwindDest());

// Function Attributes
const Attributes &Attrs = II.getAttributes();
Expand Down Expand Up @@ -544,30 +539,19 @@ void InstructionVisitor::visitCallInst(const llvm::CallInst &CI) {
// instructions due to the constraint that all direct calls must
// be able to determine the function to be called.

if (!CI.isInlineAsm()) {
// Record if instruction is direct or indirect. This is
// probably redundant since it is inferred by the logic
// itself, according to the kind of the function operand.

gen.writeFact(
CI.getCalledFunction() ? pred::call::instr_direct
: pred::call::instr_indirect,
iref);
}

#if LLVM_VERSION_MAJOR > 12
const llvm::Value *callOp = CI.getCalledOperand();
#else
const llvm::Value *callOp = CI.getCalledValue();
#endif

// call instruction function (also records type)
writeInstrOperand(pred::call::function, iref, callOp);
writeInstrOperand(pred::call::func_operand, iref, callOp);

for (unsigned op = 0; op < CI.getNumArgOperands(); ++op)
writeInstrOperand(pred::call::arg, iref, CI.getArgOperand(op), op);

if (CI.isTailCall()) gen.writeFact(pred::call::tail, iref);
if (CI.isTailCall()) gen.writeFact(pred::call::is_tail_opt, iref);

if (CI.getCallingConv() != llvm::CallingConv::C) {
refmode_t cconv = gen.refmode(CI.getCallingConv());
Expand Down
8 changes: 4 additions & 4 deletions datalog/context/drop.dl
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ call_or_invoke_instr_fn_type(?instr, ?fnType) :-

.decl indirect_call_or_invoke_instr(?instr: Instruction)
indirect_call_or_invoke_instr(?instr) :-
indirect_call_instr(?instr);
indirect_invoke_instr(?instr).
call_instr_indirect(?instr);
invoke_instr_direct(?instr).

.decl num_indirect_calls_to_compatible_func(?n: number, ?func: FunctionDecl)
num_indirect_calls_to_compatible_func(?n, ?func) :-
Expand Down Expand Up @@ -89,8 +89,8 @@ func_type_has_no_pointer_return(?funcType) :-

drop_context_by_invoc(?invoc) :-
user_option_value("drop_redundant_contexts", "on"),
( call_instr_fn_operand(?invoc, ?funcOp)
; invoke_instr_fn_operand(?invoc, ?funcOp)
( call_instr_func_operand(?invoc, ?funcOp)
; invoke_instr_func_operand(?invoc, ?funcOp)
),
operand_has_type(?funcOp, ?funcOpType),
pointer_type_has_component(?funcOpType, ?declaredType),
Expand Down
36 changes: 18 additions & 18 deletions datalog/export/debug-output-extended.dl
Original file line number Diff line number Diff line change
Expand Up @@ -143,24 +143,26 @@
.output block_predecessors (compress=true)
.output boolean_type (compress=true)
.output boolean_vector_type (compress=true)
.output br_instr (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_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)
.output call_instr_calling_conv (compress=true)
.output call_instr_direct (compress=true)
.output call_instr_fn_attr (compress=true)
.output call_instr_fn_target (compress=true)
.output call_instr_fn_type (compress=true)
.output call_instr_func_operand (compress=true)
.output call_instr_indirect (compress=true)
.output call_instr_is_tail_opt (compress=true)
.output call_instr_param_attr (compress=true)
.output call_instr_return_attr (compress=true)
.output call_instr_return_type (compress=true)
.output call_instr_with_calling_convention (compress=true)
.output call_instr_with_fn_attr (compress=true)
.output call_instr_with_param_attr (compress=true)
.output call_instr_with_return_attr (compress=true)
.output call_or_invoke_instr_fn_type (compress=true)
.output called_at_startup (compress=true)
.output calling_convention (compress=true)
Expand Down Expand Up @@ -217,8 +219,6 @@
.output default_visibility (compress=true)
.output derived_type (compress=true)
.output destructor_class_type (compress=true)
.output direct_call_instr (compress=true)
.output direct_invoke_instr (compress=true)
.output direct_subclass (compress=true)
.output direct_superclass (compress=true)
.output dllexport_linkage_type (compress=true)
Expand Down Expand Up @@ -469,9 +469,7 @@
.output icmp_instr_from_type (compress=true)
.output icmp_instr_second_operand (compress=true)
.output icmp_instr_to_type (compress=true)
.output indirect_call_instr (compress=true)
.output indirect_call_or_invoke_instr (compress=true)
.output indirect_invoke_instr (compress=true)
.output indirectbr_instr (compress=true)
.output indirectbr_instr_address (compress=true)
.output indirectbr_instr_label (compress=true)
Expand Down Expand Up @@ -504,6 +502,8 @@
.output instr_func (compress=true)
.output instr_pos (compress=true)
.output instr_returns_type (compress=true)
.output instr_successor (compress=true)
.output instr_successor_index (compress=true)
.output int1_type (compress=true)
.output int32_type (compress=true)
.output int32_vector_type (compress=true)
Expand All @@ -524,16 +524,18 @@
.output inttoptr_instr_to_type (compress=true)
.output invoke_instr (compress=true)
.output invoke_instr_arg (compress=true)
.output invoke_instr_calling_conv (compress=true)
.output invoke_instr_direct (compress=true)
.output invoke_instr_exception_label (compress=true)
.output invoke_instr_fn_operand (compress=true)
.output invoke_instr_fn_attr (compress=true)
.output invoke_instr_fn_target (compress=true)
.output invoke_instr_fn_type (compress=true)
.output invoke_instr_func_operand (compress=true)
.output invoke_instr_indirect (compress=true)
.output invoke_instr_normal_label (compress=true)
.output invoke_instr_param_attr (compress=true)
.output invoke_instr_return_attr (compress=true)
.output invoke_instr_return_type (compress=true)
.output invoke_instr_with_calling_convention (compress=true)
.output invoke_instr_with_fn_attr (compress=true)
.output invoke_instr_with_param_attr (compress=true)
.output invoke_instr_with_return_attr (compress=true)
.output label_type (compress=true)
.output landingpad (compress=true)
.output landingpad_instr (compress=true)
Expand Down Expand Up @@ -575,8 +577,6 @@
.output mul_instr_first_operand (compress=true)
.output mul_instr_second_operand (compress=true)
.output nallocs_by_pt_size (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 @@ -674,6 +674,7 @@
.output resume_instr_operand (compress=true)
.output ret_instr (compress=true)
.output ret_instr_operand (compress=true)
.output ret_instr_void_ (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 +827,6 @@
.output vector_type_has_component (compress=true)
.output vector_type_has_size (compress=true)
.output visibility (compress=true)
.output ret_instr_void_ (compress=true)
.output void_type (compress=true)
.output vtable (compress=true)
.output vtable_func (compress=true)
Expand Down
36 changes: 18 additions & 18 deletions datalog/export/debug-output.dl
Original file line number Diff line number Diff line change
Expand Up @@ -143,24 +143,26 @@
.output block_predecessors (compress=true)
.output boolean_type (compress=true)
.output boolean_vector_type (compress=true)
.output br_instr (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_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)
.output call_instr_calling_conv (compress=true)
.output call_instr_direct (compress=true)
.output call_instr_fn_attr (compress=true)
.output call_instr_fn_target (compress=true)
.output call_instr_fn_type (compress=true)
.output call_instr_func_operand (compress=true)
.output call_instr_indirect (compress=true)
.output call_instr_is_tail_opt (compress=true)
.output call_instr_param_attr (compress=true)
.output call_instr_return_attr (compress=true)
.output call_instr_return_type (compress=true)
.output call_instr_with_calling_convention (compress=true)
.output call_instr_with_fn_attr (compress=true)
.output call_instr_with_param_attr (compress=true)
.output call_instr_with_return_attr (compress=true)
.output call_or_invoke_instr_fn_type (compress=true)
.output called_at_startup (compress=true)
.output calling_convention (compress=true)
Expand Down Expand Up @@ -217,8 +219,6 @@
.output default_visibility (compress=true)
.output derived_type (compress=true)
.output destructor_class_type (compress=true)
.output direct_call_instr (compress=true)
.output direct_invoke_instr (compress=true)
.output direct_subclass (compress=true)
.output direct_superclass (compress=true)
.output dllexport_linkage_type (compress=true)
Expand Down Expand Up @@ -469,9 +469,7 @@
.output icmp_instr_from_type (compress=true)
.output icmp_instr_second_operand (compress=true)
.output icmp_instr_to_type (compress=true)
.output indirect_call_instr (compress=true)
.output indirect_call_or_invoke_instr (compress=true)
.output indirect_invoke_instr (compress=true)
.output indirectbr_instr (compress=true)
.output indirectbr_instr_address (compress=true)
.output indirectbr_instr_label (compress=true)
Expand Down Expand Up @@ -504,6 +502,8 @@
.output instr_func (compress=true)
.output instr_pos (compress=true)
.output instr_returns_type (compress=true)
.output instr_successor (compress=true)
.output instr_successor_index (compress=true)
.output int1_type (compress=true)
.output int32_type (compress=true)
.output int32_vector_type (compress=true)
Expand All @@ -524,16 +524,18 @@
.output inttoptr_instr_to_type (compress=true)
.output invoke_instr (compress=true)
.output invoke_instr_arg (compress=true)
.output invoke_instr_calling_conv (compress=true)
.output invoke_instr_direct (compress=true)
.output invoke_instr_exception_label (compress=true)
.output invoke_instr_fn_operand (compress=true)
.output invoke_instr_fn_attr (compress=true)
.output invoke_instr_fn_target (compress=true)
.output invoke_instr_fn_type (compress=true)
.output invoke_instr_func_operand (compress=true)
.output invoke_instr_indirect (compress=true)
.output invoke_instr_normal_label (compress=true)
.output invoke_instr_param_attr (compress=true)
.output invoke_instr_return_attr (compress=true)
.output invoke_instr_return_type (compress=true)
.output invoke_instr_with_calling_convention (compress=true)
.output invoke_instr_with_fn_attr (compress=true)
.output invoke_instr_with_param_attr (compress=true)
.output invoke_instr_with_return_attr (compress=true)
.output label_type (compress=true)
.output landingpad (compress=true)
.output landingpad_instr (compress=true)
Expand Down Expand Up @@ -575,8 +577,6 @@
.output mul_instr_first_operand (compress=true)
.output mul_instr_second_operand (compress=true)
.output nallocs_by_pt_size (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 @@ -674,6 +674,7 @@
.output resume_instr_operand (compress=true)
.output ret_instr (compress=true)
.output ret_instr_operand (compress=true)
.output ret_instr_void_ (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 +827,6 @@
.output vector_type_has_component (compress=true)
.output vector_type_has_size (compress=true)
.output visibility (compress=true)
.output ret_instr_void_ (compress=true)
.output void_type (compress=true)
.output vtable (compress=true)
.output vtable_func (compress=true)
Expand Down
4 changes: 2 additions & 2 deletions datalog/points-to/assertions.dl
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,8 @@ assert_bitcast_operand_in_same_func(?bitcastInstr) :-
assert_reachable_direct_calls_have_callees(?ctx, ?call) :-
subset.callgraph.reachable_context(?ctx, ?instrFunc),
instr_func(?call, ?instrFunc),
direct_call_instr(?call),
call_instr_fn_operand(?call, ?funcOp),
call_instr_direct(?call),
call_instr_func_operand(?call, ?funcOp),
! undef_constant(?funcOp),
! subset.callgraph.callgraph_edge(_, _, ?ctx, ?call).

Expand Down
Loading

0 comments on commit ac93f02

Please sign in to comment.