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