├── .gitignore ├── README.md └── ruby ├── Makefile ├── build ├── files │ ├── common.mk │ ├── host │ │ ├── p.mk │ │ ├── x.mk │ │ └── z.mk │ └── target │ │ ├── amd64.mk │ │ ├── i386.mk │ │ ├── p.mk │ │ ├── x.mk │ │ └── z.mk ├── platform │ ├── common.mk │ ├── host │ │ ├── amd64-linux64-clang.mk │ │ ├── amd64-linux64-gcc.mk │ │ ├── amd64-osx-clang.mk │ │ ├── ppc64-linux64-clang.mk │ │ ├── ppc64-linux64-gcc.mk │ │ ├── ppc64le-linux64-clang.mk │ │ ├── ppc64le-linux64-gcc.mk │ │ ├── s390-linux-clang.mk │ │ ├── s390-linux64-clang.mk │ │ └── s390-linux64-gcc.mk │ └── target │ │ └── all.mk ├── rules │ ├── common.mk │ └── gnu │ │ ├── common.mk │ │ └── filetypes.mk ├── scripts │ ├── armasm2gas.sed │ ├── generateVersion.pl │ ├── guess-platform.sh │ ├── masm2gas.pl │ └── s390m4check.pl └── toolcfg │ ├── common.mk │ ├── gnu │ └── common.mk │ ├── host │ ├── 32.mk │ ├── 64.mk │ ├── linux.mk │ ├── osx.mk │ ├── p.mk │ ├── x.mk │ └── z.mk │ └── target │ ├── 32.mk │ ├── 64.mk │ ├── p.mk │ ├── x.mk │ └── z.mk ├── codegen ├── CodeGenerator.hpp └── RubyCodeGenerator.hpp ├── compile ├── Compilation.hpp ├── RubyCompilation.cpp ├── RubyCompilation.hpp ├── RubySymbolReferenceTable.cpp ├── RubySymbolReferenceTable.hpp └── SymbolReferenceTable.hpp ├── control └── RubyJit.cpp ├── env ├── ConcreteFE.hpp ├── ObjectModel.hpp ├── RubyFE.cpp ├── RubyFE.hpp ├── RubyMethod.cpp ├── RubyMethod.hpp └── RubyObjectModel.hpp ├── il ├── Node.hpp ├── RubyNode.cpp ├── RubyNode.hpp ├── RubySymbolReference.hpp └── SymbolReference.hpp ├── ilgen ├── .RubyIlGenerator.cpp.swp ├── .RubyIlGenerator.hpp.swp ├── IlGeneratorMethodDetails.hpp ├── RubyByteCodeIterator.cpp ├── RubyByteCodeIterator.hpp ├── RubyByteCodeIteratorWithState.hpp ├── RubyIlGenerator.cpp ├── RubyIlGenerator.hpp ├── RubyIlGeneratorMethodDetails.cpp └── RubyIlGeneratorMethodDetails.hpp ├── infra ├── Monitor.hpp ├── RubyMonitor.cpp └── RubyMonitor.hpp ├── linter.mk ├── optimizer ├── OptimizationManager.hpp ├── Optimizer.cpp ├── Optimizer.hpp ├── RubyCallInfo.cpp ├── RubyCallInfo.hpp ├── RubyIlFastpather.cpp ├── RubyIlFastpather.hpp ├── RubyInliner.cpp ├── RubyInliner.hpp ├── RubyLowerMacroOps.cpp ├── RubyLowerMacroOps.hpp ├── RubyOptimizationManager.cpp ├── RubyOptimizationManager.hpp ├── RubyOptimizer.hpp ├── RubyTrivialInliner.cpp └── RubyTrivialInliner.hpp ├── p └── runtime │ ├── AsmUtil.spp │ ├── CodeDispatch.spp │ └── CodeSync.cpp ├── ruby.mk ├── runtime ├── CodeCacheManager.hpp ├── RubyCodeCacheManager.cpp ├── RubyCodeCacheManager.hpp └── RubyJitConfig.hpp ├── x ├── codegen │ └── Evaluator.cpp └── runtime │ └── AsmUtil64.asm └── z └── codegen ├── Evaluator.cpp ├── RubyCodeGenerator.cpp └── RubyCodeGenerator.hpp /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files 2 | *.slo 3 | *.lo 4 | *.o 5 | *.obj 6 | 7 | # Precompiled Headers 8 | *.gch 9 | *.pch 10 | 11 | # Compiled Dynamic libraries 12 | *.so 13 | *.dylib 14 | *.dll 15 | 16 | # Fortran module files 17 | *.mod 18 | *.smod 19 | 20 | # Compiled Static libraries 21 | *.lai 22 | *.la 23 | *.a 24 | *.lib 25 | 26 | # Executables 27 | *.exe 28 | *.out 29 | *.app 30 | 31 | 32 | ruby/rbjitglue/ 33 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | The Ruby+OMR Just-In-Time Compiler 2 | ================================== 3 | 4 | This repository contains the Ruby-specific JIT glue code that combines with the 5 | [Eclipse OMR](https://github.com/eclipse/omr) to form a Just-In-Time compiler 6 | for Ruby. 7 | 8 | Read more about the Ruby+OMR Preview in the [rubyomr-preview repo][omrpreview]. 9 | 10 | Current Status 11 | -------------- 12 | 13 | This JIT compiler currently only supports a specially modified version of Ruby 14 | 2.2, and currently exercises only a small fraction of the optimizations that 15 | exist in OMR. 16 | 17 | Platforms: 18 | ---------- 19 | 20 | Currently this JIT has only been built and tested on Linux, x86, POWER, and 21 | z/Architecture (s390x). 22 | 23 | Currently, the OMR JIT doesn't support OS X, however [an issue is open][osx]. 24 | 25 | 26 | Prerequisites: 27 | -------------- 28 | 29 | 30 | Building this JIT requires 31 | 32 | 1. A copy of the CRuby source code, modified with the OMR JIT interface. 33 | We currently have a copy of said VM in the [Ruby+OMR Preview Github 34 | organization.][rubyvm] 35 | 36 | Branches that support building against this JIT, have the current repository 37 | added as a submodule. 38 | 39 | 2. A copy of the Eclipse OMR project. This too should exist as a submodule 40 | in one of the branches of the VM above. 41 | 42 | 43 | Recent Talks 44 | ------------ 45 | 46 | * Matthew Gaudet's talk at RubyKaigi 2015 _Experiments in sharing Java VM 47 | technology with CRuby_ -- [(slides)][kaigi2015slides] [(video)][kaigi2015video] 48 | 49 | 50 | 51 | 52 | [osx]: https://github.com/eclipse/omr/issues/223 53 | [rubyvm]: https://github.com/rubyomr-preview/ruby 54 | [kaigi2015slides]: http://www.slideshare.net/MatthewGaudet/experiments-in-sharing-java-vm-technology-with-cruby 55 | [kaigi2015video]: https://www.youtube.com/watch?v=EDxoaEdR-_M 56 | [omrpreview]: https://github.com/rubyomr-preview/rubyomr-preview 57 | -------------------------------------------------------------------------------- /ruby/Makefile: -------------------------------------------------------------------------------- 1 | ################################################################################## 2 | # (c) Copyright IBM Corp. 2000, 2016 3 | # 4 | # This program and the accompanying materials are made available 5 | # under the terms of the Eclipse Public License v1.0 and 6 | # Apache License v2.0 which accompanies this distribution. 7 | # 8 | # The Eclipse Public License is available at 9 | # http://www.eclipse.org/legal/epl-v10.html 10 | # 11 | # The Apache License v2.0 is available at 12 | # http://www.opensource.org/licenses/apache2.0.php 13 | # 14 | # Contributors: 15 | # Multiple authors (IBM Corp.) - initial implementation and documentation 16 | ################################################################################## 17 | 18 | 19 | 20 | .PHONY: all clean cleanobjs cleandeps cleandll 21 | all: 22 | clean: 23 | cleanobjs: 24 | cleandeps: 25 | cleandll: 26 | 27 | # This is the logic right now for locating Clang and LLVM-config 28 | # There's probably a nicer way to do all of this... it's pretty bad 29 | 30 | ifeq ($(PLATFORM),amd64-linux64-clang) 31 | # Luckily we can just use the default path for Clang :) 32 | endif 33 | 34 | ifeq ($(PLATFORM),ppc64-linux64-clang) 35 | export CC_PATH?=/tr/llvm_checker/ppc-64/sles11/bin/clang 36 | export CXX_PATH?=/tr/llvm_checker/ppc-64/sles11/bin/clang++ 37 | endif 38 | 39 | ifeq ($(PLATFORM),s390-zos64-vacpp) 40 | export CC_PATH?=/usr/lpp/cbclib/xlc/bin/xlc 41 | export CXX_PATH?=/usr/lpp/cbclib/xlc/bin/xlC 42 | export A2E_INCLUDE_PATH?=/usr/lpp/cbclib/include 43 | endif 44 | 45 | ifeq ($(PLATFORM),arm-linux-gcc-cross) 46 | export CC_PATH?=arm-bcm2708hardfp-linux-gnueabi-gcc 47 | export CXX_PATH?=arm-bcm2708hardfp-linux-gnueabi-g++ 48 | export AS_PATH?=arm-bcm2708hardfp-linux-gnueabi-as 49 | SUBMAKE_EXTRAARGS=PLATFORM=arm-linux-gcc 50 | endif 51 | 52 | SUBMAKE_EXTRAARGS=ASSUMES=1 53 | 54 | # 55 | # Add Ruby to base targets and lint targets 56 | # 57 | all: ruby 58 | clean: ruby_clean 59 | cleanobjs: ruby_cleanobjs 60 | cleandeps: ruby_cleandeps 61 | cleandll: ruby_cleandll 62 | 63 | # 64 | # Add Ruby targets 65 | # 66 | .PHONY: ruby ruby_clean ruby_cleanobjs ruby_cleandeps ruby_cleandll 67 | 68 | ruby: 69 | $(MAKE) -f ruby.mk $(SUBMAKE_EXTRAARGS) 70 | 71 | ruby_clean: 72 | $(MAKE) -f ruby.mk clean $(SUBMAKE_EXTRAARGS) 73 | 74 | ruby_cleanobjs: 75 | $(MAKE) -f ruby.mk cleanobjs $(SUBMAKE_EXTRAARGS) 76 | 77 | ruby_cleandeps: 78 | $(MAKE) -f ruby.mk cleandeps $(SUBMAKE_EXTRAARGS) 79 | 80 | ruby_cleandll: 81 | $(MAKE) -f ruby.mk cleandll $(SUBMAKE_EXTRAARGS) 82 | -------------------------------------------------------------------------------- /ruby/build/files/host/p.mk: -------------------------------------------------------------------------------- 1 | ################################################################################### 2 | # (c) Copyright IBM Corp. 2000, 2016 3 | # 4 | # This program and the accompanying materials are made available 5 | # under the terms of the Eclipse Public License v1.0 and 6 | # Apache License v2.0 which accompanies this distribution. 7 | # 8 | # The Eclipse Public License is available at 9 | # http://www.eclipse.org/legal/epl-v10.html 10 | # 11 | # The Apache License v2.0 is available at 12 | # http://www.opensource.org/licenses/apache2.0.php 13 | # 14 | # Contributors: 15 | # Multiple authors (IBM Corp.) - initial implementation and documentation 16 | ################################################################################## 17 | 18 | 19 | JIT_PRODUCT_SOURCE_FILES+=\ 20 | $(JIT_PRODUCT_DIR)/p/runtime/AsmUtil.spp \ 21 | $(JIT_PRODUCT_DIR)/p/runtime/CodeDispatch.spp \ 22 | $(JIT_PRODUCT_DIR)/p/runtime/CodeSync.cpp \ 23 | $(JIT_OMR_DIRTY_DIR)/p/runtime/OMRCodeCacheConfig.cpp 24 | -------------------------------------------------------------------------------- /ruby/build/files/host/x.mk: -------------------------------------------------------------------------------- 1 | ################################################################################### 2 | # (c) Copyright IBM Corp. 2000, 2016 3 | # 4 | # This program and the accompanying materials are made available 5 | # under the terms of the Eclipse Public License v1.0 and 6 | # Apache License v2.0 which accompanies this distribution. 7 | # 8 | # The Eclipse Public License is available at 9 | # http://www.eclipse.org/legal/epl-v10.html 10 | # 11 | # The Apache License v2.0 is available at 12 | # http://www.opensource.org/licenses/apache2.0.php 13 | # 14 | # Contributors: 15 | # Multiple authors (IBM Corp.) - initial implementation and documentation 16 | ################################################################################## 17 | 18 | 19 | 20 | JIT_PRODUCT_SOURCE_FILES+=\ 21 | $(JIT_PRODUCT_DIR)/x/runtime/AsmUtil64.asm \ 22 | $(JIT_OMR_DIRTY_DIR)/x/runtime/CPUID.asm 23 | -------------------------------------------------------------------------------- /ruby/build/files/host/z.mk: -------------------------------------------------------------------------------- 1 | ################################################################################### 2 | # (c) Copyright IBM Corp. 2000, 2016 3 | # 4 | # This program and the accompanying materials are made available 5 | # under the terms of the Eclipse Public License v1.0 and 6 | # Apache License v2.0 which accompanies this distribution. 7 | # 8 | # The Eclipse Public License is available at 9 | # http://www.eclipse.org/legal/epl-v10.html 10 | # 11 | # The Apache License v2.0 is available at 12 | # http://www.opensource.org/licenses/apache2.0.php 13 | # 14 | # Contributors: 15 | # Multiple authors (IBM Corp.) - initial implementation and documentation 16 | ################################################################################## 17 | 18 | 19 | JIT_PRODUCT_SOURCE_FILES+= 20 | -------------------------------------------------------------------------------- /ruby/build/files/target/amd64.mk: -------------------------------------------------------------------------------- 1 | ################################################################################### 2 | # (c) Copyright IBM Corp. 2000, 2016 3 | # 4 | # This program and the accompanying materials are made available 5 | # under the terms of the Eclipse Public License v1.0 and 6 | # Apache License v2.0 which accompanies this distribution. 7 | # 8 | # The Eclipse Public License is available at 9 | # http://www.eclipse.org/legal/epl-v10.html 10 | # 11 | # The Apache License v2.0 is available at 12 | # http://www.opensource.org/licenses/apache2.0.php 13 | # 14 | # Contributors: 15 | # Multiple authors (IBM Corp.) - initial implementation and documentation 16 | ################################################################################## 17 | 18 | 19 | JIT_PRODUCT_SOURCE_FILES+=\ 20 | $(JIT_OMR_DIRTY_DIR)/x/amd64/codegen/OMRCodeGenerator.cpp \ 21 | $(JIT_OMR_DIRTY_DIR)/x/amd64/codegen/OMRMachine.cpp \ 22 | $(JIT_OMR_DIRTY_DIR)/x/amd64/codegen/OMRMemoryReference.cpp \ 23 | $(JIT_OMR_DIRTY_DIR)/x/amd64/codegen/OMRRealRegister.cpp \ 24 | $(JIT_OMR_DIRTY_DIR)/x/amd64/codegen/OMRTreeEvaluator.cpp \ 25 | $(JIT_OMR_DIRTY_DIR)/x/amd64/codegen/AMD64FPConversionSnippet.cpp \ 26 | $(JIT_OMR_DIRTY_DIR)/x/amd64/codegen/AMD64SystemLinkage.cpp 27 | -------------------------------------------------------------------------------- /ruby/build/files/target/i386.mk: -------------------------------------------------------------------------------- 1 | ################################################################################### 2 | # (c) Copyright IBM Corp. 2000, 2016 3 | # 4 | # This program and the accompanying materials are made available 5 | # under the terms of the Eclipse Public License v1.0 and 6 | # Apache License v2.0 which accompanies this distribution. 7 | # 8 | # The Eclipse Public License is available at 9 | # http://www.eclipse.org/legal/epl-v10.html 10 | # 11 | # The Apache License v2.0 is available at 12 | # http://www.opensource.org/licenses/apache2.0.php 13 | # 14 | # Contributors: 15 | # Multiple authors (IBM Corp.) - initial implementation and documentation 16 | ################################################################################## 17 | 18 | 19 | JIT_PRODUCT_SOURCE_FILES+=\ 20 | $(JIT_OMR_DIRTY_DIR)/x/i386/codegen/OMRCodeGenerator.cpp \ 21 | $(JIT_OMR_DIRTY_DIR)/x/i386/codegen/OMRMachine.cpp \ 22 | $(JIT_OMR_DIRTY_DIR)/x/i386/codegen/OMRRealRegister.cpp \ 23 | $(JIT_OMR_DIRTY_DIR)/x/i386/codegen/IA32SystemLinkage.cpp \ 24 | $(JIT_OMR_DIRTY_DIR)/x/i386/codegen/OMRTreeEvaluator.cpp 25 | -------------------------------------------------------------------------------- /ruby/build/files/target/p.mk: -------------------------------------------------------------------------------- 1 | ################################################################################### 2 | # (c) Copyright IBM Corp. 2000, 2016 3 | # 4 | # This program and the accompanying materials are made available 5 | # under the terms of the Eclipse Public License v1.0 and 6 | # Apache License v2.0 which accompanies this distribution. 7 | # 8 | # The Eclipse Public License is available at 9 | # http://www.eclipse.org/legal/epl-v10.html 10 | # 11 | # The Apache License v2.0 is available at 12 | # http://www.opensource.org/licenses/apache2.0.php 13 | # 14 | # Contributors: 15 | # Multiple authors (IBM Corp.) - initial implementation and documentation 16 | ################################################################################## 17 | 18 | 19 | JIT_PRODUCT_SOURCE_FILES+=\ 20 | $(JIT_OMR_DIRTY_DIR)/p/codegen/BinaryEvaluator.cpp \ 21 | $(JIT_OMR_DIRTY_DIR)/p/codegen/ControlFlowEvaluator.cpp \ 22 | $(JIT_OMR_DIRTY_DIR)/p/codegen/FPTreeEvaluator.cpp \ 23 | $(JIT_OMR_DIRTY_DIR)/p/codegen/GenerateInstructions.cpp \ 24 | $(JIT_OMR_DIRTY_DIR)/p/codegen/OMRMemoryReference.cpp \ 25 | $(JIT_OMR_DIRTY_DIR)/p/codegen/OpBinary.cpp \ 26 | $(JIT_OMR_DIRTY_DIR)/p/codegen/OpProperties.cpp \ 27 | $(JIT_OMR_DIRTY_DIR)/p/codegen/PPCAOTRelocation.cpp \ 28 | $(JIT_OMR_DIRTY_DIR)/p/codegen/PPCBinaryEncoding.cpp \ 29 | $(JIT_OMR_DIRTY_DIR)/p/codegen/OMRCodeGenerator.cpp \ 30 | $(JIT_OMR_DIRTY_DIR)/p/codegen/OMRInstruction.cpp \ 31 | $(JIT_OMR_DIRTY_DIR)/p/codegen/PPCDebug.cpp \ 32 | $(JIT_OMR_DIRTY_DIR)/p/codegen/PPCHelperCallSnippet.cpp \ 33 | $(JIT_OMR_DIRTY_DIR)/p/codegen/PPCInstruction.cpp \ 34 | $(JIT_OMR_DIRTY_DIR)/p/codegen/OMRLinkage.cpp \ 35 | $(JIT_OMR_DIRTY_DIR)/p/codegen/PPCSystemLinkage.cpp \ 36 | $(JIT_OMR_DIRTY_DIR)/p/codegen/OMRMachine.cpp \ 37 | $(JIT_OMR_DIRTY_DIR)/p/codegen/PPCOutOfLineCodeSection.cpp \ 38 | $(JIT_OMR_DIRTY_DIR)/p/codegen/OMRRealRegister.cpp \ 39 | $(JIT_OMR_DIRTY_DIR)/p/codegen/OMRRegisterDependency.cpp \ 40 | $(JIT_OMR_DIRTY_DIR)/p/codegen/OMRSnippet.cpp \ 41 | $(JIT_OMR_DIRTY_DIR)/p/codegen/PPCTableOfConstants.cpp \ 42 | $(JIT_OMR_DIRTY_DIR)/p/codegen/OMRTreeEvaluator.cpp \ 43 | $(JIT_OMR_DIRTY_DIR)/p/codegen/TreeEvaluatorVMX.cpp \ 44 | $(JIT_OMR_DIRTY_DIR)/p/codegen/UnaryEvaluator.cpp \ 45 | $(JIT_OMR_DIRTY_DIR)/p/codegen/OMRConstantDataSnippet.cpp \ 46 | $(JIT_OMR_DIRTY_DIR)/p/codegen/OMRRegisterIterator.cpp \ 47 | $(JIT_OMR_DIRTY_DIR)/p/env/OMRCPU.cpp \ 48 | $(JIT_OMR_DIRTY_DIR)/p/env/OMRDebugEnv.cpp \ 49 | -------------------------------------------------------------------------------- /ruby/build/files/target/x.mk: -------------------------------------------------------------------------------- 1 | ################################################################################### 2 | # (c) Copyright IBM Corp. 2000, 2016 3 | # 4 | # This program and the accompanying materials are made available 5 | # under the terms of the Eclipse Public License v1.0 and 6 | # Apache License v2.0 which accompanies this distribution. 7 | # 8 | # The Eclipse Public License is available at 9 | # http://www.eclipse.org/legal/epl-v10.html 10 | # 11 | # The Apache License v2.0 is available at 12 | # http://www.opensource.org/licenses/apache2.0.php 13 | # 14 | # Contributors: 15 | # Multiple authors (IBM Corp.) - initial implementation and documentation 16 | ################################################################################## 17 | 18 | 19 | JIT_PRODUCT_SOURCE_FILES+=\ 20 | $(JIT_OMR_DIRTY_DIR)/x/codegen/BinaryCommutativeAnalyser.cpp \ 21 | $(JIT_OMR_DIRTY_DIR)/x/codegen/BinaryEvaluator.cpp \ 22 | $(JIT_OMR_DIRTY_DIR)/x/codegen/CompareAnalyser.cpp \ 23 | $(JIT_OMR_DIRTY_DIR)/x/codegen/ConstantDataSnippet.cpp \ 24 | $(JIT_OMR_DIRTY_DIR)/x/codegen/ControlFlowEvaluator.cpp \ 25 | $(JIT_OMR_DIRTY_DIR)/x/codegen/DataSnippet.cpp \ 26 | $(JIT_OMR_DIRTY_DIR)/x/codegen/DivideCheckSnippet.cpp \ 27 | $(JIT_OMR_DIRTY_DIR)/x/codegen/FPBinaryArithmeticAnalyser.cpp \ 28 | $(JIT_OMR_DIRTY_DIR)/x/codegen/FPCompareAnalyser.cpp \ 29 | $(JIT_OMR_DIRTY_DIR)/x/codegen/FPTreeEvaluator.cpp \ 30 | $(JIT_OMR_DIRTY_DIR)/x/codegen/HelperCallSnippet.cpp \ 31 | $(JIT_OMR_DIRTY_DIR)/x/codegen/IA32LinkageUtils.cpp \ 32 | $(JIT_OMR_DIRTY_DIR)/x/codegen/IntegerMultiplyDecomposer.cpp \ 33 | $(JIT_OMR_DIRTY_DIR)/x/codegen/OMRMemoryReference.cpp \ 34 | $(JIT_OMR_DIRTY_DIR)/x/codegen/OpBinary.cpp \ 35 | $(JIT_OMR_DIRTY_DIR)/x/codegen/OpNames.cpp \ 36 | $(JIT_OMR_DIRTY_DIR)/x/codegen/OpProperties.cpp \ 37 | $(JIT_OMR_DIRTY_DIR)/x/codegen/OutlinedInstructions.cpp \ 38 | $(JIT_OMR_DIRTY_DIR)/x/codegen/RegisterRematerialization.cpp \ 39 | $(JIT_OMR_DIRTY_DIR)/x/codegen/SubtractAnalyser.cpp \ 40 | $(JIT_OMR_DIRTY_DIR)/x/codegen/OMRTreeEvaluator.cpp \ 41 | $(JIT_OMR_DIRTY_DIR)/x/codegen/UnaryEvaluator.cpp \ 42 | $(JIT_OMR_DIRTY_DIR)/x/codegen/X86BinaryEncoding.cpp \ 43 | $(JIT_OMR_DIRTY_DIR)/x/codegen/X86Debug.cpp \ 44 | $(JIT_OMR_DIRTY_DIR)/x/codegen/X86FPConversionSnippet.cpp \ 45 | $(JIT_OMR_DIRTY_DIR)/x/codegen/OMRInstruction.cpp \ 46 | $(JIT_OMR_DIRTY_DIR)/x/codegen/OMRX86Instruction.cpp \ 47 | $(JIT_OMR_DIRTY_DIR)/x/codegen/OMRMachine.cpp \ 48 | $(JIT_OMR_DIRTY_DIR)/x/codegen/OMRLinkage.cpp \ 49 | $(JIT_OMR_DIRTY_DIR)/x/codegen/OMRRealRegister.cpp \ 50 | $(JIT_OMR_DIRTY_DIR)/x/codegen/OMRRegister.cpp \ 51 | $(JIT_OMR_DIRTY_DIR)/x/codegen/OMRRegisterDependency.cpp \ 52 | $(JIT_OMR_DIRTY_DIR)/x/codegen/OMRSnippet.cpp \ 53 | $(JIT_OMR_DIRTY_DIR)/x/codegen/X86SystemLinkage.cpp \ 54 | $(JIT_OMR_DIRTY_DIR)/x/codegen/XMMBinaryArithmeticAnalyser.cpp \ 55 | $(JIT_OMR_DIRTY_DIR)/x/codegen/OMRCodeGenerator.cpp \ 56 | $(JIT_OMR_DIRTY_DIR)/x/codegen/OMRRegisterIterator.cpp \ 57 | $(JIT_OMR_DIRTY_DIR)/x/env/OMRDebugEnv.cpp \ 58 | $(JIT_OMR_DIRTY_DIR)/x/env/OMRCPU.cpp \ 59 | $(JIT_PRODUCT_DIR)/x/codegen/Evaluator.cpp 60 | 61 | 62 | include $(JIT_MAKE_DIR)/files/target/$(TARGET_SUBARCH).mk 63 | -------------------------------------------------------------------------------- /ruby/build/files/target/z.mk: -------------------------------------------------------------------------------- 1 | ################################################################################### 2 | # (c) Copyright IBM Corp. 2000, 2016 3 | # 4 | # This program and the accompanying materials are made available 5 | # under the terms of the Eclipse Public License v1.0 and 6 | # Apache License v2.0 which accompanies this distribution. 7 | # 8 | # The Eclipse Public License is available at 9 | # http://www.eclipse.org/legal/epl-v10.html 10 | # 11 | # The Apache License v2.0 is available at 12 | # http://www.opensource.org/licenses/apache2.0.php 13 | # 14 | # Contributors: 15 | # Multiple authors (IBM Corp.) - initial implementation and documentation 16 | ################################################################################## 17 | 18 | 19 | JIT_PRODUCT_SOURCE_FILES+=\ 20 | $(JIT_OMR_DIRTY_DIR)/z/codegen/BinaryAnalyser.cpp \ 21 | $(JIT_OMR_DIRTY_DIR)/z/codegen/BinaryCommutativeAnalyser.cpp \ 22 | $(JIT_OMR_DIRTY_DIR)/z/codegen/BinaryEvaluator.cpp \ 23 | $(JIT_OMR_DIRTY_DIR)/z/codegen/CallSnippet.cpp \ 24 | $(JIT_OMR_DIRTY_DIR)/z/codegen/CompareAnalyser.cpp \ 25 | $(JIT_OMR_DIRTY_DIR)/z/codegen/ConstantDataSnippet.cpp \ 26 | $(JIT_OMR_DIRTY_DIR)/z/codegen/ControlFlowEvaluator.cpp \ 27 | $(JIT_OMR_DIRTY_DIR)/z/codegen/FPTreeEvaluator.cpp \ 28 | $(JIT_OMR_DIRTY_DIR)/z/codegen/OMRMemoryReference.cpp \ 29 | $(JIT_OMR_DIRTY_DIR)/z/codegen/OpMemToMem.cpp \ 30 | $(JIT_OMR_DIRTY_DIR)/z/codegen/OMRMachine.cpp \ 31 | $(JIT_OMR_DIRTY_DIR)/z/codegen/S390BranchCondNames.cpp \ 32 | $(JIT_OMR_DIRTY_DIR)/z/codegen/S390Debug.cpp \ 33 | $(JIT_OMR_DIRTY_DIR)/z/codegen/S390GenerateInstructions.cpp \ 34 | $(JIT_OMR_DIRTY_DIR)/z/codegen/S390HelperCallSnippet.cpp \ 35 | $(JIT_OMR_DIRTY_DIR)/z/codegen/S390Instruction.cpp \ 36 | $(JIT_OMR_DIRTY_DIR)/z/codegen/OMRLinkage.cpp \ 37 | $(JIT_OMR_DIRTY_DIR)/z/codegen/SystemLinkage.cpp \ 38 | $(JIT_OMR_DIRTY_DIR)/z/codegen/S390OutOfLineCodeSection.cpp \ 39 | $(JIT_OMR_DIRTY_DIR)/z/codegen/OMRRegisterDependency.cpp \ 40 | $(JIT_OMR_DIRTY_DIR)/z/codegen/OMRSnippet.cpp \ 41 | $(JIT_OMR_DIRTY_DIR)/z/codegen/S390Snippets.cpp \ 42 | $(JIT_OMR_DIRTY_DIR)/z/codegen/TranslateEvaluator.cpp \ 43 | $(JIT_OMR_DIRTY_DIR)/z/codegen/OMRTreeEvaluator.cpp \ 44 | $(JIT_OMR_DIRTY_DIR)/z/codegen/UnaryEvaluator.cpp \ 45 | $(JIT_OMR_DIRTY_DIR)/z/codegen/OMRInstruction.cpp \ 46 | $(JIT_OMR_DIRTY_DIR)/z/codegen/OMRRegister.cpp \ 47 | $(JIT_OMR_DIRTY_DIR)/z/codegen/OMRRealRegister.cpp \ 48 | $(JIT_OMR_DIRTY_DIR)/z/codegen/OMRCodeGenerator.cpp \ 49 | $(JIT_OMR_DIRTY_DIR)/z/codegen/OMRCodeGenPhase.cpp \ 50 | $(JIT_OMR_DIRTY_DIR)/z/codegen/InstOpCode.cpp \ 51 | $(JIT_OMR_DIRTY_DIR)/z/codegen/InstOpCodeTables.cpp \ 52 | $(JIT_OMR_DIRTY_DIR)/z/codegen/OMRRegisterIterator.cpp \ 53 | $(JIT_OMR_DIRTY_DIR)/z/codegen/OMRRegisterPair.cpp \ 54 | $(JIT_PRODUCT_DIR)/z/codegen/RubyCodeGenerator.cpp \ 55 | $(JIT_PRODUCT_DIR)/z/codegen/Evaluator.cpp \ 56 | $(JIT_OMR_DIRTY_DIR)/z/env/OMRDebugEnv.cpp 57 | -------------------------------------------------------------------------------- /ruby/build/platform/common.mk: -------------------------------------------------------------------------------- 1 | ################################################################################### 2 | # (c) Copyright IBM Corp. 2000, 2016 3 | # 4 | # This program and the accompanying materials are made available 5 | # under the terms of the Eclipse Public License v1.0 and 6 | # Apache License v2.0 which accompanies this distribution. 7 | # 8 | # The Eclipse Public License is available at 9 | # http://www.eclipse.org/legal/epl-v10.html 10 | # 11 | # The Apache License v2.0 is available at 12 | # http://www.opensource.org/licenses/apache2.0.php 13 | # 14 | # Contributors: 15 | # Multiple authors (IBM Corp.) - initial implementation and documentation 16 | ################################################################################## 17 | 18 | 19 | # 20 | # Common file for setting platform tokens 21 | # Mostly just guesses the platform and includes the relevant 22 | # HOST and TARGET files 23 | # 24 | 25 | # 26 | # Try and guess platform if user didn't give it 27 | # 28 | ifeq (,$(PLATFORM)) 29 | PLATFORM:=$(shell $(SHELL) $(JIT_SCRIPT_DIR)/guess-platform.sh) 30 | $(warning PLATFORM not set. Guessing '$(PLATFORM)') 31 | endif 32 | 33 | # 34 | # If we still can't figure it out, bomb out with an error 35 | # 36 | ifeq (,$(PLATFORM)) 37 | $(error PLATFORM not set and unable to guess) 38 | endif 39 | 40 | # Make sure platform file exists 41 | $(if $(wildcard $(JIT_MAKE_DIR)/platform/host/$(PLATFORM).mk),,$(error Error: $(PLATFORM) not implemented)) 42 | 43 | # 44 | # This is where we set variables based on the "host triplet" 45 | # These variables will be tested all throughout the rest of the makefile 46 | # to make decisions based on our host architecture, OS, and toolchain 47 | # 48 | include $(JIT_MAKE_DIR)/platform/host/$(PLATFORM).mk 49 | 50 | # 51 | # This will set up the target variables 52 | # We will use these later to make decisions related to target arch 53 | # 54 | # Right now, we really don't have anything special like a 55 | # "target spec", but this leaves it open in the future 56 | # 57 | include $(JIT_MAKE_DIR)/platform/target/all.mk 58 | -------------------------------------------------------------------------------- /ruby/build/platform/host/amd64-linux64-clang.mk: -------------------------------------------------------------------------------- 1 | ################################################################################### 2 | # (c) Copyright IBM Corp. 2000, 2016 3 | # 4 | # This program and the accompanying materials are made available 5 | # under the terms of the Eclipse Public License v1.0 and 6 | # Apache License v2.0 which accompanies this distribution. 7 | # 8 | # The Eclipse Public License is available at 9 | # http://www.eclipse.org/legal/epl-v10.html 10 | # 11 | # The Apache License v2.0 is available at 12 | # http://www.opensource.org/licenses/apache2.0.php 13 | # 14 | # Contributors: 15 | # Multiple authors (IBM Corp.) - initial implementation and documentation 16 | ################################################################################## 17 | 18 | 19 | HOST_ARCH=x 20 | HOST_SUBARCH=amd64 21 | HOST_BITS=64 22 | OS=linux 23 | C_COMPILER=clang 24 | TOOLCHAIN=gnu 25 | 26 | -------------------------------------------------------------------------------- /ruby/build/platform/host/amd64-linux64-gcc.mk: -------------------------------------------------------------------------------- 1 | ################################################################################### 2 | # (c) Copyright IBM Corp. 2000, 2016 3 | # 4 | # This program and the accompanying materials are made available 5 | # under the terms of the Eclipse Public License v1.0 and 6 | # Apache License v2.0 which accompanies this distribution. 7 | # 8 | # The Eclipse Public License is available at 9 | # http://www.eclipse.org/legal/epl-v10.html 10 | # 11 | # The Apache License v2.0 is available at 12 | # http://www.opensource.org/licenses/apache2.0.php 13 | # 14 | # Contributors: 15 | # Multiple authors (IBM Corp.) - initial implementation and documentation 16 | ################################################################################## 17 | 18 | 19 | HOST_ARCH=x 20 | HOST_SUBARCH=amd64 21 | HOST_BITS=64 22 | OS=linux 23 | C_COMPILER=gcc 24 | TOOLCHAIN=gnu 25 | 26 | -------------------------------------------------------------------------------- /ruby/build/platform/host/amd64-osx-clang.mk: -------------------------------------------------------------------------------- 1 | HOST_ARCH=x 2 | HOST_SUBARCH=amd64 3 | HOST_BITS=64 4 | OS=osx 5 | C_COMPILER=clang 6 | TOOLCHAIN=gnu 7 | -------------------------------------------------------------------------------- /ruby/build/platform/host/ppc64-linux64-clang.mk: -------------------------------------------------------------------------------- 1 | ################################################################################### 2 | # (c) Copyright IBM Corp. 2000, 2016 3 | # 4 | # This program and the accompanying materials are made available 5 | # under the terms of the Eclipse Public License v1.0 and 6 | # Apache License v2.0 which accompanies this distribution. 7 | # 8 | # The Eclipse Public License is available at 9 | # http://www.eclipse.org/legal/epl-v10.html 10 | # 11 | # The Apache License v2.0 is available at 12 | # http://www.opensource.org/licenses/apache2.0.php 13 | # 14 | # Contributors: 15 | # Multiple authors (IBM Corp.) - initial implementation and documentation 16 | ################################################################################## 17 | 18 | 19 | HOST_ARCH=p 20 | HOST_SUBARCH= 21 | HOST_BITS=64 22 | OS=linux 23 | C_COMPILER=clang 24 | TOOLCHAIN=gnu 25 | -------------------------------------------------------------------------------- /ruby/build/platform/host/ppc64-linux64-gcc.mk: -------------------------------------------------------------------------------- 1 | ################################################################################### 2 | # (c) Copyright IBM Corp. 2000, 2016 3 | # 4 | # This program and the accompanying materials are made available 5 | # under the terms of the Eclipse Public License v1.0 and 6 | # Apache License v2.0 which accompanies this distribution. 7 | # 8 | # The Eclipse Public License is available at 9 | # http://www.eclipse.org/legal/epl-v10.html 10 | # 11 | # The Apache License v2.0 is available at 12 | # http://www.opensource.org/licenses/apache2.0.php 13 | # 14 | # Contributors: 15 | # Multiple authors (IBM Corp.) - initial implementation and documentation 16 | ################################################################################## 17 | 18 | 19 | HOST_ARCH=p 20 | HOST_SUBARCH= 21 | HOST_BITS=64 22 | OS=linux 23 | C_COMPILER=gcc 24 | TOOLCHAIN=gnu 25 | 26 | -------------------------------------------------------------------------------- /ruby/build/platform/host/ppc64le-linux64-clang.mk: -------------------------------------------------------------------------------- 1 | ################################################################################### 2 | # (c) Copyright IBM Corp. 2000, 2016 3 | # 4 | # This program and the accompanying materials are made available 5 | # under the terms of the Eclipse Public License v1.0 and 6 | # Apache License v2.0 which accompanies this distribution. 7 | # 8 | # The Eclipse Public License is available at 9 | # http://www.eclipse.org/legal/epl-v10.html 10 | # 11 | # The Apache License v2.0 is available at 12 | # http://www.opensource.org/licenses/apache2.0.php 13 | # 14 | # Contributors: 15 | # Multiple authors (IBM Corp.) - initial implementation and documentation 16 | ################################################################################## 17 | 18 | 19 | HOST_ARCH=p 20 | HOST_SUBARCH= 21 | HOST_BITS=64 22 | OS=linux 23 | C_COMPILER=clang 24 | TOOLCHAIN=gnu 25 | -------------------------------------------------------------------------------- /ruby/build/platform/host/ppc64le-linux64-gcc.mk: -------------------------------------------------------------------------------- 1 | ################################################################################### 2 | # (c) Copyright IBM Corp. 2000, 2016 3 | # 4 | # This program and the accompanying materials are made available 5 | # under the terms of the Eclipse Public License v1.0 and 6 | # Apache License v2.0 which accompanies this distribution. 7 | # 8 | # The Eclipse Public License is available at 9 | # http://www.eclipse.org/legal/epl-v10.html 10 | # 11 | # The Apache License v2.0 is available at 12 | # http://www.opensource.org/licenses/apache2.0.php 13 | # 14 | # Contributors: 15 | # Multiple authors (IBM Corp.) - initial implementation and documentation 16 | ################################################################################## 17 | 18 | 19 | HOST_ARCH=p 20 | HOST_SUBARCH= 21 | HOST_BITS=64 22 | OS=linux 23 | C_COMPILER=gcc 24 | TOOLCHAIN=gnu 25 | 26 | -------------------------------------------------------------------------------- /ruby/build/platform/host/s390-linux-clang.mk: -------------------------------------------------------------------------------- 1 | ################################################################################### 2 | # (c) Copyright IBM Corp. 2000, 2016 3 | # 4 | # This program and the accompanying materials are made available 5 | # under the terms of the Eclipse Public License v1.0 and 6 | # Apache License v2.0 which accompanies this distribution. 7 | # 8 | # The Eclipse Public License is available at 9 | # http://www.eclipse.org/legal/epl-v10.html 10 | # 11 | # The Apache License v2.0 is available at 12 | # http://www.opensource.org/licenses/apache2.0.php 13 | # 14 | # Contributors: 15 | # Multiple authors (IBM Corp.) - initial implementation and documentation 16 | ################################################################################## 17 | 18 | 19 | HOST_ARCH=z 20 | HOST_SUBARCH= 21 | HOST_BITS=32 22 | OS=linux 23 | C_COMPILER=clang 24 | TOOLCHAIN=gnu 25 | -------------------------------------------------------------------------------- /ruby/build/platform/host/s390-linux64-clang.mk: -------------------------------------------------------------------------------- 1 | ################################################################################### 2 | # (c) Copyright IBM Corp. 2000, 2016 3 | # 4 | # This program and the accompanying materials are made available 5 | # under the terms of the Eclipse Public License v1.0 and 6 | # Apache License v2.0 which accompanies this distribution. 7 | # 8 | # The Eclipse Public License is available at 9 | # http://www.eclipse.org/legal/epl-v10.html 10 | # 11 | # The Apache License v2.0 is available at 12 | # http://www.opensource.org/licenses/apache2.0.php 13 | # 14 | # Contributors: 15 | # Multiple authors (IBM Corp.) - initial implementation and documentation 16 | ################################################################################## 17 | 18 | 19 | HOST_ARCH=z 20 | HOST_SUBARCH= 21 | HOST_BITS=64 22 | OS=linux 23 | C_COMPILER=clang 24 | TOOLCHAIN=gnu 25 | -------------------------------------------------------------------------------- /ruby/build/platform/host/s390-linux64-gcc.mk: -------------------------------------------------------------------------------- 1 | ################################################################################### 2 | # (c) Copyright IBM Corp. 2000, 2016 3 | # 4 | # This program and the accompanying materials are made available 5 | # under the terms of the Eclipse Public License v1.0 and 6 | # Apache License v2.0 which accompanies this distribution. 7 | # 8 | # The Eclipse Public License is available at 9 | # http://www.eclipse.org/legal/epl-v10.html 10 | # 11 | # The Apache License v2.0 is available at 12 | # http://www.opensource.org/licenses/apache2.0.php 13 | # 14 | # Contributors: 15 | # Multiple authors (IBM Corp.) - initial implementation and documentation 16 | ################################################################################## 17 | 18 | 19 | HOST_ARCH=z 20 | HOST_SUBARCH= 21 | HOST_BITS=64 22 | OS=linux 23 | C_COMPILER=gcc 24 | TOOLCHAIN=gnu 25 | -------------------------------------------------------------------------------- /ruby/build/platform/target/all.mk: -------------------------------------------------------------------------------- 1 | ################################################################################### 2 | # (c) Copyright IBM Corp. 2000, 2016 3 | # 4 | # This program and the accompanying materials are made available 5 | # under the terms of the Eclipse Public License v1.0 and 6 | # Apache License v2.0 which accompanies this distribution. 7 | # 8 | # The Eclipse Public License is available at 9 | # http://www.eclipse.org/legal/epl-v10.html 10 | # 11 | # The Apache License v2.0 is available at 12 | # http://www.opensource.org/licenses/apache2.0.php 13 | # 14 | # Contributors: 15 | # Multiple authors (IBM Corp.) - initial implementation and documentation 16 | ################################################################################## 17 | 18 | 19 | # 20 | # If user didn't pass a target arch, assume same as host 21 | # 22 | ifeq (,$(TARGET_ARCH)) 23 | TARGET_ARCH=$(HOST_ARCH) 24 | TARGET_SUBARCH=$(HOST_SUBARCH) 25 | TARGET_BITS=$(HOST_BITS) 26 | endif 27 | -------------------------------------------------------------------------------- /ruby/build/rules/common.mk: -------------------------------------------------------------------------------- 1 | ################################################################################### 2 | # (c) Copyright IBM Corp. 2000, 2016 3 | # 4 | # This program and the accompanying materials are made available 5 | # under the terms of the Eclipse Public License v1.0 and 6 | # Apache License v2.0 which accompanies this distribution. 7 | # 8 | # The Eclipse Public License is available at 9 | # http://www.eclipse.org/legal/epl-v10.html 10 | # 11 | # The Apache License v2.0 is available at 12 | # http://www.opensource.org/licenses/apache2.0.php 13 | # 14 | # Contributors: 15 | # Multiple authors (IBM Corp.) - initial implementation and documentation 16 | ################################################################################## 17 | 18 | 19 | # Add our targets to the global targets 20 | all: jit 21 | clean: jit_cleanobjs jit_cleandeps jit_cleandll 22 | cleanobjs: jit_cleanobjs 23 | cleandeps: jit_cleandeps 24 | cleandll: jit_cleandll 25 | 26 | # 27 | # Define our targets. "jit_cleanobjs" "jit_cleandeps" and "jit_cleandll" 28 | # are double-colon so they can be appended to throughout the makefile. 29 | # 30 | .PHONY: jit jit_createdirs jit_cleanobjs jit_cleandeps jit_cleandll 31 | jit: 32 | jit_createdirs:: 33 | jit_cleanobjs:: 34 | jit_cleandeps:: 35 | jit_cleandll:: 36 | 37 | include $(JIT_MAKE_DIR)/rules/$(TOOLCHAIN)/common.mk 38 | -------------------------------------------------------------------------------- /ruby/build/rules/gnu/common.mk: -------------------------------------------------------------------------------- 1 | ################################################################################### 2 | # (c) Copyright IBM Corp. 2000, 2016 3 | # 4 | # This program and the accompanying materials are made available 5 | # under the terms of the Eclipse Public License v1.0 and 6 | # Apache License v2.0 which accompanies this distribution. 7 | # 8 | # The Eclipse Public License is available at 9 | # http://www.eclipse.org/legal/epl-v10.html 10 | # 11 | # The Apache License v2.0 is available at 12 | # http://www.opensource.org/licenses/apache2.0.php 13 | # 14 | # Contributors: 15 | # Multiple authors (IBM Corp.) - initial implementation and documentation 16 | ################################################################################## 17 | 18 | 19 | # 20 | # Defines rules for compiling source files into object files 21 | # 22 | # Each of these rules will also add themselves to jit_cleanobjs and jit_cleandeps 23 | # to clean build artifacts and dependecy files, respectively 24 | # 25 | include $(JIT_MAKE_DIR)/rules/gnu/filetypes.mk 26 | 27 | # Convert the source file names to object file names 28 | JIT_PRODUCT_OBJECTS=$(patsubst %,$(FIXED_OBJBASE)/%.o,$(basename $(JIT_PRODUCT_SOURCE_FILES))) 29 | 30 | # Figure out the name of the .so file 31 | JIT_PRODUCT_SONAME=$(PRODUCT_DIR)/lib$(PRODUCT_NAME).so 32 | 33 | # Add build name to JIT 34 | JIT_PRODUCT_BUILDNAME_SRC=$(FIXED_OBJBASE)/$(JIT_OMR_DIRTY_DIR)/env/TRBuildName.cpp 35 | JIT_PRODUCT_BUILDNAME_OBJ=$(FIXED_OBJBASE)/$(JIT_OMR_DIRTY_DIR)/env/TRBuildName.o 36 | JIT_PRODUCT_OBJECTS+=$(JIT_PRODUCT_BUILDNAME_OBJ) 37 | 38 | jit: $(JIT_PRODUCT_SONAME) 39 | 40 | $(JIT_PRODUCT_SONAME): $(JIT_PRODUCT_OBJECTS) | jit_createdirs 41 | $(SOLINK_CMD) $(SOLINK_FLAGS) -o $@ $(SOLINK_PRE_OBJECTS) $(JIT_PRODUCT_OBJECTS) $(SOLINK_POST_OBJECTS) $(patsubst %,-l%,$(SOLINK_SLINK)) $(SOLINK_EXTRA_ARGS) 42 | 43 | JIT_DIR_LIST+=$(dir $(JIT_PRODUCT_SONAME)) 44 | 45 | jit_cleandll:: 46 | rm -f $(JIT_PRODUCT_SONAME) 47 | 48 | $(call RULE.cpp,$(JIT_PRODUCT_BUILDNAME_OBJ),$(JIT_PRODUCT_BUILDNAME_SRC)) 49 | 50 | .PHONY: $(JIT_PRODUCT_BUILDNAME_SRC) 51 | $(JIT_PRODUCT_BUILDNAME_SRC): | jit_createdirs 52 | $(PERL_PATH) $(GENERATE_VERSION_SCRIPT) $(PRODUCT_RELEASE) > $@ 53 | 54 | JIT_DIR_LIST+=$(dir $(JIT_PRODUCT_BUILDNAME_SRC)) 55 | 56 | jit_cleanobjs:: 57 | rm -f $(JIT_PRODUCT_BUILDNAME_SRC) 58 | 59 | # 60 | # This part calls the "RULE.x" macros for each source file 61 | # 62 | $(foreach SRCFILE,$(JIT_PRODUCT_SOURCE_FILES),\ 63 | $(call RULE$(suffix $(SRCFILE)),$(FIXED_OBJBASE)/$(basename $(SRCFILE))$(OBJSUFF),$(FIXED_SRCBASE)/$(SRCFILE)) \ 64 | ) 65 | 66 | # 67 | # Generate a rule that will create every directory before the build starts 68 | # 69 | $(foreach JIT_DIR,$(sort $(JIT_DIR_LIST)),$(eval jit_createdirs:: ; mkdir -p $(JIT_DIR))) 70 | -------------------------------------------------------------------------------- /ruby/build/rules/gnu/filetypes.mk: -------------------------------------------------------------------------------- 1 | ################################################################################### 2 | # (c) Copyright IBM Corp. 2000, 2016 3 | # 4 | # This program and the accompanying materials are made available 5 | # under the terms of the Eclipse Public License v1.0 and 6 | # Apache License v2.0 which accompanies this distribution. 7 | # 8 | # The Eclipse Public License is available at 9 | # http://www.eclipse.org/legal/epl-v10.html 10 | # 11 | # The Apache License v2.0 is available at 12 | # http://www.opensource.org/licenses/apache2.0.php 13 | # 14 | # Contributors: 15 | # Multiple authors (IBM Corp.) - initial implementation and documentation 16 | ################################################################################## 17 | 18 | 19 | # 20 | # These are the rules to compile files of type ".x" into object files 21 | # as well as to generate clean and cleandeps rules 22 | # 23 | # I apologize that this is horribly ugly. Don't get too mad or attached to it 24 | # because I already have several ideas of how to do this in a more readable way 25 | # 26 | # In the meantime though, it works and is very reliable and flexible... 27 | # ...just ugly 28 | # 29 | 30 | # 31 | # Compile .c file into .o file 32 | # 33 | define DEF_RULE.c 34 | 35 | $(1): $(2) $(1)$(DEPSUFF) | jit_createdirs 36 | $$(C_CMD) $$(C_FLAGS) $$(patsubst %,-D%,$$(C_DEFINES)) $$(patsubst %,-I'%',$$(C_INCLUDES)) -MMD -MF $$@$$(DEPSUFF) -MT $$@ -MP -o $$@ -c $$< 37 | 38 | $(1)$(DEPSUFF): ; 39 | 40 | -include $(1)$(DEPSUFF) 41 | 42 | JIT_DIR_LIST+=$(dir $(1)) 43 | 44 | jit_cleanobjs:: 45 | rm -f $(1) 46 | 47 | jit_cleandeps:: 48 | rm -f $(1)$(DEPSUFF) 49 | 50 | endef # DEF_RULE.c 51 | 52 | RULE.c=$(eval $(DEF_RULE.c)) 53 | 54 | # 55 | # Compile .cpp file into .o file 56 | # 57 | define DEF_RULE.cpp 58 | $(1): $(2) $(1)$(DEPSUFF) | jit_createdirs 59 | $$(CXX_CMD) $$(CXX_FLAGS) $$(patsubst %,-D%,$$(CXX_DEFINES)) $$(patsubst %,-I'%',$$(CXX_INCLUDES)) -MMD -MF $$@$$(DEPSUFF) -MT $$@ -MP -o $$@ -c $$< 60 | 61 | $(1)$(DEPSUFF): ; 62 | 63 | -include $(1)$(DEPSUFF) 64 | 65 | JIT_DIR_LIST+=$(dir $(1)) 66 | 67 | jit_cleanobjs:: 68 | rm -f $(1) 69 | 70 | jit_cleandeps:: 71 | rm -f $(1)$(DEPSUFF) 72 | 73 | endef # DEF_RULE.cpp 74 | 75 | RULE.cpp=$(eval $(DEF_RULE.cpp)) 76 | 77 | # 78 | # Compile .s file into .o file 79 | # 80 | ifeq ($(LLVM_ASSEMBLER),1) 81 | 82 | define DEF_RULE.s 83 | $(1): $(2) | jit_createdirs 84 | $$(S_CMD) $$(S_FLAGS) $$(patsubst %,-D%=1,$$(S_DEFINES)) $$(patsubst %,-I'%',$$(S_INCLUDES)) -o $$@ $$< 85 | 86 | JIT_DIR_LIST+=$(dir $(1)) 87 | 88 | jit_cleanobjs:: 89 | rm -f $(1) 90 | 91 | endef # DEF_RULE.s 92 | 93 | else 94 | 95 | define DEF_RULE.s 96 | $(1): $(2) | jit_createdirs 97 | $$(S_CMD) $$(S_FLAGS) $$(patsubst %,--defsym %=1,$$(S_DEFINES)) $$(patsubst %,-I'%',$$(S_INCLUDES)) -o $$@ $$< 98 | 99 | JIT_DIR_LIST+=$(dir $(1)) 100 | 101 | jit_cleanobjs:: 102 | rm -f $(1) 103 | 104 | endef # DEF_RULE.s 105 | 106 | endif 107 | 108 | RULE.s=$(eval $(DEF_RULE.s)) 109 | 110 | ##### START X SPECIFIC RULES ##### 111 | ifeq ($(HOST_ARCH),x) 112 | 113 | # TODO - Fix MASM2GAS to have a little more sane output file behavior 114 | # 115 | # Compile .asm file into .o file 116 | # (By changing it to a .s file and then assembling it) 117 | # 118 | define DEF_RULE.asm 119 | $(1).s: $(2) | jit_createdirs 120 | $$(PERL_PATH) $$(ASM_SCRIPT) $$(ASM_FLAGS) $$(patsubst %,-I'%',$$(ASM_INCLUDES)) -o$$(dir $$@) $$< 121 | mv $$(dir $$@)$$(notdir $$(basename $$<).s) $$@ 122 | 123 | JIT_DIR_LIST+=$(dir $(1)) 124 | 125 | jit_cleanobjs:: 126 | rm -f $(1).s 127 | 128 | $(call RULE.s,$(1),$(1).s) 129 | endef # DEF_RULE.asm 130 | 131 | RULE.asm=$(eval $(DEF_RULE.asm)) 132 | 133 | # 134 | # Compile .pasm file into .o file 135 | # 136 | define DEF_RULE.pasm 137 | $(1).asm: $(2) | jit_createdirs 138 | $$(PASM_CMD) $$(PASM_FLAGS) $$(patsubst %,-I'%',$$(PASM_INCLUDES)) -o $$@ -E -P $$< 139 | 140 | JIT_DIR_LIST+=$(dir $(1)) 141 | 142 | jit_cleanobjs:: 143 | rm -f $(1).asm 144 | 145 | $(call RULE.asm,$(1),$(1).asm) 146 | endef # DEF_RULE.pasm 147 | 148 | RULE.pasm=$(eval $(DEF_RULE.pasm)) 149 | 150 | endif # ($(HOST_ARCH),x) 151 | ##### END X SPECIFIC RULES ##### 152 | 153 | ##### START PPC SPECIFIC RULES ##### 154 | ifeq ($(HOST_ARCH),p) 155 | 156 | # 157 | # Compile .ipp file into .o file 158 | # 159 | define DEF_RULE.ipp 160 | $(1).s: $(2) | jit_createdirs 161 | $$(IPP_CMD) $$(IPP_FLAGS) 's/\!/\#/g' $$< > $$@ 162 | 163 | JIT_DIR_LIST+=$(dir $(1)) 164 | 165 | jit_cleanobjs:: 166 | rm -f $(1).s 167 | 168 | $(call RULE.s,$(1),$(1).s) 169 | endef # DEF_RULE.ipp 170 | 171 | RULE.ipp=$(eval $(DEF_RULE.ipp)) 172 | 173 | # 174 | # Compile .spp file into .o file 175 | # 176 | define DEF_RULE.spp 177 | $(1).ipp: $(2) | jit_createdirs 178 | $$(SPP_CMD) $$(SPP_FLAGS) $$(patsubst %,-D%,$$(SPP_DEFINES)) $$(patsubst %,-I'%',$$(SPP_INCLUDES)) -o $$@ -x assembler-with-cpp -E -P $$< 179 | 180 | JIT_DIR_LIST+=$(dir $(1)) 181 | 182 | jit_cleanobjs:: 183 | rm -f $(1).ipp 184 | 185 | $(call RULE.ipp,$(1),$(1).ipp) 186 | endef # DEF_RULE.spp 187 | 188 | RULE.spp=$(eval $(DEF_RULE.spp)) 189 | 190 | endif # ($(HOST_ARCH),p) 191 | ##### END PPC SPECIFIC RULES ##### 192 | 193 | ##### START Z SPECIFIC RULES ##### 194 | ifeq ($(HOST_ARCH),z) 195 | 196 | # 197 | # Compile .m4 file into .o file 198 | # 199 | define DEF_RULE.m4 200 | $(1).s: $(2) | jit_createdirs 201 | $$(PERL_PATH) $$(JIT_SCRIPT_DIR)/s390m4check.pl $$< 202 | $$(M4_CMD) $$(M4_FLAGS) $$(patsubst %,-I'%',$$(M4_INCLUDES)) $$(patsubst %,-D%,$$(M4_DEFINES)) $$< > $$@ 203 | $$(PERL_PATH) $$(JIT_SCRIPT_DIR)/s390m4check.pl $$@ 204 | 205 | JIT_DIR_LIST+=$(dir $(1)) 206 | 207 | jit_cleanobjs:: 208 | rm -f $(1).s 209 | 210 | $(call RULE.s,$(1),$(1).s) 211 | endef # DEF_RULE.m4 212 | 213 | RULE.m4=$(eval $(DEF_RULE.m4)) 214 | 215 | endif # ($(HOST_ARCH),z) 216 | ##### END Z SPECIFIC RULES ##### 217 | 218 | -------------------------------------------------------------------------------- /ruby/build/scripts/armasm2gas.sed: -------------------------------------------------------------------------------- 1 | #!/bin/sed 2 | 3 | # (c) Copyright IBM Corp. 2000, 2016 4 | # 5 | # This program and the accompanying materials are made available 6 | # under the terms of the Eclipse Public License v1.0 and 7 | # Apache License v2.0 which accompanies this distribution. 8 | # 9 | # The Eclipse Public License is available at 10 | # http://www.eclipse.org/legal/epl-v10.html 11 | # 12 | # The Apache License v2.0 is available at 13 | # http://www.opensource.org/licenses/apache2.0.php 14 | # 15 | # Contributors: 16 | # Multiple authors (IBM Corp.) - initial implementation and documentation 17 | 18 | # Do comments first since they can appear anywhere 19 | s/;/@/g 20 | 21 | # Fix up directives 22 | s/^[[:space:]]*DCD[[:space:]]\+\(.*\)$/.long \1/g 23 | s/^[[:space:]]*DCW[[:space:]]\+\(.*\)$/.short \1/g 24 | s/^[[:space:]]*DCB[[:space:]]\+\(.*\)$/.byte \1/g 25 | s/^[[:space:]]*\([[:alnum:]_]\+\)[[:space:]]\+[Ee][Qq][Uu][[:space:]]\+\(.*\)$/ \1 = \2/g 26 | s/^[[:space:]]*AREA.*CODE.*$/.text/g 27 | s/^[[:space:]]*AREA.*DATA.*$/.data/g 28 | s/^[[:space:]]*IMPORT[[:space:]]\+\(.*\)$/.globl \1/g 29 | s/^[[:space:]]*EXPORT[[:space:]]\+\(.*\)$/.globl \1/g 30 | s/^[[:space:]]*ALIGN[[:space:]]\+\(.*\)$/.balign \1/g 31 | s/^[[:space:]]*include[[:space:]]\+\(.*$\)/.include "\1"/g 32 | s/^[[:space:]]*END[[:space:]]*$//g 33 | 34 | # Ok, now look for labels 35 | s/^\([[:alpha:]_][[:alnum:]_]*\)\(.*\)/\1:\2/g 36 | 37 | # Fix up non-local branches to append "(PLT)" 38 | s/^\([[:space:]]\+[Bb][Ll]\{0,1\}\(eq\|ne\|cs\|cc\|mi\|pl\|vs\|vc\|hi\|ls\|lt\|gt\|le\|ge\|al\)\{0,1\}[[:space:]]\+\)\([[:alpha:]_][[:alnum:]_]*\)\(.*\)$/\1\3(PLT)\4/g 39 | s/^\([[:space:]]\+[Bb][Ll]\{0,1\}\(eq\|ne\|cs\|cc\|mi\|pl\|vs\|vc\|hi\|ls\|lt\|gt\|le\|ge\|al\)\{0,1\}[[:space:]]\+\)\(L_[[:alnum:]_]*\)(PLT)\(.*\)$/\1\3\4/g 40 | 41 | -------------------------------------------------------------------------------- /ruby/build/scripts/generateVersion.pl: -------------------------------------------------------------------------------- 1 | #!/bin/perl 2 | 3 | # (c) Copyright IBM Corp. 2000, 2016 4 | # 5 | # This program and the accompanying materials are made available 6 | # under the terms of the Eclipse Public License v1.0 and 7 | # Apache License v2.0 which accompanies this distribution. 8 | # 9 | # The Eclipse Public License is available at 10 | # http://www.eclipse.org/legal/epl-v10.html 11 | # 12 | # The Apache License v2.0 is available at 13 | # http://www.opensource.org/licenses/apache2.0.php 14 | # 15 | # Contributors: 16 | # Multiple authors (IBM Corp.) - initial implementation and documentation 17 | 18 | use strict; 19 | 20 | # FIXME: incorporate the variant name into the build too (prod vs debug) 21 | 22 | die("\nUsage:\n $0 rel_name\n") unless (@ARGV eq 1); 23 | 24 | my $rel = $ARGV[0]; 25 | 26 | my $snapshot_name; 27 | if (defined $ENV{"TR_BUILD_NAME"}) { 28 | $snapshot_name = $ENV{"TR_BUILD_NAME"}; 29 | } else { 30 | use POSIX; 31 | 32 | # Optionally, check if the user has defined $USER_TR_VERSION, and incorporate 33 | # too. 34 | my $time = POSIX::strftime("\%Y\%m\%d_\%H\%M", localtime($^T)); 35 | $snapshot_name = $rel . "_" . $time . "_" . $ENV{LOGNAME}; 36 | } 37 | 38 | print "#include \"control/OMROptions.hpp\"\n\nconst char TR_BUILD_NAME[] = \"$snapshot_name\";\n\n"; 39 | -------------------------------------------------------------------------------- /ruby/build/scripts/guess-platform.sh: -------------------------------------------------------------------------------- 1 | ################################################################################### 2 | # (c) Copyright IBM Corp. 2000, 2016 3 | # 4 | # This program and the accompanying materials are made available 5 | # under the terms of the Eclipse Public License v1.0 and 6 | # Apache License v2.0 which accompanies this distribution. 7 | # 8 | # The Eclipse Public License is available at 9 | # http://www.eclipse.org/legal/epl-v10.html 10 | # 11 | # The Apache License v2.0 is available at 12 | # http://www.opensource.org/licenses/apache2.0.php 13 | # 14 | # Contributors: 15 | # Multiple authors (IBM Corp.) - initial implementation and documentation 16 | ################################################################################## 17 | 18 | 19 | thirty_two_bit=0 20 | 21 | usage() { 22 | echo "usage: guess-platform.sh [--32|--64]" >&2 23 | echo "Outputs the value that can be assigned to the PLATFORM variable in" >&2 24 | echo "the jit makefiles. If neither --32 or --64 is provided, --64 is " >&2 25 | echo "assumed." >&2 26 | exit 1 27 | } 28 | 29 | error() { 30 | echo "$0: $1" >&2 31 | exit 1 32 | } 33 | 34 | # chooseplatform 32bit_platform 64bit_platform 35 | chooseplatform() { 36 | if [[ $thirty_two_bit -eq 1 ]] ; then 37 | platform=$1 38 | else 39 | platform=$2 40 | fi 41 | } 42 | 43 | if [ $# -eq 0 ]; then 44 | arg="--64" 45 | elif [ $# -eq 1 ]; then 46 | arg=$1 47 | else 48 | usage 49 | fi 50 | 51 | case $arg in 52 | --32) 53 | thirty_two_bit=1 54 | ;; 55 | --64) 56 | thirty_two_bit=0 57 | ;; 58 | *) 59 | usage 60 | ;; 61 | esac 62 | 63 | system=$(uname -s) 64 | case $system in 65 | AIX) 66 | chooseplatform "ppc-aix-vacpp" "ppc64-aix-vacpp" 67 | ;; 68 | OS/390) 69 | chooseplatform "s390-zos-vacpp" "s390-zos64-vacpp" 70 | ;; 71 | CYGWIN*) 72 | chooseplatform "ia32-win32-mvs" "amd64-win64-mvs" 73 | ;; 74 | Darwin) 75 | platform="amd64-osx-clang" 76 | ;; 77 | Linux) 78 | p=$(uname -m) 79 | case $p in 80 | i[456]86) 81 | platform="ia32-linux-gcc" 82 | ;; 83 | x86_64) 84 | chooseplatform "amd64-linux-gcc" "amd64-linux64-gcc" 85 | ;; 86 | ppc64) 87 | chooseplatform "ppc-linux-gcc" "ppc64-linux64-gcc" 88 | ;; 89 | ppc64le) 90 | platform="ppc64le-linux64-gcc" 91 | ;; 92 | s390x) 93 | chooseplatform "s390-linux-gcc" "s390-linux64-gcc" 94 | ;; 95 | *) 96 | error "$0: uname -m returns unknown result \"$p\"" 97 | ;; 98 | esac 99 | ;; 100 | *) 101 | error "$0: uname -s returns unknown result \"$system\"" 102 | ;; 103 | esac 104 | 105 | echo $platform 106 | -------------------------------------------------------------------------------- /ruby/build/scripts/s390m4check.pl: -------------------------------------------------------------------------------- 1 | #!/bin/perl 2 | # 3 | # (c) Copyright IBM Corp. 2000, 2016 4 | # 5 | # This program and the accompanying materials are made available 6 | # under the terms of the Eclipse Public License v1.0 and 7 | # Apache License v2.0 which accompanies this distribution. 8 | # 9 | # The Eclipse Public License is available at 10 | # http://www.eclipse.org/legal/epl-v10.html 11 | # 12 | # The Apache License v2.0 is available at 13 | # http://www.opensource.org/licenses/apache2.0.php 14 | # 15 | # Contributors: 16 | # Multiple authors (IBM Corp.) - initial implementation and documentation 17 | 18 | use warnings; 19 | use strict; 20 | use bytes; # avoid using Unicode internally 21 | 22 | die "usage: $0 filename\n" unless @ARGV == 1; 23 | my $inputFile = pop @ARGV; 24 | open FILE, $inputFile or die "unable to open file $inputFile"; 25 | 26 | my $MAX_LENGTH = 71; 27 | my $is_m4 = ( $inputFile =~ m/\.m4$/ ); 28 | my $is_ascii = 1 if ord('[') == 91; 29 | 30 | while () 31 | { 32 | chomp; 33 | my $line = $_; 34 | my $length = length($line); 35 | die "line longer than $MAX_LENGTH characters ($length)" 36 | if ( $length > $MAX_LENGTH ); 37 | 38 | # check that only valid characters show up in the string 39 | # %goodchars is a hash of characters allowed 40 | my %goodchars = $is_ascii ? 41 | map { $_ => 1 } ( 10, 13, 31 .. 127 ) : # ascii 42 | map { $_ => 1 } ( 13, 21, 64 .. 249 ); # ebcdic 43 | my $newline = $line; 44 | $newline =~ s/(.)/$goodchars{ord($1)} ? $1 : ' '/eg; 45 | die "invalid character(s)" 46 | if $newline ne $line; 47 | 48 | my $comment_regex = 49 | $is_m4 ? "ZZ" # M4 50 | : $is_ascii ? "#" # GAS 51 | : "\\*\\*"; # HLASM 52 | 53 | # skip comment lines 54 | next if $line =~ m/^$comment_regex/; 55 | die "comment lines should not have preceding whitespace" 56 | if $line =~ m/^\s+$comment_regex/; 57 | 58 | # strip the comments out 59 | $line =~ s/$comment_regex.*$//; 60 | 61 | # the # character is considered a comment everywhere 62 | $line =~ s/\#.*$//; 63 | 64 | die "comma in first column" if $line =~ m/^,/; 65 | die "whitespace next to comma" if $line =~ m/\s,|,\s/; 66 | die "whitespace within parentheses" 67 | if $line =~ m/\(.*\s.*\)/; 68 | die "whitespace before parentheses" 69 | if $line =~ m/,\s+\(/; 70 | } 71 | -------------------------------------------------------------------------------- /ruby/build/toolcfg/common.mk: -------------------------------------------------------------------------------- 1 | ################################################################################### 2 | # (c) Copyright IBM Corp. 2000, 2016 3 | # 4 | # This program and the accompanying materials are made available 5 | # under the terms of the Eclipse Public License v1.0 and 6 | # Apache License v2.0 which accompanies this distribution. 7 | # 8 | # The Eclipse Public License is available at 9 | # http://www.eclipse.org/legal/epl-v10.html 10 | # 11 | # The Apache License v2.0 is available at 12 | # http://www.opensource.org/licenses/apache2.0.php 13 | # 14 | # Contributors: 15 | # Multiple authors (IBM Corp.) - initial implementation and documentation 16 | ################################################################################## 17 | 18 | 19 | # 20 | # If build didn't pass in the RUBY_IPATH, we will synthesize it 21 | # 22 | ifeq (,$(RUBY_IPATH)) 23 | $(warning RUBY_IPATH not set, so we're taking a guess) 24 | 25 | # This gives us OMR_INCLUDES_FOR_JIT 26 | OMR_COMPONENT_INSTALL?=$(OMR_RUBY_INSTALL)/omr 27 | OMR_DIR:=$(OMR_COMPONENT_INSTALL) 28 | include $(OMR_DIR)/omrmakefiles/jitinclude.mk 29 | 30 | # TODO - There MUST be a nicer way to do this 31 | ifeq ($(SPEC),linux_ppc-64) 32 | OMR_EXT_INCLUDE=$(OMR_RUBY_INSTALL)/.ext/include/powerpc64-linux 33 | endif 34 | ifeq ($(SPEC),linux_x86-64) 35 | OMR_EXT_INCLUDE=$(OMR_RUBY_INSTALL)/.ext/include/x86_64-linux 36 | endif 37 | ifeq ($(SPEC),linux_ppcle-64) 38 | OMR_EXT_INCLUDE=$(OMR_RUBY_INSTALL)/.ext/include/powerpc64le-linux 39 | endif 40 | ifeq ($(SPEC),linux_390-64) 41 | OMR_EXT_INCLUDE=$(OMR_RUBY_INSTALL)/.ext/include/s390x-linux 42 | endif 43 | 44 | RUBY_INCLUDES=\ 45 | $(OMR_RUBY_INSTALL)/include \ 46 | $(OMR_EXT_INCLUDE) \ 47 | $(OMR_INCLUDES_FOR_JIT) \ 48 | $(OMR_RUBY_INSTALL)/omrglue \ 49 | $(OMR_RUBY_INSTALL) 50 | 51 | else 52 | RUBY_INCLUDES=$(RUBY_IPATH) 53 | endif 54 | 55 | PRODUCT_INCLUDES=\ 56 | $(FIXED_SRCBASE)/$(JIT_PRODUCT_DIR)/$(TARGET_ARCH)/$(TARGET_SUBARCH) \ 57 | $(FIXED_SRCBASE)/$(JIT_PRODUCT_DIR)/$(TARGET_ARCH) \ 58 | $(FIXED_SRCBASE)/$(JIT_PRODUCT_DIR) \ 59 | $(FIXED_SRCBASE)/$(RBJITGLUE_DIR) \ 60 | $(RUBY_INCLUDES) \ 61 | $(FIXED_SRCBASE)/$(JIT_OMR_DIRTY_DIR)/$(TARGET_ARCH)/$(TARGET_SUBARCH) \ 62 | $(FIXED_SRCBASE)/$(JIT_OMR_DIRTY_DIR)/$(TARGET_ARCH) \ 63 | $(FIXED_SRCBASE)/$(JIT_OMR_DIRTY_DIR) \ 64 | $(FIXED_SRCBASE)/$(RELATIVE_OMR_DIR) \ 65 | $(FIXED_SRCBASE) 66 | 67 | 68 | PRODUCT_DEFINES+=OMR_RUBY RUBY_PROJECT_SPECIFIC 69 | 70 | # TODO - Better way to get release name than hard-coding it here 71 | PRODUCT_RELEASE?=tr.open.ruby 72 | 73 | PRODUCT_DIR=$(FIXED_DLL_DIR) 74 | PRODUCT_NAME?=rbjit 75 | 76 | # 77 | # Now we include the host and target tool config 78 | # These don't really do much generally... They set a few defines but there really 79 | # isn't a lot of stuff that's host/target dependent that isn't also dependent 80 | # on what tools you're using 81 | # 82 | include $(JIT_MAKE_DIR)/toolcfg/host/$(HOST_ARCH).mk 83 | include $(JIT_MAKE_DIR)/toolcfg/host/$(HOST_BITS).mk 84 | include $(JIT_MAKE_DIR)/toolcfg/host/$(OS).mk 85 | include $(JIT_MAKE_DIR)/toolcfg/target/$(TARGET_ARCH).mk 86 | include $(JIT_MAKE_DIR)/toolcfg/target/$(TARGET_BITS).mk 87 | 88 | # 89 | # Now this is the big tool config file. This is where all the includes and defines 90 | # get turned into flags, and where all the flags get setup for the different 91 | # tools and file types 92 | # 93 | include $(JIT_MAKE_DIR)/toolcfg/$(TOOLCHAIN)/common.mk 94 | 95 | -------------------------------------------------------------------------------- /ruby/build/toolcfg/gnu/common.mk: -------------------------------------------------------------------------------- 1 | ################################################################################### 2 | # (c) Copyright IBM Corp. 2000, 2016 3 | # 4 | # This program and the accompanying materials are made available 5 | # under the terms of the Eclipse Public License v1.0 and 6 | # Apache License v2.0 which accompanies this distribution. 7 | # 8 | # The Eclipse Public License is available at 9 | # http://www.eclipse.org/legal/epl-v10.html 10 | # 11 | # The Apache License v2.0 is available at 12 | # http://www.opensource.org/licenses/apache2.0.php 13 | # 14 | # Contributors: 15 | # Multiple authors (IBM Corp.) - initial implementation and documentation 16 | ################################################################################## 17 | 18 | 19 | # 20 | # Explicitly set shell 21 | # 22 | SHELL=/bin/sh 23 | 24 | # 25 | # These are the prefixes and suffixes that all GNU tools use for things 26 | # 27 | OBJSUFF=.o 28 | ARSUFF=.a 29 | SOSUFF=.so 30 | EXESUFF= 31 | LIBPREFIX=lib 32 | DEPSUFF=.depend.mk 33 | 34 | # 35 | # Paths for default programs on the platform 36 | # Most rules will use these default programs, but they can be overwritten individually if, 37 | # for example, you want to compile .spp files with a different C++ compiler than you use 38 | # to compile .spp files 39 | # 40 | AR_PATH?=ar 41 | SED_PATH?=sed 42 | M4_PATH?=m4 43 | PERL_PATH?=perl 44 | 45 | ifeq ($(OS),osx) 46 | AS_PATH?=clang 47 | else 48 | AS_PATH?=as 49 | endif 50 | 51 | # TODO - Redo GCC version logic that used to be here 52 | ifeq ($(C_COMPILER),gcc) 53 | CC_PATH?=gcc 54 | CXX_PATH?=g++ 55 | endif 56 | 57 | ifeq ($(C_COMPILER),clang) 58 | CC_PATH?=clang 59 | CXX_PATH?=clang++ 60 | endif 61 | 62 | AS_VERSION:=$(shell $(AS_PATH) --version) 63 | ifneq (,$(findstring LLVM,$(AS_VERSION))) 64 | LLVM_ASSEMBLER:=1 65 | endif 66 | 67 | # This is the script that's used to generate TRBuildName.cpp 68 | GENERATE_VERSION_SCRIPT?=$(JIT_SCRIPT_DIR)/generateVersion.pl 69 | 70 | # 71 | # First setup C and C++ compilers. 72 | # 73 | # Note: "CX" means both C and C++ 74 | # 75 | C_CMD?=$(CC_PATH) 76 | CXX_CMD?=$(CXX_PATH) 77 | 78 | CX_DEFINES+=\ 79 | $(PRODUCT_DEFINES) \ 80 | $(HOST_DEFINES) \ 81 | $(TARGET_DEFINES) \ 82 | SUPPORTS_THREAD_LOCAL \ 83 | _LONG_LONG 84 | 85 | CX_FLAGS+=\ 86 | -pthread \ 87 | -fomit-frame-pointer \ 88 | -fasynchronous-unwind-tables \ 89 | -fno-dollars-in-identifiers \ 90 | -fPIC \ 91 | -fno-strict-aliasing \ 92 | -Wreturn-type \ 93 | -g 94 | 95 | CXX_FLAGS+=\ 96 | -std=c++0x \ 97 | -fno-rtti \ 98 | -fno-threadsafe-statics \ 99 | -fno-strict-aliasing \ 100 | -Wno-deprecated \ 101 | -Wno-enum-compare \ 102 | -Wno-invalid-offsetof \ 103 | -Wno-write-strings 104 | 105 | ifeq ($(C_COMPILER),clang) 106 | SOLINK_FLAGS+=-undefined dynamic_lookup 107 | endif 108 | 109 | CX_DEFINES_DEBUG+=DEBUG 110 | CX_FLAGS_DEBUG+=-g -ggdb3 111 | 112 | CX_DEFAULTOPT=-O3 113 | CX_OPTFLAG?=$(CX_DEFAULTOPT) 114 | CX_FLAGS_PROD+=$(CX_OPTFLAG) 115 | 116 | ifeq ($(HOST_ARCH),x) 117 | # Nothing for X 118 | endif 119 | 120 | ifeq ($(HOST_ARCH),p) 121 | CX_DEFINES+=LINUXPPC LINUXPPC64 USING_ANSI 122 | CX_FLAGS_PROD+=-mcpu=powerpc64 123 | 124 | ifdef ENABLE_SIMD_LIB 125 | CX_DEFINES+=ENABLE_SPMD_SIMD 126 | CX_FLAGS+=-qaltivec -qarch=pwr7 -qtune=pwr7 127 | endif 128 | endif 129 | 130 | ifeq ($(HOST_ARCH),z) 131 | CX_DEFINES+=S390 S39064 FULL_ANSI MAXMOVE 132 | CX_FLAGS+=-march=z900 -mtune=z9-109 -mzarch 133 | endif 134 | 135 | ifeq ($(HOST_BITS),64) 136 | CX_FLAGS+=-m64 137 | endif 138 | 139 | ifeq ($(C_COMPILER),clang) 140 | CX_FLAGS+=-Wno-parentheses -Werror=header-guard 141 | endif 142 | 143 | ifeq ($(BUILD_CONFIG),debug) 144 | CX_DEFINES+=$(CX_DEFINES_DEBUG) 145 | CX_FLAGS+=$(CX_FLAGS_DEBUG) 146 | endif 147 | 148 | ifeq ($(BUILD_CONFIG),prod) 149 | CX_DEFINES+=$(CX_DEFINES_PROD) 150 | CX_FLAGS+=$(CX_FLAGS_PROD) 151 | endif 152 | 153 | C_INCLUDES=$(PRODUCT_INCLUDES) 154 | C_DEFINES+=$(CX_DEFINES) $(CX_DEFINES_EXTRA) $(C_DEFINES_EXTRA) 155 | C_FLAGS+=$(CX_FLAGS) $(CX_FLAGS_EXTRA) $(C_FLAGS_EXTRA) 156 | 157 | CXX_INCLUDES=$(PRODUCT_INCLUDES) 158 | CXX_DEFINES+=$(CX_DEFINES) $(CX_DEFINES_EXTRA) $(CXX_DEFINES_EXTRA) 159 | CXX_FLAGS+=$(CX_FLAGS) $(CX_FLAGS_EXTRA) $(CXX_FLAGS_EXTRA) 160 | 161 | # 162 | # We now setup the GNU Assembler (GAS) 163 | # 164 | S_CMD?=$(AS_PATH) 165 | 166 | S_INCLUDES=$(PRODUCT_INCLUDES) 167 | 168 | S_DEFINES+=$(HOST_DEFINES) $(TARGET_DEFINES) 169 | 170 | ifeq ($(LLVM_ASSEMBLER),1) 171 | S_FLAGS+=-Wa,--noexecstack 172 | else 173 | S_FLAGS+=--noexecstack 174 | S_FLAGS_DEBUG+=--gstabs 175 | endif 176 | 177 | S_DEFINES_DEBUG+=DEBUG 178 | 179 | ifeq ($(HOST_ARCH),x) 180 | ifeq ($(LLVM_ASSEMBLER),1) 181 | S_FLAGS+=-march=x86-64 -c 182 | else 183 | S_FLAGS+=--64 184 | endif 185 | endif 186 | 187 | ifeq ($(HOST_ARCH),z) 188 | S_FLAGS+=-march=z990 -mzarch 189 | endif 190 | 191 | ifeq ($(BUILD_CONFIG),debug) 192 | S_DEFINES+=$(S_DEFINES_DEBUG) 193 | S_FLAGS+=$(S_FLAGS_DEBUG) 194 | endif 195 | 196 | ifeq ($(BUILD_CONFIG),prod) 197 | S_DEFINES+=$(S_DEFINES_PROD) 198 | S_FLAGS+=$(S_FLAGS_PROD) 199 | endif 200 | 201 | S_DEFINES+=$(S_DEFINES_EXTRA) 202 | S_FLAGS+=$(S_FLAGS_EXTRA) 203 | 204 | # 205 | # Now setup ASM and Preprocessed ASM (PASM) on x86 206 | # 207 | # Because GNU Assembler doesn't understand MASM syntax, we use MASM2GAS 208 | # to translate it 209 | # 210 | ifeq ($(HOST_ARCH),x) 211 | ASM_SCRIPT?=$(JIT_SCRIPT_DIR)/masm2gas.pl 212 | 213 | ASM_INCLUDES=$(PRODUCT_INCLUDES) 214 | 215 | ASM_FLAGS+=--64 216 | 217 | ifeq ($(BUILD_CONFIG),debug) 218 | ASM_FLAGS+=$(ASM_FLAGS_DEBUG) 219 | endif 220 | 221 | ifeq ($(BUILD_CONFIG),prod) 222 | ASM_FLAGS+=$(ASM_FLAGS_PROD) 223 | endif 224 | 225 | ASM_FLAGS+=$(ASM_FLAGS_EXTRA) 226 | 227 | PASM_CMD?=$(CC_PATH) 228 | 229 | PASM_INCLUDES=$(PRODUCT_INCLUDES) 230 | 231 | ifeq ($(BUILD_CONFIG),debug) 232 | PASM_FLAGS+=$(PASM_FLAGS_DEBUG) 233 | endif 234 | 235 | ifeq ($(BUILD_CONFIG),prod) 236 | PASM_FLAGS+=$(PASM_FLAGS_PROD) 237 | endif 238 | 239 | PASM_FLAGS+=$(PASM_FLAGS_EXTRA) 240 | endif 241 | 242 | # 243 | # PowerPC has these .spp files that are preprocessed PPC assembly 244 | # However, after being preprocessed with CPP, they contain comments that start 245 | # with a bang '!' that need to be converted to start with a pound '#' so they can 246 | # be understood by GAS 247 | # 248 | ifeq ($(HOST_ARCH),p) 249 | IPP_CMD?=$(SED_PATH) 250 | 251 | ifeq ($(BUILD_CONFIG),debug) 252 | IPP_FLAGS+=$(IPP_FLAGS_DEBUG) 253 | endif 254 | 255 | ifeq ($(BUILD_CONFIG),prod) 256 | IPP_FLAGS+=$(IPP_FLAGS_PROD) 257 | endif 258 | 259 | IPP_FLAGS+=$(IPP_FLAGS_EXTRA) 260 | 261 | SPP_CMD?=$(CC_PATH) 262 | 263 | SPP_INCLUDES=$(PRODUCT_INCLUDES) 264 | SPP_DEFINES+=$(CX_DEFINES) 265 | SPP_FLAGS+=$(CX_FLAGS) 266 | 267 | ifeq ($(BUILD_CONFIG),debug) 268 | SPP_DEFINES+=$(SPP_DEFINES_DEBUG) 269 | SPP_FLAGS+=$(SPP_FLAGS_DEBUG) 270 | endif 271 | 272 | ifeq ($(BUILD_CONFIG),prod) 273 | SPP_DEFINES+=$(SPP_DEFINES_PROD) 274 | SPP_FLAGS+=$(SPP_FLAGS_PROD) 275 | endif 276 | 277 | SPP_DEFINES+=$(SPP_DEFINES_EXTRA) 278 | SPP_FLAGS+=$(SPP_FLAGS_EXTRA) 279 | endif 280 | 281 | # 282 | # System/z uses preprocessed assembly written using GNU M4 283 | # 284 | ifeq ($(HOST_ARCH),z) 285 | M4_CMD?=$(M4_PATH) 286 | 287 | M4_INCLUDES=$(PRODUCT_INCLUDES) 288 | 289 | M4_DEFINES+=$(HOST_DEFINES) $(TARGET_DEFINES) 290 | 291 | ifeq ($(BUILD_CONFIG),debug) 292 | M4_DEFINES+=$(M4_DEFINES_DEBUG) 293 | M4_FLAGS+=$(M4_FLAGS_DEBUG) 294 | endif 295 | 296 | ifeq ($(BUILD_CONFIG),prod) 297 | M4_DEFINES+=$(M4_DEFINES_PROD) 298 | M4_FLAGS+=$(M4_FLAGS_PROD) 299 | endif 300 | 301 | M4_DEFINES+=$(M4_DEFINES_EXTRA) 302 | M4_FLAGS+=$(M4_FLAGS_EXTRA) 303 | endif 304 | 305 | # 306 | # The GNU archiver is nothing special... pretty much standard UNIX syntax 307 | # It doesn't have to use ranlib, so that's rather nice :) 308 | # 309 | AR_CMD?=$(AR_PATH) 310 | AR_OPTS?=rcv 311 | 312 | # 313 | # There really isn't much to setting up the linker for Ruby actually 314 | # This will look a lot crazier on J9 315 | # 316 | SOLINK_CMD?=$(CXX_PATH) 317 | SOLINK_FLAGS+=-shared 318 | SOLINK_SLINK+=dl pthread 319 | SOLINK_FLAGS_PROD= 320 | 321 | ifeq ($(BUILD_CONFIG),debug) 322 | SOLINK_FLAGS+=$(SOLINK_FLAGS_DEBUG) 323 | endif 324 | 325 | ifeq ($(BUILD_CONFIG),prod) 326 | SOLINK_FLAGS+=$(SOLINK_FLAGS_PROD) 327 | endif 328 | 329 | SOLINK_FLAGS+=$(SOLINK_FLAGS_EXTRA) 330 | -------------------------------------------------------------------------------- /ruby/build/toolcfg/host/32.mk: -------------------------------------------------------------------------------- 1 | ################################################################################### 2 | # (c) Copyright IBM Corp. 2000, 2016 3 | # 4 | # This program and the accompanying materials are made available 5 | # under the terms of the Eclipse Public License v1.0 and 6 | # Apache License v2.0 which accompanies this distribution. 7 | # 8 | # The Eclipse Public License is available at 9 | # http://www.eclipse.org/legal/epl-v10.html 10 | # 11 | # The Apache License v2.0 is available at 12 | # http://www.opensource.org/licenses/apache2.0.php 13 | # 14 | # Contributors: 15 | # Multiple authors (IBM Corp.) - initial implementation and documentation 16 | ################################################################################## 17 | 18 | 19 | HOST_DEFINES+=TR_HOST_32BIT 20 | -------------------------------------------------------------------------------- /ruby/build/toolcfg/host/64.mk: -------------------------------------------------------------------------------- 1 | ################################################################################### 2 | # (c) Copyright IBM Corp. 2000, 2016 3 | # 4 | # This program and the accompanying materials are made available 5 | # under the terms of the Eclipse Public License v1.0 and 6 | # Apache License v2.0 which accompanies this distribution. 7 | # 8 | # The Eclipse Public License is available at 9 | # http://www.eclipse.org/legal/epl-v10.html 10 | # 11 | # The Apache License v2.0 is available at 12 | # http://www.opensource.org/licenses/apache2.0.php 13 | # 14 | # Contributors: 15 | # Multiple authors (IBM Corp.) - initial implementation and documentation 16 | ################################################################################## 17 | 18 | 19 | HOST_DEFINES+=TR_HOST_64BIT BITVECTOR_64BIT 20 | -------------------------------------------------------------------------------- /ruby/build/toolcfg/host/linux.mk: -------------------------------------------------------------------------------- 1 | ################################################################################### 2 | # (c) Copyright IBM Corp. 2000, 2016 3 | # 4 | # This program and the accompanying materials are made available 5 | # under the terms of the Eclipse Public License v1.0 and 6 | # Apache License v2.0 which accompanies this distribution. 7 | # 8 | # The Eclipse Public License is available at 9 | # http://www.eclipse.org/legal/epl-v10.html 10 | # 11 | # The Apache License v2.0 is available at 12 | # http://www.opensource.org/licenses/apache2.0.php 13 | # 14 | # Contributors: 15 | # Multiple authors (IBM Corp.) - initial implementation and documentation 16 | ################################################################################## 17 | 18 | 19 | HOST_DEFINES+=LINUX 20 | -------------------------------------------------------------------------------- /ruby/build/toolcfg/host/osx.mk: -------------------------------------------------------------------------------- 1 | HOST_DEFINES+=OSX 2 | -------------------------------------------------------------------------------- /ruby/build/toolcfg/host/p.mk: -------------------------------------------------------------------------------- 1 | ################################################################################### 2 | # (c) Copyright IBM Corp. 2000, 2016 3 | # 4 | # This program and the accompanying materials are made available 5 | # under the terms of the Eclipse Public License v1.0 and 6 | # Apache License v2.0 which accompanies this distribution. 7 | # 8 | # The Eclipse Public License is available at 9 | # http://www.eclipse.org/legal/epl-v10.html 10 | # 11 | # The Apache License v2.0 is available at 12 | # http://www.opensource.org/licenses/apache2.0.php 13 | # 14 | # Contributors: 15 | # Multiple authors (IBM Corp.) - initial implementation and documentation 16 | ################################################################################## 17 | 18 | 19 | HOST_DEFINES+=TR_HOST_POWER 20 | -------------------------------------------------------------------------------- /ruby/build/toolcfg/host/x.mk: -------------------------------------------------------------------------------- 1 | ################################################################################### 2 | # (c) Copyright IBM Corp. 2000, 2016 3 | # 4 | # This program and the accompanying materials are made available 5 | # under the terms of the Eclipse Public License v1.0 and 6 | # Apache License v2.0 which accompanies this distribution. 7 | # 8 | # The Eclipse Public License is available at 9 | # http://www.eclipse.org/legal/epl-v10.html 10 | # 11 | # The Apache License v2.0 is available at 12 | # http://www.opensource.org/licenses/apache2.0.php 13 | # 14 | # Contributors: 15 | # Multiple authors (IBM Corp.) - initial implementation and documentation 16 | ################################################################################## 17 | 18 | 19 | HOST_DEFINES+=TR_HOST_X86 20 | -------------------------------------------------------------------------------- /ruby/build/toolcfg/host/z.mk: -------------------------------------------------------------------------------- 1 | ################################################################################### 2 | # (c) Copyright IBM Corp. 2000, 2016 3 | # 4 | # This program and the accompanying materials are made available 5 | # under the terms of the Eclipse Public License v1.0 and 6 | # Apache License v2.0 which accompanies this distribution. 7 | # 8 | # The Eclipse Public License is available at 9 | # http://www.eclipse.org/legal/epl-v10.html 10 | # 11 | # The Apache License v2.0 is available at 12 | # http://www.opensource.org/licenses/apache2.0.php 13 | # 14 | # Contributors: 15 | # Multiple authors (IBM Corp.) - initial implementation and documentation 16 | ################################################################################## 17 | 18 | 19 | HOST_DEFINES+=TR_HOST_S390 20 | -------------------------------------------------------------------------------- /ruby/build/toolcfg/target/32.mk: -------------------------------------------------------------------------------- 1 | ################################################################################### 2 | # (c) Copyright IBM Corp. 2000, 2016 3 | # 4 | # This program and the accompanying materials are made available 5 | # under the terms of the Eclipse Public License v1.0 and 6 | # Apache License v2.0 which accompanies this distribution. 7 | # 8 | # The Eclipse Public License is available at 9 | # http://www.eclipse.org/legal/epl-v10.html 10 | # 11 | # The Apache License v2.0 is available at 12 | # http://www.opensource.org/licenses/apache2.0.php 13 | # 14 | # Contributors: 15 | # Multiple authors (IBM Corp.) - initial implementation and documentation 16 | ################################################################################## 17 | 18 | 19 | TARGET_DEFINES+=TR_TARGET_32BIT 20 | -------------------------------------------------------------------------------- /ruby/build/toolcfg/target/64.mk: -------------------------------------------------------------------------------- 1 | ################################################################################### 2 | # (c) Copyright IBM Corp. 2000, 2016 3 | # 4 | # This program and the accompanying materials are made available 5 | # under the terms of the Eclipse Public License v1.0 and 6 | # Apache License v2.0 which accompanies this distribution. 7 | # 8 | # The Eclipse Public License is available at 9 | # http://www.eclipse.org/legal/epl-v10.html 10 | # 11 | # The Apache License v2.0 is available at 12 | # http://www.opensource.org/licenses/apache2.0.php 13 | # 14 | # Contributors: 15 | # Multiple authors (IBM Corp.) - initial implementation and documentation 16 | ################################################################################## 17 | 18 | 19 | TARGET_DEFINES+=TR_TARGET_64BIT 20 | -------------------------------------------------------------------------------- /ruby/build/toolcfg/target/p.mk: -------------------------------------------------------------------------------- 1 | ################################################################################### 2 | # (c) Copyright IBM Corp. 2000, 2016 3 | # 4 | # This program and the accompanying materials are made available 5 | # under the terms of the Eclipse Public License v1.0 and 6 | # Apache License v2.0 which accompanies this distribution. 7 | # 8 | # The Eclipse Public License is available at 9 | # http://www.eclipse.org/legal/epl-v10.html 10 | # 11 | # The Apache License v2.0 is available at 12 | # http://www.opensource.org/licenses/apache2.0.php 13 | # 14 | # Contributors: 15 | # Multiple authors (IBM Corp.) - initial implementation and documentation 16 | ################################################################################## 17 | 18 | 19 | TARGET_DEFINES+=TR_TARGET_POWER 20 | -------------------------------------------------------------------------------- /ruby/build/toolcfg/target/x.mk: -------------------------------------------------------------------------------- 1 | ################################################################################### 2 | # (c) Copyright IBM Corp. 2000, 2016 3 | # 4 | # This program and the accompanying materials are made available 5 | # under the terms of the Eclipse Public License v1.0 and 6 | # Apache License v2.0 which accompanies this distribution. 7 | # 8 | # The Eclipse Public License is available at 9 | # http://www.eclipse.org/legal/epl-v10.html 10 | # 11 | # The Apache License v2.0 is available at 12 | # http://www.opensource.org/licenses/apache2.0.php 13 | # 14 | # Contributors: 15 | # Multiple authors (IBM Corp.) - initial implementation and documentation 16 | ################################################################################## 17 | 18 | 19 | TARGET_DEFINES+=TR_TARGET_X86 20 | -------------------------------------------------------------------------------- /ruby/build/toolcfg/target/z.mk: -------------------------------------------------------------------------------- 1 | ################################################################################### 2 | # (c) Copyright IBM Corp. 2000, 2016 3 | # 4 | # This program and the accompanying materials are made available 5 | # under the terms of the Eclipse Public License v1.0 and 6 | # Apache License v2.0 which accompanies this distribution. 7 | # 8 | # The Eclipse Public License is available at 9 | # http://www.eclipse.org/legal/epl-v10.html 10 | # 11 | # The Apache License v2.0 is available at 12 | # http://www.opensource.org/licenses/apache2.0.php 13 | # 14 | # Contributors: 15 | # Multiple authors (IBM Corp.) - initial implementation and documentation 16 | ################################################################################## 17 | 18 | 19 | TARGET_DEFINES+=TR_TARGET_S390 20 | -------------------------------------------------------------------------------- /ruby/codegen/CodeGenerator.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * (c) Copyright IBM Corp. 2000, 2016 4 | * 5 | * This program and the accompanying materials are made available 6 | * under the terms of the Eclipse Public License v1.0 and 7 | * Apache License v2.0 which accompanies this distribution. 8 | * 9 | * The Eclipse Public License is available at 10 | * http://www.eclipse.org/legal/epl-v10.html 11 | * 12 | * The Apache License v2.0 is available at 13 | * http://www.opensource.org/licenses/apache2.0.php 14 | * 15 | * Contributors: 16 | * Multiple authors (IBM Corp.) - initial implementation and documentation 17 | *******************************************************************************/ 18 | 19 | 20 | #ifndef RUBY_CODEGENERATOR_INCL 21 | #define RUBY_CODEGENERATOR_INCL 22 | 23 | #include "codegen/RubyCodeGenerator.hpp" 24 | 25 | namespace TR 26 | { 27 | class OMR_EXTENSIBLE CodeGenerator : public ::Ruby::CodeGeneratorConnector 28 | { 29 | public: 30 | 31 | CodeGenerator() : 32 | ::Ruby::CodeGeneratorConnector() {} 33 | }; 34 | } 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /ruby/codegen/RubyCodeGenerator.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * (c) Copyright IBM Corp. 2000, 2016 4 | * 5 | * This program and the accompanying materials are made available 6 | * under the terms of the Eclipse Public License v1.0 and 7 | * Apache License v2.0 which accompanies this distribution. 8 | * 9 | * The Eclipse Public License is available at 10 | * http://www.eclipse.org/legal/epl-v10.html 11 | * 12 | * The Apache License v2.0 is available at 13 | * http://www.opensource.org/licenses/apache2.0.php 14 | * 15 | * Contributors: 16 | * Multiple authors (IBM Corp.) - initial implementation and documentation 17 | *******************************************************************************/ 18 | 19 | #ifndef RUBY_CODEGENERATORBASE_INCL 20 | #define RUBY_CODEGENERATORBASE_INCL 21 | 22 | /* 23 | * The following #define and typedef must appear before any #includes in this file 24 | */ 25 | #ifndef RUBY_CODEGENERATORBASE_CONNECTOR 26 | #define RUBY_CODEGENERATORBASE_CONNECTOR 27 | namespace Ruby { class CodeGenerator; } 28 | namespace Ruby { typedef CodeGenerator CodeGeneratorConnector; } 29 | #endif 30 | 31 | 32 | #include "codegen/OMRCodeGenerator.hpp" 33 | 34 | namespace Ruby 35 | { 36 | 37 | class OMR_EXTENSIBLE CodeGenerator : public OMR::CodeGeneratorConnector 38 | { 39 | public: 40 | 41 | CodeGenerator() : 42 | OMR::CodeGeneratorConnector() {} 43 | 44 | }; 45 | 46 | } 47 | #endif 48 | 49 | 50 | -------------------------------------------------------------------------------- /ruby/compile/Compilation.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * (c) Copyright IBM Corp. 2000, 2016 4 | * 5 | * This program and the accompanying materials are made available 6 | * under the terms of the Eclipse Public License v1.0 and 7 | * Apache License v2.0 which accompanies this distribution. 8 | * 9 | * The Eclipse Public License is available at 10 | * http://www.eclipse.org/legal/epl-v10.html 11 | * 12 | * The Apache License v2.0 is available at 13 | * http://www.opensource.org/licenses/apache2.0.php 14 | * 15 | * Contributors: 16 | * Multiple authors (IBM Corp.) - initial implementation and documentation 17 | *******************************************************************************/ 18 | 19 | 20 | #ifndef TR_COMPILATION_INCL 21 | #define TR_COMPILATION_INCL 22 | 23 | #include "compile/RubyCompilation.hpp" 24 | #include "env/OMRMemory.hpp" 25 | #include "control/Options.hpp" 26 | #include "control/Options_inlines.hpp" 27 | 28 | class TR_FrontEnd; 29 | class TR_ResolvedMethod; 30 | class TR_OptimizationPlan; 31 | namespace TR { class IlGenRequest; } 32 | struct OMR_VMThread; 33 | 34 | namespace TR 35 | { 36 | class Compilation : public ::Ruby::CompilationConnector 37 | { 38 | public: 39 | 40 | Compilation( 41 | int32_t compThreadId, 42 | OMR_VMThread *omrVMThread, 43 | TR_FrontEnd *fe, 44 | TR_ResolvedMethod *method, 45 | TR::IlGenRequest &request, 46 | TR::Options &options, 47 | const TR::Region &dispatchRegion, 48 | TR_Memory *memory, 49 | TR_OptimizationPlan *optimizationPlan) : 50 | ::Ruby::CompilationConnector( 51 | compThreadId, 52 | omrVMThread, 53 | fe, 54 | method, 55 | request, 56 | options, 57 | dispatchRegion, 58 | memory, 59 | optimizationPlan) 60 | {} 61 | 62 | ~Compilation() {} 63 | }; 64 | } 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /ruby/compile/RubyCompilation.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * (c) Copyright IBM Corp. 2000, 2016 4 | * 5 | * This program and the accompanying materials are made available 6 | * under the terms of the Eclipse Public License v1.0 and 7 | * Apache License v2.0 which accompanies this distribution. 8 | * 9 | * The Eclipse Public License is available at 10 | * http://www.eclipse.org/legal/epl-v10.html 11 | * 12 | * The Apache License v2.0 is available at 13 | * http://www.opensource.org/licenses/apache2.0.php 14 | * 15 | * Contributors: 16 | * Multiple authors (IBM Corp.) - initial implementation and documentation 17 | *******************************************************************************/ 18 | 19 | #pragma csect(CODE,"RubyCompilation#C") 20 | #pragma csect(STATIC,"RubyCompilation#S") 21 | #pragma csect(TEST,"RubyCompilation#T") 22 | 23 | #include "compile/Compilation.hpp" 24 | #include "control/Options.hpp" 25 | #include "control/Options_inlines.hpp" 26 | #include "env/TRMemory.hpp" 27 | #include "ilgen/IlGenRequest.hpp" 28 | #include "control/OptimizationPlan.hpp" 29 | #include "optimizer/Optimizer.hpp" 30 | #include "infra/List.hpp" 31 | #include "il/Node.hpp" 32 | #include "optimizer/OptimizationManager.hpp" 33 | #include 34 | #include "compile/ResolvedMethod.hpp" 35 | 36 | 37 | Ruby::Compilation::Compilation( 38 | int32_t id, 39 | OMR_VMThread *omrVMThread, 40 | TR_FrontEnd *fe, 41 | TR_ResolvedMethod *compilee, 42 | TR::IlGenRequest &ilGenRequest, 43 | TR::Options &options, 44 | const TR::Region &dispatchRegion, 45 | TR_Memory *m, 46 | TR_OptimizationPlan *optimizationPlan) 47 | : OMR::CompilationConnector( 48 | id, 49 | omrVMThread, 50 | fe, 51 | compilee, 52 | ilGenRequest, 53 | options, 54 | dispatchRegion, 55 | m, 56 | optimizationPlan) 57 | { 58 | } 59 | -------------------------------------------------------------------------------- /ruby/compile/RubyCompilation.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * (c) Copyright IBM Corp. 2000, 2016 4 | * 5 | * This program and the accompanying materials are made available 6 | * under the terms of the Eclipse Public License v1.0 and 7 | * Apache License v2.0 which accompanies this distribution. 8 | * 9 | * The Eclipse Public License is available at 10 | * http://www.eclipse.org/legal/epl-v10.html 11 | * 12 | * The Apache License v2.0 is available at 13 | * http://www.opensource.org/licenses/apache2.0.php 14 | * 15 | * Contributors: 16 | * Multiple authors (IBM Corp.) - initial implementation and documentation 17 | *******************************************************************************/ 18 | 19 | 20 | #ifndef RUBY_COMPILATION_INCL 21 | #define RUBY_COMPILATION_INCL 22 | 23 | /* 24 | * The following #define and typedef must appear before any #includes in this file 25 | */ 26 | #ifndef RUBY_COMPILATION_CONNECTOR 27 | #define RUBY_COMPILATION_CONNECTOR 28 | namespace Ruby { class Compilation; } 29 | namespace Ruby { typedef Ruby::Compilation CompilationConnector; } 30 | #endif 31 | 32 | #include "compile/OMRCompilation.hpp" 33 | #include "env/OMRMemory.hpp" 34 | #include "control/Options.hpp" 35 | #include "control/Options_inlines.hpp" 36 | 37 | class TR_FrontEnd; 38 | class TR_ResolvedMethod; 39 | class TR_OptimizationPlan; 40 | namespace TR { class IlGenRequest; } 41 | struct OMR_VMThread; 42 | 43 | namespace Ruby 44 | { 45 | 46 | class Compilation : public OMR::CompilationConnector 47 | { 48 | public: 49 | 50 | TR_ALLOC(TR_Memory::Compilation) 51 | 52 | Compilation( 53 | int32_t compThreadId, 54 | OMR_VMThread *omrVMThread, 55 | TR_FrontEnd *, 56 | TR_ResolvedMethod *, 57 | TR::IlGenRequest &, 58 | TR::Options &, 59 | const TR::Region &dispatchRegion, 60 | TR_Memory *, 61 | TR_OptimizationPlan *optimizationPlan); 62 | 63 | ~Compilation() {} 64 | 65 | }; 66 | 67 | } 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /ruby/compile/RubySymbolReferenceTable.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * (c) Copyright IBM Corp. 2000, 2016 4 | * 5 | * This program and the accompanying materials are made available 6 | * under the terms of the Eclipse Public License v1.0 and 7 | * Apache License v2.0 which accompanies this distribution. 8 | * 9 | * The Eclipse Public License is available at 10 | * http://www.eclipse.org/legal/epl-v10.html 11 | * 12 | * The Apache License v2.0 is available at 13 | * http://www.opensource.org/licenses/apache2.0.php 14 | * 15 | * Contributors: 16 | * Multiple authors (IBM Corp.) - initial implementation and documentation 17 | *******************************************************************************/ 18 | 19 | #include "compile/SymbolReferenceTable.hpp" 20 | #include "compile/Compilation.hpp" 21 | #include "env/TRMemory.hpp" // for TR_HeapMemory, etc 22 | #include "env/RubyFE.hpp" 23 | #include "il/SymbolReference.hpp" // for SymbolReference, etc 24 | #include "il/symbol/StaticSymbol.hpp" // for StaticSymbol, etc 25 | #include "il/symbol/RegisterMappedSymbol.hpp" // for RegisterMappedSymbol, etc 26 | #include "il/symbol/ResolvedMethodSymbol.hpp" // for ResolvedMethodSymbol 27 | #include "il/symbol/ParameterSymbol.hpp" 28 | #include "infra/List.hpp" 29 | 30 | 31 | Ruby::SymbolReferenceTable::SymbolReferenceTable(size_t sizeHint, TR::Compilation *c) : 32 | OMR::SymbolReferenceTableConnector(sizeHint, c), 33 | _ruby_vm_event_flags_SymRef(0), 34 | _ruby_threadSymRefs(c->trMemory()), 35 | _rubyHelperSymRefs(0), 36 | _rubyHelperSymRefsBV(sizeHint, c->trMemory(), heapAlloc, growable, TR_Memory::BitVector), 37 | _rubyRedefinedFlagSymRefs(0), 38 | _rubyInterrupt_flag_SymRef(0), 39 | _rubyInterrupt_mask_SymRef(0), 40 | _ruby_inlined_receiver_temp_SymRef(c->allocator("SymRefTab")) 41 | { 42 | } 43 | 44 | 45 | /** 46 | * Return the thread symref for a particular resolved method. 47 | */ 48 | TR::SymbolReference * 49 | Ruby::SymbolReferenceTable::findOrCreateRubyThreadSymbolRef(TR::ResolvedMethodSymbol * methodSymbol) 50 | { 51 | 52 | auto index = methodSymbol->getResolvedMethodIndex(); 53 | ListIterator i(&_ruby_threadSymRefs); 54 | TR::SymbolReference * symRef; 55 | for (symRef = i.getFirst(); symRef; symRef = i.getNext()) 56 | { 57 | if (symRef->getOwningMethodIndex() == index) 58 | return symRef; 59 | } 60 | 61 | // Not found. 62 | auto *parmSymbol = methodSymbol->getParameterList().getListHead()->getData(); 63 | parmSymbol->setNotCollected(); 64 | 65 | symRef = self()->findOrCreateAutoSymbol(methodSymbol, // Owning 66 | parmSymbol->getSlot(), // Slot 67 | parmSymbol->getDataType(), // DT 68 | true, // isReference 69 | false, // isInternalPointer 70 | true, // reuse auto 71 | false // isAdjunct 72 | ); 73 | 74 | 75 | 76 | symRef->setOwningMethodIndex(index); 77 | _ruby_threadSymRefs.add(symRef); 78 | 79 | 80 | return symRef; 81 | 82 | } 83 | 84 | 85 | void 86 | Ruby::SymbolReferenceTable::initializeRubyHelperSymbolRefs(uint32_t maxIndex) 87 | { 88 | if(_rubyHelperSymRefs == NULL) 89 | { 90 | size_t sizeNeeded = (maxIndex + 1) * sizeof(TR::SymbolReference *); 91 | _rubyHelperSymRefs = (TR::SymbolReference **) trMemory()->allocateMemory(sizeNeeded, heapAlloc); 92 | memset(_rubyHelperSymRefs, 0, sizeNeeded); 93 | } 94 | } 95 | 96 | 97 | TR::SymbolReference * 98 | Ruby::SymbolReferenceTable::findOrCreateRubyHelperSymbolRef(TR_RuntimeHelper helper, 99 | bool canGCandReturn, 100 | bool canGCandExcept, 101 | bool preservesAllRegisters) 102 | { 103 | uint32_t nameIndex = static_cast(helper); 104 | if (_rubyHelperSymRefs[nameIndex] == NULL) 105 | { 106 | TR::SymbolReference *symRef = findOrCreateRuntimeHelper(helper, canGCandReturn, canGCandExcept, preservesAllRegisters); 107 | symRef->setEmptyUseDefAliases(self()); 108 | symRef->getSymbol()->castToMethodSymbol()->setSystemLinkageDispatch(); 109 | symRef->getSymbol()->castToMethodSymbol()->setLinkage(TR_System); 110 | _rubyHelperSymRefsBV.set(symRef->getReferenceNumber()); 111 | _rubyHelperSymRefs[nameIndex] = symRef; 112 | } 113 | 114 | return _rubyHelperSymRefs[nameIndex]; 115 | } 116 | 117 | 118 | TR::SymbolReference * 119 | Ruby::SymbolReferenceTable::createRubyNamedShadowSymRef(char* name, TR::DataTypes dt, size_t size, int32_t offset, bool killedAcrossCalls) 120 | { 121 | TR::Symbol* symbol = TR::Symbol::createNamedShadow(comp()->trHeapMemory(), dt, size, name); 122 | TR::SymbolReference* symRef = new (comp()->trHeapMemory()) TR::SymbolReference(self(), symbol, offset); 123 | symRef->setEmptyUseDefAliases(self()); 124 | 125 | if(killedAcrossCalls) 126 | symRef->setAliasedTo(_rubyHelperSymRefsBV, self(), true /*symmetric*/); 127 | 128 | return symRef; 129 | } 130 | 131 | 132 | TR::SymbolReference * 133 | Ruby::SymbolReferenceTable::createRubyNamedStaticSymRef(char* name, TR::DataTypes dt, void* addr, int32_t offset, bool killedAcrossCalls) 134 | { 135 | TR::Symbol* symbol = TR::StaticSymbol::createNamed(comp()->trHeapMemory(), dt, addr, name); 136 | TR::SymbolReference* symRef = new (comp()->trHeapMemory()) TR::SymbolReference(self(), symbol, offset); 137 | symRef->setEmptyUseDefAliases(self()); 138 | 139 | if (killedAcrossCalls) 140 | symRef->setAliasedTo(_rubyHelperSymRefsBV, self(), true /*symmetric*/); 141 | 142 | return symRef; 143 | } 144 | 145 | 146 | void 147 | Ruby::SymbolReferenceTable::initializeRubyRedefinedFlagSymbolRefs(uint32_t maxIndex) 148 | { 149 | if(_rubyRedefinedFlagSymRefs == NULL) 150 | { 151 | size_t sizeNeeded = (maxIndex + 1) * sizeof(TR::SymbolReference *); 152 | _rubyRedefinedFlagSymRefs = (TR::SymbolReference **) trMemory()->allocateMemory(sizeNeeded, heapAlloc); 153 | memset(_rubyRedefinedFlagSymRefs, 0, sizeNeeded); 154 | } 155 | } 156 | 157 | 158 | TR::SymbolReference * 159 | Ruby::SymbolReferenceTable::findOrCreateRubyRedefinedFlagSymbolRef(int32_t bop, char* name, TR::DataTypes dt, void* addr, int32_t offset, bool killedAcrossCalls) 160 | { 161 | 162 | if(_rubyRedefinedFlagSymRefs[bop] == NULL) 163 | _rubyRedefinedFlagSymRefs[bop] = createRubyNamedStaticSymRef(name, dt, addr, offset, killedAcrossCalls); 164 | 165 | return _rubyRedefinedFlagSymRefs[bop]; 166 | } 167 | 168 | 169 | TR::SymbolReference * 170 | Ruby::SymbolReferenceTable::findRubyRedefinedFlagSymbolRef(int32_t bop) 171 | { 172 | return _rubyRedefinedFlagSymRefs[bop]; 173 | } 174 | 175 | 176 | TR::SymbolReference * 177 | Ruby::SymbolReferenceTable::findOrCreateRubyVMEventFlagsSymbolRef(char* name, TR::DataTypes dt, void* addr, int32_t offset, bool killedAcrossCalls) 178 | { 179 | if (_ruby_vm_event_flags_SymRef == NULL) 180 | _ruby_vm_event_flags_SymRef = createRubyNamedStaticSymRef(name, dt, addr, offset, killedAcrossCalls); 181 | 182 | return _ruby_vm_event_flags_SymRef; 183 | } 184 | 185 | 186 | TR::SymbolReference * 187 | Ruby::SymbolReferenceTable::findRubyVMEventFlagsSymbolRef() 188 | { 189 | return _ruby_vm_event_flags_SymRef; 190 | } 191 | 192 | 193 | TR::SymbolReference * 194 | Ruby::SymbolReferenceTable::findOrCreateRubyInterruptFlagSymRef() 195 | { 196 | if (!_rubyInterrupt_flag_SymRef) 197 | _rubyInterrupt_flag_SymRef = createRubyNamedShadowSymRef("interrupt_flag", 198 | TR_RubyFE::slotType(), 199 | TR_RubyFE::SLOTSIZE, 200 | offsetof(rb_thread_t, interrupt_flag), 201 | true); 202 | return _rubyInterrupt_flag_SymRef; 203 | } 204 | 205 | 206 | TR::SymbolReference * 207 | Ruby::SymbolReferenceTable::findOrCreateRubyInterruptMaskSymRef() 208 | { 209 | if (!_rubyInterrupt_mask_SymRef) 210 | _rubyInterrupt_mask_SymRef = createRubyNamedShadowSymRef("interrupt_mask", 211 | TR_RubyFE::slotType(), 212 | TR_RubyFE::SLOTSIZE, 213 | offsetof(rb_thread_t, interrupt_mask), 214 | true); 215 | return _rubyInterrupt_mask_SymRef; 216 | } 217 | 218 | 219 | TR::SymbolReference * 220 | Ruby::SymbolReferenceTable::setRubyInlinedReceiverTempSymRef(TR_CallSite* callSite, TR::SymbolReference* receiverTempSymRef) 221 | { 222 | _ruby_inlined_receiver_temp_SymRef.Add(callSite, receiverTempSymRef); 223 | return receiverTempSymRef; 224 | } 225 | 226 | 227 | TR::SymbolReference * 228 | Ruby::SymbolReferenceTable::getRubyInlinedReceiverTempSymRef(TR_CallSite* callSite) 229 | { 230 | if(_ruby_inlined_receiver_temp_SymRef.Locate(callSite)) 231 | { 232 | return _ruby_inlined_receiver_temp_SymRef.Get(callSite); 233 | } 234 | else 235 | { 236 | return NULL; 237 | } 238 | } 239 | -------------------------------------------------------------------------------- /ruby/compile/RubySymbolReferenceTable.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * (c) Copyright IBM Corp. 2000, 2016 4 | * 5 | * This program and the accompanying materials are made available 6 | * under the terms of the Eclipse Public License v1.0 and 7 | * Apache License v2.0 which accompanies this distribution. 8 | * 9 | * The Eclipse Public License is available at 10 | * http://www.eclipse.org/legal/epl-v10.html 11 | * 12 | * The Apache License v2.0 is available at 13 | * http://www.opensource.org/licenses/apache2.0.php 14 | * 15 | * Contributors: 16 | * Multiple authors (IBM Corp.) - initial implementation and documentation 17 | *******************************************************************************/ 18 | 19 | #ifndef RUBY_SYMBOLREFERENCETABLE_INCL 20 | #define RUBY_SYMBOLREFERENCETABLE_INCL 21 | 22 | /* 23 | * The following #define and typedef must appear before any #includes in this file 24 | */ 25 | #ifndef RUBY_SYMBOLREFERENCETABLE_CONNECTOR 26 | #define RUBY_SYMBOLREFERENCETABLE_CONNECTOR 27 | namespace Ruby { class SymbolReferenceTable; } 28 | namespace Ruby { typedef Ruby::SymbolReferenceTable SymbolReferenceTableConnector; } 29 | #endif 30 | 31 | 32 | #include "compile/OMRSymbolReferenceTable.hpp" 33 | #include "infra/BitVector.hpp" 34 | #include "cs2/hashtab.h" // for HashTable, etc 35 | 36 | namespace TR { class Compilation; } 37 | namespace OMR { class SymbolReference; } 38 | class TR_CallSite; 39 | 40 | 41 | namespace Ruby 42 | { 43 | 44 | class SymbolReferenceTable : public OMR::SymbolReferenceTableConnector 45 | { 46 | public: 47 | 48 | SymbolReferenceTable(size_t size, TR::Compilation *comp); 49 | 50 | TR::SymbolReference * findOrCreateRubyThreadSymbolRef(TR::ResolvedMethodSymbol*); 51 | 52 | void initializeRubyHelperSymbolRefs(uint32_t maxIndex); 53 | TR::SymbolReference * findOrCreateRubyHelperSymbolRef(TR_RuntimeHelper helper, bool canGCandReturn, bool canGCandExcept, bool preservesAllRegisters); 54 | TR::SymbolReference * createRubyNamedShadowSymRef(char* name, TR::DataTypes dt, size_t size, int32_t offset, bool killedAcrossCalls); 55 | TR::SymbolReference * createRubyNamedStaticSymRef(char* name, TR::DataTypes dt, void* addr, int32_t offset, bool killedAcrossCalls); 56 | 57 | void initializeRubyRedefinedFlagSymbolRefs(uint32_t maxIndex); 58 | TR::SymbolReference * findRubyRedefinedFlagSymbolRef(int32_t bop); 59 | TR::SymbolReference * findOrCreateRubyRedefinedFlagSymbolRef(int32_t bop, char* name, TR::DataTypes dt, void* addr, int32_t offset, bool killedAcrossCalls); 60 | TR::SymbolReference * findRubyVMEventFlagsSymbolRef(); 61 | TR::SymbolReference * findOrCreateRubyVMEventFlagsSymbolRef(char* name, TR::DataTypes dt, void* addr, int32_t offset, bool killedAcrossCalls); 62 | 63 | TR::SymbolReference * findOrCreateRubyInterruptFlagSymRef(); 64 | TR::SymbolReference * findOrCreateRubyInterruptMaskSymRef(); 65 | 66 | //Inlining 67 | TR::SymbolReference *setRubyInlinedReceiverTempSymRef(TR_CallSite* callSite, TR::SymbolReference* receiverTempSymRef); 68 | TR::SymbolReference *getRubyInlinedReceiverTempSymRef(TR_CallSite* callSite); 69 | 70 | private: 71 | 72 | // Ruby support 73 | TR::SymbolReference *_ruby_vm_event_flags_SymRef; 74 | List _ruby_threadSymRefs; 75 | 76 | //Helper SymbolRefs and associated BitVector 77 | TR::SymbolReference ** _rubyHelperSymRefs; 78 | TR_BitVector _rubyHelperSymRefsBV; 79 | 80 | //Redefined Flag SymbolRefs 81 | TR::SymbolReference ** _rubyRedefinedFlagSymRefs; 82 | 83 | // Pending interrupt SymbolRefs. 84 | TR::SymbolReference * _rubyInterrupt_flag_SymRef; 85 | TR::SymbolReference * _rubyInterrupt_mask_SymRef; 86 | 87 | //Inlining 88 | CS2::HashTable _ruby_inlined_receiver_temp_SymRef; 89 | 90 | }; 91 | 92 | } 93 | 94 | #endif 95 | -------------------------------------------------------------------------------- /ruby/compile/SymbolReferenceTable.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * (c) Copyright IBM Corp. 2000, 2016 4 | * 5 | * This program and the accompanying materials are made available 6 | * under the terms of the Eclipse Public License v1.0 and 7 | * Apache License v2.0 which accompanies this distribution. 8 | * 9 | * The Eclipse Public License is available at 10 | * http://www.eclipse.org/legal/epl-v10.html 11 | * 12 | * The Apache License v2.0 is available at 13 | * http://www.opensource.org/licenses/apache2.0.php 14 | * 15 | * Contributors: 16 | * Multiple authors (IBM Corp.) - initial implementation and documentation 17 | *******************************************************************************/ 18 | 19 | #ifndef TR_SYMBOLREFERENCETABLE_INCL 20 | #define TR_SYMBOLREFERENCETABLE_INCL 21 | 22 | #include "compile/RubySymbolReferenceTable.hpp" 23 | 24 | namespace TR { class Compilation; } 25 | 26 | namespace TR 27 | { 28 | class SymbolReferenceTable : public Ruby::SymbolReferenceTableConnector 29 | { 30 | public: 31 | 32 | SymbolReferenceTable(size_t s, TR::Compilation *c) : 33 | Ruby::SymbolReferenceTableConnector(s, c) 34 | { 35 | } 36 | }; 37 | } 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /ruby/env/ConcreteFE.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * (c) Copyright IBM Corp. 2000, 2016 4 | * 5 | * This program and the accompanying materials are made available 6 | * under the terms of the Eclipse Public License v1.0 and 7 | * Apache License v2.0 which accompanies this distribution. 8 | * 9 | * The Eclipse Public License is available at 10 | * http://www.eclipse.org/legal/epl-v10.html 11 | * 12 | * The Apache License v2.0 is available at 13 | * http://www.opensource.org/licenses/apache2.0.php 14 | * 15 | * Contributors: 16 | * Multiple authors (IBM Corp.) - initial implementation and documentation 17 | *******************************************************************************/ 18 | 19 | #include "ruby/env/RubyFE.hpp" 20 | 21 | // translate RubyFE into the OMR namespace as the frontend so that everyone 22 | // can use that 23 | namespace OMR 24 | { 25 | typedef ::TR_RubyFE FrontEnd; 26 | } 27 | 28 | -------------------------------------------------------------------------------- /ruby/env/ObjectModel.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * (c) Copyright IBM Corp. 2000, 2016 4 | * 5 | * This program and the accompanying materials are made available 6 | * under the terms of the Eclipse Public License v1.0 and 7 | * Apache License v2.0 which accompanies this distribution. 8 | * 9 | * The Eclipse Public License is available at 10 | * http://www.eclipse.org/legal/epl-v10.html 11 | * 12 | * The Apache License v2.0 is available at 13 | * http://www.opensource.org/licenses/apache2.0.php 14 | * 15 | * Contributors: 16 | * Multiple authors (IBM Corp.) - initial implementation and documentation 17 | *******************************************************************************/ 18 | 19 | 20 | #ifndef TR_OBJECTMODEL_INCL 21 | #define TR_OBJECTMODEL_INCL 22 | 23 | #include "env/RubyObjectModel.hpp" 24 | 25 | 26 | namespace TR 27 | { 28 | class ObjectModel : public Ruby::ObjectModelConnector 29 | { 30 | public: 31 | 32 | ObjectModel() : Ruby::ObjectModelConnector() {} 33 | 34 | }; 35 | } 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /ruby/env/RubyFE.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * (c) Copyright IBM Corp. 2000, 2016 4 | * 5 | * This program and the accompanying materials are made available 6 | * under the terms of the Eclipse Public License v1.0 and 7 | * Apache License v2.0 which accompanies this distribution. 8 | * 9 | * The Eclipse Public License is available at 10 | * http://www.eclipse.org/legal/epl-v10.html 11 | * 12 | * The Apache License v2.0 is available at 13 | * http://www.opensource.org/licenses/apache2.0.php 14 | * 15 | * Contributors: 16 | * Multiple authors (IBM Corp.) - initial implementation and documentation 17 | *******************************************************************************/ 18 | 19 | #include "ruby/env/RubyFE.hpp" 20 | 21 | #include "codegen/CodeGenerator.hpp" 22 | #include "compile/CompilationTypes.hpp" 23 | #include "env/FEBase_t.hpp" 24 | #include "il/Block.hpp" 25 | #include "il/Node.hpp" 26 | #include "il/Node_inlines.hpp" 27 | #include "il/TreeTop.hpp" 28 | #include "il/TreeTop_inlines.hpp" 29 | #include "optimizer/CallInfo.hpp" 30 | #include "optimizer/InlinerFailureReason.hpp" 31 | #include "ruby/config.h" 32 | #include "ruby/version.h" 33 | 34 | TR_RubyFE *TR_RubyFE::_instance = 0; 35 | 36 | TR_RubyFE::TR_RubyFE(struct rb_vm_struct *vm) 37 | : TR::FEBase(), 38 | _vm(vm) 39 | { 40 | TR_ASSERT(!_instance, "TR_RubyFE must be initialized only once"); 41 | _instance = this; 42 | } 43 | 44 | 45 | const char * 46 | TR_RubyFE::id2name(ID id) 47 | { 48 | return _vm->jit->callbacks.rb_id2name_f(id); 49 | } 50 | -------------------------------------------------------------------------------- /ruby/env/RubyFE.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * (c) Copyright IBM Corp. 2000, 2016 4 | * 5 | * This program and the accompanying materials are made available 6 | * under the terms of the Eclipse Public License v1.0 and 7 | * Apache License v2.0 which accompanies this distribution. 8 | * 9 | * The Eclipse Public License is available at 10 | * http://www.eclipse.org/legal/epl-v10.html 11 | * 12 | * The Apache License v2.0 is available at 13 | * http://www.opensource.org/licenses/apache2.0.php 14 | * 15 | * Contributors: 16 | * Multiple authors (IBM Corp.) - initial implementation and documentation 17 | *******************************************************************************/ 18 | 19 | 20 | #ifndef RUBYFE_HPP_gfgYoA 21 | #define RUBYFE_HPP_gfgYoA 22 | 23 | #include "env/FEBase.hpp" 24 | #include "env/jittypes.h" 25 | #include "runtime/RubyJitConfig.hpp" 26 | #include "runtime/CodeCache.hpp" 27 | 28 | /* Ruby */ 29 | extern "C" { 30 | #define RUBY_DONT_SUBST 31 | #include "ruby.h" 32 | #include "vm_core.h" 33 | #include "jit.h" 34 | #include "vm_insnhelper.h" // For BOP_MINUS and FIXNUM_ruby_redefined_OP_FLAG etc. 35 | } 36 | 37 | class TR_RubyFE; 38 | 39 | namespace TR 40 | { 41 | template <> struct FETraits 42 | { 43 | typedef ::TR_RubyJitConfig JitConfig; 44 | typedef TR::CodeCacheManager CodeCacheManager; 45 | typedef TR::CodeCache CodeCache; 46 | static const size_t DEFAULT_SEG_SIZE = (128 * 1024); // 128kb 47 | static const size_t SLOTSIZE = (sizeof(VALUE)); 48 | }; 49 | } 50 | 51 | class TR_RubyFE : public TR::FEBase 52 | { 53 | private: 54 | static TR_RubyFE *_instance; 55 | struct rb_vm_struct *_vm; 56 | 57 | public: 58 | // The constructor can only be called once by jitInit 59 | TR_RubyFE(struct rb_vm_struct *vm); 60 | static TR_RubyFE *instance() { TR_ASSERT(_instance, "bad singleton"); return _instance; } 61 | 62 | // Map some of the traits in here for convenience 63 | static const size_t DEFAULT_SEG_SIZE = TR::FETraits::DEFAULT_SEG_SIZE; 64 | static const size_t SLOTSIZE = TR::FETraits::SLOTSIZE; 65 | 66 | static TR::DataTypes slotType() 67 | { return SLOTSIZE == 8 ? TR::Int64 : TR::Int32; } 68 | 69 | 70 | #if defined(TR_TARGET_S390) 71 | virtual void generateBinaryEncodingPrologue(TR_BinaryEncodingData *beData, TR::CodeGenerator *cg); 72 | #endif 73 | 74 | rb_jit_t *getJitInterface() { return _vm->jit; } 75 | const char *id2name(ID); 76 | 77 | }; 78 | 79 | #endif /* RUBYFE_HPP_gfgYoA */ 80 | -------------------------------------------------------------------------------- /ruby/env/RubyMethod.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * (c) Copyright IBM Corp. 2000, 2016 4 | * 5 | * This program and the accompanying materials are made available 6 | * under the terms of the Eclipse Public License v1.0 and 7 | * Apache License v2.0 which accompanies this distribution. 8 | * 9 | * The Eclipse Public License is available at 10 | * http://www.eclipse.org/legal/epl-v10.html 11 | * 12 | * The Apache License v2.0 is available at 13 | * http://www.opensource.org/licenses/apache2.0.php 14 | * 15 | * Contributors: 16 | * Multiple authors (IBM Corp.) - initial implementation and documentation 17 | *******************************************************************************/ 18 | 19 | #include "ruby/env/RubyMethod.hpp" 20 | 21 | 22 | /* nothing here for now */ 23 | -------------------------------------------------------------------------------- /ruby/env/RubyMethod.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * (c) Copyright IBM Corp. 2000, 2016 4 | * 5 | * This program and the accompanying materials are made available 6 | * under the terms of the Eclipse Public License v1.0 and 7 | * Apache License v2.0 which accompanies this distribution. 8 | * 9 | * The Eclipse Public License is available at 10 | * http://www.eclipse.org/legal/epl-v10.html 11 | * 12 | * The Apache License v2.0 is available at 13 | * http://www.opensource.org/licenses/apache2.0.php 14 | * 15 | * Contributors: 16 | * Multiple authors (IBM Corp.) - initial implementation and documentation 17 | *******************************************************************************/ 18 | 19 | 20 | #ifndef RUBYMETHOD_INCL 21 | #define RUBYMETHOD_INCL 22 | 23 | #include "compile/Method.hpp" 24 | #include "compile/ResolvedMethod.hpp" 25 | 26 | extern "C" { 27 | #define RUBY_DONT_SUBST 28 | #include "ruby.h" 29 | #include "method.h" 30 | #include "vm_core.h" 31 | #include "iseq.h" 32 | } 33 | 34 | class RubyMethodBlock 35 | { 36 | public: 37 | RubyMethodBlock(rb_iseq_t *iseq, const char *name) 38 | : _iseq(iseq), _name(name) 39 | { 40 | // Ensure that the original iseq exists, as in v222, raw 41 | // iseqs are deleted. 42 | // 43 | // To save memory, we could free this if created here, 44 | // hoewver for now, we leave it behind to fastpath 45 | // future accesses. 46 | rb_iseq_original_iseq(iseq); 47 | } 48 | 49 | const rb_iseq_t *iseq() const { return _iseq; } 50 | const char *name() const { return _name; } 51 | unsigned long size() const { return _iseq->iseq_size; } 52 | VALUE *bytecodes() const { return _iseq->iseq; } 53 | VALUE *bytecodesEncoded() const { return _iseq->iseq_encoded; } 54 | size_t stack_max() const { return _iseq->stack_max; } 55 | 56 | private: 57 | const rb_iseq_t *_iseq; 58 | const char *_name; 59 | }; 60 | 61 | 62 | class RubyMethod : public TR_Method 63 | { 64 | public: 65 | TR_ALLOC(TR_Memory::Method); 66 | 67 | RubyMethod() : TR_Method(TR_Method::Ruby) {} 68 | 69 | // Better answers could happen here. 70 | virtual uint16_t classNameLength() { return strlen(classNameChars()); } 71 | virtual uint16_t nameLength() { return strlen(nameChars()); } 72 | virtual uint16_t signatureLength() { return strlen(signatureChars()); } 73 | virtual char *classNameChars() { return "noclass"; } 74 | virtual char *signatureChars() { return "(Lrb_thread_t;)V"; } 75 | 76 | virtual bool isConstructor() { return false; } 77 | virtual bool isFinalInObject() { return false; } 78 | }; 79 | 80 | class ResolvedRubyMethodBase : public TR_ResolvedMethod 81 | { 82 | public: 83 | ResolvedRubyMethodBase(RubyMethodBlock &method) 84 | : _method(method) 85 | { } 86 | 87 | virtual const char * signature(TR_Memory *, TR_AllocationKind) { return _method.name(); } 88 | 89 | // This group of functions only make sense for Java - we ought to provide answers from that definition 90 | virtual bool isConstructor() { return false; } // returns true if this method is object constructor. 91 | virtual bool isStatic() { return true; } // ie. has no corresponding class 92 | virtual bool isAbstract() { return false; } // we do have a concrete impl. 93 | virtual bool isCompilable(TR_Memory *) { return true; } 94 | virtual bool isNative() { return false; } // ie. not a JNI native 95 | virtual bool isSynchronized() { return false; }// no monitors required 96 | virtual bool isPrivate() { return false; } // 97 | virtual bool isProtected() { return false; } // 98 | virtual bool isPublic() { return true; } // public scope 99 | virtual bool isFinal() { return false; } 100 | virtual bool isStrictFP() { return false; } 101 | virtual bool isSubjectToPhaseChange(TR::Compilation *comp) { return false; } 102 | virtual bool hasBackwardBranches() { return false; } 103 | virtual void * resolvedMethodAddress() { return (void *)getPersistentIdentifier(); } 104 | 105 | virtual uint16_t numberOfParameterSlots() { return 1; } 106 | virtual TR::DataTypes parmType(uint32_t slot) { return TR::Address; } 107 | virtual uint16_t numberOfTemps() { return 0; } 108 | 109 | virtual uint32_t maxBytecodeIndex() { return _method.size(); } 110 | 111 | virtual bool isNewInstanceImplThunk() { return false; } 112 | virtual bool isJNINative() { return false; } 113 | virtual bool isJITInternalNative() { return false; } 114 | 115 | virtual TR_OpaqueMethodBlock *getPersistentIdentifier() { return (TR_OpaqueMethodBlock *) &_method; } 116 | RubyMethodBlock &getRubyMethodBlock() { return _method; } 117 | VALUE* code() { return _method.bytecodes(); } 118 | 119 | uint32_t numberOfExceptionHandlers() { return 0; } 120 | 121 | virtual bool isInterpreted() { return true; } 122 | virtual void * startAddressForJittedMethod() { return 0; } 123 | virtual void * startAddressForInterpreterOfJittedMethod() { return 0; } 124 | 125 | virtual bool isSameMethod(TR_ResolvedMethod *other) 126 | { return getPersistentIdentifier() == other->getPersistentIdentifier(); } 127 | virtual TR_OpaqueClassBlock *classOfMethod() { return 0; } 128 | 129 | protected: 130 | RubyMethodBlock &_method; 131 | }; 132 | 133 | class ResolvedRubyMethod : public ResolvedRubyMethodBase, public RubyMethod 134 | { 135 | public: 136 | ResolvedRubyMethod(RubyMethodBlock &method) : ResolvedRubyMethodBase(method), RubyMethod() { } 137 | 138 | virtual TR_Method *convertToMethod() { return this; } 139 | 140 | virtual uint16_t classNameLength() { return RubyMethod::classNameLength(); } 141 | virtual uint16_t nameLength() { return RubyMethod::nameLength(); } 142 | virtual uint16_t signatureLength() { return RubyMethod::signatureLength(); } 143 | virtual char *classNameChars() { return RubyMethod::signatureChars(); } 144 | virtual char *nameChars() { return RubyMethod::signatureChars(); } 145 | virtual char *signatureChars() { return RubyMethod::signatureChars(); } 146 | 147 | virtual bool isConstructor() { return false; } 148 | virtual bool isFinalInObject() { return false; } 149 | virtual bool isNonEmptyObjectConstructor() { return false; } 150 | virtual TR::DataTypes returnType() { return TR::NoType; } 151 | }; 152 | 153 | #endif 154 | -------------------------------------------------------------------------------- /ruby/env/RubyObjectModel.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * (c) Copyright IBM Corp. 2000, 2016 4 | * 5 | * This program and the accompanying materials are made available 6 | * under the terms of the Eclipse Public License v1.0 and 7 | * Apache License v2.0 which accompanies this distribution. 8 | * 9 | * The Eclipse Public License is available at 10 | * http://www.eclipse.org/legal/epl-v10.html 11 | * 12 | * The Apache License v2.0 is available at 13 | * http://www.opensource.org/licenses/apache2.0.php 14 | * 15 | * Contributors: 16 | * Multiple authors (IBM Corp.) - initial implementation and documentation 17 | *******************************************************************************/ 18 | 19 | 20 | #ifndef RUBY_OBJECTMODEL_INCL 21 | #define RUBY_OBJECTMODEL_INCL 22 | 23 | /* 24 | * The following #define and typedef must appear before any #includes in this file 25 | */ 26 | #ifndef RUBY_OBJECTMODEL_CONNECTOR 27 | #define RUBY_OBJECTMODEL_CONNECTOR 28 | namespace Ruby { class ObjectModel; } 29 | namespace Ruby { typedef Ruby::ObjectModel ObjectModelConnector; } 30 | #endif 31 | 32 | 33 | #include "env/OMRObjectModel.hpp" 34 | 35 | namespace Ruby 36 | { 37 | class ObjectModel : public OMR::ObjectModelConnector 38 | { 39 | public: 40 | 41 | ObjectModel() : 42 | OMR::ObjectModelConnector() {} 43 | 44 | virtual int32_t sizeofReferenceField() { return sizeof(char *); } 45 | 46 | }; 47 | } 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /ruby/il/Node.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * (c) Copyright IBM Corp. 2000, 2016 4 | * 5 | * This program and the accompanying materials are made available 6 | * under the terms of the Eclipse Public License v1.0 and 7 | * Apache License v2.0 which accompanies this distribution. 8 | * 9 | * The Eclipse Public License is available at 10 | * http://www.eclipse.org/legal/epl-v10.html 11 | * 12 | * The Apache License v2.0 is available at 13 | * http://www.opensource.org/licenses/apache2.0.php 14 | * 15 | * Contributors: 16 | * Multiple authors (IBM Corp.) - initial implementation and documentation 17 | *******************************************************************************/ 18 | 19 | #ifndef TR_NODE_INCL 20 | #define TR_NODE_INCL 21 | 22 | #include "il/RubyNode.hpp" 23 | 24 | #include // for NULL 25 | #include // for uint16_t 26 | #include "il/ILOpCodes.hpp" // for ILOpCodes 27 | #include "infra/Annotations.hpp" // for OMR_EXTENSIBLE 28 | 29 | namespace TR 30 | { 31 | 32 | class OMR_EXTENSIBLE Node : public ::Ruby::NodeConnector 33 | { 34 | 35 | public: 36 | 37 | Node() : ::Ruby::NodeConnector() {} 38 | 39 | Node(TR::Node *originatingByteCodeNode, TR::ILOpCodes op, 40 | uint16_t numChildren, OptAttributes * oa = NULL) 41 | : ::Ruby::NodeConnector(originatingByteCodeNode, op, numChildren, oa) 42 | {} 43 | 44 | Node(Node *from, uint16_t numChildren = 0) 45 | : ::Ruby::NodeConnector(from, numChildren) 46 | {} 47 | 48 | }; 49 | 50 | } 51 | 52 | #endif 53 | 54 | -------------------------------------------------------------------------------- /ruby/il/RubyNode.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * (c) Copyright IBM Corp. 2000, 2016 4 | * 5 | * This program and the accompanying materials are made available 6 | * under the terms of the Eclipse Public License v1.0 and 7 | * Apache License v2.0 which accompanies this distribution. 8 | * 9 | * The Eclipse Public License is available at 10 | * http://www.eclipse.org/legal/epl-v10.html 11 | * 12 | * The Apache License v2.0 is available at 13 | * http://www.opensource.org/licenses/apache2.0.php 14 | * 15 | * Contributors: 16 | * Multiple authors (IBM Corp.) - initial implementation and documentation 17 | *******************************************************************************/ 18 | 19 | #include "il/RubyNode.hpp" 20 | 21 | #include "il/Node.hpp" 22 | #include "il/Node_inlines.hpp" 23 | #include "il/Block.hpp" 24 | #include "il/TreeTop.hpp" 25 | 26 | TR::Node * 27 | Ruby::Node::axadd(TR::Node *addr, TR::Node *offset) 28 | { 29 | TR::ILOpCodes op = TR_RubyFE::SLOTSIZE == 8 ? TR::aladd : TR::aiadd; 30 | return TR::Node::create(op, 2, addr, offset); 31 | } 32 | 33 | TR::Node * 34 | Ruby::Node::xload(TR::SymbolReference *symRef) 35 | { 36 | return TR::Node::createLoad(symRef); 37 | } 38 | 39 | TR::Node * 40 | Ruby::Node::xadd(TR::Node *a, TR::Node *b) 41 | { 42 | return TR::Node::create(TR_RubyFE::SLOTSIZE == 8 ? TR::ladd : TR::iadd, 2, a, b); 43 | } 44 | 45 | TR::Node * 46 | Ruby::Node::xsub(TR::Node *a, TR::Node *b) 47 | { 48 | return TR::Node::create(TR_RubyFE::SLOTSIZE == 8 ? TR::lsub : TR::isub, 2, a, b); 49 | } 50 | 51 | TR::Node * 52 | Ruby::Node::xand(TR::Node *a, TR::Node *b) 53 | { 54 | return TR::Node::create(TR_RubyFE::SLOTSIZE == 8 ? TR::land : TR::iand, 2, a, b); 55 | } 56 | 57 | TR::Node * 58 | Ruby::Node::xxor(TR::Node *a, TR::Node *b) 59 | { 60 | return TR::Node::create(TR_RubyFE::SLOTSIZE == 8 ? TR::lxor : TR::ixor, 2, a, b); 61 | } 62 | 63 | TR::Node * 64 | Ruby::Node::xnot(TR::Node *a) 65 | { 66 | return TR::Node::xxor(a, TR::Node::xconst(-1)); 67 | } 68 | 69 | TR::Node * 70 | Ruby::Node::ifxcmpne(TR::Node *a, TR::Node *b) 71 | { 72 | return TR::Node::createif(TR::Node::ifxcmpneOp(), a, b); 73 | } 74 | 75 | TR::Node * 76 | Ruby::Node::ifxcmpeq(TR::Node *a, TR::Node *b) 77 | { 78 | return TR::Node::createif(TR::Node::ifxcmpeqOp(), a, b); 79 | } 80 | 81 | TR::Node * 82 | Ruby::Node::xcmpge(TR::Node *a, TR::Node *b) 83 | { 84 | return TR::Node::create(TR_RubyFE::SLOTSIZE == 8 ? TR::lcmpge : TR::icmpge, 2, a, b); 85 | } 86 | 87 | TR::Node * 88 | Ruby::Node::xternary(TR::Node *cmp, TR::Node *t, TR::Node *f) 89 | { 90 | return TR::Node::create(TR_RubyFE::SLOTSIZE == 8 ? TR::lternary : TR::iternary, 3, cmp, t, f); 91 | } 92 | 93 | TR::Node * 94 | Ruby::Node::xconst(uintptr_t value) 95 | { 96 | return TR_RubyFE::SLOTSIZE == 8 ? TR::Node::lconst(value) : TR::Node::iconst(value); 97 | } 98 | 99 | TR::ILOpCodes 100 | Ruby::Node::xloadOp(TR_RubyFE *fe) 101 | { 102 | return TR::comp()->il.opCodeForDirectLoad( TR_RubyFE::slotType() ); 103 | } 104 | 105 | TR::Node * 106 | Ruby::Node::xloadi(TR::SymbolReference *symRef, TR::Node *base, TR_FrontEnd * fe) 107 | { 108 | return TR::Node::createWithSymRef(TR::comp()->il.opCodeForIndirectLoad( TR_RubyFE::slotType() ), 1, 1, base, symRef); 109 | } 110 | 111 | TR::Node * 112 | Ruby::Node::xstorei(TR::SymbolReference *symRef, TR::Node *base, TR::Node *value, TR_RubyFE * fe) 113 | { 114 | return TR::Node::createWithSymRef(TR::comp()->il.opCodeForIndirectStore( TR_RubyFE::slotType() ), 2, 2, base, value, symRef); 115 | } 116 | 117 | TR::Node * 118 | Ruby::Node::createCallNode(TR::ILOpCodes opcode, TR::SymbolReference *symRef, int32_t num, ...) 119 | { 120 | // FIXME: var args loop duplicated from RubyIlGenerator::genCall 121 | auto node = TR::Node::createWithSymRef(opcode, num, symRef); 122 | va_list args; 123 | va_start(args, num); 124 | for (int i = 0; i < num; ++i) 125 | { 126 | node->setAndIncChild(i, va_arg(args, TR::Node *)); 127 | } 128 | va_end(args); 129 | return node; 130 | } 131 | 132 | /** 133 | * Create a treetop for node, and insert it before the passed treetop. 134 | */ 135 | void 136 | Ruby::Node::anchorBefore(TR::Node *node, TR::TreeTop *tt) 137 | { 138 | tt->insertBefore(TR::TreeTop::create(TR::comp(), TR::Node::create(TR::treetop, 1, node))); 139 | } 140 | 141 | /** 142 | * Generate a tree top and link into the passed block. 143 | */ 144 | TR::TreeTop * 145 | Ruby::Node::genTreeTop(TR::Node *n, TR::Block *inBlock) 146 | { 147 | if (!n->getOpCode().isTreeTop()) 148 | n = TR::Node::create(TR::treetop, 1, n); 149 | 150 | return inBlock->append(TR::TreeTop::create(TR::comp(), n)); 151 | } 152 | 153 | 154 | TR::SymbolReference * 155 | Ruby::Node::storeToTemp(TR::Node *value, TR::Block *inBlock) 156 | { 157 | TR::SymbolReference *tempSymRef = TR::comp()->getSymRefTab()->createTemporary(TR::comp()->getMethodSymbol(), TR_RubyFE::slotType()); 158 | TR::Node::genTreeTop(TR::Node::createStore(tempSymRef, value), inBlock); 159 | return tempSymRef; 160 | } 161 | 162 | TR::SymbolReference * 163 | Ruby::Node::storeToTemp(TR::Node *value, TR::TreeTop *tt) 164 | { 165 | TR::SymbolReference *tempSymRef = TR::comp()->getSymRefTab()->createTemporary(TR::comp()->getMethodSymbol(), TR_RubyFE::slotType()); 166 | TR::Node* storeNode = TR::Node::createStore(tempSymRef, value); 167 | tt->insertBefore(TR::TreeTop::create(TR::comp(), TR::Node::create(TR::treetop, 1, storeNode))); 168 | return tempSymRef; 169 | } 170 | 171 | /** 172 | * Load ruby thread symref for a method. 173 | */ 174 | TR::Node * 175 | Ruby::Node::loadThread(TR::ResolvedMethodSymbol * methodSymbol) 176 | { 177 | return TR::Node::createLoad(TR::comp()->getSymRefTab()->findOrCreateRubyThreadSymbolRef(methodSymbol)); 178 | } 179 | -------------------------------------------------------------------------------- /ruby/il/RubyNode.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * (c) Copyright IBM Corp. 2000, 2016 4 | * 5 | * This program and the accompanying materials are made available 6 | * under the terms of the Eclipse Public License v1.0 and 7 | * Apache License v2.0 which accompanies this distribution. 8 | * 9 | * The Eclipse Public License is available at 10 | * http://www.eclipse.org/legal/epl-v10.html 11 | * 12 | * The Apache License v2.0 is available at 13 | * http://www.opensource.org/licenses/apache2.0.php 14 | * 15 | * Contributors: 16 | * Multiple authors (IBM Corp.) - initial implementation and documentation 17 | *******************************************************************************/ 18 | 19 | #ifndef RUBY_NODE_INCL 20 | #define RUBY_NODE_INCL 21 | 22 | /* 23 | * The following #define and typedef must appear before any #includes in this file 24 | */ 25 | #ifndef RUBY_NODE_CONNECTOR 26 | #define RUBY_NODE_CONNECTOR 27 | namespace Ruby { class Node; } 28 | namespace Ruby { typedef Ruby::Node NodeConnector; } 29 | #endif 30 | 31 | #include "il/OMRNode.hpp" 32 | 33 | #include // for NULL 34 | #include // for uint16_t 35 | #include "il/ILOpCodes.hpp" // for ILOpCodes 36 | #include "infra/Annotations.hpp" // for OMR_EXTENSIBLE 37 | #include "ruby/env/RubyFE.hpp" 38 | 39 | namespace TR { class Node; } 40 | 41 | namespace Ruby 42 | { 43 | 44 | 45 | class OMR_EXTENSIBLE Node : public OMR::NodeConnector 46 | { 47 | public: 48 | //Forwarding constructors 49 | Node() : OMR::NodeConnector() {} 50 | 51 | Node(TR::Node *originatingByteCodeNode, TR::ILOpCodes op, 52 | uint16_t numChildren, OptAttributes * oa = NULL) 53 | : OMR::NodeConnector(originatingByteCodeNode, op, numChildren, oa) 54 | {} 55 | 56 | Node(TR::Node *from, uint16_t numChildren = 0) 57 | : OMR::NodeConnector(from, numChildren) 58 | {} 59 | 60 | 61 | // Convenience methods 62 | static TR::Node *axadd(TR::Node *addr, TR::Node *offset); 63 | 64 | static TR::Node *xload(TR::SymbolReference *symRef); 65 | 66 | static TR::ILOpCodes xcallOp() 67 | { return TR_RubyFE::SLOTSIZE == 8 ? TR::lcall : TR::icall; } 68 | 69 | static TR::Node *xloadi(TR::SymbolReference *symRef, TR::Node *base, TR_FrontEnd * fe); 70 | 71 | static TR::Node *xstorei(TR::SymbolReference *symRef, TR::Node *base, TR::Node *value, TR_RubyFE * fe); 72 | 73 | static TR::Node *xadd(TR::Node *a, TR::Node *b); 74 | static TR::Node *xsub(TR::Node *a, TR::Node *b); 75 | static TR::Node *xand(TR::Node *a, TR::Node *b); 76 | static TR::Node *xxor(TR::Node *a, TR::Node *b); 77 | static TR::Node *xnot(TR::Node *a); 78 | 79 | static TR::ILOpCodes ifxcmpneOp() 80 | { return TR_RubyFE::SLOTSIZE == 8 ? TR::iflcmpne : TR::ificmpne; } 81 | static TR::ILOpCodes ifxcmpeqOp() 82 | { return TR_RubyFE::SLOTSIZE == 8 ? TR::iflcmpeq : TR::ificmpeq; } 83 | 84 | static TR::Node *ifxcmpne(TR::Node *a, TR::Node *b); 85 | static TR::Node *ifxcmpeq(TR::Node *a, TR::Node *b); 86 | 87 | static TR::Node *xcmpge(TR::Node *a, TR::Node *b); 88 | static TR::Node *xternary(TR::Node *cmp, TR::Node *t, TR::Node *f); 89 | 90 | static TR::Node * xconst(uintptr_t value); 91 | 92 | static TR::ILOpCodes xloadOp(TR_RubyFE *fe); 93 | 94 | static TR::Node *createCallNode(TR::ILOpCodes, TR::SymbolReference *, int32_t num, ...); 95 | 96 | static void anchorBefore(TR::Node *node, TR::TreeTop *tt); 97 | 98 | static TR::TreeTop *genTreeTop(TR::Node *node, TR::Block *inBlock); 99 | 100 | static TR::SymbolReference *storeToTemp(TR::Node *value, TR::Block *inBlock); 101 | static TR::SymbolReference *storeToTemp(TR::Node *value, TR::TreeTop *tt); 102 | 103 | static TR::Node *loadThread(TR::ResolvedMethodSymbol*); 104 | 105 | }; 106 | 107 | } 108 | 109 | #endif 110 | 111 | -------------------------------------------------------------------------------- /ruby/il/RubySymbolReference.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * (c) Copyright IBM Corp. 2000, 2016 4 | * 5 | * This program and the accompanying materials are made available 6 | * under the terms of the Eclipse Public License v1.0 and 7 | * Apache License v2.0 which accompanies this distribution. 8 | * 9 | * The Eclipse Public License is available at 10 | * http://www.eclipse.org/legal/epl-v10.html 11 | * 12 | * The Apache License v2.0 is available at 13 | * http://www.opensource.org/licenses/apache2.0.php 14 | * 15 | * Contributors: 16 | * Multiple authors (IBM Corp.) - initial implementation and documentation 17 | *******************************************************************************/ 18 | 19 | #ifndef RUBY_SYMBOLREFERENCE_INCL 20 | #define RUBY_SYMBOLREFERENCE_INCL 21 | 22 | /* 23 | * The following #define and typedef must appear before any #includes in this file 24 | */ 25 | #ifndef RUBY_SYMBOLREFERENCE_CONNECTOR 26 | #define RUBY_SYMBOLREFERENCE_CONNECTOR 27 | namespace Ruby { class SymbolReference; } 28 | namespace Ruby { typedef Ruby::SymbolReference SymbolReferenceConnector; } 29 | #endif 30 | 31 | #include "il/OMRSymbolReference.hpp" 32 | 33 | #include // for int32_t 34 | #include "env/KnownObjectTable.hpp" // for KnownObjectTable, etc 35 | #include "compile/SymbolReferenceTable.hpp" // for SymbolReferenceTable, etc 36 | #include "env/jittypes.h" // for intptrj_t 37 | #include "infra/Annotations.hpp" // for OMR_EXTENSIBLE 38 | 39 | class mcount_t; 40 | namespace TR { class Symbol; } 41 | 42 | namespace Ruby 43 | { 44 | 45 | class OMR_EXTENSIBLE SymbolReference : public OMR::SymbolReferenceConnector 46 | { 47 | 48 | public: 49 | 50 | SymbolReference(TR::SymbolReferenceTable * symRefTab) : 51 | OMR::SymbolReferenceConnector(symRefTab) {} 52 | 53 | SymbolReference(TR::SymbolReferenceTable * symRefTab, 54 | TR::Symbol * symbol, 55 | intptrj_t offset = 0) : 56 | OMR::SymbolReferenceConnector(symRefTab, 57 | symbol, 58 | offset) {} 59 | 60 | SymbolReference(TR::SymbolReferenceTable * symRefTab, 61 | int32_t refNumber, 62 | TR::Symbol *ps, 63 | intptrj_t offset = 0) : 64 | OMR::SymbolReferenceConnector(symRefTab, 65 | refNumber, 66 | ps, 67 | offset) {} 68 | 69 | SymbolReference(TR::SymbolReferenceTable *symRefTab, 70 | TR::SymbolReferenceTable::CommonNonhelperSymbol number, 71 | TR::Symbol *ps, 72 | intptrj_t offset = 0) : 73 | OMR::SymbolReferenceConnector(symRefTab, 74 | number, 75 | ps, 76 | offset) {} 77 | 78 | SymbolReference(TR::SymbolReferenceTable *symRefTab, 79 | TR::Symbol *sym, 80 | mcount_t owningMethodIndex, 81 | int32_t cpIndex, 82 | int32_t unresolvedIndex = 0) : 83 | OMR::SymbolReferenceConnector(symRefTab, 84 | sym, 85 | owningMethodIndex, 86 | cpIndex, 87 | unresolvedIndex) {} 88 | 89 | SymbolReference(TR::SymbolReferenceTable *symRefTab, 90 | TR::SymbolReference& sr, 91 | intptrj_t offset, 92 | TR::KnownObjectTable::Index knownObjectIndex = TR::KnownObjectTable::UNKNOWN) : 93 | OMR::SymbolReferenceConnector(symRefTab, 94 | sr, 95 | offset, 96 | knownObjectIndex) {} 97 | 98 | protected: 99 | 100 | SymbolReference(TR::SymbolReferenceTable * symRefTab, 101 | TR::Symbol * symbol, 102 | intptrj_t offset, 103 | const char * name) : 104 | OMR::SymbolReferenceConnector(symRefTab, 105 | symbol, 106 | offset, 107 | name) {} 108 | 109 | }; 110 | 111 | } 112 | 113 | #endif 114 | -------------------------------------------------------------------------------- /ruby/il/SymbolReference.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * (c) Copyright IBM Corp. 2000, 2016 4 | * 5 | * This program and the accompanying materials are made available 6 | * under the terms of the Eclipse Public License v1.0 and 7 | * Apache License v2.0 which accompanies this distribution. 8 | * 9 | * The Eclipse Public License is available at 10 | * http://www.eclipse.org/legal/epl-v10.html 11 | * 12 | * The Apache License v2.0 is available at 13 | * http://www.opensource.org/licenses/apache2.0.php 14 | * 15 | * Contributors: 16 | * Multiple authors (IBM Corp.) - initial implementation and documentation 17 | *******************************************************************************/ 18 | 19 | #ifndef TR_SYMBOLREFERENCE_INCL 20 | #define TR_SYMBOLREFERENCE_INCL 21 | 22 | #include "il/RubySymbolReference.hpp" 23 | 24 | #include // for int32_t 25 | #include "env/KnownObjectTable.hpp" // for KnownObjectTable, etc 26 | #include "compile/SymbolReferenceTable.hpp" // for SymbolReferenceTable, etc 27 | #include "env/jittypes.h" // for intptrj_t 28 | #include "infra/Annotations.hpp" // for OMR_EXTENSIBLE 29 | 30 | class mcount_t; 31 | namespace TR { class Symbol; } 32 | 33 | namespace TR 34 | { 35 | 36 | class OMR_EXTENSIBLE SymbolReference : public ::Ruby::SymbolReferenceConnector 37 | { 38 | 39 | public: 40 | 41 | SymbolReference(TR::SymbolReferenceTable * symRefTab) : 42 | ::Ruby::SymbolReferenceConnector(symRefTab) {} 43 | 44 | SymbolReference(TR::SymbolReferenceTable * symRefTab, 45 | TR::Symbol * symbol, 46 | intptrj_t offset = 0) : 47 | ::Ruby::SymbolReferenceConnector(symRefTab, 48 | symbol, 49 | offset) {} 50 | 51 | SymbolReference(TR::SymbolReferenceTable * symRefTab, 52 | int32_t refNumber, 53 | TR::Symbol *ps, 54 | intptrj_t offset = 0) : 55 | ::Ruby::SymbolReferenceConnector(symRefTab, 56 | refNumber, 57 | ps, 58 | offset) {} 59 | 60 | SymbolReference(TR::SymbolReferenceTable *symRefTab, 61 | TR::SymbolReferenceTable::CommonNonhelperSymbol number, 62 | TR::Symbol *ps, 63 | intptrj_t offset = 0) : 64 | ::Ruby::SymbolReferenceConnector(symRefTab, 65 | number, 66 | ps, 67 | offset) {} 68 | 69 | SymbolReference(TR::SymbolReferenceTable *symRefTab, 70 | TR::Symbol *sym, 71 | mcount_t owningMethodIndex, 72 | int32_t cpIndex, 73 | int32_t unresolvedIndex = 0) : 74 | ::Ruby::SymbolReferenceConnector(symRefTab, 75 | sym, 76 | owningMethodIndex, 77 | cpIndex, 78 | unresolvedIndex) {} 79 | 80 | SymbolReference(TR::SymbolReferenceTable *symRefTab, 81 | TR::SymbolReference& sr, 82 | intptrj_t offset, 83 | TR::KnownObjectTable::Index knownObjectIndex = TR::KnownObjectTable::UNKNOWN) : 84 | ::Ruby::SymbolReferenceConnector(symRefTab, 85 | sr, 86 | offset, 87 | knownObjectIndex) {} 88 | 89 | protected: 90 | 91 | SymbolReference(TR::SymbolReferenceTable * symRefTab, 92 | TR::Symbol * symbol, 93 | intptrj_t offset, 94 | const char * name) : 95 | ::Ruby::SymbolReferenceConnector(symRefTab, 96 | symbol, 97 | offset, 98 | name) {} 99 | 100 | }; 101 | 102 | } 103 | 104 | #endif 105 | -------------------------------------------------------------------------------- /ruby/ilgen/.RubyIlGenerator.cpp.swp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rubyomr-preview/rbjitglue/3eeacb8d343d8f8067bb77d8cfac4a18877e0d95/ruby/ilgen/.RubyIlGenerator.cpp.swp -------------------------------------------------------------------------------- /ruby/ilgen/.RubyIlGenerator.hpp.swp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rubyomr-preview/rbjitglue/3eeacb8d343d8f8067bb77d8cfac4a18877e0d95/ruby/ilgen/.RubyIlGenerator.hpp.swp -------------------------------------------------------------------------------- /ruby/ilgen/IlGeneratorMethodDetails.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * (c) Copyright IBM Corp. 2000, 2016 4 | * 5 | * This program and the accompanying materials are made available 6 | * under the terms of the Eclipse Public License v1.0 and 7 | * Apache License v2.0 which accompanies this distribution. 8 | * 9 | * The Eclipse Public License is available at 10 | * http://www.eclipse.org/legal/epl-v10.html 11 | * 12 | * The Apache License v2.0 is available at 13 | * http://www.opensource.org/licenses/apache2.0.php 14 | * 15 | * Contributors: 16 | * Multiple authors (IBM Corp.) - initial implementation and documentation 17 | *******************************************************************************/ 18 | 19 | #ifndef TR_ILGENERATOR_METHOD_DETAILS_INCL 20 | #define TR_ILGENERATOR_METHOD_DETAILS_INCL 21 | 22 | #include "infra/Annotations.hpp" 23 | #include "ilgen/RubyIlGeneratorMethodDetails.hpp" 24 | 25 | class ResolvedRubyMethod; 26 | class TR_ResolvedMethod; 27 | 28 | 29 | namespace TR 30 | { 31 | 32 | class OMR_EXTENSIBLE IlGeneratorMethodDetails : public Ruby::IlGeneratorMethodDetailsConnector 33 | { 34 | 35 | public: 36 | 37 | IlGeneratorMethodDetails() : 38 | Ruby::IlGeneratorMethodDetailsConnector() {} 39 | 40 | IlGeneratorMethodDetails(ResolvedRubyMethod *method) : 41 | Ruby::IlGeneratorMethodDetailsConnector(method) {} 42 | 43 | IlGeneratorMethodDetails(TR_ResolvedMethod *method) : 44 | Ruby::IlGeneratorMethodDetailsConnector(method) {} 45 | }; 46 | } 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /ruby/ilgen/RubyByteCodeIterator.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * (c) Copyright IBM Corp. 2000, 2016 4 | * 5 | * This program and the accompanying materials are made available 6 | * under the terms of the Eclipse Public License v1.0 and 7 | * Apache License v2.0 which accompanies this distribution. 8 | * 9 | * The Eclipse Public License is available at 10 | * http://www.eclipse.org/legal/epl-v10.html 11 | * 12 | * The Apache License v2.0 is available at 13 | * http://www.opensource.org/licenses/apache2.0.php 14 | * 15 | * Contributors: 16 | * Multiple authors (IBM Corp.) - initial implementation and documentation 17 | *******************************************************************************/ 18 | 19 | #ifndef RUBYBYTECODEITERATOR_HPP 20 | #define RUBYBYTECODEITERATOR_HPP 21 | 22 | #include "ilgen/ByteCodeIterator.hpp" 23 | #include "ruby/env/RubyFE.hpp" 24 | #include "ruby/env/RubyMethod.hpp" 25 | #include "il/Symbol.hpp" 26 | #include "il/symbol/LabelSymbol.hpp" 27 | #include "il/symbol/MethodSymbol.hpp" 28 | #include "il/symbol/ResolvedMethodSymbol.hpp" 29 | #include "il/symbol/RegisterMappedSymbol.hpp" 30 | #include "il/symbol/StaticSymbol.hpp" 31 | 32 | /* Ruby */ 33 | #include "ruby.h" 34 | #include "vm_core.h" 35 | #include "vm_exec.h" 36 | #include "insns.inc" 37 | #include "iseq.h" 38 | 39 | 40 | typedef VALUE RubyByteCode; 41 | 42 | class TR_RubyByteCodeIterator : public TR_ByteCodeIterator 43 | { 44 | public: 45 | typedef TR_ByteCodeIterator Base; 46 | 47 | TR_RubyByteCodeIterator(TR::ResolvedMethodSymbol *methodSymbol, TR::Compilation *comp) 48 | : Base(methodSymbol, 49 | static_cast(methodSymbol->getResolvedMethod()), 50 | comp), 51 | _fe(TR_RubyFE::instance()) 52 | {} 53 | 54 | RubyByteCode first() { _bcIndex = 0; return current(); } 55 | RubyByteCode next(); 56 | RubyByteCode current() const { return (_bcIndex >= _maxByteCodeIndex) ? VM_INSTRUCTION_SIZE : at(_bcIndex); } 57 | 58 | protected: 59 | 60 | TR_RubyFE *fe() const { return _fe; } 61 | RubyMethodBlock &mb() const { return method()->getRubyMethodBlock(); } 62 | 63 | RubyByteCode at (int32_t index) const; 64 | int32_t byteCodeLength(RubyByteCode bc) const; 65 | const char *operandTypes (RubyByteCode bc) const; 66 | const char *byteCodeName (RubyByteCode bc) const; 67 | 68 | VALUE getOperand(int32_t op) const { return at(_bcIndex + op); } 69 | 70 | bool isBranch() const 71 | { VALUE insn = current(); return 72 | insn == BIN(jump) || 73 | insn == BIN(branchif) || 74 | insn == BIN(branchunless) || 75 | insn == BIN(getinlinecache); } 76 | int32_t branchDestination(int32_t base) const; 77 | 78 | void printByteCodePrologue(); 79 | void printByteCode(); 80 | void printByteCodeEpilogue(); 81 | 82 | void printLocalTables() const; 83 | void printLocalTable(rb_iseq_t const *iseq, int32_t const level) const; 84 | void printCatchTable(rb_iseq_t const *iseq, int32_t const level) const; 85 | void printArgsTable(rb_iseq_t const *iseq) const; 86 | 87 | char const *getLocalName(lindex_t index, const rb_iseq_t *iseq) const; 88 | char const *getLocalName(lindex_t index, rb_num_t level) const 89 | { return getLocalName(index, getParentIseq(level)); } 90 | 91 | rb_iseq_t const *getParentIseq(rb_num_t level) const; 92 | 93 | private: 94 | RubyByteCode const * bytecodes() const { return mb().bytecodes(); } 95 | 96 | TR_RubyFE * const _fe; 97 | }; 98 | 99 | const char* catch_type(iseq_catch_table_entry::catch_type t); 100 | #endif 101 | -------------------------------------------------------------------------------- /ruby/ilgen/RubyByteCodeIteratorWithState.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * (c) Copyright IBM Corp. 2000, 2016 4 | * 5 | * This program and the accompanying materials are made available 6 | * under the terms of the Eclipse Public License v1.0 and 7 | * Apache License v2.0 which accompanies this distribution. 8 | * 9 | * The Eclipse Public License is available at 10 | * http://www.eclipse.org/legal/epl-v10.html 11 | * 12 | * The Apache License v2.0 is available at 13 | * http://www.opensource.org/licenses/apache2.0.php 14 | * 15 | * Contributors: 16 | * Multiple authors (IBM Corp.) - initial implementation and documentation 17 | *******************************************************************************/ 18 | 19 | #ifndef RUBYBYTECODEITERATORWITHSTATE_HPP 20 | #define RUBYBYTECODEITERATORWITHSTATE_HPP 21 | 22 | #include "ilgen/RubyByteCodeIterator.hpp" 23 | #include "ilgen/ByteCodeIteratorWithState.hpp" 24 | 25 | class TR_RubyByteCodeIteratorWithState : 26 | public TR_ByteCodeIteratorWithState 28 | { 29 | public: 30 | typedef TR_ByteCodeIteratorWithState Base; 32 | 33 | TR_RubyByteCodeIteratorWithState(TR::ResolvedMethodSymbol *methodSymbol, TR_RubyFE *fe) 34 | : Base(methodSymbol, TR::comp()) 35 | { } 36 | 37 | protected: 38 | virtual void findAndMarkExceptionRanges(); 39 | }; 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /ruby/ilgen/RubyIlGeneratorMethodDetails.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * (c) Copyright IBM Corp. 2000, 2016 4 | * 5 | * This program and the accompanying materials are made available 6 | * under the terms of the Eclipse Public License v1.0 and 7 | * Apache License v2.0 which accompanies this distribution. 8 | * 9 | * The Eclipse Public License is available at 10 | * http://www.eclipse.org/legal/epl-v10.html 11 | * 12 | * The Apache License v2.0 is available at 13 | * http://www.opensource.org/licenses/apache2.0.php 14 | * 15 | * Contributors: 16 | * Multiple authors (IBM Corp.) - initial implementation and documentation 17 | *******************************************************************************/ 18 | 19 | #include "codegen/FrontEnd.hpp" 20 | #include "ilgen/IlGeneratorMethodDetails_inlines.hpp" 21 | #include "ruby/env/RubyMethod.hpp" 22 | #include "ruby/ilgen/RubyIlGenerator.hpp" 23 | #include "compile/ResolvedMethod.hpp" 24 | #include "compile/InlineBlock.hpp" 25 | #include "env/IO.hpp" 26 | 27 | 28 | Ruby::IlGeneratorMethodDetails::IlGeneratorMethodDetails(TR_ResolvedMethod *method) : 29 | _method(static_cast(method)) 30 | { 31 | } 32 | 33 | 34 | TR_IlGenerator * 35 | Ruby::IlGeneratorMethodDetails::getIlGenerator( 36 | TR::ResolvedMethodSymbol *methodSymbol, 37 | TR_FrontEnd * fe, 38 | TR::Compilation *comp, 39 | TR::SymbolReferenceTable *symRefTab, 40 | bool forceClassLookahead, 41 | TR_InlineBlocks *blocksToInline) 42 | { 43 | TR_ASSERT(forceClassLookahead == false, "RubyIlGenerator does not support class lookahead"); 44 | TR_ASSERT(blocksToInline == 0, "RubyIlGenerator does not yet support partial inlining"); 45 | 46 | return new (comp->trHeapMemory()) RubyIlGenerator(*(self()), 47 | methodSymbol, 48 | static_cast(fe), 49 | *symRefTab); 50 | } 51 | 52 | 53 | void 54 | Ruby::IlGeneratorMethodDetails::print(TR_FrontEnd *fe, TR::FILE *file) 55 | { 56 | if (file == NULL) 57 | return; 58 | 59 | trfprintf(file, "( %p )", self()->getMethod()); 60 | } 61 | 62 | 63 | bool 64 | Ruby::IlGeneratorMethodDetails::sameAs(TR::IlGeneratorMethodDetails & other, TR_FrontEnd *fe) 65 | { 66 | return self()->getMethod() == other.getMethod(); 67 | } 68 | 69 | -------------------------------------------------------------------------------- /ruby/ilgen/RubyIlGeneratorMethodDetails.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * (c) Copyright IBM Corp. 2000, 2016 4 | * 5 | * This program and the accompanying materials are made available 6 | * under the terms of the Eclipse Public License v1.0 and 7 | * Apache License v2.0 which accompanies this distribution. 8 | * 9 | * The Eclipse Public License is available at 10 | * http://www.eclipse.org/legal/epl-v10.html 11 | * 12 | * The Apache License v2.0 is available at 13 | * http://www.opensource.org/licenses/apache2.0.php 14 | * 15 | * Contributors: 16 | * Multiple authors (IBM Corp.) - initial implementation and documentation 17 | *******************************************************************************/ 18 | 19 | 20 | #ifndef RUBY_ILGENERATOR_METHOD_DETAILS_INCL 21 | #define RUBY_ILGENERATOR_METHOD_DETAILS_INCL 22 | 23 | /* 24 | * The following #define and typedef must appear before any #includes in this file 25 | */ 26 | #ifndef RUBY_ILGENERATOR_METHOD_DETAILS_CONNECTOR 27 | #define RUBY_ILGENERATOR_METHOD_DETAILS_CONNECTOR 28 | namespace Ruby { class IlGeneratorMethodDetails; } 29 | namespace Ruby { typedef Ruby::IlGeneratorMethodDetails IlGeneratorMethodDetailsConnector; } 30 | #endif 31 | 32 | #include "ilgen/OMRIlGeneratorMethodDetails.hpp" 33 | 34 | #include "infra/Annotations.hpp" 35 | #include "env/IO.hpp" 36 | 37 | class ResolvedRubyMethod; 38 | class TR_ResolvedMethod; 39 | class TR_IlGenerator; 40 | class TR_InlineBlocks; 41 | namespace TR { class ResolvedMethodSymbol; } 42 | namespace TR { class SymbolReferenceTable; } 43 | 44 | namespace Ruby 45 | { 46 | 47 | class OMR_EXTENSIBLE IlGeneratorMethodDetails : public OMR::IlGeneratorMethodDetailsConnector 48 | { 49 | 50 | public: 51 | 52 | IlGeneratorMethodDetails() : _method(NULL) { } 53 | 54 | IlGeneratorMethodDetails(ResolvedRubyMethod *method) : _method(method) { } 55 | 56 | IlGeneratorMethodDetails(TR_ResolvedMethod *method); 57 | 58 | ResolvedRubyMethod * getMethod() { return _method; } 59 | 60 | bool sameAs(TR::IlGeneratorMethodDetails & other, TR_FrontEnd *fe); 61 | 62 | void print(TR_FrontEnd *fe, TR::FILE *file); 63 | 64 | virtual TR_IlGenerator *getIlGenerator(TR::ResolvedMethodSymbol *methodSymbol, 65 | TR_FrontEnd * fe, 66 | TR::Compilation *comp, 67 | TR::SymbolReferenceTable *symRefTab, 68 | bool forceClassLookahead, 69 | TR_InlineBlocks *blocksToInline); 70 | 71 | protected: 72 | 73 | ResolvedRubyMethod * _method; 74 | }; 75 | 76 | } 77 | 78 | #endif 79 | -------------------------------------------------------------------------------- /ruby/infra/Monitor.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * (c) Copyright IBM Corp. 2000, 2016 4 | * 5 | * This program and the accompanying materials are made available 6 | * under the terms of the Eclipse Public License v1.0 and 7 | * Apache License v2.0 which accompanies this distribution. 8 | * 9 | * The Eclipse Public License is available at 10 | * http://www.eclipse.org/legal/epl-v10.html 11 | * 12 | * The Apache License v2.0 is available at 13 | * http://www.opensource.org/licenses/apache2.0.php 14 | * 15 | * Contributors: 16 | * Multiple authors (IBM Corp.) - initial implementation and documentation 17 | *******************************************************************************/ 18 | 19 | #ifndef TR_MONITOR_INCL 20 | #define TR_MONITOR_INCL 21 | 22 | #include "infra/RubyMonitor.hpp" 23 | 24 | namespace TR 25 | { 26 | 27 | class Monitor : public ::Ruby::MonitorConnector 28 | { 29 | public: 30 | 31 | Monitor(char const *name) : 32 | Ruby::MonitorConnector(name) {} 33 | }; 34 | } 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /ruby/infra/RubyMonitor.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * (c) Copyright IBM Corp. 2000, 2016 4 | * 5 | * This program and the accompanying materials are made available 6 | * under the terms of the Eclipse Public License v1.0 and 7 | * Apache License v2.0 which accompanies this distribution. 8 | * 9 | * The Eclipse Public License is available at 10 | * http://www.eclipse.org/legal/epl-v10.html 11 | * 12 | * The Apache License v2.0 is available at 13 | * http://www.opensource.org/licenses/apache2.0.php 14 | * 15 | * Contributors: 16 | * Multiple authors (IBM Corp.) - initial implementation and documentation 17 | *******************************************************************************/ 18 | 19 | #include "infra/RubyMonitor.hpp" 20 | 21 | #include 22 | #include "env/TRMemory.hpp" 23 | #include "infra/Assert.hpp" 24 | #include "infra/Monitor.hpp" 25 | #include "infra/MonitorTable.hpp" 26 | 27 | // We don't currently use a monitor table, but we still have to declare these statics 28 | TR::MonitorTable *OMR::MonitorTable::_instance = 0; 29 | 30 | TR::Monitor *memoryAllocMonitor; 31 | 32 | void * 33 | Ruby::Monitor::operator new(size_t size) 34 | { 35 | return TR::globalAllocator().allocate(size); 36 | } 37 | 38 | void 39 | Ruby::Monitor::operator delete(void *p) 40 | { 41 | TR::globalAllocator().deallocate(p, sizeof(TR::Monitor)); 42 | } 43 | 44 | TR::Monitor * 45 | Ruby::Monitor::create(char *name) 46 | { 47 | return new TR::Monitor(name); 48 | } 49 | 50 | Ruby::Monitor::Monitor(char const *name) : 51 | _name(name) 52 | { 53 | int32_t rc = pthread_mutex_init(&_monitor, 0); 54 | TR_ASSERT(rc == 0, "error initializing monitor\n"); 55 | } 56 | 57 | Ruby::Monitor::~Monitor() 58 | { 59 | int32_t rc = pthread_mutex_destroy(&_monitor); 60 | TR_ASSERT(rc == 0, "error destroying monitor\n"); 61 | } 62 | 63 | void 64 | Ruby::Monitor::enter() 65 | { 66 | int32_t rc = pthread_mutex_lock(&_monitor); 67 | TR_ASSERT(rc == 0, "error locking monitor\n"); 68 | } 69 | 70 | int32_t 71 | Ruby::Monitor::exit() 72 | { 73 | int32_t rc = pthread_mutex_unlock(&_monitor); 74 | TR_ASSERT(rc == 0, "error unlocking monitor\n"); 75 | return rc; 76 | } 77 | -------------------------------------------------------------------------------- /ruby/infra/RubyMonitor.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * (c) Copyright IBM Corp. 2000, 2016 4 | * 5 | * This program and the accompanying materials are made available 6 | * under the terms of the Eclipse Public License v1.0 and 7 | * Apache License v2.0 which accompanies this distribution. 8 | * 9 | * The Eclipse Public License is available at 10 | * http://www.eclipse.org/legal/epl-v10.html 11 | * 12 | * The Apache License v2.0 is available at 13 | * http://www.opensource.org/licenses/apache2.0.php 14 | * 15 | * Contributors: 16 | * Multiple authors (IBM Corp.) - initial implementation and documentation 17 | *******************************************************************************/ 18 | 19 | #ifndef RUBY_MONITOR_INCL 20 | #define RUBY_MONITOR_INCL 21 | 22 | #ifndef RUBY_MONITOR_CONNECTOR 23 | #define RUBY_MONITOR_CONNECTOR 24 | namespace Ruby { class Monitor; } 25 | namespace Ruby { typedef Ruby::Monitor MonitorConnector; } 26 | #endif 27 | 28 | #include "infra/OMRMonitor.hpp" 29 | 30 | #include 31 | 32 | namespace Ruby 33 | { 34 | 35 | class Monitor : public OMR::MonitorConnector 36 | { 37 | public: 38 | 39 | Monitor(char const *name); 40 | 41 | ~Monitor(); 42 | 43 | static TR::Monitor *create(char *name); 44 | 45 | static void *operator new(size_t size); 46 | 47 | static void operator delete(void *p); 48 | 49 | void enter(); 50 | 51 | int32_t exit(); 52 | 53 | private: 54 | 55 | char const *_name; 56 | pthread_mutex_t _monitor; 57 | }; 58 | 59 | } 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /ruby/linter.mk: -------------------------------------------------------------------------------- 1 | ################################################################################## 2 | # (c) Copyright IBM Corp. 2000, 2016 3 | # 4 | # This program and the accompanying materials are made available 5 | # under the terms of the Eclipse Public License v1.0 and 6 | # Apache License v2.0 which accompanies this distribution. 7 | # 8 | # The Eclipse Public License is available at 9 | # http://www.eclipse.org/legal/epl-v10.html 10 | # 11 | # The Apache License v2.0 is available at 12 | # http://www.opensource.org/licenses/apache2.0.php 13 | # 14 | # Contributors: 15 | # Multiple authors (IBM Corp.) - initial implementation and documentation 16 | ################################################################################## 17 | 18 | # To lint: 19 | # 20 | # PLATFORM=foo-bar-clang make -f linter.mk 21 | # 22 | 23 | .PHONY: linter 24 | linter:: 25 | 26 | # Handy macro to check to make sure variables are set 27 | REQUIRE_VARS=$(foreach VAR,$(1),$(if $($(VAR)),,$(error $(VAR) must be set))) 28 | $(call REQUIRE_VARS,OMR_RUBY_INSTALL) 29 | 30 | ifeq ($(PLATFORM),ppc64-linux64-clangLinter) 31 | export LLVM_CONFIG?=/tr/llvm_checker/ppc-64/sles11/bin/llvm-config 32 | export CC_PATH?=/tr/llvm_checker/ppc-64/sles11/bin/clang 33 | export CXX_PATH?=/tr/llvm_checker/ppc-64/sles11/bin/clang++ 34 | else 35 | #default paths, unless overriden 36 | export LLVM_CONFIG?=llvm-config 37 | export CC_PATH?=clang 38 | export CXX_PATH?=clang++ 39 | endif 40 | 41 | # 42 | # First setup some important paths 43 | # Personally, I feel it's best to default to out-of-tree build but who knows, there may be 44 | # differing opinions on that. 45 | # 46 | JIT_SRCBASE?=.. 47 | JIT_OBJBASE?=../objs/ruby_$(BUILD_CONFIG) 48 | JIT_DLL_DIR?=$(JIT_OBJBASE) 49 | 50 | # 51 | # Windows users will likely use backslashes, but Make tends to not like that so much 52 | # 53 | FIXED_SRCBASE=$(subst \,/,$(JIT_SRCBASE)) 54 | FIXED_OBJBASE=$(subst \,/,$(JIT_OBJBASE)) 55 | FIXED_DLL_DIR=$(subst \,/,$(JIT_DLL_DIR)) 56 | 57 | # TODO - "debug" as default? 58 | BUILD_CONFIG?=prod 59 | 60 | # 61 | # This is where we setup our component dirs 62 | # Note these are all relative to JIT_SRCBASE and JIT_OBJBASE 63 | # It just makes sense since source and build dirs may be in different places 64 | # in the filesystem :) 65 | # 66 | JIT_OMR_DIRTY_DIR?=omr/compiler 67 | JIT_PRODUCT_DIR?=ruby 68 | 69 | # 70 | # Dirs used internally by the makefiles 71 | # 72 | JIT_MAKE_DIR?=$(FIXED_SRCBASE)/ruby/build 73 | JIT_SCRIPT_DIR?=$(FIXED_SRCBASE)/ruby/build/scripts 74 | 75 | # 76 | # First we set a bunch of tokens about the platform that the rest of the 77 | # makefile will use as conditionals 78 | # 79 | include $(JIT_MAKE_DIR)/platform/common.mk 80 | 81 | # 82 | # Now we include the names of all the files that will go into building the JIT 83 | # Will automatically include files needed from HOST and TARGET platform 84 | # 85 | include $(JIT_MAKE_DIR)/files/common.mk 86 | 87 | # 88 | # Now we configure all the tooling we will use to build the files 89 | # 90 | # There is quite a bit of shared stuff, but the overwhelming majority of this 91 | # is toolchain-dependent. 92 | # 93 | # That makes sense - You can't expect XLC and GCC to take the same arguments 94 | # 95 | include $(JIT_MAKE_DIR)/toolcfg/common.mk 96 | 97 | 98 | # 99 | # Add OMRChecker targets 100 | # 101 | # This likely ought to be using the OMRChecker fragment that 102 | # exists in that repo, but in the mean time, this is fine. 103 | # 104 | 105 | OMRCHECKER_DIR?=$(JIT_SRCBASE)/omr/tools/compiler/OMRChecker 106 | 107 | OMRCHECKER_OBJECT=$(OMRCHECKER_DIR)/OMRChecker.so 108 | 109 | OMRCHECKER_LDFLAGS=`$(LLVM_CONFIG) --ldflags` 110 | OMRCHECKER_CXXFLAGS=`$(LLVM_CONFIG) --cxxflags` 111 | 112 | $(OMRCHECKER_OBJECT): 113 | cd $(OMRCHECKER_DIR); sh smartmake.sh 114 | 115 | .PHONY: omrchecker omrchecker_test omrchecker_clean omrchecker_cleandll omrchecker_cleanall 116 | omrchecker: $(OMRCHECKER_OBJECT) 117 | 118 | omrchecker_test: $(OMRCHECKER_OBJECT) 119 | cd $(OMRCHECKER_DIR); make test 120 | 121 | omrchecker_clean: 122 | cd $(OMRCHECKER_DIR); make clean 123 | 124 | omrchecker_cleandll: 125 | cd $(OMRCHECKER_DIR); make cleandll 126 | 127 | omrchecker_cleanall: 128 | cd $(OMRCHECKER_DIR); make cleanall 129 | 130 | 131 | # The core linter bits. 132 | # 133 | # linter:: is the default target, and we construct a pre-req for each 134 | # .cpp file. 135 | # 136 | linter:: omrchecker 137 | 138 | 139 | # The clang invocation magic line. 140 | LINTER_EXTRA=-Xclang -load -Xclang $(OMRCHECKER_OBJECT) -Xclang -add-plugin -Xclang omr-checker 141 | LINTER_FLAGS=-std=c++0x -w -fsyntax-only -ferror-limit=0 $(LINTER_FLAGS_EXTRA) 142 | 143 | define DEF_RULE.linter 144 | .PHONY: $(1).linted 145 | 146 | $(1).linted: $(1) omrchecker 147 | $$(CXX_CMD) $(LINTER_FLAGS) $(LINTER_EXTRA) $$(patsubst %,-D%,$$(CXX_DEFINES)) $$(patsubst %,-I'%',$$(CXX_INCLUDES)) -o $$@ -c $$< 148 | 149 | linter:: $(1).linted 150 | 151 | endef # DEF_RULE.linter 152 | 153 | RULE.linter=$(eval $(DEF_RULE.linter)) 154 | 155 | # The list of sources. 156 | JIT_CPP_FILES=$(filter %.cpp,$(JIT_PRODUCT_SOURCE_FILES) $(JIT_PRODUCT_BACKEND_SOURCES)) 157 | 158 | # Construct lint dependencies. 159 | $(foreach SRCFILE,$(JIT_CPP_FILES),\ 160 | $(call RULE.linter,$(FIXED_SRCBASE)/$(SRCFILE))) 161 | 162 | -------------------------------------------------------------------------------- /ruby/optimizer/OptimizationManager.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * (c) Copyright IBM Corp. 2000, 2016 4 | * 5 | * This program and the accompanying materials are made available 6 | * under the terms of the Eclipse Public License v1.0 and 7 | * Apache License v2.0 which accompanies this distribution. 8 | * 9 | * The Eclipse Public License is available at 10 | * http://www.eclipse.org/legal/epl-v10.html 11 | * 12 | * The Apache License v2.0 is available at 13 | * http://www.opensource.org/licenses/apache2.0.php 14 | * 15 | * Contributors: 16 | * Multiple authors (IBM Corp.) - initial implementation and documentation 17 | *******************************************************************************/ 18 | 19 | 20 | #ifndef TR_OPTIMIZATIONMANAGER_INCL 21 | #define TR_OPTIMIZATIONMANAGER_INCL 22 | 23 | #include "optimizer/RubyOptimizationManager.hpp" 24 | 25 | namespace TR 26 | { 27 | 28 | class OMR_EXTENSIBLE OptimizationManager : public ::Ruby::OptimizationManagerConnector 29 | { 30 | public: 31 | 32 | OptimizationManager(TR::Optimizer *o, OptimizationFactory factory, OMR::Optimizations optNum, const char *optDetailString, const OptimizationStrategy *groupOfOpts = NULL) : 33 | ::Ruby::OptimizationManagerConnector(o, factory, optNum, optDetailString, groupOfOpts) {} 34 | }; 35 | 36 | } 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /ruby/optimizer/Optimizer.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * (c) Copyright IBM Corp. 2000, 2016 4 | * 5 | * This program and the accompanying materials are made available 6 | * under the terms of the Eclipse Public License v1.0 and 7 | * Apache License v2.0 which accompanies this distribution. 8 | * 9 | * The Eclipse Public License is available at 10 | * http://www.eclipse.org/legal/epl-v10.html 11 | * 12 | * The Apache License v2.0 is available at 13 | * http://www.opensource.org/licenses/apache2.0.php 14 | * 15 | * Contributors: 16 | * Multiple authors (IBM Corp.) - initial implementation and documentation 17 | *******************************************************************************/ 18 | 19 | //On zOS XLC linker can't handle files with same name at link time 20 | //This workaround with pragma is needed. What this does is essentially 21 | //give a different name to the codesection (csect) for this file. So it 22 | //doesn't conflict with another file with same name. 23 | #pragma csect(CODE,"RubyOptimizer#C") 24 | #pragma csect(STATIC,"RubyOptimizer#S") 25 | #pragma csect(TEST,"RubyOptimizer#T") 26 | 27 | #include "optimizer/Optimizer.hpp" 28 | #include "optimizer/GlobalRegisterAllocator.hpp" 29 | #include "optimizer/IsolatedStoreElimination.hpp" 30 | #include "optimizer/LocalOpts.hpp" 31 | #include "optimizer/RubyIlFastpather.hpp" 32 | #include "optimizer/RubyLowerMacroOps.hpp" 33 | #include "optimizer/RubyTrivialInliner.hpp" 34 | #include "optimizer/RubyInliner.hpp" 35 | #include "il/Node.hpp" 36 | #include "il/Node_inlines.hpp" 37 | 38 | 39 | // ********************************************************** 40 | // 41 | // Ruby Strategies 42 | // 43 | // ********************************************************** 44 | 45 | static const OptimizationStrategy rubyCheapTacticalGlobalRegisterAllocatorOpts[] = 46 | { 47 | { OMR::redundantGotoElimination, OMR::IfNotProfiling }, // need to be run before global register allocator 48 | { OMR::lowerRubyMacroOps, OMR::MustBeDone }, // Also must be done before GRA, to break asyncheck blocks 49 | { OMR::tacticalGlobalRegisterAllocator }, 50 | { OMR::endGroup } 51 | }; 52 | 53 | static const OptimizationStrategy rubyNoOptStrategyOpts[] = 54 | { 55 | { OMR::lowerRubyMacroOps, OMR::MustBeDone }, 56 | { OMR::endOpts }, 57 | }; 58 | 59 | static const OptimizationStrategy rubyColdStrategyOpts[] = 60 | { 61 | { OMR::trivialInlining }, 62 | { OMR::rubyIlFastpather }, 63 | { OMR::basicBlockExtension }, 64 | { OMR::localCSE }, 65 | { OMR::treeSimplification }, 66 | { OMR::localCSE }, 67 | { OMR::localDeadStoreElimination }, 68 | { OMR::globalDeadStoreGroup }, 69 | { OMR::isolatedStoreGroup }, 70 | { OMR::deadTreesElimination }, 71 | { OMR::cheapTacticalGlobalRegisterAllocatorGroup }, 72 | { OMR::lowerRubyMacroOps, OMR::MustBeDone }, 73 | { OMR::endOpts }, 74 | }; 75 | 76 | static const OptimizationStrategy rubyWarmStrategyOpts[] = 77 | { 78 | //{ rubyIlFastpather }, 79 | { OMR::basicBlockExtension }, 80 | { OMR::localCSE }, 81 | { OMR::treeSimplification }, 82 | { OMR::localCSE }, 83 | { OMR::localDeadStoreElimination }, 84 | { OMR::globalDeadStoreGroup }, 85 | { OMR::isolatedStoreGroup }, 86 | { OMR::deadTreesElimination }, 87 | { OMR::cheapTacticalGlobalRegisterAllocatorGroup }, 88 | { OMR::lowerRubyMacroOps, OMR::MustBeDone }, 89 | { OMR::endOpts }, 90 | }; 91 | 92 | const OptimizationStrategy *rubyCompilationStrategies[] = 93 | { 94 | rubyNoOptStrategyOpts,// only must-be-done opts 95 | rubyColdStrategyOpts, // << specialized 96 | rubyWarmStrategyOpts, // << specialized 97 | }; 98 | 99 | 100 | const OptimizationStrategy * 101 | Ruby::Optimizer::optimizationStrategy(TR::Compilation *c) 102 | { 103 | TR_Hotness strategy = c->getMethodHotness(); 104 | TR_ASSERT(strategy <= lastRubyStrategy, "Invalid optimization strategy"); 105 | 106 | // Downgrade strategy rather than crashing in prod. 107 | if (strategy > lastRubyStrategy) 108 | strategy = lastRubyStrategy; 109 | 110 | return rubyCompilationStrategies[strategy]; 111 | } 112 | 113 | 114 | Ruby::Optimizer::Optimizer(TR::Compilation *comp, TR::ResolvedMethodSymbol *methodSymbol, bool isIlGen, 115 | const OptimizationStrategy *strategy, uint16_t VNType) 116 | : OMR::Optimizer(comp, methodSymbol, isIlGen, strategy, VNType) 117 | { 118 | // initialize additional Ruby optimizations 119 | _opts[OMR::isolatedStoreElimination] = 120 | new (comp->allocator()) TR::OptimizationManager(self(), TR_IsolatedStoreElimination::create, OMR::isolatedStoreElimination, "O^O ISOLATED STORE ELIMINATION: "); 121 | _opts[OMR::redundantGotoElimination] = 122 | new (comp->allocator()) TR::OptimizationManager(self(), TR_EliminateRedundantGotos::create, OMR::redundantGotoElimination, "O^O GOTO ELIMINATION: "); 123 | _opts[OMR::tacticalGlobalRegisterAllocator] = 124 | new (comp->allocator()) TR::OptimizationManager(self(), TR_GlobalRegisterAllocator::create, OMR::tacticalGlobalRegisterAllocator, "O^O GLOBAL REGISTER ASSIGNER: "); 125 | 126 | // NOTE: Please add new Ruby optimizations here! 127 | // 128 | _opts[OMR::rubyIlFastpather] = 129 | new (comp->allocator()) TR::OptimizationManager(self(), Ruby::IlFastpather::create, OMR::rubyIlFastpather, "O^O RUBY IL FASTPATHER"); 130 | 131 | _opts[OMR::lowerRubyMacroOps] = 132 | new (comp->allocator()) TR::OptimizationManager(self(), Ruby::LowerMacroOps::create, OMR::lowerRubyMacroOps, "O^O LOWER RUBY MACRO OPS"); 133 | 134 | _opts[OMR::trivialInlining] = 135 | new (comp->allocator()) TR::OptimizationManager(self(), Ruby::TrivialInliner::create, OMR::trivialInlining, "O^O RUBY TRIVIAL INLINER: "); 136 | 137 | // initialize additional Ruby optimization groups 138 | 139 | _opts[OMR::isolatedStoreGroup] = 140 | new (comp->allocator()) TR::OptimizationManager(self(), NULL, OMR::isolatedStoreGroup, "", isolatedStoreOpts); 141 | 142 | _opts[OMR::cheapTacticalGlobalRegisterAllocatorGroup] = 143 | new (comp->allocator()) TR::OptimizationManager(self(), NULL, OMR::cheapTacticalGlobalRegisterAllocatorGroup, "", rubyCheapTacticalGlobalRegisterAllocatorOpts); 144 | 145 | // NOTE: Please add new Ruby optimization groups here! 146 | 147 | // turn requested on for optimizations/groups 148 | _opts[OMR::lowerRubyMacroOps]->setRequested(); 149 | 150 | } 151 | 152 | inline 153 | TR::Optimizer *Ruby::Optimizer::self() 154 | { 155 | return (static_cast(this)); 156 | } 157 | 158 | OMR_InlinerUtil *Ruby::Optimizer::getInlinerUtil() 159 | { 160 | return new (comp()->allocator()) Ruby::InlinerUtil(comp()); 161 | } 162 | -------------------------------------------------------------------------------- /ruby/optimizer/Optimizer.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * (c) Copyright IBM Corp. 2000, 2016 4 | * 5 | * This program and the accompanying materials are made available 6 | * under the terms of the Eclipse Public License v1.0 and 7 | * Apache License v2.0 which accompanies this distribution. 8 | * 9 | * The Eclipse Public License is available at 10 | * http://www.eclipse.org/legal/epl-v10.html 11 | * 12 | * The Apache License v2.0 is available at 13 | * http://www.opensource.org/licenses/apache2.0.php 14 | * 15 | * Contributors: 16 | * Multiple authors (IBM Corp.) - initial implementation and documentation 17 | *******************************************************************************/ 18 | 19 | 20 | #ifndef TR_OPTIMIZER_INCL 21 | #define TR_OPTIMIZER_INCL 22 | 23 | #include "optimizer/RubyOptimizer.hpp" 24 | 25 | namespace TR 26 | { 27 | 28 | class Optimizer : public ::Ruby::OptimizerConnector 29 | { 30 | public: 31 | 32 | Optimizer(TR::Compilation *comp, TR::ResolvedMethodSymbol *methodSymbol, bool isIlGen, 33 | const OptimizationStrategy *strategy = NULL, uint16_t VNType = 0) : 34 | ::Ruby::OptimizerConnector(comp, methodSymbol, isIlGen, strategy, VNType) {} 35 | }; 36 | 37 | } 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /ruby/optimizer/RubyCallInfo.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * (c) Copyright IBM Corp. 2000, 2016 4 | * 5 | * This program and the accompanying materials are made available 6 | * under the terms of the Eclipse Public License v1.0 and 7 | * Apache License v2.0 which accompanies this distribution. 8 | * 9 | * The Eclipse Public License is available at 10 | * http://www.eclipse.org/legal/epl-v10.html 11 | * 12 | * The Apache License v2.0 is available at 13 | * http://www.opensource.org/licenses/apache2.0.php 14 | * 15 | * Contributors: 16 | * Multiple authors (IBM Corp.) - initial implementation and documentation 17 | *******************************************************************************/ 18 | 19 | 20 | #include "ruby/optimizer/RubyCallInfo.hpp" 21 | 22 | #include "compile/SymbolReferenceTable.hpp" 23 | #include "il/SymbolReference.hpp" 24 | #include "il/Node_inlines.hpp" 25 | #include "optimizer/Inliner.hpp" 26 | #include "ruby/env/RubyMethod.hpp" 27 | 28 | #ifdef RUBY_PROJECT_SPECIFIC 29 | #include "ruby/config.h" 30 | #endif 31 | 32 | TR_CallSite* TR_CallSite::create(TR::TreeTop* tt, 33 | TR::Node *parent, 34 | TR::Node *node, 35 | TR_OpaqueClassBlock *receiverClass, TR::SymbolReference *symRef, 36 | TR_ResolvedMethod *resolvedMethod, 37 | TR::Compilation* comp, 38 | TR_Memory* trMemory, 39 | TR_AllocationKind kind, 40 | TR_ResolvedMethod* caller, 41 | int32_t depth, 42 | bool allConsts) 43 | { 44 | TR_ResolvedMethod* lCaller = caller ? caller : symRef->getOwningMethod(comp); 45 | if(node->getSymbol()->castToMethodSymbol()->isHelper()) 46 | { 47 | if (node->getSymbolReference() == comp->getSymRefTab()->getSymRef(RubyHelper_vm_send)) 48 | { 49 | return new (trMemory, kind) TR_Ruby_Send_CallSite(lCaller, 50 | tt, 51 | parent, 52 | node, 53 | NULL, 54 | receiverClass, 55 | (int32_t)symRef->getOffset(), 56 | symRef->getCPIndex(), 57 | resolvedMethod, 58 | NULL, 59 | node->getOpCode().isCallIndirect(), 60 | false, 61 | node->getByteCodeInfo(), 62 | comp); 63 | } 64 | else if (node->getSymbolReference() == comp->getSymRefTab()->getSymRef(RubyHelper_vm_invokeblock)) 65 | { 66 | return new (trMemory, kind) TR_Ruby_InvokeBlock_CallSite(lCaller, 67 | tt, 68 | parent, 69 | node, 70 | NULL, 71 | receiverClass, 72 | (int32_t)symRef->getOffset(), 73 | symRef->getCPIndex(), 74 | resolvedMethod, 75 | NULL, 76 | node->getOpCode().isCallIndirect(), 77 | false, 78 | node->getByteCodeInfo(), 79 | comp); 80 | } 81 | else if (node->getSymbolReference() == comp->getSymRefTab()->getSymRef(RubyHelper_vm_send_without_block)) 82 | { 83 | TR_CallSite* callSite = new (trMemory, kind) TR_Ruby_SendSimple_CallSite(lCaller, 84 | tt, 85 | parent, 86 | node, 87 | NULL, 88 | receiverClass, 89 | (int32_t)symRef->getOffset(), 90 | symRef->getCPIndex(), 91 | resolvedMethod, 92 | NULL, 93 | node->getOpCode().isCallIndirect(), 94 | false, 95 | node->getByteCodeInfo(), 96 | comp); 97 | 98 | //Store the receiver in a temporary to be used by TR_InlinerBase::calleeTreeTopPreMergeActions. 99 | //VirtualGuard splits the block up so we cannot directly reference the receiver from the callNode 100 | //without BlockVerfier triggering an assertion on it. 101 | //DeadStoreElimination should get rid of this temp if nobody uses it. 102 | TR::Node *receiver = node->getThirdChild(); 103 | TR::SymbolReference *receiverTemp = TR::Node::storeToTemp(receiver, tt); 104 | comp->getSymRefTab()->setRubyInlinedReceiverTempSymRef(callSite, receiverTemp); 105 | 106 | return callSite; 107 | } 108 | } 109 | 110 | //For everything else. 111 | return new (trMemory, kind) TR_RubyCallSite(lCaller, 112 | tt, 113 | parent, 114 | node, 115 | NULL, 116 | receiverClass, 117 | (int32_t)symRef->getOffset(), 118 | symRef->getCPIndex(), 119 | resolvedMethod, 120 | NULL, 121 | node->getOpCode().isCallIndirect(), 122 | false, 123 | node->getByteCodeInfo(), 124 | comp); 125 | } 126 | 127 | bool 128 | TR_RubyCallSite::findCallSiteTarget (TR_CallStack* callStack, TR_InlinerBase* inliner) 129 | { 130 | //No targets to add, don't know which type of call this is. 131 | return false; 132 | } 133 | 134 | bool 135 | TR_Ruby_Send_CallSite::findCallSiteTarget (TR_CallStack* callStack, TR_InlinerBase* inliner) 136 | { 137 | return false; 138 | } 139 | 140 | bool 141 | TR_Ruby_InvokeBlock_CallSite::findCallSiteTarget (TR_CallStack* callStack, TR_InlinerBase* inliner) 142 | { 143 | return false; 144 | } 145 | 146 | bool 147 | TR_Ruby_SendSimple_CallSite::findCallSiteTarget (TR_CallStack* callStack, TR_InlinerBase* inliner) 148 | { 149 | //Landing here implies TR_RubyFE::checkInlineableWithoutInitialCalleeSymbol did all the checks and 150 | //decided this callSite was a valid inlineable target. 151 | 152 | TR::Node* node = _callNode; 153 | 154 | //Ensure that ILGen hasn't changed the children's layout we expect. 155 | TR_ASSERT( ((node->getNumChildren() == 3) && 156 | node->getSecondChild() && 157 | node->getSecondChild()->getOpCodeValue() == TR::aconst), "Unexpected children in hierarchy of vm_send_without_block when creating callsite target."); 158 | 159 | rb_call_info_t *ci = (rb_call_info_t *) node->getSecondChild()->getAddress(); 160 | #ifdef OMR_JIT_PROFILING 161 | VALUE klass = ci->profiled_klass; 162 | #else 163 | VALUE klass = Qundef; 164 | #endif 165 | VALUE actual_klass; 166 | rb_method_entry_t *me = (rb_method_entry_t*)TR_RubyFE::instance()->getJitInterface()->callbacks.rb_method_entry_f(klass, ci->mid, &actual_klass); 167 | rb_iseq_t *iseq_callee = me->def->body.iseq; 168 | 169 | int32_t len = 170 | RSTRING_LEN(iseq_callee->location.path) + 171 | (sizeof(size_t) * 3) + // first_lineno: estimate three decimal digits per byte 172 | RSTRING_LEN(iseq_callee->location.label) + 173 | 3; // two colons and a null terminator 174 | 175 | char *name = (char*) comp()->trMemory()->allocateHeapMemory(len); 176 | sprintf(name, "%s:%lld:%s", 177 | (char*) RSTRING_PTR(iseq_callee->location.path), 178 | FIX2LONG(iseq_callee->location.first_lineno), 179 | (char*)RSTRING_PTR(iseq_callee->location.label)); 180 | 181 | RubyMethodBlock* callee_mb = new (comp()->trPersistentMemory()) RubyMethodBlock(iseq_callee, name); 182 | ResolvedRubyMethod* callee_method = new (comp()->trPersistentMemory()) ResolvedRubyMethod(*callee_mb); 183 | TR::ResolvedMethodSymbol *calleeSymbol = TR::ResolvedMethodSymbol::createJittedMethodSymbol(comp()->trHeapMemory(), callee_method, comp()); 184 | 185 | //Set ResolvedMethod and ResolvedMethodSymbol. 186 | _initialCalleeMethod = callee_method; 187 | _initialCalleeSymbol = calleeSymbol; 188 | 189 | //Add a target for inliner to process. 190 | TR_VirtualGuardSelection *guard = new (comp()->trHeapMemory()) TR_VirtualGuardSelection(TR_ProfiledGuard, TR_RubyInlineTest, (TR_OpaqueClassBlock *) klass); 191 | 192 | //Send out a callTarget 193 | addTarget(comp()->trMemory(), 194 | inliner, 195 | guard, 196 | _initialCalleeMethod, 197 | _initialCalleeMethod->classOfMethod(), 198 | heapAlloc); 199 | return true; 200 | } 201 | -------------------------------------------------------------------------------- /ruby/optimizer/RubyCallInfo.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * (c) Copyright IBM Corp. 2000, 2016 4 | * 5 | * This program and the accompanying materials are made available 6 | * under the terms of the Eclipse Public License v1.0 and 7 | * Apache License v2.0 which accompanies this distribution. 8 | * 9 | * The Eclipse Public License is available at 10 | * http://www.eclipse.org/legal/epl-v10.html 11 | * 12 | * The Apache License v2.0 is available at 13 | * http://www.opensource.org/licenses/apache2.0.php 14 | * 15 | * Contributors: 16 | * Multiple authors (IBM Corp.) - initial implementation and documentation 17 | *******************************************************************************/ 18 | 19 | 20 | #ifndef RUBY_CALLINFO_INCL 21 | #define RUBY_CALLINFO_INCL 22 | 23 | #include "optimizer/CallInfo.hpp" 24 | 25 | class TR_RubyCallSite : public TR_CallSite 26 | { 27 | public: 28 | TR_CALLSITE_INHERIT_CONSTRUCTOR_AND_TR_ALLOC(TR_RubyCallSite, TR_CallSite) 29 | virtual bool findCallSiteTarget (TR_CallStack *callStack, TR_InlinerBase* inliner); 30 | virtual const char* name () { return "TR_RubyCallSite"; } 31 | }; 32 | 33 | class TR_Ruby_Send_CallSite : public TR_RubyCallSite 34 | { 35 | public: 36 | TR_CALLSITE_INHERIT_CONSTRUCTOR_AND_TR_ALLOC(TR_Ruby_Send_CallSite, TR_RubyCallSite) 37 | virtual bool findCallSiteTarget (TR_CallStack *callStack, TR_InlinerBase* inliner); 38 | virtual const char* name () { return "TR_Ruby_VM_Send_CallSite"; } 39 | }; 40 | 41 | class TR_Ruby_SendSimple_CallSite : public TR_RubyCallSite 42 | { 43 | public: 44 | TR_CALLSITE_INHERIT_CONSTRUCTOR_AND_TR_ALLOC(TR_Ruby_SendSimple_CallSite, TR_RubyCallSite) 45 | virtual bool findCallSiteTarget (TR_CallStack *callStack, TR_InlinerBase* inliner); 46 | virtual const char* name () { return "TR_Ruby_VM_SendSimple_CallSite"; } 47 | }; 48 | 49 | class TR_Ruby_InvokeBlock_CallSite : public TR_RubyCallSite 50 | { 51 | public: 52 | TR_CALLSITE_INHERIT_CONSTRUCTOR_AND_TR_ALLOC(TR_Ruby_InvokeBlock_CallSite, TR_RubyCallSite) 53 | virtual bool findCallSiteTarget (TR_CallStack *callStack, TR_InlinerBase* inliner); 54 | virtual const char* name () { return "TR_Ruby_VM_InvokeBlock_CallSite"; } 55 | }; 56 | 57 | #endif /*RUBY_CALLINFO_INCL*/ 58 | -------------------------------------------------------------------------------- /ruby/optimizer/RubyIlFastpather.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * (c) Copyright IBM Corp. 2000, 2016 4 | * 5 | * This program and the accompanying materials are made available 6 | * under the terms of the Eclipse Public License v1.0 and 7 | * Apache License v2.0 which accompanies this distribution. 8 | * 9 | * The Eclipse Public License is available at 10 | * http://www.eclipse.org/legal/epl-v10.html 11 | * 12 | * The Apache License v2.0 is available at 13 | * http://www.opensource.org/licenses/apache2.0.php 14 | * 15 | * Contributors: 16 | * Multiple authors (IBM Corp.) - initial implementation and documentation 17 | *******************************************************************************/ 18 | 19 | 20 | #ifndef RUBYILFASTPATHER_INCL 21 | #define RUBYILFASTPATHER_INCL 22 | 23 | #include "optimizer/Optimization.hpp" 24 | 25 | #include "ruby.h" //VALUE 26 | #include "vm_core.h" // For BOP_MINUS and FIXNUM_REDEFINED_OP_FLAG etc. 27 | #include "vm_insnhelper.h" // For BOP_MINUS and FIXNUM_REDEFINED_OP_FLAG etc. 28 | 29 | 30 | namespace Ruby 31 | { 32 | /** 33 | * Optimization class that modifies IL to fastpath operations from 34 | * the ruby VM implementation. 35 | * 36 | * This optimization must be kept up to date with the RubyVM. 37 | */ 38 | class IlFastpather : public TR::Optimization 39 | { 40 | public: 41 | 42 | IlFastpather(TR::OptimizationManager * manager); 43 | 44 | /** 45 | * Optimization factory method 46 | */ 47 | static TR::Optimization *create(TR::OptimizationManager *manager) 48 | { 49 | return new (manager->allocator()) IlFastpather(manager); 50 | } 51 | 52 | TR::CFG * cfg() { return comp()->getFlowGraph(); } 53 | 54 | virtual int32_t perform(); 55 | virtual bool shouldPerform() { 56 | static auto * disableIlFastpather = feGetEnv("OMR_DISABLE_FASTPATH"); 57 | return !disableIlFastpather; 58 | } 59 | 60 | private: 61 | 62 | void performOnTreeTop(TR::TreeTop *); 63 | void fastpathTrace (TR::TreeTop *, TR::Node *); 64 | 65 | //Fast Pathing 66 | TR::Node *genFixNumTest(TR::Node *); 67 | TR::Node *genRedefinedTest(int32_t, int32_t, TR::TreeTop *); 68 | TR::Node *genTraceTest(TR::Node * flag); 69 | 70 | TR::TreeTop * genTreeTop(TR::Node*, TR::Block*); 71 | 72 | void fastpathPlusMinus(TR::TreeTop *, TR::Node *, bool); 73 | void fastpathGE (TR::TreeTop *, TR::Node *); 74 | 75 | // There is also an implementation of this function inside the pythonFE 76 | // that uses STL containers. We ought to common with that version. 77 | void createMultiDiamond(TR::TreeTop *, TR::Block *, uint32_t, 78 | TR::Block *&, TR::Block *&, TR::Block *&, 79 | CS2::ArrayOf &); 80 | 81 | TR::ILOpCodes getCompareOp(TR::Node *origif); 82 | TR::Node *loadBOPRedefined(int32_t bop); 83 | 84 | 85 | TR::SymbolReference * storeToTempBefore(TR::Node *, TR::TreeTop *); 86 | 87 | }; 88 | 89 | } 90 | 91 | 92 | #endif 93 | -------------------------------------------------------------------------------- /ruby/optimizer/RubyInliner.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * (c) Copyright IBM Corp. 2000, 2016 4 | * 5 | * This program and the accompanying materials are made available 6 | * under the terms of the Eclipse Public License v1.0 and 7 | * Apache License v2.0 which accompanies this distribution. 8 | * 9 | * The Eclipse Public License is available at 10 | * http://www.eclipse.org/legal/epl-v10.html 11 | * 12 | * The Apache License v2.0 is available at 13 | * http://www.opensource.org/licenses/apache2.0.php 14 | * 15 | * Contributors: 16 | * Multiple authors (IBM Corp.) - initial implementation and documentation 17 | *******************************************************************************/ 18 | 19 | 20 | 21 | #ifndef RUBYINLINER_INCL 22 | #define RUBYINLINER_INCL 23 | class OMR_InlinerUtil; 24 | class TR_InlinerBase; 25 | namespace Ruby{ 26 | 27 | class InlinerUtil: public OMR_InlinerUtil 28 | { 29 | friend class TR_InlinerBase; 30 | public: 31 | InlinerUtil(TR::Compilation *comp); 32 | protected: 33 | virtual void calleeTreeTopPreMergeActions(TR::ResolvedMethodSymbol *calleeResolvedMethodSymbol, TR_CallSite* callSite); 34 | }; 35 | 36 | } 37 | #endif 38 | -------------------------------------------------------------------------------- /ruby/optimizer/RubyLowerMacroOps.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * (c) Copyright IBM Corp. 2000, 2016 4 | * 5 | * This program and the accompanying materials are made available 6 | * under the terms of the Eclipse Public License v1.0 and 7 | * Apache License v2.0 which accompanies this distribution. 8 | * 9 | * The Eclipse Public License is available at 10 | * http://www.eclipse.org/legal/epl-v10.html 11 | * 12 | * The Apache License v2.0 is available at 13 | * http://www.opensource.org/licenses/apache2.0.php 14 | * 15 | * Contributors: 16 | * Multiple authors (IBM Corp.) - initial implementation and documentation 17 | *******************************************************************************/ 18 | 19 | 20 | #include "optimizer/RubyLowerMacroOps.hpp" 21 | 22 | #include "il/Node.hpp" 23 | #include "il/Node_inlines.hpp" 24 | #include "il/Block.hpp" 25 | #include "il/TreeTop.hpp" 26 | #include "il/TreeTop_inlines.hpp" 27 | #include "optimizer/Optimization_inlines.hpp" 28 | 29 | #define OPT_DETAILS "O^O RUBYLOWERMACROOPS: " 30 | 31 | Ruby::LowerMacroOps::LowerMacroOps(TR::OptimizationManager *manager) 32 | : TR::Optimization(manager) 33 | {} 34 | 35 | 36 | /** 37 | * Extract some of the semantics of ruby calls into trees, providing a 38 | * fast-path version. 39 | * 40 | * Executes on a treetop basis. 41 | * 42 | */ 43 | int32_t 44 | Ruby::LowerMacroOps::perform() 45 | { 46 | if (trace()) 47 | traceMsg(comp(), OPT_DETAILS "Processing method: %s\n", comp()->signature()); 48 | 49 | auto lastTT = cfg()->findLastTreeTop(); 50 | for (auto tt = comp()->getMethodSymbol()->getFirstTreeTop(); 51 | tt != lastTT; 52 | tt = tt->getNextTreeTop()) 53 | { 54 | lowerTreeTop(tt); 55 | } 56 | 57 | //Disable myself for future calls: 58 | manager()->setRequested(false); 59 | return 0; 60 | } 61 | 62 | /** 63 | * Transform a tree top. 64 | */ 65 | void 66 | Ruby::LowerMacroOps::lowerTreeTop(TR::TreeTop* tt) 67 | { 68 | auto *node = tt->getNode(); 69 | if (node->getOpCodeValue() == TR::treetop) 70 | node = node->getFirstChild(); 71 | 72 | switch (node->getOpCodeValue()) 73 | { 74 | case TR::asynccheck: 75 | lowerAsyncCheck(node, tt); 76 | default: 77 | break; 78 | } 79 | 80 | } 81 | 82 | 83 | TR::Node * 84 | Ruby::LowerMacroOps::pendingInterruptsNode() 85 | { 86 | static auto * irritate_asynccheck = feGetEnv("TR_RUBY_IRRITATE_ASYNCHECK"); 87 | if (irritate_asynccheck == NULL) 88 | { 89 | TR::Node *interrupt_flag = 90 | TR::Node::xloadi(TR::comp()->getSymRefTab()->findOrCreateRubyInterruptFlagSymRef(), 91 | TR::Node::loadThread(comp()->getMethodSymbol()), 92 | fe()); 93 | 94 | TR::Node *not_interrupt_mask = 95 | TR::Node::xnot( 96 | TR::Node::xloadi(TR::comp()->getSymRefTab()->findOrCreateRubyInterruptMaskSymRef(), 97 | TR::Node::loadThread(comp()->getMethodSymbol()), 98 | fe()) 99 | ); 100 | 101 | return TR::Node::xand( 102 | interrupt_flag, 103 | not_interrupt_mask); 104 | } 105 | else 106 | { 107 | // asynccheck irritator: This path can be enabled to make the 108 | // asyncchek behave deterministically in case that helps in isolating 109 | // a bug. 110 | return TR::Node::xconst(1); 111 | } 112 | } 113 | 114 | 115 | /** 116 | * Lower an asynccheck call into a branch and call. 117 | * 118 | * \note We do this here rather than in the lowerTrees call from 119 | * CodeGenPrep.cpp because we would like this done before we run tactical GRA, 120 | * as block splitting after tacticalGRA is difficult. There is precedent in 121 | * doing so, but it involves a bit of non-local analysis. 122 | * 123 | */ 124 | void 125 | Ruby::LowerMacroOps::lowerAsyncCheck(TR::Node *asynccheckNode, TR::TreeTop *asynccheckTree) 126 | { 127 | if (!performTransformation(comp(), "%s Lowering asynccheck (%p)\n", OPT_DETAILS, asynccheckNode)) 128 | { 129 | TR_ASSERT(false, "Disabled asynccheck lowering. This will break in code generation"); 130 | return; 131 | } 132 | 133 | TR::Compilation *comp = TR::comp(); 134 | TR::CFG *cfg = comp->getFlowGraph(); 135 | 136 | cfg->setStructure(0); 137 | 138 | TR::Block *asynccheckBlock = asynccheckTree->getEnclosingBlock(); 139 | TR::Block *remainderBlock = asynccheckBlock->split(asynccheckTree->getNextTreeTop(), cfg, true); 140 | 141 | // Create a call to the asynccheck handler 142 | TR::SymbolReference *callSymRef = asynccheckNode->getSymbolReference(); 143 | 144 | auto threadLoadNode = TR::Node::loadThread(comp->getMethodSymbol()); 145 | auto callNode = TR::Node::create(TR::call, 2, threadLoadNode, TR::Node::iconst(0)); 146 | callNode->setSymbolReference(callSymRef); 147 | auto callTree = TR::TreeTop::create(comp, TR::Node::create(TR::treetop, 1, callNode)); 148 | 149 | TR::Node *valueNode = pendingInterruptsNode(); 150 | TR::DataTypes valueType = valueNode->getDataType(); 151 | TR::Node *constNode = TR::Node::create(asynccheckNode, TR::ILOpCode::constOpCode(valueType), 0); 152 | TR::ILOpCodes op = TR::ILOpCode::ifcmpneOpCode(valueType); 153 | TR::Node *ifNode = TR::Node::createif(op, valueNode, constNode); 154 | TR::TreeTop *ifTree = TR::TreeTop::create(comp, ifNode); 155 | 156 | asynccheckBlock->append(ifTree); 157 | asynccheckNode->removeAllChildren(); 158 | asynccheckTree->getPrevTreeTop()->join(asynccheckTree->getNextTreeTop()); // remove the ac tree 159 | 160 | TR::Block *callBlock = TR::Block::createEmptyBlock(comp, 0); 161 | cfg->addNode(callBlock); 162 | cfg->findLastTreeTop()->join(callBlock->getEntry()); 163 | callBlock->append(callTree); 164 | 165 | TR::Node *gotoNode = TR::Node::create(TR::Goto, 0, remainderBlock->getEntry()); 166 | TR::TreeTop *gotoTree = TR::TreeTop::create(comp, gotoNode); 167 | callBlock->append(gotoTree); 168 | 169 | cfg->addEdge(asynccheckBlock, callBlock); 170 | cfg->addEdge(callBlock, remainderBlock); 171 | 172 | ifNode->setBranchDestination(callBlock->getEntry()); 173 | 174 | return; 175 | } 176 | 177 | -------------------------------------------------------------------------------- /ruby/optimizer/RubyLowerMacroOps.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * (c) Copyright IBM Corp. 2000, 2016 4 | * 5 | * This program and the accompanying materials are made available 6 | * under the terms of the Eclipse Public License v1.0 and 7 | * Apache License v2.0 which accompanies this distribution. 8 | * 9 | * The Eclipse Public License is available at 10 | * http://www.eclipse.org/legal/epl-v10.html 11 | * 12 | * The Apache License v2.0 is available at 13 | * http://www.opensource.org/licenses/apache2.0.php 14 | * 15 | * Contributors: 16 | * Multiple authors (IBM Corp.) - initial implementation and documentation 17 | *******************************************************************************/ 18 | 19 | 20 | #ifndef RUBYLOWERMACROOPS_INCL 21 | #define RUBYLOWERMACROOPS_INCL 22 | 23 | #include "optimizer/Optimization.hpp" 24 | 25 | 26 | namespace Ruby 27 | { 28 | 29 | /** 30 | * Lower Ruby macro ops. 31 | */ 32 | class LowerMacroOps : public TR::Optimization 33 | { 34 | public: 35 | 36 | LowerMacroOps(TR::OptimizationManager *manager); 37 | 38 | /** 39 | * Optimization factory method 40 | */ 41 | static TR::Optimization *create(TR::OptimizationManager *manager) 42 | { 43 | return new (manager->allocator()) LowerMacroOps(manager); 44 | } 45 | 46 | TR::CFG * cfg() { return comp()->getFlowGraph(); } 47 | 48 | virtual int32_t perform(); 49 | 50 | /** 51 | * This opt must happen at least once before codegen, but once it has 52 | * happened once, it needn't happen again. 53 | * 54 | * This opt is therefore set-requested at construction in Ruby::Optimizer, 55 | * but LowerMacroOps::perform will unset this once it has lowered. 56 | * 57 | */ 58 | virtual bool shouldPerform() { return manager()->requested(); } 59 | 60 | private: 61 | 62 | void lowerTreeTop(TR::TreeTop *); 63 | void lowerAsyncCheck(TR::Node *, TR::TreeTop *); 64 | TR::Node* pendingInterruptsNode(); 65 | 66 | }; 67 | 68 | } 69 | 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /ruby/optimizer/RubyOptimizationManager.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * (c) Copyright IBM Corp. 2000, 2016 4 | * 5 | * This program and the accompanying materials are made available 6 | * under the terms of the Eclipse Public License v1.0 and 7 | * Apache License v2.0 which accompanies this distribution. 8 | * 9 | * The Eclipse Public License is available at 10 | * http://www.eclipse.org/legal/epl-v10.html 11 | * 12 | * The Apache License v2.0 is available at 13 | * http://www.opensource.org/licenses/apache2.0.php 14 | * 15 | * Contributors: 16 | * Multiple authors (IBM Corp.) - initial implementation and documentation 17 | *******************************************************************************/ 18 | 19 | 20 | #include "optimizer/OptimizationManager.hpp" 21 | #include "optimizer/OptimizationManager_inlines.hpp" // for OptimizationManager::self, etc 22 | 23 | #include "env/CompilerEnv.hpp" 24 | #include "codegen/CodeGenerator.hpp" 25 | #include "il/Block.hpp" 26 | #include "il/symbol/MethodSymbol.hpp" 27 | 28 | 29 | Ruby::OptimizationManager::OptimizationManager(TR::Optimizer *o, OptimizationFactory factory, OMR::Optimizations optNum, const char *optDetailString, const OptimizationStrategy *groupOfOpts) 30 | : OMR::OptimizationManager(o, factory, optNum, optDetailString, groupOfOpts) 31 | { 32 | // set flags if necessary 33 | switch (self()->id()) 34 | { 35 | case OMR::tacticalGlobalRegisterAllocator: 36 | _flags.set(requiresStructure); 37 | if (self()->comp()->getMethodHotness() >= hot && (TR::Compiler->target.is64Bit())) 38 | _flags.set(requiresLocalsUseDefInfo | doesNotRequireLoadsAsDefs); 39 | break; 40 | default: 41 | // do nothing 42 | break; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /ruby/optimizer/RubyOptimizationManager.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * (c) Copyright IBM Corp. 2000, 2016 4 | * 5 | * This program and the accompanying materials are made available 6 | * under the terms of the Eclipse Public License v1.0 and 7 | * Apache License v2.0 which accompanies this distribution. 8 | * 9 | * The Eclipse Public License is available at 10 | * http://www.eclipse.org/legal/epl-v10.html 11 | * 12 | * The Apache License v2.0 is available at 13 | * http://www.opensource.org/licenses/apache2.0.php 14 | * 15 | * Contributors: 16 | * Multiple authors (IBM Corp.) - initial implementation and documentation 17 | *******************************************************************************/ 18 | 19 | 20 | #ifndef RUBY_OPTIMIZATIONMANAGER_INCL 21 | #define RUBY_OPTIMIZATIONMANAGER_INCL 22 | 23 | /* 24 | * The following #define and typedef must appear before any #includes in this file 25 | */ 26 | #ifndef RUBY_OPTIMIZATIONMANAGER_CONNECTOR 27 | #define RUBY_OPTIMIZATIONMANAGER_CONNECTOR 28 | 29 | namespace Ruby { class OptimizationManager; } 30 | namespace Ruby { typedef Ruby::OptimizationManager OptimizationManagerConnector; } 31 | 32 | #endif 33 | 34 | #include "optimizer/OMROptimizationManager.hpp" 35 | 36 | namespace TR { class Optimization; } 37 | 38 | namespace Ruby 39 | { 40 | 41 | class OMR_EXTENSIBLE OptimizationManager : public OMR::OptimizationManagerConnector 42 | { 43 | public: 44 | 45 | OptimizationManager(TR::Optimizer *o, OptimizationFactory factory, OMR::Optimizations optNum, const char *optDetailString, 46 | const OptimizationStrategy *groupOfOpts = NULL); 47 | }; 48 | 49 | } 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /ruby/optimizer/RubyOptimizer.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * (c) Copyright IBM Corp. 2000, 2016 4 | * 5 | * This program and the accompanying materials are made available 6 | * under the terms of the Eclipse Public License v1.0 and 7 | * Apache License v2.0 which accompanies this distribution. 8 | * 9 | * The Eclipse Public License is available at 10 | * http://www.eclipse.org/legal/epl-v10.html 11 | * 12 | * The Apache License v2.0 is available at 13 | * http://www.opensource.org/licenses/apache2.0.php 14 | * 15 | * Contributors: 16 | * Multiple authors (IBM Corp.) - initial implementation and documentation 17 | *******************************************************************************/ 18 | 19 | 20 | #ifndef RUBY_OPTIMIZER_INCL 21 | #define RUBY_OPTIMIZER_INCL 22 | 23 | /* 24 | * The following #define and typedef must appear before any #includes in this file 25 | */ 26 | #ifndef RUBY_OPTIMIZER_CONNECTOR 27 | #define RUBY_OPTIMIZER_CONNECTOR 28 | 29 | namespace Ruby { class Optimizer; } 30 | namespace Ruby { typedef Ruby::Optimizer OptimizerConnector; } 31 | 32 | #endif 33 | 34 | #include "optimizer/OMROptimizer.hpp" 35 | 36 | namespace Ruby 37 | { 38 | 39 | class Optimizer : public OMR::OptimizerConnector 40 | { 41 | public: 42 | 43 | Optimizer(TR::Compilation *comp, TR::ResolvedMethodSymbol *methodSymbol, bool isIlGen, 44 | const OptimizationStrategy *strategy = NULL, uint16_t VNType = 0); 45 | 46 | static const OptimizationStrategy *optimizationStrategy( TR::Compilation *c); 47 | OMR_InlinerUtil *getInlinerUtil(); 48 | 49 | private: 50 | 51 | TR::Optimizer *self(); 52 | }; 53 | 54 | } 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /ruby/optimizer/RubyTrivialInliner.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * (c) Copyright IBM Corp. 2000, 2016 4 | * 5 | * This program and the accompanying materials are made available 6 | * under the terms of the Eclipse Public License v1.0 and 7 | * Apache License v2.0 which accompanies this distribution. 8 | * 9 | * The Eclipse Public License is available at 10 | * http://www.eclipse.org/legal/epl-v10.html 11 | * 12 | * The Apache License v2.0 is available at 13 | * http://www.opensource.org/licenses/apache2.0.php 14 | * 15 | * Contributors: 16 | * Multiple authors (IBM Corp.) - initial implementation and documentation 17 | *******************************************************************************/ 18 | 19 | 20 | #include "ruby/optimizer/RubyTrivialInliner.hpp" 21 | 22 | Ruby::TrivialInliner::TrivialInliner(TR::OptimizationManager *manager) 23 | : TR::Optimization(manager) 24 | {} 25 | 26 | int32_t Ruby::TrivialInliner::perform() 27 | { 28 | //defaultInitialSize must be consistent with 29 | //TRIVIAL_INLINER_MAX_SIZE under ibm/control/Options.hpp 30 | const uint32_t defaultInitialSize = 25; 31 | 32 | uint32_t initialSize = comp()->getOptions()->getTrivialInlinerMaxSize(); 33 | 34 | //Check if we're overriding the defaultInitialSize via an option. 35 | //If not increase initialSize as defaultInitialSize is too small. 36 | if(initialSize == defaultInitialSize) 37 | { 38 | //TODO: Get statistics on a good threshold for inlining Ruby methods. 39 | initialSize = 400; 40 | } 41 | 42 | comp()->generateAccurateNodeCount(); 43 | 44 | TR::ResolvedMethodSymbol * sym = comp()->getMethodSymbol(); 45 | if (sym->mayHaveInlineableCall() && !comp()->isDisabled(OMR::inlining)) 46 | { 47 | TR_DumbInliner inliner(optimizer(), this, initialSize); 48 | inliner.performInlining(sym); 49 | } 50 | 51 | comp()->setSupressEarlyInlining(false); 52 | 53 | return 1; // cost?? 54 | } 55 | -------------------------------------------------------------------------------- /ruby/optimizer/RubyTrivialInliner.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * (c) Copyright IBM Corp. 2000, 2016 4 | * 5 | * This program and the accompanying materials are made available 6 | * under the terms of the Eclipse Public License v1.0 and 7 | * Apache License v2.0 which accompanies this distribution. 8 | * 9 | * The Eclipse Public License is available at 10 | * http://www.eclipse.org/legal/epl-v10.html * 11 | * The Apache License v2.0 is available at 12 | * http://www.opensource.org/licenses/apache2.0.php 13 | * 14 | * Contributors: 15 | * Multiple authors (IBM Corp.) - initial implementation and documentation 16 | *******************************************************************************/ 17 | 18 | 19 | #ifndef RUBY_DUMBINLINER_INCL 20 | #define RUBY_DUMBINLINER_INCL 21 | 22 | #include "optimizer/Inliner.hpp" 23 | 24 | namespace Ruby 25 | { 26 | class TrivialInliner : public TR::Optimization 27 | { 28 | public: 29 | TrivialInliner(TR::OptimizationManager *manager); 30 | static TR::Optimization *create(TR::OptimizationManager *manager) 31 | { 32 | return new (manager->allocator()) TrivialInliner(manager); 33 | } 34 | 35 | virtual int32_t perform(); 36 | }; 37 | } 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /ruby/p/runtime/AsmUtil.spp: -------------------------------------------------------------------------------- 1 | !! (c) Copyright IBM Corp. 2000, 2016 2 | !! 3 | !! This program and the accompanying materials are made available 4 | !! under the terms of the Eclipse Public License v1.0 and 5 | !! Apache License v2.0 which accompanies this distribution. 6 | !! 7 | !! The Eclipse Public License is available at 8 | !! http://www.eclipse.org/legal/epl-v10.html 9 | !! 10 | !! The Apache License v2.0 is available at 11 | !! http://www.opensource.org/licenses/apache2.0.php 12 | !! 13 | !! Contributors: 14 | !! Multiple authors (IBM Corp.) - initial implementation and documentation 15 | 16 | #include "p/runtime/ppcasmdefines.inc" 17 | #include "p/runtime/PPCAsmUtil.inc" 18 | -------------------------------------------------------------------------------- /ruby/p/runtime/CodeDispatch.spp: -------------------------------------------------------------------------------- 1 | !! (c) Copyright IBM Corp. 2000, 2016 2 | !! 3 | !! This program and the accompanying materials are made available 4 | !! under the terms of the Eclipse Public License v1.0 and 5 | !! Apache License v2.0 which accompanies this distribution. 6 | !! 7 | !! The Eclipse Public License is available at 8 | !! http://www.eclipse.org/legal/epl-v10.html 9 | !! 10 | !! The Apache License v2.0 is available at 11 | !! http://www.opensource.org/licenses/apache2.0.php 12 | !! 13 | !! Contributors: 14 | !! Multiple authors (IBM Corp.) - initial implementation and documentation 15 | 16 | 17 | #include "p/runtime/ppcasmdefines.inc" 18 | 19 | #ifdef AIXPPC 20 | .globl .compiledCodeDispatch 21 | #elif defined(LINUXPPC64) 22 | .globl FUNC_LABEL(compiledCodeDispatch) 23 | .type FUNC_LABEL(compiledCodeDispatch),@function 24 | #endif 25 | 26 | #ifdef AIXPPC 27 | ! .text section 28 | .csect PicBuilder_TEXT{PR} 29 | #elif defined(LINUXPPC64) 30 | .section ".text" 31 | .align 2 32 | #endif 33 | 34 | #if defined(LINUXPPC64) 35 | 36 | #if defined(__LITTLE_ENDIAN__) 37 | FUNC_LABEL(compiledCodeDispatch): 38 | #else 39 | .compiledCodeDispatch: 40 | #endif 41 | 42 | #else 43 | .compiledCodeDispatch: 44 | #endif 45 | mr r2, r5 46 | mtctr r4 47 | bctr 48 | 49 | #if defined(LINUXPPC64) 50 | #if !defined(__LITTLE_ENDIAN__) 51 | .section ".opd","aw" 52 | .align 3 53 | .globl compiledCodeDispatch 54 | .size compiledCodeDispactch,24 55 | 56 | compiledCodeDispatch: 57 | .quad .compiledCodeDispatch 58 | .quad .TOC.@tocbase 59 | .long 0x00000000 60 | .long 0x00000000 61 | 62 | #endif 63 | #endif 64 | -------------------------------------------------------------------------------- /ruby/p/runtime/CodeSync.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * (c) Copyright IBM Corp. 2000, 2016 4 | * 5 | * This program and the accompanying materials are made available 6 | * under the terms of the Eclipse Public License v1.0 and 7 | * Apache License v2.0 which accompanies this distribution. 8 | * 9 | * The Eclipse Public License is available at 10 | * http://www.eclipse.org/legal/epl-v10.html 11 | * 12 | * The Apache License v2.0 is available at 13 | * http://www.opensource.org/licenses/apache2.0.php 14 | * 15 | * Contributors: 16 | * Multiple authors (IBM Corp.) - initial implementation and documentation 17 | *******************************************************************************/ 18 | 19 | #include "p/runtime/PPCCodeSync.inc" 20 | -------------------------------------------------------------------------------- /ruby/ruby.mk: -------------------------------------------------------------------------------- 1 | ################################################################################### 2 | # (c) Copyright IBM Corp. 2000, 2016 3 | # 4 | # This program and the accompanying materials are made available 5 | # under the terms of the Eclipse Public License v1.0 and 6 | # Apache License v2.0 which accompanies this distribution. 7 | # 8 | # The Eclipse Public License is available at 9 | # http://www.eclipse.org/legal/epl-v10.html 10 | # 11 | # The Apache License v2.0 is available at 12 | # http://www.opensource.org/licenses/apache2.0.php 13 | # 14 | # Contributors: 15 | # Multiple authors (IBM Corp.) - initial implementation and documentation 16 | ################################################################################## 17 | 18 | 19 | # 20 | # 21 | # "all" should be the first target to appear so it's the default 22 | # 23 | .PHONY: all clean cleanobjs cleandeps cleandll 24 | all: ; @echo SUCCESS - All files are up-to-date 25 | clean: ; @echo SUCCESS - All files are cleaned 26 | cleanobjs: ; @echo SUCCESS - All objects are cleaned 27 | cleandeps: ; @echo SUCCESS - All dependencies are cleaned 28 | cleandll: ; @echo SUCCESS - All shared libraries are cleaned 29 | 30 | # Handy macro to check to make sure variables are set 31 | REQUIRE_VARS=$(foreach VAR,$(1),$(if $($(VAR)),,$(error $(VAR) must be set))) 32 | 33 | # Verify SDK pointer for non-cleaning targets 34 | ifeq (,$(filter clean cleandeps cleandll,$(MAKECMDGOALS))) 35 | $(call REQUIRE_VARS,RBJITGLUE_DIR) 36 | $(call REQUIRE_VARS,RELATIVE_OMR_DIR) 37 | endif 38 | 39 | # 40 | # First setup some important paths 41 | # Personally, I feel it's best to default to out-of-tree build but who knows, there may be 42 | # differing opinions on that. 43 | # 44 | # These makefiles assume a common root. I'm going to make them work assuming rbjitglue 45 | # and omr are inside the ruby VM directory. 46 | JIT_SRCBASE?=$(RUBY_DIR) 47 | JIT_OBJBASE?=$(RBJITGLUE_DIR)/objs/ruby_$(BUILD_CONFIG) 48 | 49 | JIT_DLL_DIR?=../.. 50 | 51 | # 52 | # Windows users will likely use backslashes, but Make tends to not like that so much 53 | # 54 | FIXED_SRCBASE=$(subst \,/,$(JIT_SRCBASE)) 55 | FIXED_OBJBASE=$(subst \,/,$(JIT_OBJBASE)) 56 | FIXED_DLL_DIR=$(subst \,/,$(JIT_DLL_DIR)) 57 | 58 | # TODO - "debug" as default? 59 | BUILD_CONFIG?=prod 60 | 61 | # 62 | # This is where we setup our component dirs 63 | # Note these are all relative to JIT_SRCBASE and JIT_OBJBASE 64 | # It just makes sense since source and build dirs may be in different places 65 | # in the filesystem :) 66 | # 67 | JIT_OMR_DIRTY_DIR?=$(RELATIVE_OMR_DIR)/compiler 68 | JIT_PRODUCT_DIR?=$(RBJITGLUE_DIR)/ruby 69 | 70 | # 71 | # Dirs used internally by the makefiles 72 | # 73 | JIT_MAKE_DIR?=$(FIXED_SRCBASE)/$(RBJITGLUE_DIR)/ruby/build 74 | JIT_SCRIPT_DIR?=$(FIXED_SRCBASE)/$(RBJITGLUE_DIR)/ruby/build/scripts 75 | 76 | # 77 | # First we set a bunch of tokens about the platform that the rest of the 78 | # makefile will use as conditionals 79 | # 80 | include $(JIT_MAKE_DIR)/platform/common.mk 81 | 82 | # 83 | # Now we include the names of all the files that will go into building the JIT 84 | # Will automatically include files needed from HOST and TARGET platform 85 | # 86 | include $(JIT_MAKE_DIR)/files/common.mk 87 | 88 | # 89 | # Now we configure all the tooling we will use to build the files 90 | # 91 | # There is quite a bit of shared stuff, but the overwhelming majority of this 92 | # is toolchain-dependent. 93 | # 94 | # That makes sense - You can't expect XLC and GCC to take the same arguments 95 | # 96 | include $(JIT_MAKE_DIR)/toolcfg/common.mk 97 | 98 | # 99 | # Here's where everything has been setup and we lay down the actual targets and 100 | # recipes that Make will use to build them 101 | # 102 | include $(JIT_MAKE_DIR)/rules/common.mk 103 | -------------------------------------------------------------------------------- /ruby/runtime/CodeCacheManager.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * (c) Copyright IBM Corp. 2000, 2016 4 | * 5 | * This program and the accompanying materials are made available 6 | * under the terms of the Eclipse Public License v1.0 and 7 | * Apache License v2.0 which accompanies this distribution. 8 | * 9 | * The Eclipse Public License is available at 10 | * http://www.eclipse.org/legal/epl-v10.html 11 | * 12 | * The Apache License v2.0 is available at 13 | * http://www.opensource.org/licenses/apache2.0.php 14 | * 15 | * Contributors: 16 | * Multiple authors (IBM Corp.) - initial implementation and documentation 17 | *******************************************************************************/ 18 | 19 | #ifndef TR_CODECACHEMANAGER_INCL 20 | #define TR_CODECACHEMANAGER_INCL 21 | 22 | #include "runtime/RubyCodeCacheManager.hpp" 23 | 24 | namespace TR 25 | { 26 | 27 | class OMR_EXTENSIBLE CodeCacheManager : public Ruby::CodeCacheManagerConnector 28 | { 29 | public: 30 | CodeCacheManager(TR_FrontEnd *fe) : Ruby::CodeCacheManagerConnector(fe) { } 31 | }; 32 | 33 | } 34 | 35 | #endif // TR_CODECACHEMANAGER_INCL 36 | -------------------------------------------------------------------------------- /ruby/runtime/RubyCodeCacheManager.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * (c) Copyright IBM Corp. 2000, 2016 4 | * 5 | * This program and the accompanying materials are made available 6 | * under the terms of the Eclipse Public License v1.0 and 7 | * Apache License v2.0 which accompanies this distribution. 8 | * 9 | * The Eclipse Public License is available at 10 | * http://www.eclipse.org/legal/epl-v10.html 11 | * 12 | * The Apache License v2.0 is available at 13 | * http://www.opensource.org/licenses/apache2.0.php 14 | * 15 | * Contributors: 16 | * Multiple authors (IBM Corp.) - initial implementation and documentation 17 | *******************************************************************************/ 18 | 19 | #include 20 | #include "ruby/env/RubyFE.hpp" 21 | #include "ruby/runtime/RubyCodeCacheManager.hpp" 22 | 23 | TR::CodeCacheManager *Ruby::CodeCacheManager::_codeCacheManager = NULL; 24 | TR_RubyJitConfig *Ruby::CodeCacheManager::_jitConfig = NULL; 25 | 26 | TR::CodeCacheManager * 27 | Ruby::CodeCacheManager::self() 28 | { 29 | return static_cast(this); 30 | } 31 | 32 | 33 | TR_RubyFE * 34 | Ruby::CodeCacheManager::pyfe() 35 | { 36 | return reinterpret_cast(self()->fe()); 37 | } 38 | 39 | 40 | TR::CodeCache * 41 | Ruby::CodeCacheManager::initialize(bool useConsolidatedCache, uint32_t numberOfCodeCachesToCreateAtStartup) 42 | { 43 | _jitConfig = self()->pyfe()->jitConfig(); 44 | return self()->OMR::CodeCacheManager::initialize(useConsolidatedCache, numberOfCodeCachesToCreateAtStartup); 45 | } 46 | 47 | void * 48 | Ruby::CodeCacheManager::getMemory(size_t sizeInBytes) 49 | { 50 | void * ptr = malloc(sizeInBytes); 51 | return ptr; 52 | } 53 | 54 | void 55 | Ruby::CodeCacheManager::freeMemory(void *memoryToFree) 56 | { 57 | free(memoryToFree); 58 | } 59 | 60 | TR::CodeCacheMemorySegment * 61 | Ruby::CodeCacheManager::allocateCodeCacheSegment(size_t segmentSize, 62 | size_t &codeCacheSizeToAllocate, 63 | void *preferredStartAddress) 64 | { 65 | // ignore preferredStartAddress for now, since it's NULL anyway 66 | // goal would be to allocate code cache segments near the JIT library address 67 | codeCacheSizeToAllocate = segmentSize; 68 | TR::CodeCacheConfig & config = self()->codeCacheConfig(); 69 | if (segmentSize < config.codeCachePadKB() << 10) 70 | codeCacheSizeToAllocate = config.codeCachePadKB() << 10; 71 | uint8_t *memorySlab = (uint8_t *) mmap(NULL, 72 | codeCacheSizeToAllocate, 73 | PROT_READ | PROT_WRITE | PROT_EXEC, 74 | MAP_ANONYMOUS | MAP_PRIVATE, 75 | 0, 76 | 0); 77 | 78 | TR::CodeCacheMemorySegment *memSegment = (TR::CodeCacheMemorySegment *) ((size_t)memorySlab + codeCacheSizeToAllocate - sizeof(TR::CodeCacheMemorySegment)); 79 | new (memSegment) TR::CodeCacheMemorySegment(memorySlab, reinterpret_cast(memSegment)); 80 | return memSegment; 81 | } 82 | -------------------------------------------------------------------------------- /ruby/runtime/RubyCodeCacheManager.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * (c) Copyright IBM Corp. 2000, 2016 4 | * 5 | * This program and the accompanying materials are made available 6 | * under the terms of the Eclipse Public License v1.0 and 7 | * Apache License v2.0 which accompanies this distribution. 8 | * 9 | * The Eclipse Public License is available at 10 | * http://www.eclipse.org/legal/epl-v10.html 11 | * 12 | * The Apache License v2.0 is available at 13 | * http://www.opensource.org/licenses/apache2.0.php 14 | * 15 | * Contributors: 16 | * Multiple authors (IBM Corp.) - initial implementation and documentation 17 | *******************************************************************************/ 18 | 19 | 20 | #ifndef RUBY_CODECACHEMANAGER_INCL 21 | #define RUBY_CODECACHEMANAGER_INCL 22 | 23 | #ifndef RUBY_CODECACHEMANAGER_COMPOSED 24 | #define RUBY_CODECACHEMANAGER_COMPOSED 25 | namespace Ruby { class CodeCacheManager; } 26 | namespace Ruby { typedef CodeCacheManager CodeCacheManagerConnector; } 27 | #endif 28 | 29 | #include "runtime/OMRCodeCacheManager.hpp" 30 | 31 | #include 32 | #include 33 | #include "codegen/FrontEnd.hpp" 34 | #include "runtime/CodeCacheMemorySegment.hpp" 35 | 36 | class TR_RubyJitConfig; 37 | class TR_RubyFE; 38 | 39 | namespace TR { class CodeCache; } 40 | namespace TR { class CodeCacheManager; } 41 | 42 | namespace Ruby 43 | { 44 | 45 | class OMR_EXTENSIBLE CodeCacheManager : public OMR::CodeCacheManagerConnector 46 | { 47 | TR::CodeCacheManager *self(); 48 | 49 | public: 50 | CodeCacheManager(TR_FrontEnd *fe) : OMR::CodeCacheManagerConnector(fe) 51 | { 52 | _codeCacheManager = reinterpret_cast(this); 53 | } 54 | 55 | void *operator new(size_t s, TR::CodeCacheManager *m) { return m; } 56 | 57 | static TR::CodeCacheManager *instance() { return _codeCacheManager; } 58 | static TR_RubyJitConfig *jitConfig() { return _jitConfig; } 59 | TR_RubyFE *pyfe(); 60 | 61 | TR::CodeCache *initialize(bool useConsolidatedCache, uint32_t numberOfCodeCachesToCreateAtStartup); 62 | 63 | void *getMemory(size_t sizeInBytes); 64 | void freeMemory(void *memoryToFree); 65 | 66 | TR::CodeCacheMemorySegment *allocateCodeCacheSegment(size_t segmentSize, 67 | size_t &codeCacheSizeToAllocate, 68 | void *preferredStartAddress); 69 | 70 | private : 71 | static TR::CodeCacheManager *_codeCacheManager; 72 | static TR_RubyJitConfig *_jitConfig; 73 | }; 74 | 75 | } // namespace Ruby 76 | 77 | #endif // RUBY_CODECACHEMANAGER_INCL 78 | -------------------------------------------------------------------------------- /ruby/runtime/RubyJitConfig.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * (c) Copyright IBM Corp. 2000, 2016 4 | * 5 | * This program and the accompanying materials are made available 6 | * under the terms of the Eclipse Public License v1.0 and 7 | * Apache License v2.0 which accompanies this distribution. 8 | * 9 | * The Eclipse Public License is available at 10 | * http://www.eclipse.org/legal/epl-v10.html 11 | * 12 | * The Apache License v2.0 is available at 13 | * http://www.opensource.org/licenses/apache2.0.php 14 | * 15 | * Contributors: 16 | * Multiple authors (IBM Corp.) - initial implementation and documentation 17 | *******************************************************************************/ 18 | 19 | 20 | #ifndef RUBYJITCONFIG_HPP_tqsqgv 21 | #define RUBYJITCONFIG_HPP_tqsqgv 22 | 23 | #include "env/FEBase.hpp" 24 | #include "env/JitConfig.hpp" 25 | 26 | class TR_RubyJitConfig : public TR::JitConfig 27 | { 28 | public: 29 | TR_RubyJitConfig() : TR::JitConfig() {} 30 | }; 31 | 32 | #endif /* RUBYJITCONFIG_HPP_tqsqgv */ 33 | -------------------------------------------------------------------------------- /ruby/x/codegen/Evaluator.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * (c) Copyright IBM Corp. 2000, 2016 4 | * 5 | * This program and the accompanying materials are made available 6 | * under the terms of the Eclipse Public License v1.0 and 7 | * Apache License v2.0 which accompanies this distribution. 8 | * 9 | * The Eclipse Public License is available at 10 | * http://www.eclipse.org/legal/epl-v10.html 11 | * 12 | * The Apache License v2.0 is available at 13 | * http://www.opensource.org/licenses/apache2.0.php 14 | * 15 | * Contributors: 16 | * Multiple authors (IBM Corp.) - initial implementation and documentation 17 | *******************************************************************************/ 18 | 19 | 20 | #include "codegen/TreeEvaluator.hpp" 21 | #include "codegen/X86Evaluator.hpp" 22 | #include "il/Node.hpp" 23 | #include "il/Node_inlines.hpp" 24 | 25 | extern "C" 26 | { 27 | void *fwdHalfWordCopyTable = 0; 28 | }; 29 | 30 | -------------------------------------------------------------------------------- /ruby/x/runtime/AsmUtil64.asm: -------------------------------------------------------------------------------- 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 2 | ;; 3 | ;; (c) Copyright IBM Corp. 2000, 2016 4 | ;; 5 | ;; This program and the accompanying materials are made available 6 | ;; under the terms of the Eclipse Public License v1.0 and 7 | ;; Apache License v2.0 which accompanies this distribution. 8 | ;; 9 | ;; The Eclipse Public License is available at 10 | ;; http://www.eclipse.org/legal/epl-v10.html 11 | ;; 12 | ;; The Apache License v2.0 is available at 13 | ;; http://www.opensource.org/licenses/apache2.0.php 14 | ;; 15 | ;; Contributors: 16 | ;; Multiple authors (IBM Corp.) - initial implementation and documentation 17 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 18 | 19 | 20 | ; VM should define this at some point 21 | OFFSETOF_CPU_CYCLE_COUNT equ 0 22 | 23 | ifdef TR_HOST_64BIT 24 | 25 | include x/amd64/runtime/AMD64AsmUtil.inc 26 | 27 | public initCycleCounter 28 | public incrementCycleCounter 29 | public getCycles 30 | 31 | GetCycles MACRO 32 | rdtsc 33 | shl rdx,32 34 | or rax,rdx 35 | ENDM 36 | 37 | ; void initCycleCounter() 38 | initCycleCounter PROC NEAR 39 | GetCycles 40 | mov qword ptr [rbp + OFFSETOF_CPU_CYCLE_COUNT], rax 41 | ret 42 | initCycleCounter ENDP 43 | 44 | ; void incrementCycleCounter(intptr_t cycleCounterPointer) 45 | incrementCycleCounter PROC NEAR 46 | GetCycles 47 | sub rax, qword ptr [rbp + OFFSETOF_CPU_CYCLE_COUNT] 48 | add qword ptr [rdi], rax 49 | ret 50 | incrementCycleCounter ENDP 51 | 52 | getCycles PROC NEAR 53 | GetCycles 54 | ret 55 | getCycles ENDP 56 | 57 | else 58 | .686p 59 | assume cs:flat,ds:flat,ss:flat 60 | _DATA segment para use32 public 'DATA' 61 | AMD64AsmUtil: 62 | db 00h 63 | _DATA ends 64 | 65 | endif 66 | end 67 | 68 | -------------------------------------------------------------------------------- /ruby/z/codegen/Evaluator.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * (c) Copyright IBM Corp. 2000, 2016 4 | * 5 | * This program and the accompanying materials are made available 6 | * under the terms of the Eclipse Public License v1.0 and 7 | * Apache License v2.0 which accompanies this distribution. 8 | * 9 | * The Eclipse Public License is available at 10 | * http://www.eclipse.org/legal/epl-v10.html 11 | * 12 | * The Apache License v2.0 is available at 13 | * http://www.opensource.org/licenses/apache2.0.php 14 | * 15 | * Contributors: 16 | * Multiple authors (IBM Corp.) - initial implementation and documentation 17 | *******************************************************************************/ 18 | 19 | #include "codegen/CodeGenerator.hpp" 20 | #include "env/ConcreteFE.hpp" 21 | #include "z/codegen/S390GenerateInstructions.hpp" 22 | #include "z/codegen/TRSystemLinkage.hpp" 23 | #include "codegen/S390Snippets.hpp" 24 | #include "il/Node.hpp" 25 | #include "il/Node_inlines.hpp" 26 | #include "env/IO.hpp" 27 | 28 | #define NOT_IMPLEMENTED { TR_ASSERT(0, "This function is not implemented in Ruby JIT"); } 29 | 30 | 31 | uint32_t 32 | TR_S390RestoreGPR7Snippet::getLength(int32_t estimatedSnippetStart) 33 | { 34 | NOT_IMPLEMENTED; 35 | return 0; 36 | } 37 | 38 | uint8_t * 39 | TR_S390RestoreGPR7Snippet::emitSnippetBody() 40 | { 41 | NOT_IMPLEMENTED; 42 | return NULL; 43 | } 44 | 45 | void 46 | TR_Debug::print(TR::FILE *pOutFile, TR_S390RestoreGPR7Snippet *snippet) 47 | { 48 | NOT_IMPLEMENTED; 49 | } 50 | 51 | void 52 | TR_RubyFE::generateBinaryEncodingPrologue( 53 | TR_BinaryEncodingData *beData, 54 | TR::CodeGenerator *cg) 55 | { 56 | TR::Compilation* comp = cg->comp(); 57 | TR_S390BinaryEncodingData *data = (TR_S390BinaryEncodingData *)beData; 58 | 59 | data->cursorInstruction = comp->getFirstInstruction(); 60 | data->estimate = 0; 61 | data->preProcInstruction = data->cursorInstruction; 62 | data->jitTojitStart = data->cursorInstruction; 63 | data->cursorInstruction = NULL; 64 | 65 | TR::Instruction * preLoadArgs, * endLoadArgs; 66 | preLoadArgs = data->preProcInstruction; 67 | endLoadArgs = preLoadArgs; 68 | 69 | TR::Instruction * oldFirstInstruction = data->cursorInstruction; 70 | 71 | data->cursorInstruction = comp->getFirstInstruction(); 72 | 73 | static char *disableAlignJITEP = feGetEnv("TR_DisableAlignJITEP"); 74 | 75 | // Padding for JIT Entry Point 76 | if (!disableAlignJITEP) 77 | { 78 | data->estimate += 256; 79 | } 80 | 81 | while (data->cursorInstruction && data->cursorInstruction->getOpCodeValue() != TR::InstOpCode::PROC) 82 | { 83 | data->estimate = data->cursorInstruction->estimateBinaryLength(data->estimate); 84 | data->cursorInstruction = data->cursorInstruction->getNext(); 85 | } 86 | 87 | cg->getLinkage()->createPrologue(data->cursorInstruction); 88 | //cg->getLinkage()->analyzePrologue(); 89 | } 90 | 91 | -------------------------------------------------------------------------------- /ruby/z/codegen/RubyCodeGenerator.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * (c) Copyright IBM Corp. 2000, 2016 4 | * 5 | * This program and the accompanying materials are made available 6 | * under the terms of the Eclipse Public License v1.0 and 7 | * Apache License v2.0 which accompanies this distribution. 8 | * 9 | * The Eclipse Public License is available at 10 | * http://www.eclipse.org/legal/epl-v10.html 11 | * 12 | * The Apache License v2.0 is available at 13 | * http://www.opensource.org/licenses/apache2.0.php 14 | * 15 | * Contributors: 16 | * Multiple authors (IBM Corp.) - initial implementation and documentation 17 | *******************************************************************************/ 18 | 19 | 20 | #include "codegen/CodeGenerator.hpp" 21 | #include "z/codegen/TRSystemLinkage.hpp" 22 | #include "compile/Compilation.hpp" 23 | #include "env/CompilerEnv.hpp" 24 | 25 | Ruby::Z::CodeGenerator::CodeGenerator() : 26 | OMR::CodeGeneratorConnector() 27 | { 28 | } 29 | 30 | 31 | TR::Linkage * 32 | Ruby::Z::CodeGenerator::createLinkage(TR_LinkageConventions lc) 33 | { 34 | // *this swipeable for debugging purposes 35 | bool lockLitPoolRegister = false; 36 | TR::Linkage * linkage; 37 | TR::Compilation *comp = self()->comp(); 38 | switch (lc) 39 | { 40 | case TR_Helper: 41 | linkage = new (self()->trHeapMemory()) TR_S390zLinuxSystemLinkage(self()); 42 | lockLitPoolRegister = true; 43 | break; 44 | 45 | case TR_Private: 46 | // no private linkage, fall through to system 47 | 48 | case TR_System: 49 | if (TR::Compiler->target.isLinux()) 50 | { 51 | linkage = new (self()->trHeapMemory()) TR_S390zLinuxSystemLinkage(self()); 52 | lockLitPoolRegister = true; 53 | } 54 | else 55 | { 56 | linkage = new (self()->trHeapMemory()) TR_S390zOSSystemLinkage(self()); 57 | } 58 | break; 59 | 60 | default : 61 | TR_ASSERT(0, "\nTestarossa error: Illegal linkage convention %d\n", lc); 62 | } 63 | 64 | if (lockLitPoolRegister) 65 | { 66 | // TR_S390zLinuxSystemLinkage uses GPR13 for the literal pool, yet that 67 | // register remains unlocked as most other projects seem to be managing 68 | // that register separately. In the future, we should instead have a 69 | // Ruby::Z::Linux::Linkage (or whatever the class would work out to), 70 | // however, in the short term I'm going to lock the single register to avoid 71 | // having to create a whole new subclass of TR_S390zLinuxSystemLinkage. 72 | self()->machine()->getRegisterFile( linkage->getLitPoolRegister() )->setState(TR::RealRegister::Locked); 73 | } 74 | 75 | self()->setLinkage(lc, linkage); 76 | return linkage; 77 | } 78 | 79 | -------------------------------------------------------------------------------- /ruby/z/codegen/RubyCodeGenerator.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * (c) Copyright IBM Corp. 2000, 2016 4 | * 5 | * This program and the accompanying materials are made available 6 | * under the terms of the Eclipse Public License v1.0 and 7 | * Apache License v2.0 which accompanies this distribution. 8 | * 9 | * The Eclipse Public License is available at 10 | * http://www.eclipse.org/legal/epl-v10.html 11 | * 12 | * The Apache License v2.0 is available at 13 | * http://www.opensource.org/licenses/apache2.0.php 14 | * 15 | * Contributors: 16 | * Multiple authors (IBM Corp.) - initial implementation and documentation 17 | *******************************************************************************/ 18 | 19 | 20 | #ifndef RUBY_Z_CODEGENERATORBASE_INCL 21 | #define RUBY_Z_CODEGENERATORBASE_INCL 22 | 23 | /* 24 | * The following #define and typedef must appear before any #includes in this file 25 | */ 26 | #ifndef RUBY_CODEGENERATORBASE_CONNECTOR 27 | #define RUBY_CODEGENERATORBASE_CONNECTOR 28 | 29 | namespace Ruby { namespace Z { class CodeGenerator; } } 30 | namespace Ruby { typedef Ruby::Z::CodeGenerator CodeGeneratorConnector; } 31 | 32 | #else 33 | #error Ruby::Z::CodeGenerator expected to be a primary connector, but a Ruby connector is already defined 34 | #endif 35 | 36 | 37 | #include "codegen/OMRCodeGenerator.hpp" 38 | 39 | 40 | namespace Ruby 41 | { 42 | 43 | namespace Z 44 | { 45 | 46 | class OMR_EXTENSIBLE CodeGenerator : public OMR::CodeGeneratorConnector 47 | { 48 | public: 49 | 50 | CodeGenerator(); 51 | 52 | TR::Linkage *createLinkage(TR_LinkageConventions lc); 53 | }; 54 | 55 | } 56 | 57 | } 58 | #endif 59 | 60 | 61 | --------------------------------------------------------------------------------