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//===----------------------------------------------------------------------===//
28
29#ifndef LLVM_ANALYSIS_IR2VEC_H
30#define LLVM_ANALYSIS_IR2VEC_H
31
32#include "llvm/ADT/DenseMap.h"
33#include "llvm/IR/PassManager.h"
34#include "llvm/IR/Type.h"
38#include "llvm/Support/JSON.h"
39#include <array>
40#include <map>
41
42namespace llvm {
43
44class Module;
45class BasicBlock;
46class Instruction;
47class Function;
48class Value;
49class raw_ostream;
50class LLVMContext;
51class IR2VecVocabAnalysis;
52
53/// IR2Vec computes two kinds of embeddings: Symbolic and Flow-aware.
54/// Symbolic embeddings capture the "syntactic" and "statistical correlation"
55/// of the IR entities. Flow-aware embeddings build on top of symbolic
56/// embeddings and additionally capture the flow information in the IR.
57/// IR2VecKind is used to specify the type of embeddings to generate.
58/// Note: Implementation of FlowAware embeddings is not same as the one
59/// described in the paper. The current implementation is a simplified version
60/// that captures the flow information (SSA-based use-defs) without tracing
61/// through memory level use-defs in the embedding computation described in the
62/// paper.
64
65namespace ir2vec {
66
72
73/// Embedding is a datatype that wraps std::vector<double>. It provides
74/// additional functionality for arithmetic and comparison operations.
75/// It is meant to be used *like* std::vector<double> but is more restrictive
76/// in the sense that it does not allow the user to change the size of the
77/// embedding vector. The dimension of the embedding is fixed at the time of
78/// construction of Embedding object. But the elements can be modified in-place.
79struct Embedding {
80private:
81 std::vector<double> Data;
82
83public:
84 Embedding() = default;
85 Embedding(const std::vector<double> &V) : Data(V) {}
86 Embedding(std::vector<double> &&V) : Data(std::move(V)) {}
87 Embedding(std::initializer_list<double> IL) : Data(IL) {}
88
89 explicit Embedding(size_t Size) : Data(Size) {}
90 Embedding(size_t Size, double InitialValue) : Data(Size, InitialValue) {}
91
92 size_t size() const { return Data.size(); }
93 bool empty() const { return Data.empty(); }
94
95 double &operator[](size_t Itr) {
96 assert(Itr < Data.size() && "Index out of bounds");
97 return Data[Itr];
98 }
99
100 const double &operator[](size_t Itr) const {
101 assert(Itr < Data.size() && "Index out of bounds");
102 return Data[Itr];
103 }
104
105 using iterator = typename std::vector<double>::iterator;
106 using const_iterator = typename std::vector<double>::const_iterator;
107
108 iterator begin() { return Data.begin(); }
109 iterator end() { return Data.end(); }
110 const_iterator begin() const { return Data.begin(); }
111 const_iterator end() const { return Data.end(); }
112 const_iterator cbegin() const { return Data.cbegin(); }
113 const_iterator cend() const { return Data.cend(); }
114
115 const std::vector<double> &getData() const { return Data; }
116
117 /// Arithmetic operators
122 LLVM_ABI Embedding &operator*=(double Factor);
123 LLVM_ABI Embedding operator*(double Factor) const;
124
125 /// Adds Src Embedding scaled by Factor with the called Embedding.
126 /// Called_Embedding += Src * Factor
127 LLVM_ABI Embedding &scaleAndAdd(const Embedding &Src, float Factor);
128
129 /// Returns true if the embedding is approximately equal to the RHS embedding
130 /// within the specified tolerance.
132 double Tolerance = 1e-4) const;
133
134 LLVM_ABI void print(raw_ostream &OS) const;
135};
136
139
140/// Class for storing and accessing the IR2Vec vocabulary.
141/// The Vocabulary class manages seed embeddings for LLVM IR entities. The
142/// seed embeddings are the initial learned representations of the entities
143/// of LLVM IR. The IR2Vec representation for a given IR is derived from these
144/// seed embeddings.
145///
146/// The vocabulary contains the seed embeddings for three types of entities:
147/// instruction opcodes, types, and operands. Types are grouped/canonicalized
148/// for better learning (e.g., all float variants map to FloatTy). The
149/// vocabulary abstracts away the canonicalization effectively, the exposed APIs
150/// handle all the known LLVM IR opcodes, types and operands.
151///
152/// This class helps populate the seed embeddings in an internal vector-based
153/// ADT. It provides logic to map every IR entity to a specific slot index or
154/// position in this vector, enabling O(1) embedding lookup while avoiding
155/// unnecessary computations involving string based lookups while generating the
156/// embeddings.
159 using VocabVector = std::vector<ir2vec::Embedding>;
160 VocabVector Vocab;
161 bool Valid = false;
162
163public:
164 // Slot layout:
165 // [0 .. MaxOpcodes-1] => Instruction opcodes
166 // [MaxOpcodes .. MaxOpcodes+MaxCanonicalTypeIDs-1] => Canonicalized types
167 // [MaxOpcodes+MaxCanonicalTypeIDs .. NumCanonicalEntries-1] => Operand kinds
168
169 /// Canonical type IDs supported by IR2Vec Vocabulary
170 enum class CanonicalTypeID : unsigned {
171 FloatTy,
172 VoidTy,
173 LabelTy,
175 VectorTy,
176 TokenTy,
177 IntegerTy,
179 PointerTy,
180 StructTy,
181 ArrayTy,
182 UnknownTy,
184 };
185
186 /// Operand kinds supported by IR2Vec Vocabulary
187 enum class OperandKind : unsigned {
189 PointerID,
193 };
194
195 /// Vocabulary layout constants
196#define LAST_OTHER_INST(NUM) static constexpr unsigned MaxOpcodes = NUM;
197#include "llvm/IR/Instruction.def"
198#undef LAST_OTHER_INST
199
200 static constexpr unsigned MaxTypeIDs = Type::TypeID::TargetExtTyID + 1;
201 static constexpr unsigned MaxCanonicalTypeIDs =
202 static_cast<unsigned>(CanonicalTypeID::MaxCanonicalType);
203 static constexpr unsigned MaxOperandKinds =
204 static_cast<unsigned>(OperandKind::MaxOperandKind);
205
206 Vocabulary() = default;
207 LLVM_ABI Vocabulary(VocabVector &&Vocab);
208
209 LLVM_ABI bool isValid() const;
210 LLVM_ABI unsigned getDimension() const;
211 /// Total number of entries (opcodes + canonicalized types + operand kinds)
212 static constexpr size_t getCanonicalSize() { return NumCanonicalEntries; }
213
214 /// Function to get vocabulary key for a given Opcode
215 LLVM_ABI static StringRef getVocabKeyForOpcode(unsigned Opcode);
216
217 /// Function to get vocabulary key for a given TypeID
219
220 /// Function to get vocabulary key for a given OperandKind
222
223 /// Function to classify an operand into OperandKind
225
226 /// Functions to return the slot index or position of a given Opcode, TypeID,
227 /// or OperandKind in the vocabulary.
228 LLVM_ABI static unsigned getSlotIndex(unsigned Opcode);
229 LLVM_ABI static unsigned getSlotIndex(Type::TypeID TypeID);
230 LLVM_ABI static unsigned getSlotIndex(const Value &Op);
231
232 /// Accessors to get the embedding for a given entity.
233 LLVM_ABI const ir2vec::Embedding &operator[](unsigned Opcode) const;
235 LLVM_ABI const ir2vec::Embedding &operator[](const Value &Arg) const;
236
237 /// Const Iterator type aliases
238 using const_iterator = VocabVector::const_iterator;
240 assert(Valid && "IR2Vec Vocabulary is invalid");
241 return Vocab.begin();
242 }
243
245 assert(Valid && "IR2Vec Vocabulary is invalid");
246 return Vocab.cbegin();
247 }
248
250 assert(Valid && "IR2Vec Vocabulary is invalid");
251 return Vocab.end();
252 }
253
255 assert(Valid && "IR2Vec Vocabulary is invalid");
256 return Vocab.cend();
257 }
258
259 /// Returns the string key for a given index position in the vocabulary.
260 /// This is useful for debugging or printing the vocabulary. Do not use this
261 /// for embedding generation as string based lookups are inefficient.
262 LLVM_ABI static StringRef getStringKey(unsigned Pos);
263
264 /// Create a dummy vocabulary for testing purposes.
265 LLVM_ABI static VocabVector createDummyVocabForTest(unsigned Dim = 1);
266
267 LLVM_ABI bool invalidate(Module &M, const PreservedAnalyses &PA,
269
270private:
271 constexpr static unsigned NumCanonicalEntries =
273
274 /// String mappings for CanonicalTypeID values
275 static constexpr StringLiteral CanonicalTypeNames[] = {
276 "FloatTy", "VoidTy", "LabelTy", "MetadataTy",
277 "VectorTy", "TokenTy", "IntegerTy", "FunctionTy",
278 "PointerTy", "StructTy", "ArrayTy", "UnknownTy"};
279 static_assert(std::size(CanonicalTypeNames) ==
280 static_cast<unsigned>(CanonicalTypeID::MaxCanonicalType),
281 "CanonicalTypeNames array size must match MaxCanonicalType");
282
283 /// String mappings for OperandKind values
284 static constexpr StringLiteral OperandKindNames[] = {"Function", "Pointer",
285 "Constant", "Variable"};
286 static_assert(std::size(OperandKindNames) ==
287 static_cast<unsigned>(OperandKind::MaxOperandKind),
288 "OperandKindNames array size must match MaxOperandKind");
289
290 /// Every known TypeID defined in llvm/IR/Type.h is expected to have a
291 /// corresponding mapping here in the same order as enum Type::TypeID.
292 static constexpr std::array<CanonicalTypeID, MaxTypeIDs> TypeIDMapping = {{
293 CanonicalTypeID::FloatTy, // HalfTyID = 0
294 CanonicalTypeID::FloatTy, // BFloatTyID
295 CanonicalTypeID::FloatTy, // FloatTyID
296 CanonicalTypeID::FloatTy, // DoubleTyID
297 CanonicalTypeID::FloatTy, // X86_FP80TyID
298 CanonicalTypeID::FloatTy, // FP128TyID
299 CanonicalTypeID::FloatTy, // PPC_FP128TyID
300 CanonicalTypeID::VoidTy, // VoidTyID
301 CanonicalTypeID::LabelTy, // LabelTyID
302 CanonicalTypeID::MetadataTy, // MetadataTyID
303 CanonicalTypeID::VectorTy, // X86_AMXTyID
304 CanonicalTypeID::TokenTy, // TokenTyID
305 CanonicalTypeID::IntegerTy, // IntegerTyID
306 CanonicalTypeID::FunctionTy, // FunctionTyID
307 CanonicalTypeID::PointerTy, // PointerTyID
308 CanonicalTypeID::StructTy, // StructTyID
309 CanonicalTypeID::ArrayTy, // ArrayTyID
310 CanonicalTypeID::VectorTy, // FixedVectorTyID
311 CanonicalTypeID::VectorTy, // ScalableVectorTyID
312 CanonicalTypeID::PointerTy, // TypedPointerTyID
313 CanonicalTypeID::UnknownTy // TargetExtTyID
314 }};
315 static_assert(TypeIDMapping.size() == MaxTypeIDs,
316 "TypeIDMapping must cover all Type::TypeID values");
317
318 /// Function to get vocabulary key for canonical type by enum
319 LLVM_ABI static StringRef
320 getVocabKeyForCanonicalTypeID(CanonicalTypeID CType);
321
322 /// Function to convert TypeID to CanonicalTypeID
323 LLVM_ABI static CanonicalTypeID getCanonicalTypeID(Type::TypeID TypeID);
324};
325
326/// Embedder provides the interface to generate embeddings (vector
327/// representations) for instructions, basic blocks, and functions. The
328/// vector representations are generated using IR2Vec algorithms.
329///
330/// The Embedder class is an abstract class and it is intended to be
331/// subclassed for different IR2Vec algorithms like Symbolic and Flow-aware.
332class Embedder {
333protected:
334 const Function &F;
336
337 /// Dimension of the vector representation; captured from the input vocabulary
338 const unsigned Dimension;
339
340 /// Weights for different entities (like opcode, arguments, types)
341 /// in the IR instructions to generate the vector representation.
343
344 // Utility maps - these are used to store the vector representations of
345 // instructions, basic blocks and functions.
349
350 LLVM_ABI Embedder(const Function &F, const Vocabulary &Vocab);
351
352 /// Function to compute embeddings. It generates embeddings for all
353 /// the instructions and basic blocks in the function F.
354 void computeEmbeddings() const;
355
356 /// Function to compute the embedding for a given basic block.
357 /// Specific to the kind of embeddings being computed.
358 virtual void computeEmbeddings(const BasicBlock &BB) const = 0;
359
360public:
361 virtual ~Embedder() = default;
362
363 /// Factory method to create an Embedder object.
364 LLVM_ABI static std::unique_ptr<Embedder>
366
367 /// Returns a map containing instructions and the corresponding embeddings for
368 /// the function F if it has been computed. If not, it computes the embeddings
369 /// for the function and returns the map.
371
372 /// Returns a map containing basic block 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.
375 LLVM_ABI const BBEmbeddingsMap &getBBVecMap() const;
376
377 /// Returns the embedding for a given basic block in the function F if it has
378 /// been computed. If not, it computes the embedding for the basic block and
379 /// returns it.
380 LLVM_ABI const Embedding &getBBVector(const BasicBlock &BB) const;
381
382 /// Computes and returns the embedding for the current function.
383 LLVM_ABI const Embedding &getFunctionVector() const;
384};
385
386/// Class for computing the Symbolic embeddings of IR2Vec.
387/// Symbolic embeddings are constructed based on the entity-level
388/// representations obtained from the Vocabulary.
390private:
391 void computeEmbeddings(const BasicBlock &BB) const override;
392
393public:
394 SymbolicEmbedder(const Function &F, const Vocabulary &Vocab)
395 : Embedder(F, Vocab) {}
396};
397
398/// Class for computing the Flow-aware embeddings of IR2Vec.
399/// Flow-aware embeddings build on the vocabulary, just like Symbolic
400/// embeddings, and additionally capture the flow information in the IR.
402private:
403 void computeEmbeddings(const BasicBlock &BB) const override;
404
405public:
407 : Embedder(F, Vocab) {}
408};
409
410} // namespace ir2vec
411
412/// This analysis provides the vocabulary for IR2Vec. The vocabulary provides a
413/// mapping between an entity of the IR (like opcode, type, argument, etc.) and
414/// its corresponding embedding.
415class IR2VecVocabAnalysis : public AnalysisInfoMixin<IR2VecVocabAnalysis> {
416 using VocabVector = std::vector<ir2vec::Embedding>;
417 using VocabMap = std::map<std::string, ir2vec::Embedding>;
418 VocabMap OpcVocab, TypeVocab, ArgVocab;
419 VocabVector Vocab;
420
421 Error readVocabulary();
422 Error parseVocabSection(StringRef Key, const json::Value &ParsedVocabValue,
423 VocabMap &TargetVocab, unsigned &Dim);
424 void generateNumMappedVocab();
425 void emitError(Error Err, LLVMContext &Ctx);
426
427public:
430 LLVM_ABI explicit IR2VecVocabAnalysis(const VocabVector &Vocab);
431 LLVM_ABI explicit IR2VecVocabAnalysis(VocabVector &&Vocab);
434};
435
436/// This pass prints the IR2Vec embeddings for instructions, basic blocks, and
437/// functions.
438class IR2VecPrinterPass : public PassInfoMixin<IR2VecPrinterPass> {
439 raw_ostream &OS;
440
441public:
442 explicit IR2VecPrinterPass(raw_ostream &OS) : OS(OS) {}
444 static bool isRequired() { return true; }
445};
446
447/// This pass prints the embeddings in the vocabulary
448class IR2VecVocabPrinterPass : public PassInfoMixin<IR2VecVocabPrinterPass> {
449 raw_ostream &OS;
450
451public:
454 static bool isRequired() { return true; }
455};
456
457} // namespace llvm
458
459#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.
uint64_t Size
Provides ErrorOr<T> smart pointer.
This header defines various interfaces for pass management in LLVM.
This file supports working with JSON data.
#define F(x, y, z)
Definition: MD5.cpp:55
Machine Check Debug Module
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")))
raw_pwrite_stream & OS
Value * RHS
API to communicate dependencies between analyses during invalidation.
Definition: PassManager.h:294
A container for analyses that lazily runs them and caches their results.
Definition: PassManager.h:255
LLVM Basic Block Representation.
Definition: BasicBlock.h:62
This class represents an Operation in the Expression.
Lightweight error class with error context and mandatory checking.
Definition: Error.h:159
This pass prints the IR2Vec embeddings for instructions, basic blocks, and functions.
Definition: IR2Vec.h:438
IR2VecPrinterPass(raw_ostream &OS)
Definition: IR2Vec.h:442
static bool isRequired()
Definition: IR2Vec.h:444
LLVM_ABI PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM)
Definition: IR2Vec.cpp:572
This analysis provides the vocabulary for IR2Vec.
Definition: IR2Vec.h:415
LLVM_ABI Result run(Module &M, ModuleAnalysisManager &MAM)
Definition: IR2Vec.cpp:535
static LLVM_ABI AnalysisKey Key
Definition: IR2Vec.h:428
This pass prints the embeddings in the vocabulary.
Definition: IR2Vec.h:448
static bool isRequired()
Definition: IR2Vec.h:454
LLVM_ABI PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM)
Definition: IR2Vec.cpp:614
IR2VecVocabPrinterPass(raw_ostream &OS)
Definition: IR2Vec.h:452
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
Embedder provides the interface to generate embeddings (vector representations) for instructions,...
Definition: IR2Vec.h:332
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:347
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:335
void computeEmbeddings() const
Function to compute embeddings.
Definition: IR2Vec.cpp:198
virtual ~Embedder()=default
const float TypeWeight
Definition: IR2Vec.h:342
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:342
const unsigned Dimension
Dimension of the vector representation; captured from the input vocabulary.
Definition: IR2Vec.h:338
const float ArgWeight
Definition: IR2Vec.h:342
Embedding FuncVector
Definition: IR2Vec.h:346
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:348
const Function & F
Definition: IR2Vec.h:334
Class for computing the Flow-aware embeddings of IR2Vec.
Definition: IR2Vec.h:401
FlowAwareEmbedder(const Function &F, const Vocabulary &Vocab)
Definition: IR2Vec.h:406
Class for computing the Symbolic embeddings of IR2Vec.
Definition: IR2Vec.h:389
SymbolicEmbedder(const Function &F, const Vocabulary &Vocab)
Definition: IR2Vec.h:394
Class for storing and accessing the IR2Vec vocabulary.
Definition: IR2Vec.h:157
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:275
LLVM_ABI bool invalidate(Module &M, const PreservedAnalyses &PA, ModuleAnalysisManager::Invalidator &Inv) const
Definition: IR2Vec.cpp:363
LLVM_ABI const ir2vec::Embedding & operator[](unsigned Opcode) const
Accessors to get the embedding for a given entity.
Definition: IR2Vec.cpp:291
const_iterator begin() const
Definition: IR2Vec.h:239
static LLVM_ABI OperandKind getOperandKind(const Value *Op)
Function to classify an operand into OperandKind.
Definition: IR2Vec.cpp:338
LLVM_ABI bool isValid() const
Definition: IR2Vec.cpp:266
VocabVector::const_iterator const_iterator
Const Iterator type aliases.
Definition: IR2Vec.h:238
static LLVM_ABI StringRef getStringKey(unsigned Pos)
Returns the string key for a given index position in the vocabulary.
Definition: IR2Vec.cpp:348
static constexpr unsigned MaxCanonicalTypeIDs
Definition: IR2Vec.h:201
static LLVM_ABI VocabVector createDummyVocabForTest(unsigned Dim=1)
Create a dummy vocabulary for testing purposes.
Definition: IR2Vec.cpp:369
static constexpr unsigned MaxOperandKinds
Definition: IR2Vec.h:203
const_iterator cbegin() const
Definition: IR2Vec.h:244
OperandKind
Operand kinds supported by IR2Vec Vocabulary.
Definition: IR2Vec.h:187
static constexpr size_t getCanonicalSize()
Total number of entries (opcodes + canonicalized types + operand kinds)
Definition: IR2Vec.h:212
static constexpr unsigned MaxTypeIDs
Definition: IR2Vec.h:200
static LLVM_ABI StringRef getVocabKeyForTypeID(Type::TypeID TypeID)
Function to get vocabulary key for a given TypeID.
Definition: IR2Vec.cpp:327
const_iterator end() const
Definition: IR2Vec.h:249
static LLVM_ABI StringRef getVocabKeyForOpcode(unsigned Opcode)
Function to get vocabulary key for a given Opcode.
Definition: IR2Vec.cpp:303
const_iterator cend() const
Definition: IR2Vec.h:254
LLVM_ABI unsigned getDimension() const
Definition: IR2Vec.cpp:270
CanonicalTypeID
Canonical type IDs supported by IR2Vec Vocabulary.
Definition: IR2Vec.h:170
static LLVM_ABI StringRef getVocabKeyForOperandKind(OperandKind Kind)
Function to get vocabulary key for a given OperandKind.
Definition: IR2Vec.cpp:331
A Value is an JSON value of unknown type.
Definition: JSON.h:288
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
@ BasicBlock
Various leaf nodes.
Definition: ISDOpcodes.h:81
LLVM_ABI cl::opt< float > ArgWeight
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.
Definition: AddressRanges.h:18
IR2VecKind
IR2Vec computes two kinds of embeddings: Symbolic and Flow-aware.
Definition: IR2Vec.h:63
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:1886
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:856
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:79
const_iterator end() const
Definition: IR2Vec.h:111
iterator begin()
Definition: IR2Vec.h:108
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:112
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:115
typename std::vector< double >::const_iterator const_iterator
Definition: IR2Vec.h:106
Embedding(size_t Size, double InitialValue)
Definition: IR2Vec.h:90
LLVM_ABI Embedding & operator-=(const Embedding &RHS)
Definition: IR2Vec.cpp:99
const_iterator cend() const
Definition: IR2Vec.h:113
LLVM_ABI Embedding operator*(double Factor) const
Definition: IR2Vec.cpp:118
size_t size() const
Definition: IR2Vec.h:92
LLVM_ABI Embedding & operator*=(double Factor)
Definition: IR2Vec.cpp:112
Embedding(std::initializer_list< double > IL)
Definition: IR2Vec.h:87
Embedding(const std::vector< double > &V)
Definition: IR2Vec.h:85
LLVM_ABI Embedding operator+(const Embedding &RHS) const
Definition: IR2Vec.cpp:93
bool empty() const
Definition: IR2Vec.h:93
typename std::vector< double >::iterator iterator
Definition: IR2Vec.h:105
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:86
const double & operator[](size_t Itr) const
Definition: IR2Vec.h:100
Embedding(size_t Size)
Definition: IR2Vec.h:89
LLVM_ABI void print(raw_ostream &OS) const
Definition: IR2Vec.cpp:144
const_iterator begin() const
Definition: IR2Vec.h:110
double & operator[](size_t Itr)
Definition: IR2Vec.h:95