[PATCH] Roundtrip the inalloca bit on allocas through bitcode

Reid Kleckner rnk at google.com
Thu May 29 13:33:39 PDT 2014


On Thu, May 29, 2014 at 11:31 AM, Nick Lewycky <nicholas at mxc.ca> wrote:

> Reid Kleckner wrote:
>
>> Hi nicholas, nlewycky,
>>
>> 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 6 bits.
>>
>
> How was alloca encoded in the 3.4 release? What would it someone need to
> have in their 3.4 .bc file to cause it to be read as inalloca in 3.5?
> "align 18446744073709551616"?


I think using alignment of 9223372036854775808 (2**63) will be read in as
'inalloca' with this patch, because it's encoded as log2(alignment)+1, and
reconstituted with (1<<align)>>1.  Do you want to raise the bar for the
maximum supported alignment?


>
>   On the other hand, adding a separate
>
>> record might be cleaner.  Hence, I'm asking for a review, since we can't
>> change the decision once we make it.
>>
>> http://reviews.llvm.org/D3943
>>
>> Files:
>>    include/llvm/Bitcode/LLVMBitCodes.h
>>    lib/Bitcode/Reader/BitcodeReader.cpp
>>    lib/Bitcode/Writer/BitcodeWriter.cpp
>>    test/Bitcode/inalloca.ll
>>
>> Index: include/llvm/Bitcode/LLVMBitCodes.h
>> ===================================================================
>> --- include/llvm/Bitcode/LLVMBitCodes.h
>> +++ include/llvm/Bitcode/LLVMBitCodes.h
>> @@ -289,7 +289,7 @@
>>       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.
>> Index: lib/Bitcode/Reader/BitcodeReader.cpp
>> ===================================================================
>> --- lib/Bitcode/Reader/BitcodeReader.cpp
>> +++ lib/Bitcode/Reader/BitcodeReader.cpp
>> @@ -2874,10 +2874,14 @@
>>           dyn_cast_or_null<PointerType>(getTypeByID(Record[0]));
>>         Type *OpTy = getTypeByID(Record[1]);
>>         Value *Size = getFnValueByID(Record[2], OpTy);
>> -      unsigned Align = Record[3];
>> +      unsigned AlignBits = Record[3];
>> +      bool InAlloca = AlignBits&  (1<<  6);
>> +      unsigned Align = AlignBits&  ((1<<  6) - 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;
>>       }
>> Index: lib/Bitcode/Writer/BitcodeWriter.cpp
>> ===================================================================
>> --- lib/Bitcode/Writer/BitcodeWriter.cpp
>> +++ lib/Bitcode/Writer/BitcodeWriter.cpp
>> @@ -1397,13 +1397,18 @@
>>       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(AlignRecord<  1<<  6&&  "alignment greater than 1<<  64");
>>
>> +    AlignRecord |= AI.isUsedWithInAlloca()<<  6;
>> +    Vals.push_back(AlignRecord);
>>       break;
>> +  }
>>
>>     case Instruction::Load:
>>       if (cast<LoadInst>(I).isAtomic()) {
>> Index: test/Bitcode/inalloca.ll
>> ===================================================================
>> --- /dev/null
>> +++ test/Bitcode/inalloca.ll
>> @@ -0,0 +1,17 @@
>> +; 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() {
>> +  %args = alloca inalloca i32
>> +  call void @foo(i32* inalloca %args)
>> +  ret void
>> +}
>> +; CHECK-LABEL: define void @bar() {
>> +; CHECK: %args = alloca inalloca i32
>> +; CHECK: call void @foo(i32* inalloca %args)
>>
>>
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140529/0a70f2e8/attachment.html>


More information about the llvm-commits mailing list