Skip to content

Cache information gathered about external ids in getCgIdInfo.

In getCgIdInfo we lookup (or generate) information required by the code generator for Ids.

Local ids are already cached. However information about external Ids is instead recreated each time we come across them.

getCgIdInfo :: Id -> FCode CgIdInfo
getCgIdInfo id
  = do  { dflags <- getDynFlags
        ; local_binds <- getBinds -- Try local bindings first
        ; case lookupVarEnv local_binds id of {
            Just info -> return info ;
            Nothing   -> do {

                -- Should be imported; make up a CgIdInfo for it
          let name = idName id
        ; if isExternalName name then
              let ext_lbl
                      | isUnliftedType (idType id) =
                          -- An unlifted external Id must refer to a top-level
                          -- string literal. See Note [Bytes label] in CLabel.
                          ASSERT( idType id `eqType` addrPrimTy )
                          mkBytesLabel name
                      | otherwise = mkClosureLabel name $ idCafInfo id
              in return $
                  litIdInfo dflags id (mkLFImported id) (CmmLabel ext_lbl)
          else
              cgLookupPanic id -- Bug
        }}}

For GHC itself out of on average ~380 external Ids referenced per module over half are True/False/[], so this should definitely be worthwhile.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information