]> CyberLeo.Net >> Repos - FreeBSD/releng/9.0.git/blob - contrib/llvm/utils/TableGen/PseudoLoweringEmitter.h
Copy stable/9 to releng/9.0 as part of the FreeBSD 9.0-RELEASE release
[FreeBSD/releng/9.0.git] / contrib / llvm / utils / TableGen / PseudoLoweringEmitter.h
1 //===- PseudoLoweringEmitter.h - PseudoLowering Generator -------*- 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 #ifndef PSEUDOLOWERINGEMITTER_H
11 #define PSEUDOLOWERINGEMITTER_H
12
13 #include "CodeGenInstruction.h"
14 #include "CodeGenTarget.h"
15 #include "llvm/TableGen/TableGenBackend.h"
16 #include "llvm/ADT/IndexedMap.h"
17 #include "llvm/ADT/SmallVector.h"
18
19 namespace llvm {
20
21 class PseudoLoweringEmitter : public TableGenBackend {
22   struct OpData {
23     enum MapKind { Operand, Imm, Reg };
24     MapKind Kind;
25     union {
26       unsigned Operand;   // Operand number mapped to.
27       uint64_t Imm;       // Integer immedate value.
28       Record *Reg;        // Physical register.
29     } Data;
30   };
31   struct PseudoExpansion {
32     CodeGenInstruction Source;  // The source pseudo instruction definition.
33     CodeGenInstruction Dest;    // The destination instruction to lower to.
34     IndexedMap<OpData> OperandMap;
35
36     PseudoExpansion(CodeGenInstruction &s, CodeGenInstruction &d,
37                     IndexedMap<OpData> &m) :
38       Source(s), Dest(d), OperandMap(m) {}
39   };
40
41   RecordKeeper &Records;
42
43   // It's overkill to have an instance of the full CodeGenTarget object,
44   // but it loads everything on demand, not in the constructor, so it's
45   // lightweight in performance, so it works out OK.
46   CodeGenTarget Target;
47
48   SmallVector<PseudoExpansion, 64> Expansions;
49
50   unsigned addDagOperandMapping(Record *Rec, DagInit *Dag,
51                                 CodeGenInstruction &Insn,
52                                 IndexedMap<OpData> &OperandMap,
53                                 unsigned BaseIdx);
54   void evaluateExpansion(Record *Pseudo);
55   void emitLoweringEmitter(raw_ostream &o);
56 public:
57   PseudoLoweringEmitter(RecordKeeper &R) : Records(R), Target(R) {}
58
59   /// run - Output the pseudo-lowerings.
60   void run(raw_ostream &o);
61 };
62
63 } // end llvm namespace
64
65 #endif