blob: cc09034a9c3964b5dfe2a312fd5ff15dbd18b491 [file] [log] [blame]
Jia Liudd6c1cd2012-02-17 01:23:50 +00001//===-- MipsAnalyzeImmediate.h - Analyze Immediates ------------*- C++ -*--===//
Akira Hatanakaff36fd32012-01-25 01:43:36 +00002//
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"
NAKAMURA Takumi6c421ea2012-01-25 03:34:41 +000013#include "llvm/Support/DataTypes.h"
Akira Hatanakaff36fd32012-01-25 01:43:36 +000014
15namespace llvm {
16
17 class MipsAnalyzeImmediate {
18 public:
19 struct Inst {
20 unsigned Opc, ImmOpnd;
21 Inst(unsigned Opc, unsigned ImmOpnd);
22 };
23 typedef SmallVector<Inst, 7 > InstSeq;
24
Robert Wilhelm2788d3e2013-09-28 13:42:22 +000025 /// Analyze - Get an instruction sequence to load immediate Imm. The last
Akira Hatanakaff36fd32012-01-25 01:43:36 +000026 /// instruction in the sequence must be an ADDiu if LastInstrIsADDiu is
27 /// true;
Ahmed Charles16620132012-03-09 06:36:45 +000028 const InstSeq &Analyze(uint64_t Imm, unsigned Size, bool LastInstrIsADDiu);
Akira Hatanakaff36fd32012-01-25 01:43:36 +000029 private:
30 typedef SmallVector<InstSeq, 5> InstSeqLs;
31
32 /// AddInstr - Add I to all instruction sequences in SeqLs.
33 void AddInstr(InstSeqLs &SeqLs, const Inst &I);
34
Robert Wilhelm2788d3e2013-09-28 13:42:22 +000035 /// GetInstSeqLsADDiu - Get instruction sequences which end with an ADDiu to
Akira Hatanakaff36fd32012-01-25 01:43:36 +000036 /// load immediate Imm
Ahmed Charles16620132012-03-09 06:36:45 +000037 void GetInstSeqLsADDiu(uint64_t Imm, unsigned RemSize, InstSeqLs &SeqLs);
Akira Hatanakaff36fd32012-01-25 01:43:36 +000038
Robert Wilhelm2788d3e2013-09-28 13:42:22 +000039 /// GetInstSeqLsORi - Get instrutcion sequences which end with an ORi to
Akira Hatanakaff36fd32012-01-25 01:43:36 +000040 /// load immediate Imm
Ahmed Charles16620132012-03-09 06:36:45 +000041 void GetInstSeqLsORi(uint64_t Imm, unsigned RemSize, InstSeqLs &SeqLs);
Akira Hatanakaff36fd32012-01-25 01:43:36 +000042
Robert Wilhelm2788d3e2013-09-28 13:42:22 +000043 /// GetInstSeqLsSLL - Get instruction sequences which end with a SLL to
Akira Hatanakaff36fd32012-01-25 01:43:36 +000044 /// load immediate Imm
Ahmed Charles16620132012-03-09 06:36:45 +000045 void GetInstSeqLsSLL(uint64_t Imm, unsigned RemSize, InstSeqLs &SeqLs);
Akira Hatanakaff36fd32012-01-25 01:43:36 +000046
Robert Wilhelm2788d3e2013-09-28 13:42:22 +000047 /// GetInstSeqLs - Get instruction sequences to load immediate Imm.
Ahmed Charles16620132012-03-09 06:36:45 +000048 void GetInstSeqLs(uint64_t Imm, unsigned RemSize, InstSeqLs &SeqLs);
Akira Hatanakaff36fd32012-01-25 01:43:36 +000049
50 /// ReplaceADDiuSLLWithLUi - Replace an ADDiu & SLL pair with a LUi.
51 void ReplaceADDiuSLLWithLUi(InstSeq &Seq);
52
53 /// GetShortestSeq - Find the shortest instruction sequence in SeqLs and
Jia Liuf54f60f2012-02-28 07:46:26 +000054 /// return it in Insts.
Akira Hatanakaff36fd32012-01-25 01:43:36 +000055 void GetShortestSeq(InstSeqLs &SeqLs, InstSeq &Insts);
56
57 unsigned Size;
58 unsigned ADDiu, ORi, SLL, LUi;
59 InstSeq Insts;
60 };
61}
62
63#endif