#ifndef LLVM_XRAY_INSTRUMENTATIONMAP_H
#define LLVM_XRAY_INSTRUMENTATIONMAP_H
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/YAMLTraits.h"
#include <cstdint>
#include <unordered_map>
#include <vector>
namespace llvm {
namespace xray {
class InstrumentationMap;
Expected<InstrumentationMap> loadInstrumentationMap(StringRef Filename);
struct SledEntry {
enum class FunctionKinds { ENTRY, EXIT, TAIL, LOG_ARGS_ENTER, CUSTOM_EVENT };
uint64_t Address;
uint64_t Function;
FunctionKinds Kind;
bool AlwaysInstrument;
unsigned char Version;
};
struct YAMLXRaySledEntry {
int32_t FuncId;
yaml::Hex64 Address;
yaml::Hex64 Function;
SledEntry::FunctionKinds Kind;
bool AlwaysInstrument;
std::string FunctionName;
unsigned char Version;
};
class InstrumentationMap {
public:
using FunctionAddressMap = std::unordered_map<int32_t, uint64_t>;
using FunctionAddressReverseMap = std::unordered_map<uint64_t, int32_t>;
using SledContainer = std::vector<SledEntry>;
private:
SledContainer Sleds;
FunctionAddressMap FunctionAddresses;
FunctionAddressReverseMap FunctionIds;
friend Expected<InstrumentationMap> loadInstrumentationMap(StringRef);
public:
const FunctionAddressMap &getFunctionAddresses() { return FunctionAddresses; }
Optional<int32_t> getFunctionId(uint64_t Addr) const;
Optional<uint64_t> getFunctionAddr(int32_t FuncId) const;
const SledContainer &sleds() const { return Sleds; };
};
}
namespace yaml {
template <> struct ScalarEnumerationTraits<xray::SledEntry::FunctionKinds> {
static void enumeration(IO &IO, xray::SledEntry::FunctionKinds &Kind) {
IO.enumCase(Kind, "function-enter", xray::SledEntry::FunctionKinds::ENTRY);
IO.enumCase(Kind, "function-exit", xray::SledEntry::FunctionKinds::EXIT);
IO.enumCase(Kind, "tail-exit", xray::SledEntry::FunctionKinds::TAIL);
IO.enumCase(Kind, "log-args-enter",
xray::SledEntry::FunctionKinds::LOG_ARGS_ENTER);
IO.enumCase(Kind, "custom-event",
xray::SledEntry::FunctionKinds::CUSTOM_EVENT);
}
};
template <> struct MappingTraits<xray::YAMLXRaySledEntry> {
static void mapping(IO &IO, xray::YAMLXRaySledEntry &Entry) {
IO.mapRequired("id", Entry.FuncId);
IO.mapRequired("address", Entry.Address);
IO.mapRequired("function", Entry.Function);
IO.mapRequired("kind", Entry.Kind);
IO.mapRequired("always-instrument", Entry.AlwaysInstrument);
IO.mapOptional("function-name", Entry.FunctionName);
IO.mapOptional("version", Entry.Version, 0);
}
static constexpr bool flow = true;
};
}
}
LLVM_YAML_IS_SEQUENCE_VECTOR(xray::YAMLXRaySledEntry)
#endif