Commit 072e711b authored by Henrich Lauko's avatar Henrich Lauko

lart: Introduce annotation pass.

parent 4cf1f4a8
......@@ -8,6 +8,7 @@
#include <lart/svcomp/passes.h>
#include <lart/divine/passes.h>
#include <lart/support/fixphi.h>
#include <lart/support/annotate.h>
#include <iostream>
......@@ -32,6 +33,7 @@ struct Driver {
std::vector< PassMeta > passes() const {
std::vector< PassMeta > out;
out.push_back( AnnotateFunctions::meta() );
out.push_back( weakmem::meta() );
insertPasses( out, reduction::passes() );
insertPasses( out, svcomp::passes() );
......
// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 4 -*-
/*
* (c) 2019 Henrich Lauko <xlauko@mail.muni.cz>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <lart/support/annotate.h>
namespace lart {
void AnnotateFunctions::run( llvm::Module &m )
{
for ( auto & fn : m )
if ( match( fn ) )
annotate( fn );
}
bool AnnotateFunctions::match( const llvm::Function & fn ) const noexcept
{
auto name = fn.getName();
return std::regex_match( name.begin(), name.end(), _rgx );
}
void AnnotateFunctions::annotate( llvm::Function & fn ) const noexcept
{
fn.addFnAttr( _annotation.name() );
}
} // namespace lart
// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 4 -*-
/*
* (c) 2019 Henrich Lauko <xlauko@mail.muni.cz>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#pragma once
DIVINE_RELAX_WARNINGS
#include <llvm/IR/Module.h>
#include <llvm/IR/Instructions.h>
DIVINE_UNRELAX_WARNINGS
#include <lart/support/pass.h>
#include <lart/support/meta.h>
#include <brick-llvm>
#include <regex>
namespace lart
{
/* Annotates all functions which name is matched by given regex */
struct AnnotateFunctions
{
using Annotation = brick::llvm::Annotation;
AnnotateFunctions( std::string opt )
{
std::stringstream ss( opt );
std::string annotation;
std::getline( ss, annotation, ':' );
_annotation = Annotation{ annotation };
std::string rgx;
std::getline( ss, rgx, ':' );
_rgx = std::regex{ rgx };
}
static PassMeta meta() {
return passMetaO< AnnotateFunctions >( "annotate",
"options: annotation:regex\n"
"\n"
"Adds to matched functions attribute named 'annotation'.\n" );
}
void run( llvm::Module &m );
bool match( const llvm::Function & fn ) const noexcept;
void annotate( llvm::Function & fn ) const noexcept;
brick::llvm::Annotation _annotation;
std::regex _rgx;
};
} // namespace lart
......@@ -200,6 +200,13 @@ struct PtrPlusBit {
T *ptr;
};
static inline auto functions_with_attr( const std::string & attr, llvm::Module & m ) {
std::set< llvm::Function * > set;
brick::llvm::enumerateFunctionsForAttribute( attr, m,
[&]( llvm::Function &f ) { set.insert( &f ); } );
return set;
}
template< typename... Ts >
bool is_one_of( llvm::Value *v ) {
return ( llvm::isa< Ts >( v ) || ... );
......
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