MSP430 Optimizing C/C++ Compiler V17.6.0.STS User's Guide
Total Page:16
File Type:pdf, Size:1020Kb
MSP430 Optimizing C/C++ Compiler v17.6.0.STS User's Guide Literature Number: SLAU132P June 2017 Contents Preface ........................................................................................................................................ 9 1 Introduction to the Software Development Tools.................................................................... 12 1.1 Software Development Tools Overview ................................................................................. 13 1.2 Compiler Interface.......................................................................................................... 15 1.3 ANSI/ISO Standard ........................................................................................................ 15 1.4 Output Files ................................................................................................................. 15 1.5 Utilities ....................................................................................................................... 16 2 Using the C/C++ Compiler ................................................................................................... 17 2.1 About the Compiler......................................................................................................... 18 2.2 Invoking the C/C++ Compiler ............................................................................................. 18 2.3 Changing the Compiler's Behavior with Options ....................................................................... 19 2.3.1 Linker Options ..................................................................................................... 26 2.3.2 Frequently Used Options......................................................................................... 28 2.3.3 Miscellaneous Useful Options ................................................................................... 29 2.3.4 Run-Time Model Options......................................................................................... 31 2.3.5 Symbolic Debugging Options .................................................................................... 34 2.3.6 Specifying Filenames ............................................................................................. 35 2.3.7 Changing How the Compiler Interprets Filenames ........................................................... 35 2.3.8 Changing How the Compiler Processes C Files .............................................................. 35 2.3.9 Changing How the Compiler Interprets and Names Extensions ............................................ 36 2.3.10 Specifying Directories............................................................................................ 36 2.3.11 Assembler Options............................................................................................... 37 2.3.12 Deprecated Options.............................................................................................. 38 2.4 Controlling the Compiler Through Environment Variables............................................................ 38 2.4.1 Setting Default Compiler Options (MSP430_C_OPTION) ................................................... 38 2.4.2 Naming One or More Alternate Directories (MSP430_C_DIR).............................................. 39 2.5 Controlling the Preprocessor ............................................................................................. 40 2.5.1 Predefined Macro Names ........................................................................................ 40 2.5.2 The Search Path for #include Files ............................................................................. 41 2.5.3 Support for the #warning and #warn Directives ............................................................... 42 2.5.4 Generating a Preprocessed Listing File (--preproc_only Option) ........................................... 42 2.5.5 Continuing Compilation After Preprocessing (--preproc_with_compile Option) ........................... 42 2.5.6 Generating a Preprocessed Listing File with Comments (--preproc_with_comment Option) ........... 42 2.5.7 Generating Preprocessed Listing with Line-Control Details (--preproc_with_line Option) ............... 43 2.5.8 Generating Preprocessed Output for a Make Utility (--preproc_dependency Option) ................... 43 2.5.9 Generating a List of Files Included with #include (--preproc_includes Option) ........................... 43 2.5.10 Generating a List of Macros in a File (--preproc_macros Option) ......................................... 43 2.6 Passing Arguments to main()............................................................................................. 43 2.7 Understanding Diagnostic Messages.................................................................................... 44 2.7.1 Controlling Diagnostic Messages ............................................................................... 45 2.7.2 How You Can Use Diagnostic Suppression Options ......................................................... 46 2.8 Other Messages ............................................................................................................ 47 2.9 Generating Cross-Reference Listing Information (--gen_cross_reference Option)................................ 47 2.10 Generating a Raw Listing File (--gen_preprocessor_listing Option)................................................. 47 2.11 Using Inline Function Expansion ......................................................................................... 49 2 Contents SLAU132P–June 2017 Submit Documentation Feedback Copyright © 2017, Texas Instruments Incorporated www.ti.com 2.11.1 Inlining Intrinsic Operators ...................................................................................... 50 2.11.2 Inlining Restrictions .............................................................................................. 50 2.12 Using Interlist ............................................................................................................... 51 2.13 Controlling Application Binary Interface ................................................................................. 52 2.14 Enabling Entry Hook and Exit Hook Functions......................................................................... 53 3 Optimizing Your Code......................................................................................................... 54 3.1 Invoking Optimization ...................................................................................................... 55 3.2 Performing File-Level Optimization (--opt_level=3 option)............................................................ 56 3.2.1 Creating an Optimization Information File (--gen_opt_info Option)......................................... 56 3.3 Program-Level Optimization (--program_level_compile and --opt_level=3 options)............................... 56 3.3.1 Controlling Program-Level Optimization (--call_assumptions Option)...................................... 57 3.3.2 Optimization Considerations When Mixing C/C++ and Assembly .......................................... 58 3.4 Link-Time Optimization (--opt_level=4 Option) ......................................................................... 59 3.4.1 Option Handling ................................................................................................... 59 3.4.2 Incompatible Types ............................................................................................... 59 3.5 Using Feedback Directed Optimization.................................................................................. 59 3.5.1 Feedback Directed Optimization ................................................................................ 60 3.5.2 Profile Data Decoder.............................................................................................. 62 3.5.3 Feedback Directed Optimization API ........................................................................... 63 3.5.4 Feedback Directed Optimization Summary .................................................................... 63 3.6 Using Profile Information to Analyze Code Coverage ................................................................. 64 3.6.1 Code Coverage.................................................................................................... 64 3.6.2 Related Features and Capabilities .............................................................................. 65 3.7 Accessing Aliased Variables in Optimized Code....................................................................... 66 3.8 Use Caution With asm Statements in Optimized Code ............................................................... 66 3.9 Automatic Inline Expansion (--auto_inline Option) ..................................................................... 67 3.10 Using the Interlist Feature With Optimization........................................................................... 67 3.11 Debugging Optimized Code............................................................................................... 69 3.12 Controlling Code Size Versus Speed ................................................................................... 69 3.13 What Kind of Optimization Is Being Performed? ....................................................................... 70 3.13.1 Cost-Based Register Allocation ................................................................................ 70 3.13.2 Alias Disambiguation