Docsity

Optimizing ANSI C Interpreter with Superoperators: Design and Implementation - Prof. Prasa, Study notes of Deductive Database Systems

Partial preview of the text

Download Optimizing ANSI C Interpreter with Superoperators: Design and Implementation - Prof. Prasa and more Study notes Deductive Database Systems in PDF only on Docsity!

Optimizing an ANSI C Interpreter

with Superoperators

By Todd A. Proebsting University of Arizona Presented by Jonathan Lanning University of Kansas

Overview

  • Introduction to the paper
  • Translator Output
  • Superoperator Optimization
  • Translator Design
  • Interpreter Generation
  • Implementation Details

Introduction

  • This paper will describe the design and implementation of hti , a hybrid translator/interpreter system for ANSI C that has been targeted to both the MIPS R3000 [KH92], and the SPARC [Sun91].
  • hti will introduce superoperators, a novel optimization technique for customizing interpreted code for space and time, Superoperators automatically fold many atomic operations into a more efficient compound operation in a fashion similar to supercombinators in functional language implementations.

Translator Output

  • For example, the tree for 2+3 would be ADD I (CNSTI, CNSTI ), where ADD I represents integer addition (ADD+ I)
  • For this VM, the translation of 2+3 would be similar to the following: ▫ byte 36 # CNSTI ▫. word 2 # immediate value ▫ byte 36 # CNSTI ▫. word 3 # immediate value ▫ byte 8 # ADDI
  • A prologue on the R3000 looks like the following:
  • main: ▫ li $24, 192 # put activation ▫ # record size in $ ▫ li $8, 96 # put location of ▫ # evaluation stack in ▫ la $25, $$11 # put location of ▫ # bytecode in $ ▫ j.prologue.scalar # jump to interpreter

Translator Design

  • Bytecode Emitter - hti translates lCC’S IR into bytecodes and attributes. The optimal translation of an IR tree into bytecodes is automated via tree pattern matching using burg.
  • Some sample patterns in the burg specification: ▫ stk : ADDP (INDIRP (stk), CNSTI) =5(1); ▫ stk : ADDP(stk, stk) =9(1); ▫ stk : CNSTI = 36 (1) ; ▫ stk : INDIRP(stk) = 77 (1) ;
  • Attribute Emitter - hti must emit node attributes after appropriate bytecodes. ▫ ADDI (MULI (x, CNSTI), CNSTI) becomes ▫ reg: CNSTI = (1) “emitsymbol (%P->syms [0] ->x. name, 4, 4) ; “

Interpreter Generation

  • The interpreter is implemented in assembly language.
  • The pattern matcher processes superoperator trees to determine how to best translate each into machine code.
  • The interpreter-generator selects instructions and allocates temporary registers for each superoperator.
  • Machine/emitter specifications are not limited to single-operator patterns. Complex IR tree patterns may better express the relationship between target machine instructions and lcc’s IR

System Obstacles

  • Limitations of system software on both R

and SPARC systems.

  • Neither machine’s assembler supports unaligned

initialized data words or halfwords.

Experimental Results

  • Comparisons were made for three programs:

▫ burg: A 5000-line tree pattern matcher generator, p ocessing a 136-rule specification. ▫ hti: The 13,000-line translator and subject of this paper, translating a 1117-line C file. ▫ loop: An empty for loop that executes 10^6 times

Experimental Results

Limitations and Extensions

  • Each additional superoperator contributes

decreasing marginal returns.

  • The C expression, x? y, cannot be expressed as a

single tree by lcc.

  • hti generates bytecode as. data assembler

directives and function prologues as assembly language instructions.

Discussion

  • For the MIPS R3000 and the SPARC, each machine required fewer than 800 lines of machine-specific code to be retargeted.
  • Superoperators make the interpreted code both smaller and faster.
  • Heuristics can automatically isolate beneficial superoperators from static or dynamic feedback information.

Acknowledgements and

References

  • These are on the last page…
  • You should have read them already!

Conclusion Cont’d

  • System Obstacles
  • Experimental Results
  • Limitations and Extensions
  • Related Work
  • Discussion
  • Acknowledgements and References

Questions?