retdec
Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
retdec::llvmir2hll::BasicBlockConverter Class Referencefinal

A converter of LLVM basic blocks. More...

#include <basic_block_converter.h>

Inheritance diagram for retdec::llvmir2hll::BasicBlockConverter:
Inheritance graph
[legend]
Collaboration diagram for retdec::llvmir2hll::BasicBlockConverter:
Collaboration graph
[legend]

Public Member Functions

 BasicBlockConverter (ShPtr< LLVMValueConverter > converter, ShPtr< LabelsHandler > labelsHandler)
 Constructs a new basic block converter. More...
 
ShPtr< Statementconvert (llvm::BasicBlock &bb)
 Converts the given LLVM basic block bb into a sequence of statements in BIR. More...
 

Private Member Functions

bool shouldBeConverted (const llvm::Instruction &inst) const
 Determines whether the given LLVM instruction inst should be converted by BasicBlockConverter. More...
 
ShPtr< StatementconvertInstructionsOf (llvm::BasicBlock &bb)
 Converts instruction of the given LLVM basic block bb into a sequence of statements in BIR. More...
 
ShPtr< StatementvisitCallInst (llvm::CallInst &inst)
 Converts the given LLVM call instruction inst into a statement in BIR. More...
 
ShPtr< StatementvisitInsertValueInst (llvm::InsertValueInst &inst)
 Converts the given LLVM insertvalue instruction inst into two assign statements in BIR. More...
 
ShPtr< StatementvisitLoadInst (llvm::LoadInst &inst)
 Converts the given LLVM load instruction inst into an assign statement in BIR. More...
 
ShPtr< StatementvisitReturnInst (llvm::ReturnInst &inst)
 Converts the given LLVM return instruction inst into a statement in BIR. More...
 
ShPtr< StatementvisitStoreInst (llvm::StoreInst &inst)
 Converts the given LLVM store instruction inst into an assign statement in BIR. More...
 
ShPtr< StatementvisitUnreachableInst (llvm::UnreachableInst &inst)
 Converts the given LLVM unreachable instruction inst into an unreachable statement in BIR. More...
 
ShPtr< StatementvisitInstruction (llvm::Instruction &inst)
 Converts the given LLVM instruction inst into an assign statement in BIR. This method converts other instructions. More...
 
ShPtr< StatementgenerateAssignOfPrevValForInsertValueInst (llvm::InsertValueInst &inst)
 Generates assignment of previous value to aggregate type expression for the given LLVM insertvalue instruction inst. More...
 
- Private Member Functions inherited from retdec::utils::NonCopyable
 NonCopyable (const NonCopyable &)=delete
 
NonCopyableoperator= (const NonCopyable &)=delete
 
 NonCopyable ()=default
 
 ~NonCopyable ()=default
 

Private Attributes

ShPtr< LLVMValueConverterconverter
 A converter from LLVM values to values in BIR. More...
 
ShPtr< LabelsHandlerlabelsHandler
 A handler of labels. More...
 

Friends

class llvm::InstVisitor< BasicBlockConverter, ShPtr< Statement > >
 

Detailed Description

A converter of LLVM basic blocks.

This class converts only not inlinable instructions which are converted into statements.

Constructor & Destructor Documentation

◆ BasicBlockConverter()

retdec::llvmir2hll::BasicBlockConverter::BasicBlockConverter ( ShPtr< LLVMValueConverter converter,
ShPtr< LabelsHandler labelsHandler 
)

Constructs a new basic block converter.

Parameters
[in]converterA converter from LLVM values to values in BIR.
[in]labelsHandlerA handler of labels.

Member Function Documentation

◆ convert()

ShPtr< Statement > retdec::llvmir2hll::BasicBlockConverter::convert ( llvm::BasicBlock &  bb)

Converts the given LLVM basic block bb into a sequence of statements in BIR.

◆ convertInstructionsOf()

ShPtr< Statement > retdec::llvmir2hll::BasicBlockConverter::convertInstructionsOf ( llvm::BasicBlock &  bb)
private

Converts instruction of the given LLVM basic block bb into a sequence of statements in BIR.

◆ generateAssignOfPrevValForInsertValueInst()

ShPtr< Statement > retdec::llvmir2hll::BasicBlockConverter::generateAssignOfPrevValForInsertValueInst ( llvm::InsertValueInst &  inst)
private

Generates assignment of previous value to aggregate type expression for the given LLVM insertvalue instruction inst.

◆ shouldBeConverted()

bool retdec::llvmir2hll::BasicBlockConverter::shouldBeConverted ( const llvm::Instruction &  inst) const
private

Determines whether the given LLVM instruction inst should be converted by BasicBlockConverter.

Following instruction shouldn't be converted:

  • Inlinable instructions - reason is that these instructions are inlined as operands in other instructions.
  • Direct allocations - reason is that variable is created, when it is used for the first time and variable definitions are appended to the beginning of the function for all defined variables.
  • Branch and switch instructions - reason is that branch instructions are handled by StructureConverter.
  • PHI nodes - reason is that PHI nodes have to be converted multiple times, at the end of the basic block which is followed by basic block with PHI node.

◆ visitCallInst()

ShPtr< Statement > retdec::llvmir2hll::BasicBlockConverter::visitCallInst ( llvm::CallInst &  inst)
private

Converts the given LLVM call instruction inst into a statement in BIR.

If function result is used somewhere, an assign statement will be created. Otherwise, a call statement will be created.

◆ visitInsertValueInst()

ShPtr< Statement > retdec::llvmir2hll::BasicBlockConverter::visitInsertValueInst ( llvm::InsertValueInst &  inst)
private

Converts the given LLVM insertvalue instruction inst into two assign statements in BIR.

The reason why this instruction is converted into two statements is that this instruction does two operations: Inserts value to the specified position of the composite and returns new composite with inserted value (original composite remains unchanged).

Example code in LLVM IR:

define void @function([10 x i32] %arr, i32 %value) {
%a = insertvalue [10 x i32] %arr, i32 %value, 3
; ...
}

The example code is converted into following code in BIR:

function(a[10] arr, int value) {
int a[10];
a = arr;
a[3] = value;
// ...
}

◆ visitInstruction()

ShPtr< Statement > retdec::llvmir2hll::BasicBlockConverter::visitInstruction ( llvm::Instruction &  inst)
private

Converts the given LLVM instruction inst into an assign statement in BIR. This method converts other instructions.

◆ visitLoadInst()

ShPtr< Statement > retdec::llvmir2hll::BasicBlockConverter::visitLoadInst ( llvm::LoadInst &  inst)
private

Converts the given LLVM load instruction inst into an assign statement in BIR.

◆ visitReturnInst()

ShPtr< Statement > retdec::llvmir2hll::BasicBlockConverter::visitReturnInst ( llvm::ReturnInst &  inst)
private

Converts the given LLVM return instruction inst into a statement in BIR.

◆ visitStoreInst()

ShPtr< Statement > retdec::llvmir2hll::BasicBlockConverter::visitStoreInst ( llvm::StoreInst &  inst)
private

Converts the given LLVM store instruction inst into an assign statement in BIR.

◆ visitUnreachableInst()

ShPtr< Statement > retdec::llvmir2hll::BasicBlockConverter::visitUnreachableInst ( llvm::UnreachableInst &  inst)
private

Converts the given LLVM unreachable instruction inst into an unreachable statement in BIR.

Friends And Related Function Documentation

◆ llvm::InstVisitor< BasicBlockConverter, ShPtr< Statement > >

friend class llvm::InstVisitor< BasicBlockConverter, ShPtr< Statement > >
friend

Member Data Documentation

◆ converter

ShPtr<LLVMValueConverter> retdec::llvmir2hll::BasicBlockConverter::converter
private

A converter from LLVM values to values in BIR.

◆ labelsHandler

ShPtr<LabelsHandler> retdec::llvmir2hll::BasicBlockConverter::labelsHandler
private

A handler of labels.


The documentation for this class was generated from the following files: