  We present the galaxy stellar mass function (MF) and its evolution in
clusters from z~0.8 to the current epoch, based on the WIde-field Nearby
Galaxy-cluster Survey (WINGS) (0.04<z<0.07), and the ESO Distant Cluster Survey
(EDisCS) (0.4<z <0.8). We investigate the total MF and find it evolves
noticeably with redshift. The shape at M*>10^11 M' does not evolve, but below
M*~10^10.8 M' the MF at high redshift is flat, while in the Local Universe it
flattens out at lower masses. The population of M* = 10^10.2 - 10^10.8 M'
galaxies must have grown significantly between z=0.8 and z=0. We analyze the MF
of different morphological types (ellipticals, S0s and late-types), and find
that also each of them evolves with redshift. All types have proportionally
more massive galaxies at high- than at low-z, and the strongest evolution
occurs among S0 galaxies. Examining the morphology-mass relation (the way the
proportion of galaxies of different morphological types changes with galaxy
mass), we find it strongly depends on redshift. At both redshifts, ~40% of the
stellar mass is in elliptical galaxies. Another ~43% of the mass is in S0
galaxies in local clusters, while it is in spirals in distant clusters. To
explain the observed trends, we discuss the importance of those mechanisms that
could shape the MF. We conclude that mass growth due to star formation plays a
crucial role in driving the evolution. It has to be accompanied by infall of
galaxies onto clusters, and the mass distribution of infalling galaxies might
be different from that of cluster galaxies. However, comparing with high-z
field samples, we do not find conclusive evidence for such an environmental
mass segregation. Our results suggest that star formation and infall change
directly the MF of late-type galaxies in clusters and, indirectly, that of
early-type galaxies through subsequent morphological transformations.
