Skip to content

Commit dc95302

Browse files
author
Mikhail Gudim
committed
Negative frame indicies as register.
This is used by reaching definitions analysis in order to track stores / loads from negative frame indices.
1 parent 7287816 commit dc95302

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

llvm/include/llvm/CodeGen/Register.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#define LLVM_CODEGEN_REGISTER_H
1111

1212
#include "llvm/MC/MCRegister.h"
13+
#include "llvm/Support/MathExtras.h"
1314
#include <cassert>
1415

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

@@ -46,8 +50,8 @@ class Register {
4650

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

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

9397
constexpr operator unsigned() const { return Reg; }

llvm/lib/CodeGen/ReachingDefAnalysis.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,6 @@ void ReachingDefInfo::processDefs(MachineInstr *MI) {
193193
for (auto &MO : MI->operands()) {
194194
if (MO.isFI()) {
195195
int FrameIndex = MO.getIndex();
196-
assert(FrameIndex >= 0 && "Can't handle negative frame indicies yet!");
197196
if (!isFIDef(*MI, FrameIndex, TII))
198197
continue;
199198
MBBFrameObjsReachingDefs[{MBBNumber, FrameIndex}].push_back(CurInstr);
@@ -302,8 +301,6 @@ void ReachingDefInfo::print(raw_ostream &OS) {
302301
Register Reg;
303302
if (MO.isFI()) {
304303
int FrameIndex = MO.getIndex();
305-
assert(FrameIndex >= 0 &&
306-
"Can't handle negative frame indicies yet!");
307304
Reg = Register::index2StackSlot(FrameIndex);
308305
} else if (MO.isReg()) {
309306
if (MO.isDef())

0 commit comments

Comments
 (0)