Skip to content

Commit 7914bae

Browse files
authored
Merge pull request #8938 from bnbarham/get-rebranch-compiling
[rebranch] Various changes to get rebranch compiling
2 parents a77673b + 0b4c4c0 commit 7914bae

File tree

14 files changed

+144
-113
lines changed

14 files changed

+144
-113
lines changed

clang/include/clang/CodeGen/SwiftCallingConv.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ class SwiftAggLowering {
8888
/// passed indirectly as an argument
8989
bool shouldPassIndirectly(bool asReturnValue) const;
9090

91+
bool shouldReturnTypedErrorIndirectly() const;
92+
9193
using EnumerationCallback =
9294
llvm::function_ref<void(CharUnits offset, CharUnits end, llvm::Type *type)>;
9395

clang/include/module.modulemap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ module Clang_Basic {
3737
umbrella "clang/Basic"
3838

3939
textual header "clang/Basic/AArch64SVEACLETypes.def"
40+
textual header "clang/Basic/AMDGPUTypes.def"
4041
textual header "clang/Basic/BuiltinsAArch64.def"
4142
textual header "clang/Basic/BuiltinsAMDGPU.def"
4243
textual header "clang/Basic/BuiltinsAArch64NeonSVEBridge.def"

clang/lib/CodeGen/ABIInfo.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,15 @@ bool SwiftABIInfo::shouldPassIndirectly(ArrayRef<llvm::Type *> ComponentTys,
275275
return occupiesMoreThan(ComponentTys, /*total=*/4);
276276
}
277277

278+
bool SwiftABIInfo::shouldReturnTypedErrorIndirectly(
279+
ArrayRef<llvm::Type *> ComponentTys) const {
280+
for (llvm::Type *type : ComponentTys) {
281+
if (!type->isIntegerTy() && !type->isPointerTy())
282+
return true;
283+
}
284+
return shouldPassIndirectly(ComponentTys, /*AsReturnValue=*/true);
285+
}
286+
278287
bool SwiftABIInfo::isLegalVectorType(CharUnits VectorSize, llvm::Type *EltTy,
279288
unsigned NumElts) const {
280289
// The default implementation of this assumes that the target guarantees

clang/lib/CodeGen/ABIInfo.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ class SwiftABIInfo {
153153

154154
/// Returns true if swifterror is lowered to a register by the target ABI.
155155
bool isSwiftErrorInRegister() const { return SwiftErrorInRegister; };
156+
157+
virtual bool
158+
shouldReturnTypedErrorIndirectly(ArrayRef<llvm::Type *> ComponentTys) const;
156159
};
157160
} // end namespace CodeGen
158161
} // end namespace clang

clang/lib/CodeGen/SwiftCallingConv.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,27 @@ bool SwiftAggLowering::shouldPassIndirectly(bool asReturnValue) const {
644644
return getSwiftABIInfo(CGM).shouldPassIndirectly(componentTys, asReturnValue);
645645
}
646646

647+
bool SwiftAggLowering::shouldReturnTypedErrorIndirectly() const {
648+
assert(Finished && "haven't yet finished lowering");
649+
650+
// Empty types don't need to be passed indirectly.
651+
if (Entries.empty())
652+
return false;
653+
654+
// Avoid copying the array of types when there's just a single element.
655+
if (Entries.size() == 1) {
656+
return getSwiftABIInfo(CGM).shouldReturnTypedErrorIndirectly(
657+
Entries.back().Type);
658+
}
659+
660+
SmallVector<llvm::Type *, 8> componentTys;
661+
componentTys.reserve(Entries.size());
662+
for (auto &entry : Entries) {
663+
componentTys.push_back(entry.Type);
664+
}
665+
return getSwiftABIInfo(CGM).shouldReturnTypedErrorIndirectly(componentTys);
666+
}
667+
647668
bool swiftcall::shouldPassIndirectly(CodeGenModule &CGM,
648669
ArrayRef<llvm::Type*> componentTys,
649670
bool asReturnValue) {

clang/lib/Index/IndexRecordHasher.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,10 @@ static hash_code computeHash(const TemplateArgument &Arg,
367367
case TemplateArgument::Integral:
368368
COMBINE_HASH('V', Hasher.hash(Arg.getIntegralType()), Arg.getAsIntegral());
369369
break;
370+
371+
case TemplateArgument::StructuralValue:
372+
// FIXME: Hash structural values
373+
break;
370374
}
371375

372376
return Hash;

lldb/include/lldb/Expression/ExpressionParser.h

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,35 @@ class ExpressionParser {
119119
/// \return
120120
/// An error code indicating the success or failure of the operation.
121121
/// Test with Success().
122-
virtual Status
122+
Status
123123
PrepareForExecution(lldb::addr_t &func_addr, lldb::addr_t &func_end,
124124
std::shared_ptr<IRExecutionUnit> &execution_unit_sp,
125125
ExecutionContext &exe_ctx, bool &can_interpret,
126-
lldb_private::ExecutionPolicy execution_policy) = 0;
126+
lldb_private::ExecutionPolicy execution_policy);
127127

128128
bool GetGenerateDebugInfo() const { return m_generate_debug_info; }
129129

130+
protected:
131+
virtual Status
132+
DoPrepareForExecution(lldb::addr_t &func_addr, lldb::addr_t &func_end,
133+
std::shared_ptr<IRExecutionUnit> &execution_unit_sp,
134+
ExecutionContext &exe_ctx, bool &can_interpret,
135+
lldb_private::ExecutionPolicy execution_policy) = 0;
136+
137+
private:
138+
/// Run all static initializers for an execution unit.
139+
///
140+
/// \param[in] execution_unit_sp
141+
/// The execution unit.
142+
///
143+
/// \param[in] exe_ctx
144+
/// The execution context to use when running them. Thread can't be null.
145+
///
146+
/// \return
147+
/// The error code indicating the
148+
Status RunStaticInitializers(lldb::IRExecutionUnitSP &execution_unit_sp,
149+
ExecutionContext &exe_ctx);
150+
130151
protected:
131152
Expression &m_expr; ///< The expression to be parsed
132153
bool m_generate_debug_info;

lldb/source/Expression/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ add_lldb_library(lldbExpression ${PLUGIN_DEPENDENCY_ARG}
1010
DWARFExpression.cpp
1111
DWARFExpressionList.cpp
1212
Expression.cpp
13+
ExpressionParser.cpp
1314
ExpressionTypeSystemHelper.cpp
1415
ExpressionVariable.cpp
1516
FunctionCaller.cpp
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
//===-- ExpressionParser.cpp ----------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "lldb/Expression/ExpressionParser.h"
10+
#include "lldb/Expression/DiagnosticManager.h"
11+
#include "lldb/Expression/IRExecutionUnit.h"
12+
#include "lldb/Target/ExecutionContext.h"
13+
#include "lldb/Target/ThreadPlanCallFunction.h"
14+
15+
using namespace lldb;
16+
using namespace lldb_private;
17+
18+
Status ExpressionParser::PrepareForExecution(
19+
addr_t &func_addr, addr_t &func_end,
20+
std::shared_ptr<IRExecutionUnit> &execution_unit_sp,
21+
ExecutionContext &exe_ctx, bool &can_interpret,
22+
ExecutionPolicy execution_policy) {
23+
Status status =
24+
DoPrepareForExecution(func_addr, func_end, execution_unit_sp, exe_ctx,
25+
can_interpret, execution_policy);
26+
if (status.Success() && exe_ctx.GetProcessPtr() && exe_ctx.HasThreadScope())
27+
status = RunStaticInitializers(execution_unit_sp, exe_ctx);
28+
29+
return status;
30+
}
31+
32+
Status
33+
ExpressionParser::RunStaticInitializers(IRExecutionUnitSP &execution_unit_sp,
34+
ExecutionContext &exe_ctx) {
35+
Status err;
36+
37+
if (!execution_unit_sp.get()) {
38+
err.SetErrorString(
39+
"can't run static initializers for a NULL execution unit");
40+
return err;
41+
}
42+
43+
if (!exe_ctx.HasThreadScope()) {
44+
err.SetErrorString("can't run static initializers without a thread");
45+
return err;
46+
}
47+
48+
std::vector<addr_t> static_initializers;
49+
50+
execution_unit_sp->GetStaticInitializers(static_initializers);
51+
52+
for (addr_t static_initializer : static_initializers) {
53+
EvaluateExpressionOptions options;
54+
55+
ThreadPlanSP call_static_initializer(new ThreadPlanCallFunction(
56+
exe_ctx.GetThreadRef(), Address(static_initializer), CompilerType(),
57+
llvm::ArrayRef<addr_t>(), options));
58+
59+
DiagnosticManager execution_errors;
60+
ExpressionResults results =
61+
exe_ctx.GetThreadRef().GetProcess()->RunThreadPlan(
62+
exe_ctx, call_static_initializer, options, execution_errors);
63+
64+
if (results != eExpressionCompleted) {
65+
err.SetErrorStringWithFormat("couldn't run static initializer: %s",
66+
execution_errors.GetString().c_str());
67+
return err;
68+
}
69+
}
70+
71+
return err;
72+
}

lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,7 +1296,7 @@ static bool FindFunctionInModule(ConstString &mangled_name,
12961296
return false;
12971297
}
12981298

1299-
lldb_private::Status ClangExpressionParser::PrepareForExecution(
1299+
lldb_private::Status ClangExpressionParser::DoPrepareForExecution(
13001300
lldb::addr_t &func_addr, lldb::addr_t &func_end,
13011301
lldb::IRExecutionUnitSP &execution_unit_sp, ExecutionContext &exe_ctx,
13021302
bool &can_interpret, ExecutionPolicy execution_policy) {
@@ -1472,47 +1472,3 @@ lldb_private::Status ClangExpressionParser::PrepareForExecution(
14721472

14731473
return err;
14741474
}
1475-
1476-
lldb_private::Status ClangExpressionParser::RunStaticInitializers(
1477-
lldb::IRExecutionUnitSP &execution_unit_sp, ExecutionContext &exe_ctx) {
1478-
lldb_private::Status err;
1479-
1480-
lldbassert(execution_unit_sp.get());
1481-
lldbassert(exe_ctx.HasThreadScope());
1482-
1483-
if (!execution_unit_sp.get()) {
1484-
err.SetErrorString(
1485-
"can't run static initializers for a NULL execution unit");
1486-
return err;
1487-
}
1488-
1489-
if (!exe_ctx.HasThreadScope()) {
1490-
err.SetErrorString("can't run static initializers without a thread");
1491-
return err;
1492-
}
1493-
1494-
std::vector<lldb::addr_t> static_initializers;
1495-
1496-
execution_unit_sp->GetStaticInitializers(static_initializers);
1497-
1498-
for (lldb::addr_t static_initializer : static_initializers) {
1499-
EvaluateExpressionOptions options;
1500-
1501-
lldb::ThreadPlanSP call_static_initializer(new ThreadPlanCallFunction(
1502-
exe_ctx.GetThreadRef(), Address(static_initializer), CompilerType(),
1503-
llvm::ArrayRef<lldb::addr_t>(), options));
1504-
1505-
DiagnosticManager execution_errors;
1506-
lldb::ExpressionResults results =
1507-
exe_ctx.GetThreadRef().GetProcess()->RunThreadPlan(
1508-
exe_ctx, call_static_initializer, options, execution_errors);
1509-
1510-
if (results != lldb::eExpressionCompleted) {
1511-
err.SetErrorStringWithFormat("couldn't run static initializer: %s",
1512-
execution_errors.GetString().c_str());
1513-
return err;
1514-
}
1515-
}
1516-
1517-
return err;
1518-
}

lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.h

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -113,24 +113,11 @@ class ClangExpressionParser : public ExpressionParser {
113113
/// \return
114114
/// An error code indicating the success or failure of the operation.
115115
/// Test with Success().
116-
Status
117-
PrepareForExecution(lldb::addr_t &func_addr, lldb::addr_t &func_end,
118-
lldb::IRExecutionUnitSP &execution_unit_sp,
119-
ExecutionContext &exe_ctx, bool &can_interpret,
120-
lldb_private::ExecutionPolicy execution_policy) override;
121-
122-
/// Run all static initializers for an execution unit.
123-
///
124-
/// \param[in] execution_unit_sp
125-
/// The execution unit.
126-
///
127-
/// \param[in] exe_ctx
128-
/// The execution context to use when running them. Thread can't be null.
129-
///
130-
/// \return
131-
/// The error code indicating the
132-
Status RunStaticInitializers(lldb::IRExecutionUnitSP &execution_unit_sp,
133-
ExecutionContext &exe_ctx);
116+
Status DoPrepareForExecution(
117+
lldb::addr_t &func_addr, lldb::addr_t &func_end,
118+
lldb::IRExecutionUnitSP &execution_unit_sp, ExecutionContext &exe_ctx,
119+
bool &can_interpret,
120+
lldb_private::ExecutionPolicy execution_policy) override;
134121

135122
/// Returns a string representing current ABI.
136123
///

lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -698,21 +698,6 @@ bool ClangUserExpression::Parse(DiagnosticManager &diagnostic_manager,
698698
if (!parse_success)
699699
return false;
700700

701-
if (exe_ctx.GetProcessPtr() && execution_policy == eExecutionPolicyTopLevel) {
702-
Status static_init_error =
703-
m_parser->RunStaticInitializers(m_execution_unit_sp, exe_ctx);
704-
705-
if (!static_init_error.Success()) {
706-
const char *error_cstr = static_init_error.AsCString();
707-
if (error_cstr && error_cstr[0])
708-
diagnostic_manager.Printf(lldb::eSeverityError, "%s\n", error_cstr);
709-
else
710-
diagnostic_manager.PutString(lldb::eSeverityError,
711-
"couldn't run static initializers\n");
712-
return false;
713-
}
714-
}
715-
716701
if (m_execution_unit_sp) {
717702
bool register_execution_unit = false;
718703

lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserSwift.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ class DWARFASTParserSwift : public lldb_private::plugin::dwarf::DWARFASTParser,
7070
lldb_private::CompilerDeclContext decl_context) override {}
7171

7272
// FIXME: What should this do?
73-
lldb_private::ConstString
73+
std::string
7474
GetDIEClassTemplateParams(const DWARFDIE &die) override {
7575
assert(false && "DWARFASTParserSwift::GetDIEClassTemplateParams has not "
7676
"yet been implemented");
77-
return lldb_private::ConstString();
77+
return {};
7878
}
7979

8080
static bool classof(const DWARFASTParser *Parser) {

lldb/source/Target/ThreadPlanStepOverRange.cpp

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -334,37 +334,6 @@ bool ThreadPlanStepOverRange::ShouldStop(Event *event_ptr) {
334334
return false;
335335
}
336336

337-
bool ThreadPlanStepRange::DoPlanExplainsStop(Event *event_ptr) {
338-
// For crashes, breakpoint hits, signals, etc,cd let the base plan (or some
339-
// plan above us) handle the stop. That way the user can see the stop, step
340-
// around, and then when they are done, continue and have their step
341-
// complete. The exception is if we've hit our "run to next branch"
342-
// breakpoint. Note, unlike the step in range plan, we don't mark ourselves
343-
// complete if we hit an unexplained breakpoint/crash.
344-
345-
Log *log = GetLog(LLDBLog::Step);
346-
StopInfoSP stop_info_sp = GetPrivateStopInfo();
347-
bool return_value;
348-
349-
if (stop_info_sp) {
350-
StopReason reason = stop_info_sp->GetStopReason();
351-
352-
if (reason == eStopReasonTrace) {
353-
return_value = true;
354-
} else if (reason == eStopReasonBreakpoint) {
355-
return_value = NextRangeBreakpointExplainsStop(stop_info_sp);
356-
} else {
357-
if (log)
358-
log->PutCString("ThreadPlanStepOverRange got asked if it explains the "
359-
"stop for some reason other than step.");
360-
return_value = false;
361-
}
362-
} else
363-
return_value = true;
364-
365-
return return_value;
366-
}
367-
368337
bool ThreadPlanStepOverRange::DoWillResume(lldb::StateType resume_state,
369338
bool current_plan) {
370339
if (resume_state != eStateSuspended && m_first_resume) {

0 commit comments

Comments
 (0)