# In-Class Design Exercise 3: SSA-IR Design Design an in-memory representation (data structure) for an SSA-based IR. Think about the following aspects: - Instructions: - How many result values? If one: how to handle operations with multiple results (e.g., add-with-overflow)? - How many operands? Can instructions have a variable number of operands? - How to handle constant operands? - How to refer to operands, esp. if instructions have multiple results? - How to store the instruction and operands in memory? (Hint: reduce the amount of necessary memory allocations for the common case.) - Think about representing other (constant) properties, e.g. load/store alignment, vector element index (e.g., for extraction), comparison predicates, . - Basic Blocks: - How to store enclosed instructions? - How to represent phi nodes -- instructions or block arguments? - How to manage control flow -- store successors/predecessors? Think about efficient construction and modification. - Memory Management: how? - Operations on the IR: (these should be executed efficiently) - Replacing all uses of an instruction result with a different value or a constant - Inserting an instruction or phi node/block argument - Removing an instruction or phi node/block argument - Changing the operand of an instruction - Finding predecessors and successors of a basic block - Finding all users of an instruction result ## Variant A: Fast Compilation The IR has a limited set of operations and types. Optimize the IR design for compilation speed, thereby focusing on efficient construction, iteration, and memory footprint. Modifying operations should work nonetheless. ## Variant B: Optimization The IR has a large set of possibly complex operations and complex types, including structures and fixed-size arrays. Optimize the IR for performing analyses and transformations and support the IR operations described above efficiently.