Skip to content

Commit

Permalink
Allow llvm optimzation pass opt to be called at various optimization …
Browse files Browse the repository at this point in the history
…levels

The llvm opt tool does various IR to IR optimization transformations.
This tool is only invoked if -O (or -O0-3) is specified on the command line.

The file generated is basefile_opt.(mb|ib) and is deleted unless -keep
is also specified.
  • Loading branch information
peter mckinna committed Nov 3, 2017
1 parent c901779 commit e75323b
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions m3-sys/cminstall/src/config-no-install/Unix.common
Expand Up @@ -78,8 +78,9 @@ if not defined("m3back_debug")
m3back_debug = "-gstabs+"
end

%default optimization level if passed -O
if not defined("m3back_optimize")
m3back_optimize = "-O2 -Wuninitialized"
m3back_optimize = "-O2"
end

if not defined("m3back_pic")
Expand Down Expand Up @@ -115,6 +116,7 @@ proc m3_backend(source, object, optimize, debug) is
m3back_m64 ]
if optimize
args += m3back_optimize
args += "-Wuninitialized"
end
if debug
args += m3back_debug
Expand Down Expand Up @@ -161,7 +163,7 @@ if not defined("llvmback_debug")
end

if not defined("llvmback_optimize")
llvmback_optimize = "-O0"
llvmback_optimize = "-O2"
end

if not defined("llvmback_pic")
Expand All @@ -174,19 +176,31 @@ if not defined("llvm_backend")
%local t = try_exec ("llvm-dis", outfile)

local args = [ "-disable-fp-elim"]
local llvmopt = ""

args += "-filetype=" & filetype

if optimize
args += llvmback_optimize
local tmp = split(source,".")
llvmopt = tmp[0] & "_opt." & tmp[1]
local opt_ret = try_exec ("@opt", llvmback_optimize, source, "-o", llvmopt )
%reset source for llc
source = llvmopt
else
args += "-O0"
end
if debug
args += llvmback_debug
end
args += llvmback_pic

local llvmback = "@llc"
return try_exec (llvmback, args, source, "-o", outfile )
local llc_ret = try_exec (llvmback, args, source, "-o", outfile )
if optimize and not defined ("M3_KEEP_FILES")
DeleteFile(llvmopt)
end
return llc_ret
end % proc llvm_backend

end % if not defined("llvm_backend")
Expand Down

0 comments on commit e75323b

Please sign in to comment.