Worth buying, regrettably
This book is above average quality for Packt, but substandard by the standards of reputable publishers. It’s newer, but substantially worse, than _LLVM Techniques, Tips, and Best Practices Clang and Middle-End Libraries_ by Min-Yih Hsu, which is the only book from Packt I’ve read worthy of a real publisher. While the copy-editing is, unusually for Packt, tolerable for both, the lack of a general editor is painfully apparent.
You may, regrettably, need to read this as well, as Hsu concentrates on the Clang front-end and middle-end; Nacke has considerable coverage of the back-end. (I skipped most of Nacke’s sections on the front-end, as it was already covered by Hsu.) Nacke’s organization is badly defective, and explanations are largely missing in favor of cookbook recipe steps; details below.
It was still worth reading parts, for me at least, for a unified presentation of some topics, and for what it omits. It is much nicer, for instance, to start with a _short_ explanation of datalayout. (Exceptionally, read Nacke’s section on TableGen instead of, or perhaps after, Hsu’s — which uses a nonsensical example, doughnut recipes.)
Nacke generally fails to explain new concepts; he just provides recipes. (Nor is there an architectural diagram.)
• His introduction of “unsigned” on page 149 does not mention how different its meaning is from higher-level languages.
• His first mention of Undef, on page 164, merely describes it as special, with no attempt to explain LLVM’s difficult concepts of Undef and Poison.
• The first substantive occurrence of metadata (p. 219) does not define it; I don’t think there is a real definition, but you can at least skip ahead to p. 240 to see an example.
• The existence of both an old and a new Pass Manager is not mentioned until the 17th occurrence (of 42) of the phrase, on p. 293. (The lack of definitional consistency means that a possible interpretation of the text is that the Legacy Pass Manager is distinct from the Old Pass Manager, which would make three in all.)
• The section on SelectionDAG never properly explains what a DAG is. (Hsu does.) The following section on its intended replacement, GlobalISel, merely presents a rival list of recipe steps, without explaining the difference.
Nacke’s organization is conspicuously incorrect in places, e.g.:
• The name of Part 2: “From Source to Machine Code Generation” is incorrect; it doesn’t cover machine code.
• The name of Part 3: “Taking LLVM to the Next Level” is both meaningless and incorrect.
• Chapter 8 “The TableGen Language” belongs where it is; it is used in what should be the following chapter, 13.1 “Adding a new machine function pass to LLVM.”
• The other two, Chapter 9 “JIT Compilation” and Chapter 10 “Debugging Using LLVM Tools” do not, and Chapter 10 is not about debugging. (It includes libFuzzer, sanitizers, and the Clang Static Analyzer.)
• Chapter 13 “Beyond Instruction Selection” should actually be three distinct chapters:
• 13.1 “Adding a new machine function pass to LLVM,”
• 13.2 “Integrating a new target into the clang frontend,”
• 13.2 “How to target a different CPU architecture.” The last is misnamed; it should be titled “Cross-Compilation.” (Much of the book is about targeting a different CPU architecture.)