LLVM 24.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 <optional>
58#include <set>
59#include <string>
60
61namespace llvm {
62
63class Module;
64class raw_ostream;
65class LLVMContext;
67class TargetInstrInfo;
68
69enum class MIR2VecKind { Symbolic };
70
71namespace mir2vec {
72
73// Forward declarations
74class MIREmbedder;
76
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 // MO_Register is handled by the register sections. Operand types without an
136 // entry, such as MO_DbgInstrRef, get a zero embedding.
137 struct CommonOperandEntry {
139 StringLiteral Name;
140 };
141 static constexpr CommonOperandEntry CommonOperands[] = {
142 {MachineOperand::MO_Immediate, "Immediate"},
143 {MachineOperand::MO_CImmediate, "CImmediate"},
144 {MachineOperand::MO_FPImmediate, "FPImmediate"},
146 {MachineOperand::MO_FrameIndex, "FrameIndex"},
147 {MachineOperand::MO_ConstantPoolIndex, "ConstantPoolIndex"},
148 {MachineOperand::MO_TargetIndex, "TargetIndex"},
149 {MachineOperand::MO_JumpTableIndex, "JumpTableIndex"},
150 {MachineOperand::MO_ExternalSymbol, "ExternalSymbol"},
151 {MachineOperand::MO_GlobalAddress, "GlobalAddress"},
152 {MachineOperand::MO_BlockAddress, "BlockAddress"},
153 {MachineOperand::MO_RegisterMask, "RegisterMask"},
154 {MachineOperand::MO_RegisterLiveOut, "RegisterLiveOut"},
155 {MachineOperand::MO_Metadata, "Metadata"},
156 {MachineOperand::MO_MCSymbol, "MCSymbol"},
157 {MachineOperand::MO_CFIIndex, "CFIIndex"},
158 {MachineOperand::MO_IntrinsicID, "IntrinsicID"},
159 {MachineOperand::MO_Predicate, "Predicate"},
160 {MachineOperand::MO_ShuffleMask, "ShuffleMask"},
161 {MachineOperand::MO_LaneMask, "LaneMask"}};
162
163 const TargetInstrInfo &TII;
164 const TargetRegisterInfo &TRI;
165
166 void generateStorage(const VocabMap &OpcodeMap,
167 const VocabMap &CommonOperandMap,
168 const VocabMap &PhyRegMap, const VocabMap &VirtRegMap);
169 void buildCanonicalOpcodeMapping();
170 void buildRegisterOperandMapping();
171
172 /// Get canonical index for a machine opcode
173 LLVM_ABI unsigned getCanonicalOpcodeIndex(unsigned Opcode) const;
174
175 /// Get index for a common (non-register) machine operand. Returns
176 /// std::nullopt if OperandType has no vocabulary entry.
177 LLVM_ABI std::optional<unsigned>
178 getCommonOperandIndex(MachineOperand::MachineOperandType OperandType) const;
179
180 /// Get index for a register machine operand. Returns std::nullopt if Reg
181 /// belongs to no register class, which is a valid outcome for some target
182 /// physical registers.
183 LLVM_ABI std::optional<unsigned>
184 getRegisterOperandIndex(Register Reg, const MachineRegisterInfo &MRI) const;
185
186 // Accessors for operand types
187 const Embedding &
188 operator[](MachineOperand::MachineOperandType OperandType) const {
189 std::optional<unsigned> LocalIndex = getCommonOperandIndex(OperandType);
190 if (!LocalIndex)
191 return ZeroEmbedding;
192 return Storage[static_cast<unsigned>(Section::CommonOperands)][*LocalIndex];
193 }
194
195 const Embedding &getRegisterEmbedding(Register Reg,
196 const MachineRegisterInfo &MRI) const {
197 // Reg is sometimes NoRegister (0) for optional operands. We return a zero
198 // vector in this case.
199 if (!Reg.isValid())
200 return ZeroEmbedding;
201 // TODO: Implement proper stack slot handling for MIR2Vec embeddings.
202 // Stack slots represent frame indices and should have their own
203 // embedding strategy rather than defaulting to register class 0.
204 // Consider: 1) Separate vocabulary section for stack slots
205 // 2) Stack slot size/alignment based embeddings
206 // 3) Frame index based categorization
207 if (Reg.isStack())
208 return ZeroEmbedding;
209
210 // Registers that belong to no register class have no vocabulary entry;
211 // treat them like the other unmapped cases above.
212 std::optional<unsigned> LocalIndex = getRegisterOperandIndex(Reg, MRI);
213 if (!LocalIndex)
214 return ZeroEmbedding;
215 auto SectionID =
216 Reg.isPhysical() ? Section::PhyRegisters : Section::VirtRegisters;
217 return Storage[static_cast<unsigned>(SectionID)][*LocalIndex];
218 }
219
220 /// Get entity ID (flat index) for a common operand type
221 /// This is used for triplet generation
222 unsigned getEntityIDForCommonOperand(
223 MachineOperand::MachineOperandType OperandType) const {
224 std::optional<unsigned> LocalIndex = getCommonOperandIndex(OperandType);
225 assert(LocalIndex && "Operand type has no vocabulary entry");
226 return Layout.CommonOperandBase + *LocalIndex;
227 }
228
229 /// Get entity ID (flat index) for a register
230 /// This is used for triplet generation
231 unsigned getEntityIDForRegister(Register Reg,
232 const MachineRegisterInfo &MRI) const {
233 if (!Reg.isValid() || Reg.isStack())
234 return Layout
235 .VirtRegBase; // Return VirtRegBase for invalid/stack registers
236 std::optional<unsigned> LocalIndex = getRegisterOperandIndex(Reg, MRI);
237 // Registers without a register class share the invalid/stack fallback.
238 if (!LocalIndex)
239 return Layout.VirtRegBase;
240 size_t BaseOffset =
241 Reg.isPhysical() ? Layout.PhyRegBase : Layout.VirtRegBase;
242 return BaseOffset + *LocalIndex;
243 }
244
245public:
246 /// Static method for extracting base opcode names (public for testing)
247 LLVM_ABI static std::string extractBaseOpcodeName(StringRef InstrName);
248
249 /// Get indices from opcode or operand names. These are public for testing.
250 /// String based lookups are inefficient and should be avoided in general.
251 LLVM_ABI unsigned getCanonicalIndexForBaseName(StringRef BaseName) const;
252 LLVM_ABI unsigned
253 getCanonicalIndexForOperandName(StringRef OperandName) const;
254 LLVM_ABI unsigned
256 bool IsPhysical = true) const;
257
258 /// Get the string key for a vocabulary entry at the given position
259 LLVM_ABI std::string getStringKey(unsigned Pos) const;
260
261 unsigned getDimension() const { return Storage.getDimension(); }
262
263 /// Get entity ID (flat index) for an opcode
264 /// This is used for triplet generation
265 unsigned getEntityIDForOpcode(unsigned Opcode) const {
266 return Layout.OpcodeBase + getCanonicalOpcodeIndex(Opcode);
267 }
268
269 /// Get entity ID (flat index) for a machine operand
270 /// This is used for triplet generation
272 const MachineRegisterInfo &MRI) const {
274 return getEntityIDForRegister(MO.getReg(), MRI);
275 return getEntityIDForCommonOperand(MO.getType());
276 }
277
278 // Accessor methods
279 const Embedding &operator[](unsigned Opcode) const {
280 unsigned LocalIndex = getCanonicalOpcodeIndex(Opcode);
281 return Storage[static_cast<unsigned>(Section::Opcodes)][LocalIndex];
282 }
283
285 const MachineRegisterInfo &MRI) const {
286 auto OperandType = Operand.getType();
287 if (OperandType == MachineOperand::MO_Register)
288 return getRegisterEmbedding(Operand.getReg(), MRI);
289 else
290 return operator[](OperandType);
291 }
292
293 // Iterator access
295 const_iterator begin() const { return Storage.begin(); }
296
297 const_iterator end() const { return Storage.end(); }
298
299 MIRVocabulary() = delete;
300
301 /// Factory method to create MIRVocabulary from vocabulary map
303 create(VocabMap &&OpcMap, VocabMap &&CommonOperandsMap, VocabMap &&PhyRegMap,
304 VocabMap &&VirtRegMap, const TargetInstrInfo &TII,
305 const TargetRegisterInfo &TRI);
306
307 /// Create a dummy vocabulary for testing purposes.
310 const TargetRegisterInfo &TRI, unsigned Dim = 1);
311
312 /// Total number of entries in the vocabulary
313 size_t getCanonicalSize() const { return Storage.size(); }
314
315private:
316 MIRVocabulary(VocabMap &&OpcMap, VocabMap &&CommonOperandsMap,
317 VocabMap &&PhyRegMap, VocabMap &&VirtRegMap,
319};
320
321/// Base class for MIR embedders
323protected:
326
327 /// Dimension of the embeddings; Captured from the vocabulary
328 const unsigned Dimension;
329
330 /// Weight for opcode embeddings
332
334
335 /// Function to compute embeddings.
337
338 /// Function to compute the embedding for a given machine basic block.
340
341 /// Function to compute the embedding for a given machine instruction.
342 /// Specific to the kind of embeddings being computed.
343 virtual Embedding computeEmbeddings(const MachineInstr &MI) const = 0;
344
345public:
346 virtual ~MIREmbedder() = default;
347
348 /// Factory method to create an Embedder object of the specified kind
349 /// Returns nullptr if the requested kind is not supported.
350 LLVM_ABI static std::unique_ptr<MIREmbedder>
352 const MIRVocabulary &Vocab);
353
354 /// Computes and returns the embedding for a given machine instruction MI in
355 /// the machine function MF.
357 return computeEmbeddings(MI);
358 }
359
360 /// Computes and returns the embedding for a given machine basic block in the
361 /// machine function MF.
365
366 /// Computes and returns the embedding for the current machine function.
368 // Currently, we always (re)compute the embeddings for the function. This is
369 // cheaper than caching the vector.
370 return computeEmbeddings();
371 }
372};
373
374/// Class for computing Symbolic embeddings
375/// Symbolic embeddings are constructed based on the entity-level
376/// representations obtained from the MIR Vocabulary.
378private:
379 Embedding computeEmbeddings(const MachineInstr &MI) const override;
380
381public:
383 static std::unique_ptr<SymbolicMIREmbedder>
385};
386
387} // namespace mir2vec
388
389/// MIR2Vec vocabulary provider used by pass managers and standalone tools.
390/// This class encapsulates the core vocabulary loading logic and can be used
391/// independently of the pass manager infrastructure. For pass-based usage,
392/// see MIR2VecVocabLegacyAnalysis and MIR2VecVocabAnalysis.
394public:
395 MIR2VecVocabProvider(const MachineModuleInfo &MMI) : MMI(MMI) {}
396
398
399private:
400 const MachineModuleInfo &MMI;
401};
402
403/// Pass to analyze and populate MIR2Vec vocabulary from a module
405 using VocabMap = std::map<std::string, mir2vec::Embedding>;
406
407 StringRef getPassName() const override;
408
409protected:
410 void getAnalysisUsage(AnalysisUsage &AU) const override {
412 AU.setPreservesAll();
413 }
414 std::unique_ptr<MIR2VecVocabProvider> Provider;
415
416public:
417 static char ID;
419
421 MachineModuleInfo &MMI =
423 if (!Provider)
424 Provider = std::make_unique<MIR2VecVocabProvider>(MMI);
425 return Provider->getVocabulary(M);
426 }
427
429 assert(Provider && "Provider not initialized");
430 return *Provider;
431 }
432};
433
434/// This pass prints the embeddings in the MIR2Vec vocabulary
436 raw_ostream &OS;
437
438public:
439 static char ID;
442
443 bool runOnMachineFunction(MachineFunction &MF) override;
444 bool doFinalization(Module &M) override;
450
451 StringRef getPassName() const override {
452 return "MIR2Vec Vocabulary Printer Pass";
453 }
454};
455
456/// This pass prints the MIR2Vec embeddings for machine functions, basic blocks,
457/// and instructions
459 raw_ostream &OS;
460
461public:
462 static char ID;
465
466 bool runOnMachineFunction(MachineFunction &MF) override;
472
473 StringRef getPassName() const override {
474 return "MIR2Vec Embedder Printer Pass";
475 }
476};
477
478/// Create a machine pass that prints MIR2Vec embeddings
479LLVM_ABI MachineFunctionPass *createMIR2VecPrinterLegacyPass(raw_ostream &OS);
480
481/// New pass manager analysis that provides the MIR2Vec vocabulary for a machine
482/// function.
483class MIR2VecVocabAnalysis : public AnalysisInfoMixin<MIR2VecVocabAnalysis> {
485 LLVM_ABI static AnalysisKey Key;
486
487public:
491};
492
493/// New pass manager pass that prints the MIR2Vec embeddings for machine
494/// functions, basic blocks, and instructions.
495class MIR2VecPrinterPass : public RequiredPassInfoMixin<MIR2VecPrinterPass> {
496 raw_ostream &OS;
497
498public:
499 explicit MIR2VecPrinterPass(raw_ostream &OS) : OS(OS) {}
502};
503
504} // namespace llvm
505
506#endif // LLVM_CODEGEN_MIR2VEC_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock & MBB
#define LLVM_ABI
Definition Compiler.h:211
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
std::map< std::string, Embedding > VocabMap
Definition MIR2Vec.cpp:463
Register Reg
Register const TargetRegisterInfo * TRI
Promote Memory to Register
Definition Mem2Reg.cpp:110
MachineRegisterInfo & MRI
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.
Tagged union holding either a T or a Error.
Definition Error.h:485
ImmutablePass(char &pid)
Definition Pass.h:285
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:76
MIR2VecPrinterLegacyPass(raw_ostream &OS)
Definition MIR2Vec.h:463
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
Definition MIR2Vec.h:467
StringRef getPassName() const override
getPassName - Return a nice clean name for a pass.
Definition MIR2Vec.h:473
MIR2VecPrinterPass(raw_ostream &OS)
Definition MIR2Vec.h:499
LLVM_ABI PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
Definition MIR2Vec.cpp:749
New pass manager analysis that provides the MIR2Vec vocabulary for a machine function.
Definition MIR2Vec.h:483
mir2vec::MIRVocabulary Result
Definition MIR2Vec.h:488
LLVM_ABI Result run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
Definition MIR2Vec.cpp:558
Pass to analyze and populate MIR2Vec vocabulary from a module.
Definition MIR2Vec.h:404
MIR2VecVocabProvider & getProvider()
Definition MIR2Vec.h:428
Expected< mir2vec::MIRVocabulary > getMIR2VecVocabulary(const Module &M)
Definition MIR2Vec.h:420
std::unique_ptr< MIR2VecVocabProvider > Provider
Definition MIR2Vec.h:414
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
Definition MIR2Vec.h:410
StringRef getPassName() const override
getPassName - Return a nice clean name for a pass.
Definition MIR2Vec.h:451
MIR2VecVocabPrinterLegacyPass(raw_ostream &OS)
Definition MIR2Vec.h:440
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
Definition MIR2Vec.h:445
MIR2Vec vocabulary provider used by pass managers and standalone tools.
Definition MIR2Vec.h:393
MIR2VecVocabProvider(const MachineModuleInfo &MMI)
Definition MIR2Vec.h:395
LLVM_ABI Expected< mir2vec::MIRVocabulary > getVocabulary(const Module &M)
Definition MIR2Vec.cpp:532
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_CFIIndex
MCCFIInstruction index.
@ MO_Immediate
Immediate operand.
@ MO_ConstantPoolIndex
Address of indexed Constant in Constant Pool.
@ MO_MCSymbol
MCSymbol reference (for debug/eh info)
@ MO_Predicate
Generic predicate for ISel.
@ MO_GlobalAddress
Address of a global value.
@ MO_RegisterMask
Mask of preserved registers.
@ MO_ShuffleMask
Other IR Constant for ISel (shuffle masks)
@ MO_CImmediate
Immediate >64bit operand.
@ MO_BlockAddress
Address of a basic block.
@ MO_MachineBasicBlock
MachineBasicBlock reference.
@ MO_LaneMask
Mask to represent active parts of registers.
@ MO_FrameIndex
Abstract Stack Frame Index.
@ MO_Register
Register operand.
@ MO_ExternalSymbol
Name of external global symbol.
@ MO_IntrinsicID
Intrinsic ID for ISel.
@ MO_JumpTableIndex
Address of indexed Jump Table for switch.
@ MO_TargetIndex
Target-dependent index+offset operand.
@ MO_Metadata
Metadata reference (for debug info)
@ MO_FPImmediate
Floating-point immediate operand.
@ MO_RegisterLiveOut
Mask of live-out registers.
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:68
AnalysisType & getAnalysis() const
getAnalysis<AnalysisType>() - This function is used by subclasses to get to the analysis information ...
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
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:888
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
TargetInstrInfo - Interface to description of machine instruction set.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
Iterator support for section-based access.
Definition IR2Vec.h:199
Generic storage class for section-based vocabularies.
Definition IR2Vec.h:154
Base class for MIR embedders.
Definition MIR2Vec.h:322
const unsigned Dimension
Dimension of the embeddings; Captured from the vocabulary.
Definition MIR2Vec.h:328
Embedding getMFunctionVector() const
Computes and returns the embedding for the current machine function.
Definition MIR2Vec.h:367
const MIRVocabulary & Vocab
Definition MIR2Vec.h:325
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:356
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:362
const float RegOperandWeight
Definition MIR2Vec.h:331
const float CommonOperandWeight
Definition MIR2Vec.h:331
LLVM_ABI Embedding computeEmbeddings() const
Function to compute embeddings.
Definition MIR2Vec.cpp:609
const float OpcWeight
Weight for opcode embeddings.
Definition MIR2Vec.h:331
const MachineFunction & MF
Definition MIR2Vec.h:324
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:570
LLVM_ABI MIREmbedder(const MachineFunction &MF, const MIRVocabulary &Vocab)
Definition MIR2Vec.cpp:580
Class for storing and accessing the MIR2Vec vocabulary.
Definition MIR2Vec.h:86
unsigned getDimension() const
Definition MIR2Vec.h:261
unsigned getEntityIDForOpcode(unsigned Opcode) const
Get entity ID (flat index) for an opcode This is used for triplet generation.
Definition MIR2Vec.h:265
const_iterator end() const
Definition MIR2Vec.h:297
const Embedding & getOperandEmbedding(const MachineOperand &Operand, const MachineRegisterInfo &MRI) const
Definition MIR2Vec.h:284
LLVM_ABI unsigned getCanonicalIndexForOperandName(StringRef OperandName) const
Definition MIR2Vec.cpp:168
LLVM_ABI unsigned getCanonicalIndexForRegisterClass(StringRef RegName, bool IsPhysical=true) const
Definition MIR2Vec.cpp:179
static LLVM_ABI std::string extractBaseOpcodeName(StringRef InstrName)
Static method for extracting base opcode names (public for testing)
Definition MIR2Vec.cpp:123
ir2vec::VocabStorage::const_iterator const_iterator
Definition MIR2Vec.h:294
const_iterator begin() const
Definition MIR2Vec.h:295
static LLVM_ABI Expected< MIRVocabulary > createDummyVocabForTest(const TargetInstrInfo &TII, const TargetRegisterInfo &TRI, unsigned Dim=1)
Create a dummy vocabulary for testing purposes.
Definition MIR2Vec.cpp:418
const Embedding & operator[](unsigned Opcode) const
Definition MIR2Vec.h:279
unsigned getEntityIDForMachineOperand(const MachineOperand &MO, const MachineRegisterInfo &MRI) const
Get entity ID (flat index) for a machine operand This is used for triplet generation.
Definition MIR2Vec.h:271
size_t getCanonicalSize() const
Total number of entries in the vocabulary.
Definition MIR2Vec.h:313
static LLVM_ABI Expected< MIRVocabulary > create(VocabMap &&OpcMap, VocabMap &&CommonOperandsMap, VocabMap &&PhyRegMap, VocabMap &&VirtRegMap, const TargetInstrInfo &TII, const TargetRegisterInfo &TRI)
Factory method to create MIRVocabulary from vocabulary map.
Definition MIR2Vec.cpp:101
LLVM_ABI std::string getStringKey(unsigned Pos) const
Get the string key for a vocabulary entry at the given position.
Definition MIR2Vec.cpp:189
LLVM_ABI unsigned getCanonicalIndexForBaseName(StringRef BaseName) const
Get indices from opcode or operand names.
Definition MIR2Vec.cpp:153
Class for computing Symbolic embeddings Symbolic embeddings are constructed based on the entity-level...
Definition MIR2Vec.h:377
static std::unique_ptr< SymbolicMIREmbedder > create(const MachineFunction &MF, const MIRVocabulary &Vocab)
Definition MIR2Vec.cpp:626
SymbolicMIREmbedder(const MachineFunction &F, const MIRVocabulary &Vocab)
Definition MIR2Vec.cpp:621
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
ir2vec::Embedding Embedding
Definition MIR2Vec.h:79
DenseMap< const MachineBasicBlock *, Embedding > MachineBlockEmbeddingsMap
Definition MIR2Vec.h:81
This is an optimization pass for GlobalISel generic memory operations.
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
LLVM_ABI MachineFunctionPass * createMIR2VecPrinterLegacyPass(raw_ostream &OS)
Create a machine pass that prints MIR2Vec embeddings.
Definition MIR2Vec.cpp:744
MIR2VecKind
Definition MIR2Vec.h:69
A CRTP mix-in that provides informational APIs needed for analysis passes.
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition Analysis.h:29
A CRTP mix-in for passes that should not be skipped.
Embedding is a datatype that wraps std::vector<double>.
Definition IR2Vec.h:85