3232#include " llvm/ADT/DenseMap.h"
3333#include " llvm/IR/PassManager.h"
3434#include " llvm/Support/CommandLine.h"
35+ #include " llvm/Support/Compiler.h"
3536#include " llvm/Support/ErrorOr.h"
3637#include " llvm/Support/JSON.h"
3738#include < map>
@@ -57,9 +58,9 @@ enum class IR2VecKind { Symbolic };
5758
5859namespace ir2vec {
5960
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;
6364
6465// / Embedding is a datatype that wraps std::vector<double>. It provides
6566// / additional functionality for arithmetic and comparison operations.
@@ -106,16 +107,17 @@ struct Embedding {
106107 const std::vector<double > &getData () const { return Data; }
107108
108109 // / 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);
111112
112113 // / Adds Src Embedding scaled by Factor with the called Embedding.
113114 // / Called_Embedding += Src * Factor
114- Embedding &scaleAndAdd (const Embedding &Src, float Factor);
115+ LLVM_ABI Embedding &scaleAndAdd (const Embedding &Src, float Factor);
115116
116117 // / Returns true if the embedding is approximately equal to the RHS embedding
117118 // / 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 ;
119121};
120122
121123using InstEmbeddingsMap = DenseMap<const Instruction *, Embedding>;
@@ -148,7 +150,7 @@ class Embedder {
148150 mutable BBEmbeddingsMap BBVecMap;
149151 mutable InstEmbeddingsMap InstVecMap;
150152
151- Embedder (const Function &F, const Vocab &Vocabulary);
153+ LLVM_ABI Embedder (const Function &F, const Vocab &Vocabulary);
152154
153155 // / Helper function to compute embeddings. It generates embeddings for all
154156 // / the instructions and basic blocks in the function F. Logic of computing
@@ -161,38 +163,38 @@ class Embedder {
161163
162164 // / Lookup vocabulary for a given Key. If the key is not found, it returns a
163165 // / zero vector.
164- Embedding lookupVocab (const std::string &Key) const ;
166+ LLVM_ABI Embedding lookupVocab (const std::string &Key) const ;
165167
166168public:
167169 virtual ~Embedder () = default ;
168170
169171 // / Factory method to create an Embedder object.
170- static Expected<std::unique_ptr<Embedder>>
172+ LLVM_ABI static Expected<std::unique_ptr<Embedder>>
171173 create (IR2VecKind Mode, const Function &F, const Vocab &Vocabulary);
172174
173175 // / Returns a map containing instructions and the corresponding embeddings for
174176 // / the function F if it has been computed. If not, it computes the embeddings
175177 // / for the function and returns the map.
176- const InstEmbeddingsMap &getInstVecMap () const ;
178+ LLVM_ABI const InstEmbeddingsMap &getInstVecMap () const ;
177179
178180 // / Returns a map containing basic block and the corresponding embeddings for
179181 // / the function F if it has been computed. If not, it computes the embeddings
180182 // / for the function and returns the map.
181- const BBEmbeddingsMap &getBBVecMap () const ;
183+ LLVM_ABI const BBEmbeddingsMap &getBBVecMap () const ;
182184
183185 // / Returns the embedding for a given basic block in the function F if it has
184186 // / been computed. If not, it computes the embedding for the basic block and
185187 // / returns it.
186- const Embedding &getBBVector (const BasicBlock &BB) const ;
188+ LLVM_ABI const Embedding &getBBVector (const BasicBlock &BB) const ;
187189
188190 // / Computes and returns the embedding for the current function.
189- const Embedding &getFunctionVector () const ;
191+ LLVM_ABI const Embedding &getFunctionVector () const ;
190192};
191193
192194// / Class for computing the Symbolic embeddings of IR2Vec.
193195// / Symbolic embeddings are constructed based on the entity-level
194196// / representations obtained from the Vocabulary.
195- class SymbolicEmbedder : public Embedder {
197+ class LLVM_ABI SymbolicEmbedder : public Embedder {
196198private:
197199 // / Utility function to compute the embedding for a given type.
198200 Embedding getTypeEmbedding (const Type *Ty) const ;
@@ -219,13 +221,13 @@ class IR2VecVocabResult {
219221
220222public:
221223 IR2VecVocabResult () = default ;
222- IR2VecVocabResult (ir2vec::Vocab &&Vocabulary);
224+ LLVM_ABI IR2VecVocabResult (ir2vec::Vocab &&Vocabulary);
223225
224226 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 ;
229231};
230232
231233// / This analysis provides the vocabulary for IR2Vec. The vocabulary provides a
@@ -237,12 +239,12 @@ class IR2VecVocabAnalysis : public AnalysisInfoMixin<IR2VecVocabAnalysis> {
237239 void emitError (Error Err, LLVMContext &Ctx);
238240
239241public:
240- static AnalysisKey Key;
242+ LLVM_ABI static AnalysisKey Key;
241243 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);
244246 using Result = IR2VecVocabResult;
245- Result run (Module &M, ModuleAnalysisManager &MAM);
247+ LLVM_ABI Result run (Module &M, ModuleAnalysisManager &MAM);
246248};
247249
248250// / This pass prints the IR2Vec embeddings for instructions, basic blocks, and
@@ -253,7 +255,7 @@ class IR2VecPrinterPass : public PassInfoMixin<IR2VecPrinterPass> {
253255
254256public:
255257 explicit IR2VecPrinterPass (raw_ostream &OS) : OS(OS) {}
256- PreservedAnalyses run (Module &M, ModuleAnalysisManager &MAM);
258+ LLVM_ABI PreservedAnalyses run (Module &M, ModuleAnalysisManager &MAM);
257259 static bool isRequired () { return true ; }
258260};
259261
0 commit comments