Skip to content

Commit

Permalink
Rename instruction relations
Browse files Browse the repository at this point in the history
Used this script to rename files in datalog/schema:

    import os

    for f in os.listdir("."):
        if "instruction" in f:
            os.rename(f, f.replace("instruction", "instr"))
  • Loading branch information
langston-barrett committed Oct 7, 2022
1 parent e119c57 commit 4602f5b
Show file tree
Hide file tree
Showing 544 changed files with 5,375 additions and 6,807 deletions.
2 changes: 1 addition & 1 deletion FactGenerator/include/InstructionVisitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class cclyzer::InstructionVisitor

// default synchScope: crossthread
if (instr.getSyncScopeID() == SyncScope::SingleThread) {
gen.writeFact(predicates::instruction::flag, iref, "singlethread");
gen.writeFact(predicates::instr::flag, iref, "singlethread");
}

if (!atomic.empty()) gen.writeFact(P::ordering, iref, atomic);
Expand Down
450 changes: 225 additions & 225 deletions FactGenerator/include/predicates.inc

Large diffs are not rendered by default.

10 changes: 5 additions & 5 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::instruction::to, iref, targetVar);
writeFact(pred::instr::to, iref, targetVar);
recordVariable(targetVar, instr.getType());

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

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

// Store the refmode of this instruction for next iteration
prev_iref = iref;
prev_instr = &instr;

// Record instruction's container function
writeFact(pred::instruction::function, iref, funcref);
writeFact(pred::instr::func, iref, funcref);

// Record instruction's basic block entry (label)
const llvm::BasicBlock *bbEntry = instr.getParent();
refmode_t bbEntryId = refmode<llvm::BasicBlock>(*bbEntry);
writeFact(pred::instruction::bb_entry, iref, bbEntryId);
writeFact(pred::instr::bb_entry, iref, bbEntryId);

// Visit instruction
IV.visit(const_cast<llvm::Instruction &>(instr));
Expand All @@ -193,7 +193,7 @@ auto FactGenerator::processModule(
unsigned line = location.getLine();
unsigned column = location.getCol();

writeFact(pred::instruction::pos, iref, line, column);
writeFact(pred::instr::pos, iref, line, column);
}
}

Expand Down
29 changes: 12 additions & 17 deletions FactGenerator/src/InstructionVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ void InstructionVisitor::visitResumeInst(const llvm::ResumeInst &RI) {
}

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

void InstructionVisitor::visitAllocaInst(const llvm::AllocaInst &AI) {
Expand Down Expand Up @@ -410,7 +410,7 @@ void InstructionVisitor::visitAtomicCmpXchgInst(
#else
if (AXI.getSyncScopeID() == llvm::SyncScope::SingleThread) {
#endif
gen.writeFact(pred::instruction::flag, iref, "singlethread");
gen.writeFact(pred::instr::flag, iref, "singlethread");
}

if (!successOrdStr.empty())
Expand Down Expand Up @@ -786,39 +786,34 @@ void InstructionVisitor::writeOptimizationInfo(
#else
if (fpo->hasUnsafeAlgebra()) {
#endif
gen.writeFact(pred::instruction::flag, iref, "fast");
gen.writeFact(pred::instr::flag, iref, "fast");
} else {
if (fpo->hasNoNaNs())
gen.writeFact(pred::instruction::flag, iref, "nnan");
if (fpo->hasNoNaNs()) gen.writeFact(pred::instr::flag, iref, "nnan");

if (fpo->hasNoInfs())
gen.writeFact(pred::instruction::flag, iref, "ninf");
if (fpo->hasNoInfs()) gen.writeFact(pred::instr::flag, iref, "ninf");

if (fpo->hasNoSignedZeros())
gen.writeFact(pred::instruction::flag, iref, "nsz");
gen.writeFact(pred::instr::flag, iref, "nsz");

if (fpo->hasAllowReciprocal())
gen.writeFact(pred::instruction::flag, iref, "arcp");
gen.writeFact(pred::instr::flag, iref, "arcp");

#if LLVM_VERSION_MAJOR > 4 // new FPO fields
if (fpo->hasAllowContract())
gen.writeFact(pred::instruction::flag, iref, "acon");
gen.writeFact(pred::instr::flag, iref, "acon");
#endif
#if LLVM_VERSION_MAJOR > 5 // new FPO fields
if (fpo->hasApproxFunc())
gen.writeFact(pred::instruction::flag, iref, "apfn");
if (fpo->hasApproxFunc()) gen.writeFact(pred::instr::flag, iref, "apfn");
#endif
}
}

if (const auto *obo = dyn_cast<OverflowingBinaryOperator>(u)) {
if (obo->hasNoUnsignedWrap())
gen.writeFact(pred::instruction::flag, iref, "nuw");
if (obo->hasNoUnsignedWrap()) gen.writeFact(pred::instr::flag, iref, "nuw");

if (obo->hasNoSignedWrap())
gen.writeFact(pred::instruction::flag, iref, "nsw");
if (obo->hasNoSignedWrap()) gen.writeFact(pred::instr::flag, iref, "nsw");
} else if (const auto *div = dyn_cast<PossiblyExactOperator>(u)) {
if (div->isExact()) gen.writeFact(pred::instruction::flag, iref, "exact");
if (div->isExact()) gen.writeFact(pred::instr::flag, iref, "exact");
}
}

Expand Down
6 changes: 3 additions & 3 deletions PAInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ constexpr static char const* assertion_relations[] = {
"debuginfo_invalid_entry",
"schema_invalid_alias",
"schema_invalid_constant",
"schema_invalid_function",
"schema_invalid_global_variable",
"schema_invalid_instruction",
"schema_invalid_func",
"schema_invalid_global_var",
"schema_invalid_instr",
"schema_invalid_type",
"user_option_invalid"};

Expand Down
8 changes: 4 additions & 4 deletions PointerAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,16 +256,16 @@ static auto allocation_size(Analysis which) -> std::string {
assert(false && "unreachable");
}

static auto allocation_by_instruction(Analysis which) -> std::string {
static auto allocation_by_instr(Analysis which) -> std::string {
switch (which) {
case Analysis::DEBUG:
[[fallthrough]];
case Analysis::SUBSET_AND_UNIFICATION:
[[fallthrough]];
case Analysis::SUBSET:
return "subset_lift.allocation_by_instruction_ctx";
return "subset_lift.allocation_by_instr_ctx";
case Analysis::UNIFICATION:
return "unification_lift.allocation_by_instruction_ctx";
return "unification_lift.allocation_by_instr_ctx";
}
assert(false && "unreachable");
}
Expand Down Expand Up @@ -373,7 +373,7 @@ auto LegacyPointerAnalysis::runOnModule(llvm::Module &mod) -> bool {
const llvm::Value *,
int,
boost::flyweight<std::string>>(
allocation_by_instruction(datalog_analysis), llvm_val_map),
allocation_by_instr(datalog_analysis), llvm_val_map),
std::move(null_ptr_set),
std::move(call_graph));
if (!datalog_debug_option) {
Expand Down
114 changes: 57 additions & 57 deletions datalog/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,75 +34,75 @@ set(DL_SOURCES
${CMAKE_CURRENT_LIST_DIR}/context/drop.dl
${CMAKE_CURRENT_LIST_DIR}/context/lift.dl
${CMAKE_CURRENT_LIST_DIR}/context/interface.dl
${CMAKE_CURRENT_LIST_DIR}/schema/instruction.dl
${CMAKE_CURRENT_LIST_DIR}/schema/sitofp-instruction.dl
${CMAKE_CURRENT_LIST_DIR}/schema/extractvalue-instruction.dl
${CMAKE_CURRENT_LIST_DIR}/schema/xor-instruction.dl
${CMAKE_CURRENT_LIST_DIR}/schema/udiv-instruction.dl
${CMAKE_CURRENT_LIST_DIR}/schema/va-arg-instruction.dl
${CMAKE_CURRENT_LIST_DIR}/schema/instr.dl
${CMAKE_CURRENT_LIST_DIR}/schema/sitofp-instr.dl
${CMAKE_CURRENT_LIST_DIR}/schema/extractvalue-instr.dl
${CMAKE_CURRENT_LIST_DIR}/schema/xor-instr.dl
${CMAKE_CURRENT_LIST_DIR}/schema/udiv-instr.dl
${CMAKE_CURRENT_LIST_DIR}/schema/va-arg-instr.dl
${CMAKE_CURRENT_LIST_DIR}/schema/debug.dl
${CMAKE_CURRENT_LIST_DIR}/schema/func.dl
${CMAKE_CURRENT_LIST_DIR}/schema/fcmp-instruction.dl
${CMAKE_CURRENT_LIST_DIR}/schema/fdiv-instruction.dl
${CMAKE_CURRENT_LIST_DIR}/schema/select-instruction.dl
${CMAKE_CURRENT_LIST_DIR}/schema/indirectbr-instruction.dl
${CMAKE_CURRENT_LIST_DIR}/schema/srem-instruction.dl
${CMAKE_CURRENT_LIST_DIR}/schema/shufflevector-instruction.dl
${CMAKE_CURRENT_LIST_DIR}/schema/and-instruction.dl
${CMAKE_CURRENT_LIST_DIR}/schema/fcmp-instr.dl
${CMAKE_CURRENT_LIST_DIR}/schema/fdiv-instr.dl
${CMAKE_CURRENT_LIST_DIR}/schema/select-instr.dl
${CMAKE_CURRENT_LIST_DIR}/schema/indirectbr-instr.dl
${CMAKE_CURRENT_LIST_DIR}/schema/srem-instr.dl
${CMAKE_CURRENT_LIST_DIR}/schema/shufflevector-instr.dl
${CMAKE_CURRENT_LIST_DIR}/schema/and-instr.dl
${CMAKE_CURRENT_LIST_DIR}/schema/calling-convention.dl
${CMAKE_CURRENT_LIST_DIR}/schema/asm.dl
${CMAKE_CURRENT_LIST_DIR}/schema/sdiv-instruction.dl
${CMAKE_CURRENT_LIST_DIR}/schema/inttoptr-instruction.dl
${CMAKE_CURRENT_LIST_DIR}/schema/store-instruction.dl
${CMAKE_CURRENT_LIST_DIR}/schema/sdiv-instr.dl
${CMAKE_CURRENT_LIST_DIR}/schema/inttoptr-instr.dl
${CMAKE_CURRENT_LIST_DIR}/schema/store-instr.dl
${CMAKE_CURRENT_LIST_DIR}/schema/ordering.dl
${CMAKE_CURRENT_LIST_DIR}/schema/insertelement-instruction.dl
${CMAKE_CURRENT_LIST_DIR}/schema/icmp-instruction.dl
${CMAKE_CURRENT_LIST_DIR}/schema/shl-instruction.dl
${CMAKE_CURRENT_LIST_DIR}/schema/getelementptr-instruction.dl
${CMAKE_CURRENT_LIST_DIR}/schema/ashr-instruction.dl
${CMAKE_CURRENT_LIST_DIR}/schema/bitcast-instruction.dl
${CMAKE_CURRENT_LIST_DIR}/schema/uitofp-instruction.dl
${CMAKE_CURRENT_LIST_DIR}/schema/mul-instruction.dl
${CMAKE_CURRENT_LIST_DIR}/schema/fence-instruction.dl
${CMAKE_CURRENT_LIST_DIR}/schema/insertvalue-instruction.dl
${CMAKE_CURRENT_LIST_DIR}/schema/unreachable-instruction.dl
${CMAKE_CURRENT_LIST_DIR}/schema/insertelement-instr.dl
${CMAKE_CURRENT_LIST_DIR}/schema/icmp-instr.dl
${CMAKE_CURRENT_LIST_DIR}/schema/shl-instr.dl
${CMAKE_CURRENT_LIST_DIR}/schema/getelementptr-instr.dl
${CMAKE_CURRENT_LIST_DIR}/schema/ashr-instr.dl
${CMAKE_CURRENT_LIST_DIR}/schema/bitcast-instr.dl
${CMAKE_CURRENT_LIST_DIR}/schema/uitofp-instr.dl
${CMAKE_CURRENT_LIST_DIR}/schema/mul-instr.dl
${CMAKE_CURRENT_LIST_DIR}/schema/fence-instr.dl
${CMAKE_CURRENT_LIST_DIR}/schema/insertvalue-instr.dl
${CMAKE_CURRENT_LIST_DIR}/schema/unreachable-instr.dl
${CMAKE_CURRENT_LIST_DIR}/schema/activate-sanity.dl
${CMAKE_CURRENT_LIST_DIR}/schema/constants.dl
${CMAKE_CURRENT_LIST_DIR}/schema/sext-instruction.dl
${CMAKE_CURRENT_LIST_DIR}/schema/alloca-instruction.dl
${CMAKE_CURRENT_LIST_DIR}/schema/add-instruction.dl
${CMAKE_CURRENT_LIST_DIR}/schema/cmpxchg-instruction.dl
${CMAKE_CURRENT_LIST_DIR}/schema/br-instruction.dl
${CMAKE_CURRENT_LIST_DIR}/schema/invoke-instruction.dl
${CMAKE_CURRENT_LIST_DIR}/schema/ptrtoint-instruction.dl
${CMAKE_CURRENT_LIST_DIR}/schema/zext-instruction.dl
${CMAKE_CURRENT_LIST_DIR}/schema/fptoui-instruction.dl
${CMAKE_CURRENT_LIST_DIR}/schema/load-instruction.dl
${CMAKE_CURRENT_LIST_DIR}/schema/fsub-instruction.dl
${CMAKE_CURRENT_LIST_DIR}/schema/extractelement-instruction.dl
${CMAKE_CURRENT_LIST_DIR}/schema/fptosi-instruction.dl
${CMAKE_CURRENT_LIST_DIR}/schema/sub-instruction.dl
${CMAKE_CURRENT_LIST_DIR}/schema/fptrunc-instruction.dl
${CMAKE_CURRENT_LIST_DIR}/schema/phi-instruction.dl
${CMAKE_CURRENT_LIST_DIR}/schema/fmul-instruction.dl
${CMAKE_CURRENT_LIST_DIR}/schema/sext-instr.dl
${CMAKE_CURRENT_LIST_DIR}/schema/alloca-instr.dl
${CMAKE_CURRENT_LIST_DIR}/schema/add-instr.dl
${CMAKE_CURRENT_LIST_DIR}/schema/cmpxchg-instr.dl
${CMAKE_CURRENT_LIST_DIR}/schema/br-instr.dl
${CMAKE_CURRENT_LIST_DIR}/schema/invoke-instr.dl
${CMAKE_CURRENT_LIST_DIR}/schema/ptrtoint-instr.dl
${CMAKE_CURRENT_LIST_DIR}/schema/zext-instr.dl
${CMAKE_CURRENT_LIST_DIR}/schema/fptoui-instr.dl
${CMAKE_CURRENT_LIST_DIR}/schema/load-instr.dl
${CMAKE_CURRENT_LIST_DIR}/schema/fsub-instr.dl
${CMAKE_CURRENT_LIST_DIR}/schema/extractelement-instr.dl
${CMAKE_CURRENT_LIST_DIR}/schema/fptosi-instr.dl
${CMAKE_CURRENT_LIST_DIR}/schema/sub-instr.dl
${CMAKE_CURRENT_LIST_DIR}/schema/fptrunc-instr.dl
${CMAKE_CURRENT_LIST_DIR}/schema/phi-instr.dl
${CMAKE_CURRENT_LIST_DIR}/schema/fmul-instr.dl
${CMAKE_CURRENT_LIST_DIR}/schema/basic-block.dl
${CMAKE_CURRENT_LIST_DIR}/schema/global.dl
${CMAKE_CURRENT_LIST_DIR}/schema/call-instruction.dl
${CMAKE_CURRENT_LIST_DIR}/schema/ret-instruction.dl
${CMAKE_CURRENT_LIST_DIR}/schema/urem-instruction.dl
${CMAKE_CURRENT_LIST_DIR}/schema/fadd-instruction.dl
${CMAKE_CURRENT_LIST_DIR}/schema/call-instr.dl
${CMAKE_CURRENT_LIST_DIR}/schema/ret-instr.dl
${CMAKE_CURRENT_LIST_DIR}/schema/urem-instr.dl
${CMAKE_CURRENT_LIST_DIR}/schema/fadd-instr.dl
${CMAKE_CURRENT_LIST_DIR}/schema/type.dl
${CMAKE_CURRENT_LIST_DIR}/schema/operand.dl
${CMAKE_CURRENT_LIST_DIR}/schema/resume-instruction.dl
${CMAKE_CURRENT_LIST_DIR}/schema/frem-instruction.dl
${CMAKE_CURRENT_LIST_DIR}/schema/atomicrmw-instruction.dl
${CMAKE_CURRENT_LIST_DIR}/schema/or-instruction.dl
${CMAKE_CURRENT_LIST_DIR}/schema/trunc-instruction.dl
${CMAKE_CURRENT_LIST_DIR}/schema/switch-instruction.dl
${CMAKE_CURRENT_LIST_DIR}/schema/lshr-instruction.dl
${CMAKE_CURRENT_LIST_DIR}/schema/fpext-instruction.dl
${CMAKE_CURRENT_LIST_DIR}/schema/resume-instr.dl
${CMAKE_CURRENT_LIST_DIR}/schema/frem-instr.dl
${CMAKE_CURRENT_LIST_DIR}/schema/atomicrmw-instr.dl
${CMAKE_CURRENT_LIST_DIR}/schema/or-instr.dl
${CMAKE_CURRENT_LIST_DIR}/schema/trunc-instr.dl
${CMAKE_CURRENT_LIST_DIR}/schema/switch-instr.dl
${CMAKE_CURRENT_LIST_DIR}/schema/lshr-instr.dl
${CMAKE_CURRENT_LIST_DIR}/schema/fpext-instr.dl
${CMAKE_CURRENT_LIST_DIR}/schema/attr.dl
${CMAKE_CURRENT_LIST_DIR}/schema/landingpad-instruction.dl
${CMAKE_CURRENT_LIST_DIR}/schema/landingpad-instr.dl
${CMAKE_CURRENT_LIST_DIR}/callgraph/entry-points.dl
${CMAKE_CURRENT_LIST_DIR}/export/auxiliary-records.dl
${CMAKE_CURRENT_LIST_DIR}/export/subset.dl
Expand Down
24 changes: 12 additions & 12 deletions datalog/context/drop.dl
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,23 @@ num_direct_calls_to_func(?n, ?func) :-
func_decl(?func),
?n = count : _instr_calls_func(_, ?func).

.decl call_or_invoke_instruction_fn_type(?instr: Instruction, ?type: Type)
call_or_invoke_instruction_fn_type(?instr, ?fnType) :-
( call_instruction_fn_type(?instr, ?fnType)
; invoke_instruction_fn_type(?instr, ?fnType)
.decl call_or_invoke_instr_fn_type(?instr: Instruction, ?type: Type)
call_or_invoke_instr_fn_type(?instr, ?fnType) :-
( call_instr_fn_type(?instr, ?fnType)
; invoke_instr_fn_type(?instr, ?fnType)
).

.decl indirect_call_or_invoke_instruction(?instr: Instruction)
indirect_call_or_invoke_instruction(?instr) :-
indirect_call_instruction(?instr);
indirect_invoke_instruction(?instr).
.decl indirect_call_or_invoke_instr(?instr: Instruction)
indirect_call_or_invoke_instr(?instr) :-
indirect_call_instr(?instr);
indirect_invoke_instr(?instr).

.decl num_indirect_calls_to_compatible_func(?n: number, ?func: FunctionDecl)
num_indirect_calls_to_compatible_func(?n, ?func) :-
func_ty(?func, ?targetType),
?n = count : {
indirect_call_or_invoke_instruction(?instr),
call_or_invoke_instruction_fn_type(?instr, ?fnType),
indirect_call_or_invoke_instr(?instr),
call_or_invoke_instr_fn_type(?instr, ?fnType),
type_compatible(?fnType, ?targetType)
}.

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_instruction_fn_operand(?invoc, ?funcOp)
; invoke_instruction_fn_operand(?invoc, ?funcOp)
( call_instr_fn_operand(?invoc, ?funcOp)
; invoke_instr_fn_operand(?invoc, ?funcOp)
),
operand_has_type(?funcOp, ?funcOpType),
pointer_type_has_component(?funcOpType, ?declaredType),
Expand Down
16 changes: 8 additions & 8 deletions datalog/context/interface.dl
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ drop_last(?out, ?in),

.decl _reachable_call(?ctx: Context, ?instr: Instruction)
_reachable_call(?ctx, ?instr) :-
(call_instruction(?instr); invoke_instruction(?instr)),
instruction_in_func(?instr, ?func),
(call_instr(?instr); invoke_instr(?instr)),
instr_func(?instr, ?func),
reachable_context(?ctx, ?func).

// Merge is the constructor for new calling contexts.
Expand Down Expand Up @@ -156,14 +156,14 @@ drop_last(?out, ?in),

.decl count_context_items(?instr: Instruction, ?nContextItems: number)
count_context_items(?instr, ?nContextItems) :-
(call_instruction(?instr); invoke_instruction(?instr)),
(call_instr(?instr); invoke_instr(?instr)),
!drop_context_by_invoc(?instr),
!drop_context_item_by_invoc(?instr),
?nContextItems = count : context_item_by_invoc(?instr, _).

.decl count_contexts(?instr: Instruction, ?nContexts: number)
count_contexts(?instr, ?nContexts) :-
(call_instruction(?instr); invoke_instruction(?instr)),
(call_instr(?instr); invoke_instr(?instr)),
!drop_context_by_invoc(?instr),
!drop_context_item_by_invoc(?instr),
// Have to access internal relation due to inlining
Expand Down Expand Up @@ -251,8 +251,8 @@ context_item_by_invoc_interim(?invoc, ?ctxItem) :-
; Config = "8-callsite"
; Config = "9-callsite"
),
(call_instruction(?invoc);
invoke_instruction(?invoc)),
(call_instr(?invoc);
invoke_instr(?invoc)),
?ctxItem = ?invoc.

context_item_by_invoc_interim(?invoc, ?ctxItem) :-
Expand All @@ -267,8 +267,8 @@ context_item_by_invoc_interim(?invoc, ?ctxItem) :-
; Config = "8-caller"
; Config = "9-caller"
),
(call_instruction(?invoc); invoke_instruction(?invoc)),
instruction_in_func(?invoc, ?func),
(call_instr(?invoc); invoke_instr(?invoc)),
instr_func(?invoc, ?func),
func_name(?func, ?name),
?ctxItem = ?name.

Expand Down
Loading

0 comments on commit 4602f5b

Please sign in to comment.