/* * (c) 2016 Vladimír Štill * (c) 2020 Lukáš Korenčik * * 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 DIVINE_UNRELAX_WARNINGS namespace lart { namespace meta { inline bool has_tag( llvm::GlobalObject &go, const std::string &kind ) { return go.getMetadata( kind ); } inline bool tag( llvm::GlobalObject &go, const std::string &kind ) { if ( has_tag( go, kind ) ) return false; auto node = llvm::MDNode::get( go.getContext(), llvm::MDString::get( go.getContext(), kind ) ); go.setMetadata( kind, node ); return true; } } inline bool tagModuleWithMetadata( llvm::Module &m, std::string tag ) { if ( m.getNamedMetadata( tag ) ) return false; m.getOrInsertNamedMetadata( tag ); return true; } inline bool tagFunctionWithMetadata( llvm::Function &fn, std::string tag ) { if ( fn.getMetadata( tag ) ) return false; auto & ctx = fn.getContext(); auto dummy = llvm::MDString::get( ctx, "dummy" ); auto meta = llvm::MDTuple::get( ctx , { dummy } ); fn.setMetadata( tag, meta ); return true; } }