1+ // ===-- NVPTXISelDAGToDAG.cpp - A dag to dag inst selector for NVPTX ------===//
2+ //
3+ // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+ // See https://llvm.org/LICENSE.txt for license information.
5+ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+ //
7+ // ===----------------------------------------------------------------------===//
8+ //
9+ // This file defines an instruction selector for the NVPTX target.
10+ //
11+ // ===----------------------------------------------------------------------===//
12+
13+ #include " NVPTXISelDAGToDAG.h"
14+ #include " NVPTX.h"
15+ #include " NVPTXUtilities.h"
16+ #include " llvm/ADT/APInt.h"
17+ #include " llvm/Analysis/ValueTracking.h"
18+ #include " llvm/CodeGen/ISDOpcodes.h"
19+ #include " llvm/CodeGen/SelectionDAG.h"
20+ #include " llvm/CodeGen/SelectionDAGNodes.h"
21+ #include " llvm/IR/GlobalValue.h"
22+ #include " llvm/IR/Instructions.h"
23+ #include " llvm/IR/IntrinsicsNVPTX.h"
24+ #include " llvm/IR/NVVMIntrinsicUtils.h"
25+ #include " llvm/Support/AtomicOrdering.h"
26+ #include " llvm/Support/CommandLine.h"
27+ #include " llvm/Support/ErrorHandling.h"
28+ #include " llvm/Support/FormatVariadic.h"
29+ #include < optional>
30+ using namespace llvm ;
31+
32+ namespace {
33+ class NVPTXRegCountPass : public MachineFunctionPass {
34+ public:
35+ static char ID;
36+ NVPTXRegCountPass () : MachineFunctionPass(ID) {}
37+
38+ bool runOnMachineFunction (MachineFunction &MF) override {
39+ unsigned maxRegs = 0 ;
40+ for (const MachineBasicBlock &MBB : MF) {
41+ unsigned liveRegs = 0 ;
42+ for (const MachineInstr &MI : MBB) {
43+ // Count unique virtual and physical registers
44+ for (const MachineOperand &MO : MI.operands ()) {
45+ if (MO.isReg () && MO.getReg ())
46+ liveRegs++;
47+ }
48+ }
49+ maxRegs = std::max (maxRegs, liveRegs);
50+ }
51+ errs () << " Function " << MF.getName () << " uses maximum of "
52+ << maxRegs << " registers\n " ;
53+ return false ;
54+ }
55+ };
56+ } // namespace
57+
58+ char NVPTXRegCountPass::ID = 0 ;
59+ // INITIALIZE_PASS(NVPTXRegCountPass, "nvptx-count-reg",
60+ // "NVPTX count reg", false, false)
61+
62+ FunctionPass *llvm::createNVPTXRegCountPass () {
63+ return new NVPTXRegCountPass ();
64+ }
0 commit comments