LLVM 22.0.0git
IR2Vec.h
Go to the documentation of this file.
1//===- IR2Vec.h - Implementation of IR2Vec ----------------------*- C++ -*-===//
2//
3// Part of the LLVM 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/// \file
10/// This file defines the IR2Vec vocabulary analysis(IR2VecVocabAnalysis),
11/// the core ir2vec::Embedder interface for generating IR embeddings,
12/// and related utilities like the IR2VecPrinterPass.
13///
14/// Program Embeddings are typically or derived-from a learned
15/// representation of the program. Such embeddings are used to represent the
16/// programs as input to machine learning algorithms. IR2Vec represents the
17/// LLVM IR as embeddings.
18///
19/// The IR2Vec algorithm is described in the following paper:
20///
21/// IR2Vec: LLVM IR Based Scalable Program Embeddings, S. VenkataKeerthy,
22/// Rohit Aggarwal, Shalini Jain, Maunendra Sankar Desarkar, Ramakrishna
23/// Upadrasta, and Y. N. Srikant, ACM Transactions on Architecture and
24/// Code Optimization (TACO), 2020. https://doi.org/10.1145/3418463.
25/// https://arxiv.org/abs/1909.06228
26///
27/// To obtain embeddings:
28/// First run IR2VecVocabAnalysis to populate the vocabulary.
29/// Then, use the Embedder interface to generate embeddings for the desired IR
30/// entities. See the documentation for more details -
31/// https://llvm.org/docs/MLGO.html#ir2vec-embeddings
32///
33//===----------------------------------------------------------------------===//
34
35#ifndef LLVM_ANALYSIS_IR2VEC_H
36#define LLVM_ANALYSIS_IR2VEC_H
37
38#include "llvm/ADT/DenseMap.h"
39#include "llvm/IR/PassManager.h"
40#include "llvm/IR/Type.h"
44#include "llvm/Support/JSON.h"
45#include <array>
46#include <map>
47
48namespace llvm {
49
50class Module;
51class BasicBlock;
52class Instruction;
53class Function;
54class Value;
55class raw_ostream;
56class LLVMContext;
58
59/// IR2Vec computes two kinds of embeddings: Symbolic and Flow-aware.
60/// Symbolic embeddings capture the "syntactic" and "statistical correlation"
61/// of the IR entities. Flow-aware embeddings build on top of symbolic
62/// embeddings and additionally capture the flow information in the IR.
63/// IR2VecKind is used to specify the type of embeddings to generate.
64/// Note: Implementation of FlowAware embeddings is not same as the one
65/// described in the paper. The current implementation is a simplified version
66/// that captures the flow information (SSA-based use-defs) without tracing
67/// through memory level use-defs in the embedding computation described in the
68/// paper.
70
71namespace ir2vec {
72
78
79/// Embedding is a datatype that wraps std::vector<double>. It provides
80/// additional functionality for arithmetic and comparison operations.
81/// It is meant to be used *like* std::vector<double> but is more restrictive
82/// in the sense that it does not allow the user to change the size of the
83/// embedding vector. The dimension of the embedding is fixed at the time of
84/// construction of Embedding object. But the elements can be modified in-place.
85struct Embedding {
86private:
87 std::vector<double> Data;
88
89public:
90 Embedding() = default;
91 Embedding(const std::vector<double> &V) : Data(V) {}
92 Embedding(std::vector<double> &&V) : Data(std::move(V)) {}
93 Embedding(std::initializer_list<double> IL) : Data(IL) {}
94
95 explicit Embedding(size_t Size) : Data(Size, 0.0) {}
96 Embedding(size_t Size, double InitialValue) : Data(Size, InitialValue) {}
97
98 size_t size() const { return Data.size(); }
99 bool empty() const { return Data.empty(); }
100
101 double &operator[](size_t Itr) {
102 assert(Itr < Data.size() && "Index out of bounds");
103 return Data[Itr];
104 }
105
106 const double &operator[](size_t Itr) const {
107 assert(Itr < Data.size() && "Index out of bounds");
108 return Data[Itr];
109 }
110
111 using iterator = typename std::vector<double>::iterator;
112 using const_iterator = typename std::vector<double>::const_iterator;
113
114 iterator begin() { return Data.begin(); }
115 iterator end() { return Data.end(); }
116 const_iterator begin() const { return Data.begin(); }
117 const_iterator end() const { return Data.end(); }
118 const_iterator cbegin() const { return Data.cbegin(); }
119 const_iterator cend() const { return Data.cend(); }
120
121 const std::vector<double> &getData() const { return Data; }
122
123 /// Arithmetic operators
128 LLVM_ABI Embedding &operator*=(double Factor);
129 LLVM_ABI Embedding operator*(double Factor) const;
130
131 /// Adds Src Embedding scaled by Factor with the called Embedding.
132 /// Called_Embedding += Src * Factor
133 LLVM_ABI Embedding &scaleAndAdd(const Embedding &Src, float Factor);
134
135 /// Returns true if the embedding is approximately equal to the RHS embedding
136 /// within the specified tolerance.
138 double Tolerance = 1e-4) const;
139
140 LLVM_ABI void print(raw_ostream &OS) const;
141};
142
145
146/// Class for storing and accessing the IR2Vec vocabulary.
147/// The Vocabulary class manages seed embeddings for LLVM IR entities. The
148/// seed embeddings are the initial learned representations of the entities
149/// of LLVM IR. The IR2Vec representation for a given IR is derived from these
150/// seed embeddings.
151///
152/// The vocabulary contains the seed embeddings for three types of entities:
153/// instruction opcodes, types, and operands. Types are grouped/canonicalized
154/// for better learning (e.g., all float variants map to FloatTy). The
155/// vocabulary abstracts away the canonicalization effectively, the exposed APIs
156/// handle all the known LLVM IR opcodes, types and operands.
157///
158/// This class helps populate the seed embeddings in an internal vector-based
159/// ADT. It provides logic to map every IR entity to a specific slot index or
160/// position in this vector, enabling O(1) embedding lookup while avoiding
161/// unnecessary computations involving string based lookups while generating the
162/// embeddings.
165 using VocabVector = std::vector<ir2vec::Embedding>;
166 VocabVector Vocab;
167
168public:
169 // Slot layout:
170 // [0 .. MaxOpcodes-1] => Instruction opcodes
171 // [MaxOpcodes .. MaxOpcodes+MaxCanonicalTypeIDs-1] => Canonicalized types
172 // [MaxOpcodes+MaxCanonicalTypeIDs .. NumCanonicalEntries-1] => Operand kinds
173
174 /// Canonical type IDs supported by IR2Vec Vocabulary
190
191 /// Operand kinds supported by IR2Vec Vocabulary
199
200 /// Vocabulary layout constants
201#define LAST_OTHER_INST(NUM) static constexpr unsigned MaxOpcodes = NUM;
202#include "llvm/IR/Instruction.def"
203#undef LAST_OTHER_INST
204
205 static constexpr unsigned MaxTypeIDs = Type::TypeID::TargetExtTyID + 1;
206 static constexpr unsigned MaxCanonicalTypeIDs =
207 static_cast<unsigned>(CanonicalTypeID::MaxCanonicalType);
208 static constexpr unsigned MaxOperandKinds =
209 static_cast<unsigned>(OperandKind::MaxOperandKind);
210
211 Vocabulary() = default;
212 LLVM_ABI Vocabulary(VocabVector &&Vocab) : Vocab(std::move(Vocab)) {}
213
214 LLVM_ABI bool isValid() const { return Vocab.size() == NumCanonicalEntries; };
215 LLVM_ABI unsigned getDimension() const;
216 /// Total number of entries (opcodes + canonicalized types + operand kinds)
217 static constexpr size_t getCanonicalSize() { return NumCanonicalEntries; }
218
219 /// Function to get vocabulary key for a given Opcode
220 LLVM_ABI static StringRef getVocabKeyForOpcode(unsigned Opcode);
221
222 /// Function to get vocabulary key for a given TypeID
224
225 /// Function to get vocabulary key for a given OperandKind
227
228 /// Function to classify an operand into OperandKind
230
231 /// Functions to return the slot index or position of a given Opcode, TypeID,
232 /// or OperandKind in the vocabulary.
233 LLVM_ABI static unsigned getSlotIndex(unsigned Opcode);
234 LLVM_ABI static unsigned getSlotIndex(Type::TypeID TypeID);
235 LLVM_ABI static unsigned getSlotIndex(const Value &Op);
236
237 /// Accessors to get the embedding for a given entity.
238 LLVM_ABI const ir2vec::Embedding &operator[](unsigned Opcode) const;
240 LLVM_ABI const ir2vec::Embedding &operator[](const Value &Arg) const;
241
242 /// Const Iterator type aliases
243 using const_iterator = VocabVector::const_iterator;
245 assert(isValid() && "IR2Vec Vocabulary is invalid");
246 return Vocab.begin();
247 }
248
250 assert(isValid() && "IR2Vec Vocabulary is invalid");
251 return Vocab.cbegin();
252 }
253
255 assert(isValid() && "IR2Vec Vocabulary is invalid");
256 return Vocab.end();
257 }
258
260 assert(isValid() && "IR2Vec Vocabulary is invalid");
261 return Vocab.cend();
262 }
263
264 /// Returns the string key for a given index position in the vocabulary.
265 /// This is useful for debugging or printing the vocabulary. Do not use this
266 /// for embedding generation as string based lookups are inefficient.
267 LLVM_ABI static StringRef getStringKey(unsigned Pos);
268
269 /// Create a dummy vocabulary for testing purposes.
270 LLVM_ABI static VocabVector createDummyVocabForTest(unsigned Dim = 1);
271
272 LLVM_ABI bool invalidate(Module &M, const PreservedAnalyses &PA,
273 ModuleAnalysisManager::Invalidator &Inv) const;
274
275private:
276 constexpr static unsigned NumCanonicalEntries =
278
279 /// String mappings for CanonicalTypeID values
280 static constexpr StringLiteral CanonicalTypeNames[] = {
281 "FloatTy", "VoidTy", "LabelTy", "MetadataTy",
282 "VectorTy", "TokenTy", "IntegerTy", "FunctionTy",
283 "PointerTy", "StructTy", "ArrayTy", "UnknownTy"};
284 static_assert(std::size(CanonicalTypeNames) ==
285 static_cast<unsigned>(CanonicalTypeID::MaxCanonicalType),
286 "CanonicalTypeNames array size must match MaxCanonicalType");
287
288 /// String mappings for OperandKind values
289 static constexpr StringLiteral OperandKindNames[] = {"Function", "Pointer",
290 "Constant", "Variable"};
291 static_assert(std::size(OperandKindNames) ==
292 static_cast<unsigned>(OperandKind::MaxOperandKind),
293 "OperandKindNames array size must match MaxOperandKind");
294
295 /// Every known TypeID defined in llvm/IR/Type.h is expected to have a
296 /// corresponding mapping here in the same order as enum Type::TypeID.
297 static constexpr std::array<CanonicalTypeID, MaxTypeIDs> TypeIDMapping = {{
298 CanonicalTypeID::FloatTy, // HalfTyID = 0
299 CanonicalTypeID::FloatTy, // BFloatTyID
300 CanonicalTypeID::FloatTy, // FloatTyID
301 CanonicalTypeID::FloatTy, // DoubleTyID
302 CanonicalTypeID::FloatTy, // X86_FP80TyID
303 CanonicalTypeID::FloatTy, // FP128TyID
304 CanonicalTypeID::FloatTy, // PPC_FP128TyID
305 CanonicalTypeID::VoidTy, // VoidTyID
306 CanonicalTypeID::LabelTy, // LabelTyID
307 CanonicalTypeID::MetadataTy, // MetadataTyID
308 CanonicalTypeID::VectorTy, // X86_AMXTyID
309 CanonicalTypeID::TokenTy, // TokenTyID
310 CanonicalTypeID::IntegerTy, // IntegerTyID
311 CanonicalTypeID::FunctionTy, // FunctionTyID
312 CanonicalTypeID::PointerTy, // PointerTyID
313 CanonicalTypeID::StructTy, // StructTyID
314 CanonicalTypeID::ArrayTy, // ArrayTyID
315 CanonicalTypeID::VectorTy, // FixedVectorTyID
316 CanonicalTypeID::VectorTy, // ScalableVectorTyID
317 CanonicalTypeID::PointerTy, // TypedPointerTyID
318 CanonicalTypeID::UnknownTy // TargetExtTyID
319 }};
320 static_assert(TypeIDMapping.size() == MaxTypeIDs,
321 "TypeIDMapping must cover all Type::TypeID values");
322
323 /// Function to get vocabulary key for canonical type by enum
324 LLVM_ABI static StringRef
325 getVocabKeyForCanonicalTypeID(CanonicalTypeID CType);
326
327 /// Function to convert TypeID to CanonicalTypeID
328 LLVM_ABI static CanonicalTypeID getCanonicalTypeID(Type::TypeID TypeID);
329};
330
331/// Embedder provides the interface to generate embeddings (vector
332/// representations) for instructions, basic blocks, and functions. The
333/// vector representations are generated using IR2Vec algorithms.
334///
335/// The Embedder class is an abstract class and it is intended to be
336/// subclassed for different IR2Vec algorithms like Symbolic and Flow-aware.
337class Embedder {
338protected:
339 const Function &F;
341
342 /// Dimension of the vector representation; captured from the input vocabulary
343 const unsigned Dimension;
344
345 /// Weights for different entities (like opcode, arguments, types)
346 /// in the IR instructions to generate the vector representation.
348
349 // Utility maps - these are used to store the vector representations of
350 // instructions, basic blocks and functions.
354
355 LLVM_ABI Embedder(const Function &F, const Vocabulary &Vocab);
356
357 /// Function to compute embeddings. It generates embeddings for all
358 /// the instructions and basic blocks in the function F.
359 void computeEmbeddings() const;
360
361 /// Function to compute the embedding for a given basic block.
362 /// Specific to the kind of embeddings being computed.
363 virtual void computeEmbeddings(const BasicBlock &BB) const = 0;
364
365public:
366 virtual ~Embedder() = default;
367
368 /// Factory method to create an Embedder object.
369 LLVM_ABI static std::unique_ptr<Embedder>
371
372 /// Returns a map containing instructions and the corresponding embeddings for
373 /// the function F if it has been computed. If not, it computes the embeddings
374 /// for the function and returns the map.
376
377 /// Returns a map containing basic block and the corresponding embeddings for
378 /// the function F if it has been computed. If not, it computes the embeddings
379 /// for the function and returns the map.
380 LLVM_ABI const BBEmbeddingsMap &getBBVecMap() const;
381
382 /// Returns the embedding for a given basic block in the function F if it has
383 /// been computed. If not, it computes the embedding for the basic block and
384 /// returns it.
385 LLVM_ABI const Embedding &getBBVector(const BasicBlock &BB) const;
386
387 /// Computes and returns the embedding for the current function.
388 LLVM_ABI const Embedding &getFunctionVector() const;
389};
390
391/// Class for computing the Symbolic embeddings of IR2Vec.
392/// Symbolic embeddings are constructed based on the entity-level
393/// representations obtained from the Vocabulary.
395private:
396 void computeEmbeddings(const BasicBlock &BB) const override;
397
398public:
401};
402
403/// Class for computing the Flow-aware embeddings of IR2Vec.
404/// Flow-aware embeddings build on the vocabulary, just like Symbolic
405/// embeddings, and additionally capture the flow information in the IR.
407private:
408 void computeEmbeddings(const BasicBlock &BB) const override;
409
410public:
413};
414
415} // namespace ir2vec
416
417/// This analysis provides the vocabulary for IR2Vec. The vocabulary provides a
418/// mapping between an entity of the IR (like opcode, type, argument, etc.) and
419/// its corresponding embedding.
420class IR2VecVocabAnalysis : public AnalysisInfoMixin<IR2VecVocabAnalysis> {
421 using VocabVector = std::vector<ir2vec::Embedding>;
422 using VocabMap = std::map<std::string, ir2vec::Embedding>;
423 VocabMap OpcVocab, TypeVocab, ArgVocab;
424 VocabVector Vocab;
425
426 Error readVocabulary();
427 Error parseVocabSection(StringRef Key, const json::Value &ParsedVocabValue,
428 VocabMap &TargetVocab, unsigned &Dim);
429 void generateNumMappedVocab();
430 void emitError(Error Err, LLVMContext &Ctx);
431
432public:
435 LLVM_ABI explicit IR2VecVocabAnalysis(const VocabVector &Vocab);
436 LLVM_ABI explicit IR2VecVocabAnalysis(VocabVector &&Vocab);
439};
440
441/// This pass prints the IR2Vec embeddings for instructions, basic blocks, and
442/// functions.
443class IR2VecPrinterPass : public PassInfoMixin<IR2VecPrinterPass> {
444 raw_ostream &OS;
445
446public:
447 explicit IR2VecPrinterPass(raw_ostream &OS) : OS(OS) {}
449 static bool isRequired() { return true; }
450};
451
452/// This pass prints the embeddings in the vocabulary
453class IR2VecVocabPrinterPass : public PassInfoMixin<IR2VecVocabPrinterPass> {
454 raw_ostream &OS;
455
456public:
457 explicit IR2VecVocabPrinterPass(raw_ostream &OS) : OS(OS) {}
459 static bool isRequired() { return true; }
460};
461
462} // namespace llvm
463
464#endif // LLVM_ANALYSIS_IR2VEC_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define LLVM_ABI
Definition Compiler.h:213
This file defines the DenseMap class.
Provides ErrorOr<T> smart pointer.
This header defines various interfaces for pass management in LLVM.
This file supports working with JSON data.
Type::TypeID TypeID
ModuleAnalysisManager MAM
static cl::opt< RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode > Mode("regalloc-enable-advisor", cl::Hidden, cl::init(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default), cl::desc("Enable regalloc advisor mode"), cl::values(clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default, "default", "Default"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Release, "release", "precompiled"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Development, "development", "for training")))
Value * RHS
LLVM Basic Block Representation.
Definition BasicBlock.h:62
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
IR2VecPrinterPass(raw_ostream &OS)
Definition IR2Vec.h:447
static bool isRequired()
Definition IR2Vec.h:449
LLVM_ABI PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM)
Definition IR2Vec.cpp:565
This analysis provides the vocabulary for IR2Vec.
Definition IR2Vec.h:420
ir2vec::Vocabulary Result
Definition IR2Vec.h:437
LLVM_ABI Result run(Module &M, ModuleAnalysisManager &MAM)
Definition IR2Vec.cpp:528
static LLVM_ABI AnalysisKey Key
Definition IR2Vec.h:433
static bool isRequired()
Definition IR2Vec.h:459
LLVM_ABI PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM)
Definition IR2Vec.cpp:607
IR2VecVocabPrinterPass(raw_ostream &OS)
Definition IR2Vec.h:457
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:68
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:67
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
A wrapper around a string literal that serves as a proxy for constructing global tables of StringRefs...
Definition StringRef.h:862
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
TypeID
Definitions of all of the base types for the Type system.
Definition Type.h:54
LLVM Value Representation.
Definition Value.h:75
LLVM_ABI const Embedding & getBBVector(const BasicBlock &BB) const
Returns the embedding for a given basic block in the function F if it has been computed.
Definition IR2Vec.cpp:183
static LLVM_ABI std::unique_ptr< Embedder > create(IR2VecKind Mode, const Function &F, const Vocabulary &Vocab)
Factory method to create an Embedder object.
Definition IR2Vec.cpp:160
BBEmbeddingsMap BBVecMap
Definition IR2Vec.h:352
LLVM_ABI const BBEmbeddingsMap & getBBVecMap() const
Returns a map containing basic block and the corresponding embeddings for the function F if it has be...
Definition IR2Vec.cpp:177
const Vocabulary & Vocab
Definition IR2Vec.h:340
void computeEmbeddings() const
Function to compute embeddings.
Definition IR2Vec.cpp:198
virtual ~Embedder()=default
const float TypeWeight
Definition IR2Vec.h:347
LLVM_ABI const InstEmbeddingsMap & getInstVecMap() const
Returns a map containing instructions and the corresponding embeddings for the function F if it has b...
Definition IR2Vec.cpp:171
const float OpcWeight
Weights for different entities (like opcode, arguments, types) in the IR instructions to generate the...
Definition IR2Vec.h:347
const unsigned Dimension
Dimension of the vector representation; captured from the input vocabulary.
Definition IR2Vec.h:343
LLVM_ABI Embedder(const Function &F, const Vocabulary &Vocab)
Definition IR2Vec.cpp:155
const float ArgWeight
Definition IR2Vec.h:347
Embedding FuncVector
Definition IR2Vec.h:351
virtual void computeEmbeddings(const BasicBlock &BB) const =0
Function to compute the embedding for a given basic block.
LLVM_ABI const Embedding & getFunctionVector() const
Computes and returns the embedding for the current function.
Definition IR2Vec.cpp:191
InstEmbeddingsMap InstVecMap
Definition IR2Vec.h:353
const Function & F
Definition IR2Vec.h:339
FlowAwareEmbedder(const Function &F, const Vocabulary &Vocab)
Definition IR2Vec.h:411
SymbolicEmbedder(const Function &F, const Vocabulary &Vocab)
Definition IR2Vec.h:399
Class for storing and accessing the IR2Vec vocabulary.
Definition IR2Vec.h:163
static LLVM_ABI unsigned getSlotIndex(unsigned Opcode)
Functions to return the slot index or position of a given Opcode, TypeID, or OperandKind in the vocab...
Definition IR2Vec.cpp:268
LLVM_ABI bool invalidate(Module &M, const PreservedAnalyses &PA, ModuleAnalysisManager::Invalidator &Inv) const
Definition IR2Vec.cpp:356
LLVM_ABI const ir2vec::Embedding & operator[](unsigned Opcode) const
Accessors to get the embedding for a given entity.
Definition IR2Vec.cpp:284
LLVM_ABI Vocabulary(VocabVector &&Vocab)
Definition IR2Vec.h:212
const_iterator begin() const
Definition IR2Vec.h:244
static LLVM_ABI OperandKind getOperandKind(const Value *Op)
Function to classify an operand into OperandKind.
Definition IR2Vec.cpp:331
VocabVector::const_iterator const_iterator
Const Iterator type aliases.
Definition IR2Vec.h:243
static LLVM_ABI StringRef getStringKey(unsigned Pos)
Returns the string key for a given index position in the vocabulary.
Definition IR2Vec.cpp:341
static constexpr unsigned MaxCanonicalTypeIDs
Definition IR2Vec.h:206
static LLVM_ABI VocabVector createDummyVocabForTest(unsigned Dim=1)
Create a dummy vocabulary for testing purposes.
Definition IR2Vec.cpp:362
static constexpr unsigned MaxOperandKinds
Definition IR2Vec.h:208
const_iterator cbegin() const
Definition IR2Vec.h:249
OperandKind
Operand kinds supported by IR2Vec Vocabulary.
Definition IR2Vec.h:192
static constexpr size_t getCanonicalSize()
Total number of entries (opcodes + canonicalized types + operand kinds)
Definition IR2Vec.h:217
static constexpr unsigned MaxTypeIDs
Definition IR2Vec.h:205
static LLVM_ABI StringRef getVocabKeyForTypeID(Type::TypeID TypeID)
Function to get vocabulary key for a given TypeID.
Definition IR2Vec.cpp:320
const_iterator end() const
Definition IR2Vec.h:254
static LLVM_ABI StringRef getVocabKeyForOpcode(unsigned Opcode)
Function to get vocabulary key for a given Opcode.
Definition IR2Vec.cpp:296
const_iterator cend() const
Definition IR2Vec.h:259
LLVM_ABI bool isValid() const
Definition IR2Vec.h:214
LLVM_ABI unsigned getDimension() const
Definition IR2Vec.cpp:263
CanonicalTypeID
Canonical type IDs supported by IR2Vec Vocabulary.
Definition IR2Vec.h:175
static LLVM_ABI StringRef getVocabKeyForOperandKind(OperandKind Kind)
Function to get vocabulary key for a given OperandKind.
Definition IR2Vec.cpp:324
A Value is an JSON value of unknown type.
Definition JSON.h:290
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
DenseMap< const Instruction *, Embedding > InstEmbeddingsMap
Definition IR2Vec.h:143
LLVM_ABI cl::opt< float > ArgWeight
DenseMap< const BasicBlock *, Embedding > BBEmbeddingsMap
Definition IR2Vec.h:144
LLVM_ABI cl::opt< float > OpcWeight
LLVM_ABI cl::opt< float > TypeWeight
LLVM_ABI cl::opt< IR2VecKind > IR2VecEmbeddingKind
llvm::cl::OptionCategory IR2VecCategory
This is an optimization pass for GlobalISel generic memory operations.
IR2VecKind
IR2Vec computes two kinds of embeddings: Symbolic and Flow-aware.
Definition IR2Vec.h:69
DWARFExpression::Operation Op
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1869
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
Definition MIRParser.h:39
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:851
A CRTP mix-in that provides informational APIs needed for analysis passes.
Definition PassManager.h:93
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition Analysis.h:29
A CRTP mix-in to automatically provide informational APIs needed for passes.
Definition PassManager.h:70
Embedding is a datatype that wraps std::vector<double>.
Definition IR2Vec.h:85
const_iterator end() const
Definition IR2Vec.h:117
LLVM_ABI bool approximatelyEquals(const Embedding &RHS, double Tolerance=1e-4) const
Returns true if the embedding is approximately equal to the RHS embedding within the specified tolera...
Definition IR2Vec.cpp:131
const_iterator cbegin() const
Definition IR2Vec.h:118
LLVM_ABI Embedding & operator+=(const Embedding &RHS)
Arithmetic operators.
Definition IR2Vec.cpp:86
LLVM_ABI Embedding operator-(const Embedding &RHS) const
Definition IR2Vec.cpp:106
const std::vector< double > & getData() const
Definition IR2Vec.h:121
typename std::vector< double >::const_iterator const_iterator
Definition IR2Vec.h:112
Embedding(size_t Size, double InitialValue)
Definition IR2Vec.h:96
LLVM_ABI Embedding & operator-=(const Embedding &RHS)
Definition IR2Vec.cpp:99
const_iterator cend() const
Definition IR2Vec.h:119
LLVM_ABI Embedding operator*(double Factor) const
Definition IR2Vec.cpp:118
size_t size() const
Definition IR2Vec.h:98
LLVM_ABI Embedding & operator*=(double Factor)
Definition IR2Vec.cpp:112
Embedding(std::initializer_list< double > IL)
Definition IR2Vec.h:93
Embedding(const std::vector< double > &V)
Definition IR2Vec.h:91
LLVM_ABI Embedding operator+(const Embedding &RHS) const
Definition IR2Vec.cpp:93
bool empty() const
Definition IR2Vec.h:99
typename std::vector< double >::iterator iterator
Definition IR2Vec.h:111
LLVM_ABI Embedding & scaleAndAdd(const Embedding &Src, float Factor)
Adds Src Embedding scaled by Factor with the called Embedding.
Definition IR2Vec.cpp:124
Embedding(std::vector< double > &&V)
Definition IR2Vec.h:92
const double & operator[](size_t Itr) const
Definition IR2Vec.h:106
Embedding(size_t Size)
Definition IR2Vec.h:95
LLVM_ABI void print(raw_ostream &OS) const
Definition IR2Vec.cpp:144
const_iterator begin() const
Definition IR2Vec.h:116
double & operator[](size_t Itr)
Definition IR2Vec.h:101