]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/include/llvm/CodeGen/Register.h
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / llvm / include / llvm / CodeGen / Register.h
1 //===-- llvm/CodeGen/Register.h ---------------------------------*- C++ -*-===//
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 #ifndef LLVM_CODEGEN_REGISTER_H
10 #define LLVM_CODEGEN_REGISTER_H
11
12 #include <cassert>
13
14 namespace llvm {
15
16 /// Wrapper class representing virtual and physical registers. Should be passed
17 /// by value.
18 class Register {
19   unsigned Reg;
20
21 public:
22   Register(unsigned Val = 0): Reg(Val) {}
23
24   /// Return true if the specified register number is in the virtual register
25   /// namespace.
26   bool isVirtual() const {
27     return int(Reg) < 0;
28   }
29
30   /// Return true if the specified register number is in the physical register
31   /// namespace.
32   bool isPhysical() const {
33     return int(Reg) > 0;
34   }
35
36   /// Convert a virtual register number to a 0-based index. The first virtual
37   /// register in a function will get the index 0.
38   unsigned virtRegIndex() const {
39     assert(isVirtual() && "Not a virtual register");
40     return Reg & ~(1u << 31);
41   }
42
43   /// Convert a 0-based index to a virtual register number.
44   /// This is the inverse operation of VirtReg2IndexFunctor below.
45   static Register index2VirtReg(unsigned Index) {
46     return Register(Index | (1u << 31));
47   }
48
49   operator unsigned() const {
50     return Reg;
51   }
52
53   bool isValid() const {
54     return Reg != 0;
55   }
56 };
57
58 }
59
60 #endif