PinaVM and Tweto: Compilation and Optimization Techniques...

90
SystemC Overview PinaVM Tweto Conclusion PinaVM and Tweto: Compilation and Optimization Techniques for SystemC Matthieu Moy Verimag (Grenoble INP) Grenoble France Journées compil’, 04/2011 Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 1 / 53 >

Transcript of PinaVM and Tweto: Compilation and Optimization Techniques...

Page 1: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

PinaVM and Tweto: Compilation and OptimizationTechniques for SystemC

Matthieu Moy

Verimag (Grenoble INP)GrenobleFrance

Journées compil’, 04/2011

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 1 / 53 >

Page 2: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

Summary

1 SystemC and Transaction Level Modeling

2 Overview of PinaVM and Tweto

3 PinaVM: a SystemC Front-End

4 Tweto: TLM With Elaboration-Time Optimizations

5 Conclusion

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 2 / 53 >

Page 3: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

This section

1 SystemC and Transaction Level Modeling

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 3 / 53 >

Page 4: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

Modern Systems-on-a-Chip

Software

Hardware

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 4 / 53 >

Page 5: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

Modern Systems-on-a-Chip

Software

Hardware

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 4 / 53 >

Page 6: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

SystemC and Transaction-Level Modeling

(Fast) simulation essential in the design-flowI To write/debug softwareI To validate architectural choicesI As reference for hardware verification

Transaction-Level Modeling (TLM):I high level of abstraction,I suitable for

SystemC:I Industry-standard for high-level modeling (TLM, . . . ) of

Systems-on-a-Chip,I Library for C++ (compile with g++ -lsystemc. . . )

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 5 / 53 >

Page 7: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

SystemC and Transaction-Level Modeling

(Fast) simulation essential in the design-flowI To write/debug softwareI To validate architectural choicesI As reference for hardware verification

Transaction-Level Modeling (TLM):I high level of abstraction,I suitable for

SystemC:I Industry-standard for high-level modeling (TLM, . . . ) of

Systems-on-a-Chip,I Library for C++ (compile with g++ -lsystemc. . . )

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 5 / 53 >

Page 8: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

SystemC: Simple Example

N1 N2

SC_MODULE(not_gate) {sc_in<bool> in;sc_out<bool> out;

void compute (void) {// Behaviorbool val = in.read();out.write(!val);

}

SC_CTOR(not_gate) {SC_METHOD(compute);sensitive << in;

}};

int sc_main(int argc, char **argv) {// Elaboration phase (Architecture)// Instantiate modules ...not_gate n1("N1");not_gate n2("N2");sc_signal<bool> s1, s2;// ... and bind them togethern1.out.bind(s1);n2.out.bind(s2);n1.in.bind(s2);n2.in.bind(s1);

// Start simulationsc_start(100, SC_NS);return 0;

}

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 6 / 53 >

Page 9: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

Summary

1 SystemC and Transaction Level Modeling

2 Overview of PinaVM and Tweto

3 PinaVM: a SystemC Front-End

4 Tweto: TLM With Elaboration-Time Optimizations

5 Conclusion

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 7 / 53 >

Page 10: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

This section

2 Overview of PinaVM and Tweto

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 8 / 53 >

Page 11: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

This talk: PinaVM and Tweto

PinaVM: just like a compiler front-end,but for the SystemC library

IRFrontend

CodeGeneration Link Executable ExecutionC++

Optimizer

SystemC JIT

Kevin Marquet

Matthieu Moy Claire Maïza

ClaudeHelmstetter

Si-MohamedLamraoui

Tweto: use the information provided by PinaVM tooptimize the program better than C++ compilers

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 9 / 53 >

Page 12: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

This talk: PinaVM and Tweto

PinaVM: just like a compiler front-end,but for the SystemC library

IRFrontend

CodeGeneration Link Executable ExecutionC++

Optimizer

SystemC

JIT

Kevin Marquet

Matthieu Moy Claire Maïza

ClaudeHelmstetter

Si-MohamedLamraoui

Tweto: use the information provided by PinaVM tooptimize the program better than C++ compilers

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 9 / 53 >

Page 13: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

This talk: PinaVM and Tweto

PinaVM: just like a compiler front-end,but for the SystemC library

IRFrontend

CodeGeneration Link Executable ExecutionC++

Optimizer

SystemC JIT

Kevin Marquet

Matthieu Moy Claire Maïza

ClaudeHelmstetter

Si-MohamedLamraoui

Tweto: use the information provided by PinaVM tooptimize the program better than C++ compilers

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 9 / 53 >

Page 14: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

This talk: PinaVM and Tweto

PinaVM: just like a compiler front-end,but for the SystemC library

IRFrontend

CodeGeneration Link Executable ExecutionC++

Optimizer

SystemC JIT

Kevin Marquet

Matthieu Moy Claire Maïza

ClaudeHelmstetter

Si-MohamedLamraoui

Tweto: use the information provided by PinaVM tooptimize the program better than C++ compilers

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 9 / 53 >

Page 15: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

This talk: PinaVM and TwetoPinaVM: just like a compiler front-end,but for the SystemC library

IRFrontend

CodeGeneration Link Executable ExecutionC++

Optimizer

SystemC JIT

Kevin Marquet

Matthieu Moy Claire Maïza

ClaudeHelmstetter

Si-MohamedLamraoui

Tweto: use the information provided by PinaVM tooptimize the program better than C++ compilers

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 9 / 53 >

Page 16: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

This talk: PinaVM and TwetoPinaVM: just like a compiler front-end,but for the SystemC library

IRFrontend

CodeGeneration Link Executable ExecutionC++

Optimizer

SystemC JIT

Kevin Marquet

Matthieu Moy Claire Maïza

ClaudeHelmstetter

Si-MohamedLamraoui

Tweto: use the information provided by PinaVM tooptimize the program better than C++ compilers

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 9 / 53 >

Page 17: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

Summary

1 SystemC and Transaction Level Modeling

2 Overview of PinaVM and Tweto

3 PinaVM: a SystemC Front-End

4 Tweto: TLM With Elaboration-Time Optimizations

5 Conclusion

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 10 / 53 >

Page 18: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

This section

3 PinaVM: a SystemC Front-EndSystemC Front-EndsThe Beginning ...PinaVM Is Not A Virtual MachinePinaVM: Summary

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 11 / 53 >

Page 19: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

This section

3 PinaVM: a SystemC Front-EndSystemC Front-EndsThe Beginning ...PinaVM Is Not A Virtual MachinePinaVM: Summary

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 12 / 53 >

Page 20: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

SystemC Front-End

In this talk: Front-end = “Compiler front-end” (AKA “Parser”)

SystemC Frontend

IntermediateRepresentation

Backend

Intermediate Representation = Architecture + Behavior

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 13 / 53 >

Page 21: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

When you don’t need a front-end

Main application of SystemC: simulationI Just need a C++ compiler + the library

Testing, run-time verification, monitoring. . .I (Small) modifications of the SystemC library

IDE integration, Debugging . . .I Plain C++ front-ends can do most of the job.

No reference front-end available onhttp://www.systemc.org/

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 14 / 53 >

Page 22: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

When you don’t need a front-end

Main application of SystemC: simulationI Just need a C++ compiler + the library

Testing, run-time verification, monitoring. . .I (Small) modifications of the SystemC library

IDE integration, Debugging . . .I Plain C++ front-ends can do most of the job.

No reference front-end available onhttp://www.systemc.org/

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 14 / 53 >

Page 23: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

When you really need a front-end

Symbolic formal verification, high-level synthesis

I Need to extract almost everything about the platform

Visualization

I Need to extract the architecture. Behavior is less important

Introspection

I Information about the module (architecture) + possibly localvariables (behavior)

Advanced debugging features (architecture→ source code, . . . )

I Need architecture and behavior

SystemC-specific compiler optimizations

I Can use architecture information to optimize behavior

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 15 / 53 >

Page 24: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

When you really need a front-end

Symbolic formal verification, high-level synthesisI Need to extract almost everything about the platform

Visualization

I Need to extract the architecture. Behavior is less important

Introspection

I Information about the module (architecture) + possibly localvariables (behavior)

Advanced debugging features (architecture→ source code, . . . )

I Need architecture and behavior

SystemC-specific compiler optimizations

I Can use architecture information to optimize behavior

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 15 / 53 >

Page 25: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

When you really need a front-end

Symbolic formal verification, high-level synthesisI Need to extract almost everything about the platform

VisualizationI Need to extract the architecture. Behavior is less important

Introspection

I Information about the module (architecture) + possibly localvariables (behavior)

Advanced debugging features (architecture→ source code, . . . )

I Need architecture and behavior

SystemC-specific compiler optimizations

I Can use architecture information to optimize behavior

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 15 / 53 >

Page 26: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

When you really need a front-end

Symbolic formal verification, high-level synthesisI Need to extract almost everything about the platform

VisualizationI Need to extract the architecture. Behavior is less important

IntrospectionI Information about the module (architecture) + possibly local

variables (behavior)Advanced debugging features (architecture→ source code, . . . )

I Need architecture and behavior

SystemC-specific compiler optimizations

I Can use architecture information to optimize behavior

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 15 / 53 >

Page 27: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

When you really need a front-end

Symbolic formal verification, high-level synthesisI Need to extract almost everything about the platform

VisualizationI Need to extract the architecture. Behavior is less important

IntrospectionI Information about the module (architecture) + possibly local

variables (behavior)Advanced debugging features (architecture→ source code, . . . )

I Need architecture and behaviorSystemC-specific compiler optimizations

I Can use architecture information to optimize behavior

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 15 / 53 >

Page 28: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

When you really need a front-end

Symbolic formal verification, high-level synthesisI Need to extract almost everything about the platform

VisualizationI Need to extract the architecture. Behavior is less important

IntrospectionI Information about the module (architecture) + possibly local

variables (behavior)Advanced debugging features (architecture→ source code, . . . )

I Need architecture and behaviorSystemC-specific compiler optimizations

I Can use architecture information to optimize behavior

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 15 / 53 >

Page 29: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

Challenges and Solutions with SystemC Front-Ends1 C++ is complex (e.g. clang ≈ 200,000 LOC)

Write a C++ front-end or reuse one (g++, clang, edg, . . . )

2 Architecture built at runtime, with C++ code

Analyze elaboration phase or execute it

SC_MODULE(not_gate) {sc_in<bool> in;sc_out<bool> out;void compute (void) {

// Behaviorbool val = in.read();out.write(!val);

}

SC_CTOR(not_gate) {SC_METHOD(compute);sensitive << in;

}};

int sc_main(int argc, char **argv) {// Elaboration phase (Architecture)not_gate n1("N1");not_gate n2("N2");sc_signal<bool> s1, s2;// Bindingn1.out.bind(s1);n2.out.bind(s2);n1.in.bind(s2);n2.in.bind(s1);

// Start simulationsc_start(100, SC_NS); return 0;

}

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 16 / 53 >

Page 30: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

Challenges and Solutions with SystemC Front-Ends1 C++ is complex (e.g. clang ≈ 200,000 LOC) Write a C++ front-end or reuse one (g++, clang, edg, . . . )

2 Architecture built at runtime, with C++ code Analyze elaboration phase or execute it

SC_MODULE(not_gate) {sc_in<bool> in;sc_out<bool> out;void compute (void) {

// Behaviorbool val = in.read();out.write(!val);

}

SC_CTOR(not_gate) {SC_METHOD(compute);sensitive << in;

}};

int sc_main(int argc, char **argv) {// Elaboration phase (Architecture)not_gate n1("N1");not_gate n2("N2");sc_signal<bool> s1, s2;// Bindingn1.out.bind(s1);n2.out.bind(s2);n1.in.bind(s2);n2.in.bind(s1);

// Start simulationsc_start(100, SC_NS); return 0;

}

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 16 / 53 >

Page 31: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

Challenges and Solutions with SystemC Front-Ends1 C++ is complex (e.g. clang ≈ 200,000 LOC) Write a C++ front-end or reuse one (g++, clang, edg, . . . )

2 Architecture built at runtime, with C++ code Analyze elaboration phase or execute it

SC_MODULE(not_gate) {sc_in<bool> in;sc_out<bool> out;void compute (void) {

// Behaviorbool val = in.read();out.write(!val);

}

SC_CTOR(not_gate) {SC_METHOD(compute);sensitive << in;

}};

int sc_main(int argc, char **argv) {// Elaboration phase (Architecture)not_gate n1("N1");not_gate n2("N2");sc_signal<bool> s1, s2;// Bindingn1.out.bind(s1);n2.out.bind(s2);n1.in.bind(s2);n2.in.bind(s1);

// Start simulationsc_start(100, SC_NS); return 0;

}

Static Approaches

Dynamic Approaches

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 16 / 53 >

Page 32: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

Dealing with the architectureWhen it becomes tricky. . .

int sc_main(int argc, char **argv) {int n = atoi(argv[1]);int m = atoi(argv[2]);Node array[n][m];for (int i = 0; i < n; i++) {

for (int j = 0; j < m; j++) {array[i][j]

= new Node(...);...

}}

sc_start(100, SC_NS);return 0;

}

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 17 / 53 >

Page 33: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

Dealing with the architectureWhen it becomes tricky. . .

Static approach: cannotdeal with such codeDynamic approach: canextract the architecture forindividual instances of thesystem

int sc_main(int argc, char **argv) {int n = atoi(argv[1]);int m = atoi(argv[2]);Node array[n][m];for (int i = 0; i < n; i++) {

for (int j = 0; j < m; j++) {array[i][j]

= new Node(...);...

}}

sc_start(100, SC_NS);return 0;

}

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 17 / 53 >

Page 34: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

Dealing with the architectureWhen it becomes very tricky. . .

void compute(void) {for (int i = 0; i < n; i++) {

ports[i].write(true);}...

}

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 18 / 53 >

Page 35: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

Dealing with the architectureWhen it becomes very tricky. . .

One can unroll the loop tolet i become constant,Undecidable in the generalcase.

void compute(void) {for (int i = 0; i < n; i++) {

ports[i].write(true);}...

}

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 18 / 53 >

Page 36: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

Existing SystemC front-endsAn attempt at a classification

Static Dynamic

Home-made parserKaSCPar, sc2v,ParSyC, Scoot,SystemPerl. . .

Existing parser SystemCXML DATE09, Pinapa,PinaVM

Hard to classify: Quiny (purely dynamic approach)Commercial tools (closed, not detailed here): Synopsys, SemanticDesign, NC-SystemC (Cadence)

Self-advertisementA Theoretical and Experimental Review of SystemC Front-ends,Marquet et al. FDL 2010

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 19 / 53 >

Page 37: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

This section

3 PinaVM: a SystemC Front-EndSystemC Front-EndsThe Beginning ...PinaVM Is Not A Virtual MachinePinaVM: Summary

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 20 / 53 >

Page 38: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

Before it started: Pinapa [Moy et al, EMSOFT 05]AKA “my Ph.D’s front-end”

Pinapa’s principle:I Use GCC’s C++ front-endI Compile, dynamically load and execute the elaboration (sc_main)

Pinapa’s drawbacks:I Uses GCC’s internals (hard to port to newer versions)I Hard to installI No separate compilationI Based on complex Abstract Syntax Tree (AST)

(e.g. one construct for for, one for while and one for do ...while)

I Ad-hoc match of SystemC constructs in AST

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 21 / 53 >

Page 39: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

Static Single Assignment

Non-SSA program

x = 42;x = x + 1;y = x;

SSA program

x1 = 42;x2 = x1 + 1;y = x2;

SSA form widely used by modern compilers. . .. . . and by some formal verification tools1

Candidates C++ front-end providing SSA form:I GCC ≥ 4.0I LLVM

1Automatic translation of C/C++ parallel code into synchronous formalism using anSSA intermediate form. Besnard et al. AVOCS 2009

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 22 / 53 >

Page 40: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

LLVM: Low Level Virtual Machine

BitcodeFrontends

Backends

C

C++

...Optimizer

JITcompilation

CodeGeneration

Clean APIClean SSA intermediate representationMany tools available

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 23 / 53 >

Page 41: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

LLVM: Low Level Virtual Machine

BitcodeFrontends

Backends

C

C++

...Optimizer

JITcompilation

CodeGeneration

Clean APIClean SSA intermediate representationMany tools available

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 23 / 53 >

Page 42: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

LLVM: Low Level Virtual Machine

BitcodeFrontends

Backends

C

C++

...Optimizer

JITcompilation

CodeGeneration

Clean APIClean SSA intermediate representationMany tools available

Can we be here?

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 23 / 53 >

Page 43: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

This section

3 PinaVM: a SystemC Front-EndSystemC Front-EndsThe Beginning ...PinaVM Is Not A Virtual MachinePinaVM: Summary

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 24 / 53 >

Page 44: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

PinaVM: ArchitectureSystemC

Compilation(llvm-g++, llvm-link)

LLVM bitcode

Executeelaboration

Architecture

IdentifySC constructs

bitcode++

IntermediateRepresentation

Existing tools

Intermediate file

LLVM’s JIT(Just-In-Time)

Engine

Pattern-matchfunction names

SystemC’sdata-structure after

elaboration

PinaVM front-end

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 25 / 53 >

Page 45: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

PinaVM: ArchitectureSystemC

Compilation(llvm-g++, llvm-link)

LLVM bitcode

Executeelaboration

Architecture

IdentifySC constructs

bitcode++

IntermediateRepresentation

Existing tools

Intermediate file

LLVM’s JIT(Just-In-Time)

Engine

Pattern-matchfunction names

SystemC’sdata-structure after

elaboration

PinaVM front-end

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 25 / 53 >

Page 46: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

PinaVM: ArchitectureSystemC

Compilation(llvm-g++, llvm-link)

LLVM bitcode

Executeelaboration

Architecture

IdentifySC constructs

bitcode++

IntermediateRepresentation

Existing tools

Intermediate file

LLVM’s JIT(Just-In-Time)

Engine

Pattern-matchfunction names

SystemC’sdata-structure after

elaboration

PinaVM front-end

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 25 / 53 >

Page 47: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

SystemC constructs in LLVM’s bitcode

SystemC (C++) source code:

void compute() {out.write(true);

}

Bitcode after compilation with llvm-g++:define linkonce_odr void @_ZN6Source7computeEv(%struct.Source* %this) {entry:

%0 = alloca i8%"alloca point" = bitcast i32 0 to i32store i8 1, i8* %0, align 1%1 = getelementptr inbounds %struct.Source* %this, i32 0, i32 1%2 = getelementptr inbounds %"struct.sc_core::sc_out<bool>"* %1, i32 0, i32 0call void @_ZN7sc_core8sc_inoutIbE5writeERKb

(%"struct.sc_core::sc_inout<bool>"* %2, i8* %0)br label %return

return:ret void

}

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 26 / 53 >

Page 48: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

SystemC constructs in LLVM’s bitcode

SystemC (C++) source code:

void compute() {out.write(true);

}

Bitcode after compilation with llvm-g++:define linkonce_odr void @_ZN6Source7computeEv(%struct.Source* %this) {entry:

%0 = alloca i8%"alloca point" = bitcast i32 0 to i32store i8 1, i8* %0, align 1%1 = getelementptr inbounds %struct.Source* %this, i32 0, i32 1%2 = getelementptr inbounds %"struct.sc_core::sc_out<bool>"* %1, i32 0, i32 0call void @_ZN7sc_core8sc_inoutIbE5writeERKb

(%"struct.sc_core::sc_inout<bool>"* %2, i8* %0)br label %return

return:ret void

}

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 26 / 53 >

Page 49: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

SystemC constructs in LLVM’s bitcodeSimplified Bitcode:define void Source::compute(%this) {

; "out.write(true)" compiled into:; piece of code computing %data = true = 1

; piece of code computing %port as; a function of %this

call sc_core::sc_inout::write(%port, %data)ret void

}

Computation of %port and %data (argument of SystemCprimitive)

I Unknown statically (depend on this)I Computable for each module once we know this!

What PinaVM does:I Extract (slice) pieces of code computing %data and %portI JIT-compile and execute them after fixing %this

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 27 / 53 >

Page 50: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

SystemC constructs in LLVM’s bitcodeSimplified Bitcode:define void Source::compute(%this) {

; "out.write(true)" compiled into:; piece of code computing %data = true = 1

; piece of code computing %port as; a function of %this

call sc_core::sc_inout::write(%port, %data)ret void

}Computation of %port and %data (argument of SystemCprimitive)

I Unknown statically (depend on this)I Computable for each module once we know this!

What PinaVM does:I Extract (slice) pieces of code computing %data and %portI JIT-compile and execute them after fixing %this

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 27 / 53 >

Page 51: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

Back to the exampleComputation of “port” in port.write(true):

define linkonce_odr void@_ZN6Source7computeEv(%struct.Source* %this) {

entry:%0 = alloca i8%"alloca point" = bitcast i32 0 to i32store i8 1, i8* %0, align 1%1 = getelementptr inbounds

%struct.Source* %this, i32 0, i32 1%2 = getelementptr inbounds

%"struct.sc_core::sc_out<bool>"* %1, i32 0, i32 0

call void @_ZN7sc_core8sc_inoutIbE5writeERKb(%"struct.sc_core::sc_inout<bool>"* %2, i8* %0)

br label %returnreturn:

ret void}

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 28 / 53 >

Page 52: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

Back to the exampleComputation of “port” in port.write(true):

define linkonce_odr void@_ZN6Source7computeEv(%struct.Source* %this) {

entry:%0 = alloca i8%"alloca point" = bitcast i32 0 to i32store i8 1, i8* %0, align 1%1 = getelementptr inbounds

%struct.Source* %this, i32 0, i32 1%2 = getelementptr inbounds

%"struct.sc_core::sc_out<bool>"* %1, i32 0, i32 0

call void @_ZN7sc_core8sc_inoutIbE5writeERKb(%"struct.sc_core::sc_inout<bool>"* %2, i8* %0)

br label %returnreturn:

ret void}

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 28 / 53 >

Page 53: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

Back to the exampleComputation of “port” in port.write(true):

define private %"struct.sc_core::sc_inout<bool>"*function_to_jit(%struct.Source* %this) {

%1 = getelementptr inbounds%struct.Source* %this, i32 0, i32 1

%2 = getelementptr inbounds%"struct.sc_core::sc_out<bool>"* %1, i32 0, i32 0

ret %"struct.sc_core::sc_inout<bool>"* %2}

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 28 / 53 >

Page 54: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

PinaVM: Enriching the bitcode?SystemC

Compilation(llvm-g++, llvm-link)

LLVM bitcode

Executeelaboration

Architecture

IdentifySC constructs

bitcode++

IntermediateRepresentation

Executedependencies

...%port = expr1%data = expr2SCWrite- data = ??- port = ??

...

SystemC constructis still a normal function

%thisis fixed

%this not knownCannot compute %port

...%port = expr1%data = expr2call write %port, %data...

...%port = expr1%data = expr2SCWrite

- data =

{Process 0→ data d0Process 1→ data d1

}

- port =

{Process 0→ port p0Process 1→ port p1

}...

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 29 / 53 >

Page 55: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

PinaVM: Enriching the bitcode?SystemC

Compilation(llvm-g++, llvm-link)

LLVM bitcode

Executeelaboration

Architecture

IdentifySC constructs

bitcode++

IntermediateRepresentation

Executedependencies

...%port = expr1%data = expr2SCWrite- data = ??- port = ??

...

SystemC constructis still a normal function

%thisis fixed

%this not knownCannot compute %port

...%port = expr1%data = expr2call write %port, %data...

...%port = expr1%data = expr2SCWrite

- data =

{Process 0→ data d0Process 1→ data d1

}

- port =

{Process 0→ port p0Process 1→ port p1

}...

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 29 / 53 >

Page 56: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

This section

3 PinaVM: a SystemC Front-EndSystemC Front-EndsThe Beginning ...PinaVM Is Not A Virtual MachinePinaVM: Summary

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 30 / 53 >

Page 57: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

Summary

PinaVM relies on executability (JIT Compiler) for:I Execution of elaboration phase (≈ like Pinapa)I Execution of sliced pieces of code

Using a virtual machine to write a SystemC front-end is a reallygood idea!Could have benefited from some higher-level constructs inbytecode (builtin object and method calls?)

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 31 / 53 >

Page 58: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

PinaVM

Open Source:http://gitorious.org/pinavm/pages/Home

Still a prototype, but very few fundamental limitations≈ 3000 lines of C++ code on top of LLVMExperimental back-ends for

I Model-checking (using SPIN)I Execution (Tweto)

PinaVM: a SystemC front-end based on an executableintermediate representation. Marquet et al. EMSOFT 2010.

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 32 / 53 >

Page 59: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

Summary

1 SystemC and Transaction Level Modeling

2 Overview of PinaVM and Tweto

3 PinaVM: a SystemC Front-End

4 Tweto: TLM With Elaboration-Time Optimizations

5 Conclusion

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 33 / 53 >

Page 60: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

This section

4 Tweto: TLM With Elaboration-Time OptimizationsLimitations of Plain C++ Compilers and How to do BetterExploiting Constant DataDealing with Addresses: Protocol-Aware Optimizations

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 34 / 53 >

Page 61: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

This section

4 Tweto: TLM With Elaboration-Time OptimizationsLimitations of Plain C++ Compilers and How to do BetterExploiting Constant DataDealing with Addresses: Protocol-Aware Optimizations

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 35 / 53 >

Page 62: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

Typical Transaction Journey

Bus

CPU

RAM

T1 T2

0x00000x1000

T1

0x20000x3000

T2

0x50000x6000

RAM

Call virtual methodon socket

Forward methodcall to target socket

AddressDecoding

Another virtualmethod call

Forwarded totarget socket

Ends-up callingtarget module’s

method

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 36 / 53 >

Page 63: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

Typical Transaction Journey

Bus

CPU

RAM

T1 T2

0x00000x1000

T1

0x20000x3000

T2

0x50000x6000

RAM...

socket.write(addr,data);...

status write(addr,data) {mem[addr] = data;

}

Call virtual methodon socket

Forward methodcall to target socket

AddressDecoding

Another virtualmethod call

Forwarded totarget socket

Ends-up callingtarget module’s

method

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 36 / 53 >

Page 64: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

Typical Transaction Journey

Bus

CPU

RAM

T1 T2

0x00000x1000

T1

0x20000x3000

T2

0x50000x6000

RAM...

socket.write(addr,data);...

status write(addr,data) {mem[addr] = data;

}

Call virtual methodon socket

Forward methodcall to target socket

AddressDecoding

Another virtualmethod call

Forwarded totarget socket

Ends-up callingtarget module’s

method

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 36 / 53 >

Page 65: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

Typical Transaction Journey

Bus

CPU

RAM

T1 T2

0x00000x1000

T1

0x20000x3000

T2

0x50000x6000

RAM...

socket.write(addr,data);...

status write(addr,data) {mem[addr] = data;

}

Call virtual methodon socket

Forward methodcall to target socket

AddressDecoding

Another virtualmethod call

Forwarded totarget socket

Ends-up callingtarget module’s

method

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 36 / 53 >

Page 66: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

Typical Transaction Journey

Bus

CPU

RAM

T1 T2

0x00000x1000

T1

0x20000x3000

T2

0x50000x6000

RAM...

socket.write(addr,data);...

status write(addr,data) {mem[addr] = data;

}

Call virtual methodon socket

Forward methodcall to target socket

AddressDecoding

Another virtualmethod call

Forwarded totarget socket

Ends-up callingtarget module’s

method

Many costly operations for a simple functionalityWork-around: backdoor access (DMI = Direct Memory Interface)

I CPU get a pointer to RAM’s internal dataI Manual, dangerous optimization

Can a compiler do as good as DMI, automatically?

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 36 / 53 >

Page 67: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

Typical Transaction Journey

Bus

CPU

RAM

T1 T2

0x00000x1000

T1

0x20000x3000

T2

0x50000x6000

RAM...

socket.write(addr,data);...

status write(addr,data) {mem[addr] = data;

}

Call virtual methodon socket

Forward methodcall to target socket

AddressDecoding

Another virtualmethod call

Forwarded totarget socket

Ends-up callingtarget module’s

method

Many costly operations for a simple functionalityWork-around: backdoor access (DMI = Direct Memory Interface)

I CPU get a pointer to RAM’s internal dataI Manual, dangerous optimization

Can a compiler do as good as DMI, automatically?

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 36 / 53 >

Page 68: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

Basic Ideas

Do statically what can be done statically ...... considering “statically” = “after elaboration”Examples:

I Virtual function resolutionI Inlining through SystemC portsI Static address resolution

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 37 / 53 >

Page 69: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

This section

4 Tweto: TLM With Elaboration-Time OptimizationsLimitations of Plain C++ Compilers and How to do BetterExploiting Constant DataDealing with Addresses: Protocol-Aware Optimizations

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 38 / 53 >

Page 70: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

Constant data

Things that are not const for C++, but constant for SystemC:I this pointer for each module⇒ becomes constant if we specialize functions

I Architecture (set during elaboration, does not change after)⇒ marked (by user or within SystemC) withtweto_mark_const()

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 39 / 53 >

Page 71: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

Exploiting constant data

Specialize process: for each instance, duplicate body, settingthis pointer to its valueExecute constant loads using data collected bytweto_mark_const()

Resolve indirect calls once the called function is constantSpecialize calls when their argument is constant

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 40 / 53 >

Page 72: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

Specialize Process (simplified)Starting point:define @systemc_process(%struct.Module* %this) {entry:

...

... ; uses %this

...}

Intermediate:define @systemc_process_specialized() {entry:

%this = %struct.Module* <addr-of-this-module>;call @systemc_process (%this)

; use llvm::inlineFunction on this call}

Result: function with this replaced by constant

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 41 / 53 >

Page 73: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

Execute constant loads

Replace inttoptr instructions by constant integer if possibleinttoptr syntax:<result> = inttoptr <ty> <value> to <ty2>

Example:

; X = (int *)42;%X = inttoptr i32 42 to i32*; Y = *X%Y = load i32* %X

%Y = i32* <value at address 42>

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 42 / 53 >

Page 74: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

Resolve indirect calls

Replace indirect call instructions by direct call.Example:

%1 = load <pointer_to_fun>%2 = call %1(<function args>)

%2 = call fun(<function args>)

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 43 / 53 >

Page 75: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

Specialize calls

Replace calls with constant args by specialized functions.Example:

read(int a){a+1;}

read_42(){42+1;}

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 44 / 53 >

Page 76: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

This section

4 Tweto: TLM With Elaboration-Time OptimizationsLimitations of Plain C++ Compilers and How to do BetterExploiting Constant DataDealing with Addresses: Protocol-Aware Optimizations

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 45 / 53 >

Page 77: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

What can we hope? (1)

#define TIMER_ADDR 0x1000#define START_REG_OFFSET 4

cpu::compute () {...// start timersocket.write(TIMER_ADDR+START_REG_OFFSET, 0);...

}

⇒ address known statically,but address resolution still done dynamically

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 46 / 53 >

Page 78: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

What can we hope? (2)

cpu::compute () {...// Clear portion of RAMfor (addr = 0x1000; addr < 0x2000; addr++) {

socket.write(addr, 0);}...

}

⇒ address not constant,but simple analysis could allow static address resolution

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 47 / 53 >

Page 79: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

Dealing with addresses Statically

Bus

CPU

RAM

...

socket.write(0x1000,data);...

status write(addr,data) {mem[addr] = data;

}

0x00000x1000

T1

0x20000x3000

T2

0x50000x6000

RAM

Get actualport addr

from PinaVM

Follow pathto bus Address

Decoding

Find targetsocket at this

address

Find functionin targetmodule

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 48 / 53 >

Page 80: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

Dealing with addresses Statically

Bus

CPU

RAM

...

socket.write(0x1000,data);...

status write(addr,data) {mem[addr] = data;

}

0x00000x1000

T1

0x20000x3000

T2

0x50000x6000

RAM

Get actualport addr

from PinaVM

Follow pathto bus Address

Decoding

Find targetsocket at this

address

Find functionin targetmodule

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 48 / 53 >

Page 81: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

Dealing with addresses Statically

Bus

CPU

RAM

...

socket.write(0x1000,data);...

status write(addr,data) {mem[addr] = data;

}

0x00000x1000

T1

0x20000x3000

T2

0x50000x6000

RAM

Get actualport addr

from PinaVM

Follow pathto bus

AddressDecoding

Find targetsocket at this

address

Find functionin targetmodule

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 48 / 53 >

Page 82: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

Dealing with addresses Statically

Bus

CPU

RAM

...

socket.write(0x1000,data);...

status write(addr,data) {mem[addr] = data;

}

0x00000x1000

T1

0x20000x3000

T2

0x50000x6000

RAM

Get actualport addr

from PinaVM

Follow pathto bus Address

Decoding

Find targetsocket at this

address

Find functionin targetmodule

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 48 / 53 >

Page 83: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

Dealing with addresses Statically

Bus

CPU

RAM

...

socket.write(0x1000,data);...

status write(addr,data) {mem[addr] = data;

}

0x00000x1000

T1

0x20000x3000

T2

0x50000x6000

RAM

Get actualport addr

from PinaVM

Follow pathto bus Address

Decoding

Find targetsocket at this

address

Find functionin targetmodule

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 48 / 53 >

Page 84: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

Dealing with addresses Statically

Bus

CPU

RAM

...

socket.write(0x1000,data);...

status write(addr,data) {mem[addr] = data;

}

0x00000x1000

T1

0x20000x3000

T2

0x50000x6000

RAM

Get actualport addr

from PinaVM

Follow pathto bus Address

Decoding

Find targetsocket at this

address

Find functionin targetmodule

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 48 / 53 >

Page 85: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

Dealing with addresses Statically

Bus

CPU

RAM

...

socket.write(0x1000,data);...

status write(addr,data) {mem[addr] = data;

}

0x00000x1000

T1

0x20000x3000

T2

0x50000x6000

RAM

Get actualport addr

from PinaVM

Follow pathto bus Address

Decoding

Find targetsocket at this

address

Find functionin targetmodule

Possible optimizations:I Replace call to socket.write() with RAM.write()I Possibly inline it

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 48 / 53 >

Page 86: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

Optimizing Register Banks// typical code executed when receiving transactionstatus target::write(addr, data) {

switch(addr) {case REG_1:

f();break;

case REG_2:g();break;

default:return TLM_ADDRESS_ERROR_RESPONSE;

}return TLM_OK_RESPONSE;

}

⇒ Accesses to constant addresses could execute f or g directly

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 49 / 53 >

Page 87: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

Summary

1 SystemC and Transaction Level Modeling

2 Overview of PinaVM and Tweto

3 PinaVM: a SystemC Front-End

4 Tweto: TLM With Elaboration-Time Optimizations

5 Conclusion

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 50 / 53 >

Page 88: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

This section

5 Conclusion

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 51 / 53 >

Page 89: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

PinaVM and Tweto

PinaVM (front-end): prototype implemented(Kevin Marquet, Post-Doc Verimag; myself when I have time)Tweto (optimizer): work in progress(Claude Helmstetter, Post-doc LIAMA;Si-Mohamed Lamraoui, TER M1 Verimag)Other back-ends for PinaVM:

I Promela: model-checking with SPIN(prototype; Kevin Marquet)

I Simple: abstract interpretation with ConcurInterproc(draft; Kevin Marquet)

I 42: Control Contracts(draft; Pierre-Yves Delahaye, TER Ensimag)

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 52 / 53 >

Page 90: PinaVM and Tweto: Compilation and Optimization Techniques ...matthieu-moy.fr/spip/IMG/pdf/tweto-slides.pdf · SystemCOverviewPinaVMTwetoConclusion Summary 1 SystemC and Transaction

SystemC Overview PinaVM Tweto Conclusion

Thank you

Questions?

http://gitorious.org/pinavm/pages/Home

Matthieu Moy (Verimag) PinaVM and Tweto Journées compil’, 04/2011 < 53 / 53 >