LLVM 20.0.0git
|
Helper struct for converting the Instructions in a Module into a vector of unsigned integers. More...
#include "llvm/Analysis/IRSimilarityIdentifier.h"
Classes | |
struct | InstructionClassification |
Custom InstVisitor to classify different instructions for whether it can be analyzed for similarity. More... | |
Public Member Functions | |
IRInstructionData * | allocateIRInstructionData (Instruction &I, bool Legality, IRInstructionDataList &IDL) |
Get an allocated IRInstructionData struct using the InstDataAllocator. | |
IRInstructionData * | allocateIRInstructionData (IRInstructionDataList &IDL) |
Get an empty allocated IRInstructionData struct using the InstDataAllocator. | |
IRInstructionDataList * | allocateIRInstructionDataList () |
Get an allocated IRInstructionDataList object using the IDLAllocator. | |
void | initializeForBBs (Function &F, unsigned &BBNumber) |
Assigns values to all the basic blocks in function F starting from integer BBNumber . | |
void | initializeForBBs (Module &M) |
Assigns values to all the basic blocks in Module M . | |
void | convertToUnsignedVec (BasicBlock &BB, std::vector< IRInstructionData * > &InstrList, std::vector< unsigned > &IntegerMapping) |
Maps the Instructions in a BasicBlock BB to legal or illegal integers determined by InstrType . | |
unsigned | mapToLegalUnsigned (BasicBlock::iterator &It, std::vector< unsigned > &IntegerMappingForBB, std::vector< IRInstructionData * > &InstrListForBB) |
Maps an Instruction to a legal integer. | |
unsigned | mapToIllegalUnsigned (BasicBlock::iterator &It, std::vector< unsigned > &IntegerMappingForBB, std::vector< IRInstructionData * > &InstrListForBB, bool End=false) |
Maps an Instruction to an illegal integer. | |
IRInstructionMapper (SpecificBumpPtrAllocator< IRInstructionData > *IDA, SpecificBumpPtrAllocator< IRInstructionDataList > *IDLA) | |
Public Attributes | |
unsigned | IllegalInstrNumber = static_cast<unsigned>(-3) |
The starting illegal instruction number to map to. | |
unsigned | LegalInstrNumber = 0 |
The next available integer to assign to a legal Instruction to. | |
DenseMap< IRInstructionData *, unsigned, IRInstructionDataTraits > | InstructionIntegerMap |
Correspondence from IRInstructionData to unsigned integers. | |
DenseMap< BasicBlock *, unsigned > | BasicBlockToInteger |
A mapping for a basic block in a module to its assigned number/location in the module. | |
bool | AddedIllegalLastTime = false |
Set if we added an illegal number in the previous step. | |
bool | CanCombineWithPrevInstr = false |
Marks whether we found a illegal instruction in the previous step. | |
bool | HaveLegalRange = false |
Marks whether we have found a set of instructions that is long enough to be considered for similarity. | |
bool | EnableMatchCallsByName = false |
Marks whether we should use exact function names, as well as types to find similarity between calls. | |
SpecificBumpPtrAllocator< IRInstructionData > * | InstDataAllocator = nullptr |
This allocator pointer is in charge of holding on to the IRInstructionData so it is not deallocated until whatever external tool is using it is done with the information. | |
SpecificBumpPtrAllocator< IRInstructionDataList > * | IDLAllocator = nullptr |
This allocator pointer is in charge of creating the IRInstructionDataList so it is not deallocated until whatever external tool is using it is done with the information. | |
IRInstructionDataList * | IDL = nullptr |
InstructionClassification | InstClassifier |
Maps an Instruction to a member of InstrType. | |
Helper struct for converting the Instructions in a Module into a vector of unsigned integers.
This vector of unsigned integers can be thought of as a "numeric string". This numeric string can then be queried by, for example, data structures that find repeated substrings.
This hashing is done per BasicBlock in the module. To hash Instructions based off of their operations, each Instruction is wrapped in an IRInstructionData struct. The unsigned integer for an IRInstructionData depends on:
TODO: This is very similar to the MachineOutliner, and should be consolidated into the same interface.
Definition at line 381 of file IRSimilarityIdentifier.h.
|
inline |
Definition at line 504 of file IRSimilarityIdentifier.h.
References assert(), IDL, and IDLAllocator.
IRInstructionData * IRInstructionMapper::allocateIRInstructionData | ( | Instruction & | I, |
bool | Legality, | ||
IRInstructionDataList & | IDL | ||
) |
Get an allocated IRInstructionData struct using the InstDataAllocator.
I | - The Instruction to wrap with IRInstructionData. |
Legality | - A boolean value that is true if the instruction is to be considered for similarity, and false if not. |
IDL | - The InstructionDataList that the IRInstructionData is inserted into. |
Definition at line 376 of file IRSimilarityIdentifier.cpp.
References I, IDL, and InstDataAllocator.
Referenced by mapToIllegalUnsigned(), and mapToLegalUnsigned().
IRInstructionData * IRInstructionMapper::allocateIRInstructionData | ( | IRInstructionDataList & | IDL | ) |
Get an empty allocated IRInstructionData struct using the InstDataAllocator.
IDL | - The InstructionDataList that the IRInstructionData is inserted into. |
Definition at line 382 of file IRSimilarityIdentifier.cpp.
References IDL, and InstDataAllocator.
IRInstructionDataList * IRInstructionMapper::allocateIRInstructionDataList | ( | ) |
Get an allocated IRInstructionDataList object using the IDLAllocator.
Definition at line 387 of file IRSimilarityIdentifier.cpp.
References IDLAllocator.
void IRInstructionMapper::convertToUnsignedVec | ( | BasicBlock & | BB, |
std::vector< IRInstructionData * > & | InstrList, | ||
std::vector< unsigned > & | IntegerMapping | ||
) |
Maps the Instructions in a BasicBlock BB
to legal or illegal integers determined by InstrType
.
Two Instructions are mapped to the same value if they are close as defined by the InstructionData class above.
[in] | BB | - The BasicBlock to be mapped to integers. |
[in,out] | InstrList | - Vector of IRInstructionData to append to. |
[in,out] | IntegerMapping | - Vector of unsigned integers to append to. |
Definition at line 290 of file IRSimilarityIdentifier.cpp.
References AddedIllegalLastTime, llvm::append_range(), llvm::BasicBlock::begin(), llvm::BasicBlock::end(), IDL, llvm::IRSimilarity::Illegal, InstClassifier, llvm::IRSimilarity::Invisible, llvm::IRSimilarity::Legal, mapToIllegalUnsigned(), mapToLegalUnsigned(), llvm::simple_ilist< T, Options >::push_back(), and llvm::InstVisitor< SubClass, RetTy >::visit().
|
inline |
Assigns values to all the basic blocks in function F
starting from integer BBNumber
.
F | - The function containing the basic blocks to assign numbers to. |
BBNumber | - The number to start from. |
Definition at line 456 of file IRSimilarityIdentifier.h.
References BasicBlockToInteger, and F.
Referenced by initializeForBBs().
|
inline |
Assigns values to all the basic blocks in Module M
.
M | - The module containing the basic blocks to assign numbers to. |
Definition at line 463 of file IRSimilarityIdentifier.h.
References F, and initializeForBBs().
unsigned IRInstructionMapper::mapToIllegalUnsigned | ( | BasicBlock::iterator & | It, |
std::vector< unsigned > & | IntegerMappingForBB, | ||
std::vector< IRInstructionData * > & | InstrListForBB, | ||
bool | End = false |
||
) |
Maps an Instruction to an illegal integer.
[in] | It | - The Instruction to be mapped to an integer. |
[in,out] | IntegerMappingForBB | - Vector of unsigned integers to append to. |
[in,out] | InstrListForBB | - Vector of IRInstructionData to append to. |
End | - true if creating a dummy IRInstructionData at the end of a basic block. |
It
was mapped to. Definition at line 393 of file IRSimilarityIdentifier.cpp.
References AddedIllegalLastTime, allocateIRInstructionData(), assert(), CanCombineWithPrevInstr, End, IDL, IllegalInstrNumber, and LegalInstrNumber.
Referenced by convertToUnsignedVec().
unsigned IRInstructionMapper::mapToLegalUnsigned | ( | BasicBlock::iterator & | It, |
std::vector< unsigned > & | IntegerMappingForBB, | ||
std::vector< IRInstructionData * > & | InstrListForBB | ||
) |
Maps an Instruction to a legal integer.
[in] | It | - The Instruction to be mapped to an integer. |
[in,out] | IntegerMappingForBB | - Vector of unsigned integers to append to. |
[in,out] | InstrListForBB | - Vector of InstructionData to append to. |
It
was mapped to. Definition at line 322 of file IRSimilarityIdentifier.cpp.
References AddedIllegalLastTime, allocateIRInstructionData(), assert(), BasicBlockToInteger, CanCombineWithPrevInstr, EnableMatchCallsByName, HaveLegalRange, IDL, IllegalInstrNumber, InstructionIntegerMap, and LegalInstrNumber.
Referenced by convertToUnsignedVec().
bool llvm::IRSimilarity::IRInstructionMapper::AddedIllegalLastTime = false |
Set if we added an illegal number in the previous step.
Since each illegal number is unique, we only need one of them between each range of legal numbers. This lets us make sure we don't add more than one illegal number per range.
Definition at line 402 of file IRSimilarityIdentifier.h.
Referenced by convertToUnsignedVec(), mapToIllegalUnsigned(), and mapToLegalUnsigned().
DenseMap<BasicBlock *, unsigned> llvm::IRSimilarity::IRInstructionMapper::BasicBlockToInteger |
A mapping for a basic block in a module to its assigned number/location in the module.
Definition at line 396 of file IRSimilarityIdentifier.h.
Referenced by initializeForBBs(), and mapToLegalUnsigned().
bool llvm::IRSimilarity::IRInstructionMapper::CanCombineWithPrevInstr = false |
Marks whether we found a illegal instruction in the previous step.
Definition at line 405 of file IRSimilarityIdentifier.h.
Referenced by mapToIllegalUnsigned(), and mapToLegalUnsigned().
bool llvm::IRSimilarity::IRInstructionMapper::EnableMatchCallsByName = false |
Marks whether we should use exact function names, as well as types to find similarity between calls.
Definition at line 413 of file IRSimilarityIdentifier.h.
Referenced by llvm::IRSimilarity::IRSimilarityIdentifier::findSimilarity(), and mapToLegalUnsigned().
bool llvm::IRSimilarity::IRInstructionMapper::HaveLegalRange = false |
Marks whether we have found a set of instructions that is long enough to be considered for similarity.
Definition at line 409 of file IRSimilarityIdentifier.h.
Referenced by mapToLegalUnsigned().
IRInstructionDataList* llvm::IRSimilarity::IRInstructionMapper::IDL = nullptr |
Definition at line 449 of file IRSimilarityIdentifier.h.
Referenced by allocateIRInstructionData(), convertToUnsignedVec(), IRInstructionMapper(), mapToIllegalUnsigned(), and mapToLegalUnsigned().
SpecificBumpPtrAllocator<IRInstructionDataList>* llvm::IRSimilarity::IRInstructionMapper::IDLAllocator = nullptr |
This allocator pointer is in charge of creating the IRInstructionDataList so it is not deallocated until whatever external tool is using it is done with the information.
Definition at line 423 of file IRSimilarityIdentifier.h.
Referenced by allocateIRInstructionDataList(), and IRInstructionMapper().
The starting illegal instruction number to map to.
Set to -3 for compatibility with DenseMapInfo<unsigned>.
Definition at line 385 of file IRSimilarityIdentifier.h.
Referenced by createCandidatesFromSuffixTree(), mapToIllegalUnsigned(), and mapToLegalUnsigned().
InstructionClassification llvm::IRSimilarity::IRInstructionMapper::InstClassifier |
Maps an Instruction to a member of InstrType.
Definition at line 609 of file IRSimilarityIdentifier.h.
Referenced by convertToUnsignedVec(), and llvm::IRSimilarity::IRSimilarityIdentifier::findSimilarity().
SpecificBumpPtrAllocator<IRInstructionData>* llvm::IRSimilarity::IRInstructionMapper::InstDataAllocator = nullptr |
This allocator pointer is in charge of holding on to the IRInstructionData so it is not deallocated until whatever external tool is using it is done with the information.
Definition at line 418 of file IRSimilarityIdentifier.h.
Referenced by allocateIRInstructionData().
DenseMap<IRInstructionData *, unsigned, IRInstructionDataTraits> llvm::IRSimilarity::IRInstructionMapper::InstructionIntegerMap |
Correspondence from IRInstructionData to unsigned integers.
Definition at line 392 of file IRSimilarityIdentifier.h.
Referenced by mapToLegalUnsigned().
unsigned llvm::IRSimilarity::IRInstructionMapper::LegalInstrNumber = 0 |
The next available integer to assign to a legal Instruction to.
Definition at line 388 of file IRSimilarityIdentifier.h.
Referenced by mapToIllegalUnsigned(), and mapToLegalUnsigned().