Illegalize rbp/r13 for zero-offset loads on Intel x64 (#225)

* Switch RegClass to a bitmap implementation.

* Add special RegClass to remove r13 from 'ld' recipe.

* Use MASK_LEN constant instead of magic number.

* Enforce that RegClass slicing is only valid on contiguous classes.

* Use Optional[int] for RegClass optional bitmask parameter.

* Add comment explaining use of Intel ISA's GPR_NORIP register class.
This commit is contained in:
Tyler McMullen
2018-01-16 21:05:53 -07:00
committed by Jakob Stoklund Olesen
parent 1e2b7de141
commit eb85aa833c
4 changed files with 77 additions and 36 deletions

View File

@@ -11,7 +11,8 @@ from base.formats import IntCompare, FloatCompare, IntCond, FloatCond
from base.formats import Jump, Branch, BranchInt, BranchFloat
from base.formats import Ternary, FuncAddr, UnaryGlobalVar
from base.formats import RegMove, RegSpill, RegFill, CopySpecial
from .registers import GPR, ABCD, FPR, GPR8, FPR8, FLAG, StackGPR32, StackFPR32
from .registers import GPR, ABCD, FPR, GPR_NORIP, GPR8, FPR8, GPR8_NORIP
from .registers import FLAG, StackGPR32, StackFPR32
from .defs import supported_floatccs
from .settings import use_sse41
@@ -103,6 +104,7 @@ def replace_put_op(emit, prefix):
# Register class mapping for no-REX instructions.
NOREX_MAP = {
GPR: GPR8,
GPR_NORIP: GPR8_NORIP,
FPR: FPR8
}
@@ -766,7 +768,7 @@ frsp32 = TailRecipe(
# XX /r load with no offset.
ld = TailRecipe(
'ld', Load, size=1, ins=(GPR), outs=(GPR),
'ld', Load, size=1, ins=(GPR_NORIP), outs=(GPR),
instp=IsEqual(Load.offset, 0),
clobbers_flags=False,
emit='''

View File

@@ -47,6 +47,9 @@ FlagRegs = RegBank(
GPR = RegClass(IntRegs)
GPR8 = GPR[0:8]
# In certain instructions, RBP and R13 are interpreted as RIP-relative.
GPR_NORIP = GPR.without(GPR.rbp, GPR.r13)
GPR8_NORIP = GPR8.without(GPR.rbp)
ABCD = GPR[0:4]
FPR = RegClass(FloatRegs)
FPR8 = FPR[0:8]