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 _______________________________________________ svn-src-all@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-all To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"