ARMMachineFunctionInfo.h revision 210299
167754Smsmith//====- ARMMachineFuctionInfo.h - ARM machine function info -----*- C++ -*-===//
267754Smsmith//
367754Smsmith//                     The LLVM Compiler Infrastructure
467754Smsmith//
570243Smsmith// This file is distributed under the University of Illinois Open Source
667754Smsmith// License. See LICENSE.TXT for details.
767754Smsmith//
867754Smsmith//===----------------------------------------------------------------------===//
967754Smsmith//
1067754Smsmith// This file declares ARM-specific per-machine-function information.
1167754Smsmith//
1267754Smsmith//===----------------------------------------------------------------------===//
1370243Smsmith
1470243Smsmith#ifndef ARMMACHINEFUNCTIONINFO_H
1567754Smsmith#define ARMMACHINEFUNCTIONINFO_H
1667754Smsmith
1767754Smsmith#include "ARMSubtarget.h"
1867754Smsmith#include "llvm/CodeGen/MachineFunction.h"
1967754Smsmith#include "llvm/Target/TargetRegisterInfo.h"
2067754Smsmith#include "llvm/Target/TargetMachine.h"
2167754Smsmith#include "llvm/ADT/BitVector.h"
2267754Smsmith
2367754Smsmithnamespace llvm {
2467754Smsmith
2567754Smsmith/// ARMFunctionInfo - This class is derived from MachineFunction private
2667754Smsmith/// ARM target-specific information for each MachineFunction.
2767754Smsmithclass ARMFunctionInfo : public MachineFunctionInfo {
2867754Smsmith
2967754Smsmith  /// isThumb - True if this function is compiled under Thumb mode.
3067754Smsmith  /// Used to initialized Align, so must precede it.
3167754Smsmith  bool isThumb;
3267754Smsmith
3367754Smsmith  /// hasThumb2 - True if the target architecture supports Thumb2. Do not use
3467754Smsmith  /// to determine if function is compiled under Thumb mode, for that use
3567754Smsmith  /// 'isThumb'.
3667754Smsmith  bool hasThumb2;
3767754Smsmith
3867754Smsmith  /// VarArgsRegSaveSize - Size of the register save area for vararg functions.
3967754Smsmith  ///
4067754Smsmith  unsigned VarArgsRegSaveSize;
4167754Smsmith
4267754Smsmith  /// HasStackFrame - True if this function has a stack frame. Set by
4367754Smsmith  /// processFunctionBeforeCalleeSavedScan().
4467754Smsmith  bool HasStackFrame;
4567754Smsmith
4667754Smsmith  /// LRSpilledForFarJump - True if the LR register has been for spilled to
4767754Smsmith  /// enable far jump.
4867754Smsmith  bool LRSpilledForFarJump;
4967754Smsmith
5067754Smsmith  /// FramePtrSpillOffset - If HasStackFrame, this records the frame pointer
5167754Smsmith  /// spill stack offset.
5267754Smsmith  unsigned FramePtrSpillOffset;
5367754Smsmith
5467754Smsmith  /// GPRCS1Offset, GPRCS2Offset, DPRCSOffset - Starting offset of callee saved
5567754Smsmith  /// register spills areas. For Mac OS X:
5667754Smsmith  ///
5767754Smsmith  /// GPR callee-saved (1) : r4, r5, r6, r7, lr
5867754Smsmith  /// --------------------------------------------
5967754Smsmith  /// GPR callee-saved (2) : r8, r10, r11
6067754Smsmith  /// --------------------------------------------
6167754Smsmith  /// DPR callee-saved : d8 - d15
6267754Smsmith  unsigned GPRCS1Offset;
6367754Smsmith  unsigned GPRCS2Offset;
6467754Smsmith  unsigned DPRCSOffset;
6567754Smsmith
6667754Smsmith  /// GPRCS1Size, GPRCS2Size, DPRCSSize - Sizes of callee saved register spills
6767754Smsmith  /// areas.
6867754Smsmith  unsigned GPRCS1Size;
6967754Smsmith  unsigned GPRCS2Size;
7067754Smsmith  unsigned DPRCSSize;
7167754Smsmith
7267754Smsmith  /// GPRCS1Frames, GPRCS2Frames, DPRCSFrames - Keeps track of frame indices
7367754Smsmith  /// which belong to these spill areas.
7467754Smsmith  BitVector GPRCS1Frames;
7567754Smsmith  BitVector GPRCS2Frames;
7667754Smsmith  BitVector DPRCSFrames;
7767754Smsmith
7867754Smsmith  /// SpilledCSRegs - A BitVector mask of all spilled callee-saved registers.
7967754Smsmith  ///
8067754Smsmith  BitVector SpilledCSRegs;
8167754Smsmith
8267754Smsmith  /// JumpTableUId - Unique id for jumptables.
8367754Smsmith  ///
8467754Smsmith  unsigned JumpTableUId;
8567754Smsmith
8667754Smsmith  unsigned ConstPoolEntryUId;
8767754Smsmith
8867754Smsmith  /// VarArgsFrameIndex - FrameIndex for start of varargs area.
8967754Smsmith  int VarArgsFrameIndex;
9067754Smsmith
9167754Smsmith  /// HasITBlocks - True if IT blocks have been inserted.
9267754Smsmith  bool HasITBlocks;
9367754Smsmith
9467754Smsmithpublic:
9567754Smsmith  ARMFunctionInfo() :
9667754Smsmith    isThumb(false),
9767754Smsmith    hasThumb2(false),
9867754Smsmith    VarArgsRegSaveSize(0), HasStackFrame(false),
9967754Smsmith    LRSpilledForFarJump(false),
10067754Smsmith    FramePtrSpillOffset(0), GPRCS1Offset(0), GPRCS2Offset(0), DPRCSOffset(0),
10167754Smsmith    GPRCS1Size(0), GPRCS2Size(0), DPRCSSize(0),
10267754Smsmith    GPRCS1Frames(0), GPRCS2Frames(0), DPRCSFrames(0),
10367754Smsmith    JumpTableUId(0), ConstPoolEntryUId(0), VarArgsFrameIndex(0),
10467754Smsmith    HasITBlocks(false) {}
10567754Smsmith
10667754Smsmith  explicit ARMFunctionInfo(MachineFunction &MF) :
10767754Smsmith    isThumb(MF.getTarget().getSubtarget<ARMSubtarget>().isThumb()),
10867754Smsmith    hasThumb2(MF.getTarget().getSubtarget<ARMSubtarget>().hasThumb2()),
10967754Smsmith    VarArgsRegSaveSize(0), HasStackFrame(false),
11067754Smsmith    LRSpilledForFarJump(false),
11167754Smsmith    FramePtrSpillOffset(0), GPRCS1Offset(0), GPRCS2Offset(0), DPRCSOffset(0),
11267754Smsmith    GPRCS1Size(0), GPRCS2Size(0), DPRCSSize(0),
11367754Smsmith    GPRCS1Frames(32), GPRCS2Frames(32), DPRCSFrames(32),
11467754Smsmith    SpilledCSRegs(MF.getTarget().getRegisterInfo()->getNumRegs()),
11567754Smsmith    JumpTableUId(0), ConstPoolEntryUId(0), VarArgsFrameIndex(0),
11667754Smsmith    HasITBlocks(false) {}
11767754Smsmith
11867754Smsmith  bool isThumbFunction() const { return isThumb; }
11967754Smsmith  bool isThumb1OnlyFunction() const { return isThumb && !hasThumb2; }
12067754Smsmith  bool isThumb2Function() const { return isThumb && hasThumb2; }
12167754Smsmith
12267754Smsmith  unsigned getVarArgsRegSaveSize() const { return VarArgsRegSaveSize; }
12367754Smsmith  void setVarArgsRegSaveSize(unsigned s) { VarArgsRegSaveSize = s; }
12467754Smsmith
12567754Smsmith  bool hasStackFrame() const { return HasStackFrame; }
12667754Smsmith  void setHasStackFrame(bool s) { HasStackFrame = s; }
12767754Smsmith
12867754Smsmith  bool isLRSpilledForFarJump() const { return LRSpilledForFarJump; }
12967754Smsmith  void setLRIsSpilledForFarJump(bool s) { LRSpilledForFarJump = s; }
13067754Smsmith
13167754Smsmith  unsigned getFramePtrSpillOffset() const { return FramePtrSpillOffset; }
13267754Smsmith  void setFramePtrSpillOffset(unsigned o) { FramePtrSpillOffset = o; }
13367754Smsmith
13467754Smsmith  unsigned getGPRCalleeSavedArea1Offset() const { return GPRCS1Offset; }
13567754Smsmith  unsigned getGPRCalleeSavedArea2Offset() const { return GPRCS2Offset; }
13667754Smsmith  unsigned getDPRCalleeSavedAreaOffset()  const { return DPRCSOffset; }
13767754Smsmith
13867754Smsmith  void setGPRCalleeSavedArea1Offset(unsigned o) { GPRCS1Offset = o; }
13967754Smsmith  void setGPRCalleeSavedArea2Offset(unsigned o) { GPRCS2Offset = o; }
14067754Smsmith  void setDPRCalleeSavedAreaOffset(unsigned o)  { DPRCSOffset = o; }
14167754Smsmith
14267754Smsmith  unsigned getGPRCalleeSavedArea1Size() const { return GPRCS1Size; }
14367754Smsmith  unsigned getGPRCalleeSavedArea2Size() const { return GPRCS2Size; }
14467754Smsmith  unsigned getDPRCalleeSavedAreaSize()  const { return DPRCSSize; }
14567754Smsmith
14667754Smsmith  void setGPRCalleeSavedArea1Size(unsigned s) { GPRCS1Size = s; }
14767754Smsmith  void setGPRCalleeSavedArea2Size(unsigned s) { GPRCS2Size = s; }
14867754Smsmith  void setDPRCalleeSavedAreaSize(unsigned s)  { DPRCSSize = s; }
14967754Smsmith
15067754Smsmith  bool isGPRCalleeSavedArea1Frame(int fi) const {
15167754Smsmith    if (fi < 0 || fi >= (int)GPRCS1Frames.size())
15267754Smsmith      return false;
15367754Smsmith    return GPRCS1Frames[fi];
15467754Smsmith  }
15567754Smsmith  bool isGPRCalleeSavedArea2Frame(int fi) const {
15667754Smsmith    if (fi < 0 || fi >= (int)GPRCS2Frames.size())
15767754Smsmith      return false;
15867754Smsmith    return GPRCS2Frames[fi];
15967754Smsmith  }
16067754Smsmith  bool isDPRCalleeSavedAreaFrame(int fi) const {
16167754Smsmith    if (fi < 0 || fi >= (int)DPRCSFrames.size())
16267754Smsmith      return false;
16367754Smsmith    return DPRCSFrames[fi];
16467754Smsmith  }
16567754Smsmith
16667754Smsmith  void addGPRCalleeSavedArea1Frame(int fi) {
16767754Smsmith    if (fi >= 0) {
16867754Smsmith      int Size = GPRCS1Frames.size();
16967754Smsmith      if (fi >= Size) {
17067754Smsmith        Size *= 2;
17167754Smsmith        if (fi >= Size)
17267754Smsmith          Size = fi+1;
17367754Smsmith        GPRCS1Frames.resize(Size);
17467754Smsmith      }
17567754Smsmith      GPRCS1Frames[fi] = true;
17667754Smsmith    }
17767754Smsmith  }
17867754Smsmith  void addGPRCalleeSavedArea2Frame(int fi) {
17967754Smsmith    if (fi >= 0) {
18067754Smsmith      int Size = GPRCS2Frames.size();
18167754Smsmith      if (fi >= Size) {
18267754Smsmith        Size *= 2;
18367754Smsmith        if (fi >= Size)
18467754Smsmith          Size = fi+1;
18567754Smsmith        GPRCS2Frames.resize(Size);
18667754Smsmith      }
18767754Smsmith      GPRCS2Frames[fi] = true;
18867754Smsmith    }
18967754Smsmith  }
19067754Smsmith  void addDPRCalleeSavedAreaFrame(int fi) {
19167754Smsmith    if (fi >= 0) {
19267754Smsmith      int Size = DPRCSFrames.size();
19367754Smsmith      if (fi >= Size) {
19467754Smsmith        Size *= 2;
19567754Smsmith        if (fi >= Size)
19667754Smsmith          Size = fi+1;
19767754Smsmith        DPRCSFrames.resize(Size);
19867754Smsmith      }
19967754Smsmith      DPRCSFrames[fi] = true;
20067754Smsmith    }
20167754Smsmith  }
20267754Smsmith
20367754Smsmith  void setCSRegisterIsSpilled(unsigned Reg) {
20467754Smsmith    SpilledCSRegs.set(Reg);
20567754Smsmith  }
20667754Smsmith
20767754Smsmith  bool isCSRegisterSpilled(unsigned Reg) const {
20867754Smsmith    return SpilledCSRegs[Reg];
20967754Smsmith  }
21067754Smsmith
21167754Smsmith  const BitVector &getSpilledCSRegisters() const {
21267754Smsmith    return SpilledCSRegs;
21367754Smsmith  }
21467754Smsmith
21567754Smsmith  unsigned createJumpTableUId() {
21667754Smsmith    return JumpTableUId++;
21767754Smsmith  }
21867754Smsmith
21967754Smsmith  unsigned getNumJumpTables() const {
22067754Smsmith    return JumpTableUId;
22167754Smsmith  }
22267754Smsmith
22367754Smsmith  void initConstPoolEntryUId(unsigned UId) {
22467754Smsmith    ConstPoolEntryUId = UId;
22567754Smsmith  }
22667754Smsmith
22767754Smsmith  unsigned getNumConstPoolEntries() const {
22867754Smsmith    return ConstPoolEntryUId;
22967754Smsmith  }
23067754Smsmith
23167754Smsmith  unsigned createConstPoolEntryUId() {
23267754Smsmith    return ConstPoolEntryUId++;
23367754Smsmith  }
23467754Smsmith
23567754Smsmith  int getVarArgsFrameIndex() const { return VarArgsFrameIndex; }
23667754Smsmith  void setVarArgsFrameIndex(int Index) { VarArgsFrameIndex = Index; }
23767754Smsmith
23867754Smsmith  bool hasITBlocks() const { return HasITBlocks; }
23967754Smsmith  void setHasITBlocks(bool h) { HasITBlocks = h; }
24067754Smsmith};
24167754Smsmith} // End llvm namespace
24267754Smsmith
24367754Smsmith#endif // ARMMACHINEFUNCTIONINFO_H
24467754Smsmith