了解 LLVM 中的 PointerIntPair Class

Understanding PointerIntPair Class in LLVM

我正在寻找一种类似于压缩整数的位压缩方案,然后我遇到了 PinterIntPair 部分 LLVM 项目,但是我无法弄清楚这是如何完成的。谁能详细说明一下!

他们解释说:

PointerIntPair - This class implements a pair of a pointer and small integer. It is designed to represent this in the space required by one pointer by bitmangling the integer into the low part of the pointer. This can only be done for small integers: typically up to 3 bits, but it depends on the number of bits available according to PointerLikeTypeTraits for the type.

那个特定的 class 利用了这样一个事实,即在许多体系结构中,指针的低位 n 都是零。 n 在今天的 64 位机器上通常是 3。

因此,通过在对象初始化期间接受指针时检查这些位是否为零并在返回指针以供使用时将它们设置为零,可以将指针和小整数存储在彼此之上。

也可以存储一些布尔值,但是这个class存储的是一个整数。