TableGen: Generate a function for getting operand indices based on their defined...
authorTom Stellard <thomas.stellard@amd.com>
Tue, 25 Jun 2013 21:22:09 +0000 (21:22 +0000)
committerTom Stellard <thomas.stellard@amd.com>
Tue, 25 Jun 2013 21:22:09 +0000 (21:22 +0000)
commitb162d9487163de14227d146d5b468713b9c65451
tree46233618f7f3aa9117a8c769b92e04ea3dcdb45a
parent90c38bcf581c98d7b7c3c5bb98fe3930800b4e6e
TableGen: Generate a function for getting operand indices based on their defined names

This patch modifies TableGen to generate a function in
${TARGET}GenInstrInfo.inc called getNamedOperandIdx(), which can be used
to look up indices for operands based on their names.

In order to activate this feature for an instruction, you must set the
UseNamedOperandTable bit.

For example, if you have an instruction like:

def ADD : TargetInstr <(outs GPR:$dst), (ins GPR:$src0, GPR:$src1)>;

You can look up the operand indices using the new function, like this:

Target::getNamedOperandIdx(Target::ADD, Target::OpName::dst)  => 0
Target::getNamedOperandIdx(Target::ADD, Target::OpName::src0) => 1
Target::getNamedOperandIdx(Target::ADD, Target::OpName::src1) => 2

The operand names are case sensitive, so $dst and $DST are considered
different operands.

This change is useful for R600 which has instructions with a large number
of operands, many of which model single bit instruction configuration
values.  These configuration bits are common across most instructions,
but may have a different operand index depending on the instruction type.
It is useful to have a convenient way to look up the operand indices,
so these bits can be generically set on any instruction.

llvm-svn: 184879
llvm/docs/WritingAnLLVMBackend.rst
llvm/include/llvm/Target/Target.td
llvm/utils/TableGen/InstrInfoEmitter.cpp