struct IRInstructionMapper

Declaration

struct IRInstructionMapper { /* full declaration omitted */ };

Description

The numeric string for an individual BasicBlock is terminated by an unique unsigned integer. This prevents data structures which rely on repetition from matching across BasicBlocks. (For example, the SuffixTree.) As a concrete example, if we have the following two BasicBlocks: We may hash the Instructions like this (via IRInstructionData): And produce a "numeric string representation" like so: 1, 1, 2, unique_integer_1, 3, 1, unique_integer_2 TODO: This is very similar to the MachineOutliner, and should be consolidated into the same interface.

Declared at: llvm/include/llvm/Analysis/IRSimilarityIdentifier.h:375

Member Variables

public unsigned int IllegalInstrNumber = static_cast<unsigned int>(-3)
Set to -3 for compatibility with DenseMapInfo <unsigned >.
public unsigned int LegalInstrNumber = 0
The next available integer to assign to a legal Instruction to.
public DenseMap< llvm::IRSimilarity::IRInstructionData*, unsigned int, llvm::IRSimilarity::IRInstructionDataTraits> InstructionIntegerMap
Correspondence from IRInstructionData to unsigned integers.
public DenseMap<llvm::BasicBlock*, unsigned int> BasicBlockToInteger
A mapping for a basic block in a module to its assigned number/location in the module.
public bool 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.
public bool CanCombineWithPrevInstr = false
Marks whether we found a illegal instruction in the previous step.
public bool HaveLegalRange = false
Marks whether we have found a set of instructions that is long enough to be considered for similarity.
public bool EnableMatchCallsByName = false
Marks whether we should use exact function names, as well as types to find similarity between calls.
public SpecificBumpPtrAllocator< llvm::IRSimilarity::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.
public SpecificBumpPtrAllocator< llvm::IRSimilarity::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.
public llvm::IRSimilarity::IRInstructionDataList* IDL = nullptr
public llvm::IRSimilarity::IRInstructionMapper:: InstructionClassification InstClassifier
Maps an Instruction to a member of InstrType.

Method Overview

  • public IRInstructionMapper(SpecificBumpPtrAllocator<llvm::IRSimilarity::IRInstructionData> * IDA, SpecificBumpPtrAllocator<llvm::IRSimilarity::IRInstructionDataList> * IDLA)
  • public llvm::IRSimilarity::IRInstructionData * allocateIRInstructionData(llvm::Instruction & I, bool Legality, llvm::IRSimilarity::IRInstructionDataList & IDL)
  • public llvm::IRSimilarity::IRInstructionData * allocateIRInstructionData(llvm::IRSimilarity::IRInstructionDataList & IDL)
  • public llvm::IRSimilarity::IRInstructionDataList * allocateIRInstructionDataList()
  • public void convertToUnsignedVec(llvm::BasicBlock & BB, std::vector<IRInstructionData *> & InstrList, std::vector<unsigned int> & IntegerMapping)
  • public void initializeForBBs(llvm::Function & F, unsigned int & BBNumber)
  • public void initializeForBBs(llvm::Module & M)
  • public unsigned int mapToIllegalUnsigned(BasicBlock::iterator & It, std::vector<unsigned int> & IntegerMappingForBB, std::vector<IRInstructionData *> & InstrListForBB, bool End = false)
  • public unsigned int mapToLegalUnsigned(BasicBlock::iterator & It, std::vector<unsigned int> & IntegerMappingForBB, std::vector<IRInstructionData *> & InstrListForBB)

Methods

IRInstructionMapper(
    SpecificBumpPtrAllocator<
        llvm::IRSimilarity::IRInstructionData>*
        IDA,
    SpecificBumpPtrAllocator<
        llvm::IRSimilarity::
            IRInstructionDataList>* IDLA)

Declared at: llvm/include/llvm/Analysis/IRSimilarityIdentifier.h:498

Parameters

SpecificBumpPtrAllocator< llvm::IRSimilarity::IRInstructionData>* IDA
SpecificBumpPtrAllocator< llvm::IRSimilarity::IRInstructionDataList>* IDLA

llvm::IRSimilarity::IRInstructionData*
allocateIRInstructionData(
    llvm::Instruction& I,
    bool Legality,
    llvm::IRSimilarity::IRInstructionDataList&
        IDL)

Description

Get an allocated IRInstructionData struct using the InstDataAllocator.

Declared at: llvm/include/llvm/Analysis/IRSimilarityIdentifier.h:427

Parameters

llvm::Instruction& I
- The Instruction to wrap with IRInstructionData.
bool Legality
- A boolean value that is true if the instruction is to be considered for similarity, and false if not.
llvm::IRSimilarity::IRInstructionDataList& IDL
- The InstructionDataList that the IRInstructionData is inserted into.

Returns

An allocated IRInstructionData struct.

llvm::IRSimilarity::IRInstructionData*
allocateIRInstructionData(
    llvm::IRSimilarity::IRInstructionDataList&
        IDL)

Description

Get an empty allocated IRInstructionData struct using the InstDataAllocator.

Declared at: llvm/include/llvm/Analysis/IRSimilarityIdentifier.h:436

Parameters

llvm::IRSimilarity::IRInstructionDataList& IDL
- The InstructionDataList that the IRInstructionData is inserted into.

Returns

An allocated IRInstructionData struct.

llvm::IRSimilarity::IRInstructionDataList*
allocateIRInstructionDataList()

Description

Get an allocated IRInstructionDataList object using the IDLAllocator.

Declared at: llvm/include/llvm/Analysis/IRSimilarityIdentifier.h:441

Returns

An allocated IRInstructionDataList object.

void convertToUnsignedVec(
    llvm::BasicBlock& BB,
    std::vector<IRInstructionData*>& InstrList,
    std::vector<unsigned int>& IntegerMapping)

Description

Maps the Instructions in a BasicBlock \p BB to legal or illegal integers determined by \p InstrType. Two Instructions are mapped to the same value if they are close as defined by the InstructionData class above.

Declared at: llvm/include/llvm/Analysis/IRSimilarityIdentifier.h:470

Parameters

llvm::BasicBlock& BB
- The BasicBlock to be mapped to integers.
std::vector<IRInstructionData*>& InstrList
- Vector of IRInstructionData to append to.
std::vector<unsigned int>& IntegerMapping
- Vector of unsigned integers to append to.

void initializeForBBs(llvm::Function& F,
                      unsigned int& BBNumber)

Description

Assigns values to all the basic blocks in function \p F starting from integer \p BBNumber.

Declared at: llvm/include/llvm/Analysis/IRSimilarityIdentifier.h:450

Parameters

llvm::Function& F
- The function containing the basic blocks to assign numbers to.
unsigned int& BBNumber
- The number to start from.

void initializeForBBs(llvm::Module& M)

Description

Assigns values to all the basic blocks in Module \p M.

Declared at: llvm/include/llvm/Analysis/IRSimilarityIdentifier.h:457

Parameters

llvm::Module& M
- The module containing the basic blocks to assign numbers to.

unsigned int mapToIllegalUnsigned(
    BasicBlock::iterator& It,
    std::vector<unsigned int>&
        IntegerMappingForBB,
    std::vector<IRInstructionData*>&
        InstrListForBB,
    bool End = false)

Description

Maps an Instruction to an illegal integer.

Declared at: llvm/include/llvm/Analysis/IRSimilarityIdentifier.h:494

Parameters

BasicBlock::iterator& It
- The \p Instruction to be mapped to an integer.
std::vector<unsigned int>& IntegerMappingForBB
- Vector of unsigned integers to append to.
std::vector<IRInstructionData*>& InstrListForBB
- Vector of IRInstructionData to append to.
bool End = false
- true if creating a dummy IRInstructionData at the end of a basic block.

Returns

The integer \p It was mapped to.

unsigned int mapToLegalUnsigned(
    BasicBlock::iterator& It,
    std::vector<unsigned int>&
        IntegerMappingForBB,
    std::vector<IRInstructionData*>&
        InstrListForBB)

Description

Maps an Instruction to a legal integer.

Declared at: llvm/include/llvm/Analysis/IRSimilarityIdentifier.h:481

Parameters

BasicBlock::iterator& It
- The Instruction to be mapped to an integer.
std::vector<unsigned int>& IntegerMappingForBB
- Vector of unsigned integers to append to.
std::vector<IRInstructionData*>& InstrListForBB
- Vector of InstructionData to append to.

Returns

The integer \p It was mapped to.