29#ifndef LLVM_CODEGEN_MIR2VEC_H
30#define LLVM_CODEGEN_MIR2VEC_H
64 using VocabMap = std::map<std::string, ir2vec::Embedding>;
74 enum class Section :
unsigned { Opcodes = 0, MaxSections };
77 mutable std::set<std::string> UniqueBaseOpcodeNames;
79 void generateStorage(
const VocabMap &OpcodeMap);
80 void buildCanonicalOpcodeMapping();
83 unsigned getCanonicalOpcodeIndex(
unsigned Opcode)
const;
98 : Storage(
std::
move(Storage)), TII(TII) {}
101 return UniqueBaseOpcodeNames.size() > 0 &&
102 Layout.TotalEntries == Storage.size() && Storage.isValid();
108 return Storage.getDimension();
114 unsigned LocalIndex = getCanonicalOpcodeIndex(Opcode);
115 return Storage[
static_cast<unsigned>(Section::Opcodes)][LocalIndex];
122 return Storage.begin();
127 return Storage.end();
133 return Storage.size();
141 using VocabVector = std::vector<mir2vec::Embedding>;
142 using VocabMap = std::map<std::string, mir2vec::Embedding>;
143 VocabMap StrVocabMap;
147 Error readVocabulary();
180 return "MIR2Vec Vocabulary Printer Pass";
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
Provides ErrorOr<T> smart pointer.
const HexagonInstrInfo * TII
This file defines the IR2Vec vocabulary analysis(IR2VecVocabAnalysis), the core ir2vec::Embedder inte...
This header defines various interfaces for pass management in LLVM.
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.
This is an important class for using LLVM in a threaded context.
Pass to analyze and populate MIR2Vec vocabulary from a module.
mir2vec::MIRVocabulary getMIR2VecVocabulary(const Module &M)
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
MIR2VecVocabLegacyAnalysis()
StringRef getPassName() const override
getPassName - Return a nice clean name for a pass.
bool doFinalization(Module &M) override
doFinalization - Virtual method overriden by subclasses to do any necessary clean up after all passes...
bool runOnMachineFunction(MachineFunction &MF) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
MIR2VecVocabPrinterLegacyPass(raw_ostream &OS)
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
MachineFunctionPass(char &ID)
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
A Module instance is used to store all the information related to an LLVM module.
virtual StringRef getPassName() const
getPassName - Return a nice clean name for a pass.
StringRef - Represent a constant reference to a string, i.e.
TargetInstrInfo - Interface to description of machine instruction set.
Iterator support for section-based access.
Generic storage class for section-based vocabularies.
Class for storing and accessing the MIR2Vec vocabulary.
unsigned getDimension() const
const_iterator end() const
static std::string extractBaseOpcodeName(StringRef InstrName)
Static method for extracting base opcode names (public for testing)
ir2vec::VocabStorage::const_iterator const_iterator
const_iterator begin() const
const Embedding & operator[](unsigned Opcode) const
size_t getCanonicalSize() const
Total number of entries in the vocabulary.
MIRVocabulary(ir2vec::VocabStorage &&Storage, const TargetInstrInfo &TII)
std::string getStringKey(unsigned Pos) const
Get the string key for a vocabulary entry at the given position.
unsigned getCanonicalIndexForBaseName(StringRef BaseName) const
Get canonical index for base name (public for testing)
This class implements an extremely fast bulk output stream that can only output to a stream.
llvm::cl::OptionCategory MIR2VecCategory
cl::opt< float > OpcWeight
ir2vec::Embedding Embedding
This is an optimization pass for GlobalISel generic memory operations.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Implement std::hash so that hash_code can be used in STL containers.
Embedding is a datatype that wraps std::vector<double>.