1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/shark/sharkBuilder.hpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,228 @@ 1.4 +/* 1.5 + * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. 1.6 + * Copyright 2008, 2009, 2010 Red Hat, Inc. 1.7 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.8 + * 1.9 + * This code is free software; you can redistribute it and/or modify it 1.10 + * under the terms of the GNU General Public License version 2 only, as 1.11 + * published by the Free Software Foundation. 1.12 + * 1.13 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.14 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.15 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.16 + * version 2 for more details (a copy is included in the LICENSE file that 1.17 + * accompanied this code). 1.18 + * 1.19 + * You should have received a copy of the GNU General Public License version 1.20 + * 2 along with this work; if not, write to the Free Software Foundation, 1.21 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.22 + * 1.23 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.24 + * or visit www.oracle.com if you need additional information or have any 1.25 + * questions. 1.26 + * 1.27 + */ 1.28 + 1.29 +#ifndef SHARE_VM_SHARK_SHARKBUILDER_HPP 1.30 +#define SHARE_VM_SHARK_SHARKBUILDER_HPP 1.31 + 1.32 +#include "ci/ciType.hpp" 1.33 +#include "memory/barrierSet.hpp" 1.34 +#include "memory/cardTableModRefBS.hpp" 1.35 +#include "shark/llvmHeaders.hpp" 1.36 +#include "shark/llvmValue.hpp" 1.37 +#include "shark/sharkCodeBuffer.hpp" 1.38 +#include "shark/sharkEntry.hpp" 1.39 +#include "shark/sharkType.hpp" 1.40 +#include "shark/sharkValue.hpp" 1.41 +#include "utilities/debug.hpp" 1.42 +#include "utilities/sizes.hpp" 1.43 + 1.44 +class SharkBuilder : public llvm::IRBuilder<> { 1.45 + friend class SharkCompileInvariants; 1.46 + 1.47 + public: 1.48 + SharkBuilder(SharkCodeBuffer* code_buffer); 1.49 + 1.50 + // The code buffer we are building into. 1.51 + private: 1.52 + SharkCodeBuffer* _code_buffer; 1.53 + 1.54 + protected: 1.55 + SharkCodeBuffer* code_buffer() const { 1.56 + return _code_buffer; 1.57 + } 1.58 + 1.59 + public: 1.60 + llvm::LoadInst* CreateAtomicLoad(llvm::Value* ptr, 1.61 + unsigned align = HeapWordSize, 1.62 + llvm::AtomicOrdering ordering = llvm::SequentiallyConsistent, 1.63 + llvm::SynchronizationScope synchScope = llvm::CrossThread, 1.64 + bool isVolatile = true, 1.65 + const char *name = ""); 1.66 + llvm::StoreInst* CreateAtomicStore(llvm::Value *val, 1.67 + llvm::Value *ptr, 1.68 + unsigned align = HeapWordSize, 1.69 + llvm::AtomicOrdering ordering = llvm::SequentiallyConsistent, 1.70 + llvm::SynchronizationScope SynchScope = llvm::CrossThread, 1.71 + bool isVolatile = true, 1.72 + const char *name = ""); 1.73 + 1.74 + // Helpers for accessing structures. 1.75 + public: 1.76 + llvm::Value* CreateAddressOfStructEntry(llvm::Value* base, 1.77 + ByteSize offset, 1.78 + llvm::Type* type, 1.79 + const char *name = ""); 1.80 + llvm::LoadInst* CreateValueOfStructEntry(llvm::Value* base, 1.81 + ByteSize offset, 1.82 + llvm::Type* type, 1.83 + const char *name = ""); 1.84 + 1.85 + // Helpers for accessing arrays. 1.86 + public: 1.87 + llvm::LoadInst* CreateArrayLength(llvm::Value* arrayoop); 1.88 + llvm::Value* CreateArrayAddress(llvm::Value* arrayoop, 1.89 + llvm::Type* element_type, 1.90 + int element_bytes, 1.91 + ByteSize base_offset, 1.92 + llvm::Value* index, 1.93 + const char* name = ""); 1.94 + llvm::Value* CreateArrayAddress(llvm::Value* arrayoop, 1.95 + BasicType basic_type, 1.96 + ByteSize base_offset, 1.97 + llvm::Value* index, 1.98 + const char* name = ""); 1.99 + llvm::Value* CreateArrayAddress(llvm::Value* arrayoop, 1.100 + BasicType basic_type, 1.101 + llvm::Value* index, 1.102 + const char* name = ""); 1.103 + 1.104 + // Helpers for creating intrinsics and external functions. 1.105 + private: 1.106 + static llvm::Type* make_type(char type, bool void_ok); 1.107 + static llvm::FunctionType* make_ftype(const char* params, 1.108 + const char* ret); 1.109 + llvm::Value* make_function(const char* name, 1.110 + const char* params, 1.111 + const char* ret); 1.112 + llvm::Value* make_function(address func, 1.113 + const char* params, 1.114 + const char* ret); 1.115 + 1.116 + // Intrinsics and external functions, part 1: VM calls. 1.117 + // These are functions declared with JRT_ENTRY and JRT_EXIT, 1.118 + // macros which flip the thread from _thread_in_Java to 1.119 + // _thread_in_vm and back. VM calls always safepoint, and can 1.120 + // therefore throw exceptions. VM calls require of setup and 1.121 + // teardown, and must be called with SharkTopLevelBlock::call_vm. 1.122 + public: 1.123 + llvm::Value* find_exception_handler(); 1.124 + llvm::Value* monitorenter(); 1.125 + llvm::Value* monitorexit(); 1.126 + llvm::Value* new_instance(); 1.127 + llvm::Value* newarray(); 1.128 + llvm::Value* anewarray(); 1.129 + llvm::Value* multianewarray(); 1.130 + llvm::Value* register_finalizer(); 1.131 + llvm::Value* safepoint(); 1.132 + llvm::Value* throw_ArithmeticException(); 1.133 + llvm::Value* throw_ArrayIndexOutOfBoundsException(); 1.134 + llvm::Value* throw_ClassCastException(); 1.135 + llvm::Value* throw_NullPointerException(); 1.136 + 1.137 + // Intrinsics and external functions, part 2: High-level non-VM calls. 1.138 + // These are called like normal functions. The stack is not set 1.139 + // up for walking so they must not safepoint or throw exceptions, 1.140 + // or call anything that might. 1.141 + public: 1.142 + llvm::Value* f2i(); 1.143 + llvm::Value* f2l(); 1.144 + llvm::Value* d2i(); 1.145 + llvm::Value* d2l(); 1.146 + llvm::Value* is_subtype_of(); 1.147 + llvm::Value* current_time_millis(); 1.148 + llvm::Value* sin(); 1.149 + llvm::Value* cos(); 1.150 + llvm::Value* tan(); 1.151 + llvm::Value* atan2(); 1.152 + llvm::Value* sqrt(); 1.153 + llvm::Value* log(); 1.154 + llvm::Value* log10(); 1.155 + llvm::Value* pow(); 1.156 + llvm::Value* exp(); 1.157 + llvm::Value* fabs(); 1.158 + llvm::Value* unsafe_field_offset_to_byte_offset(); 1.159 + llvm::Value* osr_migration_end(); 1.160 + 1.161 + // Intrinsics and external functions, part 3: semi-VM calls. 1.162 + // These are special cases that do VM call stuff but are invoked 1.163 + // as though they were normal calls. This is acceptable so long 1.164 + // as the method that calls them returns to its immediately that 1.165 + // the semi VM call returns. 1.166 + public: 1.167 + llvm::Value* throw_StackOverflowError(); 1.168 + llvm::Value* uncommon_trap(); 1.169 + llvm::Value* deoptimized_entry_point(); 1.170 + 1.171 + // Intrinsics and external functions, part 4: Native-Java transition. 1.172 + // This is a special case in that it is invoked during a thread 1.173 + // state transition. The stack must be set up for walking, and it 1.174 + // may throw exceptions, but the state is _thread_in_native_trans. 1.175 + public: 1.176 + llvm::Value* check_special_condition_for_native_trans(); 1.177 + 1.178 + // Intrinsics and external functions, part 5: Low-level non-VM calls. 1.179 + // These have the same caveats as the high-level non-VM calls 1.180 + // above. They are not accessed directly; rather, you should 1.181 + // access them via the various Create* methods below. 1.182 + private: 1.183 + llvm::Value* cmpxchg_int(); 1.184 + llvm::Value* cmpxchg_ptr(); 1.185 + llvm::Value* frame_address(); 1.186 + llvm::Value* memset(); 1.187 + llvm::Value* unimplemented(); 1.188 + llvm::Value* should_not_reach_here(); 1.189 + llvm::Value* dump(); 1.190 + 1.191 + // Public interface to low-level non-VM calls. 1.192 + public: 1.193 + llvm::CallInst* CreateGetFrameAddress(); 1.194 + llvm::CallInst* CreateMemset(llvm::Value* dst, 1.195 + llvm::Value* value, 1.196 + llvm::Value* len, 1.197 + llvm::Value* align); 1.198 + llvm::CallInst* CreateUnimplemented(const char* file, int line); 1.199 + llvm::CallInst* CreateShouldNotReachHere(const char* file, int line); 1.200 + NOT_PRODUCT(llvm::CallInst* CreateDump(llvm::Value* value)); 1.201 + 1.202 + // HotSpot memory barriers 1.203 + public: 1.204 + void CreateUpdateBarrierSet(BarrierSet* bs, llvm::Value* field); 1.205 + 1.206 + // Helpers for accessing the code buffer. 1.207 + public: 1.208 + llvm::Value* code_buffer_address(int offset); 1.209 + llvm::Value* CreateInlineOop(jobject object, const char* name = ""); 1.210 + llvm::Value* CreateInlineOop(ciObject* object, const char* name = "") { 1.211 + return CreateInlineOop(object->constant_encoding(), name); 1.212 + } 1.213 + 1.214 + llvm::Value* CreateInlineMetadata(Metadata* metadata, llvm::PointerType* type, const char* name = ""); 1.215 + llvm::Value* CreateInlineMetadata(ciMetadata* metadata, llvm::PointerType* type, const char* name = "") { 1.216 + return CreateInlineMetadata(metadata->constant_encoding(), type, name); 1.217 + } 1.218 + llvm::Value* CreateInlineData(void* data, 1.219 + size_t size, 1.220 + llvm::Type* type, 1.221 + const char* name = ""); 1.222 + 1.223 + // Helpers for creating basic blocks. 1.224 + // NB don't use unless SharkFunction::CreateBlock is unavailable. 1.225 + // XXX these are hacky and should be removed. 1.226 + public: 1.227 + llvm::BasicBlock* GetBlockInsertionPoint() const; 1.228 + llvm::BasicBlock* CreateBlock(llvm::BasicBlock* ip, 1.229 + const char* name="") const; 1.230 +}; 1.231 + #endif // SHARE_VM_SHARK_SHARKBUILDER_HPP