don't use memset for temps unless necessary
This commit is contained in:
parent
5cb60ffbe0
commit
32d2327be0
1 changed files with 10 additions and 7 deletions
|
|
@ -370,14 +370,17 @@ proc resetLoc(p: BProc, loc: var TLoc) =
|
||||||
# on the bytes following the m_type field?
|
# on the bytes following the m_type field?
|
||||||
genObjectInit(p, cpsStmts, loc.t, loc, true)
|
genObjectInit(p, cpsStmts, loc.t, loc, true)
|
||||||
|
|
||||||
proc constructLoc(p: BProc, loc: TLoc, section = cpsStmts) =
|
proc constructLoc(p: BProc, loc: TLoc, isTemp = false) =
|
||||||
if not isComplexValueType(skipTypes(loc.t, abstractRange)):
|
if not isComplexValueType(skipTypes(loc.t, abstractRange)):
|
||||||
linefmt(p, section, "$1 = 0;$n", rdLoc(loc))
|
linefmt(p, cpsStmts, "$1 = 0;$n", rdLoc(loc))
|
||||||
else:
|
else:
|
||||||
useStringh(p.module)
|
if not isTemp or containsGarbageCollectedRef(loc.t):
|
||||||
linefmt(p, section, "memset((void*)$1, 0, sizeof($2));$n",
|
# don't use memset for temporary values for performance if we can
|
||||||
addrLoc(loc), rdLoc(loc))
|
# avoid it:
|
||||||
genObjectInit(p, section, loc.t, loc, true)
|
useStringh(p.module)
|
||||||
|
linefmt(p, cpsStmts, "memset((void*)$1, 0, sizeof($2));$n",
|
||||||
|
addrLoc(loc), rdLoc(loc))
|
||||||
|
genObjectInit(p, cpsStmts, loc.t, loc, true)
|
||||||
|
|
||||||
proc initLocalVar(p: BProc, v: PSym, immediateAsgn: bool) =
|
proc initLocalVar(p: BProc, v: PSym, immediateAsgn: bool) =
|
||||||
if sfNoInit notin v.flags:
|
if sfNoInit notin v.flags:
|
||||||
|
|
@ -403,7 +406,7 @@ proc getTemp(p: BProc, t: PType, result: var TLoc) =
|
||||||
result.t = getUniqueType(t)
|
result.t = getUniqueType(t)
|
||||||
result.s = OnStack
|
result.s = OnStack
|
||||||
result.flags = {}
|
result.flags = {}
|
||||||
constructLoc(p, result)
|
constructLoc(p, result, isTemp=true)
|
||||||
|
|
||||||
proc keepAlive(p: BProc, toKeepAlive: TLoc) =
|
proc keepAlive(p: BProc, toKeepAlive: TLoc) =
|
||||||
when false:
|
when false:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue