blob: b721adcf4cef36bce99e001f1dc2fd28ae6c1def [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
Chris Lattner44435a72008-01-06 01:53:37 +000044 // Instruction analysis.
45 void InferFromPattern(const CodeGenInstruction &Inst,
46 bool &isStore, bool &isLoad, bool &NeverHasSideEffects);
47
Dan Gohmanf17a25c2007-07-18 16:29:46 +000048 void emitRecord(const CodeGenInstruction &Inst, unsigned Num,
49 Record *InstrInfo,
50 std::map<std::vector<Record*>, unsigned> &EL,
Chris Lattner0d58d022008-01-06 01:20:13 +000051 const OperandInfoMapTy &OpInfo,
Dan Gohmanf17a25c2007-07-18 16:29:46 +000052 std::ostream &OS);
Chris Lattner4533a722008-01-06 01:21:51 +000053 void emitShiftedValue(Record *R, StringInit *Val, IntInit *Shift,
54 std::ostream &OS);
Chris Lattner0d58d022008-01-06 01:20:13 +000055
Chris Lattner4533a722008-01-06 01:21:51 +000056 // Itinerary information.
Dan Gohmanf17a25c2007-07-18 16:29:46 +000057 void GatherItinClasses();
Chris Lattner126489a2008-01-06 01:12:44 +000058 unsigned getItinClassNumber(const Record *InstRec);
Chris Lattner0d58d022008-01-06 01:20:13 +000059
Chris Lattner4533a722008-01-06 01:21:51 +000060 // Operand information.
Chris Lattner0d58d022008-01-06 01:20:13 +000061 void EmitOperandInfo(std::ostream &OS, OperandInfoMapTy &OperandInfoIDs);
62 std::vector<std::string> GetOperandInfo(const CodeGenInstruction &Inst);
Dan Gohmanf17a25c2007-07-18 16:29:46 +000063};
64
65} // End llvm namespace
66
67#endif