IR2Vec
Loading...
Searching...
No Matches
IR2Vec.h
1//===- IR2Vec.h - Top-level driver utility ----------------------*- C++ -*-===//
2//
3// Part of the IR2Vec Project, under the Apache License v2.0 with LLVM
4// Exceptions. See the LICENSE file for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef __IR2Vec__
10#define __IR2Vec__
11
12#include "llvm/ADT/MapVector.h"
13#include "llvm/IR/Module.h"
14#include <string>
15
16namespace IR2Vec {
17
18#define DIM 300
19using Vector = llvm::SmallVector<double, DIM>;
20
21enum IR2VecMode { FlowAware, Symbolic };
22
24 int generateEncodings(llvm::Module &M, IR2VecMode mode, char level = '\0',
25 std::string funcName = "", std::ostream *o = nullptr,
26 int cls = -1, float WO = 1, float WA = 0.2,
27 float WT = 0.5);
28
29 llvm::SmallMapVector<const llvm::Instruction *, Vector, 128> instVecMap;
30 llvm::SmallMapVector<const llvm::Function *, Vector, 16> funcVecMap;
31 Vector pgmVector;
32
33public:
34 Embeddings() = default;
35 Embeddings(llvm::Module &M, IR2VecMode mode, std::string funcName = "",
36 float WO = 1, float WA = 0.2, float WT = 0.5) {
37 generateEncodings(M, mode, '\0', funcName, nullptr, -1, WO, WA, WT);
38 }
39
40 // Use this constructor if the representations ought to be written to a
41 // file. Analogous to the command line options that are being used in IR2Vec
42 // binary.
43 Embeddings(llvm::Module &M, IR2VecMode mode, char level, std::ostream *o,
44 std::string funcName = "", float WO = 1, float WA = 0.2,
45 float WT = 0.5) {
46 generateEncodings(M, mode, level, funcName, o, -1, WO, WA, WT);
47 }
48
49 // Returns a map containing instructions and the corresponding vector
50 // representations for a given module corresponding to the IR2VecMode and
51 // other configurations that is set in constructor
52 llvm::SmallMapVector<const llvm::Instruction *, Vector, 128> &
53 getInstVecMap() {
54 return instVecMap;
55 }
56
57 // Returns a map containing functions and the corresponding vector
58 // representations for a given module corresponding to the IR2VecMode and
59 // other configurations that is set in constructor
60 llvm::SmallMapVector<const llvm::Function *, Vector, 16> &
61 getFunctionVecMap() {
62 return funcVecMap;
63 }
64
65 // Returns the program vector for a module corresponding to the IR2VecMode
66 // and other configurations that is set in constructor
67 Vector &getProgramVector() { return pgmVector; }
68};
69
70} // namespace IR2Vec
71#endif
Definition IR2Vec.h:23