32
32
#include " llvm/ADT/DenseMap.h"
33
33
#include " llvm/IR/PassManager.h"
34
34
#include " llvm/Support/CommandLine.h"
35
+ #include " llvm/Support/Compiler.h"
35
36
#include " llvm/Support/ErrorOr.h"
36
37
#include " llvm/Support/JSON.h"
37
38
#include < map>
@@ -57,9 +58,9 @@ enum class IR2VecKind { Symbolic };
57
58
58
59
namespace ir2vec {
59
60
60
- extern cl::opt<float > OpcWeight;
61
- extern cl::opt<float > TypeWeight;
62
- extern cl::opt<float > ArgWeight;
61
+ LLVM_ABI extern cl::opt<float > OpcWeight;
62
+ LLVM_ABI extern cl::opt<float > TypeWeight;
63
+ LLVM_ABI extern cl::opt<float > ArgWeight;
63
64
64
65
// / Embedding is a datatype that wraps std::vector<double>. It provides
65
66
// / additional functionality for arithmetic and comparison operations.
@@ -106,16 +107,17 @@ struct Embedding {
106
107
const std::vector<double > &getData () const { return Data; }
107
108
108
109
// / Arithmetic operators
109
- Embedding &operator +=(const Embedding &RHS);
110
- Embedding &operator -=(const Embedding &RHS);
110
+ LLVM_ABI Embedding &operator +=(const Embedding &RHS);
111
+ LLVM_ABI Embedding &operator -=(const Embedding &RHS);
111
112
112
113
// / Adds Src Embedding scaled by Factor with the called Embedding.
113
114
// / Called_Embedding += Src * Factor
114
- Embedding &scaleAndAdd (const Embedding &Src, float Factor);
115
+ LLVM_ABI Embedding &scaleAndAdd (const Embedding &Src, float Factor);
115
116
116
117
// / Returns true if the embedding is approximately equal to the RHS embedding
117
118
// / within the specified tolerance.
118
- bool approximatelyEquals (const Embedding &RHS, double Tolerance = 1e-6 ) const ;
119
+ LLVM_ABI bool approximatelyEquals (const Embedding &RHS,
120
+ double Tolerance = 1e-6 ) const ;
119
121
};
120
122
121
123
using InstEmbeddingsMap = DenseMap<const Instruction *, Embedding>;
@@ -148,7 +150,7 @@ class Embedder {
148
150
mutable BBEmbeddingsMap BBVecMap;
149
151
mutable InstEmbeddingsMap InstVecMap;
150
152
151
- Embedder (const Function &F, const Vocab &Vocabulary);
153
+ LLVM_ABI Embedder (const Function &F, const Vocab &Vocabulary);
152
154
153
155
// / Helper function to compute embeddings. It generates embeddings for all
154
156
// / the instructions and basic blocks in the function F. Logic of computing
@@ -161,38 +163,38 @@ class Embedder {
161
163
162
164
// / Lookup vocabulary for a given Key. If the key is not found, it returns a
163
165
// / zero vector.
164
- Embedding lookupVocab (const std::string &Key) const ;
166
+ LLVM_ABI Embedding lookupVocab (const std::string &Key) const ;
165
167
166
168
public:
167
169
virtual ~Embedder () = default ;
168
170
169
171
// / Factory method to create an Embedder object.
170
- static Expected<std::unique_ptr<Embedder>>
172
+ LLVM_ABI static Expected<std::unique_ptr<Embedder>>
171
173
create (IR2VecKind Mode, const Function &F, const Vocab &Vocabulary);
172
174
173
175
// / Returns a map containing instructions and the corresponding embeddings for
174
176
// / the function F if it has been computed. If not, it computes the embeddings
175
177
// / for the function and returns the map.
176
- const InstEmbeddingsMap &getInstVecMap () const ;
178
+ LLVM_ABI const InstEmbeddingsMap &getInstVecMap () const ;
177
179
178
180
// / Returns a map containing basic block and the corresponding embeddings for
179
181
// / the function F if it has been computed. If not, it computes the embeddings
180
182
// / for the function and returns the map.
181
- const BBEmbeddingsMap &getBBVecMap () const ;
183
+ LLVM_ABI const BBEmbeddingsMap &getBBVecMap () const ;
182
184
183
185
// / Returns the embedding for a given basic block in the function F if it has
184
186
// / been computed. If not, it computes the embedding for the basic block and
185
187
// / returns it.
186
- const Embedding &getBBVector (const BasicBlock &BB) const ;
188
+ LLVM_ABI const Embedding &getBBVector (const BasicBlock &BB) const ;
187
189
188
190
// / Computes and returns the embedding for the current function.
189
- const Embedding &getFunctionVector () const ;
191
+ LLVM_ABI const Embedding &getFunctionVector () const ;
190
192
};
191
193
192
194
// / Class for computing the Symbolic embeddings of IR2Vec.
193
195
// / Symbolic embeddings are constructed based on the entity-level
194
196
// / representations obtained from the Vocabulary.
195
- class SymbolicEmbedder : public Embedder {
197
+ class LLVM_ABI SymbolicEmbedder : public Embedder {
196
198
private:
197
199
// / Utility function to compute the embedding for a given type.
198
200
Embedding getTypeEmbedding (const Type *Ty) const ;
@@ -219,13 +221,13 @@ class IR2VecVocabResult {
219
221
220
222
public:
221
223
IR2VecVocabResult () = default ;
222
- IR2VecVocabResult (ir2vec::Vocab &&Vocabulary);
224
+ LLVM_ABI IR2VecVocabResult (ir2vec::Vocab &&Vocabulary);
223
225
224
226
bool isValid () const { return Valid; }
225
- const ir2vec::Vocab &getVocabulary () const ;
226
- unsigned getDimension () const ;
227
- bool invalidate (Module &M, const PreservedAnalyses &PA,
228
- ModuleAnalysisManager::Invalidator &Inv) const ;
227
+ LLVM_ABI const ir2vec::Vocab &getVocabulary () const ;
228
+ LLVM_ABI unsigned getDimension () const ;
229
+ LLVM_ABI bool invalidate (Module &M, const PreservedAnalyses &PA,
230
+ ModuleAnalysisManager::Invalidator &Inv) const ;
229
231
};
230
232
231
233
// / This analysis provides the vocabulary for IR2Vec. The vocabulary provides a
@@ -237,12 +239,12 @@ class IR2VecVocabAnalysis : public AnalysisInfoMixin<IR2VecVocabAnalysis> {
237
239
void emitError (Error Err, LLVMContext &Ctx);
238
240
239
241
public:
240
- static AnalysisKey Key;
242
+ LLVM_ABI static AnalysisKey Key;
241
243
IR2VecVocabAnalysis () = default ;
242
- explicit IR2VecVocabAnalysis (const ir2vec::Vocab &Vocab);
243
- explicit IR2VecVocabAnalysis (ir2vec::Vocab &&Vocab);
244
+ LLVM_ABI explicit IR2VecVocabAnalysis (const ir2vec::Vocab &Vocab);
245
+ LLVM_ABI explicit IR2VecVocabAnalysis (ir2vec::Vocab &&Vocab);
244
246
using Result = IR2VecVocabResult;
245
- Result run (Module &M, ModuleAnalysisManager &MAM);
247
+ LLVM_ABI Result run (Module &M, ModuleAnalysisManager &MAM);
246
248
};
247
249
248
250
// / This pass prints the IR2Vec embeddings for instructions, basic blocks, and
@@ -253,7 +255,7 @@ class IR2VecPrinterPass : public PassInfoMixin<IR2VecPrinterPass> {
253
255
254
256
public:
255
257
explicit IR2VecPrinterPass (raw_ostream &OS) : OS(OS) {}
256
- PreservedAnalyses run (Module &M, ModuleAnalysisManager &MAM);
258
+ LLVM_ABI PreservedAnalyses run (Module &M, ModuleAnalysisManager &MAM);
257
259
static bool isRequired () { return true ; }
258
260
};
259
261
0 commit comments