Opened 10 years ago
Last modified 10 years ago
#2852 accepted defect
Use the same C-code for identical functions
Reported by: | Martin Sjölund | Owned by: | Martin Sjölund |
---|---|---|---|
Priority: | high | Milestone: | Future |
Component: | Code Generation | Version: | trunk |
Keywords: | Cc: | Adrian Pop |
Description
With calling of functions through components, identical functions are often generated. The C compiler will generate equivalent code for both, which is not desirable. We should figure out which functions are equivalent and replace calls to one with calls to another (or simply alias them via function pointer).
model N function f input Real r; output Real o := r; end f; end N; model M N n1,n2; Real r1 = n1.f(time), r2 = n2.f(time); end M;
A Hash from DAE.Function to Absyn.Path should be sufficient (or String->Path and manually DAEDump the function to speed up any hash conflicts).
Change History (4)
comment:1 by , 10 years ago
comment:2 by , 10 years ago
Owner: | changed from | to
---|---|
Status: | new → accepted |
I guess I can try to implement it
comment:3 by , 10 years ago
The new frontend actually does things wrong here. The functions are no longer unique, creating only one function N.f instead of the expected one :(
model N constant Real c; function x input Real r; output Real o := r; end x; function f input Real r; output Real o := x(sum(c*i for i in r:r+1)); end f; end N; model M N n1(c=1),n2(c=2); Real r1 = n1.f(time), r2 = n2.f(time); end M;
The model above only gives one N.f, with the wrong c set for n2.f(time)
function N.f input Real r; output Real o = N.x(sum(i for i in r:1.0 + r)); end N.f; function N.x input Real r; output Real o = r; end N.x; class M constant Real n1.c = 1.0; constant Real n2.c = 2.0; Real r1 = N.f(time); Real r2 = N.f(time); end M;
Good ticket. Who can do it?