Wiki Roadmap Timeline Tickets New Ticket Source Search Help / Guide About Trac Login

Changeset 938:a904cc9bc064

Show
Ignore:
Timestamp:
02/04/09 12:39:33 (3 years ago)
Author:
Christian Kamm <kamm incasoftware de>
branch:
default
Message:

Convert struct arg to integer when passing inreg to make sure LLVM doesn't
ignore the attribute!

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • dmd/mtype.c

    r930 r938  
    26922692    this->usesThis = false; 
    26932693    this->usesNest = false; 
    2694     this->structInregArg = false
     2694    this->structInregArg = NULL
    26952695    this->retAttrs = 0; 
    26962696    this->thisAttrs = 0; 
  • dmd/mtype.h

    r930 r938  
    2424// llvm 
    2525#include "../ir/irtype.h" 
     26namespace llvm { class Type; } 
    2627 
    2728struct Scope; 
     
    439440    bool usesThis; 
    440441    bool usesNest; 
    441     bool structInregArg; 
     442    // when the last arg is a struct and passed in EAX, this holds its real type 
     443    const llvm::Type* structInregArg; 
    442444    unsigned retAttrs; 
    443445    unsigned thisAttrs; // also used for nest 
  • gen/functions.cpp

    r930 r938  
    221221                    assert((f->thisAttrs & llvm::Attribute::InReg) == 0 && "can't have two inreg args!"); 
    222222 
    223                     // structs need to go from {...}* byval to {...} inreg 
     223                    // structs need to go from {...}* byval to i8/i16/i32 inreg 
    224224                    if ((arg->storageClass & STCin) && t->ty == Tstruct) 
    225225                    { 
     
    227227                        assert(isaPointer(paramvec[n_param]) && (arg->llvmAttrs & llvm::Attribute::ByVal) 
    228228                            && "struct parameter expected to be {...}* byval before inreg is applied"); 
    229                         paramvec[n_param] = paramvec[n_param]->getContainedType(0); 
     229                        f->structInregArg = paramvec[n_param]->getContainedType(0); 
     230                        paramvec[n_param] = LLIntegerType::get(8*t->size()); 
    230231                        arg->llvmAttrs &= ~llvm::Attribute::ByVal; 
    231                         f->structInregArg = true; 
    232232                    } 
    233233                } 
     
    760760            { 
    761761                int n_param = f->reverseParams ? f->firstRealArg + n - 1 - i : f->firstRealArg + i; 
    762                 assert(!f->usesNest && !f->usesThis && isaStruct(functype->getParamType(n_param)) 
     762                const LLType* paramty = functype->getParamType(n_param); 
     763                assert(!f->usesNest && !f->usesThis &&  
     764                    llvm::isa<LLIntegerType>(paramty) && isaStruct(f->structInregArg) 
    763765                    && "Preconditions for inreg struct arg not met!"); 
    764766 
    765                 LLValue* mem = DtoAlloca(functype->getParamType(n_param), "inregstructarg"); 
    766                 DtoStore(irloc->value, mem); 
     767                LLValue* mem = DtoAlloca(f->structInregArg, "inregstructarg"); 
     768                 
     769                DtoStore(irloc->value, DtoBitCast(mem, getPtrToType(paramty))); 
    767770                irloc->value = mem; 
    768771            } 
  • gen/tocall.cpp

    r930 r938  
    371371            LLValue* arg = argval->getRVal(); 
    372372 
     373            int j = tf->reverseParams ? beg + n - i - 1 : beg + i; 
     374 
    373375            // if it's a struct inreg arg, load first to pass as first-class value 
    374376            if (tf->structInregArg && i == (tf->reverseParams ? n - 1 : 0)) 
    375377            { 
    376                 assert(fnarg->llvmAttrs & llvm::Attribute::InReg); 
     378                assert((fnarg->llvmAttrs & llvm::Attribute::InReg) && isaStruct(tf->structInregArg)); 
     379                arg = DtoBitCast(arg, getPtrToType(callableTy->getParamType(j))); 
    377380                arg = DtoLoad(arg); 
    378381            } 
    379  
    380             int j = tf->reverseParams ? beg + n - i - 1 : beg + i; 
    381382 
    382383            // parameter type mismatch, this is hard to get rid of 
Copyright © 2008, LDC Development Team.