1234285Sdim//===-- MipsAnalyzeImmediate.h - Analyze Immediates ------------*- C++ -*--===// 2234285Sdim// 3234285Sdim// The LLVM Compiler Infrastructure 4234285Sdim// 5234285Sdim// This file is distributed under the University of Illinois Open Source 6234285Sdim// License. See LICENSE.TXT for details. 7234285Sdim// 8234285Sdim//===----------------------------------------------------------------------===// 9234285Sdim#ifndef MIPS_ANALYZE_IMMEDIATE_H 10234285Sdim#define MIPS_ANALYZE_IMMEDIATE_H 11234285Sdim 12234285Sdim#include "llvm/ADT/SmallVector.h" 13234285Sdim#include "llvm/Support/DataTypes.h" 14234285Sdim 15234285Sdimnamespace llvm { 16234285Sdim 17234285Sdim class MipsAnalyzeImmediate { 18234285Sdim public: 19234285Sdim struct Inst { 20234285Sdim unsigned Opc, ImmOpnd; 21234285Sdim Inst(unsigned Opc, unsigned ImmOpnd); 22234285Sdim }; 23234285Sdim typedef SmallVector<Inst, 7 > InstSeq; 24234285Sdim 25263508Sdim /// Analyze - Get an instruction sequence to load immediate Imm. The last 26234285Sdim /// instruction in the sequence must be an ADDiu if LastInstrIsADDiu is 27234285Sdim /// true; 28234285Sdim const InstSeq &Analyze(uint64_t Imm, unsigned Size, bool LastInstrIsADDiu); 29234285Sdim private: 30234285Sdim typedef SmallVector<InstSeq, 5> InstSeqLs; 31234285Sdim 32234285Sdim /// AddInstr - Add I to all instruction sequences in SeqLs. 33234285Sdim void AddInstr(InstSeqLs &SeqLs, const Inst &I); 34234285Sdim 35263508Sdim /// GetInstSeqLsADDiu - Get instruction sequences which end with an ADDiu to 36234285Sdim /// load immediate Imm 37234285Sdim void GetInstSeqLsADDiu(uint64_t Imm, unsigned RemSize, InstSeqLs &SeqLs); 38234285Sdim 39263508Sdim /// GetInstSeqLsORi - Get instrutcion sequences which end with an ORi to 40234285Sdim /// load immediate Imm 41234285Sdim void GetInstSeqLsORi(uint64_t Imm, unsigned RemSize, InstSeqLs &SeqLs); 42234285Sdim 43263508Sdim /// GetInstSeqLsSLL - Get instruction sequences which end with a SLL to 44234285Sdim /// load immediate Imm 45234285Sdim void GetInstSeqLsSLL(uint64_t Imm, unsigned RemSize, InstSeqLs &SeqLs); 46234285Sdim 47263508Sdim /// GetInstSeqLs - Get instruction sequences to load immediate Imm. 48234285Sdim void GetInstSeqLs(uint64_t Imm, unsigned RemSize, InstSeqLs &SeqLs); 49234285Sdim 50234285Sdim /// ReplaceADDiuSLLWithLUi - Replace an ADDiu & SLL pair with a LUi. 51234285Sdim void ReplaceADDiuSLLWithLUi(InstSeq &Seq); 52234285Sdim 53234285Sdim /// GetShortestSeq - Find the shortest instruction sequence in SeqLs and 54234285Sdim /// return it in Insts. 55234285Sdim void GetShortestSeq(InstSeqLs &SeqLs, InstSeq &Insts); 56234285Sdim 57234285Sdim unsigned Size; 58234285Sdim unsigned ADDiu, ORi, SLL, LUi; 59234285Sdim InstSeq Insts; 60234285Sdim }; 61234285Sdim} 62234285Sdim 63234285Sdim#endif 64