PPCMachineFunctionInfo.cpp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. //===-- PPCMachineFunctionInfo.cpp - Private data used for PowerPC --------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #include "PPCMachineFunctionInfo.h"
  9. #include "llvm/ADT/Twine.h"
  10. #include "llvm/BinaryFormat/XCOFF.h"
  11. #include "llvm/IR/DataLayout.h"
  12. #include "llvm/MC/MCContext.h"
  13. #include "llvm/Support/CommandLine.h"
  14. using namespace llvm;
  15. static cl::opt<bool> PPCDisableNonVolatileCR(
  16. "ppc-disable-non-volatile-cr",
  17. cl::desc("Disable the use of non-volatile CR register fields"),
  18. cl::init(false), cl::Hidden);
  19. void PPCFunctionInfo::anchor() {}
  20. PPCFunctionInfo::PPCFunctionInfo(const Function &F,
  21. const TargetSubtargetInfo *STI)
  22. : DisableNonVolatileCR(PPCDisableNonVolatileCR) {}
  23. MachineFunctionInfo *
  24. PPCFunctionInfo::clone(BumpPtrAllocator &Allocator, MachineFunction &DestMF,
  25. const DenseMap<MachineBasicBlock *, MachineBasicBlock *>
  26. &Src2DstMBB) const {
  27. return DestMF.cloneInfo<PPCFunctionInfo>(*this);
  28. }
  29. MCSymbol *PPCFunctionInfo::getPICOffsetSymbol(MachineFunction &MF) const {
  30. const DataLayout &DL = MF.getDataLayout();
  31. return MF.getContext().getOrCreateSymbol(Twine(DL.getPrivateGlobalPrefix()) +
  32. Twine(MF.getFunctionNumber()) +
  33. "$poff");
  34. }
  35. MCSymbol *PPCFunctionInfo::getGlobalEPSymbol(MachineFunction &MF) const {
  36. const DataLayout &DL = MF.getDataLayout();
  37. return MF.getContext().getOrCreateSymbol(Twine(DL.getPrivateGlobalPrefix()) +
  38. "func_gep" +
  39. Twine(MF.getFunctionNumber()));
  40. }
  41. MCSymbol *PPCFunctionInfo::getLocalEPSymbol(MachineFunction &MF) const {
  42. const DataLayout &DL = MF.getDataLayout();
  43. return MF.getContext().getOrCreateSymbol(Twine(DL.getPrivateGlobalPrefix()) +
  44. "func_lep" +
  45. Twine(MF.getFunctionNumber()));
  46. }
  47. MCSymbol *PPCFunctionInfo::getTOCOffsetSymbol(MachineFunction &MF) const {
  48. const DataLayout &DL = MF.getDataLayout();
  49. return MF.getContext().getOrCreateSymbol(Twine(DL.getPrivateGlobalPrefix()) +
  50. "func_toc" +
  51. Twine(MF.getFunctionNumber()));
  52. }
  53. bool PPCFunctionInfo::isLiveInSExt(Register VReg) const {
  54. for (const std::pair<Register, ISD::ArgFlagsTy> &LiveIn : LiveInAttrs)
  55. if (LiveIn.first == VReg)
  56. return LiveIn.second.isSExt();
  57. return false;
  58. }
  59. bool PPCFunctionInfo::isLiveInZExt(Register VReg) const {
  60. for (const std::pair<Register, ISD::ArgFlagsTy> &LiveIn : LiveInAttrs)
  61. if (LiveIn.first == VReg)
  62. return LiveIn.second.isZExt();
  63. return false;
  64. }
  65. void PPCFunctionInfo::appendParameterType(ParamType Type) {
  66. ParamtersType.push_back(Type);
  67. switch (Type) {
  68. case FixedType:
  69. ++FixedParmsNum;
  70. return;
  71. case ShortFloatingPoint:
  72. case LongFloatingPoint:
  73. ++FloatingParmsNum;
  74. return;
  75. case VectorChar:
  76. case VectorShort:
  77. case VectorInt:
  78. case VectorFloat:
  79. ++VectorParmsNum;
  80. return;
  81. }
  82. llvm_unreachable("Error ParamType type.");
  83. }
  84. uint32_t PPCFunctionInfo::getVecExtParmsType() const {
  85. uint32_t VectExtParamInfo = 0;
  86. unsigned ShiftBits = 32 - XCOFF::TracebackTable::WidthOfParamType;
  87. int Bits = 0;
  88. if (!hasVectorParms())
  89. return 0;
  90. for (const auto &Elt : ParamtersType) {
  91. switch (Elt) {
  92. case VectorChar:
  93. VectExtParamInfo <<= XCOFF::TracebackTable::WidthOfParamType;
  94. VectExtParamInfo |=
  95. XCOFF::TracebackTable::ParmTypeIsVectorCharBit >> ShiftBits;
  96. Bits += XCOFF::TracebackTable::WidthOfParamType;
  97. break;
  98. case VectorShort:
  99. VectExtParamInfo <<= XCOFF::TracebackTable::WidthOfParamType;
  100. VectExtParamInfo |=
  101. XCOFF::TracebackTable::ParmTypeIsVectorShortBit >> ShiftBits;
  102. Bits += XCOFF::TracebackTable::WidthOfParamType;
  103. break;
  104. case VectorInt:
  105. VectExtParamInfo <<= XCOFF::TracebackTable::WidthOfParamType;
  106. VectExtParamInfo |=
  107. XCOFF::TracebackTable::ParmTypeIsVectorIntBit >> ShiftBits;
  108. Bits += XCOFF::TracebackTable::WidthOfParamType;
  109. break;
  110. case VectorFloat:
  111. VectExtParamInfo <<= XCOFF::TracebackTable::WidthOfParamType;
  112. VectExtParamInfo |=
  113. XCOFF::TracebackTable::ParmTypeIsVectorFloatBit >> ShiftBits;
  114. Bits += XCOFF::TracebackTable::WidthOfParamType;
  115. break;
  116. default:
  117. break;
  118. }
  119. // There are only 32bits in the VectExtParamInfo.
  120. if (Bits >= 32)
  121. break;
  122. }
  123. return Bits < 32 ? VectExtParamInfo << (32 - Bits) : VectExtParamInfo;
  124. }
  125. uint32_t PPCFunctionInfo::getParmsType() const {
  126. uint32_t ParamsTypeInfo = 0;
  127. unsigned ShiftBits = 32 - XCOFF::TracebackTable::WidthOfParamType;
  128. int Bits = 0;
  129. for (const auto &Elt : ParamtersType) {
  130. if (Bits > 31 || (Bits > 30 && (Elt != FixedType || hasVectorParms())))
  131. break;
  132. switch (Elt) {
  133. case FixedType:
  134. if (hasVectorParms()) {
  135. //'00' ==> fixed parameter if HasVectorParms is true.
  136. ParamsTypeInfo <<= XCOFF::TracebackTable::WidthOfParamType;
  137. ParamsTypeInfo |=
  138. XCOFF::TracebackTable::ParmTypeIsFixedBits >> ShiftBits;
  139. Bits += XCOFF::TracebackTable::WidthOfParamType;
  140. } else {
  141. //'0' ==> fixed parameter if HasVectorParms is false.
  142. ParamsTypeInfo <<= 1;
  143. ++Bits;
  144. }
  145. break;
  146. case ShortFloatingPoint:
  147. // '10'b => floating point short parameter.
  148. ParamsTypeInfo <<= XCOFF::TracebackTable::WidthOfParamType;
  149. ParamsTypeInfo |=
  150. XCOFF::TracebackTable::ParmTypeIsFloatingBits >> ShiftBits;
  151. Bits += XCOFF::TracebackTable::WidthOfParamType;
  152. break;
  153. case LongFloatingPoint:
  154. // '11'b => floating point long parameter.
  155. ParamsTypeInfo <<= XCOFF::TracebackTable::WidthOfParamType;
  156. ParamsTypeInfo |=
  157. XCOFF::TracebackTable::ParmTypeIsDoubleBits >> ShiftBits;
  158. Bits += XCOFF::TracebackTable::WidthOfParamType;
  159. break;
  160. case VectorChar:
  161. case VectorShort:
  162. case VectorInt:
  163. case VectorFloat:
  164. // '01' ==> vector parameter
  165. ParamsTypeInfo <<= XCOFF::TracebackTable::WidthOfParamType;
  166. ParamsTypeInfo |=
  167. XCOFF::TracebackTable::ParmTypeIsVectorBits >> ShiftBits;
  168. Bits += XCOFF::TracebackTable::WidthOfParamType;
  169. break;
  170. }
  171. }
  172. return Bits < 32 ? ParamsTypeInfo << (32 - Bits) : ParamsTypeInfo;
  173. }