forked from microsoft/llvm-mctoll
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFunctionFilter.h
97 lines (87 loc) · 3.8 KB
/
FunctionFilter.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
//===-- FunctionFilter.h ----------------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file contains the definition of FunctionFilter class that encapsulates
// user-specified function filters (include and exclude) of functions to be
// raised via the command line option --filter-functions-file.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_TOOLS_LLVM_MCTOLL_FUNCTIONFILTER_H
#define LLVM_TOOLS_LLVM_MCTOLL_FUNCTIONFILTER_H
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/Module.h"
using namespace llvm;
/// Class encapsulating lists of function specifications to be included and
/// excluded along with methods to maintain and query the lists.
class FunctionFilter {
public:
/// Filter types supported
enum FilterType {
FILTER_NONE,
FILTER_EXCLUDE, // To be excluded.
FILTER_INCLUDE // To be included.
};
/// The function information which is used during raising call instructions.
class FuncInfo {
public:
FuncInfo()
: StartIdx(0), SymName(nullptr), FuncType(nullptr), Func(nullptr){};
~FuncInfo() {
if (SymName == nullptr)
delete SymName;
};
StringRef getSymName() const {
assert(SymName != nullptr && "Uninitialized symbol name found!");
StringRef Sym(*SymName);
return Sym;
};
uint64_t StartIdx; // The function start index.
std::string *SymName; // Symbol name.
FunctionType *FuncType; // Function type.
Function *Func; // Pointer to the corresponding module function.
};
using FuncInfoVector = std::vector<FunctionFilter::FuncInfo *>;
FunctionFilter() = delete;
FunctionFilter(Module &Mod) : M(Mod){};
~FunctionFilter();
/// Parse input string as symbol name and function type.
bool parsePrototypeStr(StringRef &InProt, FuncInfo &OutProt);
/// Get the function corresponding to the function prototype, if it exists;
/// else create one add it to Module.
Function *getOrCreateFunctionByPrototype(FuncInfo &Prot);
/// Find function with symbol name in specified list type.
FunctionFilter::FuncInfo *findFuncInfoBySymbol(StringRef &Sym,
FunctionFilter::FilterType FT);
/// Find function with start index in the specified list type.
Function *findFunctionByIndex(uint64_t StartIndex,
FunctionFilter::FilterType FT);
/// Add a new function with given prototype to excluded function list.
void addExcludedFunction(StringRef &PrototypeStr);
/// Add a new function with given prototype to included function list.
void addIncludedFunction(StringRef &PrototypeStr);
/// Erase a function information from specified list type by symbol name.
void eraseFunctionBySymbol(StringRef &Sym, FunctionFilter::FilterType FT);
/// Get the data type corresponding to type string.
Type *getPrimitiveDataType(const StringRef &TypeStr);
/// Read user-specified include and exclude functions from file
bool readFilterFunctionConfigFile(std::string &FunctionFilterFilename);
/// Test if the list of specified list is empty.
bool isFilterSetEmpty(FilterType);
/// Dump the list of specified list; dump both include and exclude lists if no
/// argument is specified.
void dump(FilterType FT = FILTER_NONE);
private:
/// Excluded function vector.
FuncInfoVector ExcludedFunctionVector;
/// Included function vector.
FuncInfoVector IncludedFunctionVector;
// Module associated with this class
Module &M;
};
#endif // LLVM_TOOLS_LLVM_MCTOLL_FUNCTIONFILTER_H