@@ -837,7 +837,8 @@ aot_create_comp_context(AOTCompData *comp_data,
837837 char * triple_norm_new = NULL , * cpu_new = NULL ;
838838 char * err = NULL , * fp_round = "round.tonearest" , * fp_exce = "fpexcept.strict" ;
839839 char triple_buf [32 ] = {0 };
840- uint32 opt_level ;
840+ uint32 opt_level , size_level ;
841+ LLVMCodeModel code_model ;
841842
842843 /* Initialize LLVM environment */
843844 LLVMInitializeAllTargetInfos ();
@@ -896,6 +897,7 @@ aot_create_comp_context(AOTCompData *comp_data,
896897 cpu = option -> target_cpu ;
897898 features = option -> cpu_features ;
898899 opt_level = option -> opt_level ;
900+ size_level = option -> size_level ;
899901
900902 if (arch ) {
901903 /* Add default sub-arch if not specified */
@@ -1001,6 +1003,7 @@ aot_create_comp_context(AOTCompData *comp_data,
10011003 bh_printf (" target cpu: %s\n" , cpu );
10021004 bh_printf (" cpu features: %s\n" , features );
10031005 bh_printf (" opt level: %d\n" , opt_level );
1006+ bh_printf (" size level: %d\n" , size_level );
10041007 switch (option -> output_format ) {
10051008 case AOT_LLVMIR_UNOPT_FILE :
10061009 bh_printf (" output format: unoptimized LLVM IR\n" );
@@ -1030,11 +1033,21 @@ aot_create_comp_context(AOTCompData *comp_data,
10301033 goto fail ;
10311034 }
10321035
1036+ /* Set code model */
1037+ if (size_level == 0 )
1038+ code_model = LLVMCodeModelLarge ;
1039+ else if (size_level == 1 )
1040+ code_model = LLVMCodeModelMedium ;
1041+ else if (size_level == 2 )
1042+ code_model = LLVMCodeModelKernel ;
1043+ else
1044+ code_model = LLVMCodeModelSmall ;
1045+
10331046 /* Create the target machine */
10341047 if (!(comp_ctx -> target_machine =
10351048 LLVMCreateTargetMachine (target , triple_norm , cpu , features ,
10361049 opt_level , LLVMRelocStatic ,
1037- LLVMCodeModelSmall ))) {
1050+ code_model ))) {
10381051 aot_set_last_error ("create LLVM target machine failed." );
10391052 goto fail ;
10401053 }
0 commit comments