Ejemplo n.º 1
0
def peval(input_file,
          output_file,
          llpe_analysis,
          log=None,
          trail=None,
          **opts):
    "intra module previrtualization"
    if not trail:
        opt = tempfile.NamedTemporaryFile(suffix='.bc', delete=False)
        pre = tempfile.NamedTemporaryFile(suffix='.bc', delete=False)
        done = tempfile.NamedTemporaryFile(suffix='.bc', delete=False)
        opt.close()
        pre.close()
        done.close()

        if llpe_analysis:
            args = [
                '-load=%s' % config.LLPE_MAIN,
                '-load=%s' % config.LLPE_DRIVER, '-loop-simplify', '-lcssa',
                '-llpe', '-llpe-omit-checks', '-llpe-single-threaded',
                input_file,
                '-o=%s' % done.name
            ]

            run("opt", args)
            shutil.copy(done.name, input_file)

        #pre_args=[config.LLVM['opt'], '-load=%s' % config.OCCAM_LIB,
        #          opt.name, '-o=%s' % done.name,
        #          '-Ppeval']

        out = ['']

        shutil.copy(input_file, done.name)
        while True:
            retcode = optimize(done.name, opt.name, **opts)
            if retcode != 0:
                # TODO: an error occurred
                shutil.copy(done.name, output_file)
                return retcode

            if previrt_progress(opt.name, done.name, ['-Ppeval'], output=out):
                print "previrt successful"
                if log is not None:
                    log.write(out[0])
            else:
                break
        shutil.move(opt.name, output_file)
        try:
            os.unlink(done.name)
            os.unlink(pre.name)
        except:
            pass
        return retcode
    else:
        assert False
Ejemplo n.º 2
0
def peval(input_file, output_file, llpe_analysis, log=None, trail=None, **opts):
    "intra module previrtualization"
    if not trail:
        opt  = tempfile.NamedTemporaryFile(suffix='.bc', delete=False)
        pre  = tempfile.NamedTemporaryFile(suffix='.bc', delete=False)
        done = tempfile.NamedTemporaryFile(suffix='.bc', delete=False)
        opt.close()
        pre.close()
        done.close()
        
        
        if llpe_analysis:
	    args=['-load=%s' % config.LLPE_MAIN, '-load=%s' % config.LLPE_DRIVER,              
                  '-loop-simplify', '-lcssa', '-llpe', '-llpe-omit-checks', '-llpe-single-threaded', input_file, '-o=%s' % done.name]       
	 
	    run("opt", args)	
	    shutil.copy(done.name, input_file)		
	
	
        #pre_args=[config.LLVM['opt'], '-load=%s' % config.OCCAM_LIB,
        #          opt.name, '-o=%s' % done.name,
        #          '-Ppeval']
        
        out = ['']
        
        shutil.copy(input_file, done.name)
        while True:
            retcode = optimize(done.name, opt.name, **opts)
            if retcode != 0:
                # TODO: an error occurred
                shutil.copy(done.name, output_file)
                return retcode

            if previrt_progress(opt.name, done.name, ['-Ppeval'], 
                                output=out):
                print "previrt successful"
                if log is not None:
                    log.write(out[0])
            else:
                break
        shutil.move(opt.name, output_file)
        try:
            os.unlink(done.name)
            os.unlink(pre.name)
        except:
            pass
        return retcode
    else:
        assert False
Ejemplo n.º 3
0
def peval(input_file, output_file, log=None, trail=None, **opts):
    "intra module previrtualization"
    if not trail:
        opt = tempfile.NamedTemporaryFile(suffix='.bc', delete=False)
        pre = tempfile.NamedTemporaryFile(suffix='.bc', delete=False)
        done = tempfile.NamedTemporaryFile(suffix='.bc', delete=False)
        opt.close()
        pre.close()
        done.close()

        #        pre_args=[config.getLLVMTool('opt'), '-load=%s' % config.getOccamLib(),
        #                  opt.name, '-o=%s' % done.name,
        #                  '-Ppeval']

        out = ['']

        shutil.copy(input_file, done.name)
        while True:
            retcode = optimize(done.name, opt.name, **opts)
            if retcode != 0:
                # TODO: an error occurred
                shutil.copy(done.name, output_file)
                return retcode

            if previrt_progress(opt.name, done.name, ['-Ppeval'], output=out):
                print "previrt successful"
                if log is not None:
                    log.write(out[0])
            else:
                break

        print "Moving %s to %s" % (opt.name, output_file)
        shutil.move(opt.name, output_file)
        try:
            os.unlink(done.name)
            os.unlink(pre.name)
        except:
            pass
        return retcode
    else:
        assert False
Ejemplo n.º 4
0
def peval(input_file, output_file, log=None, trail=None, **opts):
    "intra module previrtualization"
    if not trail:
        opt  = tempfile.NamedTemporaryFile(suffix='.bc', delete=False)
        pre  = tempfile.NamedTemporaryFile(suffix='.bc', delete=False)
        done = tempfile.NamedTemporaryFile(suffix='.bc', delete=False)
        opt.close()
        pre.close()
        done.close()
        
        pre_args=[config.getLLVMTool('opt'), '-load=%s' % config.getOccamLib(),
                  opt.name, '-o=%s' % done.name,
                  '-Ppeval']
        
        out = ['']
        
        shutil.copy(input_file, done.name)
        while True:
            retcode = optimize(done.name, opt.name, **opts)
            if retcode != 0:
                # TODO: an error occurred
                shutil.copy(done.name, output_file)
                return retcode

            if previrt_progress(opt.name, done.name, ['-Ppeval'], 
                                output=out):
                print "previrt successful"
                if log is not None:
                    log.write(out[0])
            else:
                break
        shutil.move(opt.name, output_file)
        try:
            os.unlink(done.name)
            os.unlink(pre.name)
        except:
            pass
        return retcode
    else:
        assert False
Ejemplo n.º 5
0
def intern(input_file, output_file, interfaces, **opts):
    "strips unused symbols"
    return previrt_progress(input_file, output_file,
                            ['-Poccam'] + 
                            all_args('-Poccam-input', interfaces), 
                            **opts)
Ejemplo n.º 6
0
def rewrite(input_file, output_file, rewrites, debug=None, **opts):
    "inter module rewriting"
    return previrt_progress(input_file, output_file,
                            ['-Prewrite'] + 
                            all_args('-Prewrite-input', rewrites), 
                            **opts)
Ejemplo n.º 7
0
def intern(input_file, output_file, interfaces, **opts):
    "strips unused symbols"
    return previrt_progress(input_file, output_file, ['-Poccam'] +
                            all_args('-Poccam-input', interfaces), **opts)
Ejemplo n.º 8
0
def rewrite(input_file, output_file, rewrites, debug=None, **opts):
    "inter module rewriting"
    return previrt_progress(input_file, output_file, ['-Prewrite'] +
                            all_args('-Prewrite-input', rewrites), **opts)