nv50/ir: Build a "symbol" table with the binary offsets of each function.

This commit is contained in:
Francisco Jerez 2012-04-06 18:50:56 +02:00 committed by Christoph Bumiller
parent 5e4b2a1a47
commit 98116cc3dc
7 changed files with 45 additions and 5 deletions

View File

@ -976,7 +976,7 @@ Program::Program(Type type, Target *arch)
maxGPR = -1;
main = new Function(this, "MAIN");
main = new Function(this, "MAIN", ~0);
calls.insert(&main->call);
dbgFlags = 0;

View File

@ -916,7 +916,7 @@ private:
class Function
{
public:
Function(Program *, const char *name);
Function(Program *, const char *name, uint32_t label);
~Function();
static inline Function *get(Graph::Node *node);
@ -924,6 +924,7 @@ public:
inline Program *getProgram() const { return prog; }
inline const char *getName() const { return name; }
inline int getId() const { return id; }
inline uint32_t getLabel() const { return label; }
void print();
void printLiveIntervals() const;
@ -968,6 +969,7 @@ private:
void buildDefSetsPreSSA(BasicBlock *bb, const int seq);
private:
uint32_t label;
int id;
const char *const name;
Program *prog;
@ -1015,6 +1017,8 @@ public:
const Target *getTarget() const { return target; }
private:
void emitSymbolTable(struct nv50_ir_prog_info *);
Type progType;
Target *target;

View File

@ -24,8 +24,9 @@
namespace nv50_ir {
Function::Function(Program *p, const char *fnName)
Function::Function(Program *p, const char *fnName, uint32_t label)
: call(this),
label(label),
name(fnName),
prog(p)
{

View File

@ -87,6 +87,12 @@ struct nv50_ir_varying
#define NV50_PRIM_PATCHES PIPE_PRIM_MAX
struct nv50_ir_prog_symbol
{
uint32_t label;
uint32_t offset;
};
struct nv50_ir_prog_info
{
uint16_t target; /* chipset (0x50, 0x84, 0xc0, ...) */
@ -105,6 +111,8 @@ struct nv50_ir_prog_info
uint8_t sourceRep; /* NV50_PROGRAM_IR */
const void *source;
void *relocData;
struct nv50_ir_prog_symbol *syms;
uint16_t numSyms;
} bin;
struct nv50_ir_varying sv[PIPE_MAX_SHADER_INPUTS];

View File

@ -431,7 +431,9 @@ void Instruction::print() const
PRINT(" %sBUILTIN:%i", colour[TXT_BRA], asFlow()->target.builtin);
} else
if (op == OP_CALL && asFlow()->target.fn) {
PRINT(" %s%s", colour[TXT_BRA], asFlow()->target.fn->getName());
PRINT(" %s%s:%i", colour[TXT_BRA],
asFlow()->target.fn->getName(),
asFlow()->target.fn->getLabel());
} else
if (asFlow()->target.bb)
PRINT(" %sBB:%i", colour[TXT_BRA], asFlow()->target.bb->getId());
@ -508,7 +510,7 @@ private:
bool
PrintPass::visit(Function *fn)
{
INFO("\n%s:\n", fn->getName());
INFO("\n%s:%i\n", fn->getName(), fn->getLabel());
return true;
}

View File

@ -208,6 +208,27 @@ CodeEmitter::prepareEmission(BasicBlock *bb)
func->binSize += bb->binSize;
}
void
Program::emitSymbolTable(struct nv50_ir_prog_info *info)
{
unsigned int n = 0, nMax = allFuncs.getSize();
info->bin.syms =
(struct nv50_ir_prog_symbol *)MALLOC(nMax * sizeof(*info->bin.syms));
for (ArrayList::Iterator fi = allFuncs.iterator();
!fi.end();
fi.next(), ++n) {
Function *f = (Function *)fi.get();
assert(n < nMax);
info->bin.syms[n].label = f->getLabel();
info->bin.syms[n].offset = f->binPos;
}
info->bin.numSyms = n;
}
bool
Program::emitBinary(struct nv50_ir_prog_info *info)
{
@ -238,6 +259,8 @@ Program::emitBinary(struct nv50_ir_prog_info *info)
}
info->bin.relocData = emit->getRelocInfo();
emitSymbolTable(info);
delete emit;
return true;
}

View File

@ -568,6 +568,8 @@ nvc0_program_translate(struct nvc0_program *prog)
NOUVEAU_ERR("shader translation failed: %i\n", ret);
goto out;
}
if (info->bin.syms) /* we don't need them yet */
FREE(info->bin.syms);
prog->code = info->bin.code;
prog->code_size = info->bin.codeSize;