struct IRInstructionData

Declaration

struct IRInstructionData : public ilist_node { /* full declaration omitted */ };

Description

so: This hashing scheme will be used to represent the program as a very long string. This string can then be placed in a data structure which can be used for similarity queries. TODO: Handle types of Instructions which can be equal even with different operands. (E.g. comparisons with swapped predicates.) TODO: Handle CallInsts, which are only checked for function type by \ref isSameOperationAs. TODO: Handle GetElementPtrInsts, as some of the operands have to be the exact same, and some do not.

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

Inherits from: ilist_node

Member Variables

public llvm::Instruction* Inst = nullptr
The source Instruction that is being wrapped.
public SmallVector<llvm::Value*, 4> OperVals
The values of the operands in the Instruction.
The legality of the wrapped instruction. This is informed by InstrType, and is used when checking when two instructions are considered similar. If either instruction is not legal, the instructions are automatically not considered similar.
public Optional<CmpInst::Predicate> RevisedPredicate
This is only relevant if we are wrapping a CmpInst where we needed to change the predicate of a compare instruction from a greater than form to a less than form. It is None otherwise.
public Optional<std::string> CalleeName
This is only relevant if we are wrapping a CallInst. If we are requiring that the function calls have matching names as well as types, and the call is not an indirect call, this will hold the name of the function. If it is an indirect string, it will be the empty string. However, if this requirement is not in place it will be the empty string regardless of the function call type. The value held here is used to create the hash of the instruction, and check to make sure two instructions are close to one another.
public SmallVector<int, 4> RelativeBlockLocations
Taking block_2 as our example, block_1 is "behind" block_2, and block_2 is "ahead" of block_2.
public llvm::IRSimilarity::IRInstructionDataList* IDL = nullptr

Method Overview

Methods

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

Description

Gather the information that is difficult to gather for an Instruction, or is changed. i.e. the operands of an Instruction and the Types of those operands. This extra information allows for similarity matching to make assertions that allow for more flexibility when checking for whether an Instruction performs the same operation.

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

Parameters

llvm::Instruction& I
bool Legality
llvm::IRSimilarity::IRInstructionDataList& IDL

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

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

Parameters

llvm::IRSimilarity::IRInstructionDataList& IDL

llvm::StringRef getCalleeName() const

Description

Get the callee name that the call instruction is using for hashing the instruction. The IRInstructionData must be wrapping a CallInst.

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

CmpInst::Predicate getPredicate() const

Description

Get the predicate that the compare instruction is using for hashing the instruction. the IRInstructionData must be wrapping a CmpInst.

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

void initializeInstruction()

Description

Fills data stuctures for IRInstructionData when it is constructed from a

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

static CmpInst::Predicate predicateForConsistency(
    llvm::CmpInst* CI)

Description

A function that swaps the predicates to their less than form if they are in a greater than form. Otherwise, the predicate is unchanged.

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

Parameters

llvm::CmpInst* CI
- The comparison operation to find a consistent preidcate for.

Returns

the consistent comparison predicate.

void setBranchSuccessors(
    DenseMap<llvm::BasicBlock*, unsigned int>&
        BasicBlockToInteger)

Description

For an IRInstructionData containing a branch, finds the relative distances from the source basic block to the target by taking the difference of the number assigned to the current basic block and the target basic block of the branch.

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

Parameters

DenseMap<llvm::BasicBlock*, unsigned int>& BasicBlockToInteger
- The mapping of basic blocks to their location in the module.

void setCalleeName(bool MatchByName = true)

Description

For an IRInstructionData containing a CallInst, set the function name appropriately. This will be an empty string if it is an indirect call, or we are not matching by name of the called function. It will be the name of the function if \p MatchByName is true and it is not an indirect call. We may decide not to match by name in order to expand the size of the regions we can match. If a function name has the same type signature, but the different name, the region of code is still almost the same. Since function names can be treated as constants, the name itself could be extrapolated away. However, matching by name provides a specificity and more "identical" code than not matching by name.

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

Parameters

bool MatchByName = true
- A flag to mark whether we are using the called function name as a differentiating parameter.

void setPHIPredecessors(
    DenseMap<llvm::BasicBlock*, unsigned int>&
        BasicBlockToInteger)

Description

For an IRInstructionData containing a PHINode, finds the relative distances from the incoming basic block to the current block by taking the difference of the number assigned to the current basic block and the incoming basic block of the branch.

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

Parameters

DenseMap<llvm::BasicBlock*, unsigned int>& BasicBlockToInteger
- The mapping of basic blocks to their location in the module.