Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions llvm/include/llvm/CodeGen/Register.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#define LLVM_CODEGEN_REGISTER_H

#include "llvm/MC/MCRegister.h"
#include "llvm/Support/MathExtras.h"
#include <cassert>

namespace llvm {
Expand All @@ -35,7 +36,10 @@ class Register {
// DenseMapInfo<unsigned> uses -1u and -2u.
static_assert(std::numeric_limits<decltype(Reg)>::max() >= 0xFFFFFFFF,
"Reg isn't large enough to hold full range.");
static constexpr unsigned FirstStackSlot = 1u << 30;
static constexpr unsigned MaxFrameIndexBitwidth = 30;
static constexpr unsigned FirstStackSlot = 1u << MaxFrameIndexBitwidth;
static const unsigned StackSlotMask =
(unsigned)(-1) >> (CHAR_BIT * sizeof(unsigned) - MaxFrameIndexBitwidth);
static_assert(FirstStackSlot >= MCRegister::LastPhysicalReg);
static constexpr unsigned VirtualRegFlag = 1u << 31;

Expand All @@ -46,8 +50,8 @@ class Register {

/// Convert a non-negative frame index to a stack slot register value.
static Register index2StackSlot(int FI) {
assert(FI >= 0 && "Cannot hold a negative frame index.");
return Register(FI + Register::FirstStackSlot);
assert(isInt<30>(FI) && "Frame index must be at most 30 bit integer");
return Register((FI & Register::StackSlotMask) | Register::FirstStackSlot);
}

/// Return true if the specified register number is in
Expand Down Expand Up @@ -87,7 +91,7 @@ class Register {
/// Compute the frame index from a register value representing a stack slot.
int stackSlotIndex() const {
assert(isStack() && "Not a stack slot");
return static_cast<int>(Reg - Register::FirstStackSlot);
return static_cast<int>(SignExtend64(Reg & Register::StackSlotMask, 30));
}

constexpr operator unsigned() const { return Reg; }
Expand Down
3 changes: 0 additions & 3 deletions llvm/lib/CodeGen/ReachingDefAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ void ReachingDefInfo::processDefs(MachineInstr *MI) {
for (auto &MO : MI->operands()) {
if (MO.isFI()) {
int FrameIndex = MO.getIndex();
assert(FrameIndex >= 0 && "Can't handle negative frame indicies yet!");
if (!isFIDef(*MI, FrameIndex, TII))
continue;
MBBFrameObjsReachingDefs[{MBBNumber, FrameIndex}].push_back(CurInstr);
Expand Down Expand Up @@ -302,8 +301,6 @@ void ReachingDefInfo::print(raw_ostream &OS) {
Register Reg;
if (MO.isFI()) {
int FrameIndex = MO.getIndex();
assert(FrameIndex >= 0 &&
"Can't handle negative frame indicies yet!");
Reg = Register::index2StackSlot(FrameIndex);
} else if (MO.isReg()) {
if (MO.isDef())
Expand Down