diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ca2e702508..f98da339895 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - LLVM for prebuilt packages bumped to v18.1.8 (incl. macOS arm64). (#4712) - Android: NDK for prebuilt package bumped from r26d to r27. (#4711) - ldc2.conf: %%ldcconfigpath%% placeholder added - specifies the directory where current configuration file is located. (#4717) +- The insanity switch `-release` is now called `-ludicrous`. `-magazine-benchmark` has been added to provide what would have actually been expected by the switch. #### Platform support diff --git a/dmd/frontend.h b/dmd/frontend.h index 845e4889e95..192a8b057b1 100644 --- a/dmd/frontend.h +++ b/dmd/frontend.h @@ -8016,6 +8016,8 @@ struct Param final bool useUnitTests; bool useInline; bool release; + bool ludicrous; + bool magazineBench; bool preservePaths; DiagnosticReporting warnings; bool cov; @@ -8099,6 +8101,8 @@ struct Param final useUnitTests(), useInline(false), release(), + ludicrous(), + magazineBench(), preservePaths(), warnings((DiagnosticReporting)2u), cov(), @@ -8166,7 +8170,7 @@ struct Param final mapfile() { } - Param(bool obj, bool multiobj = false, bool trace = false, bool tracegc = false, bool vcg_ast = false, DiagnosticReporting useDeprecated = (DiagnosticReporting)1u, bool useUnitTests = false, bool useInline = false, bool release = false, bool preservePaths = false, DiagnosticReporting warnings = (DiagnosticReporting)2u, bool cov = false, uint8_t covPercent = 0u, bool ctfe_cov = false, bool ignoreUnsupportedPragmas = true, bool useModuleInfo = true, bool useTypeInfo = true, bool useExceptions = true, bool useGC = true, bool betterC = false, bool addMain = false, bool allInst = false, bool bitfields = false, CppStdRevision cplusplus = (CppStdRevision)201103u, Help help = Help(), Verbose v = Verbose(), FeatureState useDIP25 = (FeatureState)2u, FeatureState useDIP1000 = (FeatureState)0u, bool ehnogc = false, bool useDIP1021 = false, FeatureState fieldwise = (FeatureState)0u, bool fixAliasThis = false, FeatureState rvalueRefParam = (FeatureState)0u, FeatureState noSharedAccess = (FeatureState)0u, bool previewIn = false, bool inclusiveInContracts = false, bool shortenedMethods = true, bool fixImmutableConv = false, bool fix16997 = true, FeatureState dtorFields = (FeatureState)0u, FeatureState systemVariables = (FeatureState)0u, CHECKENABLE useInvariants = (CHECKENABLE)0u, CHECKENABLE useIn = (CHECKENABLE)0u, CHECKENABLE useOut = (CHECKENABLE)0u, CHECKENABLE useArrayBounds = (CHECKENABLE)0u, CHECKENABLE useAssert = (CHECKENABLE)0u, CHECKENABLE useSwitchError = (CHECKENABLE)0u, CHECKENABLE boundscheck = (CHECKENABLE)0u, CHECKACTION checkAction = (CHECKACTION)0u, CLIIdentifierTable dIdentifierTable = (CLIIdentifierTable)0u, CLIIdentifierTable cIdentifierTable = (CLIIdentifierTable)0u, _d_dynamicArray< const char > argv0 = {}, Array modFileAliasStrings = Array(), Array imppath = Array(), Array fileImppath = Array(), _d_dynamicArray< const char > objdir = {}, _d_dynamicArray< const char > objname = {}, _d_dynamicArray< const char > libname = {}, Output ddoc = Output(), Output dihdr = Output(), Output cxxhdr = Output(), Output json = Output(), JsonFieldFlags jsonFieldFlags = (JsonFieldFlags)0u, Output makeDeps = Output(), Output mixinOut = Output(), Output moduleDeps = Output(), uint32_t debuglevel = 0u, uint32_t versionlevel = 0u, bool run = false, Array runargs = Array(), Array cppswitches = Array(), const char* cpp = nullptr, Array objfiles = Array(), Array linkswitches = Array(), Array linkswitchIsForCC = Array(), Array libfiles = Array(), Array dllfiles = Array(), _d_dynamicArray< const char > deffile = {}, _d_dynamicArray< const char > resfile = {}, _d_dynamicArray< const char > exefile = {}, _d_dynamicArray< const char > mapfile = {}) : + Param(bool obj, bool multiobj = false, bool trace = false, bool tracegc = false, bool vcg_ast = false, DiagnosticReporting useDeprecated = (DiagnosticReporting)1u, bool useUnitTests = false, bool useInline = false, bool release = false, bool ludicrous = false, bool magazineBench = false, bool preservePaths = false, DiagnosticReporting warnings = (DiagnosticReporting)2u, bool cov = false, uint8_t covPercent = 0u, bool ctfe_cov = false, bool ignoreUnsupportedPragmas = true, bool useModuleInfo = true, bool useTypeInfo = true, bool useExceptions = true, bool useGC = true, bool betterC = false, bool addMain = false, bool allInst = false, bool bitfields = false, CppStdRevision cplusplus = (CppStdRevision)201103u, Help help = Help(), Verbose v = Verbose(), FeatureState useDIP25 = (FeatureState)2u, FeatureState useDIP1000 = (FeatureState)0u, bool ehnogc = false, bool useDIP1021 = false, FeatureState fieldwise = (FeatureState)0u, bool fixAliasThis = false, FeatureState rvalueRefParam = (FeatureState)0u, FeatureState noSharedAccess = (FeatureState)0u, bool previewIn = false, bool inclusiveInContracts = false, bool shortenedMethods = true, bool fixImmutableConv = false, bool fix16997 = true, FeatureState dtorFields = (FeatureState)0u, FeatureState systemVariables = (FeatureState)0u, CHECKENABLE useInvariants = (CHECKENABLE)0u, CHECKENABLE useIn = (CHECKENABLE)0u, CHECKENABLE useOut = (CHECKENABLE)0u, CHECKENABLE useArrayBounds = (CHECKENABLE)0u, CHECKENABLE useAssert = (CHECKENABLE)0u, CHECKENABLE useSwitchError = (CHECKENABLE)0u, CHECKENABLE boundscheck = (CHECKENABLE)0u, CHECKACTION checkAction = (CHECKACTION)0u, CLIIdentifierTable dIdentifierTable = (CLIIdentifierTable)0u, CLIIdentifierTable cIdentifierTable = (CLIIdentifierTable)0u, _d_dynamicArray< const char > argv0 = {}, Array modFileAliasStrings = Array(), Array imppath = Array(), Array fileImppath = Array(), _d_dynamicArray< const char > objdir = {}, _d_dynamicArray< const char > objname = {}, _d_dynamicArray< const char > libname = {}, Output ddoc = Output(), Output dihdr = Output(), Output cxxhdr = Output(), Output json = Output(), JsonFieldFlags jsonFieldFlags = (JsonFieldFlags)0u, Output makeDeps = Output(), Output mixinOut = Output(), Output moduleDeps = Output(), uint32_t debuglevel = 0u, uint32_t versionlevel = 0u, bool run = false, Array runargs = Array(), Array cppswitches = Array(), const char* cpp = nullptr, Array objfiles = Array(), Array linkswitches = Array(), Array linkswitchIsForCC = Array(), Array libfiles = Array(), Array dllfiles = Array(), _d_dynamicArray< const char > deffile = {}, _d_dynamicArray< const char > resfile = {}, _d_dynamicArray< const char > exefile = {}, _d_dynamicArray< const char > mapfile = {}) : obj(obj), multiobj(multiobj), trace(trace), @@ -8176,6 +8180,8 @@ struct Param final useUnitTests(useUnitTests), useInline(useInline), release(release), + ludicrous(ludicrous), + magazineBench(magazineBench), preservePaths(preservePaths), warnings(warnings), cov(cov), diff --git a/dmd/globals.d b/dmd/globals.d index e1b9c466061..b1b9643191f 100644 --- a/dmd/globals.d +++ b/dmd/globals.d @@ -190,6 +190,8 @@ extern (C++) struct Param bool useUnitTests; // generate unittest code bool useInline = false; // inline expand functions bool release; // build release version + bool ludicrous; // build ludicrous version + bool magazineBench; // ludicrous + O3 bool preservePaths; // true means don't strip path from source file DiagnosticReporting warnings = DiagnosticReporting.off; // how compiler warnings are handled bool cov; // generate code coverage data diff --git a/dmd/globals.h b/dmd/globals.h index 42127a84098..a9fcd69e736 100644 --- a/dmd/globals.h +++ b/dmd/globals.h @@ -190,6 +190,8 @@ struct Param d_bool useUnitTests; // generate unittest code d_bool useInline; // inline expand functions d_bool release; // build release version + d_bool ludicrous; // build ludicrous version + d_bool magazineBench; // ludicrous + O3 d_bool preservePaths; // true means don't strip path from source file Diagnostic warnings; d_bool cov; // generate code coverage data diff --git a/dmd/main.d b/dmd/main.d index b1588b8a0cd..b924cb83a39 100644 --- a/dmd/main.d +++ b/dmd/main.d @@ -1185,7 +1185,22 @@ else params.useAssert = CHECKENABLE.on; } + if (params.magazineBench) + { + params.ludicrous = true; + //driverParams.optimize = true; + } + if (params.release) + { + deprecation( + Loc.initial, + "Switch `-release` is deprecated; use `-ludicrous` or `-magazine-benchmark` instead." + ); + params.ludicrous = true; + } + + if (params.release || params.ludicrous) { if (params.useInvariants == CHECKENABLE._default) params.useInvariants = CHECKENABLE.off; diff --git a/driver/cl_options.cpp b/driver/cl_options.cpp index 6e6b498bf13..ae137cac8c7 100644 --- a/driver/cl_options.cpp +++ b/driver/cl_options.cpp @@ -503,9 +503,21 @@ static cl::opt checkAction( static cl::opt release("release", cl::ZeroOrMore, cl::location(global.params.release), - cl::desc("Compile release version, defaulting to disabled " - "asserts/contracts/invariants, and bounds checks in @safe " - "functions only"), + cl::desc("Deprecated alias of `-ludicrous`."), + cl::ValueDisallowed); + +static cl::opt + ludicrous("ludicrous", cl::ZeroOrMore, cl::location(global.params.ludicrous), + cl::desc("Compile for ludicrous runtime performance, disabling " + "asserts/contracts/invariants, and performing bounds checks " + "in @safe functions only. This switch should be used with " + "bug-free code only."), + cl::ValueDisallowed); + +static cl::opt + magazineBench("magazine-benchmark", cl::ZeroOrMore, cl::location(global.params.magazineBench), + cl::desc("Special release mode, enables various optimizations for " + "ludicrous speed."), cl::ValueDisallowed); cl::opt diff --git a/driver/ldmd.cpp b/driver/ldmd.cpp index 919add2ea26..2af23f0acf8 100644 --- a/driver/ldmd.cpp +++ b/driver/ldmd.cpp @@ -659,9 +659,10 @@ void translateArgs(const llvm::SmallVectorImpl &ldmdArgs, goto Lnot_in_ldc; } else if (strcmp(p + 1, "quiet") == 0) { // ignore + } else if (strcmp(p + 1, "release") == 0) { + ldcArgs.push_back("-ludicrous"); } - /* -release - * -betterC + /* -betterC */ else if (strcmp(p + 1, "noboundscheck") == 0) { ldcArgs.push_back("-boundscheck=off"); diff --git a/driver/main.cpp b/driver/main.cpp index 331b12dfa36..37c814d003c 100644 --- a/driver/main.cpp +++ b/driver/main.cpp @@ -943,6 +943,7 @@ void registerPredefinedTargetVersions() { //Issue deprecations for deprecated arguments // N.B `-nodefaultlib` is checked in `getDefaultLibNames` + // N.B `-release` is checked in `reconcileCommands` if (checkPrintf) deprecation(Loc(), "'-check-printf-calls' is deprecated, use `pragma(printf)` instead."); } diff --git a/gen/optimizer.cpp b/gen/optimizer.cpp index 76b37eb1186..8c816699855 100644 --- a/gen/optimizer.cpp +++ b/gen/optimizer.cpp @@ -127,6 +127,10 @@ static cl::opt fSanitizeMemoryTrackOrigins( "Enable origins tracking in MemorySanitizer (0=disabled, default)")); unsigned optLevel() { + if (global.params.magazineBench) { + return 3; + } + // Use -O2 as a base for the size-optimization levels. return optimizeLevel >= 0 ? optimizeLevel : 2; } @@ -146,6 +150,10 @@ bool willCrossModuleInline() { bool isOptimizationEnabled() { return optimizeLevel != 0; } llvm::CodeGenOptLevel codeGenOptLevel() { + if (global.params.magazineBench) { + return llvm::CodeGenOptLevel::Aggressive; + } + // Use same appoach as clang (see lib/CodeGen/BackendUtil.cpp) if (optLevel() == 0) { return llvm::CodeGenOptLevel::None; @@ -165,6 +173,14 @@ std::unique_ptr createTLII(llvm::Module &M) { } static OptimizationLevel getOptimizationLevel(){ + if (global.params.magazineBench) { + switch(optimizeLevel) { + case -1: return OptimizationLevel::Os; + case -2: return OptimizationLevel::Oz; + } + return OptimizationLevel::O3; + } + switch(optimizeLevel) { case 0: return OptimizationLevel::O0; case 1: return OptimizationLevel::O1; diff --git a/packaging/bash_completion.d/ldc2 b/packaging/bash_completion.d/ldc2 index ff596ae9226..528973080c4 100644 --- a/packaging/bash_completion.d/ldc2 +++ b/packaging/bash_completion.d/ldc2 @@ -35,24 +35,24 @@ -enable-unsafe-fp-math -fatal-assembler-warnings -fdata-sections -ffunction-sections \ -float-abi -help -ignore -internalize-public-api-file \ -internalize-public-api-list -jit-emit-debug -jit-enable-eh -join-liveintervals \ - -lib -limit-float-precision -linkonce-templates -m32 \ - -m64 -march -mattr -mc-x86-disable-arith-relaxation\ - -mcpu -mtriple -nested-ctx -noasm \ - -nodefaultlib -noruntime -noverify -nozero-initialized-in-bss \ - -O -O0 -O1 -O2 \ - -O3 -O4 -O5 -o- \ - -od -of -op -oq \ - -output-bc -output-ll -output-o -output-s \ - -pre-RA-sched -print-after-all -print-before-all -print-machineinstrs \ - -profile-estimator-loop-weight -profile-info-file -profile-verifier-noassert -realign-stack \ - -regalloc -release -relocation-model -rewriter \ - -run -schedule-spills -segmented-stacks -shared \ - -shrink-wrap -singleobj -soft-float -spiller \ - -stack-alignment -stack-protector-buffer-size -stats -tailcallopt \ - -time-passes -unittest -v -v-cg \ - -verify-dom-info -verify-loop-info -verify-regalloc -verify-region-info \ - -version -vv -w -x86-asm-syntax \ - -x86-use-vzeroupper + -lib -limit-float-precision -linkonce-templates -ludicrous \ + -m32 -m64 -magazine-benchmark -march \ + -mattr -mc-x86-disable-arith-relaxation -mcpu -mtriple \ + -nested-ctx -noasm -nodefaultlib -noruntime \ + -noverify -nozero-initialized-in-bss -O -O0 \ + -O1 -O2 -O3 -O4 \ + -O5 -o- -od -of \ + -op -oq -output-bc -output-ll \ + -output-o -output-s -pre-RA-sched -print-after-all \ + -print-before-all -print-machineinstrs -profile-estimator-loop-weight -profile-info-file \ + -profile-verifier-noassert -realign-stack -regalloc -relocation-model \ + -rewriter -run -schedule-spills -segmented-stacks \ + -shared -shrink-wrap -singleobj -soft-float \ + -spiller -stack-alignment -stack-protector-buffer-size -stats \ + -tailcallopt -time-passes -unittest -v \ + -v-cg -verify-dom-info -verify-loop-info -verify-regalloc \ + -verify-region-info -version -vv -w \ + -x86-asm-syntax -x86-use-vzeroupper " opts_with_equal=(-Df Hd -Hf -I -J -Xf -code-model -d-version -debuglib -defaultlib -deps \ -internalize-public-api-file -float-abi -limit-float-precision -march -mtriple -mattr \ diff --git a/runtime/CMakeLists.txt b/runtime/CMakeLists.txt index ca9e50f2516..6a5edb34b43 100644 --- a/runtime/CMakeLists.txt +++ b/runtime/CMakeLists.txt @@ -38,7 +38,7 @@ set(BUILD_SHARED_LIBS AUTO CACHE STRING "Whet set(D_FLAGS -w;-de;-preview=dip1000;-preview=dtorfields;-preview=fieldwise CACHE STRING "Runtime D compiler flags, separated by ';'") set(D_EXTRA_FLAGS "" CACHE STRING "Runtime extra D compiler flags, separated by ';'") set(D_FLAGS_DEBUG -g;-link-defaultlib-debug;-d-debug CACHE STRING "Runtime D compiler flags (debug libraries), separated by ';'") -set(D_FLAGS_RELEASE -O3;-release;-femit-local-var-lifetime CACHE STRING "Runtime D compiler flags (release libraries), separated by ';'") +set(D_FLAGS_RELEASE -O3;-ludicrous;-femit-local-var-lifetime CACHE STRING "Runtime D compiler flags (release libraries), separated by ';'") set(COMPILE_ALL_D_FILES_AT_ONCE ON CACHE BOOL "Compile all D files for the runtime libs in a single command line instead of separately. Disabling this is useful for many CPU cores and/or iterative development.") set(RT_ARCHIVE_WITH_LDC ON CACHE STRING "Whether to archive the static runtime libs via LDC instead of CMake archiver") set(RT_CFLAGS "" CACHE STRING "Runtime extra C compiler flags, separated by ' '") diff --git a/runtime/druntime/Makefile b/runtime/druntime/Makefile index df9543950fc..e87c37a2c07 100644 --- a/runtime/druntime/Makefile +++ b/runtime/druntime/Makefile @@ -106,7 +106,7 @@ ifeq ($(BUILD),debug) UDFLAGS += -g -debug DFLAGS:=$(UDFLAGS) else - UDFLAGS += -O -release + UDFLAGS += -O -ludicrous DFLAGS:=$(UDFLAGS) -inline # unittests don't compile with -inline endif diff --git a/runtime/druntime/test/common.mak b/runtime/druntime/test/common.mak index 10e3f949da8..2eec034e8a4 100644 --- a/runtime/druntime/test/common.mak +++ b/runtime/druntime/test/common.mak @@ -50,7 +50,7 @@ ifeq ($(BUILD),debug) DFLAGS+=-g -debug $(if $(findstring ldmd2,$(DMD)),-link-defaultlib-debug,) CFLAGS:=$(CFLAGS_BASE) $(if $(findstring $(OS),windows),/Zi,-g) else - DFLAGS+=-O -release + DFLAGS+=-O -ludicrous CFLAGS:=$(CFLAGS_BASE) $(if $(findstring $(OS),windows),/O2,-O3) endif CXXFLAGS_BASE:=$(CFLAGS_BASE) diff --git a/runtime/druntime/test/profile/Makefile b/runtime/druntime/test/profile/Makefile index 4c263336e3c..dede58ca525 100644 --- a/runtime/druntime/test/profile/Makefile +++ b/runtime/druntime/test/profile/Makefile @@ -22,7 +22,7 @@ endif .PHONY: all clean all: $(addprefix $(ROOT)/,$(addsuffix .done,$(TESTS))) -# LDC: enable assertions for BUILD=RELEASE (=> `-O -release`) +# LDC: enable assertions for BUILD=RELEASE (=> `-O -ludicrous`) $(ROOT)/profile.done: DFLAGS+=-profile $(if $(findstring ldmd2,$(DMD)),-check=assert=on,) $(ROOT)/profile.done: $(ROOT)/%.done: $(ROOT)/%$(DOTEXE) @echo Testing $*