Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1 | //===- InstrInfoEmitter.h - Generate a Instruction Set Desc. ----*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | fd6c2f0 | 2007-12-29 20:37:13 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 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" |
Chris Lattner | 126489a | 2008-01-06 01:12:44 +0000 | [diff] [blame] | 19 | #include "CodeGenDAGPatterns.h" |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 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; |
Chris Lattner | ccc5d9c | 2008-01-06 02:16:26 +0000 | [diff] [blame] | 32 | const CodeGenDAGPatterns CDP; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 33 | std::map<std::string, unsigned> ItinClassMap; |
| 34 | |
| 35 | public: |
Chris Lattner | 126489a | 2008-01-06 01:12:44 +0000 | [diff] [blame] | 36 | InstrInfoEmitter(RecordKeeper &R) : Records(R), CDP(R) { } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 37 | |
| 38 | // run - Output the instruction set description, returning true on failure. |
| 39 | void run(std::ostream &OS); |
| 40 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 41 | private: |
Chris Lattner | 0d58d02 | 2008-01-06 01:20:13 +0000 | [diff] [blame] | 42 | typedef std::map<std::vector<std::string>, unsigned> OperandInfoMapTy; |
| 43 | |
Chris Lattner | 44435a7 | 2008-01-06 01:53:37 +0000 | [diff] [blame] | 44 | // Instruction analysis. |
| 45 | void InferFromPattern(const CodeGenInstruction &Inst, |
Chris Lattner | 8463122 | 2008-01-10 05:39:30 +0000 | [diff] [blame] | 46 | bool &MayStore, bool &MayLoad, bool &HasSideEffects); |
Chris Lattner | 44435a7 | 2008-01-06 01:53:37 +0000 | [diff] [blame] | 47 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 48 | void emitRecord(const CodeGenInstruction &Inst, unsigned Num, |
| 49 | Record *InstrInfo, |
| 50 | std::map<std::vector<Record*>, unsigned> &EL, |
Chris Lattner | 0d58d02 | 2008-01-06 01:20:13 +0000 | [diff] [blame] | 51 | const OperandInfoMapTy &OpInfo, |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 52 | std::ostream &OS); |
Chris Lattner | 4533a72 | 2008-01-06 01:21:51 +0000 | [diff] [blame] | 53 | void emitShiftedValue(Record *R, StringInit *Val, IntInit *Shift, |
| 54 | std::ostream &OS); |
Chris Lattner | 0d58d02 | 2008-01-06 01:20:13 +0000 | [diff] [blame] | 55 | |
Chris Lattner | 4533a72 | 2008-01-06 01:21:51 +0000 | [diff] [blame] | 56 | // Itinerary information. |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 57 | void GatherItinClasses(); |
Chris Lattner | 126489a | 2008-01-06 01:12:44 +0000 | [diff] [blame] | 58 | unsigned getItinClassNumber(const Record *InstRec); |
Chris Lattner | 0d58d02 | 2008-01-06 01:20:13 +0000 | [diff] [blame] | 59 | |
Chris Lattner | 4533a72 | 2008-01-06 01:21:51 +0000 | [diff] [blame] | 60 | // Operand information. |
Chris Lattner | 0d58d02 | 2008-01-06 01:20:13 +0000 | [diff] [blame] | 61 | void EmitOperandInfo(std::ostream &OS, OperandInfoMapTy &OperandInfoIDs); |
| 62 | std::vector<std::string> GetOperandInfo(const CodeGenInstruction &Inst); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 63 | }; |
| 64 | |
| 65 | } // End llvm namespace |
| 66 | |
| 67 | #endif |