Commit 967115eb authored by Henrich Lauko's avatar Henrich Lauko

lart: Introduce generic freeze/thaw instrumentation.

parent c95a7186
......@@ -6,6 +6,8 @@ DIVINE_RELAX_WARNINGS
#include <llvm/IR/IRBuilder.h>
DIVINE_UNRELAX_WARNINGS
#include <lart/abstract/stash.h>
#include <lart/support/util.h>
#include <lart/abstract/util.h>
#include <lart/abstract/operation.h>
......@@ -13,23 +15,63 @@ DIVINE_UNRELAX_WARNINGS
namespace lart::abstract
{
bool is_faultable( llvm::Instruction * inst )
{
using Inst = llvm::Instruction;
if ( auto bin = llvm::dyn_cast< llvm::BinaryOperator >( inst ) ) {
auto op = bin->getOpcode();
return op == Inst::UDiv ||
op == Inst::SDiv ||
op == Inst::FDiv ||
op == Inst::URem ||
op == Inst::SRem ||
op == Inst::FRem;
struct ThawPass {
void run( llvm::Module &m )
{
thawFn = llvm::cast< llvm::Function >( m.getFunction( "__lart_thaw" ) );
ASSERT( thawFn, "Missing implementation of 'thaw' function." );
const auto tag = meta::tag::operation::thaw;
for ( auto l : meta::enumerate< llvm::LoadInst >( m, tag ) )
thaw( l );
}
return llvm::isa< llvm::CallInst >( inst );
}
void thaw( llvm::LoadInst *load ) const noexcept
{
llvm::IRBuilder<> irb( load->getNextNode() );
auto fty = thawFn->getFunctionType();
auto addr = irb.CreateBitCast( load->getPointerOperand(), fty->getParamType( 0 ) );
irb.CreateCall( thawFn, { addr } );
}
llvm::Function * thawFn = nullptr;
};
struct FreezePass {
void run( llvm::Module &m )
{
freezeFn = llvm::cast< llvm::Function >( m.getFunction( "__lart_freeze" ) );
ASSERT( freezeFn, "Missing implementation of 'freeze' function." );
_matched.init( m );
const auto tag = meta::tag::operation::freeze;
for ( auto s : meta::enumerate< llvm::StoreInst >( m, tag ) )
freeze( s );
}
void freeze( llvm::StoreInst *store ) const noexcept
{
auto abs = _matched.abstract.at( store->getValueOperand() );
auto fty = freezeFn->getFunctionType();
llvm::IRBuilder<> irb( store->getNextNode() );
auto addr = irb.CreateBitCast( store->getPointerOperand(), fty->getParamType( 1 ) );
irb.CreateCall( freezeFn, { abs, addr } );
}
Matched _matched;
llvm::Function * freezeFn = nullptr;
};
void Syntactic::run( llvm::Module &m ) {
ThawPass().run( m );
auto abstract = query::query( meta::enumerate( m ) )
.map( query::llvmdyncast< llvm::Instruction > )
.filter( query::notnull )
......@@ -48,6 +90,8 @@ namespace lart::abstract
builder.construct( inst );
}
FreezePass().run( m );
}
} // namespace lart::abstract
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment