Compiling C/C++ Code
3-7
Optimizing C/C++ Code
3.2.2
Memory Dependencies
To maximize the efficiency of your code, the ’C6000 compiler schedules as
many instructions as possible in parallel. To schedule instructions in parallel,
the compiler must determine the relationships, or dependencies, between in-
structions. Dependency means that one instruction must occur before anoth-
er, for example, a variable must be loaded from memory before it can be used.
Because only independent instructions can execute in parallel, dependencies
inhibit parallelism.
-
If the compiler cannot determine that two instructions are independent (for
example,
b does not depend on a), it assumes a dependency and sched-
ules the two instructions sequentially accounting for any latencies needed
to complete the first instruction.
-
If the compiler can determine that two instructions are independent of one
another, it can schedule them in parallel.
Often it is difficult for the compiler to determine if instructions that access
memory are independent. The following techniques help the compiler deter-
mine which instructions are independent:
-
Use the restrict keyword to indicate that a pointer is the only pointer that
can point to a particular object in the scope in which the pointer is declared.
-
Use the –pm (program-level optimization) option, which gives the compiler
global access to the whole program or module and allows it to be more
aggressive in ruling out dependencies.
-
Use the –mt option, which allows the compiler to use assumptions that al-
low it to eliminate dependencies. Remember, using the –mt option on lin-
ear assembly code is equivalent to adding the .no_mdep directive to the
linear assembly source file. Specific memory dependencies should be
specified with the .mdep directive. For more information see section 4.4,
Assembly Optimizer Directives in the TMS320C6000 Optimizing C/C++
Compiler User’s Guide.