OPT(1)

πŸ’… OPT(1) β€” the LLVM optimizer, but make it make sense

okay bestie, gather round, because this is opt(1) from the LLVM manual and it's genuinely one of the most useful little tools in the whole compiler-nerd universe 🫢

✨ NAME ✨

opt β€” the LLVM optimizer πŸ‘‘ no cap, that's literally its whole job.

🌸 SYNOPSIS 🌸

opt [options] [filename]

πŸ¦‹ DESCRIPTION πŸ¦‹

so the opt command is the modular LLVM optimizer and analyzer ✨ and here's the vibe: it takes LLVM source files as input, runs whatever optimizations or analyses you told it to run, and then outputs the optimized file. that's it. that's the whole main character moment.

the optimizations available through opt depend on what libraries were linked into it as well as any additional libraries you loaded in with the -load option πŸ‘€ so it's giving "your mileage may vary, bestie." use the -help option to figure out which optimizations you actually have access to πŸ’–

if filename is left out of the command line, or if it's -, opt reads its input from standard input. and the inputs can be in either the LLVM assembly language format (.ll) or the LLVM bitcode format (.bc) πŸŽ€

and if you don't specify an output filename with the -o option, opt writes its output straight to standard output. iconic behaviour, honestly.


πŸ’… OPTIONS πŸ’…

  • -f β€” enables binary output on terminals πŸ’€ normally opt flat-out refuses to write raw bitcode output if the output stream is a terminal, but with this option it'll write raw bitcode regardless of what the output device is. chaotic, but slay.
  • -help β€” prints a summary of the command line options. your bestie when you're lost.
  • -o <filename> β€” specifies the output filename πŸŽ€
  • -S β€” writes the output in LLVM intermediate language instead of bitcode. that's the .ll vibe, not the .bc vibe ✨
  • -{passname} β€” opt gives you the ability to run any of LLVM's optimization or analysis passes, in any order πŸ‘‘ the -help option lists all the passes available to you. and the order in which the options occur on the command line is the order in which they're executed (within pass constraints). so like, order matters, bestie, don't come for me.
  • -strip-debug β€” makes opt strip debug information from the module before applying other optimizations. it's essentially the same as -strip, but it makes sure the stripping of debug info happens first 🧚
  • -verify-each β€” makes opt add a verify pass after every pass otherwise specified on the command line (including -verify) πŸ”₯ this is genuinely so useful when you suspect a pass is creating an invalid module but you can't tell which pass is the culprit. detective mode: activated πŸ•΅οΈβ€β™€οΈ
  • -stats β€” prints statistics πŸ“Š
  • -time-passes β€” records how much time each pass needed and prints it to standard error ⏱️
  • -debug β€” if this is a debug build, this option enables debug printouts from passes that use the LLVM_DEBUG() macro. see the LLVM Programmer's Manual, section #DEBUG for more info πŸ™ˆ
  • -load=<plugin> β€” loads the dynamic object plugin. this object should register new optimization or analysis passes ✨ once loaded, the object adds new command line options that enable various optimizations or analyses. to see the new complete list of optimizations, use -help and -load together. for example:
opt -load=plugin.so -help
  • -print-passes β€” prints all available passes and exits 🌈 like a little parade of passes, then it dips.
ok real talk for a sec: -f is the one where you're overriding a safety-ish default (writing raw bitcode to a terminal). opt normally refuses for a reason β€” so use it on purpose, not by accident πŸ’œ

⭐ EXIT STATUS ⭐

if opt succeeds, it exits with 0 πŸŽ‰ otherwise, if an error occurs, it exits with a non-zero value. sad girl hours 😭


πŸŽ€ AUTHOR πŸŽ€

maintained by the LLVM Team (https://llvm.org/) 🫢

2003-2023, LLVM Project


alright bestie, that's the whole page πŸ’– go optimize something and think of me. this was LLVM, page 15, dated 2023-07-14, and that's the vibe check: passed βœ… periodt πŸ’…

πŸ“¦ where this page comes from