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
16#include "Vocabulary.h"
17namespace IR2Vec {
18
19enum IR2VecMode { FlowAware, Symbolic };
20
22 int generateEncodings(llvm::Module &M, IR2VecMode mode, char level = '\0',
23 std::string funcName = "", unsigned dim = 300,
24 std::ostream *o = nullptr, int cls = -1, float WO = 1,
25 float WA = 0.2, float WT = 0.5);
26
27 llvm::SmallMapVector<const llvm::Instruction *, Vector, 128> instVecMap;
28 llvm::SmallMapVector<const llvm::BasicBlock *, IR2Vec::Vector, 16> bbVecMap;
29 llvm::SmallMapVector<const llvm::Function *, Vector, 16> funcVecMap;
30 Vector pgmVector;
31 std::map<std::string, IR2Vec::Vector> vocabulary;
32
33public:
34 Embeddings() = default;
35 Embeddings(llvm::Module &M, IR2VecMode mode, unsigned dim = 300,
36 std::string funcName = "", float WO = 1, float WA = 0.2,
37 float WT = 0.5) {
38 vocabulary = VocabularyFactory::createVocabulary(dim)->getVocabulary();
39 generateEncodings(M, mode, '\0', funcName, dim, nullptr, -1, WO, WA, WT);
40 }
41
42 // Use this constructor if the representations ought to be written to a
43 // file. Analogous to the command line options that are being used in IR2Vec
44 // binary.
45 Embeddings(llvm::Module &M, IR2VecMode mode, char level, std::ostream *o,
46 unsigned dim = 300, std::string funcName = "", float WO = 1,
47 float WA = 0.2, float WT = 0.5) {
48 vocabulary = VocabularyFactory::createVocabulary(dim)->getVocabulary();
49 generateEncodings(M, mode, level, funcName, dim, o, -1, WO, WA, WT);
50 }
51
52 // Returns a map containing instructions and the corresponding vector
53 // representations for a given module corresponding to the IR2VecMode and
54 // other configurations that is set in constructor
55 llvm::SmallMapVector<const llvm::Instruction *, Vector, 128> &
56 getInstVecMap() {
57 return instVecMap;
58 }
59
60 // Returns a map containing basic block and the corresponding vector
61 // representations for a given module corresponding to the IR2VecMode and
62 // other configurations that is set in constructor
63 llvm::SmallMapVector<const llvm::BasicBlock *, IR2Vec::Vector, 16>
64 getBBVecMap() {
65 return bbVecMap;
66 }
67
68 // Returns a map containing functions and the corresponding vector
69 // representations for a given module corresponding to the IR2VecMode and
70 // other configurations that is set in constructor
71 llvm::SmallMapVector<const llvm::Function *, Vector, 16> &
72 getFunctionVecMap() {
73 return funcVecMap;
74 }
75
76 // Returns the program vector for a module corresponding to the IR2VecMode
77 // and other configurations that is set in constructor
78 Vector &getProgramVector() { return pgmVector; }
79};
80
81} // namespace IR2Vec
82#endif
Definition IR2Vec.h:21