The rules are in ASC 260, Earnings Per Share, and the result is tagged in XBRL as WeightedAverageNumberOfDilutedSharesOutstanding. The difference from the basic count is tagged WeightedAverageNumberDilutedSharesOutstandingAdjustment, and the part coming from stock compensation is often shown as IncrementalCommonSharesAttributableToShareBasedPaymentArrangements.
Options and warrants are added using the treasury stock method. It assumes they are exercised and the proceeds are used to buy back shares at the average market price, so only the net new shares count, and only when the options are in the money. Convertible securities use the if-converted method: the shares they would convert into are added, and the related interest or preferred dividends are added back to the numerator. A security is left out entirely if including it would raise earnings per share. Such securities are called antidilutive and are disclosed separately.
This antidilution rule has a practical consequence. When a company reports a loss from continuing operations, adding shares would make the loss per share smaller, so diluted shares equal basic shares for that period. A company that swings from loss to profit can therefore show a jump in its diluted count with no new issuance. The gap between basic and diluted counts is a quick gauge of how much stock-based pay and convertible financing weigh on existing shareholders.