1 //===-- llvm/CodeGen/Register.h ---------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_CODEGEN_REGISTER_H
10 #define LLVM_CODEGEN_REGISTER_H
16 /// Wrapper class representing virtual and physical registers. Should be passed
22 Register(unsigned Val
= 0): Reg(Val
) {}
24 /// Return true if the specified register number is in the virtual register
26 bool isVirtual() const {
30 /// Return true if the specified register number is in the physical register
32 bool isPhysical() const {
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);
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));
49 operator unsigned() const {
53 bool isValid() const {