def test_issue100(self): m = Module.new('a') pm = FunctionPassManager.new(m) ee = ExecutionEngine.new(m) pm.add(ee.target_data) ti = Type.int() tf = Type.function(ti, []) f = m.add_function(tf, "func1") bb = f.append_basic_block('entry') b = Builder.new(bb) b.ret(Constant.int(ti, 0)) f.verify() pm.run(f) assert ee.run_function(f, []).as_int() == 0
def __init__(self, context): self._context = context self._module = llvm.core.Module.new('intrlib.%X' % id(self)) # A lookup dictionary that matches (name) -> (intr) self._functions = {} # (name, args) -> (lfunc) self._compiled = {} # Build function pass manager to reduce memory usage of from llvm.passes import FunctionPassManager, PassManagerBuilder pmb = PassManagerBuilder.new() pmb.opt_level = 2 self._fpm = FunctionPassManager.new(self._module) pmb.populate(self._fpm)
def __init__(self, code, optz=True, debug=True): # parse = Semantica(code.read()) s = Semantica(code.read()) s.inicio() self.tree = s.tree self.module = Module.new('program') self.symbols = s.table self.scope = "global" self.builder = None self.func = None self.debug = debug self.printf_f = Function.new(self.module, Type.function(Type.float(), [Type.float()]), "printf_f") self.scanf_f = Function.new(self.module, Type.function(Type.float(), []), "scanf_f") ###OTIMIZAÇÕES### self.optz = optz self.passes = FunctionPassManager.new(self.module) # combina e remove instruções redundantes self.passes.add(PASS_INSTCOMBINE) # reassocia instruções para otimizar aritmética de constantes self.passes.add(PASS_REASSOCIATE) # elimina subexpressões comuns self.passes.add(PASS_GVN) # self.passes.add(PASS_MEM2REG) # remove blocos básicos sem predecessor, elimina nó PHI para blocos básicos # com um único predecessor e elimina blocos que contém salto incondicional self.passes.add(PASS_SIMPLIFYCFG) # inicializa as otimizações self.passes.initialize() ###FIM_OTIMIZAÇÕES#### self.gen_inicio(self.tree) self.builder.ret(Constant.int(Type.int(), 0)) print('\n\n;=== Código LLVM final ===') if(self.optz==True): print("----SEM OTIMIZAÇÃO----\n",self.module) self.passes.run(self.func) print("----COM OTIMIZAÇÃO----\n",self.module) else: print(self.module)
from llvm.core import Module, Constant, Type, Function, Builder from llvm.ee import ExecutionEngine, TargetData from llvm.passes import FunctionPassManager import llvm.core from llvm.core import FCMP_ULT, FCMP_ONE, ICMP_NE, CC_FASTCALL, CC_C from llvm.passes import (PASS_PROMOTE_MEMORY_TO_REGISTER, PASS_INSTRUCTION_COMBINING, PASS_REASSOCIATE, PASS_GVN, PASS_CFG_SIMPLIFICATION) G_LLVM_MODULE = Module.new('my cool jit') G_LLVM_BUILDER = None G_NAMED_VALUES = {} G_LLVM_PASS_MANAGER = FunctionPassManager.new(G_LLVM_MODULE) G_LLVM_EXECUTOR = ExecutionEngine.new(G_LLVM_MODULE) G_BINOP_PRECEDENCE = {} llvm.core.load_library_permanently('/home/popolit/code/ibcl/putchard.so') llvm.core.load_library_permanently('/home/popolit/code/ibcl/intern.so') llvm.core.load_library_permanently('/home/popolit/code/ibcl/repr.so') llvm.core.load_library_permanently('/home/popolit/code/ibcl/eq.so') llvm.core.load_library_permanently('/home/popolit/code/ibcl/cons.so') llvm.core.load_library_permanently('/home/popolit/code/ibcl/atom.so') llvm.core.load_library_permanently('/home/popolit/code/ibcl/carcdr.so') llvm.core.load_library_permanently('/home/popolit/code/ibcl/read.so') llvm.core.load_library_permanently('/home/popolit/code/ibcl/length.so') llvm.core.load_library_permanently( '/home/popolit/code/ibcl/find_llvm_function.so')
__author__ = 'jesse' from llvm.core import Constant, Type, Module, Function, Builder, FCMP_ULT from llvm.passes import FunctionPassManager from llvm.ee import ExecutionEngine g_llvm_module = Module.new("my cool jit") g_llvm_builder = None g_named_values = {} g_llvm_pass_manager = FunctionPassManager.new(g_llvm_module) g_llvm_executor = ExecutionEngine.new(g_llvm_module) class ExpressionNode(object): pass class NumberExpressionNode(ExpressionNode): def __init__(self, value): self.value = value def code_gen(self): return Constant.real(Type.double(), self.value) class VariableExpressionNode(ExpressionNode): def __init__(self, name): self.name = name def code_gen(self): if self.name in g_named_values: return g_named_values[self.name]
import re from llvm.core import Module, Constant, Type, Function, Builder, FCMP_ULT from llvm.ee import ExecutionEngine, TargetData from llvm.passes import FunctionPassManager from llvm.passes import (PASS_INSTRUCTION_COMBINING, PASS_REASSOCIATE, PASS_GVN, PASS_CFG_SIMPLIFICATION) # Globals g_llvm_module = Module.new('my cool jit') g_llvm_builder = None g_named_values = {} g_llvm_pass_manager = FunctionPassManager.new(g_llvm_module) g_llvm_executor = ExecutionEngine.new(g_llvm_module) class EOFToken(object): pass class DefToken(object): pass class ExternToken(object): pass class IdentifierToken(object): def __init__(self, name): self.name = name