Check-in [c50485d110]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Finish expunging the uses of 'uniqueUndef' in constructing phis.
Timelines: family | ancestors | descendants | both | kbk-phi-reform
Files: files | file ages | folders
SHA3-256:c50485d110e44e36dfafb8b1da8e86b96825c5561af4e6ed71fb498663941e8c
User & Date: kbk 2018-04-17 00:06:56
Context
2018-04-17
00:09
Finish expunging the uses of 'uniqueUndef' in constructing phis. check-in: f71cdfbdae user: kbk tags: trunk
00:06
Finish expunging the uses of 'uniqueUndef' in constructing phis. Closed-Leaf check-in: c50485d110 user: kbk tags: kbk-phi-reform
2018-04-16
04:17
More purges of uniqueUndef check-in: c9c75024dc user: kbk tags: kbk-phi-reform
Changes

Changes to codegen/build.tcl.

7100
7101
7102
7103
7104
7105
7106
7107
7108
7109
7110
7111
7112
7113
7114
7115
7116
7117
7118
7119
7120
7121
7122
7123
7124
7125
7126
7127
7128
7129
7130
7131
7132
7133
7134
7135
7136
    # Results:
    #	A NUMERIC LLVM value reference.

    method uminus(NUMERIC) {value {name ""}} {
	my call ${tcl.neg.numeric} [list $value] $name
    }

    # Builder:uniqueUndef --
    #
    #	Create a unique undefined value. This is designed so that it can be
    #	replaced later on when fixing up a loop's back-references at a phi
    #	node.
    #
    # Parameters:
    #	type -	Type (LLVM or name) of undef to create.
    #	name (optional) -
    #		The name of the result value.
    #
    # Results:
    #	LLVM undef value that is guaranteed distinct from all others.

    method uniqueUndef {type {name ""}} {
	set type [Type $type]
	set n2 $name
	if {$n2 ne ""} {
	    set n2 &$n2
	}
	my load [my alloc $type $n2] $name
    }

    # Builder:unshare(STRING) --
    #
    #	Generate a writable buffer by "unsharing" a STRING. This examines the
    #	reference counts and applies Tcl_DuplicateObj if required; the result
    #	*may* be the original value.
    #
    # Parameters:







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







7100
7101
7102
7103
7104
7105
7106























7107
7108
7109
7110
7111
7112
7113
    # Results:
    #	A NUMERIC LLVM value reference.

    method uminus(NUMERIC) {value {name ""}} {
	my call ${tcl.neg.numeric} [list $value] $name
    }
























    # Builder:unshare(STRING) --
    #
    #	Generate a writable buffer by "unsharing" a STRING. This examines the
    #	reference counts and applies Tcl_DuplicateObj if required; the result
    #	*may* be the original value.
    #
    # Parameters:

Changes to codegen/stdlib.tcl.

1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
....
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
....
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
....
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423

2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
....
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511

2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
....
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805

2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
	# in the string 'trim' (length 'numTrim'). Works on UTF-8.

	set f [$m local "tcl.impl.trimright" int<-char*,int,char*,int readonly]
	params bytes numBytes trim numTrim
	build {
	    nonnull $bytes $trim
	    set chVar [my alloc int16]
	    set nbLoop [my uniqueUndef int "nb"]
	    set p0 [my getelementptr $bytes [list $numBytes] "p.0"]
	    my condBr [my eq $numBytes $0] $ret0 $checkTrim
	label checkTrim:
	    my condBr [my eq $numTrim $0] $ret0 $outerLoop
	label ret0:
	    my ret $0
	label outerLoop:
................................................................................
		    [my mult $strLen $sizeof(Tcl_UniChar)]]
	    set wsres [my select [my eq $cmp $0] $targetObj $stringObj]
	    my br $done
	label map:
	    lassign [my GetUnicode $targetObj "target"] tgtLen tgtPtr
	    set result [$api Tcl_NewUnicodeObj $strPtr $0]
	    set srcPtr0 [my load $srcPtr]
	    set prevLoop [my uniqueUndef [TypeOf $strPtr] "prev"]
	    set curLoop [my uniqueUndef [TypeOf $strPtr] "cur"]
	    set end [my getelementptr $strPtr [list $strLen]]
	    my br $maplooptest1
	label maplooptest1 "map.loop.test"
	    set sources [list $map $maploopnext]
	    set cur [my phi [list $strPtr $curLoop] $sources "cur"]
	    set prev [my phi [list $strPtr $prevLoop] $sources "prev"]
	    my condBr [my lt $cur $end] $maplooptest2 $mapdone
	label maplooptest2 "map.loop.test"
	    my condBr [my eq [my load $cur] $srcPtr0] \
		$maplooptest3 $maploopnext
	label maplooptest3 "map.loop.test"
	    my condBr [my eq $srcLen $1] $maplooptest5 $maplooptest4
	label maplooptest4 "map.loop.test"
................................................................................
	    set cur2 [my getelementptr $prev3 [list ${-1}] "cur"]
	    $api Tcl_AppendUnicodeToObj $result $tgtPtr $tgtLen
	    my br $maploopnext
	label maploopnext "map.loop.next"
	    set sources [list $maplooptest2 $maplooptest4 $maploopbody3]
	    set prev4 [my phi [list $prev $prev $prev3] $sources "prev"]
	    set cur3 [my phi [list $cur $cur $cur2] $sources "cur"]
	    ReplaceAllUsesWith $prevLoop $prev4
	    ReplaceAllUsesWith $curLoop \
		[my getelementptr $cur3 [list $1] "cur"]
	    my br $maplooptest1
	label mapdone "map.done"
	    my assume [my not [my shared $result]]
	    my condBr [my eq $prev $cur] $done $maplast
	label maplast "map.addLast"
	    $api Tcl_AppendUnicodeToObj $result $prev \
		[my cast(int) [my diff $cur $prev] "len"]
................................................................................
	    set listPtr [my load [my cast(ptr) \
		    [my gep $list 0 Tcl_Obj.internalRep 0] \
		    TclList*] "listPtr"]
	    my condBr [my eq [my dereference $listPtr 0 TclList.refCount] $1] \
		$sublistInplace $sublistNew
	label sublistInplace "sublist.inPlace"
	    set onePast [my add $to $1 "onePast"]
	    set loopIndex [my uniqueUndef int "index"]
	    my br $sublistInplaceFreeTest
	label sublistInplaceFreeTest "sublist.inPlace.loop.test"
	    set sources [list $sublistInplace $sublistInplaceFree]
	    set index [my phi [list $onePast $loopIndex] $sources "index"]

	    my condBr [my lt $index $objc] \
		$sublistInplaceFree $sublistInplaceDone
	label sublistInplaceFree "sublist.inPlace.loop.body"
	    ReplaceAllUsesWith $loopIndex [my add $index $1 "index"]
	    set obj [my load [my getelementptr $objv [list $index]] "objPtr"]
	    my dropReference $obj
	    my br $sublistInplaceFreeTest
	label sublistInplaceDone "sublist.inPlace.done"
	    my storeInStruct $listPtr TclList.elemCount $onePast
	    my storeInStruct $listPtr TclList.canonicalFlag $1
	    $api TclInvalidateStringRep $list
................................................................................
	    set listPtr [my load [my cast(ptr) \
		    [my gep $list 0 Tcl_Obj.internalRep 0] \
		    TclList*] "listPtr"]
	    my condBr [my eq [my dereference $listPtr 0 TclList.refCount] $1] \
		$sublistInplace $sublistNew
	label sublistInplace "sublist.inPlace"
	    set onePast [my add $to $1 "onePast"]
	    set loopIndex [my uniqueUndef int "index"]
	    my br $sublistInplaceFreeTest
	label sublistInplaceFreeTest "sublist.inPlace.free.test"
	    set sources [list $sublistInplace $sublistInplaceFree]
	    set index [my phi [list $onePast $loopIndex] $sources "index"]

	    my condBr [my lt $index $objc] \
		$sublistInplaceFree $sublistInplaceDone
	label sublistInplaceFree "sublist.inPlace.free"
	    ReplaceAllUsesWith $loopIndex [my add $index $1 "index"]
	    set obj [my load [my getelementptr $objv [list $index]] "objPtr"]
	    my dropReference $obj
	    my br $sublistInplaceFreeTest
	label sublistInplaceDone "sublist.inPlace.done"
	    my storeInStruct $listPtr TclList.elemCount $onePast
	    my storeInStruct $listPtr TclList.canonicalFlag $1
	    $api TclInvalidateStringRep $list
................................................................................
	    set lenVar [my alloc int]
	    set objvVar [my alloc STRING*]
	    set code [$api Tcl_ListObjGetElements $interp $list $lenVar $objvVar]
	    my condBr [my eq $code $0] $realCheck $fail
	label realCheck:
	    set objc [my load $lenVar "objc"]
	    set objv [my load $objvVar "objv"]
	    set iLoop [my uniqueUndef int "i"]
	    my condBr [my gt $objc $0] $loop $done
	label loop:
	    set i [my phi [list $0 $iLoop] [list $realCheck $loopNext] "i"]

	    set obj [my load [my getelementptr $objv [list $i]] "obj"]
	    lassign [my GetString $obj "element"] len2 bytes2
	    my condBr [my eq $len1 $len2] $loopCompare $loopNext
	label loopCompare:
	    my condBr [my eq [my memcmp $bytes1 $bytes2 $len1] $0] \
		$done $loopNext
	label loopNext:
	    ReplaceAllUsesWith $iLoop [set i [my add $i $1 "i"]]
	    my condBr [my lt $i $objc] $loop $done
	label fail:
	    my store $1 $ecVar
	    my ret [my fail ZEROONE]
	label done:
	    set flag [my phi [list [Const false bool] [Const false bool] [Const true bool]] \
		    [list $realCheck $loopNext $loopCompare] "flag"]







<







 







<
<



|
|
|







 







|
<
|







 







<


|
<
>



|







 







<


|
<
>



|







 







<


<
>







|







1033
1034
1035
1036
1037
1038
1039

1040
1041
1042
1043
1044
1045
1046
....
1771
1772
1773
1774
1775
1776
1777


1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
....
1806
1807
1808
1809
1810
1811
1812
1813

1814
1815
1816
1817
1818
1819
1820
1821
....
2408
2409
2410
2411
2412
2413
2414

2415
2416
2417

2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
....
2495
2496
2497
2498
2499
2500
2501

2502
2503
2504

2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
....
2789
2790
2791
2792
2793
2794
2795

2796
2797

2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
	# in the string 'trim' (length 'numTrim'). Works on UTF-8.

	set f [$m local "tcl.impl.trimright" int<-char*,int,char*,int readonly]
	params bytes numBytes trim numTrim
	build {
	    nonnull $bytes $trim
	    set chVar [my alloc int16]

	    set p0 [my getelementptr $bytes [list $numBytes] "p.0"]
	    my condBr [my eq $numBytes $0] $ret0 $checkTrim
	label checkTrim:
	    my condBr [my eq $numTrim $0] $ret0 $outerLoop
	label ret0:
	    my ret $0
	label outerLoop:
................................................................................
		    [my mult $strLen $sizeof(Tcl_UniChar)]]
	    set wsres [my select [my eq $cmp $0] $targetObj $stringObj]
	    my br $done
	label map:
	    lassign [my GetUnicode $targetObj "target"] tgtLen tgtPtr
	    set result [$api Tcl_NewUnicodeObj $strPtr $0]
	    set srcPtr0 [my load $srcPtr]


	    set end [my getelementptr $strPtr [list $strLen]]
	    my br $maplooptest1
	label maplooptest1 "map.loop.test"
	    set sources {$map $maploopnext}
	    set cur [PHI [TypeOf $strPtr] {$strPtr $curLoop} $sources "cur"]
	    set prev [PHI [TypeOf $strPtr] {$strPtr $prevLoop} $sources "prev"]
	    my condBr [my lt $cur $end] $maplooptest2 $mapdone
	label maplooptest2 "map.loop.test"
	    my condBr [my eq [my load $cur] $srcPtr0] \
		$maplooptest3 $maploopnext
	label maplooptest3 "map.loop.test"
	    my condBr [my eq $srcLen $1] $maplooptest5 $maplooptest4
	label maplooptest4 "map.loop.test"
................................................................................
	    set cur2 [my getelementptr $prev3 [list ${-1}] "cur"]
	    $api Tcl_AppendUnicodeToObj $result $tgtPtr $tgtLen
	    my br $maploopnext
	label maploopnext "map.loop.next"
	    set sources [list $maplooptest2 $maplooptest4 $maploopbody3]
	    set prev4 [my phi [list $prev $prev $prev3] $sources "prev"]
	    set cur3 [my phi [list $cur $cur $cur2] $sources "cur"]
	    set prevLoop $prev4

	    set curLoop [my getelementptr $cur3 [list $1] "cur"]
	    my br $maplooptest1
	label mapdone "map.done"
	    my assume [my not [my shared $result]]
	    my condBr [my eq $prev $cur] $done $maplast
	label maplast "map.addLast"
	    $api Tcl_AppendUnicodeToObj $result $prev \
		[my cast(int) [my diff $cur $prev] "len"]
................................................................................
	    set listPtr [my load [my cast(ptr) \
		    [my gep $list 0 Tcl_Obj.internalRep 0] \
		    TclList*] "listPtr"]
	    my condBr [my eq [my dereference $listPtr 0 TclList.refCount] $1] \
		$sublistInplace $sublistNew
	label sublistInplace "sublist.inPlace"
	    set onePast [my add $to $1 "onePast"]

	    my br $sublistInplaceFreeTest
	label sublistInplaceFreeTest "sublist.inPlace.loop.test"
	    set sources {$sublistInplace $sublistInplaceFree}

	    set index [PHI [Type int32] {$onePast $loopIndex} $sources "index"]
	    my condBr [my lt $index $objc] \
		$sublistInplaceFree $sublistInplaceDone
	label sublistInplaceFree "sublist.inPlace.loop.body"
	    set loopIndex [my add $index $1 "index"]
	    set obj [my load [my getelementptr $objv [list $index]] "objPtr"]
	    my dropReference $obj
	    my br $sublistInplaceFreeTest
	label sublistInplaceDone "sublist.inPlace.done"
	    my storeInStruct $listPtr TclList.elemCount $onePast
	    my storeInStruct $listPtr TclList.canonicalFlag $1
	    $api TclInvalidateStringRep $list
................................................................................
	    set listPtr [my load [my cast(ptr) \
		    [my gep $list 0 Tcl_Obj.internalRep 0] \
		    TclList*] "listPtr"]
	    my condBr [my eq [my dereference $listPtr 0 TclList.refCount] $1] \
		$sublistInplace $sublistNew
	label sublistInplace "sublist.inPlace"
	    set onePast [my add $to $1 "onePast"]

	    my br $sublistInplaceFreeTest
	label sublistInplaceFreeTest "sublist.inPlace.free.test"
	    set sources {$sublistInplace $sublistInplaceFree}

	    set index [PHI [Type int32] {$onePast $loopIndex} $sources "index"]
	    my condBr [my lt $index $objc] \
		$sublistInplaceFree $sublistInplaceDone
	label sublistInplaceFree "sublist.inPlace.free"
	    set loopIndex [my add $index $1 "index"]
	    set obj [my load [my getelementptr $objv [list $index]] "objPtr"]
	    my dropReference $obj
	    my br $sublistInplaceFreeTest
	label sublistInplaceDone "sublist.inPlace.done"
	    my storeInStruct $listPtr TclList.elemCount $onePast
	    my storeInStruct $listPtr TclList.canonicalFlag $1
	    $api TclInvalidateStringRep $list
................................................................................
	    set lenVar [my alloc int]
	    set objvVar [my alloc STRING*]
	    set code [$api Tcl_ListObjGetElements $interp $list $lenVar $objvVar]
	    my condBr [my eq $code $0] $realCheck $fail
	label realCheck:
	    set objc [my load $lenVar "objc"]
	    set objv [my load $objvVar "objv"]

	    my condBr [my gt $objc $0] $loop $done
	label loop:

	    set i [PHI [Type int32] {$0 $iLoop} {$realCheck $loopNext} "i"]
	    set obj [my load [my getelementptr $objv [list $i]] "obj"]
	    lassign [my GetString $obj "element"] len2 bytes2
	    my condBr [my eq $len1 $len2] $loopCompare $loopNext
	label loopCompare:
	    my condBr [my eq [my memcmp $bytes1 $bytes2 $len1] $0] \
		$done $loopNext
	label loopNext:
	    set iLoop [set i [my add $i $1 "i"]]
	    my condBr [my lt $i $objc] $loop $done
	label fail:
	    my store $1 $ecVar
	    my ret [my fail ZEROONE]
	label done:
	    set flag [my phi [list [Const false bool] [Const false bool] [Const true bool]] \
		    [list $realCheck $loopNext $loopCompare] "flag"]