Add class MipsAnalyzeImmediate which comes up with an instruction sequence to
[oota-llvm.git] / lib / Target / Mips / MipsAnalyzeImmediate.h
1 //===-- MipsAnalyzeImmediate.h - Analyze immediates -----------------------===//
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 #ifndef MIPS_ANALYZE_IMMEDIATE_H
10 #define MIPS_ANALYZE_IMMEDIATE_H
11
12 #include "llvm/ADT/SmallVector.h"
13
14 namespace llvm {
15
16   class MipsAnalyzeImmediate {
17   public:
18     struct Inst {
19       unsigned Opc, ImmOpnd;
20       Inst(unsigned Opc, unsigned ImmOpnd);
21     };
22     typedef SmallVector<Inst, 7 > InstSeq;
23
24     /// Analyze - Get an instrucion sequence to load immediate Imm. The last
25     /// instruction in the sequence must be an ADDiu if LastInstrIsADDiu is
26     /// true;
27     const InstSeq &Analyze(int64_t Imm, unsigned Size, bool LastInstrIsADDiu);
28   private:
29     typedef SmallVector<InstSeq, 5> InstSeqLs;
30
31     /// AddInstr - Add I to all instruction sequences in SeqLs.
32     void AddInstr(InstSeqLs &SeqLs, const Inst &I);
33
34     /// GetInstSeqLsADDiu - Get instrucion sequences which end with an ADDiu to
35     /// load immediate Imm
36     void GetInstSeqLsADDiu(int64_t Imm, unsigned RemSize, InstSeqLs &SeqLs);
37
38     /// GetInstSeqLsORi - Get instrucion sequences which end with an ORi to
39     /// load immediate Imm
40     void GetInstSeqLsORi(int64_t Imm, unsigned RemSize, InstSeqLs &SeqLs);
41
42     /// GetInstSeqLsSLL - Get instrucion sequences which end with a SLL to
43     /// load immediate Imm
44     void GetInstSeqLsSLL(int64_t Imm, unsigned RemSize, InstSeqLs &SeqLs);
45
46     /// GetInstSeqLs - Get instrucion sequences to load immediate Imm.
47     void GetInstSeqLs(int64_t Imm, unsigned RemSize, InstSeqLs &SeqLs);
48
49     /// ReplaceADDiuSLLWithLUi - Replace an ADDiu & SLL pair with a LUi.
50     void ReplaceADDiuSLLWithLUi(InstSeq &Seq);
51
52     /// GetShortestSeq - Find the shortest instruction sequence in SeqLs and
53     /// return it in Insts. 
54     void GetShortestSeq(InstSeqLs &SeqLs, InstSeq &Insts);
55
56     unsigned Size;
57     unsigned ADDiu, ORi, SLL, LUi;
58     InstSeq Insts;
59   };
60 }
61
62 #endif