<div dir="ltr">I'll let Sean comment on the content of the patch, but please add a test that runs such an expression and demonstrates the correct output.</div><br><div class="gmail_quote"><div dir="ltr">On Thu, Apr 14, 2016 at 10:01 AM Cameron via lldb-commits <<a href="mailto:lldb-commits@lists.llvm.org">lldb-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">cameron314 created this revision.<br>
cameron314 added a reviewer: spyffe.<br>
cameron314 added subscribers: mamai, lldb-commits.<br>
cameron314 set the repository for this revision to rL LLVM.<br>
<br>
This allows expressions such as 'i == 1 || i == 2` to be executed using the IR interpreter.<br>
<br>
Repository:<br>
rL LLVM<br>
<br>
<a href="http://reviews.llvm.org/D19124" rel="noreferrer" target="_blank">http://reviews.llvm.org/D19124</a><br>
<br>
Files:<br>
source/Expression/IRInterpreter.cpp<br>
<br>
Index: source/Expression/IRInterpreter.cpp<br>
===================================================================<br>
--- source/Expression/IRInterpreter.cpp<br>
+++ source/Expression/IRInterpreter.cpp<br>
@@ -106,6 +106,7 @@<br>
DataLayout &m_target_data;<br>
lldb_private::IRExecutionUnit &m_execution_unit;<br>
const BasicBlock *m_bb;<br>
+ const BasicBlock *m_prev_bb;<br>
BasicBlock::const_iterator m_ii;<br>
BasicBlock::const_iterator m_ie;<br>
<br>
@@ -121,7 +122,9 @@<br>
lldb::addr_t stack_frame_bottom,<br>
lldb::addr_t stack_frame_top) :<br>
m_target_data (target_data),<br>
- m_execution_unit (execution_unit)<br>
+ m_execution_unit (execution_unit),<br>
+ m_bb (nullptr),<br>
+ m_prev_bb (nullptr)<br>
{<br>
m_byte_order = (target_data.isLittleEndian() ? lldb::eByteOrderLittle : lldb::eByteOrderBig);<br>
m_addr_byte_size = (target_data.getPointerSize(0));<br>
@@ -137,6 +140,7 @@<br>
<br>
void Jump (const BasicBlock *bb)<br>
{<br>
+ m_prev_bb = m_bb;<br>
m_bb = bb;<br>
m_ii = m_bb->begin();<br>
m_ie = m_bb->end();<br>
@@ -563,6 +567,7 @@<br>
case Instruction::Alloca:<br>
case Instruction::BitCast:<br>
case Instruction::Br:<br>
+ case Instruction::PHI:<br>
break;<br>
case Instruction::Call:<br>
{<br>
@@ -1052,6 +1057,46 @@<br>
}<br>
}<br>
continue;<br>
+ case Instruction::PHI:<br>
+ {<br>
+ const PHINode *phi_inst = dyn_cast<PHINode>(inst);<br>
+<br>
+ if (!phi_inst)<br>
+ {<br>
+ if (log)<br>
+ log->Printf("getOpcode() returns PHI, but instruction is not a PHINode");<br>
+ error.SetErrorToGenericError();<br>
+ error.SetErrorString(interpreter_internal_error);<br>
+ return false;<br>
+ }<br>
+ if (!frame.m_prev_bb)<br>
+ {<br>
+ if (log)<br>
+ log->Printf("Encountered PHI node without having jumped from another basic block");<br>
+ error.SetErrorToGenericError();<br>
+ error.SetErrorString(interpreter_internal_error);<br>
+ return false;<br>
+ }<br>
+<br>
+ Value* value = phi_inst->getIncomingValueForBlock(frame.m_prev_bb);<br>
+ lldb_private::Scalar result;<br>
+ if (!frame.EvaluateValue(result, value, module))<br>
+ {<br>
+ if (log)<br>
+ log->Printf("Couldn't evaluate %s", PrintValue(value).c_str());<br>
+ error.SetErrorToGenericError();<br>
+ error.SetErrorString(bad_value_error);<br>
+ return false;<br>
+ }<br>
+ frame.AssignValue(inst, result, module);<br>
+<br>
+ if (log)<br>
+ {<br>
+ log->Printf("Interpreted a %s", inst->getOpcodeName());<br>
+ log->Printf(" Incoming value : %s", frame.SummarizeValue(value).c_str());<br>
+ }<br>
+ }<br>
+ break;<br>
case Instruction::GetElementPtr:<br>
{<br>
const GetElementPtrInst *gep_inst = dyn_cast<GetElementPtrInst>(inst);<br>
<br>
<br>
_______________________________________________<br>
lldb-commits mailing list<br>
<a href="mailto:lldb-commits@lists.llvm.org" target="_blank">lldb-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits</a><br>
</blockquote></div>