Skip to content

Commit beda632

Browse files
authored
Reset mtime of BOLTed files to prevent make rebuilding targets (#55587)
This simplifies the `finish_stage` rule. Co-authored-by: Zentrik <Zentrik@users.noreply.github.com>
1 parent dc60727 commit beda632

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

contrib/bolt/Makefile

+7-5
Original file line numberDiff line numberDiff line change
@@ -79,22 +79,21 @@ copy_originals: stage1
7979

8080
# I don't think there's any particular reason to have -no-huge-pages here, perhaps slightly more accurate profile data
8181
# as the final build uses -no-huge-pages
82+
# We reset the mtime of the files to prevent make from rebuilding targets depending on them.
8283
bolt_instrument: copy_originals
8384
for file in $(FILES_TO_OPTIMIZE); do \
8485
abs_file=$(STAGE1_BUILD)/usr/lib/$$file; \
86+
old_time=$$(stat -c %Y $$abs_file); \
8587
$(LLVM_BOLT) "$$abs_file.original" -o $$abs_file --instrument --instrumentation-file-append-pid --instrumentation-file="$(PROFILE_DIR)/$$file-prof" -no-huge-pages; \
8688
mkdir -p $$(dirname "$(PROFILE_DIR)/$$file-prof"); \
89+
touch -d "@$$old_time" $$abs_file; \
8790
printf "\n"; \
8891
done && \
8992
touch $@
9093
@echo $(AFTER_INSTRUMENT_MESSAGE)
9194

92-
# We don't want to rebuild julia-src as then we lose the bolt instrumentation
93-
# So we have to manually build the sysimage and package image
9495
finish_stage1: stage1
95-
$(MAKE) -C $(STAGE1_BUILD) julia-base-cache && \
96-
$(MAKE) -C $(STAGE1_BUILD) -f sysimage.mk sysimg-release && \
97-
$(MAKE) -C $(STAGE1_BUILD) -f pkgimage.mk release
96+
$(MAKE) -C $(STAGE1_BUILD)
9897

9998
merge_data: bolt_instrument
10099
for file in $(FILES_TO_OPTIMIZE); do \
@@ -108,10 +107,13 @@ merge_data: bolt_instrument
108107
# It tries to reuse old text segments to reduce binary size
109108
# BOLT doesn't fully support computed gotos https://github.com/llvm/llvm-project/issues/89117, so we cannot use --use-old-text on libjulia-internal
110109
# That flag saves less than 1 MiB for libjulia-internal so oh well.
110+
# We reset the mtime of the files to prevent make from rebuilding targets depending on them.
111111
bolt: merge_data
112112
for file in $(FILES_TO_OPTIMIZE); do \
113113
abs_file=$(STAGE1_BUILD)/usr/lib/$$file; \
114+
old_time=$$(stat -c %Y $$abs_file); \
114115
$(LLVM_BOLT) "$$abs_file.original" -data "$(PROFILE_DIR)/$$file-prof.merged.fdata" -o $$abs_file $(BOLT_ARGS) $$(if [ "$$file" != $(shell readlink $(STAGE1_BUILD)/usr/lib/libjulia-internal.so) ]; then echo "--use-old-text -split-strategy=cdsplit"; fi); \
116+
touch -d "@$$old_time" $$abs_file; \
115117
done && \
116118
touch $@
117119

contrib/pgo-lto-bolt/Makefile

+7-5
Original file line numberDiff line numberDiff line change
@@ -123,25 +123,24 @@ copy_originals: stage2
123123

124124
# I don't think there's any particular reason to have -no-huge-pages here, perhaps slightly more accurate profile data
125125
# as the final build uses -no-huge-pages
126+
# We reset the mtime of the files to prevent make from rebuilding targets depending on them.
126127
bolt_instrument: copy_originals
127128
for file in $(FILES_TO_OPTIMIZE); do \
128129
abs_file=$(STAGE2_BUILD)/usr/lib/$$file; \
130+
old_time=$$(stat -c %Y $$abs_file); \
129131
$(LLVM_BOLT) "$$abs_file.original" -o $$abs_file --instrument --instrumentation-file-append-pid --instrumentation-file="$(BOLT_PROFILE_DIR)/$$file-prof" -no-huge-pages; \
130132
mkdir -p $$(dirname "$(BOLT_PROFILE_DIR)/$$file-prof"); \
133+
touch -d "@$$old_time" $$abs_file; \
131134
printf "\n"; \
132135
done && \
133136
touch $@
134137
@echo $(AFTER_INSTRUMENT_MESSAGE)
135138

136-
# We don't want to rebuild julia-src as then we lose the bolt instrumentation
137-
# So we have to manually build the sysimage and package image
138139
finish_stage2: PGO_CFLAGS:=-fprofile-use=$(PGO_PROFILE_FILE)
139140
finish_stage2: PGO_CXXFLAGS:=-fprofile-use=$(PGO_PROFILE_FILE)
140141
finish_stage2: PGO_LDFLAGS:=-flto=thin -fprofile-use=$(PGO_PROFILE_FILE) -Wl,--icf=safe
141142
finish_stage2: stage2
142-
$(MAKE) -C $(STAGE2_BUILD) $(TOOLCHAIN_FLAGS) julia-base-cache && \
143-
$(MAKE) -C $(STAGE2_BUILD) $(TOOLCHAIN_FLAGS) -f sysimage.mk sysimg-release && \
144-
$(MAKE) -C $(STAGE2_BUILD) $(TOOLCHAIN_FLAGS) -f pkgimage.mk release
143+
$(MAKE) -C $(STAGE2_BUILD) $(TOOLCHAIN_FLAGS)
145144

146145
merge_data: bolt_instrument
147146
for file in $(FILES_TO_OPTIMIZE); do \
@@ -155,10 +154,13 @@ merge_data: bolt_instrument
155154
# It tries to reuse old text segments to reduce binary size
156155
# BOLT doesn't fully support computed gotos https://github.com/llvm/llvm-project/issues/89117, so we cannot use --use-old-text on libjulia-internal
157156
# That flag saves less than 1 MiB for libjulia-internal so oh well.
157+
# We reset the mtime of the files to prevent make from rebuilding targets depending on them.
158158
bolt: merge_data
159159
for file in $(FILES_TO_OPTIMIZE); do \
160160
abs_file=$(STAGE2_BUILD)/usr/lib/$$file; \
161+
old_time=$$(stat -c %Y $$abs_file); \
161162
$(LLVM_BOLT) "$$abs_file.original" -data "$(BOLT_PROFILE_DIR)/$$file-prof.merged.fdata" -o $$abs_file $(BOLT_ARGS) $$(if [ "$$file" != $(shell readlink $(STAGE2_BUILD)/usr/lib/libjulia-internal.so) ]; then echo "--use-old-text -split-strategy=cdsplit"; fi); \
163+
touch -d "@$$old_time" $$abs_file; \
162164
done && \
163165
touch $@
164166

0 commit comments

Comments
 (0)