AutoUpgrade.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- AutoUpgrade.h - AutoUpgrade Helpers ----------------------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // These functions are implemented by lib/IR/AutoUpgrade.cpp.
  15. //
  16. //===----------------------------------------------------------------------===//
  17. #ifndef LLVM_IR_AUTOUPGRADE_H
  18. #define LLVM_IR_AUTOUPGRADE_H
  19. #include "llvm/ADT/StringRef.h"
  20. #include <vector>
  21. namespace llvm {
  22. class AttrBuilder;
  23. class CallBase;
  24. class Constant;
  25. class Function;
  26. class Instruction;
  27. class GlobalVariable;
  28. class MDNode;
  29. class Module;
  30. class StringRef;
  31. class Type;
  32. class Value;
  33. template <typename T> class OperandBundleDefT;
  34. using OperandBundleDef = OperandBundleDefT<Value *>;
  35. /// This is a more granular function that simply checks an intrinsic function
  36. /// for upgrading, and returns true if it requires upgrading. It may return
  37. /// null in NewFn if the all calls to the original intrinsic function
  38. /// should be transformed to non-function-call instructions.
  39. bool UpgradeIntrinsicFunction(Function *F, Function *&NewFn);
  40. /// This is the complement to the above, replacing a specific call to an
  41. /// intrinsic function with a call to the specified new function.
  42. void UpgradeIntrinsicCall(CallBase *CB, Function *NewFn);
  43. // This upgrades the comment for objc retain release markers in inline asm
  44. // calls
  45. void UpgradeInlineAsmString(std::string *AsmStr);
  46. /// This is an auto-upgrade hook for any old intrinsic function syntaxes
  47. /// which need to have both the function updated as well as all calls updated
  48. /// to the new function. This should only be run in a post-processing fashion
  49. /// so that it can update all calls to the old function.
  50. void UpgradeCallsToIntrinsic(Function* F);
  51. /// This checks for global variables which should be upgraded. It it requires
  52. /// upgrading, returns a pointer to the upgraded variable.
  53. GlobalVariable *UpgradeGlobalVariable(GlobalVariable *GV);
  54. /// This checks for module flags which should be upgraded. It returns true if
  55. /// module is modified.
  56. bool UpgradeModuleFlags(Module &M);
  57. /// Convert calls to ARC runtime functions to intrinsic calls and upgrade the
  58. /// old retain release marker to new module flag format.
  59. void UpgradeARCRuntime(Module &M);
  60. void UpgradeSectionAttributes(Module &M);
  61. /// Correct any IR that is relying on old function attribute behavior.
  62. void UpgradeFunctionAttributes(Function &F);
  63. /// If the given TBAA tag uses the scalar TBAA format, create a new node
  64. /// corresponding to the upgrade to the struct-path aware TBAA format.
  65. /// Otherwise return the \p TBAANode itself.
  66. MDNode *UpgradeTBAANode(MDNode &TBAANode);
  67. /// This is an auto-upgrade for bitcast between pointers with different
  68. /// address spaces: the instruction is replaced by a pair ptrtoint+inttoptr.
  69. Instruction *UpgradeBitCastInst(unsigned Opc, Value *V, Type *DestTy,
  70. Instruction *&Temp);
  71. /// This is an auto-upgrade for bitcast constant expression between pointers
  72. /// with different address spaces: the instruction is replaced by a pair
  73. /// ptrtoint+inttoptr.
  74. Constant *UpgradeBitCastExpr(unsigned Opc, Constant *C, Type *DestTy);
  75. /// Check the debug info version number, if it is out-dated, drop the debug
  76. /// info. Return true if module is modified.
  77. bool UpgradeDebugInfo(Module &M);
  78. /// Check whether a string looks like an old loop attachment tag.
  79. inline bool mayBeOldLoopAttachmentTag(StringRef Name) {
  80. return Name.startswith("llvm.vectorizer.");
  81. }
  82. /// Upgrade the loop attachment metadata node.
  83. MDNode *upgradeInstructionLoopAttachment(MDNode &N);
  84. /// Upgrade the datalayout string by adding a section for address space
  85. /// pointers.
  86. std::string UpgradeDataLayoutString(StringRef DL, StringRef Triple);
  87. /// Upgrade attributes that changed format or kind.
  88. void UpgradeAttributes(AttrBuilder &B);
  89. /// Upgrade operand bundles (without knowing about their user instruction).
  90. void UpgradeOperandBundles(std::vector<OperandBundleDef> &OperandBundles);
  91. } // End llvm namespace
  92. #endif
  93. #ifdef __GNUC__
  94. #pragma GCC diagnostic pop
  95. #endif