retdec
Public Member Functions | Static Public Member Functions | Private Types | Static Private Member Functions | Static Private Attributes | List of all members
retdec::llvmir2hll::LLVMSupport Class Reference

Supportive functions regarding LLVM IR. More...

#include <llvm_support.h>

Collaboration diagram for retdec::llvmir2hll::LLVMSupport:
Collaboration graph
[legend]

Public Member Functions

 LLVMSupport ()=delete
 
 LLVMSupport (const LLVMSupport &)=delete
 
 ~LLVMSupport ()=delete
 
LLVMSupportoperator= (const LLVMSupport &)=delete
 

Static Public Member Functions

static std::size_t getNumberOfUniquePredecessors (llvm::BasicBlock *bb)
 Returns the number of unique predecessors of the given basic block. More...
 
static bool isPredecessorOf (llvm::BasicBlock *pred, llvm::BasicBlock *bb)
 Returns true if pred is a predecessor of bb, false otherwise. More...
 
static bool isInlineAsm (const llvm::Instruction *i)
 Returns true if the given LLVM instruction i is a call to an inline asm chunk, false otherwise. More...
 
static bool isInlinableInst (const llvm::Instruction *i)
 Returns true if the given LLVM instruction i is inlinable, false otherwise. More...
 
static const llvm::AllocaInst * isDirectAlloca (const llvm::Value *v)
 If v is a direct alloca, it returns v converted into an alloca instruction. Otherwise, the null pointer is returned. More...
 
static bool endsWithRetOrUnreach (llvm::BasicBlock *bb, bool indirect=true)
 Returns true if bb (indirectly) ends with a return or an unreachable instruction, false otherwise. More...
 
static bool endWithSameUncondBranch (llvm::BasicBlock *bb1, llvm::BasicBlock *bb2)
 Returns true if both bb1 and bb2 end with an unconditional branch to the same basic block, false otherwise. More...
 
static const llvm::Module * getModuleFromValue (const llvm::Value *v)
 Returns the LLVM module corresponding to the given value v. More...
 
static std::string getBasicBlockLabelPrefix ()
 Returns the used prefix of labels in LLVM IR. More...
 
static bool isBasicBlockLabel (const std::string &str)
 Returns true if str has the format of a basic block's label in LLVM IR, false otherwise. More...
 
static Address getInstAddress (const llvm::Instruction *i)
 Get instruction's ASM address from metadata. More...
 

Private Types

using BasicBlockSet = std::set< llvm::BasicBlock * >
 Set of basic blocks. More...
 

Static Private Member Functions

static bool endsWithRetOrUnreachImpl (llvm::BasicBlock *bb, bool indirect)
 Implementation of endsWithRetOrUnreach(). More...
 

Static Private Attributes

static BasicBlockSet endsWithRetOrUnreachBBSet
 

Detailed Description

Supportive functions regarding LLVM IR.

This class implements the "static helper" (or "library") design pattern (it has just static functions and no instances can be created).

Member Typedef Documentation

◆ BasicBlockSet

using retdec::llvmir2hll::LLVMSupport::BasicBlockSet = std::set<llvm::BasicBlock *>
private

Set of basic blocks.

Constructor & Destructor Documentation

◆ LLVMSupport() [1/2]

retdec::llvmir2hll::LLVMSupport::LLVMSupport ( )
delete

◆ LLVMSupport() [2/2]

retdec::llvmir2hll::LLVMSupport::LLVMSupport ( const LLVMSupport )
delete

◆ ~LLVMSupport()

retdec::llvmir2hll::LLVMSupport::~LLVMSupport ( )
delete

Member Function Documentation

◆ endsWithRetOrUnreach()

bool retdec::llvmir2hll::LLVMSupport::endsWithRetOrUnreach ( llvm::BasicBlock *  bb,
bool  indirect = true 
)
static

Returns true if bb (indirectly) ends with a return or an unreachable instruction, false otherwise.

Parameters
[in]bbBasic block to be examined.
[in]indirectIf true and bb ends with an unconditional branch b, this function is called recursively on the target of b.

This function is not reentrant.

Preconditions
  • bb is non-null

◆ endsWithRetOrUnreachImpl()

bool retdec::llvmir2hll::LLVMSupport::endsWithRetOrUnreachImpl ( llvm::BasicBlock *  bb,
bool  indirect 
)
staticprivate

Implementation of endsWithRetOrUnreach().

It doesn't clear endsWithRetOrUnreachBBSet on return. This function may recursively calls itself. This function is not reentrant.

Preconditions
  • bb is non-null
  • endsWithRetOrUnreachBBSet has been cleared

◆ endWithSameUncondBranch()

bool retdec::llvmir2hll::LLVMSupport::endWithSameUncondBranch ( llvm::BasicBlock *  bb1,
llvm::BasicBlock *  bb2 
)
static

Returns true if both bb1 and bb2 end with an unconditional branch to the same basic block, false otherwise.

◆ getBasicBlockLabelPrefix()

std::string retdec::llvmir2hll::LLVMSupport::getBasicBlockLabelPrefix ( )
static

Returns the used prefix of labels in LLVM IR.

◆ getInstAddress()

Address retdec::llvmir2hll::LLVMSupport::getInstAddress ( const llvm::Instruction *  i)
static

Get instruction's ASM address from metadata.

Returns
Address, or undefined address if metadata entry is not present.
Preconditions
  • i is non-null

◆ getModuleFromValue()

const llvm::Module * retdec::llvmir2hll::LLVMSupport::getModuleFromValue ( const llvm::Value *  v)
static

Returns the LLVM module corresponding to the given value v.

If the module cannot be obtained, this function returns the null pointer.

Preconditions
  • v is non-null

◆ getNumberOfUniquePredecessors()

std::size_t retdec::llvmir2hll::LLVMSupport::getNumberOfUniquePredecessors ( llvm::BasicBlock *  bb)
static

Returns the number of unique predecessors of the given basic block.

Preconditions
  • bb is non-null

◆ isBasicBlockLabel()

bool retdec::llvmir2hll::LLVMSupport::isBasicBlockLabel ( const std::string &  str)
static

Returns true if str has the format of a basic block's label in LLVM IR, false otherwise.

◆ isDirectAlloca()

const llvm::AllocaInst * retdec::llvmir2hll::LLVMSupport::isDirectAlloca ( const llvm::Value *  v)
static

If v is a direct alloca, it returns v converted into an alloca instruction. Otherwise, the null pointer is returned.

Define fixed sized allocas in the entry block as direct variables which are accessed with the & operator.

Preconditions
  • v is non-null

◆ isInlinableInst()

bool retdec::llvmir2hll::LLVMSupport::isInlinableInst ( const llvm::Instruction *  i)
static

Returns true if the given LLVM instruction i is inlinable, false otherwise.

We attempt to inline instructions into their uses to reduce the generated "trees" as much as possible. To do this, we have to consistently decide what is acceptable to inline.

Preconditions
  • i is non-null

◆ isInlineAsm()

bool retdec::llvmir2hll::LLVMSupport::isInlineAsm ( const llvm::Instruction *  i)
static

Returns true if the given LLVM instruction i is a call to an inline asm chunk, false otherwise.

Preconditions
  • i is non-null

◆ isPredecessorOf()

bool retdec::llvmir2hll::LLVMSupport::isPredecessorOf ( llvm::BasicBlock *  pred,
llvm::BasicBlock *  bb 
)
static

Returns true if pred is a predecessor of bb, false otherwise.

Preconditions
  • both pred and bb are non-null

◆ operator=()

LLVMSupport& retdec::llvmir2hll::LLVMSupport::operator= ( const LLVMSupport )
delete

Member Data Documentation

◆ endsWithRetOrUnreachBBSet

LLVMSupport::BasicBlockSet retdec::llvmir2hll::LLVMSupport::endsWithRetOrUnreachBBSet
staticprivate

Set of basic blocks used in endsWithRetOrUnreach(). It is used to prevent endless recursion.


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