TMS320C28x Optimizing C/C Compiler V18.1.0.LTS User's Guide . - Analog

Transcription

TMS320C28x Optimizing C/C Compilerv18.1.0.LTSUser's GuideLiterature Number: SPRU514PJanuary 2018

ContentsPreface. 101Introduction to the Software Development Tools . 131.11.21.31.41.521415161616Using the C/C Compiler . 172.12.22.32.42.52.62.72.82.92.102Software Development Tools Overview .Compiler Interface .ANSI/ISO Standard .Output Files .Utilities .About the Compiler.Invoking the C/C Compiler .Changing the Compiler's Behavior with Options .2.3.1 Linker Options .2.3.2 Frequently Used Options .2.3.3 Miscellaneous Useful Options .2.3.4 Run-Time Model Options .2.3.5 Symbolic Debugging and Profiling Options .2.3.6 Specifying Filenames .2.3.7 Changing How the Compiler Interprets Filenames .2.3.8 Changing How the Compiler Processes C Files .2.3.9 Changing How the Compiler Interprets and Names Extensions .2.3.10 Specifying Directories.2.3.11 Assembler Options .2.3.12 Dynamic Linking .2.3.13 Deprecated Options .Controlling the Compiler Through Environment Variables .2.4.1 Setting Default Compiler Options (C2000 C OPTION) .2.4.2 Naming One or More Alternate Directories (C2000 C DIR) .Controlling the Preprocessor .2.5.1 Predefined Macro Names .2.5.2 The Search Path for #include Files .2.5.3 Support for the #warning and #warn Directives .2.5.4 Generating a Preprocessed Listing File (--preproc only Option) .2.5.5 Continuing Compilation After Preprocessing (--preproc with compile Option) .2.5.6 Generating a Preprocessed Listing File with Comments (--preproc with comment Option) .2.5.7 Generating Preprocessed Listing with Line-Control Details (--preproc with line Option) .2.5.8 Generating Preprocessed Output for a Make Utility (--preproc dependency Option) .2.5.9 Generating a List of Files Included with #include (--preproc includes Option) .2.5.10 Generating a List of Macros in a File (--preproc macros Option) .Passing Arguments to main() .Understanding Diagnostic Messages .2.7.1 Controlling Diagnostic Messages .2.7.2 How You Can Use Diagnostic Suppression Options .Other Messages .Generating Cross-Reference Listing Information (--gen cross reference Option) .Generating a Raw Listing File (--gen preprocessor listing Option) 940414141424242424242434445464647SPRU514P – January 2018Submit Documentation FeedbackCopyright 2018, Texas Instruments Incorporated

www.ti.com2.112.122.133Using Inline Function Expansion .2.11.1 Inlining Intrinsic Operators .2.11.2 Unguarded Definition-Controlled Inlining .2.11.3 Guarded Inlining and the INLINE Preprocessor Symbol .2.11.4 Inlining Restrictions .Using Interlist .Enabling Entry Hook and Exit Hook Functions .48494950515253Optimizing Your Code . .15Invoking Optimization .Performing File-Level Optimization (--opt level 3 option) .3.2.1 Creating an Optimization Information File (--gen opt info Option) .Program-Level Optimization (--program level compile and --opt level 3 options) .3.3.1 Controlling Program-Level Optimization (--call assumptions Option) .3.3.2 Optimization Considerations When Mixing C/C and Assembly .Link-Time Optimization (--opt level 4 Option) .3.4.1 Option Handling .3.4.2 Incompatible Types .Using Feedback Directed Optimization.3.5.1 Feedback Directed Optimization .3.5.2 Profile Data Decoder .3.5.3 Feedback Directed Optimization API .3.5.4 Feedback Directed Optimization Summary .Using Profile Information to Analyze Code Coverage .3.6.1 Code Coverage .3.6.2 Related Features and Capabilities .Special Considerations When Using Optimization .3.7.1 Use Caution With asm Statements in Optimized Code .3.7.2 Use the Volatile Keyword for Necessary Memory Accesses .Automatic Inline Expansion (--auto inline Option) .Using the Interlist Feature With Optimization .Data Page (DP) Pointer Load Optimization .Debugging and Profiling Optimized Code .3.11.1 Profiling Optimized Code .Controlling Code Size Versus Speed .Increasing Code-Size Optimizations (--opt for space Option).Compiler Support for Generating DMAC Instructions .3.14.1 Automatic Generation of DMAC Instructions .3.14.2 Assertions to Specify Data Address Alignment .3.14.3 dmac Intrinsic .What Kind of Optimization Is Being Performed? .3.15.1 Cost-Based Register Allocation .3.15.2 Alias Disambiguation .3.15.3 Branch Optimizations and Control-Flow Simplification .3.15.4 Data Flow Optimizations .3.15.5 Expression Simplification .3.15.6 Inline Expansion of Functions .3.15.7 Function Symbol Aliasing .3.15.8 Induction Variables and Strength Reduction .3.15.9 Loop-Invariant Code Motion .3.15.10 Loop Rotation .3.15.11 Instruction Scheduling .3.15.12 Register Variables .3.15.13 Register Tracking/Targeting .SPRU514P – January 2018Submit Documentation FeedbackContentsCopyright 2018, Texas Instruments 793

75.882828383848484848485868686878889The Post-Link Optimizer’s Role in the Software Development Flow .Removing Redundant DP Loads .Tracking DP Values Across Branches.Tracking DP Values Across Function Calls .Other Post-Link Optimizations .Controlling Post-Link Optimizations .5.6.1 Excluding Files (-ex Option) .5.6.2 Controlling Post-Link Optimization Within an Assembly File .5.6.3 Retaining Post-Link Optimizer Output (--keep asm Option) .5.6.4 Disable Optimization Across Function Calls (-nf Option ) .5.6.5 Annotating Assembly with Advice (--plink advice only option) .Restrictions on Using the Post-Link Optimizer .Naming the Outfile (--output file Option) .91929293939494949494949595TMS320C28x C/C Language Implementation . 966.16.26.36.46.56.66.76.84Invoking the Linker Through the Compiler (-z Option) .4.1.1 Invoking the Linker Separately .4.1.2 Invoking the Linker as Part of the Compile Step .4.1.3 Disabling the Linker (--compile only Compiler Option) .Linker Code Optimizations .4.2.1 Generating Function Subsections (--gen func subsections Compiler Option) .4.2.2 Generating Aggregate Data Subsections (--gen data subsections Compiler Option) .Controlling the Linking Process .4.3.1 Including the Run-Time-Support Library .4.3.2 Run-Time Initialization .4.3.3 Initialization by the Interrupt Vector .4.3.4 Global Object Constructors .4.3.5 Specifying the Type of Global Variable Initialization .4.3.6 Specifying Where to Allocate Sections in Memory .4.3.7 A Sample Linker Command File .Linking C28x and C2XLP Code .Post-Link Optimizer . 905.15.25.35.45.55.6679798080Linking C/C Code . 814.15Tail Merging .Autoincrement Addressing .Removing Comparisons to Zero .RPTB Generation (for FPU Targets Only).Characteristics of TMS320C28x C . 976.1.1 Implementation-Defined Behavior . 97Characteristics of TMS320C28x C . 101Using MISRA C 2004 . 102Data Types . 1036.4.1 Size of Enum Types . 1036.4.2 Support for 64-Bit Integers . 1036.4.3 C28x long double Floating-Point Type Change . 104Keywords . 1056.5.1 The const Keyword . 1056.5.2 The cregister Keyword . 1066.5.3 The interrupt Keyword . 1076.5.4 The restrict Keyword . 1086.5.5 The volatile Keyword . 108C Exception Handling . 110Register Variables and Parameters . 110The asm Statement . 111ContentsSPRU514P – January 2018Submit Documentation FeedbackCopyright 2018, Texas Instruments Incorporated

www.ti.com6.96.106.116.126.136.146.157Pragma Directives .6.9.1 The CALLS Pragma .6.9.2 The CHECK MISRA Pragma .6.9.3 The CLINK Pragma .6.9.4 The CODE ALIGN Pragma .6.9.5 The CODE SECTION Pragma .6.9.6 The DATA ALIGN Pragma .6.9.7 The DATA SECTION Pragma .6.9.8 The Diagnostic Message Pragmas .6.9.9 The FAST FUNC CALL Pragma .6.9.10 The FUNC ALWAYS INLINE Pragma .6.9.11 The FUNC CANNOT INLINE Pragma .6.9.12 The FUNC EXT CALLED Pragma .6.9.13 The FUNCTION OPTIONS Pragma .6.9.14 The INTERRUPT Pragma .6.9.15 The MUST ITERATE Pragma .6.9.16 The NO HOOKS Pragma .6.9.17 The RESET MISRA Pragma .6.9.18 The RETAIN Pragma.6.9.19 The SET CODE SECTION and SET DATA SECTION Pragmas.6.9.20 The UNROLL Pragma.The Pragma Operator .Object File Symbol Naming Conventions (Linknames) .Initializing Static and Global Variables .6.12.1 Initializing Static and Global Variables With the Linker .6.12.2 Initializing Static and Global Variables With the const Type Qualifier .Changing the ANSI/ISO C/C Language Mode .6.13.1 C99 Support (--c99) .6.13.2 Strict ANSI Mode and Relaxed ANSI Mode (--strict ansi and --relaxed ansi) .GNU and Clang Language Extensions .6.14.1 Extensions .6.14.2 Function Attributes .6.14.3 Variable Attributes .6.14.4 Type Attributes .6.14.5 Built-In Functions .6.14.6 Using the Byte Peripheral Type Attribute .Compiler Limits 133133134135Run-Time Environment . 1367.17.27.3Memory Model .7.1.1 Sections .7.1.2 C/C System Stack .7.1.3 Allocating .econst to Program Memory .7.1.4 Dynamic Memory Allocation .7.1.5 Initialization of Variables .7.1.6 Allocating Memory for Static and Global Variables.7.1.7 Field/Structure Alignment .7.1.8 Character String Constants .Register Conventions .7.2.1 TMS320C28x Register Use and Preservation .7.2.2 Status Registers .Function Structure and Calling Conventions .7.3.1 How a Function Makes a Call .7.3.2 How a Called Function Responds .SPRU514P – January 2018Submit Documentation FeedbackContentsCopyright 2018, Texas Instruments 31431445

ing the C Name Demangler . 187C Name Demangler Options . 187Sample Usage of the C Name Demangler . 188CLA Compiler . 19010.110.26C and C Run-Time Support Libraries .8.1.1 Linking Code With the Object Library .8.1.2 Header Files .8.1.3 Modifying a Library Function .8.1.4 Support for String Handling.8.1.5 Minimal Support for Internationalization .8.1.6 Allowable Number of Open Files .8.1.7 Library Naming Conventions .The C I/O Functions .8.2.1 High-Level I/O Functions .8.2.2 Overview of Low-Level I/O Implementation .8.2.3 Device-Driver Level I/O Functions .8.2.4 Adding a User-Defined Device Driver for C I/O .8.2.5 The device Prefix .Handling Reentrancy ( register lock() and register unlock() Functions) .Library-Build Process.8.4.1 Required Non-Texas Instruments Software .8.4.2 Using the Library-Build Process .8.4.3 Extending mklib .C Name Demangler . 158158159159159160160161161162Using Run-Time-Support Functions and Building Libraries . 1668.197.3.3 Special Case for a Called Function (Large Frames) .7.3.4 Accessing Arguments and Local Variables.7.3.5 Allocating the Frame and Accessing 32-Bit Values in Memory .Accessing Linker Symbols in C and C .Interfacing C and C With Assembly Language .7.5.1 Using Assembly Language Modules With C/C Code .7.5.2 Accessing Assembly Language Functions From C/C .7.5.3 Accessing Assembly Language Variables From C/C .7.5.4 Sharing C/C Header Files With Assembly Source .7.5.5 Using Inline Assembly Language .7.5.6 Using Intrinsics to Access Assembly Language Statements .Interrupt Handling .7.6.1 General Points About Interrupts .7.6.2 Using C/C Interrupt Routines .Integer Expression Analysis .7.7.1 Operations Evaluated With Run-Time

TMS320C28x Optimizing C/C Compiler v18.1.0.LTS User's Guide Literature Number: SPRU514P January 2018