Advanced Micro Devices Inc. agreed to buy Xilinx Inc. for $35 billion in stock, one of the largest chip acquisitions ever, a transaction that gives the former industry also-ran more products and a bigger research budget to challenge leader Intel Corp.