Skip to content

Instantly share code, notes, and snippets.

@vmiheer
Last active March 15, 2019 21:25
Show Gist options
  • Save vmiheer/1bfd5d4eadff59c9d230047fa970dc2c to your computer and use it in GitHub Desktop.
Save vmiheer/1bfd5d4eadff59c9d230047fa970dc2c to your computer and use it in GitHub Desktop.
Find set of spill locations from icc assembly output
# License: GPL
# Copyright: Miheer Vaidya (vaidya.56@osu.edu)
import sys
import re
def getSpillOffsets(f) -> set:
"""
Given file `f' returns set of offsets of spill locations
"""
pattern = re.compile(r".* (-?\d+\(%rsp\)).*")
pattern1 = re.compile(r".* (\(%rsp\)).*")
spillLine = re.compile(r".*\[spill\]")
s = set()
for line in f:
# icc annotates line with ending [spill] if that's not spill
# ignore that line
if not spillLine.match(line):
continue
# possibly it's rsp + offset
m = pattern.match(line)
if m:
s.add(m.group(1).split('(')[0])
continue
# possibly the offset could be empty i.e. rsp + 0
m = pattern1.match(line)
s.add(0)
# make sure one of the pattern matches!
assert(m)
return s
if __name__ == '__main__':
if len(sys.argv) == 2:
print("\n".join(map(str, getSpillOffsets(open(sys.argv[1])))))
else:
print("usage: {} infile".format(sys.argv[0]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment