Author: Vedant Kumar Date: 2020-01-31T16:33:12-08:00 New Revision: 009e3e53c1fe4848916a3b7de1dff60a2644fa46
URL: https://github.com/llvm/llvm-project/commit/009e3e53c1fe4848916a3b7de1dff60a2644fa46 DIFF: https://github.com/llvm/llvm-project/commit/009e3e53c1fe4848916a3b7de1dff60a2644fa46.diff LOG: [lldb/MCDisasm] Simplify predicates in MCDisasmInstance, NFC Added: Modified: lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp Removed: ################################################################################ diff --git a/lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp b/lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp index e9399c368e73..ea4b4cde7036 100644 --- a/lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp +++ b/lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp @@ -86,76 +86,18 @@ class InstructionLLVMC : public lldb_private::Instruction { : Instruction(address, addr_class), m_disasm_wp(std::static_pointer_cast<DisassemblerLLVMC>( disasm.shared_from_this())), - m_does_branch(eLazyBoolCalculate), m_has_delay_slot(eLazyBoolCalculate), - m_is_call(eLazyBoolCalculate), m_is_valid(false), m_using_file_addr(false) {} ~InstructionLLVMC() override = default; bool DoesBranch() override { - if (m_does_branch == eLazyBoolCalculate) { - DisassemblerScope disasm(*this); - if (disasm) { - DataExtractor data; - if (m_opcode.GetData(data)) { - bool is_alternate_isa; - lldb::addr_t pc = m_address.GetFileAddress(); - - DisassemblerLLVMC::MCDisasmInstance *mc_disasm_ptr = - GetDisasmToUse(is_alternate_isa, disasm); - const uint8_t *opcode_data = data.GetDataStart(); - const size_t opcode_data_len = data.GetByteSize(); - llvm::MCInst inst; - const size_t inst_size = - mc_disasm_ptr->GetMCInst(opcode_data, opcode_data_len, pc, inst); - // Be conservative, if we didn't understand the instruction, say it - // might branch... - if (inst_size == 0) - m_does_branch = eLazyBoolYes; - else { - const bool can_branch = mc_disasm_ptr->CanBranch(inst); - if (can_branch) - m_does_branch = eLazyBoolYes; - else - m_does_branch = eLazyBoolNo; - } - } - } - } - return m_does_branch == eLazyBoolYes; + VisitInstruction(); + return m_does_branch; } bool HasDelaySlot() override { - if (m_has_delay_slot == eLazyBoolCalculate) { - DisassemblerScope disasm(*this); - if (disasm) { - DataExtractor data; - if (m_opcode.GetData(data)) { - bool is_alternate_isa; - lldb::addr_t pc = m_address.GetFileAddress(); - - DisassemblerLLVMC::MCDisasmInstance *mc_disasm_ptr = - GetDisasmToUse(is_alternate_isa, disasm); - const uint8_t *opcode_data = data.GetDataStart(); - const size_t opcode_data_len = data.GetByteSize(); - llvm::MCInst inst; - const size_t inst_size = - mc_disasm_ptr->GetMCInst(opcode_data, opcode_data_len, pc, inst); - // if we didn't understand the instruction, say it doesn't have a - // delay slot... - if (inst_size == 0) - m_has_delay_slot = eLazyBoolNo; - else { - const bool has_delay_slot = mc_disasm_ptr->HasDelaySlot(inst); - if (has_delay_slot) - m_has_delay_slot = eLazyBoolYes; - else - m_has_delay_slot = eLazyBoolNo; - } - } - } - } - return m_has_delay_slot == eLazyBoolYes; + VisitInstruction(); + return m_has_delay_slot; } DisassemblerLLVMC::MCDisasmInstance *GetDisasmToUse(bool &is_alternate_isa) { @@ -369,14 +311,6 @@ class InstructionLLVMC : public lldb_private::Instruction { } m_mnemonics = std::string(mnemonic_strm.GetString()); return; - } else { - if (m_does_branch == eLazyBoolCalculate) { - const bool can_branch = mc_disasm_ptr->CanBranch(inst); - if (can_branch) - m_does_branch = eLazyBoolYes; - else - m_does_branch = eLazyBoolNo; - } } static RegularExpression s_regex( @@ -866,42 +800,54 @@ class InstructionLLVMC : public lldb_private::Instruction { } bool IsCall() override { - if (m_is_call == eLazyBoolCalculate) { - DisassemblerScope disasm(*this); - if (disasm) { - DataExtractor data; - if (m_opcode.GetData(data)) { - bool is_alternate_isa; - lldb::addr_t pc = m_address.GetFileAddress(); - - DisassemblerLLVMC::MCDisasmInstance *mc_disasm_ptr = - GetDisasmToUse(is_alternate_isa, disasm); - const uint8_t *opcode_data = data.GetDataStart(); - const size_t opcode_data_len = data.GetByteSize(); - llvm::MCInst inst; - const size_t inst_size = - mc_disasm_ptr->GetMCInst(opcode_data, opcode_data_len, pc, inst); - if (inst_size == 0) { - m_is_call = eLazyBoolNo; - } else { - if (mc_disasm_ptr->IsCall(inst)) - m_is_call = eLazyBoolYes; - else - m_is_call = eLazyBoolNo; - } - } - } - } - return m_is_call == eLazyBoolYes; + VisitInstruction(); + return m_is_call; } protected: std::weak_ptr<DisassemblerLLVMC> m_disasm_wp; - LazyBool m_does_branch; - LazyBool m_has_delay_slot; - LazyBool m_is_call; - bool m_is_valid; + + bool m_is_valid = false; bool m_using_file_addr; + bool m_has_visited_instruction = false; + + // Be conservative. If we didn't understand the instruction, say it: + // - Might branch + // - Does not have a delay slot + // - Is not a call + bool m_does_branch = true; + bool m_has_delay_slot = false; + bool m_is_call = false; + + void VisitInstruction() { + if (m_has_visited_instruction) + return; + + DisassemblerScope disasm(*this); + if (!disasm) + return; + + DataExtractor data; + if (!m_opcode.GetData(data)) + return; + + bool is_alternate_isa; + lldb::addr_t pc = m_address.GetFileAddress(); + DisassemblerLLVMC::MCDisasmInstance *mc_disasm_ptr = + GetDisasmToUse(is_alternate_isa, disasm); + const uint8_t *opcode_data = data.GetDataStart(); + const size_t opcode_data_len = data.GetByteSize(); + llvm::MCInst inst; + const size_t inst_size = + mc_disasm_ptr->GetMCInst(opcode_data, opcode_data_len, pc, inst); + if (inst_size == 0) + return; + + m_has_visited_instruction = true; + m_does_branch = mc_disasm_ptr->CanBranch(inst); + m_has_delay_slot = mc_disasm_ptr->HasDelaySlot(inst); + m_is_call = mc_disasm_ptr->IsCall(inst); + } private: DisassemblerLLVMC::MCDisasmInstance * _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits