Skip to content

Commit

Permalink
fact-gen: support freeze instruction
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianherrera authored and langston-barrett committed Apr 7, 2023
1 parent 79e8394 commit 1a64af9
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions FactGenerator/include/InstructionVisitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class cclyzer::InstructionVisitor
void visitCallInst(const llvm::CallInst &);
void visitDbgDeclareInst(const llvm::DbgDeclareInst &);
void visitVAArgInst(const llvm::VAArgInst &);
void visitFreezeInst(const llvm::FreezeInst &);

// Vector Operations

Expand Down
5 changes: 5 additions & 0 deletions FactGenerator/include/predicates.inc
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,11 @@ PREDICATE2(fneg, instr)
PREDICATEI(fneg, operand)
GROUP_END(fneg)

GROUP_BEGIN(freeze)
PREDICATE2(freeze, instr)
PREDICATEI(freeze, operand)
GROUP_END(freeze)

// Types

GROUP_BEGIN(primitive_type)
Expand Down
6 changes: 6 additions & 0 deletions FactGenerator/src/InstructionVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,12 @@ void InstructionVisitor::visitUnaryInstruction(
}
}

void InstructionVisitor::visitFreezeInst(const llvm::FreezeInst &FI) {
refmode_t iref = recordInstruction(pred::freeze::instr, FI);

writeInstrOperand(pred::freeze::operand, iref, FI.getOperand(0));
}

void InstructionVisitor::visitInstruction(const llvm::Instruction &I) {
unknown("instruction", I.getOpcodeName());
}
Expand Down
1 change: 1 addition & 0 deletions datalog/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ set(DL_SOURCES
${CMAKE_CURRENT_LIST_DIR}/schema/phi-instr.dl
${CMAKE_CURRENT_LIST_DIR}/schema/fmul-instr.dl
${CMAKE_CURRENT_LIST_DIR}/schema/fneg-instr.dl
${CMAKE_CURRENT_LIST_DIR}/schema/freeze-instr.dl
${CMAKE_CURRENT_LIST_DIR}/schema/basic-block.dl
${CMAKE_CURRENT_LIST_DIR}/schema/global.dl
${CMAKE_CURRENT_LIST_DIR}/schema/call-instr.dl
Expand Down
2 changes: 2 additions & 0 deletions datalog/export/debug-output-extended.dl
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,8 @@
.output fptrunc_instr_from_operand (compress=true)
.output fptrunc_instr_from_type (compress=true)
.output fptrunc_instr_to_type (compress=true)
.output freeze_instr (compress=true)
.output freeze_instr_operand (compress=true)
.output frem_instr (compress=true)
.output frem_instr_first_operand (compress=true)
.output frem_instr_second_operand (compress=true)
Expand Down
2 changes: 2 additions & 0 deletions datalog/export/debug-output.dl
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,8 @@
.output fptrunc_instr_from_operand (compress=true)
.output fptrunc_instr_from_type (compress=true)
.output fptrunc_instr_to_type (compress=true)
.output freeze_instr (compress=true)
.output freeze_instr_operand (compress=true)
.output frem_instr (compress=true)
.output frem_instr_first_operand (compress=true)
.output frem_instr_second_operand (compress=true)
Expand Down
28 changes: 28 additions & 0 deletions datalog/schema/freeze-instr.dl
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// http://llvm.org/docs/LangRef.html#freeze-instr
// keywords: instr

.type FreezeInstruction <: symbol
.decl freeze_instr(instr:FreezeInstruction)

instr(v) :- freeze_instr(v).

.decl freeze_instr_operand(instr:FreezeInstruction, val:Operand)


//------------------------------------------------------------------------------
// [Constraints]
//
// The ‘freeze‘ instr requires that the resulting value is the same type as its
// operand.
//------------------------------------------------------------------------------

schema_invalid_instr(Instr, __FILE__, __LINE__) :-
schema_sanity(),
freeze_instr(Instr),
!freeze_instr_operand(Instr, _).

schema_invalid_instr(Instr, __FILE__, __LINE__) :-
schema_sanity(),
instr_returns_type(Instr, Type),
freeze_instr_operand(Instr, Op),
!operand_has_type(Op, Type).
1 change: 1 addition & 0 deletions datalog/schema/instr.dl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
| FRemInstruction
| FSubInstruction
| FenceInstruction
| FreezeInstruction
| GetElementPtrInstruction
| ICmpInstruction
| IndirectBrInstruction
Expand Down
1 change: 1 addition & 0 deletions datalog/schema/schema.project
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "fmul-instr.dl"
#include "fneg-instr.dl"
#include "fdiv-instr.dl"
#include "freeze-instr.dl"
#include "frem-instr.dl"
#include "and-instr.dl"
#include "or-instr.dl"
Expand Down

0 comments on commit 1a64af9

Please sign in to comment.