LLVM

See also:

Glossary

Hacking on LLVM

Reading the Code

Try woboq: https://code.woboq.org/llvm/

Building

nix-shell -A llvm "<unstable>" --run zsh

Some good options for CMake:

cmake -S llvm -B build -G "Unix Makefiles" \
  -DCMAKE_INSTALL_PREFIX=$PWD/out \
  -DCMAKE_BUILD_TYPE=Debug \
  -DLLVM_TARGETS_TO_BUILD=X86 \
  -DLLVM_ENABLE_ZLIB=OFF \
  -DLLVM_ENABLE_TERMINFO=OFF \
  -DLLVM_ENABLE_LIBPFM=OFF \
  -DLLVM_PARALLEL_LINK_JOBS=4

Requesting Review With Phabricator

See Phabricator.

Documentation

Formatting

git diff -U0 --no-color --relative HEAD^ | python3 clang/tools/clang-format/clang-format-diff.py -p1 -i

Components

LLVM-Reduce

Tests here: https://github.com/llvm/llvm-project/tree/main/llvm/test/tools/llvm-reduce

Tools

The Pass Managers

All LLVM documentation and virtually all tutorials use what's called the "legacy pass manager".

This link is the only good resource I've found on this: https://github.com/banach-space/llvm-tutor

Legacy

Non-Legacy

From the docs:

Note that the implementations of the pass managers use concept-based polymorphism as outlined in the "Value Semantics and Concept-based Polymorphism" talk (or its abbreviated sibling "Inheritance Is The Base Class of Evil") by Sean Parent:

Here's an example pass using the non-legacy pass manager:

class ASTGraphWriter : public llvm::PassInfoMixin<ASTGraphWriter> {
 public:
  llvm::PreservedAnalyses run(
      llvm::Module &module,
      llvm::ModuleAnalysisManager &module_analysis_manager) {
    llvm::outs() << module;
    auto aa_results = llvm::GlobalsAA().run(module, module_analysis_manager);
    return llvm::PreservedAnalyses::all();
  }
};
}  // namespace mate

extern "C" ::llvm::PassPluginLibraryInfo LLVM_ATTRIBUTE_WEAK
llvmGetPassPluginInfo() {
  return {LLVM_PLUGIN_API_VERSION,
          "ast-graph-writer",
          "v0.1",
          [](llvm::PassBuilder &pb) {
            pb.registerPipelineParsingCallback(
                [](llvm::StringRef name,
                   llvm::ModulePassManager &module_pass_manager,
                   llvm::ArrayRef<llvm::PassBuilder::PipelineElement>) {
                  if (name == "ast-graph-writer") {
                    module_pass_manager.addPass(mate::ASTGraphWriter());
                    return true;
                  }
                  return false;
                });
          }};
}

LTO

See Link-Time Optimization.

Mangling

See also Mangling.

TableGen

nix-shell -p llvm_9 --run "llvm-tblgen -dump-json include/llvm/IR/Intrinsics.td -I include"

Types

Records

Analysis of LLVM IR

Tools

Literature

Cards

extractvalue

Text

In LLVM, the {{c1::extractvalue}} instruction is used to {{c2::extract the value of a member field from an aggregate value}}.

getelementptr

Text

In LLVM, the {{c1::getelementptr}} instruction is used to {{c2::get the address of a subelement of an aggregate data structure}}.

landingpad

Text

In LLVM, the {{c1::landingpad}} instruction is used to {{c2::mark a basic block as a landing pad - one where the exception lands, and corresponds to the code found in the catch portion of a try/catch sequence}}.

resume

Text

In LLVM, the {{c1::resume}} instruction is used to {{c2::resume propagation of an existing (in-flight) exception whose unwinding was interrupted with a landingpad instruction}}.

landing pad

Text

In the LLVM IR, a {{c1::landing pad}} is {{c2::where execution continues after an exception that occurs in an invoke}}.

cleanup landing pad

Text

In the LLVM IR, a landing pad instruction with a {{c1::cleanup clause}} will {{c2::always}} be entered when an exception is thrown.

cleanup destructor

Front

In the context of the LLVM language, what is the typical example of a cleanup in compiled C++ code?

Back

Object destructors