Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimizations #731

Merged
merged 29 commits into from
Apr 7, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
87c6c5e
bin2llvmir: use faster linear symbolic trees in binary decoding phase
PeterMatula Jan 3, 2020
9ac5bb2
bin2llvmir/symbolictree: use the new ctor interface everywhere
PeterMatula Jan 3, 2020
bae7c78
bin2llvmir/symbolyctree: do not record already processed values
PeterMatula Jan 3, 2020
c41d93f
bin2llvmir/symbolictree: unify 2 ctors into 1
PeterMatula Jan 3, 2020
1087b0c
progress
PeterMatula Jan 4, 2020
a76b109
Merge branch 'master' into optimizations
PeterMatula Jan 31, 2020
c25c01d
bin2llvmir/decoder: optmize decoder.
PeterMatula Jan 31, 2020
c30c33e
cmake/options.cmake: fix, add RETDEC_ENABLE_RETDECTOOL option
PeterMatula Jan 31, 2020
e3aba89
bin2llvmir/stack: remove instruction made unused by the analysis
PeterMatula Mar 20, 2020
beb2891
progress
PeterMatula Mar 20, 2020
e92e566
bin2llvmir/fpu: remove operations on fpu top when analysis is done
PeterMatula Mar 21, 2020
8f2c58a
capstone2llvmir/x86: remove all x87 tag reg related operations.
PeterMatula Mar 21, 2020
ccda153
bin2llvmir/cond_br_opt: erase insn unused after the opt
PeterMatula Mar 21, 2020
2330097
bin2llvmir/constants: remove insn unused after opt
PeterMatula Mar 21, 2020
66289f5
bin2llvmir/inst_opt: fix header guard names
PeterMatula Mar 21, 2020
d2452d4
bin2llvmir/rda: add position in BB to defs & uses
PeterMatula Mar 21, 2020
f77d124
bin2llvmir/irmodifier: better implementation of _eraseUnusedInstructi…
PeterMatula Mar 21, 2020
066eb2e
bin2llvmir/rda: collect also ptr2int and gep uses
PeterMatula Mar 22, 2020
b463779
bin2llvmir/value_protect: do not iterate over regs from abi
PeterMatula Mar 22, 2020
9e9ef27
bin2llvmir: add inst_opt_rda pass
PeterMatula Mar 22, 2020
c964c3f
bin2llvmir: fix int covnersions and x86 addr spaces.
PeterMatula Mar 31, 2020
2099369
bin2llvmir: remove unused local_vars analysis
PeterMatula Mar 31, 2020
5c3456f
bin2llvmir/idioms_libgcc: remove reg localization from this pass.
PeterMatula Mar 31, 2020
3254cc0
bin2llvmir/x86_fpu: remove more unused insns
PeterMatula Mar 31, 2020
b69ff63
Merge branch 'master' into optimizations
PeterMatula Apr 6, 2020
cf39921
Merge branch 'master' into stack-remove-unused-insn
PeterMatula Apr 6, 2020
d8119ac
Merge branch 'stack-remove-unused-insn' into optimizations
PeterMatula Apr 6, 2020
5705290
capstone2llvmir: remove unsused variables
PeterMatula Apr 7, 2020
c7dcd74
bin2llvmir: fix doxygen warnings
PeterMatula Apr 7, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
capstone2llvmir/x86: remove all x87 tag reg related operations.
These were not used at all.
  • Loading branch information
PeterMatula committed Mar 21, 2020
commit 8f2c58aba7b2fe7a121973be6569b75863d61739
12 changes: 0 additions & 12 deletions include/retdec/bin2llvmir/providers/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,21 +153,11 @@ class Config
bool isLlvmX87DataStorePseudoFunction(llvm::Value* f);
llvm::CallInst* isLlvmX87DataStorePseudoFunctionCall(llvm::Value* c);

void setLlvmX87TagStorePseudoFunction(llvm::Function* f);
llvm::Function* getLlvmX87TagStorePseudoFunction() const;
bool isLlvmX87TagStorePseudoFunction(llvm::Value* f);
llvm::CallInst* isLlvmX87TagStorePseudoFunctionCall(llvm::Value* c);

void setLlvmX87DataLoadPseudoFunction(llvm::Function* f);
llvm::Function* getLlvmX87DataLoadPseudoFunction() const;
bool isLlvmX87DataLoadPseudoFunction(llvm::Value* f);
llvm::CallInst* isLlvmX87DataLoadPseudoFunctionCall(llvm::Value* c);

void setLlvmX87TagLoadPseudoFunction(llvm::Function* f);
llvm::Function* getLlvmX87TagLoadPseudoFunction() const;
bool isLlvmX87TagLoadPseudoFunction(llvm::Value* f);
llvm::CallInst* isLlvmX87TagLoadPseudoFunctionCall(llvm::Value* c);

llvm::CallInst* isLlvmX87StorePseudoFunctionCall(llvm::Value* c);
llvm::CallInst* isLlvmX87LoadPseudoFunctionCall(llvm::Value* c);

Expand Down Expand Up @@ -204,9 +194,7 @@ class Config
llvm::Function* _condBranchFunction = nullptr;

llvm::Function* _x87DataStoreFunction = nullptr; // void (i3, fp80)
llvm::Function* _x87TagStoreFunction = nullptr; // void (i3, i2)
llvm::Function* _x87DataLoadFunction = nullptr; // fp80 (i3)
llvm::Function* _x87TagLoadFunction = nullptr; // i2 (i3)

std::map<IntrinsicFunctionCreatorPtr, llvm::Function*> _intrinsicFunctions;
std::set<llvm::Function*> _pseudoAsmFunctions;
Expand Down
2 changes: 0 additions & 2 deletions include/retdec/bin2llvmir/providers/names.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ const std::string pseudoReturnFunction = "__pseudo_return";
const std::string pseudoBranchFunction = "__pseudo_branch";
const std::string pseudoCondBranchFunction = "__pseudo_cond_branch";
const std::string pseudoX87dataLoadFunction = "__frontend_reg_load.fpr";
const std::string pseudoX87tagLoadFunction = "__frontend_reg_load.fpu_tag";
const std::string pseudoX87dataStoreFunction = "__frontend_reg_store.fpr";
const std::string pseudoX87tagStoreFunction = "__frontend_reg_store.fpu_tag";

std::string generateFunctionName(common::Address a, bool ida = false);
std::string generateFunctionNameUnknown(common::Address a, bool ida = false);
Expand Down
40 changes: 0 additions & 40 deletions include/retdec/capstone2llvmir/x86/x86.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,26 +42,6 @@ class Capstone2LlvmIrTranslatorX86 : virtual public Capstone2LlvmIrTranslator
*/
virtual llvm::Function* getX87DataStoreFunction() const = 0;

/**
* Is the passed LLVM function @p f the special pseudo function
* whose call represents a store of int value to the x87 fpu stack
* tag slot?
*/
virtual bool isX87TagStoreFunction(llvm::Function* f) const = 0;
/**
* Is the passed LLVM call instruction @p c a special pseudo call
* instruction representing a store of int value to the x87 fpu stack
* tag slot?
*/
virtual bool isX87TagStoreFunctionCall(llvm::CallInst* c) const = 0;
/**
* @return LLVM function used as special pseudo function whose call in
* the translated LLVM IR represents a store of int value (call second
* argument) to the x87 fpu stack tag slot (call first argument).
* Function signature: @code{.cpp} void (i3, i2) @endcode
*/
virtual llvm::Function* getX87TagStoreFunction() const = 0;

/**
* Is the passed LLVM function @p f the special pseudo function
* whose call represents a load of fp value from the x87 fpu stack slot?
Expand All @@ -81,26 +61,6 @@ class Capstone2LlvmIrTranslatorX86 : virtual public Capstone2LlvmIrTranslator
*/
virtual llvm::Function* getX87DataLoadFunction() const = 0;

/**
* Is the passed LLVM function @p f the special pseudo function
* whose call represents a load of int value from the x87 fpu stack
* tag slot?
*/
virtual bool isX87TagLoadFunction(llvm::Function* f) const = 0;
/**
* Is the passed LLVM call instruction @p c a special pseudo call
* instruction representing a load of int value from the x87 fpu stack
* tag slot?
*/
virtual bool isX87TagLoadFunctionCall(llvm::CallInst* c) const = 0;
/**
* @return LLVM function used as special pseudo function whose call in
* the translated LLVM IR represents a load of int value (call return
* value) from the x87 fpu stack tag slot (first argument).
* Function signature: @code{.cpp} i2 (i3) @endcode
*/
virtual llvm::Function* getX87TagLoadFunction() const = 0;

/**
* @return Capstone register that is parent to the specified Capstone
* register @p r. Register can be its own parent.
Expand Down
19 changes: 0 additions & 19 deletions include/retdec/capstone2llvmir/x86/x86_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,25 +106,6 @@ enum x87_reg_control
// reserved 13-15
};

/**
* An FPU tag register addition to @c x86_reg from capstone/x86.h.
* Translator works with tag registers explicitly, but it looks like they
* are not modeled in the original @c x86_reg enum.
* This is intentionally not a strongly typed enum to keep it consistent
* with @c x86_reg enum.
*/
enum x87_reg_tag
{
X87_REG_TAG0 = X87_REG_X + 1,
X87_REG_TAG1,
X87_REG_TAG2,
X87_REG_TAG3,
X87_REG_TAG4,
X87_REG_TAG5,
X87_REG_TAG6,
X87_REG_TAG7
};

/**
* Representation of x86 address spaces.
*
Expand Down
8 changes: 0 additions & 8 deletions src/bin2llvmir/optimizations/decoder/decoder_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,17 +149,9 @@ void Decoder::initEnvironmentPseudoFunctions()
dl->setName(names::pseudoX87dataLoadFunction);
_config->setLlvmX87DataLoadPseudoFunction(dl);

auto* tl = c2lX86->getX87TagLoadFunction();
tl->setName(names::pseudoX87tagLoadFunction);
_config->setLlvmX87TagLoadPseudoFunction(tl);

auto* ds = c2lX86->getX87DataStoreFunction();
ds->setName(names::pseudoX87dataStoreFunction);
_config->setLlvmX87DataStorePseudoFunction(ds);

auto* ts = c2lX86->getX87TagStoreFunction();
ts->setName(names::pseudoX87tagStoreFunction);
_config->setLlvmX87TagStorePseudoFunction(ts);
}
}

Expand Down
8 changes: 2 additions & 6 deletions src/bin2llvmir/optimizations/x87_fpu/x87_fpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,7 @@ bool X87FpuAnalysis::analyzeBb(
auto fIt = topVals.find(callStore->getArgOperand(0));
auto tmp = fIt->second;

auto regBase = _config->isLlvmX87DataStorePseudoFunctionCall(callStore)
? uint32_t(X86_REG_ST0)
: uint32_t(X87_REG_TAG0);
uint32_t regBase = X86_REG_ST0;
// Storing value to an empty stack -> suspicious.
if (tmp == 8) {
tmp = 7;
Expand All @@ -207,9 +205,7 @@ bool X87FpuAnalysis::analyzeBb(
auto fIt = topVals.find(callLoad->getArgOperand(0));
auto tmp = fIt->second;

auto regBase = _config->isLlvmX87DataLoadPseudoFunctionCall(callLoad)
? uint32_t(X86_REG_ST0)
: uint32_t(X87_REG_TAG0);
uint32_t regBase = X86_REG_ST0;
// Loading value from an empty stack -> value may have been placed
// there without us knowing, e.g. return value of some other
// function.
Expand Down
38 changes: 0 additions & 38 deletions src/bin2llvmir/providers/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -588,24 +588,6 @@ llvm::CallInst* Config::isLlvmX87DataStorePseudoFunctionCall(llvm::Value* c)
return cc && cc->getCalledValue() == _x87DataStoreFunction ? cc : nullptr;
}

void Config::setLlvmX87TagStorePseudoFunction(llvm::Function* f)
{
_x87TagStoreFunction = f;
}
llvm::Function* Config::getLlvmX87TagStorePseudoFunction() const
{
return _x87TagStoreFunction;
}
bool Config::isLlvmX87TagStorePseudoFunction(llvm::Value* f)
{
return _x87TagStoreFunction == f;
}
llvm::CallInst* Config::isLlvmX87TagStorePseudoFunctionCall(llvm::Value* c)
{
auto* cc = dyn_cast_or_null<CallInst>(c);
return cc && cc->getCalledValue() == _x87TagStoreFunction ? cc : nullptr;
}

void Config::setLlvmX87DataLoadPseudoFunction(llvm::Function* f)
{
_x87DataLoadFunction = f;
Expand All @@ -624,35 +606,15 @@ llvm::CallInst* Config::isLlvmX87DataLoadPseudoFunctionCall(llvm::Value* c)
return cc && cc->getCalledValue() == _x87DataLoadFunction ? cc : nullptr;
}

void Config::setLlvmX87TagLoadPseudoFunction(llvm::Function* f)
{
_x87TagLoadFunction = f;
}
llvm::Function* Config::getLlvmX87TagLoadPseudoFunction() const
{
return _x87TagLoadFunction;
}
bool Config::isLlvmX87TagLoadPseudoFunction(llvm::Value* f)
{
return _x87TagLoadFunction == f;
}
llvm::CallInst* Config::isLlvmX87TagLoadPseudoFunctionCall(llvm::Value* c)
{
auto* cc = dyn_cast_or_null<CallInst>(c);
return cc && cc->getCalledValue() == _x87TagLoadFunction ? cc : nullptr;
}

llvm::CallInst* Config::isLlvmX87StorePseudoFunctionCall(llvm::Value* c)
{
if (auto* cc = isLlvmX87DataStorePseudoFunctionCall(c)) return cc;
if (auto* cc = isLlvmX87TagStorePseudoFunctionCall(c)) return cc;
return nullptr;
}

llvm::CallInst* Config::isLlvmX87LoadPseudoFunctionCall(llvm::Value* c)
{
if (auto* cc = isLlvmX87DataLoadPseudoFunctionCall(c)) return cc;
if (auto* cc = isLlvmX87TagLoadPseudoFunctionCall(c)) return cc;
return nullptr;
}

Expand Down
Loading