PPCMachineFunctionInfo.cpp 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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 MachineFunction &MF)
  21. : DisableNonVolatileCR(PPCDisableNonVolatileCR) {}
  22. MCSymbol *PPCFunctionInfo::getPICOffsetSymbol(MachineFunction &MF) const {
  23. const DataLayout &DL = MF.getDataLayout();
  24. return MF.getContext().getOrCreateSymbol(Twine(DL.getPrivateGlobalPrefix()) +
  25. Twine(MF.getFunctionNumber()) +
  26. "$poff");
  27. }
  28. MCSymbol *PPCFunctionInfo::getGlobalEPSymbol(MachineFunction &MF) const {
  29. const DataLayout &DL = MF.getDataLayout();
  30. return MF.getContext().getOrCreateSymbol(Twine(DL.getPrivateGlobalPrefix()) +
  31. "func_gep" +
  32. Twine(MF.getFunctionNumber()));
  33. }
  34. MCSymbol *PPCFunctionInfo::getLocalEPSymbol(MachineFunction &MF) const {
  35. const DataLayout &DL = MF.getDataLayout();
  36. return MF.getContext().getOrCreateSymbol(Twine(DL.getPrivateGlobalPrefix()) +
  37. "func_lep" +
  38. Twine(MF.getFunctionNumber()));
  39. }
  40. MCSymbol *PPCFunctionInfo::getTOCOffsetSymbol(MachineFunction &MF) const {
  41. const DataLayout &DL = MF.getDataLayout();
  42. return MF.getContext().getOrCreateSymbol(Twine(DL.getPrivateGlobalPrefix()) +
  43. "func_toc" +
  44. Twine(MF.getFunctionNumber()));
  45. }
  46. bool PPCFunctionInfo::isLiveInSExt(Register VReg) const {
  47. for (const std::pair<Register, ISD::ArgFlagsTy> &LiveIn : LiveInAttrs)
  48. if (LiveIn.first == VReg)
  49. return LiveIn.second.isSExt();
  50. return false;
  51. }
  52. bool PPCFunctionInfo::isLiveInZExt(Register VReg) const {
  53. for (const std::pair<Register, ISD::ArgFlagsTy> &LiveIn : LiveInAttrs)
  54. if (LiveIn.first == VReg)
  55. return LiveIn.second.isZExt();
  56. return false;
  57. }
  58. void PPCFunctionInfo::appendParameterType(ParamType Type) {
  59. ParamtersType.push_back(Type);
  60. switch (Type) {
  61. case FixedType:
  62. ++FixedParmsNum;
  63. return;
  64. case ShortFloatingPoint:
  65. case LongFloatingPoint:
  66. ++FloatingParmsNum;
  67. return;
  68. case VectorChar:
  69. case VectorShort:
  70. case VectorInt:
  71. case VectorFloat:
  72. ++VectorParmsNum;
  73. return;
  74. }
  75. llvm_unreachable("Error ParamType type.");
  76. }
  77. uint32_t PPCFunctionInfo::getVecExtParmsType() const {
  78. uint32_t VectExtParamInfo = 0;
  79. unsigned ShiftBits = 32 - XCOFF::TracebackTable::WidthOfParamType;
  80. int Bits = 0;
  81. if (!hasVectorParms())
  82. return 0;
  83. for (const auto &Elt : ParamtersType) {
  84. switch (Elt) {
  85. case VectorChar:
  86. VectExtParamInfo <<= XCOFF::TracebackTable::WidthOfParamType;
  87. VectExtParamInfo |=
  88. XCOFF::TracebackTable::ParmTypeIsVectorCharBit >> ShiftBits;
  89. Bits += XCOFF::TracebackTable::WidthOfParamType;
  90. break;
  91. case VectorShort:
  92. VectExtParamInfo <<= XCOFF::TracebackTable::WidthOfParamType;
  93. VectExtParamInfo |=
  94. XCOFF::TracebackTable::ParmTypeIsVectorShortBit >> ShiftBits;
  95. Bits += XCOFF::TracebackTable::WidthOfParamType;
  96. break;
  97. case VectorInt:
  98. VectExtParamInfo <<= XCOFF::TracebackTable::WidthOfParamType;
  99. VectExtParamInfo |=
  100. XCOFF::TracebackTable::ParmTypeIsVectorIntBit >> ShiftBits;
  101. Bits += XCOFF::TracebackTable::WidthOfParamType;
  102. break;
  103. case VectorFloat:
  104. VectExtParamInfo <<= XCOFF::TracebackTable::WidthOfParamType;
  105. VectExtParamInfo |=
  106. XCOFF::TracebackTable::ParmTypeIsVectorFloatBit >> ShiftBits;
  107. Bits += XCOFF::TracebackTable::WidthOfParamType;
  108. break;
  109. default:
  110. break;
  111. }
  112. // There are only 32bits in the VectExtParamInfo.
  113. if (Bits >= 32)
  114. break;
  115. }
  116. return Bits < 32 ? VectExtParamInfo << (32 - Bits) : VectExtParamInfo;
  117. }
  118. uint32_t PPCFunctionInfo::getParmsType() const {
  119. uint32_t ParamsTypeInfo = 0;
  120. unsigned ShiftBits = 32 - XCOFF::TracebackTable::WidthOfParamType;
  121. int Bits = 0;
  122. for (const auto &Elt : ParamtersType) {
  123. if (Bits > 31 || (Bits > 30 && (Elt != FixedType || hasVectorParms())))
  124. break;
  125. switch (Elt) {
  126. case FixedType:
  127. if (hasVectorParms()) {
  128. //'00' ==> fixed parameter if HasVectorParms is true.
  129. ParamsTypeInfo <<= XCOFF::TracebackTable::WidthOfParamType;
  130. ParamsTypeInfo |=
  131. XCOFF::TracebackTable::ParmTypeIsFixedBits >> ShiftBits;
  132. Bits += XCOFF::TracebackTable::WidthOfParamType;
  133. } else {
  134. //'0' ==> fixed parameter if HasVectorParms is false.
  135. ParamsTypeInfo <<= 1;
  136. ++Bits;
  137. }
  138. break;
  139. case ShortFloatingPoint:
  140. // '10'b => floating point short parameter.
  141. ParamsTypeInfo <<= XCOFF::TracebackTable::WidthOfParamType;
  142. ParamsTypeInfo |=
  143. XCOFF::TracebackTable::ParmTypeIsFloatingBits >> ShiftBits;
  144. Bits += XCOFF::TracebackTable::WidthOfParamType;
  145. break;
  146. case LongFloatingPoint:
  147. // '11'b => floating point long parameter.
  148. ParamsTypeInfo <<= XCOFF::TracebackTable::WidthOfParamType;
  149. ParamsTypeInfo |=
  150. XCOFF::TracebackTable::ParmTypeIsDoubleBits >> ShiftBits;
  151. Bits += XCOFF::TracebackTable::WidthOfParamType;
  152. break;
  153. case VectorChar:
  154. case VectorShort:
  155. case VectorInt:
  156. case VectorFloat:
  157. // '01' ==> vector parameter
  158. ParamsTypeInfo <<= XCOFF::TracebackTable::WidthOfParamType;
  159. ParamsTypeInfo |=
  160. XCOFF::TracebackTable::ParmTypeIsVectorBits >> ShiftBits;
  161. Bits += XCOFF::TracebackTable::WidthOfParamType;
  162. break;
  163. }
  164. }
  165. return Bits < 32 ? ParamsTypeInfo << (32 - Bits) : ParamsTypeInfo;
  166. }