Ignore:
Timestamp:
Jun 30, 2014, 8:19:06 PM (5 years ago)
Author:
linmengl
Message:

add ValueTypes?.cpp, enable getTypesForEVT

File:
1 edited

Legend:

Unmodified
Added
Removed
  • parabix-LLVM/mkValueTypes.py

    r3859 r3904  
    1818    fws = []
    1919    while (fw <= maxwidth): fws.append(fw); fw = fw * 2
     20
    2021    enumVal = 0
    2122    VectorSizeMap = {}
     
    133134    """
    134135vecNumRe = re.compile("v([0-9]+)[if][0-9]+")
    135 
     136def getNumElement(typeString):
     137    """
     138    return number of elements in a type string
     139    e.g. return 32 in v32i1
     140    """
     141    m = vecNumRe.match(typeString)
     142    return int(m.group(1))
    136143
    137144def make_getVectorNumElements(VectorSizeMap):
     
    277284    f.close()
    278285
     286def make_getTypeForEVT(VectorSizeMap):
     287    res = ''
     288    for bitwidth in sorted(VectorSizeMap.keys()):
     289        for tpname in VectorSizeMap[bitwidth]:
     290            if 'f' in tpname:
     291                # only works on integer vectors
     292                continue
     293            num_elt = getNumElement(tpname)
     294            fieldtype = bitwidth / num_elt
     295            if fieldtype > 64 or fieldtype == 2 or fieldtype == 4:
     296                continue
     297            res += "  case MVT::{tpname}:   return VectorType::get(Type::getInt{fieldtype}Ty(Context), {num_elt});\n".format(
     298                    **{'tpname': tpname, 'fieldtype': fieldtype, 'num_elt': num_elt});
     299    return res
     300
     301def makeValueTypes_cpp(maxwidth, minwidth=32):
     302    f = open('ValueTypes.cpp.pytemplate')
     303    t = Template(f.read())
     304    f.close()
     305    (VTmap, VectorSizeMap, VectorFieldSizeMap) = calculateTypeData(maxwidth, minwidth)
     306    VTmap['get_type_for_vector_EVT'] = make_getTypeForEVT(VectorSizeMap)
     307    content = t.substitute(VTmap)
     308    if os.path.exists("ValueTypes.cpp") and  not os.path.exists("ValueTypes.cpp.bak"):
     309        shutil.move("ValueTypes.cpp", "ValueTypes.cpp.bak")
     310    f = open("ValueTypes.cpp", "w")
     311    f.write(content)
     312    f.close()
     313    print "ValueTypes.cpp generated."
     314
    279315if __name__ == '__main__':
    280316    makeMachineValueType_h(1024, 1)
    281317    makeValueTypes_td(1024, 1)
    282318    makeCodeGenTarget_cpp(1024, 1)
     319    makeValueTypes_cpp(1024, 1)
    283320    print "MachineValueType.h, CodeGenTarget.cpp and ValueTypes.td generated."
Note: See TracChangeset for help on using the changeset viewer.