[llvm] r213118 - Roundtrip the inalloca bit on allocas through bitcode
Reid Kleckner
reid at kleckner.net
Tue Jul 15 18:34:37 PDT 2014
Author: rnk
Date: Tue Jul 15 20:34:27 2014
New Revision: 213118
URL: http://llvm.org/viewvc/llvm-project?rev=213118&view=rev
Log:
Roundtrip the inalloca bit on allocas through bitcode
This was an oversight in the original support. As it is, I stuffed this
bit into the alignment. The alignment is stored in log2 form, so it
doesn't need more than 5 bits, given that Value::MaximumAlignment is 1
<< 29.
Reviewers: nicholas
Differential Revision: http://reviews.llvm.org/D3943
Added:
llvm/trunk/test/Bitcode/inalloca.ll
Modified:
llvm/trunk/include/llvm/Bitcode/LLVMBitCodes.h
llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp
Modified: llvm/trunk/include/llvm/Bitcode/LLVMBitCodes.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Bitcode/LLVMBitCodes.h?rev=213118&r1=213117&r2=213118&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Bitcode/LLVMBitCodes.h (original)
+++ llvm/trunk/include/llvm/Bitcode/LLVMBitCodes.h Tue Jul 15 20:34:27 2014
@@ -290,7 +290,7 @@ namespace bitc {
FUNC_CODE_INST_PHI = 16, // PHI: [ty, val0,bb0, ...]
// 17 is unused.
// 18 is unused.
- FUNC_CODE_INST_ALLOCA = 19, // ALLOCA: [instty, op, align]
+ FUNC_CODE_INST_ALLOCA = 19, // ALLOCA: [instty, opty, op, align]
FUNC_CODE_INST_LOAD = 20, // LOAD: [opty, op, align, vol]
// 21 is unused.
// 22 is unused.
Modified: llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp?rev=213118&r1=213117&r2=213118&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp (original)
+++ llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp Tue Jul 15 20:34:27 2014
@@ -2889,10 +2889,14 @@ std::error_code BitcodeReader::ParseFunc
dyn_cast_or_null<PointerType>(getTypeByID(Record[0]));
Type *OpTy = getTypeByID(Record[1]);
Value *Size = getFnValueByID(Record[2], OpTy);
- unsigned Align = Record[3];
+ unsigned AlignRecord = Record[3];
+ bool InAlloca = AlignRecord & (1 << 5);
+ unsigned Align = AlignRecord & ((1 << 5) - 1);
if (!Ty || !Size)
return Error(InvalidRecord);
- I = new AllocaInst(Ty->getElementType(), Size, (1 << Align) >> 1);
+ AllocaInst *AI = new AllocaInst(Ty->getElementType(), Size, (1 << Align) >> 1);
+ AI->setUsedWithInAlloca(InAlloca);
+ I = AI;
InstructionList.push_back(I);
break;
}
Modified: llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp?rev=213118&r1=213117&r2=213118&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp (original)
+++ llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp Tue Jul 15 20:34:27 2014
@@ -1431,13 +1431,20 @@ static void WriteInstruction(const Instr
break;
}
- case Instruction::Alloca:
+ case Instruction::Alloca: {
Code = bitc::FUNC_CODE_INST_ALLOCA;
Vals.push_back(VE.getTypeID(I.getType()));
Vals.push_back(VE.getTypeID(I.getOperand(0)->getType()));
Vals.push_back(VE.getValueID(I.getOperand(0))); // size.
- Vals.push_back(Log2_32(cast<AllocaInst>(I).getAlignment())+1);
+ const AllocaInst &AI = cast<AllocaInst>(I);
+ unsigned AlignRecord = Log2_32(AI.getAlignment()) + 1;
+ assert(Log2_32(Value::MaximumAlignment) + 1 < 1 << 5 &&
+ "not enough bits for maximum alignment");
+ assert(AlignRecord < 1 << 5 && "alignment greater than 1 << 64");
+ AlignRecord |= AI.isUsedWithInAlloca() << 5;
+ Vals.push_back(AlignRecord);
break;
+ }
case Instruction::Load:
if (cast<LoadInst>(I).isAtomic()) {
Added: llvm/trunk/test/Bitcode/inalloca.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Bitcode/inalloca.ll?rev=213118&view=auto
==============================================================================
--- llvm/trunk/test/Bitcode/inalloca.ll (added)
+++ llvm/trunk/test/Bitcode/inalloca.ll Tue Jul 15 20:34:27 2014
@@ -0,0 +1,18 @@
+; RUN: llvm-as < %s | llvm-dis | FileCheck %s
+
+; inalloca should roundtrip.
+
+define void @foo(i32* inalloca %args) {
+ ret void
+}
+; CHECK-LABEL: define void @foo(i32* inalloca %args)
+
+define void @bar() {
+ ; Use the maximum alignment, since we stuff our bit with alignment.
+ %args = alloca inalloca i32, align 536870912
+ call void @foo(i32* inalloca %args)
+ ret void
+}
+; CHECK-LABEL: define void @bar() {
+; CHECK: %args = alloca inalloca i32, align 536870912
+; CHECK: call void @foo(i32* inalloca %args)
More information about the llvm-commits
mailing list