1 /* 2 * Copyright (c) 1999, 2007, Oracle and/or its affiliates. All rights reserved. 3 * Copyright 2008, 2009 Red Hat, Inc. 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5 * 6 * This code is free software; you can redistribute it and/or modify it 7 * under the terms of the GNU General Public License version 2 only, as 8 * published by the Free Software Foundation. 9 * 10 * This code is distributed in the hope that it will be useful, but WITHOUT 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 * version 2 for more details (a copy is included in the LICENSE file that 14 * accompanied this code). 15 * 16 * You should have received a copy of the GNU General Public License version 17 * 2 along with this work; if not, write to the Free Software Foundation, 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 19 * 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 21 * or visit www.oracle.com if you need additional information or have any 22 * questions. 23 * 24 */ 25 26 class SharkTopLevelBlock; 27 class DeferredZeroCheck; 28 29 class SharkFunction : public SharkTargetInvariants { 30 friend class SharkStackWithNormalFrame; 31 32 public: 33 static llvm::Function* build(ciEnv* env, 34 SharkBuilder* builder, 35 ciTypeFlow* flow, 36 const char* name) { 37 SharkFunction function(env, builder, flow, name); 38 return function.function(); 39 } 40 41 private: 42 SharkFunction(ciEnv* env, 43 SharkBuilder* builder, 44 ciTypeFlow* flow, 45 const char* name) 46 : SharkTargetInvariants(env, builder, flow) { initialize(name); } 47 48 private: 49 void initialize(const char* name); 50 51 private: 52 llvm::Function* _function; 53 SharkTopLevelBlock** _blocks; 54 GrowableArray<DeferredZeroCheck*> _deferred_zero_checks; 55 SharkStack* _stack; 56 57 public: 58 llvm::Function* function() const { 59 return _function; 60 } 61 int block_count() const { 62 return flow()->block_count(); 63 } 64 SharkTopLevelBlock* block(int i) const { 65 assert(i < block_count(), "should be"); 66 return _blocks[i]; 67 } 68 GrowableArray<DeferredZeroCheck*>* deferred_zero_checks() { 69 return &_deferred_zero_checks; 70 } 71 SharkStack* stack() const { 72 return _stack; 73 } 74 75 // On-stack replacement 76 private: 77 bool is_osr() const { 78 return flow()->is_osr_flow(); 79 } 80 const llvm::FunctionType* entry_point_type() const { 81 if (is_osr()) 82 return SharkType::osr_entry_point_type(); 83 else 84 return SharkType::entry_point_type(); 85 } 86 87 // Block management 88 private: 89 llvm::BasicBlock* _block_insertion_point; 90 91 void set_block_insertion_point(llvm::BasicBlock* block_insertion_point) { 92 _block_insertion_point = block_insertion_point; 93 } 94 llvm::BasicBlock* block_insertion_point() const { 95 return _block_insertion_point; 96 } 97 98 public: 99 llvm::BasicBlock* CreateBlock(const char* name = "") const { 100 return llvm::BasicBlock::Create( 101 SharkContext::current(), name, function(), block_insertion_point()); 102 } 103 104 // Deferred zero checks 105 public: 106 void add_deferred_zero_check(SharkTopLevelBlock* block, 107 SharkValue* value); 108 109 private: 110 void do_deferred_zero_checks(); 111 };