Skip to content
This repository has been archived by the owner on May 18, 2019. It is now read-only.

Commit

Permalink
Change the default simulation opt. level to -Os
Browse files Browse the repository at this point in the history
Testing has shown that the performance of clang seems to be good enough
to enable -Os by default now. It's still slightly slower for most
models, especially small ones. But it should be a good default for
larger models.

The optimization level for simulations is now set by Susan, and
setCFlags will override this. This makes it possible for dynload to use
a different optimization level unless set by setCFlags. The disadvantage
is that getCFlags does not show what optimization level the simulations
will use (unless explicitly set by setCFlags), and this will be different
for C++ and C.

Note that this is how the MinGW version of OM worked before (except the
default for simulations was -O0).

OMEdit also has an option to change optimization level, so it should be
reasonably convenient for the user to change this to -O0 if desired.

Disabled -march=native as a default flag since it is annoying for FMUs.

Belonging to [master]:
  - #1869
  • Loading branch information
sjoelund authored and OpenModelica-Hudson committed Mar 14, 2018
1 parent 46dca42 commit 09e106c
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Compiler/Script/CevalScriptBackend.mo
Expand Up @@ -3288,7 +3288,7 @@ protected
dquote = if isWindows then "\"" else "'";
algorithm
CC := System.getCCompiler();
CFLAGS := System.stringReplace(System.getCFlags(),"${MODELICAUSERCFLAGS}","");
CFLAGS := "-Os "+System.stringReplace(System.getCFlags(),"${MODELICAUSERCFLAGS}","");
LDFLAGS := ("-L"+dquote+Settings.getInstallationDirectoryPath()+"/lib/"+System.getTriple()+"/omc"+dquote+" "+
"-Wl,-rpath,"+dquote+Settings.getInstallationDirectoryPath()+"/lib/"+System.getTriple()+"/omc"+dquote+" "+
System.getLDFlags()+" ");
Expand Down
4 changes: 1 addition & 3 deletions Compiler/Template/CodegenC.tpl
Expand Up @@ -5707,8 +5707,6 @@ case SIMCODE(modelInfo=MODELINFO(__), makefileParams=MAKEFILE_PARAMS(__), simula
<<
# Makefile generated by OpenModelica

# Simulations use -O0 by default
SIM_OR_DYNLOAD_OPT_LEVEL=
MODELICAUSERCFLAGS=
CC=cl
CXX=cl
Expand Down Expand Up @@ -5780,7 +5778,7 @@ case SIMCODE(modelInfo=MODELINFO(varInfo=varInfo as VARINFO(__)), delayedExps=DE
EXEEXT=<%makefileParams.exeext%>
DLLEXT=<%makefileParams.dllext%>
CFLAGS_BASED_ON_INIT_FILE=<%extraCflags%>
DEBUG_FLAGS=<% if boolOr(acceptMetaModelicaGrammar(), Flags.isSet(Flags.GEN_DEBUG_SYMBOLS)) then "-O0 -g"%>
DEBUG_FLAGS=<% if boolOr(getRunningTestsuite(), boolOr(acceptMetaModelicaGrammar(), Flags.isSet(Flags.GEN_DEBUG_SYMBOLS))) then "-O0" else "-Os"%><% if Flags.isSet(Flags.GEN_DEBUG_SYMBOLS) then " -g" %>
CFLAGS=$(CFLAGS_BASED_ON_INIT_FILE) $(DEBUG_FLAGS) <%makefileParams.cflags%> <%match sopt case SOME(s as SIMULATION_SETTINGS(__)) then '<%s.cflags%> ' /* From the simulate() command */%>
<% if stringEq(Config.simCodeTarget(),"JavaScript") then 'OMC_EMCC_PRE_JS=<%makefileParams.omhome%>/lib/<%getTriple()%>/omc/emcc/pre.js<%\n%>'
%>CPPFLAGS=<%makefileParams.includes ; separator=" "%> -I"<%makefileParams.omhome%>/include/omc/c" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME<% if stringEq(Config.simCodeTarget(),"JavaScript") then " -DOMC_EMCC"%><% if Flags.isSet(Flags.OMC_RELOCATABLE_FUNCTIONS) then " -DOMC_GENERATE_RELOCATABLE_CODE"%> -DOMC_MODEL_PREFIX=<%modelNamePrefix(simCode)%> -DOMC_NUM_MIXED_SYSTEMS=<%varInfo.numMixedSystems%> -DOMC_NUM_LINEAR_SYSTEMS=<%varInfo.numLinearSystems%> -DOMC_NUM_NONLINEAR_SYSTEMS=<%varInfo.numNonLinearSystems%> -DOMC_NDELAY_EXPRESSIONS=<%maxDelayedIndex%> -DOMC_NVAR_STRING=<%varInfo.numStringAlgVars%>
Expand Down
4 changes: 2 additions & 2 deletions Compiler/runtime/omc_config.h
Expand Up @@ -115,9 +115,9 @@
* Visual Studio then use the SSE instructions,
* not the normal i387 FPU
*/
#define DEFAULT_CFLAGS "${SIM_OR_DYNLOAD_OPT_LEVEL} -falign-functions -msse2 -mfpmath=sse ${MODELICAUSERCFLAGS}"
#define DEFAULT_CFLAGS "-falign-functions -msse2 -mfpmath=sse ${MODELICAUSERCFLAGS}"
#else
#define DEFAULT_CFLAGS "${SIM_OR_DYNLOAD_OPT_LEVEL} -falign-functions ${MODELICAUSERCFLAGS}"
#define DEFAULT_CFLAGS "-falign-functions ${MODELICAUSERCFLAGS}"
#endif
#if defined(__x86_64__)
/* -fPIC needed on x86_64! */
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Expand Up @@ -432,7 +432,7 @@ if test -z "$RUNTIMECFLAGS"; then
AC_TRY_LINK([], [return 0;], [AC_MSG_RESULT($CC ok);],[AC_MSG_ERROR($CC failed)])
CFLAGS="$FPIC"
AC_MSG_CHECKING([runtime compiler CFLAGS])
for flag in -O0 -falign-functions -march=native -mfpmath=sse; do
for flag in -falign-functions -mfpmath=sse; do
RUNTIMECFLAGS="$CFLAGS"
CFLAGS="$RUNTIMECFLAGS $flag -Werror"
AC_TRY_LINK([], [return 0;], [CFLAGS="$RUNTIMECFLAGS $flag"],[CFLAGS="$RUNTIMECFLAGS"])
Expand Down

0 comments on commit 09e106c

Please sign in to comment.