Skip to content

Commit 56a74d3

Browse files
author
git apple-llvm automerger
committed
Merge commit 'af1f38c88612' from apple/stable/20200714 into swift/main
2 parents bcffc98 + af1f38c commit 56a74d3

File tree

263 files changed

+6514
-13515
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

263 files changed

+6514
-13515
lines changed

clang/lib/APINotes/APINotesYAMLCompiler.cpp

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -429,22 +429,6 @@ namespace llvm {
429429
}
430430
};
431431

432-
template <>
433-
struct ScalarTraits<VersionTuple> {
434-
static void output(const VersionTuple &value, void*,
435-
llvm::raw_ostream &out) {
436-
out << value;
437-
}
438-
static StringRef input(StringRef scalar, void*, VersionTuple &value) {
439-
if (value.tryParse(scalar))
440-
return "not a version number in the form XX.YY";
441-
442-
return StringRef();
443-
}
444-
445-
static QuotingType mustQuote(StringRef) { return QuotingType::None; }
446-
};
447-
448432
template <>
449433
struct MappingTraits<Param> {
450434
static void mapping(IO &io, Param& p) {

lldb/include/lldb/Core/Disassembler.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class DataExtractor;
4848
class Debugger;
4949
class Disassembler;
5050
class Module;
51+
class StackFrame;
5152
class Stream;
5253
class SymbolContext;
5354
class SymbolContextList;
@@ -408,11 +409,8 @@ class Disassembler : public std::enable_shared_from_this<Disassembler>,
408409
uint32_t num_mixed_context_lines, uint32_t options,
409410
Stream &strm);
410411

411-
static bool
412-
Disassemble(Debugger &debugger, const ArchSpec &arch, const char *plugin_name,
413-
const char *flavor, const ExecutionContext &exe_ctx,
414-
uint32_t num_instructions, bool mixed_source_and_assembly,
415-
uint32_t num_mixed_context_lines, uint32_t options, Stream &strm);
412+
static bool Disassemble(Debugger &debugger, const ArchSpec &arch,
413+
StackFrame &frame, Stream &strm);
416414

417415
// Constructors and Destructors
418416
Disassembler(const ArchSpec &arch, const char *flavor);

lldb/source/Core/Disassembler.cpp

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -540,34 +540,29 @@ void Disassembler::PrintInstructions(Debugger &debugger, const ArchSpec &arch,
540540
}
541541

542542
bool Disassembler::Disassemble(Debugger &debugger, const ArchSpec &arch,
543-
const char *plugin_name, const char *flavor,
544-
const ExecutionContext &exe_ctx,
545-
uint32_t num_instructions,
546-
bool mixed_source_and_assembly,
547-
uint32_t num_mixed_context_lines,
548-
uint32_t options, Stream &strm) {
543+
StackFrame &frame, Stream &strm) {
549544
AddressRange range;
550-
StackFrame *frame = exe_ctx.GetFramePtr();
551-
if (frame) {
552-
SymbolContext sc(
553-
frame->GetSymbolContext(eSymbolContextFunction | eSymbolContextSymbol));
554-
if (sc.function) {
555-
range = sc.function->GetAddressRange();
556-
} else if (sc.symbol && sc.symbol->ValueIsAddress()) {
557-
range.GetBaseAddress() = sc.symbol->GetAddressRef();
558-
range.SetByteSize(sc.symbol->GetByteSize());
559-
} else {
560-
range.GetBaseAddress() = frame->GetFrameCodeAddress();
561-
}
545+
SymbolContext sc(
546+
frame.GetSymbolContext(eSymbolContextFunction | eSymbolContextSymbol));
547+
if (sc.function) {
548+
range = sc.function->GetAddressRange();
549+
} else if (sc.symbol && sc.symbol->ValueIsAddress()) {
550+
range.GetBaseAddress() = sc.symbol->GetAddressRef();
551+
range.SetByteSize(sc.symbol->GetByteSize());
552+
} else {
553+
range.GetBaseAddress() = frame.GetFrameCodeAddress();
554+
}
562555

563556
if (range.GetBaseAddress().IsValid() && range.GetByteSize() == 0)
564557
range.SetByteSize(DEFAULT_DISASM_BYTE_SIZE);
565-
}
566558

567-
return Disassemble(
568-
debugger, arch, plugin_name, flavor, exe_ctx, range.GetBaseAddress(),
569-
{Limit::Instructions, num_instructions}, mixed_source_and_assembly,
570-
num_mixed_context_lines, options, strm);
559+
Disassembler::Limit limit = {Disassembler::Limit::Bytes,
560+
range.GetByteSize()};
561+
if (limit.value == 0)
562+
limit.value = DEFAULT_DISASM_BYTE_SIZE;
563+
564+
return Disassemble(debugger, arch, nullptr, nullptr, frame,
565+
range.GetBaseAddress(), limit, false, 0, 0, strm);
571566
}
572567

573568
Instruction::Instruction(const Address &address, AddressClass addr_class)

lldb/source/Expression/DWARFExpression.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2248,6 +2248,29 @@ bool DWARFExpression::Evaluate(
22482248
}
22492249
break;
22502250

2251+
// OPCODE: DW_OP_implicit_value
2252+
// OPERANDS: 2
2253+
// ULEB128 size of the value block in bytes
2254+
// uint8_t* block bytes encoding value in target's memory
2255+
// representation
2256+
// DESCRIPTION: Value is immediately stored in block in the debug info with
2257+
// the memory representation of the target.
2258+
case DW_OP_implicit_value: {
2259+
const uint32_t len = opcodes.GetULEB128(&offset);
2260+
const void *data = opcodes.GetData(&offset, len);
2261+
2262+
if (!data) {
2263+
LLDB_LOG(log, "Evaluate_DW_OP_implicit_value: could not be read data");
2264+
LLDB_ERRORF(error_ptr, "Could not evaluate %s.",
2265+
DW_OP_value_to_name(op));
2266+
return false;
2267+
}
2268+
2269+
Value result(data, len);
2270+
stack.push_back(result);
2271+
break;
2272+
}
2273+
22512274
// OPCODE: DW_OP_push_object_address
22522275
// OPERANDS: none
22532276
// DESCRIPTION: Pushes the address of the object currently being

lldb/source/Target/StackFrame.cpp

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -229,21 +229,16 @@ bool StackFrame::ChangePC(addr_t pc) {
229229

230230
const char *StackFrame::Disassemble() {
231231
std::lock_guard<std::recursive_mutex> guard(m_mutex);
232-
if (m_disassembly.Empty()) {
233-
ExecutionContext exe_ctx(shared_from_this());
234-
Target *target = exe_ctx.GetTargetPtr();
235-
if (target) {
236-
const char *plugin_name = nullptr;
237-
const char *flavor = nullptr;
238-
Disassembler::Disassemble(target->GetDebugger(),
239-
target->GetArchitecture(), plugin_name, flavor,
240-
exe_ctx, 0, false, 0, 0, m_disassembly);
241-
}
242-
if (m_disassembly.Empty())
243-
return nullptr;
232+
if (!m_disassembly.Empty())
233+
return m_disassembly.GetData();
234+
235+
ExecutionContext exe_ctx(shared_from_this());
236+
if (Target *target = exe_ctx.GetTargetPtr()) {
237+
Disassembler::Disassemble(target->GetDebugger(), target->GetArchitecture(),
238+
*this, m_disassembly);
244239
}
245240

246-
return m_disassembly.GetData();
241+
return m_disassembly.Empty() ? nullptr : m_disassembly.GetData();
247242
}
248243

249244
Block *StackFrame::GetFrameBlock() {

lldb/test/API/commands/disassemble/basic/TestFrameDisassemble.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,6 @@ def frame_disassemble_test(self):
5757

5858
frame = threads[0].GetFrameAtIndex(0)
5959
disassembly = frame.Disassemble()
60-
self.assertNotEqual(len(disassembly), 0, "Disassembly was empty.")
60+
self.assertNotEqual(disassembly, "")
61+
self.assertNotIn("error", disassembly)
62+
self.assertIn(": nop", disassembly)

lldb/test/API/commands/disassemble/basic/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ int
22
sum (int a, int b)
33
{
44
int result = a + b; // Set a breakpoint here
5+
asm("nop");
56
return result;
67
}
78

lldb/unittests/Expression/DWARFExpressionTest.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,14 @@ TEST(DWARFExpression, DW_OP_piece) {
221221
llvm::HasValue(GetScalar(16, 0xff00, true)));
222222
}
223223

224+
TEST(DWARFExpression, DW_OP_implicit_value) {
225+
unsigned char bytes = 4;
226+
227+
EXPECT_THAT_EXPECTED(
228+
Evaluate({DW_OP_implicit_value, bytes, 0x11, 0x22, 0x33, 0x44}),
229+
llvm::HasValue(GetScalar(8 * bytes, 0x44332211, true)));
230+
}
231+
224232
TEST(DWARFExpression, DW_OP_unknown) {
225233
EXPECT_THAT_EXPECTED(
226234
Evaluate({0xff}),

llvm/docs/tutorial/BuildingAJIT4.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
===========================================================================
2-
Building a JIT: Extreme Laziness - Using Compile Callbacks to JIT from ASTs
3-
===========================================================================
1+
=======================================================================
2+
Building a JIT: Extreme Laziness - Using LazyReexports to JIT from ASTs
3+
=======================================================================
44

55
.. contents::
66
:local:
@@ -13,9 +13,9 @@ Chapter 4 Introduction
1313
======================
1414

1515
Welcome to Chapter 4 of the "Building an ORC-based JIT in LLVM" tutorial. This
16-
chapter introduces the Compile Callbacks and Indirect Stubs APIs and shows how
17-
they can be used to replace the CompileOnDemand layer from
18-
`Chapter 3 <BuildingAJIT3.html>`_ with a custom lazy-JITing scheme that JITs
16+
chapter introduces custom MaterializationUnits and Layers, and the lazy
17+
reexports API. Together these will be used to replace the CompileOnDemandLayer
18+
from `Chapter 3 <BuildingAJIT3.html>`_ with a custom lazy-JITing scheme that JITs
1919
directly from Kaleidoscope ASTs.
2020

2121
**To be done:**

llvm/docs/tutorial/BuildingAJIT5.rst

Lines changed: 0 additions & 57 deletions
This file was deleted.

llvm/examples/Kaleidoscope/BuildingAJIT/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ add_subdirectory(Chapter2)
33
add_subdirectory(Chapter3)
44
add_subdirectory(Chapter4)
55

6-
if (NOT WIN32)
7-
add_subdirectory(Chapter5)
8-
endif()
6+
# if (NOT WIN32)
7+
# add_subdirectory(Chapter5)
8+
# endif()

llvm/examples/Kaleidoscope/BuildingAJIT/Chapter1/KaleidoscopeJIT.h

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "llvm/ExecutionEngine/Orc/IRCompileLayer.h"
2222
#include "llvm/ExecutionEngine/Orc/JITTargetMachineBuilder.h"
2323
#include "llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h"
24+
#include "llvm/ExecutionEngine/Orc/TargetProcessControl.h"
2425
#include "llvm/ExecutionEngine/SectionMemoryManager.h"
2526
#include "llvm/IR/DataLayout.h"
2627
#include "llvm/IR/LLVMContext.h"
@@ -31,53 +32,67 @@ namespace orc {
3132

3233
class KaleidoscopeJIT {
3334
private:
34-
ExecutionSession ES;
35-
RTDyldObjectLinkingLayer ObjectLayer;
36-
IRCompileLayer CompileLayer;
35+
std::unique_ptr<TargetProcessControl> TPC;
36+
std::unique_ptr<ExecutionSession> ES;
3737

3838
DataLayout DL;
3939
MangleAndInterner Mangle;
40-
ThreadSafeContext Ctx;
40+
41+
RTDyldObjectLinkingLayer ObjectLayer;
42+
IRCompileLayer CompileLayer;
4143

4244
JITDylib &MainJD;
4345

4446
public:
45-
KaleidoscopeJIT(JITTargetMachineBuilder JTMB, DataLayout DL)
46-
: ObjectLayer(ES,
47+
KaleidoscopeJIT(std::unique_ptr<TargetProcessControl> TPC,
48+
std::unique_ptr<ExecutionSession> ES,
49+
JITTargetMachineBuilder JTMB, DataLayout DL)
50+
: TPC(std::move(TPC)), ES(std::move(ES)), DL(std::move(DL)),
51+
Mangle(*this->ES, this->DL),
52+
ObjectLayer(*this->ES,
4753
[]() { return std::make_unique<SectionMemoryManager>(); }),
48-
CompileLayer(ES, ObjectLayer,
54+
CompileLayer(*this->ES, ObjectLayer,
4955
std::make_unique<ConcurrentIRCompiler>(std::move(JTMB))),
50-
DL(std::move(DL)), Mangle(ES, this->DL),
51-
Ctx(std::make_unique<LLVMContext>()),
52-
MainJD(ES.createBareJITDylib("<main>")) {
56+
MainJD(this->ES->createBareJITDylib("<main>")) {
5357
MainJD.addGenerator(
5458
cantFail(DynamicLibrarySearchGenerator::GetForCurrentProcess(
5559
DL.getGlobalPrefix())));
5660
}
5761

62+
~KaleidoscopeJIT() {
63+
if (auto Err = ES->endSession())
64+
ES->reportError(std::move(Err));
65+
}
66+
5867
static Expected<std::unique_ptr<KaleidoscopeJIT>> Create() {
59-
auto JTMB = JITTargetMachineBuilder::detectHost();
68+
auto TPC = SelfTargetProcessControl::Create();
69+
if (!TPC)
70+
return TPC.takeError();
71+
72+
auto ES = std::make_unique<ExecutionSession>();
6073

61-
if (!JTMB)
62-
return JTMB.takeError();
74+
JITTargetMachineBuilder JTMB((*TPC)->getTargetTriple());
6375

64-
auto DL = JTMB->getDefaultDataLayoutForTarget();
76+
auto DL = JTMB.getDefaultDataLayoutForTarget();
6577
if (!DL)
6678
return DL.takeError();
6779

68-
return std::make_unique<KaleidoscopeJIT>(std::move(*JTMB), std::move(*DL));
80+
return std::make_unique<KaleidoscopeJIT>(std::move(*TPC), std::move(ES),
81+
std::move(JTMB), std::move(*DL));
6982
}
7083

7184
const DataLayout &getDataLayout() const { return DL; }
7285

73-
LLVMContext &getContext() { return *Ctx.getContext(); }
86+
JITDylib &getMainJITDylib() { return MainJD; }
7487

75-
Error addModule(std::unique_ptr<Module> M) {
76-
return CompileLayer.add(MainJD, ThreadSafeModule(std::move(M), Ctx));
88+
Error addModule(ThreadSafeModule TSM, ResourceTrackerSP RT = nullptr) {
89+
if (!RT)
90+
RT = MainJD.getDefaultResourceTracker();
91+
return CompileLayer.add(RT, std::move(TSM));
7792
}
7893

7994
Expected<JITEvaluatedSymbol> lookup(StringRef Name) {
80-
return ES.lookup({&MainJD}, Mangle(Name.str()));
95+
return ES->lookup({&MainJD}, Mangle(Name.str()));
8196
}
8297
};
8398

0 commit comments

Comments
 (0)