Fix emission of instructions that directly reference MBBs
[oota-llvm.git] / Makefile.rules
index e8a0697e60ef66b90aa8d0bd5ffc175a45cae9af..dbb91afade42961d6620b80ad281a2bbab86e3da 100644 (file)
@@ -89,7 +89,7 @@ endif
 # Determine the path of the source tree relative from $HOME (the mythical
 # home directory).
 #
-HOME_OBJ_ROOT := $(OBJ_ROOT)/$(patsubst $(HOME)%,%,$(BUILD_SRC_ROOT))
+HOME_OBJ_ROOT := $(OBJ_ROOT)$(patsubst $(HOME)%,%,$(BUILD_SRC_ROOT))
 
 #
 # Set the object build directory.  Its location depends upon the source path
@@ -149,6 +149,9 @@ install ::
 # Default rule for test.  It ensures everything has a test rule
 test::
 
+# Default rule for building only bytecode.
+bytecode::
+
 # Print out the directories used for building
 prdirs::
        echo "Home Offset      : " $(HOME_OBJ_ROOT);
@@ -159,6 +162,13 @@ prdirs::
        echo "LLVM  Source Root: " $(LLVM_SRC_ROOT);
        echo "LLVM  Object Root: " $(LLVM_OBJ_ROOT);
 
+#
+# Mark all of these targets as phony.  This will hopefully speed up builds
+# slightly since GNU Make will not try to find implicit rules for targets
+# which are marked as Phony.
+#
+.PHONY: all dynamic clean distclean install test bytecode prdirs
+
 ###########################################################################
 # Miscellaneous paths and commands:
 #      This section defines various configuration macros, such as where
@@ -256,9 +266,24 @@ PROJTOOLCURRENT := $(BUILD_OBJ_ROOT)/tools/$(CONFIGURATION)
 # Libtool is found in the current directory.
 #
 ifdef VERBOSE
-LIBTOOL=$(LLVM_SRC_ROOT)/libtool
+LIBTOOL=$(LLVM_SRC_ROOT)/mklib
 else
-LIBTOOL=$(LLVM_SRC_ROOT)/libtool --silent
+LIBTOOL=$(LLVM_SRC_ROOT)/mklib --silent
+endif
+
+#
+# If we're not building a shared library, use the disable-shared tag with
+# libtool.  This will disable the building of objects for shared libraries and
+# only generate static library objects.
+#
+# For dynamic libraries, we'll take the performance hit for now, since we
+# almost never build them.
+#
+# This should speed up compilation and require no modifications to future
+# versions of libtool.
+#
+ifndef SHARED_LIBRARY
+LIBTOOL := $(LIBTOOL) --tag=disable-shared
 endif
 
 #
@@ -297,7 +322,7 @@ CPPFLAGS += -I$(BUILD_SRC_ROOT)/include -I$(LLVM_SRC_ROOT)/include
 # By default, strip symbol information from executable
 ifndef KEEP_SYMBOLS
 STRIP = $(PLATFORMSTRIPOPTS)
-STRIP_WARN_MSG = "(without symbols) "
+STRIP_WARN_MSG = "(without symbols)"
 endif
 
 # Allow gnu extensions...
@@ -313,18 +338,6 @@ CompileOptimizeOpts := -O3 -DNDEBUG -finline-functions -fshort-enums
 Compile  := $(LIBTOOL) --mode=compile $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(CompileCommonOpts)
 CompileC  := $(LIBTOOL) --mode=compile $(CC) -c $(CPPFLAGS) $(CCFLAGS) $(CompileCommonOpts)
 
-#
-# Add the LLVM specific "-only-static" option so that we only compile .o files
-# once when not building a shared library.
-#
-# For shared libraries, we will end up building twice, but that doesn't happen
-# very often, so we'll let it go.
-#
-ifndef SHARED_LIBRARY
-Compile  := $(Compile)  -only-static
-CompileC := $(CompileC) -only-static
-endif
-
 # Compile a cpp file, don't link...
 CompileG := $(Compile) -g  -D_DEBUG
 CompileO := $(Compile) $(CompileOptimizeOpts) -felide-constructors -fomit-frame-pointer
@@ -355,7 +368,11 @@ LinkO    := $(Link) -O3 -L$(PROJLIBRELEASESOURCE) -L$(LLVMLIBRELEASESOURCE)
 LinkP    := $(Link) -O3 -L$(PROJLIBPROFILESOURCE) -L$(LLVMLIBPROFILESOURCE) $(PROFILE)
 
 # Create one .o file from a bunch of .o files...
+#ifdef SHARED_LIBRARY
 Relink = ${LIBTOOL} --mode=link $(CXX)
+#else
+Relink = ${LIBTOOL} --mode=link $(CXX) -only-static
+#endif
 
 # MakeSO - Create a .so file from a .o files...
 #MakeSO   := $(LIBTOOL) --mode=link $(CXX) $(MakeSharedObjectOption)
@@ -390,17 +407,28 @@ ifndef Source
 Source  := $(ExtraSource) $(wildcard *.cpp *.c *.y *.l)
 endif
 
-LObjs := $(sort $(patsubst Debug/%.lo, %.lo, $(addsuffix .lo,$(notdir $(basename $(Source))))))
-LObjectsO := $(addprefix $(BUILD_OBJ_DIR)/Release/,$(LObjs))
-LObjectsP := $(addprefix $(BUILD_OBJ_DIR)/Profile/,$(LObjs))
-LObjectsG := $(addprefix $(BUILD_OBJ_DIR)/Debug/,$(LObjs))
+#
+# Libtool Objects
+#
+Objs := $(sort $(patsubst Debug/%.lo, %.lo, $(addsuffix .lo,$(notdir $(basename $(Source))))))
+ObjectsO := $(addprefix $(BUILD_OBJ_DIR)/Release/,$(Objs))
+ObjectsP := $(addprefix $(BUILD_OBJ_DIR)/Profile/,$(Objs))
+ObjectsG := $(addprefix $(BUILD_OBJ_DIR)/Debug/,$(Objs))
+
+#
+# The real objects underlying the libtool objects
+#
+RObjs := $(sort $(patsubst Debug/%.o, %.o, $(addsuffix .o,$(notdir $(basename $(Source))))))
+RObjectsO := $(addprefix $(BUILD_OBJ_DIR)/Release/,$(RObjs))
+RObjectsP := $(addprefix $(BUILD_OBJ_DIR)/Profile/,$(RObjs))
+RObjectsG := $(addprefix $(BUILD_OBJ_DIR)/Debug/,$(RObjs))
 
 #---------------------------------------------------------
 # Handle the DIRS and PARALLEL_DIRS options
 #---------------------------------------------------------
 
 ifdef DIRS
-all install clean test ::
+all install clean test bytecode ::
        $(VERB) for dir in ${DIRS}; do \
                (cd $$dir; $(MAKE) $@) || exit 1; \
        done
@@ -408,18 +436,19 @@ endif
 
 # Handle PARALLEL_DIRS
 ifdef PARALLEL_DIRS
-all     :: $(addsuffix /.makeall    , $(PARALLEL_DIRS))
-install :: $(addsuffix /.makeinstall, $(PARALLEL_DIRS))
-clean   :: $(addsuffix /.makeclean  , $(PARALLEL_DIRS))
-test    :: $(addsuffix /.maketest   , $(PARALLEL_DIRS))
+all      :: $(addsuffix /.makeall     , $(PARALLEL_DIRS))
+install  :: $(addsuffix /.makeinstall , $(PARALLEL_DIRS))
+clean    :: $(addsuffix /.makeclean   , $(PARALLEL_DIRS))
+test     :: $(addsuffix /.maketest    , $(PARALLEL_DIRS))
+bytecode :: $(addsuffix /.makebytecode, $(PARALLEL_DIRS))
 
-%/.makeall %/.makeinstall %/.makeclean %/.maketest:
+%/.makeall %/.makeinstall %/.makeclean %/.maketest %/.makebytecode:
        $(VERB) cd $(@D); $(MAKE) $(subst $(@D)/.make,,$@)
 endif
 
 # Handle directories that may or may not exist
 ifdef OPTIONAL_DIRS
-all install clean test ::
+all install clean test bytecode ::
        $(VERB) for dir in ${OPTIONAL_DIRS}; do \
                if [ -d $$dir ]; \
                then\
@@ -489,53 +518,64 @@ endif
 #
 # Rules for building dynamically linked libraries.
 #
-$(LIBNAME_O): $(LObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
+$(LIBNAME_O): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
        @echo ======= Linking $(LIBRARYNAME) dynamic release library =======
-       $(VERB) $(Link) -o $*.la $(LObjectsO) $(LibSubDirs) $(LibLinkOpts);
+       $(VERB) $(Link) -o $*.la $(ObjectsO) $(LibSubDirs) $(LibLinkOpts);
        $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $*.la $(DESTLIBCURRENT);
 
-$(LIBNAME_P): $(LObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
+$(LIBNAME_P): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
        @echo ======= Linking $(LIBRARYNAME) dynamic profile library =======
-       $(VERB) $(Link) -o $*.la $(LObjectsP) $(LibSubDirs) $(LibLinkOpts);
+       $(VERB) $(Link) -o $*.la $(ObjectsP) $(LibSubDirs) $(LibLinkOpts);
        $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $*.la $(DESTLIBCURRENT);
 
-$(LIBNAME_G): $(LObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
+$(LIBNAME_G): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
        @echo ======= Linking $(LIBRARYNAME) dynamic debug library =======
-       $(VERB) $(Link) -o $*.la $(LObjectsG) $(LibSubDirs) $(LibLinkOpts);
+       $(VERB) $(Link) -o $*.la $(ObjectsG) $(LibSubDirs) $(LibLinkOpts);
        $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $*.la $(DESTLIBCURRENT);
 
 #
 # Rules for building static archive libraries.
 #
-$(LIBNAME_AO): $(LObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
+$(LIBNAME_AO): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
        @echo ======= Linking $(LIBRARYNAME) archive release library =======
        @$(RM) -f $@
-       $(VERB) $(Link) -03 -o $@ $(LObjectsO) $(LibSubDirs) -static
+       $(VERB) $(Link) -03 -o $@ $(ObjectsO) $(LibSubDirs) -static
 
-$(LIBNAME_AP): $(LObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
+$(LIBNAME_AP): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
        @echo ======= Linking $(LIBRARYNAME) archive profile library =======
        @$(RM) -f $@
-       $(VERB) $(Link) -03 $(PROFILE) -o $@ $(LObjectsP) $(LibSubDirs) -static
+       $(VERB) $(Link) -03 $(PROFILE) -o $@ $(ObjectsP) $(LibSubDirs) -static
 
-$(LIBNAME_AG): $(LObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
+$(LIBNAME_AG): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
        @echo ======= Linking $(LIBRARYNAME) archive debug library =======
        @$(RM) -f $@
-       $(VERB) $(Link) -g $(STRIP) -o $@ $(LObjectsG) $(LibSubDirs) -static
+       $(VERB) $(Link) -g $(STRIP) -o $@ $(ObjectsG) $(LibSubDirs) -static
 
 #
 # Rules for building .o libraries.
 #
-$(LIBNAME_OBJO): $(LObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
+#      JTC:
+#      Note that for this special case, we specify the actual object files
+#      instead of their libtool counterparts.  This is because libtool
+#      doesn't want to generate a reloadable object file unless it is given
+#      .o files explicitly.
+#
+#      Note that we're making an assumption here: If we build a .lo file,
+#      it's corresponding .o file will be placed in the same directory.
+#
+#      I think that is safe.
+#
+$(LIBNAME_OBJO): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
        @echo "Linking $@"
-       $(VERB) $(Relink) -o $@ $(LObjectsO) $(LibSubDirs)
+       $(VERB) $(Relink) -o $@ $(RObjectsO) $(LibSubDirs)
 
-$(LIBNAME_OBJP): $(LObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
+$(LIBNAME_OBJP): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
        @echo "Linking $@"
-       $(VERB) $(Relink) -o $@ $(LObjectsP) $(LibSubDirs)
+       $(VERB) $(Relink) -o $@ $(RObjectsP) $(LibSubDirs)
 
-$(LIBNAME_OBJG): $(LObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
+$(LIBNAME_OBJG): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
        @echo "Linking $@"
-       $(VERB) $(Relink) -o $@ $(LObjectsG) $(LibSubDirs)
+       $(VERB) $(Relink) -o $@ $(RObjectsG) $(LibSubDirs)
 
 endif
 
@@ -588,7 +628,7 @@ LIB_OPTS_P :=  $(LLVM_LIBS_OPTIONS_P) $(PROJ_LIBS_OPTIONS_P)
 
 # USED_LIB_PATHS - Compute the path of the libraries used so that tools are
 # rebuilt if libraries change.  This has to make sure to handle .a/.so and .o
-# files seperately.
+# files separately.
 #
 STATICUSEDLIBS   := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
 USED_LIB_PATHS_G := $(addprefix $(DESTLIBDEBUG)/, $(STATICUSEDLIBS))
@@ -617,17 +657,17 @@ all::   $(TOOLEXENAMES)
 clean::
        $(VERB) $(RM) -f $(TOOLEXENAMES)
 
-$(TOOLEXENAME_G): $(LObjectsG) $(USED_LIB_PATHS_G) $(DESTTOOLDEBUG)/.dir
-       @echo ======= Linking $(TOOLNAME) debug executable $(STRIP_WARN_MSG)=======
-       $(VERB) $(LinkG) -o $@ $(LObjectsG) $(LIB_OPTS_G) $(LINK_OPTS) $(LIBS)
+$(TOOLEXENAME_G): $(ObjectsG) $(USED_LIB_PATHS_G) $(DESTTOOLDEBUG)/.dir
+       @echo ======= Linking $(TOOLNAME) debug executable $(STRIP_WARN_MSG) =======
+       $(VERB) $(LinkG) -o $@ $(ObjectsG) $(LIB_OPTS_G) $(LINK_OPTS) $(LIBS)
 
-$(TOOLEXENAME_O): $(LObjectsO) $(USED_LIB_PATHS_O) $(DESTTOOLRELEASE)/.dir
+$(TOOLEXENAME_O): $(ObjectsO) $(USED_LIB_PATHS_O) $(DESTTOOLRELEASE)/.dir
        @echo ======= Linking $(TOOLNAME) release executable =======
-       $(VERB) $(LinkO) -o $@ $(LObjectsO) $(LIB_OPTS_O) $(LINK_OPTS) $(LIBS)
+       $(VERB) $(LinkO) -o $@ $(ObjectsO) $(LIB_OPTS_O) $(LINK_OPTS) $(LIBS)
 
-$(TOOLEXENAME_P): $(LObjectsP) $(USED_LIB_PATHS_P) $(DESTTOOLPROFILE)/.dir
+$(TOOLEXENAME_P): $(ObjectsP) $(USED_LIB_PATHS_P) $(DESTTOOLPROFILE)/.dir
        @echo ======= Linking $(TOOLNAME) profile executable =======
-       $(VERB) $(LinkP) -o $@ $(LObjectsP) $(LIB_OPTS_P) $(LINK_OPTS) $(LIBS)
+       $(VERB) $(LinkP) -o $@ $(ObjectsP) $(LIB_OPTS_P) $(LINK_OPTS) $(LIBS)
 
 endif
 
@@ -637,29 +677,6 @@ endif
 .PRECIOUS: $(BUILD_OBJ_DIR)/Depend/.dir
 .PRECIOUS: $(BUILD_OBJ_DIR)/Debug/.dir $(BUILD_OBJ_DIR)/Release/.dir
 
-# Create .o files in the ObjectFiles directory from the .cpp and .c files...
-#$(BUILD_OBJ_DIR)/Release/%.o: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Release/.dir
-       #@echo "Compiling $<"
-       #$(VERB) $(CompileO) $< -o $@
-
-#$(BUILD_OBJ_DIR)/Release/%.o: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Release/.dir
-       #$(VERB) $(CompileCO) $< -o $@
-
-#$(BUILD_OBJ_DIR)/Profile/%.o: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Profile/.dir
-       #@echo "Compiling $<"
-       #$(VERB) $(CompileP) $< -o $@
-
-#$(BUILD_OBJ_DIR)/Profile/%.o: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Profile/.dir
-       #@echo "Compiling $<"
-       #$(VERB) $(CompileCP) $< -o $@
-
-#$(BUILD_OBJ_DIR)/Debug/%.o: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Debug/.dir
-       #@echo "Compiling $<"
-       #$(VERB) $(CompileG) $< -o $@
-
-#$(BUILD_OBJ_DIR)/Debug/%.o: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Debug/.dir 
-       #$(VERB) $(CompileCG) $< -o $@
-
 # Create .lo files in the ObjectFiles directory from the .cpp and .c files...
 $(BUILD_OBJ_DIR)/Release/%.lo: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Release/.dir
        @echo "Compiling $<"
@@ -685,29 +702,6 @@ $(BUILD_OBJ_DIR)/Debug/%.lo: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Debug/.dir
        @echo "Compiling $<"
        $(VERB) $(CompileCG) $< -o $@
 
-# Create .lo files in the ObjectFiles directory from the .cpp and .c files...
-$(BUILD_OBJ_DIR)/Release/%.lo: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Release/.dir
-       @echo "Compiling $<"
-       $(VERB) $(CompileO) $< -o $@
-
-$(BUILD_OBJ_DIR)/Release/%.lo: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Release/.dir
-       $(VERB) $(CompileCO) $< -o $@
-
-$(BUILD_OBJ_DIR)/Profile/%.lo: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Profile/.dir
-       @echo "Compiling $<"
-       $(VERB) $(CompileP) $< -o $@
-
-$(BUILD_OBJ_DIR)/Profile/%.lo: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Profile/.dir
-       @echo "Compiling $<"
-       $(VERB) $(CompileCP) $< -o $@
-
-$(BUILD_OBJ_DIR)/Debug/%.lo: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Debug/.dir
-       @echo "Compiling $<"
-       $(VERB) $(CompileG) $< -o $@
-
-$(BUILD_OBJ_DIR)/Debug/%.lo: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Debug/.dir 
-       $(VERB) $(CompileCG) $< -o $@
-
 #
 # Rules for building lex/yacc files
 #
@@ -726,10 +720,16 @@ YACC_OUTPUT = $(addprefix $(YACC_FILES:%.y=%), .h .cpp .output)
 # FIXME.  (f.e. char Buffer[10000]; )
 #
 %.cpp: %.l
-       $(FLEX) -t $< | $(SED) '/^find_rule/d' | \
-                     $(SED) 's/void yyunput/inline void yyunput/' | \
+       @echo Flex\'ing $<...
+       $(VERB) $(FLEX) -t $< | \
+          $(SED) '/^find_rule/d' | \
+          $(SED) 's/void yyunput/inline void yyunput/' | \
           $(SED) 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' | \
-          $(SED) 's/#define YY_BUF_SIZE 16384/#define YY_BUF_SIZE (16384*64)/' > $@
+          $(SED) 's/#define YY_BUF_SIZE 16384/#define YY_BUF_SIZE (16384*64)/' \
+              > $@.tmp
+       $(VERB) cmp $@ $@.tmp > /dev/null || ${MV} -f $@.tmp $@
+       @# remove the output of flex if it didn't get moved over...
+       @rm -f $@.tmp
 
 # Rule for building the bison parsers...
 %.c: %.y     # Cancel built-in rules for yacc
@@ -737,8 +737,10 @@ YACC_OUTPUT = $(addprefix $(YACC_FILES:%.y=%), .h .cpp .output)
 %.cpp %.h : %.y
        @echo Bison\'ing $<...
        $(VERB) $(BISON) -v -d -p $(<:%Parser.y=%) $*.y
-       $(VERB) ${MV} -f $*.tab.c $*.cpp
-       $(VERB) ${MV} -f $*.tab.h $*.h
+       $(VERB) cmp $*.tab.c $*.cpp > /dev/null || ${MV} -f $*.tab.c $*.cpp
+       $(VERB) cmp $*.tab.h $*.h > /dev/null || ${MV} -f $*.tab.h $*.h
+       @# If the files were not updated, don't leave them lying around...
+       @rm -f $*.tab.c $*.tab.h
 
 # To create the directories...
 %/.dir:
@@ -778,13 +780,6 @@ distclean:: clean
 SourceBaseNames := $(basename $(notdir $(filter-out Debug/%, $(Source))))
 SourceDepend := $(SourceBaseNames:%=$(BUILD_OBJ_DIR)/Depend/%.d)
 
-#
-# Depend target:
-#      This allows a user to manually ask for an update in the dependencies
-#
-depend: $(SourceDepend)
-
-
 # Create dependencies for the *.cpp files...
 #$(SourceDepend): \x
 $(BUILD_OBJ_DIR)/Depend/%.d: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Depend/.dir