blob: b6d02459a5cf43f4cdcf6cfd660baec3eb17c3ec [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001//===- InstrInfoEmitter.h - Generate a Instruction Set Desc. ----*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattnerfd6c2f02007-12-29 20:37:13 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00007//
8//===----------------------------------------------------------------------===//
9//
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
18#include "TableGenBackend.h"
Chris Lattner126489a2008-01-06 01:12:44 +000019#include "CodeGenDAGPatterns.h"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000020#include <vector>
21#include <map>
22
23namespace llvm {
24
25class StringInit;
26class IntInit;
27class ListInit;
28class CodeGenInstruction;
29
30class InstrInfoEmitter : public TableGenBackend {
31 RecordKeeper &Records;
Chris Lattner126489a2008-01-06 01:12:44 +000032 CodeGenDAGPatterns CDP;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000033 std::map<std::string, unsigned> ItinClassMap;
34
35public:
Chris Lattner126489a2008-01-06 01:12:44 +000036 InstrInfoEmitter(RecordKeeper &R) : Records(R), CDP(R) { }
Dan Gohmanf17a25c2007-07-18 16:29:46 +000037
38 // run - Output the instruction set description, returning true on failure.
39 void run(std::ostream &OS);
40
Dan Gohmanf17a25c2007-07-18 16:29:46 +000041private:
Chris Lattner0d58d022008-01-06 01:20:13 +000042 typedef std::map<std::vector<std::string>, unsigned> OperandInfoMapTy;
43
Dan Gohmanf17a25c2007-07-18 16:29:46 +000044 void printDefList(const std::vector<Record*> &Uses, unsigned Num,
45 std::ostream &OS) const;
46 void emitRecord(const CodeGenInstruction &Inst, unsigned Num,
47 Record *InstrInfo,
48 std::map<std::vector<Record*>, unsigned> &EL,
Chris Lattner0d58d022008-01-06 01:20:13 +000049 const OperandInfoMapTy &OpInfo,
Dan Gohmanf17a25c2007-07-18 16:29:46 +000050 std::ostream &OS);
Chris Lattner0d58d022008-01-06 01:20:13 +000051
Dan Gohmanf17a25c2007-07-18 16:29:46 +000052 void GatherItinClasses();
Chris Lattner126489a2008-01-06 01:12:44 +000053 unsigned getItinClassNumber(const Record *InstRec);
Chris Lattner0d58d022008-01-06 01:20:13 +000054
55 void EmitOperandInfo(std::ostream &OS, OperandInfoMapTy &OperandInfoIDs);
56 std::vector<std::string> GetOperandInfo(const CodeGenInstruction &Inst);
57
Dan Gohmanf17a25c2007-07-18 16:29:46 +000058 void emitShiftedValue(Record *R, StringInit *Val, IntInit *Shift,
59 std::ostream &OS);
Dan Gohmanf17a25c2007-07-18 16:29:46 +000060};
61
62} // End llvm namespace
63
64#endif