Files
revng-revng/include/revng/Support/BasicBlockID.h
Alessandro Di Federico 1429b526ab Introduce libtcg
This commit drops libptc in favor of its new form libtcg.

It brings several improvements, among which:

* The QEMU version we work on has been upgraded.
* CPUStateAccessAnalysis has been reimplemented in a way that makes it
  easier to debug and solves some limitations (e.g., tracking leaking
  pointers).
* Identification of pieces of the CPU state that are read by each helper
  and fixing access to the CPU state is now performed at build-time.
* We no longer mmap the code we need to translate, dropping all the
  issues related to code that needed to be mapped where something is
  already present.
* We now have two distinct flavors of helper modules: the full one and
  the "slim" one. The latter contains the definition only of functions
  we intend to inline. It is used in most of the pipeline, a good thing
  since we spend less time optimizing code we don't really care about.
  The full module is only used on the re-compilation branch of the
  pipeline.
* We no longer split the `cpu_loop` function.
* We change MetaAddress to rely on architectures from `model::` as
  opposed to the LLVM ones.
* We no longer attach debug info to LLVM IR containing the original
  assembly.
* We now verify that the lifted code only contains code we expect.
2025-10-31 17:25:03 +01:00

106 lines
2.7 KiB
C++

#pragma once
//
// This file is distributed under the MIT License. See LICENSE.md for details.
//
#include <cstdint>
#include <string>
#include "revng/Support/MetaAddress.h"
class BasicBlockID {
private:
MetaAddress Start = MetaAddress::invalid();
uint64_t InliningIndex = 0;
public:
explicit BasicBlockID() = default;
explicit BasicBlockID(const MetaAddress &Start) : Start(Start) {}
explicit BasicBlockID(const MetaAddress &Start, uint64_t Index) :
Start(Start), InliningIndex(Index) {
revng_assert(verify());
}
/// Create an invalid BasicBlockID
static constexpr BasicBlockID invalid() { return BasicBlockID(); }
public:
const MetaAddress &start() const { return Start; }
uint64_t inliningIndex() const { return InliningIndex; }
const MetaAddress &notInlinedAddress() const {
revng_assert(InliningIndex == 0);
return start();
}
public:
[[nodiscard]] bool isInlined() const { return InliningIndex != 0; }
[[nodiscard]] bool isValid() const { return Start.isValid(); }
public:
static BasicBlockID fromString(llvm::StringRef Text);
std::string toString(model::Architecture::Values Architecture =
model::Architecture::Invalid) const;
static BasicBlockID fromValue(llvm::Value *V);
llvm::Constant *toValue(llvm::Module *M) const;
public:
/// @{
constexpr bool operator==(const BasicBlockID &Other) const {
return tie() == Other.tie();
}
constexpr bool operator!=(const BasicBlockID &Other) const {
return not(*this == Other);
}
constexpr bool operator<(const BasicBlockID &Other) const {
return tie() < Other.tie();
}
constexpr bool operator<=(const BasicBlockID &Other) const {
return tie() <= Other.tie();
}
constexpr bool operator>(const BasicBlockID &Other) const {
return tie() > Other.tie();
}
constexpr bool operator>=(const BasicBlockID &Other) const {
return tie() >= Other.tie();
}
constexpr std::strong_ordering operator<=>(const BasicBlockID &Other) const {
return tie() <=> Other.tie();
}
/// @}
public:
[[nodiscard]] bool verify() const {
if (Start.isInvalid()) {
return InliningIndex == 0;
}
return true;
}
private:
using Tied = std::tuple<const MetaAddress &, const uint64_t &>;
constexpr Tied tie() const { return std::tie(Start, InliningIndex); }
};
template<>
struct KeyedObjectTraits<BasicBlockID>
: public IdentityKeyedObjectTraits<BasicBlockID> {};
inline llvm::hash_code hash_value(const BasicBlockID &BBID) {
return llvm::hash_combine(BBID.start(), BBID.inliningIndex());
}
template<>
struct std::hash<const BasicBlockID> {
uint64_t operator()(const BasicBlockID &BBID) const {
return hash_value(BBID);
}
};
template<>
struct std::hash<BasicBlockID> : hash<const BasicBlockID> {};