Skip to content

Commit

Permalink
Makefile: LTO for all, lld for clang
Browse files Browse the repository at this point in the history
  • Loading branch information
widlarizer committed Jul 9, 2024
1 parent ad22430 commit 725746b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
19 changes: 18 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ ENABLE_PYOSYS := 0
ENABLE_GCOV := 0
ENABLE_GPROF := 0
ENABLE_DEBUG := 0
ENABLE_LTO := 1
ENABLE_CCACHE := 0
# sccache is not always a drop-in replacement for ccache in practice
ENABLE_SCCACHE := 0
Expand All @@ -52,8 +53,11 @@ SANITIZER =
# SANITIZER = undefined
# SANITIZER = cfi

# Prefer using ENABLE_DEBUG over setting this
# Prefer using ENABLE_DEBUG over setting these
OPT_LEVEL := -O3
GCC_LTO := -flto=auto
CLANG_LTO := -flto=thin

PROGRAM_PREFIX :=

OS := $(shell uname -s)
Expand Down Expand Up @@ -208,10 +212,15 @@ ifeq ($(OS), OpenBSD)
ABC_ARCHFLAGS += "-DABC_NO_RLIMIT"
endif

# This gets overridden later.
LTOFLAGS := $(GCC_LTO)

ifeq ($(CONFIG),clang)
CXX = clang++
CXXFLAGS += -std=$(CXXSTD) $(OPT_LEVEL)
LINKFLAGS += -fuse-ld=lld
ABCMKARGS += ARCHFLAGS="-DABC_USE_STDINT_H $(ABC_ARCHFLAGS)"
LTOFLAGS := $(CLANG_LTO)

ifneq ($(SANITIZER),)
$(info [Clang Sanitizer] $(SANITIZER))
Expand All @@ -227,6 +236,7 @@ endif
ifneq ($(findstring cfi,$(SANITIZER)),)
CXXFLAGS += -flto
LINKFLAGS += -flto
LTOFLAGS =
endif
endif

Expand Down Expand Up @@ -318,11 +328,18 @@ EXE = .exe
else ifeq ($(CONFIG),none)
CXXFLAGS += -std=$(CXXSTD) $(OPT_LEVEL)
ABCMKARGS += ARCHFLAGS="-DABC_USE_STDINT_H $(ABC_ARCHFLAGS)"
LTOFLAGS =

else
$(error Invalid CONFIG setting '$(CONFIG)'. Valid values: clang, gcc, mxe, msys2-32, msys2-64, none)
endif


ifeq ($(ENABLE_LTO),1)
CXXFLAGS += $(LTOFLAGS)
LINKFLAGS += $(LTOFLAGS)
endif

ifeq ($(ENABLE_LIBYOSYS),1)
TARGETS += libyosys.so
endif
Expand Down
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
packages.default = yosys;
defaultPackage = yosys;
devShell = pkgs.mkShell {
buildInputs = with pkgs; [ clang bison flex libffi tcl readline python3 llvmPackages.libcxxClang zlib git gtest abc-verifier ];
buildInputs = with pkgs; [ clang llvmPackages.bintools bison flex libffi tcl readline python3 llvmPackages.libcxxClang zlib git gtest abc-verifier ];
};
}
);
Expand Down

0 comments on commit 725746b

Please sign in to comment.