Beispiel #1
0
def composition_test():
    print("Composition Test")
    p = nest()
    xform = ASTXform(p)
    print("Input Program")
    print(xform.codegen())
    # Dimensions
    dim  = 2
    # Type of dimensions
    dim_type = [1, 2]

    # code-motion 
    alp1  = [['e', 'r1', 't1'], ['e', 'r2l', 'r2r', 's1']]
    ord1  = [['e', 't1', 'r1'], ['e', 'r2l', 'r2r', 's1']]
    ord2  = [['e', 't1', 'r1'], ['e', 's1', 'r2l', 'r2r']]

    xf1 = Transformation(
        name         = 'cm',
        in_dim       = dim,
        out_dim      = dim,
        in_dim_type  = dim_type,
        in_alp       = alp1,
        in_ord       = ord1,
        out_ord      = ord2)
    xform.transform(xf1)
    
    # Interchange
    dim1_ = 0
    dim2_ = 1
    
    xf2 = Transformation(
        name         ='ic',
        in_dim       = xf1.out_dim,
        out_dim      = xf1.out_dim,
        in_dim_type  = xf1.out_dim_type,
        in_alp       = xf1.out_alp,
        in_ord       = xf1.out_ord,
        dim_i1       = dim1_,
        dim_i2       = dim2_)
    xform.transform(xf2)
    
    # Inline
    dim_il   = 1
    call_il  = 1
    label_il = 'n'
    
    xf3 = Transformation(
        name        = 'il',
        in_dim      = xf2.out_dim,
        out_dim     = xf2.out_dim,
        in_dim_type = xf2.out_dim_type,
        in_alp      = xf2.out_alp,
        in_ord      = xf2.out_ord,
        dim_inline  = dim_il,
        call_inline = call_il,
        label       = label_il)
    xform.transform(xf3)
    
    print("Output Program")
    print(xform.codegen())
Beispiel #2
0
def deptest_cm_ic():
    print("CM-IC Test")
    # Dimensions
    dim  = 2
    # Type of dimensions
    dim_type = [1, 2]

    # code-motion 
    alp1  = [['e', 'r1', 't1'], ['e', 'r2l', 'r2r', 's1']]
    ord1  = [['e', 't1', 'r1'], ['e', 'r2l', 'r2r', 's1']]
    ord2  = [['e', 't1', 'r1'], ['e', 's1', 'r2l', 'r2r']]

    xform1 = Transformation(
        name         = 'cm',
        in_dim       = dim,
        out_dim      = dim,
        in_dim_type  = dim_type,
        in_alp       = alp1,
        in_ord       = ord1,
        out_ord      = ord2)
    
    # interchange
    dim1_ = 0
    dim2_ = 1
    
    xform2 = Transformation(
        name         ='ic',
        in_dim       = xform1.out_dim,
        out_dim      = xform1.out_dim,
        in_dim_type  = xform1.out_dim_type,
        in_alp       = xform1.out_alp,
        in_ord       = xform1.out_ord,
        dim_i1       = dim1_,
        dim_i2       = dim2_)
    
    xform = xform1.compose(xform2)
    
    # regex for witness tuple    
    rgx1 = [['t1'], ['s1']]
    rgx2 = [['r1', 't1'], ['(r2l|r2r)', 's1']]
    
    wtuple1 = WitnessTuple(dim, dim_type, alp1, ord1, rgx1, rgx2)
    wtuple1.set_fsa()

    Dep1 = Dependence(wtuple1)

    print("Tuple1: ", Dep1.test(xform))
    
    rgx3 = [['t1'], ['(r2l|r2r)', 's1']]
    rgx4 = [['t1'], ['s1']]
    
    wtuple2 = WitnessTuple(dim, dim_type, alp1, ord1, rgx3, rgx4)
    wtuple2.set_fsa()

    Dep2 = Dependence(wtuple2)

    print("Tuple2: ", Dep2.test(xform))
Beispiel #3
0
def deptest_cm_ic(filename):
    print("CM-IC Test")
    with open(filename, "r") as source:
        # reading the c file
        parser = c_parser.CParser()
        astc = parser.parse(source.read())
        # convert to python
        pysrc = CtoPy(astc)
        tree = ast.parse(pysrc.getPy())
        analyze = Analyze(tree)
        xform = Transform(analyze)
        # Input program
        print("\nInput Program")
        print(xform.codegen())
        # Dimensions
        in_dim  = xform.analyze.dims
        out_dim = in_dim
        # Type of dimensions
        in_dim_type = xform.analyze.getdimtype()
        # Input alphabet and order
        in_alp = xform.analyze.getalp()
        in_ord = xform.analyze.getord()
        # Output order
        out_ord = [['e', 't1', 'r1'], ['e', 's1', 'r2l', 'r2r']]
        
        xf1 = Transformation(
            name         = 'cm',
            in_dim       = in_dim,
            out_dim      = out_dim,
            in_dim_type  = in_dim_type,
            in_alp       = in_alp,
            in_ord       = in_ord,
            out_ord      = out_ord)

        # interchange
        dim1_ = 0
        dim2_ = 1

        xf2 = Transformation(
            name         ='ic',
            in_dim       = xf1.out_dim,
            out_dim      = xf1.out_dim,
            in_dim_type  = xf1.out_dim_type,
            in_alp       = xf1.out_alp,
            in_ord       = xf1.out_ord,
            dim_i1       = dim1_,
            dim_i2       = dim2_)

        xf = xf1.compose(xf2)

        xform.analyze.depanalyze()
        
        print(xform.analyze.deps)
        for i, wt in enumerate(xform.analyze.deps):
            Dep = Dependence(wt)
            print("Witness Tuple", i, ": ", Dep.test(xf))
Beispiel #4
0
def composition_test(filename):
    print("Composition Test")
    with open(filename, "r") as source:
        tree = ast.parse(source.read())
        analyze = Analyze(tree)
        xform = Transform(analyze)

        # Input program
        print("\nInput Program")
        print(xform.codegen())
        # Dimensions
        in_dim = xform.analyze.dims
        out_dim = in_dim
        # Type of dimensions
        in_dim_type = xform.analyze.getdimtype()
        # Input alphabet and order
        in_alp = xform.analyze.getalp()
        in_ord = xform.analyze.getord()

        # code-motion
        out_ord = [['e', 't1', 'r1'], ['e', 's1', 'r2l', 'r2r']]

        xf1 = Transformation(name='cm',
                             in_dim=in_dim,
                             out_dim=out_dim,
                             in_dim_type=in_dim_type,
                             in_alp=in_alp,
                             in_ord=in_ord,
                             out_ord=out_ord)
        xform.transform(xf1)

        # interchange
        dim1 = 0
        dim2 = 1

        xf2 = Transformation(name='ic',
                             in_dim=xf1.out_dim,
                             out_dim=xf1.out_dim,
                             in_dim_type=xf1.out_dim_type,
                             in_alp=xf1.out_alp,
                             in_ord=xf1.out_ord,
                             dim_i1=dim1,
                             dim_i2=dim2)
        xform.transform(xf2)

        # Output program
        print("\nOutput Program")
        print(xform.codegen())
Beispiel #5
0
def il_test(filename):
    print("Inlining Test")
    with open(filename, "r") as source:
        tree = ast.parse(source.read())
        analyze = Analyze(tree)
        xform = Transform(analyze)
        # Input program
        print("\nInput Program")
        print(xform.codegen())
        # Dimensions
        in_dim = xform.analyze.dims
        out_dim = in_dim
        # Type of dimensions
        in_dim_type = xform.analyze.getdimtype()
        # Input alphabet and order
        in_alp = xform.analyze.getalp()
        in_ord = xform.analyze.getord()
        # Transform
        xf = Transformation(name='il',
                            in_dim=in_dim,
                            out_dim=out_dim,
                            in_dim_type=in_dim_type,
                            in_alp=in_alp,
                            in_ord=in_ord,
                            dim_inline=1,
                            call_inline=1,
                            label='l')
        xform.transform(xf)
        # Output program
        print("\nOutput Program")
        print(xform.codegen())
Beispiel #6
0
def cm_test(filename):
    print("Code Motion Test")
    with open(filename, "r") as source:
        tree = ast.parse(source.read())
        analyze = Analyze(tree)
        xform = Transform(analyze)
        # Input program
        print("\nInput Program")
        print(xform.codegen())
        # Dimensions
        in_dim = xform.analyze.dims
        out_dim = in_dim
        # Type of dimensions
        in_dim_type = xform.analyze.getdimtype()
        # Input alphabet and order
        in_alp = xform.analyze.getalp()
        in_ord = xform.analyze.getord()
        # Output order
        out_ord = [['e', 't1', 'r1'], ['e', 's1', 'r2l', 'r2r']]
        # Transform
        xf = Transformation(name='cm',
                            in_dim=in_dim,
                            out_dim=out_dim,
                            in_dim_type=in_dim_type,
                            in_alp=in_alp,
                            in_ord=in_ord,
                            out_ord=out_ord)
        xform.transform(xf)
        # Output program
        print("\nOutput Program")
        print(xform.codegen())
Beispiel #7
0
def deptest_sm():
    print("Strip-Mining Test")
    # Dimensions
    in_dim  = 2
    out_dim = 3
    # Type of dimensions
    in_dim_type  = [1, 2]
    # Input alphabet and order
    in_alp  = [['e', 'r1', 't1'], ['e', 'r2l', 'r2r', 's1']]
    in_ord  = [['e', 't1', 'r1'], ['e', 'r2l', 'r2r', 's1']]
    # strip dimension 
    strip_dim  = 0
    # strip size
    strip_size = 2

    xform = Transformation(
        name        = 'sm',
        in_dim      = in_dim, 
        out_dim     = out_dim, 
        in_dim_type = in_dim_type, 
        in_alp      = in_alp, 
        in_ord      = in_ord, 
        dim_strip   = strip_dim, 
        strip_size  = strip_size)

    # regex for witness tuple    
    rgx1 = [['t1'], ['s1']]
    rgx2 = [['r1', '(r1)*', 't1'], ['s1']]
    
    wtuple = WitnessTuple(in_dim, in_dim_type, in_alp, in_ord, rgx1, rgx2)
    wtuple.set_fsa()

    Dep = Dependence(wtuple)

    print(Dep.test(xform))
Beispiel #8
0
def deptest_il():
    print("Inlining Test")
    # Dimensions
    in_dim  = 2
    out_dim = 2
    # Type of dimensions
    in_dim_type  = [1, 2]
    # Input alphabet and order
    in_alp  = [['e', 'r1', 't1'], ['e', 'r2l', 'r2r', 's1']]
    in_ord  = [['e', 't1', 'r1'], ['e', 'r2l', 'r2r', 's1']]

    xform = Transformation(
        name        = 'il',
        in_dim      = in_dim,
        out_dim     = out_dim,
        in_dim_type = in_dim_type,
        in_alp      = in_alp,
        in_ord      = in_ord,
        dim_inline  = 1,
        call_inline = 1,
        label       = 'l')

    # regex for witness tuple    
    rgx1 = [['t1'], ['s1']]
    rgx2 = [['r1', '(r1)*', 't1'], ['s1']]
    
    wtuple = WitnessTuple(in_dim, in_dim_type, in_alp, in_ord, rgx1, rgx2)
    wtuple.set_fsa()

    Dep = Dependence(wtuple)

    print(Dep.test(xform))
Beispiel #9
0
def sm_test():
    print("Strip Mining Test")
    p = nest()
    xform = ASTXform(p)    
    print("Input Program")
    print(xform.codegen())
    # Dimensions
    in_dim  = 2
    out_dim = 3
    # Type of dimensions
    in_dim_type  = [1, 2]
    # Input alphabet and order
    in_alp  = [['e', 'r1', 't1'], ['e', 'r2l', 'r2r', 's1']]
    in_ord  = [['e', 't1', 'r1'], ['e', 'r2l', 'r2r', 's1']]
    # strip dimension 
    strip_dim  = 0
    # strip size
    strip_size = 2

    xf = Transformation(
        name        = 'sm',
        in_dim      = in_dim, 
        out_dim     = out_dim, 
        in_dim_type = in_dim_type, 
        in_alp      = in_alp, 
        in_ord      = in_ord, 
        dim_strip   = strip_dim, 
        strip_size  = strip_size)
    
    xform.transform(xf)
    
    print("Output Program")
    print(xform.codegen())
Beispiel #10
0
def il_test():
    print("Code Motion Test")
    p = nest()
    xform = ASTXform(p)
    print("Input Program")
    print(xform.codegen())   
    # Dimensions
    in_dim  = 2
    out_dim = 2
    # Type of dimensions
    in_dim_type  = [1, 2]
    # Input alphabet and order
    in_alp  = [['e', 'r1', 't1'], ['e', 'r2l', 'r2r', 's1']]
    in_ord  = [['e', 't1', 'r1'], ['e', 'r2l', 'r2r', 's1']]

    xf = Transformation(
        name        = 'il',
        in_dim      = in_dim,
        out_dim     = out_dim,
        in_dim_type = in_dim_type,
        in_alp      = in_alp,
        in_ord      = in_ord,
        dim_inline  = 1,
        call_inline = 1,
        label       = 'l')
    xform.transform(xf)
    
    print("Output Program")
    print(xform.codegen())
Beispiel #11
0
def sm_test(filename):
    print("Strip Mining Test")
    with open(filename, "r") as source:
        tree = ast.parse(source.read())
        analyze = Analyze(tree)
        xform = Transform(analyze)
        # Input program
        print("\nInput Program")
        print(xform.codegen())
        # Dimensions
        in_dim = xform.analyze.dims
        out_dim = in_dim + 1
        # Type of dimensions
        in_dim_type = xform.analyze.getdimtype()
        # Input alphabet and order
        in_alp = xform.analyze.getalp()
        in_ord = xform.analyze.getord()
        # strip dimension
        strip_dim = 0
        # strip size
        strip_size = 2
        # Transform
        xf = Transformation(name='sm',
                            in_dim=in_dim,
                            out_dim=out_dim,
                            in_dim_type=in_dim_type,
                            in_alp=in_alp,
                            in_ord=in_ord,
                            dim_strip=strip_dim,
                            strip_size=strip_size)
        xform.transform(xf)
        # Output program
        print("\nOutput Program")
        print(xform.codegen())
Beispiel #12
0
def ic_test(filename):
    print("Interchange Test")
    with open(filename, "r") as source:
        # reading the c file
        parser = c_parser.CParser()
        astc = parser.parse(source.read())
        # convert to python
        pysrc = CtoPy(astc)
        tree = ast.parse(pysrc.getPy())
        analyze = Analyze(tree)
        xform = Transform(analyze)
        # Input program
        print("\nInput Program")
        print(xform.codegen())
        # Dimensions
        in_dim = xform.analyze.dims
        out_dim = in_dim
        # Type of dimensions
        in_dim_type = xform.analyze.getdimtype()
        # Input alphabet and order
        in_alp = xform.analyze.getalp()
        in_ord = xform.analyze.getord()
        # Transform
        xf = Transformation(name='ic',
                            in_dim=in_dim,
                            out_dim=out_dim,
                            in_dim_type=in_dim_type,
                            in_alp=in_alp,
                            in_ord=in_ord,
                            dim_i1=0,
                            dim_i2=1)
        xform.transform(xf)
        # Output program
        print("\nOutput Program")
        print(xform.codegen())
Beispiel #13
0
def ic_test():
    print("Interchange Test")
    p = nest()
    xform = ASTXform(p)
    print("Input Program")
    print(xform.codegen())
    # Dimensions
    in_dim  = 2
    out_dim = 2
    # Type of dimensions
    in_dim_type  = [1, 2]
    # Input alphabet and order
    in_alp  = [['e', 'r1', 't1'], ['e', 'r2l', 'r2r', 's1']]
    in_ord  = [['e', 't1', 'r1'], ['e', 's1', 'r2l', 'r2r']]

    xf = Transformation(
        name         ='ic',
        in_dim       = in_dim,
        out_dim      = out_dim,
        in_dim_type  = in_dim_type,
        in_alp       = in_alp,
        in_ord       = in_ord,
        dim_i1       = 0,
        dim_i2       = 1)
    xform.transform(xf)
    
    print("Output Program")
    print(xform.codegen())
Beispiel #14
0
    def next_pic(
        xf
    ):  # takes transformation and returns a list of next possible xforms that are interchange
        nxt_xfs = []
        for d in range(xf.out_dim - 1):
            xf_ = Transformation(name='ic',
                                 in_dim=xf.out_dim,
                                 out_dim=xf.out_dim,
                                 in_dim_type=xf.out_dim_type,
                                 in_alp=xf.out_alp,
                                 in_ord=xf.out_ord,
                                 dim_i1=d,
                                 dim_i2=d + 1)
            nxt_xfs.append(xf_)

        return nxt_xfs
Beispiel #15
0
    def next_pcm(
        xf
    ):  # takes transformation and returns a list of next possible xforms that are code motion
        nxt_xfs = []
        out_ords = Completion.ord_permutation(xf.out_ord, xf.out_dim)
        for out_ord in out_ords:
            xf_ = Transformation(name='cm',
                                 in_dim=xf.out_dim,
                                 out_dim=xf.out_dim,
                                 in_dim_type=xf.out_dim_type,
                                 in_alp=xf.out_alp,
                                 in_ord=xf.out_ord,
                                 out_ord=out_ord)
            nxt_xfs.append(xf_)

        return nxt_xfs
Beispiel #16
0
    def next_pil(xf, d):
        assert xf.out_dim - 1 == d

        ncalls = xf.out_dim_type[d]
        nxt_xfs = []
        for c in range(1, ncalls + 1):
            xf_ = Transformation(name='il',
                                 in_dim=xf.out_dim,
                                 out_dim=xf.out_dim,
                                 in_dim_type=xf.out_dim_type,
                                 in_alp=xf.out_alp,
                                 in_ord=xf.out_ord,
                                 dim_inline=d,
                                 call_inline=c,
                                 label='il' + str(c))
            nxt_xfs.append(xf_)

        return nxt_xfs
Beispiel #17
0
def deptest_cm():   
    print("Code Motion Test")
    # Dimensions
    in_dim  = 2
    out_dim = 2
    # Type of dimensions
    in_dim_type  = [1, 2]
    # Input alphabet and order
    in_alp  = [['e', 'r1', 't1'], ['e', 'r2l', 'r2r', 's1']]
    in_ord  = [['e', 't1', 'r1'], ['e', 'r2l', 'r2r', 's1']]
    # Output order
    out_ord = [['e', 't1', 'r1'], ['e', 's1', 'r2l', 'r2r']]

    xform = Transformation(
        name         ='cm',
        in_dim       = in_dim,
        out_dim      = out_dim,
        in_dim_type  = in_dim_type,
        in_alp       = in_alp,
        in_ord       = in_ord,
        out_ord      = out_ord)

    # regex for witness tuple    
    rgx1 = [['t1'], ['s1']]
    rgx2 = [['r1', 't1'], ['(r2l|r2r)', 's1']]
    
    wtuple1 = WitnessTuple(in_dim, in_dim_type, in_alp, in_ord, rgx1, rgx2)
    wtuple1.set_fsa()

    Dep1 = Dependence(wtuple1)

    print("Tuple1: ", Dep1.test(xform))
    
    rgx3 = [['t1'], ['(r2l|r2r)', 's1']]
    rgx4 = [['t1'], ['s1']]
    
    wtuple2 = WitnessTuple(in_dim, in_dim_type, in_alp, in_ord, rgx3, rgx4)
    wtuple2.set_fsa()

    Dep2 = Dependence(wtuple2)

    print("Tuple2: ", Dep2.test(xform))
Beispiel #18
0
def deptest_ic(filename):
    print("Interchange Test")
    with open(filename, "r") as source:
        # reading the c file
        parser = c_parser.CParser()
        astc = parser.parse(source.read())
        # convert to python
        pysrc = CtoPy(astc)
        tree = ast.parse(pysrc.getPy())
        analyze = Analyze(tree)
        xform = Transform(analyze)
        # Input program
        print("\nInput Program")
        print(xform.codegen())
        # Dimensions
        in_dim  = xform.analyze.dims
        out_dim = in_dim
        # Type of dimensions
        in_dim_type = xform.analyze.getdimtype()
        # Input alphabet and order
        in_alp = xform.analyze.getalp()
        in_ord = xform.analyze.getord()

        xf = Transformation(
            name         ='ic',
            in_dim       = in_dim,
            out_dim      = out_dim,
            in_dim_type  = in_dim_type,
            in_alp       = in_alp,
            in_ord       = in_ord,
            dim_i1       = 0,
            dim_i2       = 1)
    
        xform.analyze.depanalyze()
        print(xform.analyze.getdeps())
        for i, wt in enumerate(xform.analyze.deps):
            Dep = Dependence(wt)
            print("Witness Tuple", i, ": ", Dep.test(xf))
Beispiel #19
0
def cm_sm_ic_test(filename):
    print("CM-SM-IC Test")
    with open(filename, "r") as source:
        # reading the c file
        parser = c_parser.CParser()
        astc = parser.parse(source.read())
        # convert to python
        pysrc = CtoPy(astc)
        tree = ast.parse(pysrc.getPy())
        analyze = Analyze(tree)
        xform = Transform(analyze)
        # Input program
        print("\nInput Program")
        print(xform.codegen())

        # code-motion
        # Dimensions
        in_dim = xform.analyze.dims
        out_dim = in_dim
        # Type of dimensions
        in_dim_type = xform.analyze.getdimtype()
        # Input alphabet and order
        in_alp = xform.analyze.getalp()
        in_ord = xform.analyze.getord()
        # Output order
        out_ord = [['e', 't1', 'r1'], ['e', 's1', 'r2l', 'r2r']]
        xf1 = Transformation(name='cm',
                             in_dim=in_dim,
                             out_dim=out_dim,
                             in_dim_type=in_dim_type,
                             in_alp=in_alp,
                             in_ord=in_ord,
                             out_ord=out_ord)
        xform.transform(xf1)

        # strip mining
        # strip dimension
        strip_dim = 0
        # strip size
        strip_size = 2
        # Transform
        xf2 = Transformation(name='sm',
                             in_dim=xf1.out_dim,
                             out_dim=xf1.out_dim + 1,
                             in_dim_type=xf1.in_dim_type,
                             in_alp=xf1.out_alp,
                             in_ord=xf1.out_ord,
                             dim_strip=strip_dim,
                             strip_size=strip_size)
        xform.transform(xf2)

        # interchange
        # dimensions
        dim1 = 1
        dim2 = 2
        xf3 = Transformation(name='ic',
                             in_dim=xf2.out_dim,
                             out_dim=xf2.out_dim,
                             in_dim_type=xf2.out_dim_type,
                             in_alp=xf2.out_alp,
                             in_ord=xf2.out_ord,
                             dim_i1=dim1,
                             dim_i2=dim2)
        xform.transform(xf3)
        # Output program
        print("\nOutput Program")
        print(xform.codegen())
Beispiel #20
0
def deptest():
    # Dimensions
    dim = 2
    # Type of dimensions
    dim_type = [1, 2]

    # code-motion
    alp1 = [['e', 'r1', 't1'], ['e', 'r2l', 'r2r', 's1']]
    ord1 = [['e', 't1', 'r1'], ['e', 'r2l', 'r2r', 's1']]
    ord2 = [['e', 't1', 'r1'], ['e', 's1', 'r2l', 'r2r']]

    xform1 = Transformation(name='cm',
                            in_dim=dim,
                            out_dim=dim,
                            in_dim_type=dim_type,
                            in_alp=alp1,
                            in_ord=ord1,
                            out_ord=ord2)

    # Strip Mining
    strip_dim = 0
    strip_size = 2

    xform2 = Transformation(name='sm',
                            in_dim=xform1.out_dim,
                            out_dim=xform1.out_dim + 1,
                            in_dim_type=xform1.out_dim_type,
                            in_alp=xform1.out_alp,
                            in_ord=xform1.out_ord,
                            dim_strip=strip_dim,
                            strip_size=strip_size)

    # Interchange
    dim1_ = 1
    dim2_ = 2

    xform3 = Transformation(name='ic',
                            in_dim=xform2.out_dim,
                            out_dim=xform2.out_dim,
                            in_dim_type=xform2.out_dim_type,
                            in_alp=xform2.out_alp,
                            in_ord=xform2.out_ord,
                            dim_i1=dim1_,
                            dim_i2=dim2_)

    # Inline
    dim_il = 1
    call_il = 1
    label_il = 'l'

    xform4 = Transformation(name='il',
                            in_dim=xform3.out_dim,
                            out_dim=xform3.out_dim,
                            in_dim_type=xform3.out_dim_type,
                            in_alp=xform3.out_alp,
                            in_ord=xform3.out_ord,
                            dim_inline=dim_il,
                            call_inline=call_il,
                            label=label_il)

    xform = xform1.compose(xform2).compose(xform3).compose(xform4)

    # regex for witness tuple
    rgx1 = [['t1'], ['s1']]
    rgx2 = [['r1', '(r1)*', 't1'], ['s1']]

    print("suffix1: ", rgx1)
    print("suffix2: ", rgx2)

    wtuple = WitnessTuple(dim, dim_type, alp1, ord1, rgx1, rgx2)
    wtuple.set_fsa()

    Dep = Dependence(wtuple)

    print("Input Program")
    xform.input_program()
    print("Output Program")
    xform.output_program()

    if Dep.test(xform):
        print("Dependence is preserved")
    else:
        print("Dependence is broken")
Beispiel #21
0
def trans():
    # Dimensions
    dim = 2
    # Type of dimensions
    dim_type = [1, 2]

    # code-motion
    alp1 = [['e', 'r1', 't1'], ['e', 'r2l', 'r2r', 's1']]
    ord1 = [['e', 't1', 'r1'], ['e', 'r2l', 'r2r', 's1']]
    ord2 = [['e', 't1', 'r1'], ['e', 's1', 'r2l', 'r2r']]

    xform1 = Transformation(name='cm',
                            in_dim=dim,
                            out_dim=dim,
                            in_dim_type=dim_type,
                            in_alp=alp1,
                            in_ord=ord1,
                            out_ord=ord2)

    # Strip Mining
    strip_dim = 0
    strip_size = 2

    xform2 = Transformation(name='sm',
                            in_dim=xform1.out_dim,
                            out_dim=xform1.out_dim + 1,
                            in_dim_type=xform1.out_dim_type,
                            in_alp=xform1.out_alp,
                            in_ord=xform1.out_ord,
                            dim_strip=strip_dim,
                            strip_size=strip_size)

    # Interchange
    dim1_ = 1
    dim2_ = 2

    xform3 = Transformation(name='ic',
                            in_dim=xform2.out_dim,
                            out_dim=xform2.out_dim,
                            in_dim_type=xform2.out_dim_type,
                            in_alp=xform2.out_alp,
                            in_ord=xform2.out_ord,
                            dim_i1=dim1_,
                            dim_i2=dim2_)

    # Inline
    dim_il = 1
    call_il = 1
    label_il = 'l'

    xform4 = Transformation(name='il',
                            in_dim=xform3.out_dim,
                            out_dim=xform3.out_dim,
                            in_dim_type=xform3.out_dim_type,
                            in_alp=xform3.out_alp,
                            in_ord=xform3.out_ord,
                            dim_inline=dim_il,
                            call_inline=call_il,
                            label=label_il)

    xform = xform1.compose(xform2).compose(xform3).compose(xform4)

    xform.input_program()
    print("\nTransformation: ", xform.name)
    xform.output_program()
Beispiel #22
0
    def completion_search(self):
        # stage 1
        init_xfs = []  # initial cm ic and il transformations
        out_ords = Completion.ord_permutation(
            self.in_ord,
            self.in_dim)  # all possible different combinations of cm xforms
        for out_ord in out_ords:
            xf = Transformation(name='cm',
                                in_dim=self.in_dim,
                                out_dim=self.in_dim,
                                in_dim_type=self.in_dim_type,
                                in_alp=self.in_alp,
                                in_ord=self.in_ord,
                                out_ord=out_ord)

            if self.check_match(xf.out_ord):  #cover cm
                self.pxforms.append([xf])
            else:
                init_xfs.append([xf])

        if self.use_ic:
            for d in range(self.in_dim - 1):
                xf = Transformation(name='ic',
                                    in_dim=self.in_dim,
                                    out_dim=self.in_dim,
                                    in_dim_type=self.in_dim_type,
                                    in_alp=self.in_alp,
                                    in_ord=self.in_ord,
                                    dim_i1=d,
                                    dim_i2=d + 1)

                if self.check_match(xf.out_ord):  #cover ic
                    self.pxforms.append([xf])
                else:
                    init_xfs.append([xf])

        if self.use_il:
            ncalls = self.in_dim_type[self.in_dim - 1]
            for c in range(1, ncalls + 1):
                xf = Transformation(name='il',
                                    in_dim=self.in_dim,
                                    out_dim=self.in_dim,
                                    in_dim_type=self.in_dim_type,
                                    in_alp=self.in_alp,
                                    in_ord=self.in_ord,
                                    dim_inline=self.in_dim - 1,
                                    call_inline=c,
                                    label='il' + str(c))

                if self.check_match(xf.out_ord):  #cover il
                    self.pxforms.append([xf])
                else:
                    init_xfs.append([xf])
        # stage 2
        init_xfs_ = []
        for xfs in init_xfs:
            nxfs1 = []
            nxfs2 = []
            if xfs[-1].name == "cm":
                nxfs1 = Completion.next_pic(xfs[-1])
                nxfs2 = Completion.next_pil(xfs[-1], xfs[-1].out_dim - 1)
            elif xfs[-1].name == "ic":
                nxfs1 = Completion.next_pcm(xfs[-1])
                nxfs2 = Completion.next_pil(xfs[-1], xfs[-1].out_dim - 1)

            for xf_ in nxfs1:
                if self.check_match(xf_.out_ord):  #cover cm-ic and ic-cm
                    self.pxforms.append(xfs + [xf_])
                else:
                    init_xfs_.append(xfs + [xf_])

            if self.use_il:
                for xf_ in nxfs2:
                    if self.check_match(xf_.out_ord):  #cover cm-il and ic-il
                        self.pxforms.append(xfs + [xf_])
                    else:
                        init_xfs_.append(xfs + [xf_])
        # stage 3
        if self.use_il:
            for xfs in init_xfs_:  #covering cm-ic-il and ic-cm-il
                if xfs[-1].name != "il":
                    nxfs = Completion.next_pil(xfs[-1], xfs[-1].out_dim - 1)
                    for xf_ in nxfs:
                        if self.check_match(xf_.out_ord):
                            self.pxforms.append(xfs + [xf_])
Beispiel #23
0
def deptest_cm_sm_ic_il():
    print("CM-SM-IC-IL Test")
    # Dimensions
    dim  = 2
    # Type of dimensions
    dim_type = [1, 2]

    # code-motion 
    alp1  = [['e', 'r1', 't1'], ['e', 'r2l', 'r2r', 's1']]
    ord1  = [['e', 't1', 'r1'], ['e', 'r2l', 'r2r', 's1']]
    ord2  = [['e', 't1', 'r1'], ['e', 's1', 'r2l', 'r2r']]

    xform1 = Transformation(
        name         = 'cm',
        in_dim       = dim,
        out_dim      = dim,
        in_dim_type  = dim_type,
        in_alp       = alp1,
        in_ord       = ord1,
        out_ord      = ord2)

    # Strip Mining
    strip_dim  = 0
    strip_size = 2

    xform2 = Transformation(
        name        = 'sm',
        in_dim      = xform1.out_dim,
        out_dim     = xform1.out_dim+1,
        in_dim_type = xform1.out_dim_type,
        in_alp      = xform1.out_alp,
        in_ord      = xform1.out_ord,
        dim_strip   = strip_dim,
        strip_size  = strip_size)

    # Interchange
    dim1_ = 1
    dim2_ = 2
    
    xform3 = Transformation(
        name         ='ic',
        in_dim       = xform2.out_dim,
        out_dim      = xform2.out_dim,
        in_dim_type  = xform2.out_dim_type,
        in_alp       = xform2.out_alp,
        in_ord       = xform2.out_ord,
        dim_i1       = dim1_,
        dim_i2       = dim2_)

    # Inline
    dim_il   = 1
    call_il  = 1
    label_il = 'l'
    
    xform4 = Transformation(
        name        = 'il',
        in_dim      = xform3.out_dim,
        out_dim     = xform3.out_dim,
        in_dim_type = xform3.out_dim_type,
        in_alp      = xform3.out_alp,
        in_ord      = xform3.out_ord,
        dim_inline  = dim_il,
        call_inline = call_il,
        label       = label_il)

    xform = xform1.compose(xform2).compose(xform3).compose(xform4)
    
    # regex for witness tuple    
    rgx1 = [['t1'], ['s1']]
    rgx2 = [['r1', '(r1)*', 't1'], ['s1']]
    
    wtuple = WitnessTuple(dim, dim_type, alp1, ord1, rgx1, rgx2)
    wtuple.set_fsa()

    Dep = Dependence(wtuple)

    print(Dep.test(xform))