Skip to content

Plan B

October 25, 2014

I’ve switched allegiance to a new backend explanation for llvm. The cpu0 one was extensive and got me started but it was getting hard to follow.
2014-10-25 new plan

Also, for the record, telling llvm what machine to compile for seems ridiculously hard to figure out. The command
./clang -cc1 -triple sparc-unknown-unknown main.cpp -S
invokes the sparc target.

Speaking of clang -cc1, that is how you invoke the clang compiler by itself as opposed to a sort-of gcc front end. The options shown by clang -cc1 –help are shown below.

OVERVIEW: LLVM 'Clang' Compiler:

USAGE: clang -cc1 [options] 

  -CC                     Enable comment output in -E mode, even from macro expansions
  -C                      Enable comment output in -E mode
  -D               Predefine the specified macro
  -Eonly                  Just run preprocessor, no output (for timings)
  -E                      Run preprocessor, emit preprocessed file
  -F           Add directory to framework include search path
  -H                      Show header includes and nesting depth
  -I           Add directory to include search path
  -MG                     Add missing headers to dependency list
  -MP                     Create phony target for each dependency (other than main file)
  -MQ              Specify target to quote for dependency
  -MT              Specify target for dependency
  -Os                     Optimize for size
  -Oz                     Optimize for size, regardless of performance
  -O               Optimization level
  -P                      Disable linemarker output in -E mode
  -S                      Emit native assembly code
  -U               Undefine the specified macro
                          Warn if a function definition returns or accepts an object larger in bytes that a given value
  -Wno-rewrite-macros     Silence ObjC rewriting warnings
  -add-plugin       Use the named plugin action in addition to the default action
                          Run analysis on specific function
  -analyzer-checker-help  Display the list of analyzer checkers that are available
                          Choose analyzer checkers to enable
                          Source Code Analysis - Symbolic Constraint Engines
                          Choose analyzer checkers to disable
                          Emit verbose output about the analyzer's progress
                          Eagerly assume the truth/falseness of some symbolic constraints
  -analyzer-inline-call   Experimental transfer function inlining callees when its definition is available.
                          The maximum number of times the analyzer will go through a loop
                          The maximum number of nodes the analyzer can generate (150000 default, 0 = no limit)
                          Don't eagerly remove uninteresting ExplodedNodes from the ExplodedGraph
                          Force the static analyzer to analyze functions defined in header files
                          Analyze the definitions of blocks in addition to functions
                          Source Code Analysis - Output Options
  -analyzer-purge  Source Code Analysis - Dead Symbol Removal Frequency
  -analyzer-store  Source Code Analysis - Abstract Memory Store Models
                          Display exploded graph using GraphViz
                          Display exploded graph using Ubigraph
  -analyze                Run static analysis engine
  -arcmt-check            Check for ARC migration issues that need manual handling
                          Directory for temporary files produced during ARC migration
                          Emit ARC errors even if the migrator can fix them
                          Output path for the plist report
  -arcmt-migrate          Apply modifications and produces temporary files that conform to ARC
  -arcmt-modify           Apply modifications to files to conform to ARC
  -ast-dump-xml           Build ASTs and then debug dump them in a verbose XML format
  -ast-dump               Build ASTs and then debug dump them
  -ast-merge    Merge the given AST file into the translation unit being compiled.
  -ast-print              Build ASTs and then pretty-print them
  -ast-view               Build ASTs and view them with GraphViz
  -backend-option  Additional arguments to forward to LLVM backend (during code gen)
  -c-isystem   Add directory to the C SYSTEM include search path
  -cfg-add-implicit-dtors Add C++ implicit destructors to CFGs for all analyses
  -cfg-add-initializers   Add C++ initializers to CFGs for all analyses
  -chain-include    Include and chain a header file after turning it into PCH
  -cl-fast-relaxed-math   OpenCL only. Sets -cl-finite-math-only and -cl-unsafe-math-optimizations, and defines __FAST_RELAXED_MATH__
  -cl-finite-math-only    OpenCL only. Allow floating-point optimizations that assume arguments and results are not NaNs or +-Inf.
  -cl-mad-enable          OpenCL only. Enable less precise MAD instructions to be generated.
  -cl-opt-disable         OpenCL only. This option disables all optimizations. The default is optimizations are enabled.
                          OpenCL only. Treat double precision floating-point constant as single precision constant.
  -cl-std=         OpenCL language standard to compile for
                          OpenCL only. Allow unsafe floating-point optimizations.  Also implies -cl-no-signed-zeros and -cl-mad-enable
  -code-completion-at ::
                          Dump code-completion information at a location
  -code-completion-macros Include macros in code-completion results
                          Include code patterns in code-completion results
  -coverage-file   Emit coverage data to this filename. The extension will be replaced.
  -cxx-abi         Target a particular C++ ABI type
                          Add directory to the C++ SYSTEM include search path
  -dD                     Print macro definitions in -E mode in addition to normal output
  -dM                     Print macro definitions in -E mode instead of normal output
                          Filename (or -) to write dependency output to
                          include a detailed record of preprocessing actions
                          Filename (or -) to log diagnostics to
  -disable-free           Disable freeing of memory on exit
  -disable-llvm-optzns    Don't run LLVM optimization passes
  -disable-llvm-verifier  Don't run the LLVM IR verifier pass
  -disable-red-zone       Do not emit code that uses the red zone.
                          output a dump of some build information to a file
                          Dump declarations that are deserialized from PCH, for testing
  -dump-raw-tokens        Lex file in raw mode and dump raw tokens
  -dump-tokens            Run preprocessor, dump internal rep of tokens
                          The string to embed in the Dwarf debug flags record.
  -emit-codegen-only      Generate machine code, but discard output
  -emit-html              Output input source as HTML
  -emit-llvm-bc           Build ASTs then convert to LLVM, emit .bc file
  -emit-llvm-only         Build ASTs and convert to LLVM, discarding output
  -emit-llvm              Build ASTs then convert to LLVM, emit .ll file
  -emit-module            Generate pre-compiled module file
  -emit-obj               Emit native object files
  -emit-pch               Generate pre-compiled header file
  -emit-pth               Generate pre-tokenized header file
                          Emit error if a specific declaration is deserialized from PCH, for testing
  -faltivec               Enable AltiVec vector initializer syntax
  -fapple-kext            Use Apple's kernel extensions ABI
  -fauto-module-import    Automatically translate #include/#import into module imports when possible
                          Weakly link in the blocks runtime
  -fblocks                Enable the 'blocks' language feature
  -fborland-extensions    Accept non-standard constructs supported by the Borland compiler
                          Generate runtime checks for undefined behavior.
  -fcolor-diagnostics     Use colors in diagnostics
  -fconst-strings         Use a const qualified type for string literals in C and ObjC
                          Specify the class to use for constant Objective-C string objects.
  -fcuda-is-device        Generate code for CUDA device
  -fcxx-exceptions        Enable C++ exceptions
  -fdata-sections         Place each data in its own section (ELF Only)
  -fdebugger-support      Enable special debugger support behavior
                          Parse templated function definitions at the end of the translation unit 
  -fdeprecated-macro      Defines the __DEPRECATED macro
                          Change diagnostic formatting to match IDE and command line tools
                          Print fix-its in machine parseable form
                          Print source range spans in numeric form
                          Print diagnostic category
  -fdiagnostics-show-name Print diagnostic name
                          Display include stacks for diagnostic notes
                          Print option name with mappable diagnostics
  -fdisable-module-hash   Disable the module hash
                          Allow '$' in identifiers
  -fdump-record-layouts   Dump record layout information
  -fdump-vtable-layouts   Dump the layouts of all vtables that will be emitted in a translation unit
  -femit-all-decls        Emit all declarations, even if unused
  -femit-coverage-data    Instrument the program to emit gcov coverage data when run.
  -femit-coverage-notes   Emit a gcov coverage notes file when compiling.
  -ferror-limit        Set the maximum number of errors to emit before stopping (0 = no limit).
  -fexceptions            Enable support for exception handling
                          Use a fake address space map; OpenCL testing purposes only
                          Emit an error if a C++ static local initializer would need a guard variable
  -ffreestanding          Assert that the compilation takes place in a freestanding environment
  -ffunction-sections     Place each function in its own section (ELF Only)
  -fgnu-keywords          Allow GNU-extension keywords regardless of language standard
  -fgnu-runtime           Generate output compatible with the standard GNU Objective-C runtime
  -fgnu89-inline          Use the gnu89 inline semantics
  -fhidden-weak-vtables   Generate weak vtables and RTTI with hidden visibility
  -finstrument-functions  Generate calls to instrument function entry and exit
  -fix-what-you-can       Apply fix-it advice even in the presence of unfixable errors
  -fixit=          Apply fix-it advice creating a file with the given suffix
  -fixit                  Apply fix-it advice to the input source
  -flimit-debug-info      Limit debug information produced to reduce size of debug binary
                          Set the maximum number of entries to print in a macro expansion backtrace (0 = no limit).
  -fmath-errno            Require math functions to indicate errors by setting errno
  -fmessage-length     Format message diagnostics so that they fit within N columns or fewer, when possible.
                          Specify the module cache path
  -fms-compatibility      Enable Microsoft compatibility mode
  -fms-extensions         Accept some non-standard constructs supported by the Microsoft compiler
  -fmsc-version=   Version of the Microsoft C/C++ compiler to report in _MSC_VER (0 = don't define it (default))
  -fno-access-control     Disable C++ access control
                          Don't assume that C++'s global operator new can't alias any pointer
                          Ignore bit-field types when aligning structures
  -fno-builtin            Disable implicit builtin knowledge of functions
  -fno-caret-diagnostics  Do not include source line and caret with diagnostics
  -fno-common             Compile common globals like normal definitions
  -fno-const-strings      Don't use a const qualified type for string literals in C and ObjC
  -fno-constant-cfstrings Enable creation of CodeFoundation-type constant strings
  -fno-deprecated-macro   Undefines the __DEPRECATED macro
                          Do not include fixit information in diagnostics
                          Display include stacks for diagnostic notes
                          Disallow '$' in identifiers
  -fno-dwarf2-cfi-asm     Don't use the cfi directives
  -fno-elide-constructors Disable C++ copy constructor elision
  -fno-gnu-keywords       Disallow GNU-extension keywords regardless of language standard
                          Disallow implicit conversions between vectors with a different number of elements or different element types
                          Disallow merging of constants.
                          do not infer Objective-C related result type based on method family
  -fno-operator-names     Do not treat C++ operator name keywords as synonyms for operators
  -fno-rtti               Disable generation of rtti information
  -fno-show-column        Do not include column number on diagnostics
                          Do not include source location information with diagnostics
  -fno-signed-char        Char is unsigned
  -fno-spell-checking     Disable spell-checking
  -fno-threadsafe-statics Do not emit code to make initialization of local statics thread safe
  -fno-use-cxa-atexit     Don't use __cxa_atexit for calling destructors
  -fno-validate-pch       Disable validation of precompiled headers
                          Objective-C++ Automatic Reference Counting standard library kind
  -fobjc-arc-exceptions   Use EH-safe code when synthesizing retains and releases in -fobjc-arc
  -fobjc-arc              Synthesize retain and release calls for Objective-C pointers
                          enable the default synthesis of Objective-C properties
                          Objective-C dispatch method to use
  -fobjc-exceptions       Enable Objective-C exceptions
  -fobjc-fragile-abi      Use Objective-C's fragile ABI
  -fobjc-gc-only          Use GC exclusively for Objective-C related memory management
  -fobjc-gc               Enable Objective-C garbage collection
  -fobjc-runtime-has-arc  The target Objective-C runtime provides ARC entrypoints
                          The target Objective-C runtime provides an objc_terminate entrypoint
  -fobjc-runtime-has-weak The target Objective-C runtime supports ARC weak operations
  -fpack-struct    Specify the default maximum struct packing alignment
  -fpascal-strings        Recognize and construct Pascal-style string literals
  -fshort-enums           Allocate to an enum type only as many bytes as it needs for the declared range of possible values
  -fshort-wchar           Force wchar_t to be a short unsigned int
  -fshow-column           Include column number on diagnostics
                          Which overload candidates to show when overload resolution fails: best|all; defaults to all
  -fsjlj-exceptions       Use SjLj style exceptions
  -fsyntax-only           Run parser and perform semantic analysis
  -ftabstop            Set the tab stop distance.
                          Set the maximum number of entries to print in a template instantiation backtrace (0 = no limit).
                          Maximum depth of recursive template instantiation
  -ftime-report           Print the amount of time each phase of compilation takes
                          Specify the function to be called on overflow.
  -ftrapv                 Trap on integer overflow
  -funknown-anytype       Enable parser support for the __unknown_anytype type; for testing purposes only
  -funroll-loops          Turn on loop unroller
                          Use register sized accesses to bit-fields, when possible.
                          Give inline C++ member functions default visibility by default
  -fvisibility     Default symbol visibility
  -fwrapv                 Treat signed integer overflow as two's complement
  -fwritable-strings      Store string literals as writable data
  -g                      Generate source level debug information
                          Filename (or -) to write header include output to
  -help                   Print this help text
  -idirafter   Add directory to AFTER include search path
  -imacros          Include macros from file before parsing
  -include-pch      Include precompiled header file
  -include-pth      Include file before parsing
  -include          Include file before parsing
  -index-header-map       Make the next included directory (-I or -F) an indexer header map
  -init-only              Only execute frontend initialization
                          Add directory to the internal system include search path with implicit extern "C" semantics; these are assumed to not be user-provided and are used to model system and standard headers' paths.
                          Add directory to the internal system include search path; these are assumed to not be user-provided and are used to model system and standard headers' paths.
  -iprefix        Set the -iwithprefix/-iwithprefixbefore prefix
  -iquote      Add directory to QUOTE include search path
  -isysroot          Set the system root directory (usually /)
  -isystem     Add directory to SYSTEM include search path
                          Set directory to include search path with prefix
  -iwithprefix       Set directory to SYSTEM include search path with prefix
                          Add directory to SYSTEM include search path, absolute paths are relative to -isysroot
  -load          Load the named plugin (dynamic shared object)
  -main-file-name  Main file name to use for debug info
  -masm-verbose           Generate verbose assembly output
  -mcode-model     The code model to use
  -mconstructor-aliases   Emit complete constructors and destructors as aliases when possible
  -mdebug-pass     Enable additional debug output
  -mdisable-fp-elim       Disable frame pointer elimination optimization
  -mfloat-abi      The float ABI to use
                          Limit float precision to the given value
  -mllvm           Additional arguments to forward to LLVM's option processing
  -mms-bitfields          Set the default structure layout to be compatible with the Microsoft compiler standard.
  -mno-global-merge       Disable merging of globals
                          Do not put zero initialized data in the BSS
  -mnoexecstack           Mark the file as not needing an executable stack
                          Omit frame pointer setup for leaf functions.
  -mregparm        Limit the number of registers available for integer arguments
  -mrelax-all             (integrated-as) Relax all machine instructions
                          The relocation model to use
  -mrtd                   Make StdCall calling convention the default
  -msave-temp-labels      (integrated-as) Save temporary labels
  -msoft-float            Use software floating point
  -mstackrealign          Force realign the stack at entry to every function.
  -munwind-tables         Generate unwinding tables for all functions
                          Do not include global declarations in code-completion results.
  -no-implicit-float      Don't generate implicit floating point instructions (x86-only)
  -nobuiltininc           Disable builtin #include directories
  -nostdinc++             Disable standard #include directories for the C++ standard library
  -nostdsysteminc         Disable standard system #include directories
                          Add directory to the ObjC SYSTEM include search path
                          Add directory to the ObjC++ SYSTEM include search path
  -o                Specify output file
  -pg                     Enable mcount instrumentation
  -pic-level       Value for __PIC__
                          Pass  to plugin 
  -plugin           Use the named plugin action instead of the default action (use "help" to list available options)
  -preamble-bytes= Assume that the precompiled header is a precompiled preamble covering the first N bytes of the main file
  -print-decl-contexts    Print DeclContexts and their Decls
  -print-ivar-layout      Enable Objective-C Ivar layout bitmap print trace
  -print-preamble         Print the "preamble" of a file, which is a candidate for implicit precompiled headers.
  -print-stats            Print performance metrics and statistics
  -pthread                Support POSIX threads in generated code
  -relaxed-aliasing       Turn off Type Based Alias Analysis
  -relocatable-pch        Whether to build a relocatable precompiled header
  -remap-file ; Replace the contents of the  file with the contents of the  file
  -resource-dir    The directory which holds the compiler resource files
  -rewrite-macros         Expand macros without full preprocessing
  -rewrite-objc           Rewrite ObjC into C (code rewriter example)
  -rewrite-test           Rewriter playground
                          Enable stack protectors
  -static-define          Should __STATIC__ be defined
  -std=            Language standard to compile for
  -stdlib=         C++ standard library to use
  -sys-header-deps        Include system headers in dependency output
  -target-abi      Target a particular ABI type
  -target-cpu      Target a specific cpu type
  -target-feature  Target specific attributes
                          Target linker version
  -token-cache      Use specified token cache file
  -traditional-cpp        Enable some traditional CPP emulation
  -trigraphs              Process trigraph sequences
  -trim-egraph            Only show error-related paths in the analysis graph
  -triple          Specify target triple (e.g. i686-apple-darwin9)
  -undef                  undef all system defines
  -unoptimized-cfg        Generate unoptimized CFGs for all analyses
  -verify                 Verify emitted diagnostics and warnings
  -version                Print the compiler version
  -v                      Enable verbose output
                          Resolve file paths relative to the specified directory
  -w                      Suppress all warnings
  -x               Input language type

From → LLVM

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: