blob: a223f2466ea85d96bfb0304d97ed140e9361463b [file] [log] [blame]
Chris Lattner33ccf7e2003-08-03 17:24:10 +00001//===- InstrInfoEmitter.h - Generate a Instruction Set Desc. ----*- C++ -*-===//
Misha Brukman3da94ae2005-04-22 00:00:37 +00002//
John Criswell01d45822003-10-20 20:20:30 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattner30609102007-12-29 20:37:13 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Misha Brukman3da94ae2005-04-22 00:00:37 +00007//
John Criswell01d45822003-10-20 20:20:30 +00008//===----------------------------------------------------------------------===//
Chris Lattner33ccf7e2003-08-03 17:24:10 +00009//
10// This tablegen backend is responsible for emitting a description of the target
11// instruction set for the code generator.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef INSTRINFO_EMITTER_H
16#define INSTRINFO_EMITTER_H
17
Chris Lattnerbc017232003-08-06 04:32:07 +000018#include "TableGenBackend.h"
Chris Lattner951740a2008-01-06 01:12:44 +000019#include "CodeGenDAGPatterns.h"
Chris Lattnera3ac88d2005-08-18 21:36:47 +000020#include <vector>
21#include <map>
Brian Gaeked0fde302003-11-11 22:41:34 +000022
23namespace llvm {
24
Chris Lattnera3ae6142003-08-03 21:57:51 +000025class StringInit;
26class IntInit;
Chris Lattnerbc017232003-08-06 04:32:07 +000027class ListInit;
Jeff Cohend41b30d2006-11-05 19:31:28 +000028class CodeGenInstruction;
Chris Lattner33ccf7e2003-08-03 17:24:10 +000029
Chris Lattnerbc017232003-08-06 04:32:07 +000030class InstrInfoEmitter : public TableGenBackend {
Chris Lattner33ccf7e2003-08-03 17:24:10 +000031 RecordKeeper &Records;
Chris Lattner2d51a4c2008-01-06 02:16:26 +000032 const CodeGenDAGPatterns CDP;
Jim Laskeyb5a0c0e2005-10-31 17:16:46 +000033 std::map<std::string, unsigned> ItinClassMap;
34
Chris Lattner33ccf7e2003-08-03 17:24:10 +000035public:
Chris Lattner951740a2008-01-06 01:12:44 +000036 InstrInfoEmitter(RecordKeeper &R) : Records(R), CDP(R) { }
Misha Brukman3da94ae2005-04-22 00:00:37 +000037
Chris Lattner33ccf7e2003-08-03 17:24:10 +000038 // run - Output the instruction set description, returning true on failure.
Chris Lattnera3ae6142003-08-03 21:57:51 +000039 void run(std::ostream &OS);
Chris Lattner33ccf7e2003-08-03 17:24:10 +000040
Chris Lattnera3ae6142003-08-03 21:57:51 +000041private:
Chris Lattneref8339b2008-01-06 01:20:13 +000042 typedef std::map<std::vector<std::string>, unsigned> OperandInfoMapTy;
43
Chris Lattnera529a372008-01-06 01:53:37 +000044 // Instruction analysis.
45 void InferFromPattern(const CodeGenInstruction &Inst,
46 bool &isStore, bool &isLoad, bool &NeverHasSideEffects);
47
Chris Lattnerec352402004-08-01 05:04:00 +000048 void emitRecord(const CodeGenInstruction &Inst, unsigned Num,
Chris Lattnera3ac88d2005-08-18 21:36:47 +000049 Record *InstrInfo,
Chris Lattner366080c2005-10-28 22:59:53 +000050 std::map<std::vector<Record*>, unsigned> &EL,
Chris Lattneref8339b2008-01-06 01:20:13 +000051 const OperandInfoMapTy &OpInfo,
Chris Lattnera3ac88d2005-08-18 21:36:47 +000052 std::ostream &OS);
Chris Lattner5fbe2752008-01-06 01:21:51 +000053 void emitShiftedValue(Record *R, StringInit *Val, IntInit *Shift,
54 std::ostream &OS);
Chris Lattneref8339b2008-01-06 01:20:13 +000055
Chris Lattner5fbe2752008-01-06 01:21:51 +000056 // Itinerary information.
Jim Laskeyb5a0c0e2005-10-31 17:16:46 +000057 void GatherItinClasses();
Chris Lattner951740a2008-01-06 01:12:44 +000058 unsigned getItinClassNumber(const Record *InstRec);
Chris Lattneref8339b2008-01-06 01:20:13 +000059
Chris Lattner5fbe2752008-01-06 01:21:51 +000060 // Operand information.
Chris Lattneref8339b2008-01-06 01:20:13 +000061 void EmitOperandInfo(std::ostream &OS, OperandInfoMapTy &OperandInfoIDs);
62 std::vector<std::string> GetOperandInfo(const CodeGenInstruction &Inst);
Chris Lattner33ccf7e2003-08-03 17:24:10 +000063};
64
Brian Gaeked0fde302003-11-11 22:41:34 +000065} // End llvm namespace
66
Chris Lattner33ccf7e2003-08-03 17:24:10 +000067#endif