view ir/irdsymbol.cpp @ 1410:cc2d8a7388c7

Count the sret register as well when keeping track of how many integer registers are available for extern(C) functions on x86-64. Interestingly, llvm-g++ seems to have a very similar bug: http://llvm.org/pr4242 (So this breaks ABI-compatibility with llvm-gcc for this corner case, but gains it with gcc...) To clarify, this is about code like this: {{{ struct S { void*[3] data; } struct T { void*[2] data; } // The T should be passed in memory, and p in the last int register. extern(C) S fail(int, int, int, int, T t, void* p) { S s; s.data[0] = t.data[0]; s.data[1] = t.data[1]; s.data[2] = p; return s; } }}} which should generate code functionally equivalent to this: {{{ extern(C) S* succeed(S* s, int, int, int, int, T t, void* p) { s.data[0] = t.data[0]; s.data[1] = t.data[1]; s.data[2] = p; return s; } }}} (with the same definitions for S and T)
author Frits van Bommel <fvbommel wxs.nl>
date Fri, 22 May 2009 13:17:06 +0200
parents 229e02867307
children
line wrap: on
line source

#include "gen/llvm.h"
#include "ir/ir.h"
#include "ir/irdsymbol.h"
#include "ir/irvar.h"

#include "gen/logger.h"

std::set<IrDsymbol*> IrDsymbol::list;

void IrDsymbol::resetAll()
{
    Logger::println("resetting %zu Dsymbols", list.size());
    std::set<IrDsymbol*>::iterator it;
    for(it = list.begin(); it != list.end(); ++it)
        (*it)->reset();
}

IrDsymbol::IrDsymbol()
{
    bool incr = list.insert(this).second;
    assert(incr);
    reset();
}

IrDsymbol::IrDsymbol(const IrDsymbol& s)
{
    bool incr = list.insert(this).second;
    assert(incr);
    DModule = s.DModule;
    irModule = s.irModule;
    irStruct = s.irStruct;
    irFunc = s.irFunc;
    resolved = s.resolved;
    declared = s.declared;
    initialized = s.initialized;
    defined = s.defined;
    irGlobal = s.irGlobal;
    irLocal = s.irLocal;
    irField = s.irField;
}

IrDsymbol::~IrDsymbol()
{
    list.erase(this);
}

void IrDsymbol::reset()
{
    DModule = NULL;
    irModule = NULL;
    irStruct = NULL;
    irFunc = NULL;
    resolved = declared = initialized = defined = false;
    irGlobal = NULL;
    irLocal = NULL;
    irField = NULL;
}

bool IrDsymbol::isSet()
{
    return (irStruct || irFunc || irGlobal || irLocal || irField);
}

IrVar* IrDsymbol::getIrVar()
{
    assert(irGlobal || irLocal || irField);
    return irGlobal ? (IrVar*)irGlobal : irLocal ? (IrVar*)irLocal : (IrVar*)irField;
}

llvm::Value*& IrDsymbol::getIrValue() { return getIrVar()->value; }