blob: 325bc8be146f61bbf2db35ec946f23f4b9db137d [file] [log] [blame]
Jim Grosbach86f9adb2011-07-08 17:36:35 +00001//===- 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"
Peter Collingbourne7c788882011-10-01 16:41:13 +000015#include "llvm/TableGen/TableGenBackend.h"
Jim Grosbach86f9adb2011-07-08 17:36:35 +000016#include "llvm/ADT/IndexedMap.h"
17#include "llvm/ADT/SmallVector.h"
18
19namespace llvm {
20
21class 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
David Greene05bce0b2011-07-29 22:43:06 +000050 unsigned addDagOperandMapping(Record *Rec, DagInit *Dag,
Jim Grosbach86f9adb2011-07-08 17:36:35 +000051 CodeGenInstruction &Insn,
52 IndexedMap<OpData> &OperandMap,
53 unsigned BaseIdx);
54 void evaluateExpansion(Record *Pseudo);
55 void emitLoweringEmitter(raw_ostream &o);
56public:
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