Skip to content

Commit 92ff5df

Browse files
committed
fixup: De-duplicate MemoryMatchesIRElementOrder by plumbing in exe_ctx
This is a separate commit because it's a fairly noisy change. It'll be squashed into the previous commit before landing
1 parent be4ddf4 commit 92ff5df

File tree

1 file changed

+47
-53
lines changed

1 file changed

+47
-53
lines changed

lldb/source/Expression/IRInterpreter.cpp

Lines changed: 47 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -136,17 +136,6 @@ class InterpreterStackFrame {
136136

137137
~InterpreterStackFrame() = default;
138138

139-
bool MemoryMatchesIRElementOrder() {
140-
lldb::TargetSP target_sp = m_execution_unit.GetTarget();
141-
if (target_sp) {
142-
const auto *arch_plugin = target_sp->GetArchitecturePlugin();
143-
if (arch_plugin) {
144-
return arch_plugin->GetVectorElementOrder() == lldb::eByteOrderLittle;
145-
}
146-
}
147-
return true;
148-
}
149-
150139
void Jump(const BasicBlock *bb) {
151140
m_prev_bb = m_bb;
152141
m_bb = bb;
@@ -185,7 +174,7 @@ class InterpreterStackFrame {
185174
}
186175

187176
bool EvaluateValue(lldb_private::Scalar &scalar, const Value *value,
188-
Module &module) {
177+
Module &module, lldb_private::ExecutionContext &exe_ctx) {
189178
const Constant *constant = dyn_cast<Constant>(value);
190179

191180
if (constant) {
@@ -209,7 +198,7 @@ class InterpreterStackFrame {
209198
return AssignToMatchType(scalar, value_apint, value->getType());
210199
}
211200

212-
lldb::addr_t process_address = ResolveValue(value, module);
201+
lldb::addr_t process_address = ResolveValue(value, module, exe_ctx);
213202
size_t value_size = m_target_data.getTypeStoreSize(value->getType());
214203

215204
lldb_private::DataExtractor value_extractor;
@@ -241,8 +230,8 @@ class InterpreterStackFrame {
241230
}
242231

243232
bool AssignValue(const Value *value, lldb_private::Scalar scalar,
244-
Module &module) {
245-
lldb::addr_t process_address = ResolveValue(value, module);
233+
Module &module, lldb_private::ExecutionContext &exe_ctx) {
234+
lldb::addr_t process_address = ResolveValue(value, module, exe_ctx);
246235

247236
if (process_address == LLDB_INVALID_ADDRESS)
248237
return false;
@@ -391,7 +380,8 @@ class InterpreterStackFrame {
391380
}
392381

393382
bool ResolveVectorConstant(lldb::addr_t process_address,
394-
const Constant *constant) {
383+
const Constant *constant,
384+
lldb_private::ExecutionContext &exe_ctx) {
395385
auto *vector_type = dyn_cast<FixedVectorType>(constant->getType());
396386
if (!vector_type)
397387
return false;
@@ -400,7 +390,7 @@ class InterpreterStackFrame {
400390
unsigned num_elements = vector_type->getNumElements();
401391
size_t element_size = m_target_data.getTypeStoreSize(element_type);
402392
size_t total_size = element_size * num_elements;
403-
bool reverse_elements = !MemoryMatchesIRElementOrder();
393+
bool reverse_elements = !MemoryMatchesIRElementOrder(exe_ctx);
404394

405395
lldb_private::DataBufferHeap buf(total_size, 0);
406396
uint8_t *data_ptr = buf.GetBytes();
@@ -442,11 +432,12 @@ class InterpreterStackFrame {
442432
return false;
443433
}
444434

445-
bool ResolveConstant(lldb::addr_t process_address, const Constant *constant) {
435+
bool ResolveConstant(lldb::addr_t process_address, const Constant *constant,
436+
lldb_private::ExecutionContext &exe_ctx) {
446437
// Handle vector constants specially since they can't be represented as a
447438
// single APInt
448439
if (constant->getType()->isVectorTy()) {
449-
return ResolveVectorConstant(process_address, constant);
440+
return ResolveVectorConstant(process_address, constant, exe_ctx);
450441
}
451442

452443
APInt resolved_value;
@@ -517,7 +508,8 @@ class InterpreterStackFrame {
517508
return std::string(ss.GetString());
518509
}
519510

520-
lldb::addr_t ResolveValue(const Value *value, Module &module) {
511+
lldb::addr_t ResolveValue(const Value *value, Module &module,
512+
lldb_private::ExecutionContext &exe_ctx) {
521513
ValueMap::iterator i = m_values.find(value);
522514

523515
if (i != m_values.end())
@@ -528,7 +520,7 @@ class InterpreterStackFrame {
528520
lldb::addr_t data_address = Malloc(value->getType());
529521

530522
if (const Constant *constant = dyn_cast<Constant>(value)) {
531-
if (!ResolveConstant(data_address, constant)) {
523+
if (!ResolveConstant(data_address, constant, exe_ctx)) {
532524
lldb_private::Status free_error;
533525
m_execution_unit.Free(data_address, free_error);
534526
return LLDB_INVALID_ADDRESS;
@@ -906,13 +898,13 @@ bool IRInterpreter::Interpret(llvm::Module &module, llvm::Function &function,
906898
lldb_private::Scalar L;
907899
lldb_private::Scalar R;
908900

909-
if (!frame.EvaluateValue(L, lhs, module)) {
901+
if (!frame.EvaluateValue(L, lhs, module, exe_ctx)) {
910902
LLDB_LOGF(log, "Couldn't evaluate %s", PrintValue(lhs).c_str());
911903
error = lldb_private::Status::FromErrorString(bad_value_error);
912904
return false;
913905
}
914906

915-
if (!frame.EvaluateValue(R, rhs, module)) {
907+
if (!frame.EvaluateValue(R, rhs, module, exe_ctx)) {
916908
LLDB_LOGF(log, "Couldn't evaluate %s", PrintValue(rhs).c_str());
917909
error = lldb_private::Status::FromErrorString(bad_value_error);
918910
return false;
@@ -979,7 +971,7 @@ bool IRInterpreter::Interpret(llvm::Module &module, llvm::Function &function,
979971
break;
980972
}
981973

982-
frame.AssignValue(inst, result, module);
974+
frame.AssignValue(inst, result, module, exe_ctx);
983975

984976
if (log) {
985977
LLDB_LOGF(log, "Interpreted a %s", inst->getOpcodeName());
@@ -1054,13 +1046,13 @@ bool IRInterpreter::Interpret(llvm::Module &module, llvm::Function &function,
10541046

10551047
lldb_private::Scalar S;
10561048

1057-
if (!frame.EvaluateValue(S, source, module)) {
1049+
if (!frame.EvaluateValue(S, source, module, exe_ctx)) {
10581050
LLDB_LOGF(log, "Couldn't evaluate %s", PrintValue(source).c_str());
10591051
error = lldb_private::Status::FromErrorString(bad_value_error);
10601052
return false;
10611053
}
10621054

1063-
frame.AssignValue(inst, S, module);
1055+
frame.AssignValue(inst, S, module, exe_ctx);
10641056
} break;
10651057
case Instruction::SExt: {
10661058
const CastInst *cast_inst = cast<CastInst>(inst);
@@ -1069,7 +1061,7 @@ bool IRInterpreter::Interpret(llvm::Module &module, llvm::Function &function,
10691061

10701062
lldb_private::Scalar S;
10711063

1072-
if (!frame.EvaluateValue(S, source, module)) {
1064+
if (!frame.EvaluateValue(S, source, module, exe_ctx)) {
10731065
LLDB_LOGF(log, "Couldn't evaluate %s", PrintValue(source).c_str());
10741066
error = lldb_private::Status::FromErrorString(bad_value_error);
10751067
return false;
@@ -1079,7 +1071,7 @@ bool IRInterpreter::Interpret(llvm::Module &module, llvm::Function &function,
10791071

10801072
lldb_private::Scalar S_signextend(S.SLongLong());
10811073

1082-
frame.AssignValue(inst, S_signextend, module);
1074+
frame.AssignValue(inst, S_signextend, module, exe_ctx);
10831075
} break;
10841076
case Instruction::Br: {
10851077
const BranchInst *br_inst = cast<BranchInst>(inst);
@@ -1089,7 +1081,7 @@ bool IRInterpreter::Interpret(llvm::Module &module, llvm::Function &function,
10891081

10901082
lldb_private::Scalar C;
10911083

1092-
if (!frame.EvaluateValue(C, condition, module)) {
1084+
if (!frame.EvaluateValue(C, condition, module, exe_ctx)) {
10931085
LLDB_LOGF(log, "Couldn't evaluate %s", PrintValue(condition).c_str());
10941086
error = lldb_private::Status::FromErrorString(bad_value_error);
10951087
return false;
@@ -1127,12 +1119,12 @@ bool IRInterpreter::Interpret(llvm::Module &module, llvm::Function &function,
11271119

11281120
Value *value = phi_inst->getIncomingValueForBlock(frame.m_prev_bb);
11291121
lldb_private::Scalar result;
1130-
if (!frame.EvaluateValue(result, value, module)) {
1122+
if (!frame.EvaluateValue(result, value, module, exe_ctx)) {
11311123
LLDB_LOGF(log, "Couldn't evaluate %s", PrintValue(value).c_str());
11321124
error = lldb_private::Status::FromErrorString(bad_value_error);
11331125
return false;
11341126
}
1135-
frame.AssignValue(inst, result, module);
1127+
frame.AssignValue(inst, result, module, exe_ctx);
11361128

11371129
if (log) {
11381130
LLDB_LOGF(log, "Interpreted a %s", inst->getOpcodeName());
@@ -1148,7 +1140,7 @@ bool IRInterpreter::Interpret(llvm::Module &module, llvm::Function &function,
11481140

11491141
lldb_private::Scalar P;
11501142

1151-
if (!frame.EvaluateValue(P, pointer_operand, module)) {
1143+
if (!frame.EvaluateValue(P, pointer_operand, module, exe_ctx)) {
11521144
LLDB_LOGF(log, "Couldn't evaluate %s",
11531145
PrintValue(pointer_operand).c_str());
11541146
error = lldb_private::Status::FromErrorString(bad_value_error);
@@ -1170,7 +1162,7 @@ bool IRInterpreter::Interpret(llvm::Module &module, llvm::Function &function,
11701162
if (!constant_index) {
11711163
lldb_private::Scalar I;
11721164

1173-
if (!frame.EvaluateValue(I, *ii, module)) {
1165+
if (!frame.EvaluateValue(I, *ii, module, exe_ctx)) {
11741166
LLDB_LOGF(log, "Couldn't evaluate %s", PrintValue(*ii).c_str());
11751167
error = lldb_private::Status::FromErrorString(bad_value_error);
11761168
return false;
@@ -1191,7 +1183,7 @@ bool IRInterpreter::Interpret(llvm::Module &module, llvm::Function &function,
11911183

11921184
lldb_private::Scalar Poffset = P + offset;
11931185

1194-
frame.AssignValue(inst, Poffset, module);
1186+
frame.AssignValue(inst, Poffset, module, exe_ctx);
11951187

11961188
if (log) {
11971189
LLDB_LOGF(log, "Interpreted a GetElementPtrInst");
@@ -1212,13 +1204,13 @@ bool IRInterpreter::Interpret(llvm::Module &module, llvm::Function &function,
12121204
lldb_private::Scalar L;
12131205
lldb_private::Scalar R;
12141206

1215-
if (!frame.EvaluateValue(L, lhs, module)) {
1207+
if (!frame.EvaluateValue(L, lhs, module, exe_ctx)) {
12161208
LLDB_LOGF(log, "Couldn't evaluate %s", PrintValue(lhs).c_str());
12171209
error = lldb_private::Status::FromErrorString(bad_value_error);
12181210
return false;
12191211
}
12201212

1221-
if (!frame.EvaluateValue(R, rhs, module)) {
1213+
if (!frame.EvaluateValue(R, rhs, module, exe_ctx)) {
12221214
LLDB_LOGF(log, "Couldn't evaluate %s", PrintValue(rhs).c_str());
12231215
error = lldb_private::Status::FromErrorString(bad_value_error);
12241216
return false;
@@ -1291,7 +1283,7 @@ bool IRInterpreter::Interpret(llvm::Module &module, llvm::Function &function,
12911283
break;
12921284
}
12931285

1294-
frame.AssignValue(inst, result, module);
1286+
frame.AssignValue(inst, result, module, exe_ctx);
12951287

12961288
if (log) {
12971289
LLDB_LOGF(log, "Interpreted an ICmpInst");
@@ -1307,13 +1299,13 @@ bool IRInterpreter::Interpret(llvm::Module &module, llvm::Function &function,
13071299

13081300
lldb_private::Scalar I;
13091301

1310-
if (!frame.EvaluateValue(I, src_operand, module)) {
1302+
if (!frame.EvaluateValue(I, src_operand, module, exe_ctx)) {
13111303
LLDB_LOGF(log, "Couldn't evaluate %s", PrintValue(src_operand).c_str());
13121304
error = lldb_private::Status::FromErrorString(bad_value_error);
13131305
return false;
13141306
}
13151307

1316-
frame.AssignValue(inst, I, module);
1308+
frame.AssignValue(inst, I, module, exe_ctx);
13171309

13181310
if (log) {
13191311
LLDB_LOGF(log, "Interpreted an IntToPtr");
@@ -1328,13 +1320,13 @@ bool IRInterpreter::Interpret(llvm::Module &module, llvm::Function &function,
13281320

13291321
lldb_private::Scalar I;
13301322

1331-
if (!frame.EvaluateValue(I, src_operand, module)) {
1323+
if (!frame.EvaluateValue(I, src_operand, module, exe_ctx)) {
13321324
LLDB_LOGF(log, "Couldn't evaluate %s", PrintValue(src_operand).c_str());
13331325
error = lldb_private::Status::FromErrorString(bad_value_error);
13341326
return false;
13351327
}
13361328

1337-
frame.AssignValue(inst, I, module);
1329+
frame.AssignValue(inst, I, module, exe_ctx);
13381330

13391331
if (log) {
13401332
LLDB_LOGF(log, "Interpreted a PtrToInt");
@@ -1349,13 +1341,13 @@ bool IRInterpreter::Interpret(llvm::Module &module, llvm::Function &function,
13491341

13501342
lldb_private::Scalar I;
13511343

1352-
if (!frame.EvaluateValue(I, src_operand, module)) {
1344+
if (!frame.EvaluateValue(I, src_operand, module, exe_ctx)) {
13531345
LLDB_LOGF(log, "Couldn't evaluate %s", PrintValue(src_operand).c_str());
13541346
error = lldb_private::Status::FromErrorString(bad_value_error);
13551347
return false;
13561348
}
13571349

1358-
frame.AssignValue(inst, I, module);
1350+
frame.AssignValue(inst, I, module, exe_ctx);
13591351

13601352
if (log) {
13611353
LLDB_LOGF(log, "Interpreted a Trunc");
@@ -1374,8 +1366,8 @@ bool IRInterpreter::Interpret(llvm::Module &module, llvm::Function &function,
13741366

13751367
const Value *pointer_operand = load_inst->getPointerOperand();
13761368

1377-
lldb::addr_t D = frame.ResolveValue(load_inst, module);
1378-
lldb::addr_t P = frame.ResolveValue(pointer_operand, module);
1369+
lldb::addr_t D = frame.ResolveValue(load_inst, module, exe_ctx);
1370+
lldb::addr_t P = frame.ResolveValue(pointer_operand, module, exe_ctx);
13791371

13801372
if (D == LLDB_INVALID_ADDRESS) {
13811373
LLDB_LOGF(log, "LoadInst's value doesn't resolve to anything");
@@ -1443,8 +1435,8 @@ bool IRInterpreter::Interpret(llvm::Module &module, llvm::Function &function,
14431435
const Value *value_operand = store_inst->getValueOperand();
14441436
const Value *pointer_operand = store_inst->getPointerOperand();
14451437

1446-
lldb::addr_t D = frame.ResolveValue(value_operand, module);
1447-
lldb::addr_t P = frame.ResolveValue(pointer_operand, module);
1438+
lldb::addr_t D = frame.ResolveValue(value_operand, module, exe_ctx);
1439+
lldb::addr_t P = frame.ResolveValue(pointer_operand, module, exe_ctx);
14481440

14491441
if (D == LLDB_INVALID_ADDRESS) {
14501442
LLDB_LOGF(log, "StoreInst's value doesn't resolve to anything");
@@ -1537,7 +1529,7 @@ bool IRInterpreter::Interpret(llvm::Module &module, llvm::Function &function,
15371529
lldb_private::Scalar I;
15381530
const llvm::Value *val = call_inst->getCalledOperand();
15391531

1540-
if (!frame.EvaluateValue(I, val, module)) {
1532+
if (!frame.EvaluateValue(I, val, module, exe_ctx)) {
15411533
error = lldb_private::Status::FromErrorString(
15421534
"unable to get address of function");
15431535
return false;
@@ -1576,7 +1568,7 @@ bool IRInterpreter::Interpret(llvm::Module &module, llvm::Function &function,
15761568

15771569
// Extract the arguments value
15781570
lldb_private::Scalar tmp_op = 0;
1579-
if (!frame.EvaluateValue(tmp_op, arg_op, module)) {
1571+
if (!frame.EvaluateValue(tmp_op, arg_op, module, exe_ctx)) {
15801572
error = lldb_private::Status::FromErrorStringWithFormat(
15811573
"unable to evaluate argument %d", i);
15821574
return false;
@@ -1671,7 +1663,7 @@ bool IRInterpreter::Interpret(llvm::Module &module, llvm::Function &function,
16711663
returnVal = value.GetScalar();
16721664

16731665
// Push the return value as the result
1674-
frame.AssignValue(inst, returnVal, module);
1666+
frame.AssignValue(inst, returnVal, module, exe_ctx);
16751667
}
16761668
} break;
16771669
case Instruction::ExtractElement: {
@@ -1682,7 +1674,8 @@ bool IRInterpreter::Interpret(llvm::Module &module, llvm::Function &function,
16821674
const Value *index_operand = extract_inst->getIndexOperand();
16831675

16841676
// Get the vector address
1685-
lldb::addr_t vector_addr = frame.ResolveValue(vector_operand, module);
1677+
lldb::addr_t vector_addr =
1678+
frame.ResolveValue(vector_operand, module, exe_ctx);
16861679

16871680
if (vector_addr == LLDB_INVALID_ADDRESS) {
16881681
LLDB_LOGF(log, "ExtractElement's vector doesn't resolve to anything");
@@ -1692,7 +1685,7 @@ bool IRInterpreter::Interpret(llvm::Module &module, llvm::Function &function,
16921685

16931686
// Evaluate the index
16941687
lldb_private::Scalar index_scalar;
1695-
if (!frame.EvaluateValue(index_scalar, index_operand, module)) {
1688+
if (!frame.EvaluateValue(index_scalar, index_operand, module, exe_ctx)) {
16961689
LLDB_LOGF(log, "Couldn't evaluate index %s",
16971690
PrintValue(index_operand).c_str());
16981691
error = lldb_private::Status::FromErrorString(bad_value_error);
@@ -1731,7 +1724,8 @@ bool IRInterpreter::Interpret(llvm::Module &module, llvm::Function &function,
17311724
size_t element_offset = target_index * element_size;
17321725

17331726
// Allocate space for the result element
1734-
lldb::addr_t result_addr = frame.ResolveValue(extract_inst, module);
1727+
lldb::addr_t result_addr =
1728+
frame.ResolveValue(extract_inst, module, exe_ctx);
17351729
if (result_addr == LLDB_INVALID_ADDRESS) {
17361730
LLDB_LOGF(log, "ExtractElement's result doesn't resolve to anything");
17371731
error = lldb_private::Status::FromErrorString(bad_value_error);

0 commit comments

Comments
 (0)