LLVM 22.0.0git
MIR2Vec.h
Go to the documentation of this file.
1//===- MIR2Vec.h - Implementation of MIR2Vec ------------------*- 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 MIR2Vec framework for generating Machine IR
11/// embeddings.
12///
13/// Design Overview:
14/// ----------------------
15/// 1. MIR2VecVocabProvider - Core vocabulary loading logic (no PM dependency)
16/// - Can be used standalone or wrapped by the pass manager
17/// - Requires MachineModuleInfo with parsed machine functions
18///
19/// 2. MIR2VecVocabLegacyAnalysis - Pass manager wrapper (ImmutablePass)
20/// - Integrated and used by llc -print-mir2vec
21///
22/// 3. MIREmbedder - Generates embeddings from vocabulary
23/// - SymbolicMIREmbedder: MIR2Vec embedding implementation
24///
25/// MIR2Vec extends IR2Vec to support Machine IR embeddings. It represents the
26/// LLVM Machine IR as embeddings which can be used as input to machine learning
27/// algorithms.
28///
29/// The original idea of MIR2Vec is described in the following paper:
30///
31/// RL4ReAl: Reinforcement Learning for Register Allocation. S. VenkataKeerthy,
32/// Siddharth Jain, Anilava Kundu, Rohit Aggarwal, Albert Cohen, and Ramakrishna
33/// Upadrasta. 2023. RL4ReAl: Reinforcement Learning for Register Allocation.
34/// Proceedings of the 32nd ACM SIGPLAN International Conference on Compiler
35/// Construction (CC 2023). https://doi.org/10.1145/3578360.3580273.
36/// https://arxiv.org/abs/2204.02013
37///
38//===----------------------------------------------------------------------===//
39
40#ifndef LLVM_CODEGEN_MIR2VEC_H
41#define LLVM_CODEGEN_MIR2VEC_H
42
51#include "llvm/IR/PassManager.h"
52#include "llvm/Pass.h"
54#include "llvm/Support/Error.h"
56#include <map>
57#include <set>
58#include <string>
59
60namespace llvm {
61
62class Module;
63class raw_ostream;
64class LLVMContext;
66class TargetInstrInfo;
67
68enum class MIR2VecKind { Symbolic };
69
70namespace mir2vec {
71
72// Forward declarations
73class MIREmbedder;
75
78
83
84/// Class for storing and accessing the MIR2Vec vocabulary.
85/// The MIRVocabulary class manages seed embeddings for LLVM Machine IR
88 using VocabMap = std::map<std::string, ir2vec::Embedding>;
89
90 // MIRVocabulary Layout:
91 // +-------------------+-----------------------------------------------------+
92 // | Entity Type | Description |
93 // +-------------------+-----------------------------------------------------+
94 // | 1. Opcodes | Target specific opcodes derived from TII, grouped |
95 // | | by instruction semantics. |
96 // | 2. Common Operands| All common operand types, except register operands, |
97 // | | defined by MachineOperand::MachineOperandType enum. |
98 // | 3. Physical | Register classes defined by the target, specialized |
99 // | Reg classes | by physical registers. |
100 // | 4. Virtual | Register classes defined by the target, specialized |
101 // | Reg classes | by virtual and physical registers. |
102 // +-------------------+-----------------------------------------------------+
103
104 /// Layout information for the MIR vocabulary. Defines the starting index
105 /// and size of each section in the vocabulary.
106 struct {
107 size_t OpcodeBase = 0;
109 size_t PhyRegBase = 0;
110 size_t VirtRegBase = 0;
111 size_t TotalEntries = 0;
112 } Layout;
113
114 // TODO: See if we can have only one reg classes section instead of physical
115 // and virtual separate sections in the vocabulary. This would reduce the
116 // number of vocabulary entities significantly.
117 // We can potentially distinguish physical and virtual registers by
118 // considering them as a separate feature.
119 enum class Section : unsigned {
120 Opcodes = 0,
121 CommonOperands = 1,
122 PhyRegisters = 2,
123 VirtRegisters = 3,
124 MaxSections
125 };
126
127 ir2vec::VocabStorage Storage;
128 std::set<std::string> UniqueBaseOpcodeNames;
129 SmallVector<std::string, 24> RegisterOperandNames;
130
131 // Some instructions have optional register operands that may be NoRegister.
132 // We return a zero vector in such cases.
133 Embedding ZeroEmbedding;
134
135 // We have specialized MO_Register handling in the Register operand section,
136 // so we don't include it here. Also, no MO_DbgInstrRef for now.
137 static constexpr StringLiteral CommonOperandNames[] = {
138 "Immediate", "CImmediate", "FPImmediate", "MBB",
139 "FrameIndex", "ConstantPoolIndex", "TargetIndex", "JumpTableIndex",
140 "ExternalSymbol", "GlobalAddress", "BlockAddress", "RegisterMask",
141 "RegisterLiveOut", "Metadata", "MCSymbol", "CFIIndex",
142 "IntrinsicID", "Predicate", "ShuffleMask"};
143 static_assert(std::size(CommonOperandNames) == MachineOperand::MO_Last - 1 &&
144 "Common operand names size changed, update accordingly");
145
146 const TargetInstrInfo &TII;
147 const TargetRegisterInfo &TRI;
148 const MachineRegisterInfo &MRI;
149
150 void generateStorage(const VocabMap &OpcodeMap,
151 const VocabMap &CommonOperandMap,
152 const VocabMap &PhyRegMap, const VocabMap &VirtRegMap);
153 void buildCanonicalOpcodeMapping();
154 void buildRegisterOperandMapping();
155
156 /// Get canonical index for a machine opcode
157 LLVM_ABI unsigned getCanonicalOpcodeIndex(unsigned Opcode) const;
158
159 /// Get index for a common (non-register) machine operand
160 unsigned
161 getCommonOperandIndex(MachineOperand::MachineOperandType OperandType) const;
162
163 /// Get index for a register machine operand
164 LLVM_ABI unsigned getRegisterOperandIndex(Register Reg) const;
165
166 // Accessors for operand types
167 const Embedding &
168 operator[](MachineOperand::MachineOperandType OperandType) const {
169 unsigned LocalIndex = getCommonOperandIndex(OperandType);
170 return Storage[static_cast<unsigned>(Section::CommonOperands)][LocalIndex];
171 }
172
173 const Embedding &operator[](Register Reg) const {
174 // Reg is sometimes NoRegister (0) for optional operands. We return a zero
175 // vector in this case.
176 if (!Reg.isValid())
177 return ZeroEmbedding;
178 // TODO: Implement proper stack slot handling for MIR2Vec embeddings.
179 // Stack slots represent frame indices and should have their own
180 // embedding strategy rather than defaulting to register class 0.
181 // Consider: 1) Separate vocabulary section for stack slots
182 // 2) Stack slot size/alignment based embeddings
183 // 3) Frame index based categorization
184 if (Reg.isStack())
185 return ZeroEmbedding;
186
187 unsigned LocalIndex = getRegisterOperandIndex(Reg);
188 auto SectionID =
189 Reg.isPhysical() ? Section::PhyRegisters : Section::VirtRegisters;
190 return Storage[static_cast<unsigned>(SectionID)][LocalIndex];
191 }
192
193 /// Get entity ID (flat index) for a common operand type
194 /// This is used for triplet generation
195 LLVM_ABI unsigned getEntityIDForCommonOperand(
196 MachineOperand::MachineOperandType OperandType) const {
197 return Layout.CommonOperandBase + getCommonOperandIndex(OperandType);
198 }
199
200 /// Get entity ID (flat index) for a register
201 /// This is used for triplet generation
202 unsigned getEntityIDForRegister(Register Reg) const {
203 if (!Reg.isValid() || Reg.isStack())
204 return Layout
205 .VirtRegBase; // Return VirtRegBase for invalid/stack registers
206 unsigned LocalIndex = getRegisterOperandIndex(Reg);
207 size_t BaseOffset =
208 Reg.isPhysical() ? Layout.PhyRegBase : Layout.VirtRegBase;
209 return BaseOffset + LocalIndex;
210 }
211
212public:
213 /// Static method for extracting base opcode names (public for testing)
214 LLVM_ABI_FOR_TEST static std::string
215 extractBaseOpcodeName(StringRef InstrName);
216
217 /// Get indices from opcode or operand names. These are public for testing.
218 /// String based lookups are inefficient and should be avoided in general.
219 LLVM_ABI_FOR_TEST unsigned
220 getCanonicalIndexForBaseName(StringRef BaseName) const;
221 LLVM_ABI_FOR_TEST unsigned
222 getCanonicalIndexForOperandName(StringRef OperandName) const;
223 LLVM_ABI_FOR_TEST unsigned
225 bool IsPhysical = true) const;
226
227 /// Get the string key for a vocabulary entry at the given position
228 LLVM_ABI std::string getStringKey(unsigned Pos) const;
229
230 unsigned getDimension() const { return Storage.getDimension(); }
231
232 /// Get entity ID (flat index) for an opcode
233 /// This is used for triplet generation
234 unsigned getEntityIDForOpcode(unsigned Opcode) const {
235 return Layout.OpcodeBase + getCanonicalOpcodeIndex(Opcode);
236 }
237
238 /// Get entity ID (flat index) for a machine operand
239 /// This is used for triplet generation
242 return getEntityIDForRegister(MO.getReg());
243 return getEntityIDForCommonOperand(MO.getType());
244 }
245
246 // Accessor methods
247 const Embedding &operator[](unsigned Opcode) const {
248 unsigned LocalIndex = getCanonicalOpcodeIndex(Opcode);
249 return Storage[static_cast<unsigned>(Section::Opcodes)][LocalIndex];
250 }
251
252 const Embedding &operator[](MachineOperand Operand) const {
253 auto OperandType = Operand.getType();
254 if (OperandType == MachineOperand::MO_Register)
255 return operator[](Operand.getReg());
256 else
257 return operator[](OperandType);
258 }
259
260 // Iterator access
262 const_iterator begin() const { return Storage.begin(); }
263
264 const_iterator end() const { return Storage.end(); }
265
266 MIRVocabulary() = delete;
267
268 /// Factory method to create MIRVocabulary from vocabulary map
270 create(VocabMap &&OpcMap, VocabMap &&CommonOperandsMap, VocabMap &&PhyRegMap,
271 VocabMap &&VirtRegMap, const TargetInstrInfo &TII,
272 const TargetRegisterInfo &TRI, const MachineRegisterInfo &MRI);
273
274 /// Create a dummy vocabulary for testing purposes.
277 const TargetRegisterInfo &TRI,
278 const MachineRegisterInfo &MRI, unsigned Dim = 1);
279
280 /// Total number of entries in the vocabulary
281 size_t getCanonicalSize() const { return Storage.size(); }
282
283private:
284 MIRVocabulary(VocabMap &&OpcMap, VocabMap &&CommonOperandsMap,
285 VocabMap &&PhyRegMap, VocabMap &&VirtRegMap,
287 const MachineRegisterInfo &MRI);
288};
289
290/// Base class for MIR embedders
292protected:
295
296 /// Dimension of the embeddings; Captured from the vocabulary
297 const unsigned Dimension;
298
299 /// Weight for opcode embeddings
301
307
308 /// Function to compute embeddings.
310
311 /// Function to compute the embedding for a given machine basic block.
313
314 /// Function to compute the embedding for a given machine instruction.
315 /// Specific to the kind of embeddings being computed.
316 virtual Embedding computeEmbeddings(const MachineInstr &MI) const = 0;
317
318public:
319 virtual ~MIREmbedder() = default;
320
321 /// Factory method to create an Embedder object of the specified kind
322 /// Returns nullptr if the requested kind is not supported.
323 LLVM_ABI static std::unique_ptr<MIREmbedder>
325 const MIRVocabulary &Vocab);
326
327 /// Computes and returns the embedding for a given machine instruction MI in
328 /// the machine function MF.
330 return computeEmbeddings(MI);
331 }
332
333 /// Computes and returns the embedding for a given machine basic block in the
334 /// machine function MF.
338
339 /// Computes and returns the embedding for the current machine function.
341 // Currently, we always (re)compute the embeddings for the function. This is
342 // cheaper than caching the vector.
343 return computeEmbeddings();
344 }
345};
346
347/// Class for computing Symbolic embeddings
348/// Symbolic embeddings are constructed based on the entity-level
349/// representations obtained from the MIR Vocabulary.
351private:
352 Embedding computeEmbeddings(const MachineInstr &MI) const override;
353
354public:
356 LLVM_ABI_FOR_TEST static std::unique_ptr<SymbolicMIREmbedder>
358};
359
360} // namespace mir2vec
361
362/// MIR2Vec vocabulary provider used by pass managers and standalone tools.
363/// This class encapsulates the core vocabulary loading logic and can be used
364/// independently of the pass manager infrastructure. For pass-based usage,
365/// see MIR2VecVocabLegacyAnalysis.
366///
367/// Note: This provider pattern makes new PM migration straightforward when
368/// needed. A new PM analysis wrapper can be added that delegates to this
369/// provider, similar to how MIR2VecVocabLegacyAnalysis currently wraps it.
371 using VocabMap = std::map<std::string, mir2vec::Embedding>;
372
373public:
374 MIR2VecVocabProvider(const MachineModuleInfo &MMI) : MMI(MMI) {}
375
377
378private:
379 Error readVocabulary(VocabMap &OpcVocab, VocabMap &CommonOperandVocab,
380 VocabMap &PhyRegVocabMap, VocabMap &VirtRegVocabMap);
381 const MachineModuleInfo &MMI;
382};
383
384/// Pass to analyze and populate MIR2Vec vocabulary from a module
386 using VocabVector = std::vector<mir2vec::Embedding>;
387 using VocabMap = std::map<std::string, mir2vec::Embedding>;
388
389 StringRef getPassName() const override;
390
391protected:
392 void getAnalysisUsage(AnalysisUsage &AU) const override {
394 AU.setPreservesAll();
395 }
396 std::unique_ptr<MIR2VecVocabProvider> Provider;
397
398public:
399 static char ID;
401
403 MachineModuleInfo &MMI =
405 if (!Provider)
406 Provider = std::make_unique<MIR2VecVocabProvider>(MMI);
407 return Provider->getVocabulary(M);
408 }
409
411 assert(Provider && "Provider not initialized");
412 return *Provider;
413 }
414};
415
416/// This pass prints the embeddings in the MIR2Vec vocabulary
418 raw_ostream &OS;
419
420public:
421 static char ID;
424
425 bool runOnMachineFunction(MachineFunction &MF) override;
426 bool doFinalization(Module &M) override;
432
433 StringRef getPassName() const override {
434 return "MIR2Vec Vocabulary Printer Pass";
435 }
436};
437
438/// This pass prints the MIR2Vec embeddings for machine functions, basic blocks,
439/// and instructions
441 raw_ostream &OS;
442
443public:
444 static char ID;
447
448 bool runOnMachineFunction(MachineFunction &MF) override;
454
455 StringRef getPassName() const override {
456 return "MIR2Vec Embedder Printer Pass";
457 }
458};
459
460/// Create a machine pass that prints MIR2Vec embeddings
461LLVM_ABI MachineFunctionPass *createMIR2VecPrinterLegacyPass(raw_ostream &OS);
462
463} // namespace llvm
464
465#endif // LLVM_CODEGEN_MIR2VEC_H
unsigned const MachineRegisterInfo * MRI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock & MBB
#define LLVM_ABI
Definition Compiler.h:213
#define LLVM_ABI_FOR_TEST
Definition Compiler.h:218
Provides ErrorOr<T> smart pointer.
const HexagonInstrInfo * TII
This file defines the IR2Vec vocabulary analysis(IR2VecVocabAnalysis), the core ir2vec::Embedder inte...
IRTranslator LLVM IR MI
This header defines various interfaces for pass management in LLVM.
#define RegName(no)
#define F(x, y, z)
Definition MD5.cpp:54
Register Reg
Register const TargetRegisterInfo * TRI
Promote Memory to Register
Definition Mem2Reg.cpp:110
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")))
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
void setPreservesAll()
Set by analyses that do not transform their input at all.
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
Tagged union holding either a T or a Error.
Definition Error.h:485
ImmutablePass(char &pid)
Definition Pass.h:287
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:68
MIR2VecPrinterLegacyPass(raw_ostream &OS)
Definition MIR2Vec.h:445
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
Definition MIR2Vec.h:449
bool runOnMachineFunction(MachineFunction &MF) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
Definition MIR2Vec.cpp:632
StringRef getPassName() const override
getPassName - Return a nice clean name for a pass.
Definition MIR2Vec.h:455
Pass to analyze and populate MIR2Vec vocabulary from a module.
Definition MIR2Vec.h:385
MIR2VecVocabProvider & getProvider()
Definition MIR2Vec.h:410
Expected< mir2vec::MIRVocabulary > getMIR2VecVocabulary(const Module &M)
Definition MIR2Vec.h:402
std::unique_ptr< MIR2VecVocabProvider > Provider
Definition MIR2Vec.h:396
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
Definition MIR2Vec.h:392
StringRef getPassName() const override
getPassName - Return a nice clean name for a pass.
Definition MIR2Vec.h:433
bool doFinalization(Module &M) override
doFinalization - Virtual method overriden by subclasses to do any necessary clean up after all passes...
Definition MIR2Vec.cpp:599
bool runOnMachineFunction(MachineFunction &MF) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
Definition MIR2Vec.cpp:595
MIR2VecVocabPrinterLegacyPass(raw_ostream &OS)
Definition MIR2Vec.h:422
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
Definition MIR2Vec.h:427
MIR2Vec vocabulary provider used by pass managers and standalone tools.
Definition MIR2Vec.h:370
MIR2VecVocabProvider(const MachineModuleInfo &MMI)
Definition MIR2Vec.h:374
LLVM_ABI Expected< mir2vec::MIRVocabulary > getVocabulary(const Module &M)
Definition MIR2Vec.cpp:424
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
Representation of each machine instruction.
This class contains meta information specific to a module.
MachineOperand class - Representation of each machine instruction operand.
MachineOperandType getType() const
getType - Returns the MachineOperandType for this operand.
Register getReg() const
getReg - Returns the register number.
@ MO_Register
Register operand.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:67
AnalysisType & getAnalysis() const
getAnalysis<AnalysisType>() - This function is used by subclasses to get to the analysis information ...
virtual StringRef getPassName() const
getPassName - Return a nice clean name for a pass.
Definition Pass.cpp:85
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
A wrapper around a string literal that serves as a proxy for constructing global tables of StringRefs...
Definition StringRef.h:854
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
TargetInstrInfo - Interface to description of machine instruction set.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
Iterator support for section-based access.
Definition IR2Vec.h:196
Generic storage class for section-based vocabularies.
Definition IR2Vec.h:151
Base class for MIR embedders.
Definition MIR2Vec.h:291
const unsigned Dimension
Dimension of the embeddings; Captured from the vocabulary.
Definition MIR2Vec.h:297
Embedding getMFunctionVector() const
Computes and returns the embedding for the current machine function.
Definition MIR2Vec.h:340
const MIRVocabulary & Vocab
Definition MIR2Vec.h:294
Embedding getMInstVector(const MachineInstr &MI) const
Computes and returns the embedding for a given machine instruction MI in the machine function MF.
Definition MIR2Vec.h:329
virtual Embedding computeEmbeddings(const MachineInstr &MI) const =0
Function to compute the embedding for a given machine instruction.
Embedding getMBBVector(const MachineBasicBlock &MBB) const
Computes and returns the embedding for a given machine basic block in the machine function MF.
Definition MIR2Vec.h:335
const float RegOperandWeight
Definition MIR2Vec.h:300
MIREmbedder(const MachineFunction &MF, const MIRVocabulary &Vocab)
Definition MIR2Vec.h:302
const float CommonOperandWeight
Definition MIR2Vec.h:300
LLVM_ABI Embedding computeEmbeddings() const
Function to compute embeddings.
Definition MIR2Vec.cpp:549
const float OpcWeight
Weight for opcode embeddings.
Definition MIR2Vec.h:300
const MachineFunction & MF
Definition MIR2Vec.h:293
virtual ~MIREmbedder()=default
static LLVM_ABI std::unique_ptr< MIREmbedder > create(MIR2VecKind Mode, const MachineFunction &MF, const MIRVocabulary &Vocab)
Factory method to create an Embedder object of the specified kind Returns nullptr if the requested ki...
Definition MIR2Vec.cpp:516
Class for storing and accessing the MIR2Vec vocabulary.
Definition MIR2Vec.h:86
unsigned getDimension() const
Definition MIR2Vec.h:230
unsigned getEntityIDForOpcode(unsigned Opcode) const
Get entity ID (flat index) for an opcode This is used for triplet generation.
Definition MIR2Vec.h:234
const_iterator end() const
Definition MIR2Vec.h:264
LLVM_ABI_FOR_TEST unsigned getCanonicalIndexForOperandName(StringRef OperandName) const
Definition MIR2Vec.cpp:159
const Embedding & operator[](MachineOperand Operand) const
Definition MIR2Vec.h:252
LLVM_ABI_FOR_TEST unsigned getCanonicalIndexForRegisterClass(StringRef RegName, bool IsPhysical=true) const
Definition MIR2Vec.cpp:169
static LLVM_ABI_FOR_TEST Expected< MIRVocabulary > create(VocabMap &&OpcMap, VocabMap &&CommonOperandsMap, VocabMap &&PhyRegMap, VocabMap &&VirtRegMap, const TargetInstrInfo &TII, const TargetRegisterInfo &TRI, const MachineRegisterInfo &MRI)
Factory method to create MIRVocabulary from vocabulary map.
Definition MIR2Vec.cpp:93
static LLVM_ABI_FOR_TEST std::string extractBaseOpcodeName(StringRef InstrName)
Static method for extracting base opcode names (public for testing)
Definition MIR2Vec.cpp:114
ir2vec::VocabStorage::const_iterator const_iterator
Definition MIR2Vec.h:261
const_iterator begin() const
Definition MIR2Vec.h:262
const Embedding & operator[](unsigned Opcode) const
Definition MIR2Vec.h:247
size_t getCanonicalSize() const
Total number of entries in the vocabulary.
Definition MIR2Vec.h:281
static LLVM_ABI Expected< MIRVocabulary > createDummyVocabForTest(const TargetInstrInfo &TII, const TargetRegisterInfo &TRI, const MachineRegisterInfo &MRI, unsigned Dim=1)
Create a dummy vocabulary for testing purposes.
Definition MIR2Vec.cpp:377
unsigned getEntityIDForMachineOperand(const MachineOperand &MO) const
Get entity ID (flat index) for a machine operand This is used for triplet generation.
Definition MIR2Vec.h:240
LLVM_ABI std::string getStringKey(unsigned Pos) const
Get the string key for a vocabulary entry at the given position.
Definition MIR2Vec.cpp:179
LLVM_ABI_FOR_TEST unsigned getCanonicalIndexForBaseName(StringRef BaseName) const
Get indices from opcode or operand names.
Definition MIR2Vec.cpp:144
Class for computing Symbolic embeddings Symbolic embeddings are constructed based on the entity-level...
Definition MIR2Vec.h:350
static LLVM_ABI_FOR_TEST std::unique_ptr< SymbolicMIREmbedder > create(const MachineFunction &MF, const MIRVocabulary &Vocab)
Definition MIR2Vec.cpp:563
SymbolicMIREmbedder(const MachineFunction &F, const MIRVocabulary &Vocab)
Definition MIR2Vec.cpp:558
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
DenseMap< const MachineInstr *, Embedding > MachineInstEmbeddingsMap
Definition MIR2Vec.h:80
LLVM_ABI llvm::cl::OptionCategory MIR2VecCategory
LLVM_ABI cl::opt< float > OpcWeight
LLVM_ABI cl::opt< float > RegOperandWeight
Definition MIR2Vec.h:77
ir2vec::Embedding Embedding
Definition MIR2Vec.h:79
DenseMap< const MachineBasicBlock *, Embedding > MachineBlockEmbeddingsMap
Definition MIR2Vec.h:81
LLVM_ABI cl::opt< float > CommonOperandWeight
Definition MIR2Vec.h:77
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI MachineFunctionPass * createMIR2VecPrinterLegacyPass(raw_ostream &OS)
Create a machine pass that prints MIR2Vec embeddings.
Definition MIR2Vec.cpp:673
MIR2VecKind
Definition MIR2Vec.h:68
Embedding is a datatype that wraps std::vector<double>.
Definition IR2Vec.h:87