capstone2llvmir/x86: #891, better FXTRACT implementation

This commit is contained in:
Peter Matula 2020-12-11 18:09:02 +01:00
parent 9c389719e4
commit 89959d7fd3
3 changed files with 18 additions and 15 deletions

View File

@ -1564,14 +1564,15 @@ llvm::Function* Capstone2LlvmIrTranslator_impl<CInsn, CInsnOp>::getPseudoAsmFunc
llvm::FunctionType* type,
const std::string& name)
{
auto p = std::make_pair(insn->id, type);
auto n = name.empty() ? getPseudoAsmFunctionName(insn) : name;
auto p = std::make_pair(n, type);
auto fIt = _insn2asmFunctions.find(p);
if (fIt == _insn2asmFunctions.end())
{
auto* fnc = llvm::Function::Create(
type,
llvm::GlobalValue::LinkageTypes::ExternalLinkage,
name.empty() ? getPseudoAsmFunctionName(insn) : name,
n,
_module);
_insn2asmFunctions[p] = fnc;
_asmFunctions.insert(fnc);

View File

@ -620,8 +620,8 @@ class Capstone2LlvmIrTranslator_impl : virtual public Capstone2LlvmIrTranslator
llvm::GlobalValue::LinkageTypes _regLt =
llvm::GlobalValue::LinkageTypes::InternalLinkage;
/// (insn_id, fnc_type) -> fnc
std::map<std::pair<std::size_t, llvm::FunctionType*>, llvm::Function*>
/// (fnc_name, fnc_type) -> fnc
std::map<std::pair<std::string, llvm::FunctionType*>, llvm::Function*>
_insn2asmFunctions;
// The same functions as in the map above, but meant for fast search.
std::set<llvm::Function*> _asmFunctions;

View File

@ -2635,7 +2635,7 @@ void Capstone2LlvmIrTranslatorX86_impl::translateNeg(cs_insn* i, cs_x86* xi, llv
* SMSW, CLTS, INVD, LOCK, RSM, RDMSR, WRMSR, RDPMC, SYSENTER,
* SYSEXIT, XGETBV, LAR, LSL, INVPCID, SLDT, LLDT, SGDT, SIDT, LGDT, LIDT,
* XSAVE, XRSTOR, XSAVEOPT, INVLPG, FLDENV, ARPL,
* STR, FXTRACT,
* STR,
* FWAIT, FNOP
*/
void Capstone2LlvmIrTranslatorX86_impl::translateNop(cs_insn* i, cs_x86* xi, llvm::IRBuilder<>& irb)
@ -5159,18 +5159,20 @@ void Capstone2LlvmIrTranslatorX86_impl::translateFxtract(cs_insn* i, cs_x86* xi,
// call of pseudo function witch parse mantissa and exponent from st(0) because llvm can not
// simply represent this operation by native
static auto* pseudoGetSignificand = llvm::Function::Create(
llvm::FunctionType::get(op0->getType(), llvm::ArrayRef<llvm::Type*>{op0->getType()}, false),
llvm::GlobalValue::LinkageTypes::ExternalLinkage,
"__pseudo_get_significand",
_module);
llvm::Function* pseudoGetSignificand = getPseudoAsmFunction(
i,
op0->getType(),
llvm::ArrayRef<llvm::Type*>{op0->getType()},
"__pseudo_get_significand"
);
auto* mantissa = irb.CreateCall(pseudoGetSignificand, llvm::ArrayRef<llvm::Value*>{op0});
static auto* pseudoGetExponent = llvm::Function::Create(
llvm::FunctionType::get(op0->getType(), llvm::ArrayRef<llvm::Type*>{op0->getType()}, false),
llvm::GlobalValue::LinkageTypes::ExternalLinkage,
"__pseudo_get_exponent",
_module);
llvm::Function* pseudoGetExponent = getPseudoAsmFunction(
i,
op0->getType(),
llvm::ArrayRef<llvm::Type*>{op0->getType()},
"__pseudo_get_exponent"
);
auto* exponent = irb.CreateCall(pseudoGetExponent, llvm::ArrayRef<llvm::Value*>{op0});
storeX87DataReg(irb, top, exponent);