[patch] mergefunc struct result

Carlo Kok ck at remobjects.com
Sat Apr 19 01:30:41 PDT 2014


On Sat, 19 Apr 2014 00:03:24 +0200, Duncan P. N. Exon Smith  
<dexonsmith at apple.com> wrote:

> Hi Carlo,
>
> Thanks for working on this.  See comments below.

I'll send a new patch with all your other notes fixed next week but:

>> @@ -785,6 +785,16 @@ void MergeFunctions::writeThunkOrAlias(Function  
>> *F, Function *G) {
>>  // but a bit simpler then CastInst::getCastOpcode.
>>  static Value* createCast(IRBuilder<false> &Builder, Value *V, Type  
>> *DestTy) {
>>    Type *SrcTy = V->getType();
>> +  if (SrcTy->isStructTy() && DestTy->isStructTy()) {
>
> Should this be asserting:
>
>     assert(DestTy->isStructTy())
>
> rather than checking it?
>
>> +    assert(SrcTy->getStructNumElements() ==  
>> DestTy->getStructNumElements());
>> +    Value* res = UndefValue::get(DestTy);
>

In this case no, the function works on ints and pointers now:

static Value* createCast(IRBuilder<false> &Builder, Value *V, Type  
*DestTy) {
   Type *SrcTy = V->getType();
   if (SrcTy->isIntegerTy() && DestTy->isPointerTy())
     return Builder.CreateIntToPtr(V, DestTy);
   else if (SrcTy->isPointerTy() && DestTy->isIntegerTy())
     return Builder.CreatePtrToInt(V, DestTy);
   else
     return Builder.CreateBitCast(V, DestTy);
}

I'm just adding a new option (struct) above it so it doesn't get into
the bit cast.

-- 
Calo Kok



More information about the llvm-commits mailing list