Skip to content

Commit

Permalink
Address PR comments: move feature flag if inside loop
Browse files Browse the repository at this point in the history
  • Loading branch information
artemdinaburg committed Dec 16, 2020
1 parent 61cc8f0 commit 1076660
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions lib/Lift.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,39 +212,35 @@ static void DefineNativeToLiftedWrapper(const remill::Arch *arch,
// the spec could feasibly miss some dependencies, and so after optimization,
// we'll be able to observe uses of `__anvill_reg_*` globals, and handle
// them appropriately.
if (FLAGS_feature_inline_asm_for_unspec_registers) {

arch->ForEachRegister([=, &ir](const remill::Register *reg_) {
if (auto reg = reg_->EnclosingRegister(); reg_ == reg) {
std::stringstream ss;
arch->ForEachRegister([=, &ir](const remill::Register *reg_) {
if (auto reg = reg_->EnclosingRegister(); reg_ == reg) {
std::stringstream ss;
const auto reg_ptr = reg->AddressOf(state_ptr, block);

if (FLAGS_feature_inline_asm_for_unspec_registers) {
ss << "# read register " << reg->name;

llvm::InlineAsm *read_reg =
llvm::InlineAsm::get(llvm::FunctionType::get(reg->type, false),
ss.str(), "=r", true /* hasSideEffects */);

const auto reg_ptr = reg->AddressOf(state_ptr, block);
ir.CreateStore(ir.CreateCall(read_reg), reg_ptr);
}
});
} else {

arch->ForEachRegister([=, &ir](const remill::Register *reg_) {
if (auto reg = reg_->EnclosingRegister(); reg_ == reg) {
std::stringstream ss;
} else {
ss << "__anvill_reg_" << reg->name;

const auto reg_name = ss.str();
auto reg_global = module->getGlobalVariable(reg_name);
if (!reg_global) {
reg_global = new llvm::GlobalVariable(
*module, reg->type, false, llvm::GlobalValue::ExternalLinkage,
nullptr, reg_name);
}
auto reg_ptr = reg->AddressOf(state_ptr, block);

ir.CreateStore(ir.CreateLoad(reg_global), reg_ptr);
}
});
}
}
});

// Store the program counter into the state.
auto pc_reg = arch->RegisterByName(arch->ProgramCounterRegisterName());
Expand Down

0 comments on commit 1076660

Please sign in to comment.