1 / 43

Storage Allocation for Embedded Processors

Storage Allocation for Embedded Processors. By Jan Sjodin & Carl von Platen Present by Xie Lei ( PLS Lab). Memory In Embedded Sys. Several memory areas (on-chip, off-chip) SRAM DRAM E 2 PROM … Different properties

brynne-vang
Download Presentation

Storage Allocation for Embedded Processors

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Storage Allocation for Embedded Processors By Jan Sjodin & Carl von Platen Present by Xie Lei ( PLS Lab)

  2. Memory In Embedded Sys • Several memory areas (on-chip, off-chip) SRAM DRAM E2PROM… • Different properties access time size restricted to native pointer types

  3. Pointer Types • Different in length 8-bit 16-bit . . . • Different in cost 8-bit is cheaper than 16-bit

  4. Problem to solve • Allocate data and select pointer types in the most efficient way • Frequently accessed data in fast memory • Frequently used pointers & expression have cheap pointer type • Manual  Automatic

  5. Road Map • Brief Background • Memory Organization & Model • Cost Model • Formulation & Discussion • Implementation • Experiments & Results • Conclusion

  6. Why Allocation ? Different pointer types to access different types of memories improves performance : • execution speed • program size • energy consumption • production cost . . .

  7. Allocation Problem • Allocating each variable of a program in a memory segment • Assigning a native pointer type to each pointer expression of the same program • Dependency : latter depends on former ---take both into consider simultaneously

  8. Current solution & Drawback • Manually locate variables and select native pointer types: pragmas or keywords • Drawbacks time-consuming source code non-portable

  9. New Solution • A model which can describe architectures with irregular memory organization and several pointer types. • Derive integer linear program from the model • Solve the program = Solve the allocation problem • Optimal solution ( under assumption )

  10. An Important Condition • Condition : All memory accesses in the program should be known -- whole program optimization ( WPO ) • points-to set :Set of the objects a restricted pointer may point to • Reason The points-to set of a pointer must be allocated where that pointer can reach

  11. Road Map • Brief Background • Memory Organization & Model • Cost Model • Formulation & Discussion • Implementation • Experiment & Results • Conclusion

  12. Features in Embedded Processors • On-chip memory : efficiently • Zero page : use smaller pointer types , fast , compact code • Harvard architectures : different native pointer representations and addressing mode are used for program and data address space

  13. AVR RAM Configuration

  14. Separate VS Single address space (1) • Separate address space • disjoint sets of pointer types • know points-to sets to allocate data • use separate address buses • different memory access instructions use different pointer types as operands

  15. Separate VS Single address space (2) • Single address space • A general native pointer type • No restriction on allocation • Try to use cheaper pointer type ( need to know the point-to set to decide if that pointer type can work)

  16. Code Size Contrast

  17. An Abstract Memory Model • Memory Model : Memory Segments, Pointer Types , Relation • Memory Segments : subsets of the total memory space, uniform with properties( speed, addressing modes). M1 , M2 , M3 . . . MS • Pointer Types : P1 ,P2 ,P3 . . . PT • Relation : Pointer Type to Memory Segments

  18. Memory Model • Size( Mj) : number of addressable units of storage in Memory Segment Mj • Relation function Mem( Pk )={ j | Pk can point to Mj } In which Pk Pointer Type • Memory Model can be expressed by a table

  19. Example: AVR

  20. Road Map • Brief Background • Memory Organization & Model • Cost Model • Formulation & Discussion • Implementation • Experiment & Results • Conclusion

  21. Two Kinds of Cost • Cost : Static cost + Dynamic cost • Static cost : the size of a program, expressed by the sum of all statements in instruction set STMTR • Dynamic cost : execution time, for each statement need to be scaled by the estimate execution frequency of the statement

  22. Expressions • V = {v1 , v2 . . . vN } : set of variables referred to in the source program • Size(v) : number of allocation units required by v • STMTR : set of individual occurrences of instructions • E = {e1 , e2 . . . eM } : set of pointer expressions

  23. Functions • PtrExp : STMTR  E allow the client of the storage allocator to modify the type of single pointer expressions independently • Seg(v) : V M , the segment where a variable is allocated • PtrT(e) : EP, the pointer type a pointer expression is assigned

  24. Cost of A Statement ( 1 ) • For each statement in STMTR , we can have pointer cost and variable cost • ptrcostS ( e, t ) : pointer cost , the cost contribution of selecting “ t ” as the pointer type for pointer expression “ e ” • varcostS ( v, m ) : variable cost , the cost contribution of variable “ v ” if it is located in memory segment “ m ”

  25. Cost of A Statement ( 2 ) • The cost of a particular solution is defined in terms of the cost contribution of each statement in STMTR Cost(S) = ∑ (eE)ptrcostS ( e, PtrT (e) ) + ∑ (vV)varcostS ( v, Seg(v) )

  26. Road Map • Brief Background • Memory Organization & Model • Cost Model • Formulation & Discussion • Implementation • Experiment & Results • Conclusion

  27. BIP Formulation • BIP : Binary Integer Program • The storage allocation problem is formulated as a BIP • Based on the model of Memory Organization and the cost model

  28. Feasible Solution • Two condition must be satisfied • Total size of the variables in a single memory segment ≤ size of the segment • Pointer expression that may point to a variable must be assigned a type that can access the segment where that variable is • Find a feasible solution with minimal cost !

  29. BIP ( 1 ) • Each variable can be placed in exactly one memory segment xi1+ xi2 . . . + xiS=1 , 1 ≤ i ≤ N • Total size of the variables in a segment can not be greater than the size of the segment Size(v1) x1m+ Size(v2) x2m+ . . . + Size(vN) xNm ≤ Size(Mm) , 1 ≤ m ≤ S

  30. BIP ( 2 ) • Each pointer expression have a unique pointer type yj1+ yj2 . . . + yjT = 1 , 1 ≤ j≤ M • Type of a pointer expression be general enough for all the variables in its points-to set Seg(v)  Mem ( PtrT( ej ) ) , v Pt ( ej )

  31. BIP ( 3 ) • Objective function is the cost of the solution

  32. Discussion : Scalability • Number of variables and number of pointer expressions grow linearly in the size of the program • Number of memory segments and the number of pointer types depend on target architecture , so can be regarded as constants

  33. Discussion : Accuracy • Fundamental to the model : cost of a statement can be expressed as linear combination of cost from variables and pointer expressions ---- Not precise • Some architectures may represent pointers with multiple machine words, so loading a pointer need several instructions

  34. Road Map • Brief Background • Memory Organization & Model • Cost Model • Formulation & Discussion • Implementation • Experiment & Results • Conclusion

  35. Compiler Framework

  36. WPO Prototype • Points-to analysis estimate the points-to set of each pointer • ILP solver Information about all global variables and pointers is put into the solver to get an allocation

  37. Modified ICCAVR • Compile the C source code and use the allocation information by WPO to modify the memory attributes of variables • Allocation information is used during the parsing stage to modify the memory attributes of variables

  38. Road Map • Brief Background • Memory Organization & Model • Cost Model • Formulation & Discussion • Implementation • Experiments & Results • Conclusion

  39. Experiments • Measure the execution time and code size of 6 benchmarks • Results are compared with code compiled on the standard ICCAR compiler • Different version of AVR microcontroller , internal memory vary from 0 to 4KB or more ( 64KB and 16KB)

  40. Results • Results vary a lot with benchmarks CPU intensive or Memory intensive • Code size decreased slightly for most benchmarks ( Special : statemate ) • Execution time improved for most benchmarks( also Statemate )

  41. Road Map • Brief Background • Memory Organization & Model • Cost Model • Formulation & Discussion • Implementation • Experiments & Results • Conclusion

  42. Conclusion • Model of memory hierarchies for storage allocation for embedded system processors • Implement a memory allocator using ILP to get an optimal allocation under the memory model • Improve program size and speed • Automatically done , portable , robust : no need to include target-specific information in source code

  43. The End Thank You !

More Related