2#include "llvm/ADT/DenseMapInfo.h"
3#include <llvm/ADT/ArrayRef.h>
4#include <llvm/ADT/SmallVector.h>
5#include <llvm/ADT/StringRef.h>
6#include <llvm/ADT/Twine.h>
7#include <llvm/Demangle/Demangle.h>
8#include <llvm/IR/Function.h>
9#include <llvm/IR/Module.h>
10#include <llvm/Support/raw_ostream.h>
16template <>
struct DenseMapInfo<std::string> {
21 return std::string(
"<TOMBSTONE_KEY>");
25 return std::hash<std::string>{}(Key);
27 static bool isEqual(
const std::string &LHS,
const std::string &RHS) {
36 return llvm::demangle(Name.substr(0, Name.find(
"__intern__")));
41 OS << llvm::StringRef(reinterpret_cast<const char *>(&Value),
sizeof(Value));
44inline void writeBytes(llvm::raw_ostream &OS, llvm::StringRef Data) {
49inline void writeBytes(llvm::raw_ostream &OS, llvm::ArrayRef<uint8_t> Data) {
50 writeBytes(OS, llvm::StringRef(
reinterpret_cast<const char *
>(Data.data()),
55inline static llvm::SmallVector<std::string> getArgNames(llvm::Function &F) {
56 llvm::SmallVector<std::string>
Info;
57 for (
auto &A : F.args()) {
58 auto name = A.getName().str();
67inline static llvm::SmallVector<bool> canSpecialize(llvm::Function &F) {
68 llvm::SmallVector<bool> RRInfo;
69 for (
auto &A : F.args()) {
70 llvm::Type *ArgType = A.getType();
71 if (ArgType->isIntegerTy(1)) {
72 RRInfo.emplace_back(
true);
73 }
else if (ArgType->isIntegerTy(8)) {
74 RRInfo.emplace_back(
true);
75 }
else if (ArgType->isIntegerTy(32)) {
76 RRInfo.emplace_back(
true);
77 }
else if (ArgType->isIntegerTy(64)) {
78 RRInfo.emplace_back(
true);
79 }
else if (ArgType->isFloatTy()) {
80 RRInfo.emplace_back(
true);
81 }
else if (ArgType->isDoubleTy()) {
82 RRInfo.emplace_back(
true);
83 }
else if (ArgType->isX86_FP80Ty() || ArgType->isPPC_FP128Ty() ||
84 ArgType->isFP128Ty()) {
85 RRInfo.emplace_back(
true);
87 RRInfo.emplace_back(
false);
93inline static llvm::SmallVector<std::function<double(
void *)>>
94convertToDouble(llvm::Function &F) {
95 llvm::SmallVector<std::function<double(
void *)>> RRInfo;
96 for (
auto &A : F.args()) {
97 llvm::Type *ArgType = A.getType();
98 if (ArgType->isIntegerTy(1)) {
99 RRInfo.emplace_back([](
void *data) {
100 bool val = *(
bool *)data;
103 }
else if (ArgType->isIntegerTy(8)) {
104 RRInfo.emplace_back([](
void *data) {
105 int8_t val = *(int8_t *)data;
108 }
else if (ArgType->isIntegerTy(32)) {
109 RRInfo.emplace_back([](
void *data) {
110 int32_t val = *(int32_t *)data;
113 }
else if (ArgType->isIntegerTy(64)) {
114 RRInfo.emplace_back([](
void *data) {
115 int64_t val = *(int64_t *)data;
118 }
else if (ArgType->isFloatTy()) {
119 RRInfo.emplace_back([](
void *data) {
120 float val = *(
float *)data;
123 }
else if (ArgType->isDoubleTy()) {
124 RRInfo.emplace_back([](
void *data) {
125 double val = *(
double *)data;
128 }
else if (ArgType->isX86_FP80Ty() || ArgType->isPPC_FP128Ty() ||
129 ArgType->isFP128Ty()) {
130 RRInfo.emplace_back([](
void *data) {
131 double val = *(
double *)data;
135 RRInfo.emplace_back([](
void *data) {
136 double val = *(
double *)data;
144inline static llvm::SmallVector<uint64_t, 8> getFuncDescr(llvm::Function &F) {
145 llvm::SmallVector<uint64_t, 8> RRInfo;
146 auto DL = F.getParent()->getDataLayout();
147 for (
auto &A : F.args()) {
152 if (A.hasByRefAttr() || A.hasByValAttr()) {
153 RRInfo.emplace_back(DL.getTypeStoreSize(A.getPointeeInMemoryValueType()));
155 RRInfo.emplace_back(DL.getTypeStoreSize(A.getType()));
Definition attribute.cpp:39
Definition MnemeLLVMUtils.hpp:34
std::string demangleKernelName(const std::string &Name)
Definition MnemeLLVMUtils.hpp:35
void writeBytes(llvm::raw_ostream &OS, llvm::StringRef Data)
Definition MnemeLLVMUtils.hpp:44
void writeScalar(llvm::raw_ostream &OS, const Ty &Value)
Definition MnemeLLVMUtils.hpp:40
Definition MnemeAnnotation.cpp:3
@ Info
Definition MnemeConfig.hpp:23
static bool isEqual(const std::string &LHS, const std::string &RHS)
Definition MnemeLLVMUtils.hpp:27
static std::string getTombstoneKey()
Definition MnemeLLVMUtils.hpp:20
static unsigned getHashValue(const std::string &Key)
Definition MnemeLLVMUtils.hpp:23
static std::string getEmptyKey()
Definition MnemeLLVMUtils.hpp:17