sharingCodeGen :: Reg -> Exp -> CG ()
sharingCodeGen shReg e = do
  forM_ nonLinearVars $ \name -> do
    -- For all non-linear variables set the locations as shared.
    nonLinearVarReg <- getReg name
    -- this will copy node field info as well, but we will only use "simpleType" info
    emit $ copyStructureWithPtrInfo nonLinearVarReg shReg

  mergedFields    <- newReg
  pointsToNodeReg <- newReg
  emit IR.Fetch
    { addressReg = shReg
    , dstReg     = pointsToNodeReg
    }
  emit IR.Project
    { srcReg      = pointsToNodeReg
    , srcSelector = IR.AllFields
    , dstReg      = mergedFields
    }
  emit $ copyStructureWithPtrInfo mergedFields shReg
  where
    nonLinearVars = calcNonLinearNonUpdateLocVariables e
sharingCodeGen :: Reg -> Exp -> CG ()
sharingCodeGen shReg e = do
  forM_ nonLinearVars $ \name -> do
    -- For all non-linear variables set the locations as shared.
    nonLinearVarReg <- getReg name
    -- this will copy node field info as well, but we will only use "simpleType" info
    emit $ copyStructureWithPtrInfo nonLinearVarReg shReg

  mergedFields    <- newReg
  pointsToNodeReg <- newReg
  emit IR.Fetch
    { addressReg = shReg
    , dstReg     = pointsToNodeReg
    }
  emit IR.Project
    { srcReg      = pointsToNodeReg
    , srcSelector = IR.AllFields
    , dstReg      = mergedFields
    }
  emit $ copyStructureWithPtrInfo mergedFields shReg
  where
    nonLinearVars = calcNonLinearNonUpdateLocVariables e
sharingCodeGen shReg e = do
  forM_ nonLinearVars $ \name -> do
    -- For all non-linear variables set the locations as shared.
    nonLinearVarReg <- getReg name
    -- this will copy node field info as well, but we will only use "simpleType" info
    emit $ copyStructureWithPtrInfo nonLinearVarReg shReg

  mergedFields    <- newReg
  pointsToNodeReg <- newReg
  emit IR.Fetch
    { addressReg = shReg
    , dstReg     = pointsToNodeReg
    }
  emit IR.Project
    { srcReg      = pointsToNodeReg
    , srcSelector = IR.AllFields
    , dstReg      = mergedFields
    }
  emit $ copyStructureWithPtrInfo mergedFields shReg
  where
    nonLinearVars = calcNonLinearNonUpdateLocVariables e