# 
#     Copyright (c) 2017, NVIDIA CORPORATION.  All rights reserved.
#
# NVIDIA CORPORATION and its licensors retain all intellectual property
# and proprietary rights in and to this software, related documentation
# and any modifications thereto.  Any use, reproduction, disclosure or
# distribution of this software and related documentation without an express
# license agreement from NVIDIA CORPORATION is strictly prohibited.
# 

# Compiler Configurations for C
#

variable STLINUX_INCLUDE is
	default(include-stlin);

variable ANDROID_INCLUDE is
	default(include-droid);

variable EXTRA_STLINUXINC is
	default($STLINUXBASEDIR/target/usr/include $GCCDIR/include);

#variable ANDROIDPREFIX is
#        help(name of arm target)
#        default(arm-linux-androideabi);

variable ANDROIDLIBGCC is
        help(ANDROID lib gcc directory)
        default(lib/gcc/$ANDROIDPREFIX/$ANDROIDGCCVERSION);

variable ANDROIDSYSROOTDIR is
        help(ANDROID sysroot directory)
        default(sysroot);

variable EXTRA_ANDROIDINC is
	default($ANDROIDBASEDIR/$ANDROIDLIBGCC/include $ANDROIDBASEDIR/$ANDROIDSYSROOTDIR/usr/include);

variable STLINUXBASEDIR is
	default();

variable ANDROIDBASE is
	default();

variable ANDROIDBASEDIR is
	default();

replace switch -fast is
        help(Common optimizations; includes -O2 -Munroll=c:1 -Mnoframe -Mlre)
        helpgroup(opt)
        append(CGARGS=
                -x 9 1                  # -Munroll=c:1
                -x 42 0x14200000        # -Mlre=prefer - now that vectorization/lre works
                -x 136 0x11             # Branch prediction & BB placement      
#               -x 53 10                # Pointer target analysis
        )
        append(F901ARGS=
                -x 53 2                 # Pointer target analysis
        )
        append(CARGS=-autoinl $AUTOLEVELS -x 168 $AUTOMAXFUNCSIZE -x 174 $AUTOMAXTOTALSIZE -x 14 0x200000 $ifn($NOSTATIC, -x 14 0x400000))
        set(AUTOINLINE=YES)
	# Enable Minline
        #append(INLINELIST=-insize $MAXFUNCSIZE -x 221 $MAXTOTALSIZE -x 222 $SMALLSIZE)
        #set(INLINE=YES)
        max(OPTLEVELDEF=2)      # -O2
        max(OPTLEVELMIN=2)      # -O2
        set(NOFRAME=YES)        # -Mnoframe
        shorthand(-Mvect=simd)
        set(VECT=48)
        set(MVECT=$MVECTVAL)
        append(OPTLEVELMINLIMIT="-Mvect=simd");


replace switch -o$outputfile is
	help(Name the output file)
	helpgroup(overall)
	set(DEFOUTFILE=)
	set(OUTFILE=$path($outputfile));

replace switch -c is
	help(Stop after assemble; output in object file)
	helpgroup(overall)
	set(KEEPOBJ=YES)
 	set(ASMONLY=YES)
	set(DEFOUTFILE=)
	stopafter(Compile)
        ;

replace switch -S is
	help(Stop before assembling; output in .s file)
	helpgroup(overall)
	set(KEEPASM=YES)
	set(DEFOUTFILE=)
	set(COMPILEONLY=YES)
	stopafter(Compile)
        ;

replace switch -Msmartalloc is hide
    helpgroup(opt)
    helpname(-M[no]smartalloc)
    help(Link with the huge TLB page library)
    append(CGARGS=-x 129 0x20000000)
    nokeyword()
    keyword(
        huge(
        helpname([no]huge)
        help(Link with huge TLB page libraries)
        set(HUGEN=0)
        append(CGARGS=-x 129 0x10000000)
        set(HUGELIB=$if($NOPGIRPATH,$PGISTATIC)
            -lhugetlbfs_nvhpc
            $if($NOPGIRPATH,-u __pgi_setup_morecore))
        )
        nohuge( # disable previous -Msmartalloc=huge
        hide
        set(HUGEN=0)
        append(CGARGS=-y 129 0x14000000)
        set(HUGELIB=)
        )
        hugebss(    if($equal($TARGET,linux86-64))
        help(Put the BSS section in huge pages)
        append(CGARGS=-x 129 0x4000000)
        set(HUGELIB=$if($NOPGIRPATH,$PGISTATIC)
            -lhugetlbfs_nvhpc
            $if($NOPGIRPATH,-u __pgi_setup_elflink))
        set(COMPLIBOBJ=$COMPBASE/$COMPSYS/$COMPVER/$COMPLIBSUBDIR)
        set(STDRPATHSO=-rpath $COMPBASE/$COMPSYS/$COMPVER/$COMPLIBSUBDIR)
        append(DEFLDARGS=-T $COMPBASE/$COMPSYS/$COMPVER/$quote($COMPLIBPREFIX)lib/hugebss.ld)
        )
    );

replace switch -Mhugetlb is
    help(Link with the huge TLB page library)
    helpgroup(linker)
    set(HUGEN=0)
    append(CGARGS=-x 129 0x10000000)
    set(HUGELIB=$if($NOPGIRPATH,$PGISTATIC)
        -lhugetlbfs_nvhpc
        $if($NOPGIRPATH,-u __pgi_setup_morecore));

tool pgc_llvm is help (PGI LLVM C compiler)
	program($PGCLLVMCOMP) directory($CCOMPDIR);

tool pgc_ex_llvm is help (PGI LLVM C extractor for inlining)
	program($PGCLLVMCEXT) directory($CCOMPDIR);

tool pgprepro_llvm is help (PGI LLVM C extractor for inlining)
	program($PGCLLVMPREPRO) directory($CCOMPDIR);


