blob: 657939e46388508edf81c59af42161b4f0bddc8d [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;
Dan Gohman907df572008-04-03 00:02:49 +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.
Daniel Dunbard4287062009-07-03 00:10:29 +000039 void run(raw_ostream &OS);
Dan Gohmanf17a25c2007-07-18 16:29:46 +000040
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 emitRecord(const CodeGenInstruction &Inst, unsigned Num,
45 Record *InstrInfo,
46 std::map<std::vector<Record*>, unsigned> &EL,
Evan Cheng25144652008-10-17 21:00:09 +000047 std::map<Record*, unsigned> &BM,
Chris Lattner0d58d022008-01-06 01:20:13 +000048 const OperandInfoMapTy &OpInfo,
Daniel Dunbard4287062009-07-03 00:10:29 +000049 raw_ostream &OS);
Chris Lattner4533a722008-01-06 01:21:51 +000050 void emitShiftedValue(Record *R, StringInit *Val, IntInit *Shift,
Daniel Dunbard4287062009-07-03 00:10:29 +000051 raw_ostream &OS);
Chris Lattner0d58d022008-01-06 01:20:13 +000052
Chris Lattner4533a722008-01-06 01:21:51 +000053 // Itinerary information.
Dan Gohmanf17a25c2007-07-18 16:29:46 +000054 void GatherItinClasses();
Chris Lattner126489a2008-01-06 01:12:44 +000055 unsigned getItinClassNumber(const Record *InstRec);
Chris Lattner0d58d022008-01-06 01:20:13 +000056
Chris Lattner4533a722008-01-06 01:21:51 +000057 // Operand information.
Daniel Dunbard4287062009-07-03 00:10:29 +000058 void EmitOperandInfo(raw_ostream &OS, OperandInfoMapTy &OperandInfoIDs);
Chris Lattner0d58d022008-01-06 01:20:13 +000059 std::vector<std::string> GetOperandInfo(const CodeGenInstruction &Inst);
Evan Cheng25144652008-10-17 21:00:09 +000060
61 void DetectRegisterClassBarriers(std::vector<Record*> &Defs,
62 const std::vector<CodeGenRegisterClass> &RCs,
63 std::vector<Record*> &Barriers);
Dan Gohmanf17a25c2007-07-18 16:29:46 +000064};
65
66} // End llvm namespace
67
68#endif