// // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo // // The contents of this file are covered under the licence agreement in the // file "LICENCE" distributed with Cforall. // // MutexFuncHash.hpp -- Hash utility for mutex function identity. // // Author : Matthew Au-Yeung // Created On : Tue Jan 28 2026 // #pragma once #include #include #include "AST/Decl.hpp" #include "AST/Expr.hpp" #include "SymTab/Mangler.hpp" namespace Concurrency { // FNV-1a hash of a function declaration's mangled name. // Used to identify mutex functions across translation units, // since function pointers may differ for static inline functions. static inline uint64_t hashMangle( const ast::DeclWithType * decl ) { std::string name = Mangle::mangleType( decl ); uint64_t hash = 14695981039346656037ULL; // FNV offset basis for ( char c : name ) { hash ^= static_cast( c ); hash *= 1099511628211ULL; // FNV prime } return hash; } // Create a ConstantExpr with the hash of the mangled name. static inline ast::ConstantExpr * hashMangleExpr( const CodeLocation & location, const ast::DeclWithType * decl ) { return ast::ConstantExpr::from_ulonglong( location, hashMangle( decl ) ); } } // namespace Concurrency