[llvm-commits] [llvm] r123252 - in /llvm/trunk/utils/Target: ./ ARM/ ARM/analyze-match-table.py

Chris Lattner clattner at apple.com
Tue Jan 11 17:43:33 PST 2011


On Jan 11, 2011, at 11:06 AM, Daniel Dunbar wrote:

> Author: ddunbar
> Date: Tue Jan 11 13:06:26 2011
> New Revision: 123252
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=123252&view=rev
> Log:
> McARM: Write a silly Python script to compute some hard coded info from the
> generated ARM match table, which is substantially more efficient than dealing
> with tblgen.

Is this a short term hack?  This is really gross.

-Chris


> 
> Added:
>    llvm/trunk/utils/Target/
>    llvm/trunk/utils/Target/ARM/
>    llvm/trunk/utils/Target/ARM/analyze-match-table.py
> 
> Added: llvm/trunk/utils/Target/ARM/analyze-match-table.py
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/Target/ARM/analyze-match-table.py?rev=123252&view=auto
> ==============================================================================
> --- llvm/trunk/utils/Target/ARM/analyze-match-table.py (added)
> +++ llvm/trunk/utils/Target/ARM/analyze-match-table.py Tue Jan 11 13:06:26 2011
> @@ -0,0 +1,61 @@
> +#!/usr/bin/env python
> +
> +def analyze_match_table(path):
> +    # Extract the instruction table.
> +    data = open(path).read()
> +    start = data.index("static const MatchEntry MatchTable")
> +    end = data.index("\n};\n", start)
> +    lines = data[start:end].split("\n")[1:]
> +
> +    # Parse the instructions.
> +    insns = []
> +    for ln in lines:
> +        ln = ln.split("{", 1)[1]
> +        ln = ln.rsplit("}", 1)[0]
> +        a,bc = ln.split("{", 1)
> +        b,c = bc.split("}", 1)
> +        code, string, converter, _ = [s.strip()
> +                                      for s in a.split(",")]
> +        items = [s.strip() for s in b.split(",")]
> +        _,features = [s.strip() for s in c.split(",")]
> +        assert string[0] == string[-1] == '"'
> +        string = string[1:-1]
> +        insns.append((code,string,converter,items,features))
> +
> +    # For every mnemonic, compute whether or not it can have a carry setting
> +    # operand and whether or not it can have a predication code.
> +    mnemonic_flags = {}
> +    for insn in insns:
> +        mnemonic = insn[1]
> +        items = insn[3]
> +        flags = mnemonic_flags[mnemonic] = mnemonic_flags.get(mnemonic, set())
> +        flags.update(items)
> +
> +    mnemonics = set(mnemonic_flags)
> +    ccout_mnemonics = set(m for m in mnemonics
> +                          if 'MCK_CCOut' in mnemonic_flags[m])
> +    condcode_mnemonics = set(m for m in mnemonics
> +                             if 'MCK_CondCode' in mnemonic_flags[m])
> +    noncondcode_mnemonics = mnemonics - condcode_mnemonics
> +    print ' || '.join('Mnemonic == "%s"' % m
> +                      for m in ccout_mnemonics)
> +    print ' || '.join('Mnemonic == "%s"' % m
> +                      for m in noncondcode_mnemonics)
> +
> +def main():
> +    import sys
> +    if len(sys.argv) == 1:
> +        import os
> +        from lit.Util import capture
> +        llvm_obj_root = capture(["llvm-config", "--obj-root"])
> +        file = os.path.join(llvm_obj_root,
> +                            "lib/Target/ARM/ARMGenAsmMatcher.inc")
> +    elif len(sys.argv) == 2:
> +        file = sys.argv[1]
> +    else:
> +        raise NotImplementedError
> +
> +    analyze_match_table(file)
> +
> +if __name__ == '__main__':
> +    main()
> 
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits





More information about the llvm-commits mailing list