From owner-svn-src-head@freebsd.org Thu Oct 20 15:14:22 2016 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id BD216C1A33F; Thu, 20 Oct 2016 15:14:22 +0000 (UTC) (envelope-from jonathan@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 8048DC16; Thu, 20 Oct 2016 15:14:22 +0000 (UTC) (envelope-from jonathan@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u9KFELs8056436; Thu, 20 Oct 2016 15:14:21 GMT (envelope-from jonathan@FreeBSD.org) Received: (from jonathan@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u9KFELev056434; Thu, 20 Oct 2016 15:14:21 GMT (envelope-from jonathan@FreeBSD.org) Message-Id: <201610201514.u9KFELev056434@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: jonathan set sender to jonathan@FreeBSD.org using -f From: Jonathan Anderson Date: Thu, 20 Oct 2016 15:14:21 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r307676 - head/share/mk X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 20 Oct 2016 15:14:22 -0000 Author: jonathan Date: Thu Oct 20 15:14:21 2016 New Revision: 307676 URL: https://svnweb.freebsd.org/changeset/base/307676 Log: Add make rules to build LLVM IR from C/C++ sources. As a foundation for future work with LLVM's Intermediate Representation (IR), add new suffix rules that can be used to build .llo (text) or .bco (bitcode) files from C or C++ sources. This compilation step uses the same CFLAGS, etc., as are used for building .o files, with the exception of optimization flags. Many of the things we would like to do with IR (e.g., instrumentation) work better with unoptimized code, so our approach is to build .c->.bco without optimization and then apply the optimization in post-analysis, post-instrumentation linking. The overall result of these changes is: * one can "make foo.llo" or "make foo.bco" wherever "make foo.o" was supported * new make variables IR_CFLAGS and IR_CXXFLAGS are available to inspect the flags that are used by Clang to generate the IR These new rules are added unconditionally to our non-POSIX suffix rule set, since we cannot inspect COMPILER_TYPE in sys.mk. Future changes that depend on these rules (e.g., building IR versions of binaries from bsd.prog.mk) should use COMPILER_TYPE to determine when we can expect IR rules to succeed. Reviewed by: emaste, imp Approved by: rwatson (mentor) Sponsored by: DARPA, AFRL Differential Revision: https://reviews.freebsd.org/D4339 Modified: head/share/mk/bsd.suffixes.mk head/share/mk/sys.mk Modified: head/share/mk/bsd.suffixes.mk ============================================================================== --- head/share/mk/bsd.suffixes.mk Thu Oct 20 15:12:06 2016 (r307675) +++ head/share/mk/bsd.suffixes.mk Thu Oct 20 15:14:21 2016 (r307676) @@ -20,12 +20,24 @@ ${CC} ${STATIC_CFLAGS} ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET} ${CTFCONVERT_CMD} +.c.bco: + ${CC} -emit-llvm ${IR_CFLAGS} -c ${.IMPSRC} -o ${.TARGET} + +.c.llo: + ${CC} -emit-llvm ${IR_CFLAGS} -S ${.IMPSRC} -o ${.TARGET} + .cc .cpp .cxx .C: ${CXX} ${CXXFLAGS} ${LDFLAGS} ${.IMPSRC} ${LDLIBS} -o ${.TARGET} .cc.o .cpp.o .cxx.o .C.o: ${CXX} ${STATIC_CXXFLAGS} ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET} +.cc.bco .cpp.bco .cxx.bco .C.bco: + ${CXX} -emit-llvm ${IR_CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET} + +.cc.llo .cpp.llo .cxx.llo .C.llo: + ${CXX} -emit-llvm ${IR_CXXFLAGS} -S ${.IMPSRC} -o ${.TARGET} + .m.o: ${OBJC} ${OBJCFLAGS} -c ${.IMPSRC} -o ${.TARGET} ${CTFCONVERT_CMD} Modified: head/share/mk/sys.mk ============================================================================== --- head/share/mk/sys.mk Thu Oct 20 15:12:06 2016 (r307675) +++ head/share/mk/sys.mk Thu Oct 20 15:14:21 2016 (r307676) @@ -153,6 +153,7 @@ CFLAGS ?= -O2 -pipe CFLAGS += -fno-strict-aliasing .endif .endif +IR_CFLAGS ?= ${STATIC_CFLAGS:N-O*} ${CFLAGS:N-O*} PO_CFLAGS ?= ${CFLAGS} # cp(1) is used to copy source files to ${.OBJDIR}, make sure it can handle @@ -173,6 +174,7 @@ CTFFLAGS += -g CXX ?= c++ CXXFLAGS ?= ${CFLAGS:N-std=*:N-Wnested-externs:N-W*-prototypes:N-Wno-pointer-sign:N-Wold-style-definition} +IR_CXXFLAGS ?= ${STATIC_CXXFLAGS:N-O*} ${CXXFLAGS:N-O*} PO_CXXFLAGS ?= ${CXXFLAGS} DTRACE ?= dtrace