From ca3f9ad296a57c4b7c6cbd6495a6b7cbc1c65fe2 Mon Sep 17 00:00:00 2001 From: simonmar Date: Wed, 6 Sep 2000 12:21:15 +0000 Subject: [PATCH] [project @ 2000-09-06 12:21:15 by simonmar] When compiling code for a case where the scrutinee is a primitve comparison operator, we used to place the tag in a variable whose unique was always the same: `mkPseudoUnique1 1'. This was mostly harmless but confused the Stix inliner in the NCG into generating slightly less efficient code when the variable was used twice in a basic block. This patch fixes the problem by generating a new unique by just changing the "tag" of an existing unique, namely the case binder. --- ghc/compiler/basicTypes/Unique.lhs | 5 +++++ ghc/compiler/codeGen/CgCase.lhs | 13 +++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/ghc/compiler/basicTypes/Unique.lhs b/ghc/compiler/basicTypes/Unique.lhs index 5c76485..7d9c039 100644 --- a/ghc/compiler/basicTypes/Unique.lhs +++ b/ghc/compiler/basicTypes/Unique.lhs @@ -27,6 +27,7 @@ module Unique ( incrUnique, -- Used for renumbering deriveUnique, -- Ditto + newTagUnique, -- Used in CgCase initTyVarUnique, initTidyUniques, @@ -237,6 +238,7 @@ getKey :: Unique -> Int# -- for Var incrUnique :: Unique -> Unique deriveUnique :: Unique -> Int -> Unique +newTagUnique :: Unique -> Char -> Unique isTupleKey :: Unique -> Bool \end{code} @@ -254,6 +256,9 @@ incrUnique (MkUnique i) = MkUnique (i +# 1#) -- any of the uniques produced any other way deriveUnique (MkUnique i) delta = mkUnique 'X' (I# i + delta) +-- newTagUnique changes the "domain" of a unique to a different char +newTagUnique u c = mkUnique c i where (_,i) = unpkUnique u + -- pop the Char in the top 8 bits of the Unique(Supply) -- No 64-bit bugs here, as long as we have at least 32 bits. --JSM diff --git a/ghc/compiler/codeGen/CgCase.lhs b/ghc/compiler/codeGen/CgCase.lhs index d2fb33a..481ef02 100644 --- a/ghc/compiler/codeGen/CgCase.lhs +++ b/ghc/compiler/codeGen/CgCase.lhs @@ -1,7 +1,7 @@ % % (c) The GRASP/AQUA Project, Glasgow University, 1992-1998 % -% $Id: CgCase.lhs,v 1.45 2000/08/02 14:13:27 rrt Exp $ +% $Id: CgCase.lhs,v 1.46 2000/09/06 12:21:15 simonmar Exp $ % %******************************************************** %* * @@ -61,7 +61,7 @@ import TyCon ( TyCon, isEnumerationTyCon, isUnboxedTupleTyCon, ) import Type ( Type, typePrimRep, splitAlgTyConApp, splitTyConApp_maybe, repType ) -import Unique ( Unique, Uniquable(..), mkPseudoUnique1 ) +import Unique ( Unique, Uniquable(..), newTagUnique ) import Maybes ( maybeToBool ) import Util import Outputable @@ -143,9 +143,10 @@ alternatives (in which case we lookup the tag in the relevant closure table to get the closure). Being a bit short of uniques for temporary variables here, we use -mkPseudoUnique1 to generate a temporary for the tag. We can't use -mkBuiltinUnique, because that occasionally clashes with some -temporaries generated for _ccall_GC, amongst others (see CgExpr.lhs). +newTagUnique to generate a new unique from the case binder. The case +binder's unique will presumably have the 'c' tag (generated by +CoreToStg), so we just change its tag to 'C' (for 'case') to ensure it +doesn't clash with anything else. \begin{code} cgCase (StgPrimApp op args res_ty) @@ -155,7 +156,7 @@ cgCase (StgPrimApp op args res_ty) let tag_amode = case op of TagToEnumOp -> only arg_amodes - _ -> CTemp (mkPseudoUnique1{-see above-} 1) IntRep + _ -> CTemp (newTagUnique (getUnique bndr) 'C') IntRep closure = CVal (CIndex (CLbl (mkClosureTblLabel tycon) PtrRep) tag_amode PtrRep) PtrRep in -- 1.7.10.4