How to use CompilerOptions?

10

5

The refpage for FunctionCompile's option CompilerOptions is empty of examples:

enter image description here

Does anyone know what keys and values can be used in the Association given to CompilerOptions?

M.R.

Posted 2020-06-04T21:56:23.870

Reputation: 30 727

Answers

8

These are accepted as valid rules for CompilerOptions -> { rules }:

Options@Compile`CompileToCodeFunction
(*
{"AbortHandling" :> Compile`Utilities`$AbortHandling, 
 "AddRuntime" -> "SharedLibrary", "CacheExpr" -> False, 
 "DataLayout" -> Automatic, "Debug" -> False, 
 "EntryFunctionName" -> Automatic, "ErrorFunction" -> Null, 
 "ExceptionsModel" :> Compile`Utilities`$ExceptionsModel, 
 "ExecutionEngine" -> Automatic, "ExpressionInterface" -> Automatic, 
 "ExternalLibraries" -> {}, "ExtraPasses" -> {}, 
 "InlinePolicy" -> Automatic, "InvocationMode" -> "WolframEngine", 
 "LazyJIT" -> False, "LLVMOptimization" -> Automatic, 
 "LLVMOptions" -> Automatic, 
 "MacroEnvironment" :> Compile`$DefaultMacroEnvironment, 
 "MacroRecursionLimit" -> 5, "OptimizationLevel" -> 2, 
 "PassLogger" -> Automatic, "PassOptions" -> {}, 
 "ResetVariableID" -> True, "SaveIR" -> False, 
 "TargetArchitecture" -> Automatic, "TargetSystemID" -> Automatic, 
 "TargetTriple" -> Automatic, "TypeEnvironment" :> Automatic, 
 "TypeSystem" -> Automatic}
*)

However, CompilerOptions -> Association[..] throws an error:

FunctionCompile::compopts: CompilerOptions setting <|AbortHandling :> Compile`Utilities`$AbortHandling|> is not a rule or a list of rules.

As for the values, the only official discussion of the compiler I'm aware of can be found in the presentations of Abdul Dakkak and Tom Wickham-Jones at WTC 2019. In Dakkak's notebook you can find "InvocationMode" -> "Standalone", "LLVMOptimization" -> "ClangOptimization"[3], and "AbortHandling" -> False. GeneralUtilities`PrintDefinitions@Compile`Driver`Private`getCodeGenOptions will yield a few sparse insights into the options.

The above was discovered with my usual trick:

FunctionCompile[Function[Typed[arg, "MachineInteger"], arg + 1], 
 CompilerOptions -> {Foo -> True}]

OptionValue::nodef: Unknown option Foo for Compile`CompileToCodeFunction.

Michael E2

Posted 2020-06-04T21:56:23.870

Reputation: 190 928