start inferring 'no side effects'.
[oota-llvm.git] / utils / TableGen / InstrInfoEmitter.h
1 //===- InstrInfoEmitter.h - Generate a Instruction Set Desc. ----*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
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"
19 #include "CodeGenDAGPatterns.h"
20 #include <vector>
21 #include <map>
22
23 namespace llvm {
24
25 class StringInit;
26 class IntInit;
27 class ListInit;
28 class CodeGenInstruction;
29
30 class InstrInfoEmitter : public TableGenBackend {
31   RecordKeeper &Records;
32   const CodeGenDAGPatterns CDP;
33   std::map<std::string, unsigned> ItinClassMap;
34   
35 public:
36   InstrInfoEmitter(RecordKeeper &R) : Records(R), CDP(R) { }
37
38   // run - Output the instruction set description, returning true on failure.
39   void run(std::ostream &OS);
40
41 private:
42   typedef std::map<std::vector<std::string>, unsigned> OperandInfoMapTy;
43   
44   // Instruction analysis.
45   void InferFromPattern(const CodeGenInstruction &Inst, 
46                         bool &MayStore, bool &MayLoad, bool &HasSideEffects);
47   
48   void emitRecord(const CodeGenInstruction &Inst, unsigned Num,
49                   Record *InstrInfo, 
50                   std::map<std::vector<Record*>, unsigned> &EL,
51                   const OperandInfoMapTy &OpInfo,
52                   std::ostream &OS);
53   void emitShiftedValue(Record *R, StringInit *Val, IntInit *Shift,
54                         std::ostream &OS);
55
56   // Itinerary information.
57   void GatherItinClasses();
58   unsigned getItinClassNumber(const Record *InstRec);
59   
60   // Operand information.
61   void EmitOperandInfo(std::ostream &OS, OperandInfoMapTy &OperandInfoIDs);
62   std::vector<std::string> GetOperandInfo(const CodeGenInstruction &Inst);
63 };
64
65 } // End llvm namespace
66
67 #endif