00001 # -*- coding: utf-8 -*- 00002 # Copyright (c) 2009, Fixstars Corporation 00003 # All rights reserved. 00004 # 00005 # Redistribution and use in source and binary forms, with or without modification, 00006 # are permitted provided that the following conditions are met: 00007 # 00008 # * Redistributions of source code must retain the above copyright notice, 00009 # this list of conditions and the following disclaimer. 00010 # 00011 # * Redistributions in binary form must reproduce the above copyright notice, 00012 # this list of conditions and the following disclaimer in the documentation 00013 # and/or other materials provided with the distribution. 00014 # 00015 # * Neither the name of Fixstars Corporation nor the names of its contributors 00016 # may be used to endorse or promote products derived from this software 00017 # without specific prior written permission. 00018 # 00019 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 00020 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00021 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 00022 # IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 00023 # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00024 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00025 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 00026 # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00027 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 00028 # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00029 # 00030 00031 """Unroll Loop(未実装)""" 00032 00033 from ctrump.optimizer import * 00034 00035 global_options_table = [ 00036 ] 00037 00038 translate_options_table = [ 00039 ('unroll', "アンロール回数", '''展開する回数を指定します''',4), 00040 00041 ('enable_overun', "オーバーランを認める", 00042 '''ループ回数がアンロール回数で割り切れない場合、 00043 バッファをはみだしてストアを行います。 00044 00045 書き込まれるサイズは、最大 00046 ((unroll count)-1) * sizeof(buffer[0]) [byte] 00047 になります 00048 00049 ループ回数が割り切れない場合の処理が減るので少し速くなりますが、 00050 バッファオーバーランが不具合を起こします。 00051 よく理解したうえで使ってください''', False) 00052 ] 00053 00054 global_option = Option(global_options_table) 00055 translate_option = Option(translate_options_table) 00056 00057 class UnrollTranslator(LoopTranslatorBase): 00058 def __init__(self): 00059 None 00060 00061 def get_name(self): 00062 return 'Unroll' 00063 00064 def get_global_option(self): 00065 return global_option 00066 00067 def get_translate_option(self): 00068 return translate_option 00069 00070 def translate(self, analyze_result, stmt, cfg, attr, global_options, translate_option, prog): 00071 return [prog] 00072 00073 def is_enabled(self, analyze_results, stmt, cfg, node, errors, warnings, hints): 00074 return analyze_results[LoopParallelAnalyzer] == 0 00075 00076 00077 def init_optimizer(engine): 00078 loop_optimizer = engine.get_loop_optimizer() 00079 00080 # loop_optimizer.append_translator(UnrollTranslator(), 00081 # [LoopParallelAnalyzer])