mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-31 20:51:52 +01:00
[AllocaInst] Update getAllocationSizeInBits
to return TypeSize
.
Reviewed By: peterwaller-arm, sdesmalen Differential Revision: https://reviews.llvm.org/D92020
This commit is contained in:
parent
4a9062addf
commit
4a2f3f7420
@ -106,7 +106,7 @@ public:
|
|||||||
|
|
||||||
/// Get allocation size in bits. Returns None if size can't be determined,
|
/// Get allocation size in bits. Returns None if size can't be determined,
|
||||||
/// e.g. in case of a VLA.
|
/// e.g. in case of a VLA.
|
||||||
Optional<uint64_t> getAllocationSizeInBits(const DataLayout &DL) const;
|
Optional<TypeSize> getAllocationSizeInBits(const DataLayout &DL) const;
|
||||||
|
|
||||||
/// Return the type that is being allocated by the instruction.
|
/// Return the type that is being allocated by the instruction.
|
||||||
Type *getAllocatedType() const { return AllocatedType; }
|
Type *getAllocatedType() const { return AllocatedType; }
|
||||||
|
@ -49,13 +49,14 @@ using namespace llvm;
|
|||||||
// AllocaInst Class
|
// AllocaInst Class
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
Optional<uint64_t>
|
Optional<TypeSize>
|
||||||
AllocaInst::getAllocationSizeInBits(const DataLayout &DL) const {
|
AllocaInst::getAllocationSizeInBits(const DataLayout &DL) const {
|
||||||
uint64_t Size = DL.getTypeAllocSizeInBits(getAllocatedType());
|
TypeSize Size = DL.getTypeAllocSizeInBits(getAllocatedType());
|
||||||
if (isArrayAllocation()) {
|
if (isArrayAllocation()) {
|
||||||
auto *C = dyn_cast<ConstantInt>(getArraySize());
|
auto *C = dyn_cast<ConstantInt>(getArraySize());
|
||||||
if (!C)
|
if (!C)
|
||||||
return None;
|
return None;
|
||||||
|
assert(!Size.isScalable() && "Array elements cannot have a scalable size");
|
||||||
Size *= C->getZExtValue();
|
Size *= C->getZExtValue();
|
||||||
}
|
}
|
||||||
return Size;
|
return Size;
|
||||||
|
@ -576,9 +576,10 @@ void FrameTypeBuilder::addFieldForAllocas(const Function &F,
|
|||||||
StackLifetimeAnalyzer.getLiveRange(AI2));
|
StackLifetimeAnalyzer.getLiveRange(AI2));
|
||||||
};
|
};
|
||||||
auto GetAllocaSize = [&](const AllocaInfo &A) {
|
auto GetAllocaSize = [&](const AllocaInfo &A) {
|
||||||
Optional<uint64_t> RetSize = A.Alloca->getAllocationSizeInBits(DL);
|
Optional<TypeSize> RetSize = A.Alloca->getAllocationSizeInBits(DL);
|
||||||
assert(RetSize && "We can't handle scalable type now.\n");
|
assert(RetSize && "Variable Length Arrays (VLA) are not supported.\n");
|
||||||
return RetSize.getValue();
|
assert(!RetSize->isScalable() && "Scalable vectors are not yet supported");
|
||||||
|
return RetSize->getFixedSize();
|
||||||
};
|
};
|
||||||
// Put larger allocas in the front. So the larger allocas have higher
|
// Put larger allocas in the front. So the larger allocas have higher
|
||||||
// priority to merge, which can save more space potentially. Also each
|
// priority to merge, which can save more space potentially. Also each
|
||||||
|
@ -1400,5 +1400,45 @@ TEST(InstructionsTest, BranchWeightOverflow) {
|
|||||||
ASSERT_EQ(ProfWeight, UINT32_MAX);
|
ASSERT_EQ(ProfWeight, UINT32_MAX);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(InstructionsTest, AllocaInst) {
|
||||||
|
LLVMContext Ctx;
|
||||||
|
std::unique_ptr<Module> M = parseIR(Ctx, R"(
|
||||||
|
%T = type { i64, [3 x i32]}
|
||||||
|
define void @f(i32 %n) {
|
||||||
|
entry:
|
||||||
|
%A = alloca i32, i32 1
|
||||||
|
%B = alloca i32, i32 4
|
||||||
|
%C = alloca i32, i32 %n
|
||||||
|
%D = alloca <8 x double>
|
||||||
|
%E = alloca <vscale x 8 x double>
|
||||||
|
%F = alloca [2 x half]
|
||||||
|
%G = alloca [2 x [3 x i128]]
|
||||||
|
%H = alloca %T
|
||||||
|
ret void
|
||||||
|
}
|
||||||
|
)");
|
||||||
|
const DataLayout &DL = M->getDataLayout();
|
||||||
|
ASSERT_TRUE(M);
|
||||||
|
Function *Fun = cast<Function>(M->getNamedValue("f"));
|
||||||
|
BasicBlock &BB = Fun->front();
|
||||||
|
auto It = BB.begin();
|
||||||
|
AllocaInst &A = cast<AllocaInst>(*It++);
|
||||||
|
AllocaInst &B = cast<AllocaInst>(*It++);
|
||||||
|
AllocaInst &C = cast<AllocaInst>(*It++);
|
||||||
|
AllocaInst &D = cast<AllocaInst>(*It++);
|
||||||
|
AllocaInst &E = cast<AllocaInst>(*It++);
|
||||||
|
AllocaInst &F = cast<AllocaInst>(*It++);
|
||||||
|
AllocaInst &G = cast<AllocaInst>(*It++);
|
||||||
|
AllocaInst &H = cast<AllocaInst>(*It++);
|
||||||
|
EXPECT_EQ(A.getAllocationSizeInBits(DL), TypeSize::getFixed(32));
|
||||||
|
EXPECT_EQ(B.getAllocationSizeInBits(DL), TypeSize::getFixed(128));
|
||||||
|
EXPECT_FALSE(C.getAllocationSizeInBits(DL));
|
||||||
|
EXPECT_EQ(D.getAllocationSizeInBits(DL), TypeSize::getFixed(512));
|
||||||
|
EXPECT_EQ(E.getAllocationSizeInBits(DL), TypeSize::getScalable(512));
|
||||||
|
EXPECT_EQ(F.getAllocationSizeInBits(DL), TypeSize::getFixed(32));
|
||||||
|
EXPECT_EQ(G.getAllocationSizeInBits(DL), TypeSize::getFixed(768));
|
||||||
|
EXPECT_EQ(H.getAllocationSizeInBits(DL), TypeSize::getFixed(160));
|
||||||
|
}
|
||||||
|
|
||||||
} // end anonymous namespace
|
} // end anonymous namespace
|
||||||
} // end namespace llvm
|
} // end namespace llvm
|
||||||
|
Loading…
x
Reference in New Issue
Block a user