blob: 1c520242fb8d54eeb7787e7e901816841a30e4bb [file] [log] [blame]
Eugene Zelenko79220eae2017-08-03 22:12:30 +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//===----------------------------------------------------------------------===//
Eugene Zelenko79220eae2017-08-03 22:12:30 +00009
Benjamin Kramera7c40ef2014-08-13 16:26:38 +000010#ifndef LLVM_LIB_TARGET_MIPS_MIPSANALYZEIMMEDIATE_H
11#define LLVM_LIB_TARGET_MIPS_MIPSANALYZEIMMEDIATE_H
Akira Hatanakaff36fd32012-01-25 01:43:36 +000012
13#include "llvm/ADT/SmallVector.h"
Eugene Zelenko79220eae2017-08-03 22:12:30 +000014#include <cstdint>
Akira Hatanakaff36fd32012-01-25 01:43:36 +000015
16namespace llvm {
17
18 class MipsAnalyzeImmediate {
19 public:
20 struct Inst {
21 unsigned Opc, ImmOpnd;
Eugene Zelenko79220eae2017-08-03 22:12:30 +000022
Akira Hatanakaff36fd32012-01-25 01:43:36 +000023 Inst(unsigned Opc, unsigned ImmOpnd);
24 };
Eugene Zelenko79220eae2017-08-03 22:12:30 +000025 using InstSeq = SmallVector<Inst, 7>;
Akira Hatanakaff36fd32012-01-25 01:43:36 +000026
Robert Wilhelm2788d3e2013-09-28 13:42:22 +000027 /// Analyze - Get an instruction sequence to load immediate Imm. The last
Akira Hatanakaff36fd32012-01-25 01:43:36 +000028 /// instruction in the sequence must be an ADDiu if LastInstrIsADDiu is
29 /// true;
Ahmed Charles16620132012-03-09 06:36:45 +000030 const InstSeq &Analyze(uint64_t Imm, unsigned Size, bool LastInstrIsADDiu);
Eugene Zelenko79220eae2017-08-03 22:12:30 +000031
Akira Hatanakaff36fd32012-01-25 01:43:36 +000032 private:
Eugene Zelenko79220eae2017-08-03 22:12:30 +000033 using InstSeqLs = SmallVector<InstSeq, 5>;
Akira Hatanakaff36fd32012-01-25 01:43:36 +000034
35 /// AddInstr - Add I to all instruction sequences in SeqLs.
36 void AddInstr(InstSeqLs &SeqLs, const Inst &I);
37
Robert Wilhelm2788d3e2013-09-28 13:42:22 +000038 /// GetInstSeqLsADDiu - Get instruction sequences which end with an ADDiu to
Akira Hatanakaff36fd32012-01-25 01:43:36 +000039 /// load immediate Imm
Ahmed Charles16620132012-03-09 06:36:45 +000040 void GetInstSeqLsADDiu(uint64_t Imm, unsigned RemSize, InstSeqLs &SeqLs);
Akira Hatanakaff36fd32012-01-25 01:43:36 +000041
Robert Wilhelm2788d3e2013-09-28 13:42:22 +000042 /// GetInstSeqLsORi - Get instrutcion sequences which end with an ORi to
Akira Hatanakaff36fd32012-01-25 01:43:36 +000043 /// load immediate Imm
Ahmed Charles16620132012-03-09 06:36:45 +000044 void GetInstSeqLsORi(uint64_t Imm, unsigned RemSize, InstSeqLs &SeqLs);
Akira Hatanakaff36fd32012-01-25 01:43:36 +000045
Robert Wilhelm2788d3e2013-09-28 13:42:22 +000046 /// GetInstSeqLsSLL - Get instruction sequences which end with a SLL to
Akira Hatanakaff36fd32012-01-25 01:43:36 +000047 /// load immediate Imm
Ahmed Charles16620132012-03-09 06:36:45 +000048 void GetInstSeqLsSLL(uint64_t Imm, unsigned RemSize, InstSeqLs &SeqLs);
Akira Hatanakaff36fd32012-01-25 01:43:36 +000049
Robert Wilhelm2788d3e2013-09-28 13:42:22 +000050 /// GetInstSeqLs - Get instruction sequences to load immediate Imm.
Ahmed Charles16620132012-03-09 06:36:45 +000051 void GetInstSeqLs(uint64_t Imm, unsigned RemSize, InstSeqLs &SeqLs);
Akira Hatanakaff36fd32012-01-25 01:43:36 +000052
53 /// ReplaceADDiuSLLWithLUi - Replace an ADDiu & SLL pair with a LUi.
54 void ReplaceADDiuSLLWithLUi(InstSeq &Seq);
55
56 /// GetShortestSeq - Find the shortest instruction sequence in SeqLs and
Jia Liuf54f60f2012-02-28 07:46:26 +000057 /// return it in Insts.
Akira Hatanakaff36fd32012-01-25 01:43:36 +000058 void GetShortestSeq(InstSeqLs &SeqLs, InstSeq &Insts);
59
60 unsigned Size;
61 unsigned ADDiu, ORi, SLL, LUi;
62 InstSeq Insts;
63 };
Akira Hatanakaff36fd32012-01-25 01:43:36 +000064
Eugene Zelenko79220eae2017-08-03 22:12:30 +000065} // end namespace llvm
66
67#endif // LLVM_LIB_TARGET_MIPS_MIPSANALYZEIMMEDIATE_H