-
Notifications
You must be signed in to change notification settings - Fork 190
/
GensrcAdlc.gmk
222 lines (188 loc) · 8.36 KB
/
GensrcAdlc.gmk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
#
# Copyright (c) 2013, 2021, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation. Oracle designates this
# particular file as subject to the "Classpath" exception as provided
# by Oracle in the LICENSE file that accompanied this code.
#
# This code is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
# or visit www.oracle.com if you need additional information or have any
# questions.
#
$(eval $(call IncludeCustomExtension, hotspot/gensrc/GensrcAdlc.gmk))
ifeq ($(call check-jvm-feature, compiler2), true)
ADLC_SUPPORT_DIR := $(JVM_SUPPORT_DIR)/adlc
##############################################################################
# Build the ad compiler (the adlc build tool)
# Flags depending on the build platform/tool chain
# NOTE: No optimization or debug flags set here
ifeq ($(call isBuildOs, linux), true)
ADLC_CFLAGS := -fno-exceptions -DLINUX
else ifeq ($(call isBuildOs, solaris), true)
ADLC_LDFLAGS := -m64
ADLC_CFLAGS := -m64
ADLC_CFLAGS_WARNINGS := +w
else ifeq ($(call isBuildOs, aix), true)
ADLC_LDFLAGS := -q64
ADLC_CFLAGS := -qnortti -qeh -q64 -DAIX
else ifeq ($(call isBuildOs, windows), true)
ADLC_LDFLAGS := -nologo
ADLC_CFLAGS := -nologo -EHsc
# NOTE: The old build also have -D_CRT_SECURE_NO_DEPRECATE but it doesn't
# seem needed any more.
ADLC_CFLAGS_WARNINGS := -W3 -D_CRT_SECURE_NO_WARNINGS
endif
# Set the C++ standard if supported
ADLC_CFLAGS += $(ADLC_CXXFLAG)
# NOTE: The old build didn't set -DASSERT for windows but it doesn't seem to
# hurt.
ADLC_CFLAGS += -DASSERT
ADLC_CFLAGS += -D$(HOTSPOT_TARGET_CPU_DEFINE)
ADLC_CFLAGS += -I$(TOPDIR)/src/hotspot/share
ifneq ($(call check-jvm-feature, shenandoahgc), true)
ADLC_CFLAGS += -DINCLUDE_SHENANDOAHGC=0
endif
$(eval $(call SetupNativeCompilation, BUILD_ADLC, \
NAME := adlc, \
TYPE := EXECUTABLE, \
TOOLCHAIN := TOOLCHAIN_BUILD_LINK_CXX, \
SRC := $(TOPDIR)/src/hotspot/share/adlc, \
EXTRA_FILES := $(TOPDIR)/src/hotspot/share/opto/opcodes.cpp, \
CFLAGS := $(ADLC_CFLAGS) $(ADLC_CFLAGS_WARNINGS), \
LDFLAGS := $(ADLC_LDFLAGS), \
LIBS := $(ADLC_LIBS), \
OBJECT_DIR := $(JVM_VARIANT_OUTPUTDIR)/tools/adlc/objs, \
OUTPUT_DIR := $(JVM_VARIANT_OUTPUTDIR)/tools/adlc, \
DEBUG_SYMBOLS := false, \
DISABLED_WARNINGS_clang := tautological-compare, \
DISABLED_WARNINGS_solstudio := notemsource, \
))
ADLC_TOOL := $(BUILD_ADLC_TARGET)
##############################################################################
# Transform the ad source files into C++ source files using adlc
# Setup flags for the adlc build tool (ADLCFLAGS).
ADLCFLAGS += -q -T
# ADLC flags depending on target OS
ifeq ($(call isTargetOs, linux), true)
ADLCFLAGS += -DLINUX=1 -D_GNU_SOURCE=1
else ifeq ($(call isTargetOs, solaris), true)
ADLCFLAGS += -DSOLARIS=1 -DSPARC_WORKS=1
else ifeq ($(call isTargetOs, aix), true)
ADLCFLAGS += -DAIX=1
else ifeq ($(call isTargetOs, macosx), true)
ADLCFLAGS += -D_ALLBSD_SOURCE=1 -D_GNU_SOURCE=1
ifeq ($(HOTSPOT_TARGET_CPU_ARCH), aarch64)
ADLCFLAGS += -DR18_RESERVED
endif
else ifeq ($(OPENJDK_TARGET_OS), windows)
ifeq ($(call isTargetCpuBits, 64), true)
ADLCFLAGS += -D_WIN64=1
endif
ifeq ($(HOTSPOT_TARGET_CPU_ARCH), aarch64)
ADLCFLAGS += -DR18_RESERVED=1
endif
endif
ifeq ($(call isTargetOs, windows), false)
# NOTE: Windows adlc flags was different in the old build. Is this really
# correct?
# -g makes #line directives in the generated C++ files.
ADLCFLAGS += -g
ADLCFLAGS += -D$(HOTSPOT_TARGET_CPU_DEFINE)=1
endif
# This generates checks in the generated C++ files that _LP64 is correctly
# (un)defined when compiling them.
ifeq ($(call isTargetCpuBits, 64), true)
ADLCFLAGS += -D_LP64=1
else
ADLCFLAGS += -U_LP64
endif
ifeq ($(HOTSPOT_TARGET_CPU_ARCH), arm)
ADLCFLAGS += -DARM=1
endif
##############################################################################
# Concatenate all ad source files into a single file, which will be fed to
# adlc. Also include a #line directive at the start of every included file
# (after the initial header block), stating the original source file name.
#
# Normally, debugging is done directly on the ad_<arch>*.cpp files, but the
# #line directives in those files will be pointing back to <arch>.ad.
# AD_SRC_ROOTS might have been added to by a custom extension
AD_SRC_ROOTS += $(TOPDIR)/src/hotspot
AD_SRC_FILES := $(call uniq, $(wildcard $(foreach d, $(AD_SRC_ROOTS), \
$d/cpu/$(HOTSPOT_TARGET_CPU_ARCH)/$(HOTSPOT_TARGET_CPU).ad \
$d/cpu/$(HOTSPOT_TARGET_CPU_ARCH)/$(HOTSPOT_TARGET_CPU_ARCH).ad \
$d/os_cpu/$(HOTSPOT_TARGET_OS)_$(HOTSPOT_TARGET_CPU_ARCH)/$(HOTSPOT_TARGET_OS)_$(HOTSPOT_TARGET_CPU_ARCH).ad \
)))
ifeq ($(call check-jvm-feature, shenandoahgc), true)
AD_SRC_FILES += $(call uniq, $(wildcard $(foreach d, $(AD_SRC_ROOTS), \
$d/cpu/$(HOTSPOT_TARGET_CPU_ARCH)/gc/shenandoah/shenandoah_$(HOTSPOT_TARGET_CPU).ad \
)))
endif
SINGLE_AD_SRCFILE := $(ADLC_SUPPORT_DIR)/all-ad-src.ad
INSERT_FILENAME_AWK_SCRIPT := \
'{ \
if (CUR_FN != FILENAME) { CUR_FN=FILENAME; NR_BASE=NR-1; need_lineno=1 } \
if (need_lineno && $$0 !~ /\/\//) \
{ print "\n\n\#line " (NR-NR_BASE) " \"" FILENAME "\""; need_lineno=0 }; \
print \
}'
$(SINGLE_AD_SRCFILE): $(AD_SRC_FILES)
$(call LogInfo, Preprocessing adlc files $(^F))
$(call MakeDir, $(@D))
$(NAWK) $(INSERT_FILENAME_AWK_SCRIPT) $^ > $@
##############################################################################
# Run the adlc tool on the single concatenated ad source file, and store the
# output in support/adlc for further processing.
ADLC_RUN_MARKER := $(ADLC_SUPPORT_DIR)/_adlc_run.marker
$(ADLC_RUN_MARKER): $(BUILD_ADLC) $(SINGLE_AD_SRCFILE)
$(call LogInfo, Generating adlc files)
$(call MakeDir, $(@D))
$(call ExecuteWithLog, $(ADLC_SUPPORT_DIR)/adlc_run, \
$(FIXPATH) $(ADLC_TOOL) $(ADLCFLAGS) $(SINGLE_AD_SRCFILE) \
-c$(ADLC_SUPPORT_DIR)/ad_$(HOTSPOT_TARGET_CPU_ARCH).cpp \
-h$(ADLC_SUPPORT_DIR)/ad_$(HOTSPOT_TARGET_CPU_ARCH).hpp \
-a$(ADLC_SUPPORT_DIR)/dfa_$(HOTSPOT_TARGET_CPU_ARCH).cpp \
-v$(ADLC_SUPPORT_DIR)/adGlobals_$(HOTSPOT_TARGET_CPU_ARCH).hpp)
$(TOUCH) $@
##############################################################################
# Finally copy the generated files from support/adlc into gensrc/adfiles,
# and postprocess them by fixing dummy #line directives.
ADLC_GENERATED_FILES := $(addprefix $(JVM_VARIANT_OUTPUTDIR)/gensrc/adfiles/, \
ad_$(HOTSPOT_TARGET_CPU_ARCH).cpp \
ad_$(HOTSPOT_TARGET_CPU_ARCH).hpp \
ad_$(HOTSPOT_TARGET_CPU_ARCH)_clone.cpp \
ad_$(HOTSPOT_TARGET_CPU_ARCH)_expand.cpp \
ad_$(HOTSPOT_TARGET_CPU_ARCH)_format.cpp \
ad_$(HOTSPOT_TARGET_CPU_ARCH)_gen.cpp \
ad_$(HOTSPOT_TARGET_CPU_ARCH)_misc.cpp \
ad_$(HOTSPOT_TARGET_CPU_ARCH)_peephole.cpp \
ad_$(HOTSPOT_TARGET_CPU_ARCH)_pipeline.cpp \
adGlobals_$(HOTSPOT_TARGET_CPU_ARCH).hpp \
dfa_$(HOTSPOT_TARGET_CPU_ARCH).cpp \
)
$(JVM_VARIANT_OUTPUTDIR)/gensrc/adfiles/%: $(ADLC_RUN_MARKER)
$(call LogInfo, Postprocessing adlc file $*)
$(call MakeDir, $(@D))
$(NAWK) \
'BEGIN { print "#line 1 \"$*\""; } \
/^#line 999999$$/ {print "#line " (NR+1) " \"$*\""; next} \
$(if $(call equals, $(ALLOW_ABSOLUTE_PATHS_IN_OUTPUT), false), \
/^#line .*$$/ {sub("$(WORKSPACE_ROOT)/","")} \
) \
{print}' \
< $(ADLC_SUPPORT_DIR)/$* > $@
TARGETS := $(ADLC_GENERATED_FILES)
endif