TableGen backend support to express relations between instruction

Hi Jakob,

Here is the first draft of the patch to add TableGen backend support for the
instruction mapping tables. Please take a look and let me know your
suggestions. As of now, I create one mapping table per relation which
results into a long .inc file. So, I'm planning to combine everything into a
single table and will include APIs (one per relation) to query from this
table.

Thanks,
Jyotsna

0001-Add-TableGen-support-to-create-relationship-maps-bet.patch (18.5 KB)

Jyotsna,

I hadn't been following this, so I apologize if this has already been
provided, but can you give a quick example of how this functionality is
used?

Thanks in advance,
Hal

Hi Hal,

I will try to explain the functionality using a simple example. Let's say
that we have three formats for 'ADD' instruction and we want to relate them.

ADD - non-predicated form
ADD_pt : predicate true
ADD_pf : predicate false

We can define the relationship between the non-predicated instructions and
their predicate formats as follows:

def getPredOpcode : InstrMapping { // InstrMapping is a new class defined in
Target.td

// Used to filter instructions that have this kind of relationship
let FilterClass = "PredRel";

// Instructions with the same BaseOpcode value form a row.
let RowFields = ["BaseOpcode"];

// Instructions with the same predicate sense form a column.
let ColFields = ["PredSense"];

// The key column is the unpredicated instructions.
let KeyCol = ["nopred"];

// Value columns are PredSense=true and PredSense=false
  let ValueCols = [["true"], ["false"]];
}

Instructions need to set some fields in order for the TableGen to relate
them using the information provided in 'getPredOpcode'.

Def ADD: PredRel {
   let BaseOpcode = "ADD";
   let PredSense = "nopred";
}

Def ADD_pt: PredRel {
   let BaseOpcode = "ADD";
   let PredSense = "true";
}

Def ADD_pf: PredRel {
   let BaseOpcode = "ADD";
   let PredSense = "false";
}

Here, BaseOpcode and PredSense are the new fields added to the (Hexagon)
Instructions. Other targets can define their own relations and add new
fields if necessary. TableGen will output relations as a table which can be
queried using a function

getPredOpcode(Opcode, predsense) {
If (predsense == true)
  return getPredOpcodeTable[Opcode][0]
if (predsense == false)
  return getPredOpcodeTable[Opcode][1]
}

Let me know if something is not clear and I will try to explain it further.

Thanks,
Jyotsna

Hi Hal,

I will try to explain the functionality using a simple example. Let's
say that we have three formats for 'ADD' instruction and we want to
relate them.

ADD - non-predicated form
ADD_pt : predicate true
ADD_pf : predicate false

We can define the relationship between the non-predicated
instructions and their predicate formats as follows:

def getPredOpcode : InstrMapping { // InstrMapping is a new class
defined in Target.td

// Used to filter instructions that have this kind of relationship
let FilterClass = "PredRel";

// Instructions with the same BaseOpcode value form a row.
let RowFields = ["BaseOpcode"];

// Instructions with the same predicate sense form a column.
let ColFields = ["PredSense"];

// The key column is the unpredicated instructions.
let KeyCol = ["nopred"];

// Value columns are PredSense=true and PredSense=false
  let ValueCols = [["true"], ["false"]];
}

Instructions need to set some fields in order for the TableGen to
relate them using the information provided in 'getPredOpcode'.

Def ADD: PredRel {
   let BaseOpcode = "ADD";
   let PredSense = "nopred";
}

Def ADD_pt: PredRel {
   let BaseOpcode = "ADD";
   let PredSense = "true";
}

Def ADD_pf: PredRel {
   let BaseOpcode = "ADD";
   let PredSense = "false";
}

Here, BaseOpcode and PredSense are the new fields added to the
(Hexagon) Instructions. Other targets can define their own relations
and add new fields if necessary. TableGen will output relations as a
table which can be queried using a function

getPredOpcode(Opcode, predsense) {
If (predsense == true)
  return getPredOpcodeTable[Opcode][0]
if (predsense == false)
  return getPredOpcodeTable[Opcode][1]
}

Let me know if something is not clear and I will try to explain it
further.

Thanks! This functionality can also be used in the PowerPC backend to
match load/store instructions to their 'with update' forms, and that
would be useful.

-Hal

Hi Jakob,

Did you get a chance to look at the patch?

Thanks,
Jyotsna

Jakob,

I didn't notice your response at llvm-commits@cs.uiuc.edu.

I will work on your comments and send out the revised patch.

Thanks,
Jyotsna