LLVM 24.0.0git
AutoUpgrade.h
Go to the documentation of this file.
1//===- AutoUpgrade.h - AutoUpgrade Helpers ----------------------*- C++ -*-===//
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//
9// These functions are implemented by lib/IR/AutoUpgrade.cpp.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_IR_AUTOUPGRADE_H
14#define LLVM_IR_AUTOUPGRADE_H
15
16#include "llvm/ADT/DenseMap.h"
17#include "llvm/ADT/StringRef.h"
19#include <vector>
20
21namespace 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
34 template <typename T> class OperandBundleDefT;
36
37 /// This is a more granular function that simply checks an intrinsic function
38 /// for upgrading, and returns true if it requires upgrading. It may return
39 /// null in NewFn if the all calls to the original intrinsic function
40 /// should be transformed to non-function-call instructions.
41 LLVM_ABI bool
43 bool CanUpgradeDebugIntrinsicsToRecords = true);
44
45 /// This is the complement to the above, replacing a specific call to an
46 /// intrinsic function with a call to the specified new function.
48
49 // This upgrades the comment for objc retain release markers in inline asm
50 // calls
51 LLVM_ABI void UpgradeInlineAsmString(std::string *AsmStr);
52
53 /// This is an auto-upgrade hook for any old intrinsic function syntaxes
54 /// which need to have both the function updated as well as all calls updated
55 /// to the new function. This should only be run in a post-processing fashion
56 /// so that it can update all calls to the old function.
58
59 /// This checks for global variables which should be upgraded. If it requires
60 /// upgrading, returns a pointer to the upgraded variable.
62
63 /// This checks for module flags which should be upgraded. It returns true if
64 /// module is modified.
66
67 /// Upgrade the cfi.functions metadata node by calculating and inserting
68 /// the GUID for each function entry if it's missing.
70
71 /// Convert legacy nvvm.annotations metadata to appropriate function
72 /// attributes.
74
75 /// Convert calls to ARC runtime functions to intrinsic calls and upgrade the
76 /// old retain release marker to new module flag format.
78
80
81 /// Discover metadata used by instructions in this module, and apply the
82 /// suitable upgrade. Alias scope lists used by !alias.scope or !noalias
83 /// annotations, or by llvm.experimental.noalias.scope.decl intrinsics, are
84 /// upgraded using \ref UpgradeAliasScopeList.
86
87 /// Correct any IR that is relying on old function attribute behavior.
89
90 /// If the given TBAA tag uses the scalar TBAA format, create a new node
91 /// corresponding to the upgrade to the struct-path aware TBAA format.
92 /// Otherwise return the \p TBAANode itself.
94
95 /// If the given !tbaa.struct node has old-style scalar field tags, return an
96 /// equivalent node with each field tag upgraded to the struct-path aware
97 /// format. Otherwise return the node itself.
99
100 /// Mark any domains from scopes in \p ScopeList that don't have a
101 /// disjointness flag as non-disjoint. Returns the original list if there are
102 /// no changes.
104 UpgradeAliasScopeList(MDNode &ScopeList,
105 DenseMap<MDNode *, MDNode *> &UpgradedAliasScopes);
106
107 /// This is an auto-upgrade for bitcast between pointers with different
108 /// address spaces: the instruction is replaced by a pair ptrtoint+inttoptr.
110 Instruction *&Temp);
111
112 /// This is an auto-upgrade for bitcast constant expression between pointers
113 /// with different address spaces: the instruction is replaced by a pair
114 /// ptrtoint+inttoptr.
116 Type *DestTy);
117
118 /// Check the debug info version number, if it is out-dated, drop the debug
119 /// info. Return true if module is modified.
121
122 /// Copies module attributes to the functions in the module.
123 /// Currently only effects ARM, Thumb and AArch64 targets.
124 /// Supported attributes:
125 /// - branch-target-enforcement
126 /// - branch-protection-pauth-lr
127 /// - guarded-control-stack
128 /// - sign-return-address
129 /// - sign-return-address-with-bkey
131
132 /// Single-operand tags replacing a removed two-operand form
133 /// !{!"<Enable>", i1 X}: X = true selects Enable, X = false selects Disable.
138
139 inline constexpr BooleanLoopTags OldBooleanLoopTags[] = {
140 {"llvm.loop.distribute.enable", "llvm.loop.distribute.disable"},
141 {"llvm.loop.vectorize.enable", "llvm.loop.vectorize.disable"},
142 {"llvm.loop.vectorize.predicate.enable",
143 "llvm.loop.vectorize.predicate.disable"},
144 {"llvm.loop.vectorize.scalable.enable",
145 "llvm.loop.vectorize.scalable.disable"}};
146
147 /// Return the replacement tags for the enable tag \p Name, or nullptr.
149 for (const BooleanLoopTags &Tags : OldBooleanLoopTags)
150 if (Tags.Enable == Name)
151 return &Tags;
152 return nullptr;
153 }
154
155 /// Check whether a string looks like an old loop attachment tag.
157 // The enable tags are intentionally included: the current single-operand
158 // form shares the tag with the removed two-operand form (!{!"...", i1 X}),
159 // so we can only decide by inspecting the operands, which happens in
160 // upgradeLoopArgument().
161 return Name.starts_with("llvm.vectorizer.") || findBooleanLoopTags(Name);
162 }
163
164 /// Upgrade the loop attachment metadata node.
166
167 /// Upgrade the datalayout string by adding a section for address space
168 /// pointers.
169 LLVM_ABI std::string UpgradeDataLayoutString(StringRef DL, StringRef Triple);
170
171 /// Upgrade attributes that changed format or kind.
172 LLVM_ABI void UpgradeAttributes(AttrBuilder &B);
173
174 /// Upgrade operand bundles (without knowing about their user instruction).
175 LLVM_ABI void
176 UpgradeOperandBundles(std::vector<OperandBundleDef> &OperandBundles);
177
178} // End llvm namespace
179
180#endif
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_ABI
Definition Compiler.h:211
This file defines the DenseMap class.
#define F(x, y, z)
Definition MD5.cpp:54
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
This is an important base class in LLVM.
Definition Constant.h:44
Metadata node.
Definition Metadata.h:1081
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:68
A container for an operand bundle being viewed as a set of values rather than a set of uses.
A wrapper around a string literal that serves as a proxy for constructing global tables of StringRefs...
Definition StringRef.h:888
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
LLVM Value Representation.
Definition Value.h:75
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI void UpgradeIntrinsicCall(CallBase *CB, Function *NewFn)
This is the complement to the above, replacing a specific call to an intrinsic function with a call t...
LLVM_ABI void UpgradeSectionAttributes(Module &M)
LLVM_ABI void UpgradeInlineAsmString(std::string *AsmStr)
Upgrade comment in call to inline asm that represents an objc retain release marker.
LLVM_ABI bool UpgradeIntrinsicFunction(Function *F, Function *&NewFn, bool CanUpgradeDebugIntrinsicsToRecords=true)
This is a more granular function that simply checks an intrinsic function for upgrading,...
LLVM_ABI void UpgradeInstructionMetadata(Module &M)
Discover metadata used by instructions in this module, and apply the suitable upgrade.
LLVM_ABI MDNode * upgradeInstructionLoopAttachment(MDNode &N)
Upgrade the loop attachment metadata node.
LLVM_ABI void UpgradeAttributes(AttrBuilder &B)
Upgrade attributes that changed format or kind.
LLVM_ABI void UpgradeCallsToIntrinsic(Function *F)
This is an auto-upgrade hook for any old intrinsic function syntaxes which need to have both the func...
LLVM_ABI void UpgradeNVVMAnnotations(Module &M)
Convert legacy nvvm.annotations metadata to appropriate function attributes.
LLVM_ABI bool UpgradeModuleFlags(Module &M)
This checks for module flags which should be upgraded.
LLVM_ABI bool UpgradeCFIFunctionsMetadata(Module &M)
Upgrade the cfi.functions metadata node by calculating and inserting the GUID for each function entry...
LLVM_ABI void copyModuleAttrToFunctions(Module &M)
Copies module attributes to the functions in the module.
LLVM_ABI void UpgradeOperandBundles(std::vector< OperandBundleDef > &OperandBundles)
Upgrade operand bundles (without knowing about their user instruction).
LLVM_ABI Constant * UpgradeBitCastExpr(unsigned Opc, Constant *C, Type *DestTy)
This is an auto-upgrade for bitcast constant expression between pointers with different address space...
bool mayBeOldLoopAttachmentTag(StringRef Name)
Check whether a string looks like an old loop attachment tag.
LLVM_ABI std::string UpgradeDataLayoutString(StringRef DL, StringRef Triple)
Upgrade the datalayout string by adding a section for address space pointers.
constexpr BooleanLoopTags OldBooleanLoopTags[]
LLVM_ABI MDNode * UpgradeTBAAStructNode(MDNode &TBAAStructNode)
If the given !tbaa.struct node has old-style scalar field tags, return an equivalent node with each f...
LLVM_ABI MDNode * UpgradeAliasScopeList(MDNode &ScopeList, DenseMap< MDNode *, MDNode * > &UpgradedAliasScopes)
Mark any domains from scopes in ScopeList that don't have a disjointness flag as non-disjoint.
LLVM_ABI GlobalVariable * UpgradeGlobalVariable(GlobalVariable *GV)
This checks for global variables which should be upgraded.
const BooleanLoopTags * findBooleanLoopTags(StringRef Name)
Return the replacement tags for the enable tag Name, or nullptr.
OperandBundleDefT< Value * > OperandBundleDef
Definition AutoUpgrade.h:35
LLVM_ABI Instruction * UpgradeBitCastInst(unsigned Opc, Value *V, Type *DestTy, Instruction *&Temp)
This is an auto-upgrade for bitcast between pointers with different address spaces: the instruction i...
LLVM_ABI bool UpgradeDebugInfo(Module &M)
Check the debug info version number, if it is out-dated, drop the debug info.
LLVM_ABI void UpgradeFunctionAttributes(Function &F)
Correct any IR that is relying on old function attribute behavior.
LLVM_ABI MDNode * UpgradeTBAANode(MDNode &TBAANode)
If the given TBAA tag uses the scalar TBAA format, create a new node corresponding to the upgrade to ...
LLVM_ABI void UpgradeARCRuntime(Module &M)
Convert calls to ARC runtime functions to intrinsic calls and upgrade the old retain release marker t...
#define N
Single-operand tags replacing a removed two-operand form !
StringLiteral Disable
StringLiteral Enable