retdec
Protected Member Functions | Friends | List of all members
retdec::bin2llvmir::IdiomsCommon Class Reference

Common compiler instruction idioms. More...

#include <idioms_common.h>

Inheritance diagram for retdec::bin2llvmir::IdiomsCommon:
Inheritance graph
[legend]
Collaboration diagram for retdec::bin2llvmir::IdiomsCommon:
Collaboration graph
[legend]

Protected Member Functions

llvm::Instruction * exchangeDivByMinusTwo (llvm::BasicBlock::iterator iter) const
 
llvm::Instruction * exchangeUnsignedModulo2n (llvm::BasicBlock::iterator iter) const
 
llvm::Instruction * exchangeLessThanZero (llvm::BasicBlock::iterator iter) const
 
llvm::Instruction * exchangeGreaterEqualZero (llvm::BasicBlock::iterator iter) const
 
llvm::Instruction * exchangeBitShiftSDiv1 (llvm::BasicBlock::iterator iter) const
 
llvm::Instruction * exchangeBitShiftUDiv (llvm::BasicBlock::iterator iter) const
 
llvm::Instruction * exchangeBitShiftMul (llvm::BasicBlock::iterator iter) const
 
llvm::Instruction * exchangeSignedModulo2n (llvm::BasicBlock::iterator iter) const
 
- Protected Member Functions inherited from retdec::bin2llvmir::IdiomsAbstract
 IdiomsAbstract ()
 
void init (llvm::Module *M, CC_compiler cc, CC_arch arch)
 
CC_compiler getCompiler () const
 
CC_arch getArch () const
 
llvm::Module * getModule () const
 
virtual bool doAnalysis (llvm::Function &, llvm::Pass *)=0
 
virtual ~IdiomsAbstract ()=default
 
bool findBranchDependingOn (llvm::BranchInst **br, llvm::BasicBlock &bb, const llvm::Value *val) const
 

Friends

class IdiomsAnalysis
 

Additional Inherited Members

- Static Protected Member Functions inherited from retdec::bin2llvmir::IdiomsAbstract
static void eraseInstFromBasicBlock (llvm::Value *val, llvm::BasicBlock *bb)
 
static bool isPowerOfTwo (unsigned x)
 
static bool isPowerOfTwoRepresentable (const llvm::ConstantInt *cnst)
 

Detailed Description

Common compiler instruction idioms.

Member Function Documentation

◆ exchangeBitShiftMul()

Instruction * retdec::bin2llvmir::IdiomsCommon::exchangeBitShiftMul ( llvm::BasicBlock::iterator  iter) const
protected

Exchange shift left by with a multiplication

Parameters
itervalue to visit
Returns
replaced Instruction, otherwise nullptr

◆ exchangeBitShiftSDiv1()

Instruction * retdec::bin2llvmir::IdiomsCommon::exchangeBitShiftSDiv1 ( llvm::BasicBlock::iterator  iter) const
protected

Exchange shift right with a division. ((X >> 31) & mask) | (X >> shift)

Parameters
itervalue to visit
Returns
replaced Instruction, otherwise nullptr

◆ exchangeBitShiftUDiv()

Instruction * retdec::bin2llvmir::IdiomsCommon::exchangeBitShiftUDiv ( llvm::BasicBlock::iterator  iter) const
protected

Exchange shift left with a division

Parameters
itervalue to visit
Returns
replaced Instruction, otherwise nullptr

◆ exchangeDivByMinusTwo()

Instruction * retdec::bin2llvmir::IdiomsCommon::exchangeDivByMinusTwo ( llvm::BasicBlock::iterator  iter) const
protected

Exchange -(((lshr(x, 31) + x) >> 1)) with -(x / 2)

Parameters
itervalue to visit
Returns
replaced Instruction, otherwise nullptr

◆ exchangeGreaterEqualZero()

Instruction * retdec::bin2llvmir::IdiomsCommon::exchangeGreaterEqualZero ( llvm::BasicBlock::iterator  iter) const
protected

Exchange: ((X u>> 31) ^ 1) --> X >= 0 ((X ^ -1) u>> 31) --> X >= 0

Parameters
itervalue to visit
Returns
replaced Instruction, otherwise nullptr

◆ exchangeLessThanZero()

Instruction * retdec::bin2llvmir::IdiomsCommon::exchangeLessThanZero ( llvm::BasicBlock::iterator  iter) const
protected

Exchange x u>> 31 with x < 0

Parameters
itervalue to visit
Returns
replaced Instruction, otherwise nullptr

◆ exchangeSignedModulo2n()

Instruction * retdec::bin2llvmir::IdiomsCommon::exchangeSignedModulo2n ( llvm::BasicBlock::iterator  iter) const
protected

◆ exchangeUnsignedModulo2n()

Instruction * retdec::bin2llvmir::IdiomsCommon::exchangeUnsignedModulo2n ( llvm::BasicBlock::iterator  iter) const
protected

Exchange x & (k - 1) with x % k

Parameters
itervalue to visit
Returns
replaced Instruction, otherwise nullptr

Friends And Related Function Documentation

◆ IdiomsAnalysis

friend class IdiomsAnalysis
friend

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