LLVM  16.0.0git
ModuleUtils.cpp
Go to the documentation of this file.
1 //===-- ModuleUtils.cpp - Functions to manipulate Modules -----------------===//
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 // This family of functions perform manipulations on Modules.
10 //
11 //===----------------------------------------------------------------------===//
12 
15 #include "llvm/IR/DerivedTypes.h"
16 #include "llvm/IR/Function.h"
17 #include "llvm/IR/IRBuilder.h"
18 #include "llvm/IR/Module.h"
20 using namespace llvm;
21 
22 #define DEBUG_TYPE "moduleutils"
23 
24 static void appendToGlobalArray(StringRef ArrayName, Module &M, Function *F,
25  int Priority, Constant *Data) {
26  IRBuilder<> IRB(M.getContext());
27  FunctionType *FnTy = FunctionType::get(IRB.getVoidTy(), false);
28 
29  // Get the current set of static global constructors and add the new ctor
30  // to the list.
31  SmallVector<Constant *, 16> CurrentCtors;
32  StructType *EltTy = StructType::get(
33  IRB.getInt32Ty(), PointerType::get(FnTy, F->getAddressSpace()),
34  IRB.getInt8PtrTy());
35 
36  if (GlobalVariable *GVCtor = M.getNamedGlobal(ArrayName)) {
37  if (Constant *Init = GVCtor->getInitializer()) {
38  unsigned n = Init->getNumOperands();
39  CurrentCtors.reserve(n + 1);
40  for (unsigned i = 0; i != n; ++i)
41  CurrentCtors.push_back(cast<Constant>(Init->getOperand(i)));
42  }
43  GVCtor->eraseFromParent();
44  }
45 
46  // Build a 3 field global_ctor entry. We don't take a comdat key.
47  Constant *CSVals[3];
48  CSVals[0] = IRB.getInt32(Priority);
49  CSVals[1] = F;
52  Constant *RuntimeCtorInit =
53  ConstantStruct::get(EltTy, makeArrayRef(CSVals, EltTy->getNumElements()));
54 
55  CurrentCtors.push_back(RuntimeCtorInit);
56 
57  // Create a new initializer.
58  ArrayType *AT = ArrayType::get(EltTy, CurrentCtors.size());
59  Constant *NewInit = ConstantArray::get(AT, CurrentCtors);
60 
61  // Create the new global variable and replace all uses of
62  // the old global variable with the new one.
63  (void)new GlobalVariable(M, NewInit->getType(), false,
64  GlobalValue::AppendingLinkage, NewInit, ArrayName);
65 }
66 
68  appendToGlobalArray("llvm.global_ctors", M, F, Priority, Data);
69 }
70 
72  appendToGlobalArray("llvm.global_dtors", M, F, Priority, Data);
73 }
74 
76  GlobalVariable *GV = M.getGlobalVariable(Name);
79  if (GV) {
80  if (GV->hasInitializer()) {
81  auto *CA = cast<ConstantArray>(GV->getInitializer());
82  for (auto &Op : CA->operands()) {
83  Constant *C = cast_or_null<Constant>(Op);
84  if (InitAsSet.insert(C).second)
85  Init.push_back(C);
86  }
87  }
88  GV->eraseFromParent();
89  }
90 
91  Type *Int8PtrTy = llvm::Type::getInt8PtrTy(M.getContext());
92  for (auto *V : Values) {
94  if (InitAsSet.insert(C).second)
95  Init.push_back(C);
96  }
97 
98  if (Init.empty())
99  return;
100 
101  ArrayType *ATy = ArrayType::get(Int8PtrTy, Init.size());
103  ConstantArray::get(ATy, Init), Name);
104  GV->setSection("llvm.metadata");
105 }
106 
108  appendToUsedList(M, "llvm.used", Values);
109 }
110 
112  appendToUsedList(M, "llvm.compiler.used", Values);
113 }
114 
117  ArrayRef<Type *> InitArgTypes) {
118  assert(!InitName.empty() && "Expected init function name");
119  return M.getOrInsertFunction(
120  InitName,
121  FunctionType::get(Type::getVoidTy(M.getContext()), InitArgTypes, false),
122  AttributeList());
123 }
124 
127  FunctionType::get(Type::getVoidTy(M.getContext()), false),
128  GlobalValue::InternalLinkage, M.getDataLayout().getProgramAddressSpace(),
129  CtorName, &M);
130  Ctor->addFnAttr(Attribute::NoUnwind);
131  BasicBlock *CtorBB = BasicBlock::Create(M.getContext(), "", Ctor);
132  ReturnInst::Create(M.getContext(), CtorBB);
133  // Ensure Ctor cannot be discarded, even if in a comdat.
134  appendToUsed(M, {Ctor});
135  return Ctor;
136 }
137 
138 std::pair<Function *, FunctionCallee> llvm::createSanitizerCtorAndInitFunctions(
139  Module &M, StringRef CtorName, StringRef InitName,
140  ArrayRef<Type *> InitArgTypes, ArrayRef<Value *> InitArgs,
141  StringRef VersionCheckName) {
142  assert(!InitName.empty() && "Expected init function name");
143  assert(InitArgs.size() == InitArgTypes.size() &&
144  "Sanitizer's init function expects different number of arguments");
145  FunctionCallee InitFunction =
146  declareSanitizerInitFunction(M, InitName, InitArgTypes);
147  Function *Ctor = createSanitizerCtor(M, CtorName);
148  IRBuilder<> IRB(Ctor->getEntryBlock().getTerminator());
149  IRB.CreateCall(InitFunction, InitArgs);
150  if (!VersionCheckName.empty()) {
151  FunctionCallee VersionCheckFunction = M.getOrInsertFunction(
152  VersionCheckName, FunctionType::get(IRB.getVoidTy(), {}, false),
153  AttributeList());
154  IRB.CreateCall(VersionCheckFunction, {});
155  }
156  return std::make_pair(Ctor, InitFunction);
157 }
158 
159 std::pair<Function *, FunctionCallee>
161  Module &M, StringRef CtorName, StringRef InitName,
162  ArrayRef<Type *> InitArgTypes, ArrayRef<Value *> InitArgs,
163  function_ref<void(Function *, FunctionCallee)> FunctionsCreatedCallback,
164  StringRef VersionCheckName) {
165  assert(!CtorName.empty() && "Expected ctor function name");
166 
167  if (Function *Ctor = M.getFunction(CtorName))
168  // FIXME: Sink this logic into the module, similar to the handling of
169  // globals. This will make moving to a concurrent model much easier.
170  if (Ctor->arg_empty() ||
171  Ctor->getReturnType() == Type::getVoidTy(M.getContext()))
172  return {Ctor, declareSanitizerInitFunction(M, InitName, InitArgTypes)};
173 
174  Function *Ctor;
175  FunctionCallee InitFunction;
176  std::tie(Ctor, InitFunction) = llvm::createSanitizerCtorAndInitFunctions(
177  M, CtorName, InitName, InitArgTypes, InitArgs, VersionCheckName);
178  FunctionsCreatedCallback(Ctor, InitFunction);
179  return std::make_pair(Ctor, InitFunction);
180 }
181 
183  SmallVectorImpl<Function *> &DeadComdatFunctions) {
184  SmallPtrSet<Function *, 32> MaybeDeadFunctions;
185  SmallPtrSet<Comdat *, 32> MaybeDeadComdats;
186  for (Function *F : DeadComdatFunctions) {
187  MaybeDeadFunctions.insert(F);
188  if (Comdat *C = F->getComdat())
189  MaybeDeadComdats.insert(C);
190  }
191 
192  // Find comdats for which all users are dead now.
193  SmallPtrSet<Comdat *, 32> DeadComdats;
194  for (Comdat *C : MaybeDeadComdats) {
195  auto IsUserDead = [&](GlobalObject *GO) {
196  auto *F = dyn_cast<Function>(GO);
197  return F && MaybeDeadFunctions.contains(F);
198  };
199  if (all_of(C->getUsers(), IsUserDead))
200  DeadComdats.insert(C);
201  }
202 
203  // Only keep functions which have no comdat or a dead comdat.
204  erase_if(DeadComdatFunctions, [&](Function *F) {
205  Comdat *C = F->getComdat();
206  return C && !DeadComdats.contains(C);
207  });
208 }
209 
211  MD5 Md5;
212  bool ExportsSymbols = false;
213  auto AddGlobal = [&](GlobalValue &GV) {
214  if (GV.isDeclaration() || GV.getName().startswith("llvm.") ||
215  !GV.hasExternalLinkage() || GV.hasComdat())
216  return;
217  ExportsSymbols = true;
218  Md5.update(GV.getName());
219  Md5.update(ArrayRef<uint8_t>{0});
220  };
221 
222  for (auto &F : *M)
223  AddGlobal(F);
224  for (auto &GV : M->globals())
225  AddGlobal(GV);
226  for (auto &GA : M->aliases())
227  AddGlobal(GA);
228  for (auto &IF : M->ifuncs())
229  AddGlobal(IF);
230 
231  if (!ExportsSymbols)
232  return "";
233 
234  MD5::MD5Result R;
235  Md5.final(R);
236 
237  SmallString<32> Str;
238  MD5::stringifyResult(R, Str);
239  return ("." + Str).str();
240 }
241 
243  ArrayRef<std::string> VariantMappings) {
244  if (VariantMappings.empty())
245  return;
246 
247  SmallString<256> Buffer;
248  llvm::raw_svector_ostream Out(Buffer);
249  for (const std::string &VariantMapping : VariantMappings)
250  Out << VariantMapping << ",";
251  // Get rid of the trailing ','.
252  assert(!Buffer.str().empty() && "Must have at least one char.");
253  Buffer.pop_back();
254 
255  Module *M = CI->getModule();
256 #ifndef NDEBUG
257  for (const std::string &VariantMapping : VariantMappings) {
258  LLVM_DEBUG(dbgs() << "VFABI: adding mapping '" << VariantMapping << "'\n");
259  Optional<VFInfo> VI = VFABI::tryDemangleForVFABI(VariantMapping, *M);
260  assert(VI && "Cannot add an invalid VFABI name.");
261  assert(M->getNamedValue(VI.value().VectorName) &&
262  "Cannot add variant to attribute: "
263  "vector function declaration is missing.");
264  }
265 #endif
266  CI->addFnAttr(
267  Attribute::get(M->getContext(), MappingsAttrName, Buffer.str()));
268 }
269 
271  StringRef SectionName, Align Alignment) {
272  // Embed the memory buffer into the module.
273  Constant *ModuleConstant = ConstantDataArray::get(
274  M.getContext(), makeArrayRef(Buf.getBufferStart(), Buf.getBufferSize()));
275  GlobalVariable *GV = new GlobalVariable(
276  M, ModuleConstant->getType(), true, GlobalValue::PrivateLinkage,
277  ModuleConstant, "llvm.embedded.object");
278  GV->setSection(SectionName);
279  GV->setAlignment(Alignment);
280 
281  LLVMContext &Ctx = M.getContext();
282  NamedMDNode *MD = M.getOrInsertNamedMetadata("llvm.embedded.objects");
283  Metadata *MDVals[] = {ConstantAsMetadata::get(GV),
284  MDString::get(Ctx, SectionName)};
285 
286  MD->addOperand(llvm::MDNode::get(Ctx, MDVals));
287  GV->setMetadata(LLVMContext::MD_exclude, llvm::MDNode::get(Ctx, {}));
288 
289  appendToCompilerUsed(M, GV);
290 }
i
i
Definition: README.txt:29
llvm::GlobalVariable::eraseFromParent
void eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing module and deletes it.
Definition: Globals.cpp:459
llvm::IRBuilderBase::getInt32Ty
IntegerType * getInt32Ty()
Fetch the type representing a 32-bit integer.
Definition: IRBuilder.h:512
llvm::MemoryBufferRef::getBufferStart
const char * getBufferStart() const
Definition: MemoryBufferRef.h:35
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
M
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
Definition: README.txt:252
llvm::Instruction::getModule
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
Definition: Instruction.cpp:69
llvm::NamedMDNode
A tuple of MDNodes.
Definition: Metadata.h:1588
llvm::MD5::update
void update(ArrayRef< uint8_t > Data)
Updates the hash for the byte stream provided.
Definition: MD5.cpp:189
llvm::StructType::get
static StructType * get(LLVMContext &Context, ArrayRef< Type * > Elements, bool isPacked=false)
This static method is the primary way to create a literal StructType.
Definition: Type.cpp:406
appendToGlobalArray
static void appendToGlobalArray(StringRef ArrayName, Module &M, Function *F, int Priority, Constant *Data)
Definition: ModuleUtils.cpp:24
llvm::Type::getInt8PtrTy
static PointerType * getInt8PtrTy(LLVMContext &C, unsigned AS=0)
Definition: Type.cpp:291
llvm::MD5::stringifyResult
static void stringifyResult(MD5Result &Result, SmallVectorImpl< char > &Str)
Translates the bytes in Res to a hex string that is deposited into Str.
Definition: MD5.cpp:287
llvm::Function
Definition: Function.h:60
llvm::ConstantStruct::get
static Constant * get(StructType *T, ArrayRef< Constant * > V)
Definition: Constants.cpp:1306
llvm::PointerType::get
static PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space.
Definition: Type.cpp:727
llvm::Attribute::get
static Attribute get(LLVMContext &Context, AttrKind Kind, uint64_t Val=0)
Return a uniquified Attribute object.
Definition: Attributes.cpp:91
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1199
llvm::AMDGPUISD::IF
@ IF
Definition: AMDGPUISelLowering.h:361
llvm::createSanitizerCtor
Function * createSanitizerCtor(Module &M, StringRef CtorName)
Creates sanitizer constructor function.
Definition: ModuleUtils.cpp:125
llvm::Function::getEntryBlock
const BasicBlock & getEntryBlock() const
Definition: Function.h:691
llvm::IRBuilder<>
llvm::GlobalVariable
Definition: GlobalVariable.h:39
llvm::erase_if
void erase_if(Container &C, UnaryPredicate P)
Provide a container algorithm similar to C++ Library Fundamentals v2's erase_if which is equivalent t...
Definition: STLExtras.h:1997
llvm::FunctionType::get
static FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
Definition: Type.cpp:361
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
Module.h
llvm::AttributeList
Definition: Attributes.h:431
llvm::Optional
Definition: APInt.h:33
llvm::MemoryBufferRef::getBufferSize
size_t getBufferSize() const
Definition: MemoryBufferRef.h:37
llvm::ConstantAsMetadata::get
static ConstantAsMetadata * get(Constant *C)
Definition: Metadata.h:420
llvm::SmallPtrSet
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
Definition: SmallPtrSet.h:450
llvm::ArrayType
Class to represent array types.
Definition: DerivedTypes.h:357
llvm::Data
@ Data
Definition: SIMachineScheduler.h:55
llvm::MemoryBufferRef
Definition: MemoryBufferRef.h:22
llvm::ArrayRef::empty
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:159
LLVM_DEBUG
#define LLVM_DEBUG(X)
Definition: Debug.h:101
llvm::MDNode::get
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition: Metadata.h:1400
F
#define F(x, y, z)
Definition: MD5.cpp:55
llvm::GlobalVariable::hasInitializer
bool hasInitializer() const
Definitions have initializers, declarations don't.
Definition: GlobalVariable.h:91
llvm::ConstantExpr::getPointerCast
static Constant * getPointerCast(Constant *C, Type *Ty)
Create a BitCast, AddrSpaceCast, or a PtrToInt cast constant expression.
Definition: Constants.cpp:2014
llvm::BasicBlock
LLVM Basic Block Representation.
Definition: BasicBlock.h:55
llvm::appendToGlobalDtors
void appendToGlobalDtors(Module &M, Function *F, int Priority, Constant *Data=nullptr)
Same as appendToGlobalCtors(), but for global dtors.
Definition: ModuleUtils.cpp:71
llvm::dbgs
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
llvm::NamedMDNode::addOperand
void addOperand(MDNode *M)
Definition: Metadata.cpp:1222
llvm::getOrCreateSanitizerCtorAndInitFunctions
std::pair< Function *, FunctionCallee > getOrCreateSanitizerCtorAndInitFunctions(Module &M, StringRef CtorName, StringRef InitName, ArrayRef< Type * > InitArgTypes, ArrayRef< Value * > InitArgs, function_ref< void(Function *, FunctionCallee)> FunctionsCreatedCallback, StringRef VersionCheckName=StringRef())
Creates sanitizer constructor function lazily.
Definition: ModuleUtils.cpp:160
llvm::all_of
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1734
llvm::MD5::final
void final(MD5Result &Result)
Finishes off the hash and puts the result in result.
Definition: MD5.cpp:234
llvm::GlobalObject::setSection
void setSection(StringRef S)
Change the section for this global.
Definition: Globals.cpp:243
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::GlobalObject
Definition: GlobalObject.h:27
llvm::CallBase::addFnAttr
void addFnAttr(Attribute::AttrKind Kind)
Adds the attribute to the function.
Definition: InstrTypes.h:1507
llvm::appendToCompilerUsed
void appendToCompilerUsed(Module &M, ArrayRef< GlobalValue * > Values)
Adds global values to the llvm.compiler.used list.
Definition: ModuleUtils.cpp:111
llvm::GlobalValue::InternalLinkage
@ InternalLinkage
Rename collisions when linking (static functions).
Definition: GlobalValue.h:55
llvm::Align
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
llvm::Comdat
Definition: Comdat.h:33
llvm::Metadata
Root of the metadata hierarchy.
Definition: Metadata.h:62
llvm::SmallString< 32 >
llvm::function_ref
An efficient, type-erasing, non-owning reference to a callable.
Definition: STLFunctionalExtras.h:36
llvm::StringRef::empty
constexpr bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:134
VectorUtils.h
llvm::GlobalValue
Definition: GlobalValue.h:44
llvm::GlobalVariable::getInitializer
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
Definition: GlobalVariable.h:135
VI
@ VI
Definition: SIInstrInfo.cpp:7967
llvm::Constant
This is an important base class in LLVM.
Definition: Constant.h:41
llvm::createSanitizerCtorAndInitFunctions
std::pair< Function *, FunctionCallee > createSanitizerCtorAndInitFunctions(Module &M, StringRef CtorName, StringRef InitName, ArrayRef< Type * > InitArgTypes, ArrayRef< Value * > InitArgs, StringRef VersionCheckName=StringRef())
Creates sanitizer constructor function, and calls sanitizer's init function from it.
Definition: ModuleUtils.cpp:138
llvm::filterDeadComdatFunctions
void filterDeadComdatFunctions(SmallVectorImpl< Function * > &DeadComdatFunctions)
Filter out potentially dead comdat functions where other entries keep the entire comdat group alive.
Definition: ModuleUtils.cpp:182
llvm::IRBuilderBase::getInt32
ConstantInt * getInt32(uint32_t C)
Get a constant 32-bit value.
Definition: IRBuilder.h:472
llvm::MD5
Definition: MD5.h:41
llvm::LLVMContext
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:67
llvm::declareSanitizerInitFunction
FunctionCallee declareSanitizerInitFunction(Module &M, StringRef InitName, ArrayRef< Type * > InitArgTypes)
Definition: ModuleUtils.cpp:116
llvm::embedBufferInModule
void embedBufferInModule(Module &M, MemoryBufferRef Buf, StringRef SectionName, Align Alignment=Align(1))
Embed the memory buffer Buf into the module M as a global using the specified section name.
Definition: ModuleUtils.cpp:270
llvm::IRBuilderBase::getInt8PtrTy
PointerType * getInt8PtrTy(unsigned AddrSpace=0)
Fetch the type representing a pointer to an 8-bit integer value.
Definition: IRBuilder.h:560
llvm::appendToUsed
void appendToUsed(Module &M, ArrayRef< GlobalValue * > Values)
Adds global values to the llvm.used list.
Definition: ModuleUtils.cpp:107
llvm::MDString::get
static MDString * get(LLVMContext &Context, StringRef Str)
Definition: Metadata.cpp:498
IRBuilder.h
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::ArrayType::get
static ArrayType * get(Type *ElementType, uint64_t NumElements)
This static method is the primary way to construct an ArrayType.
Definition: Type.cpp:638
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:66
llvm::GlobalValue::AppendingLinkage
@ AppendingLinkage
Special purpose, only applies to global arrays.
Definition: GlobalValue.h:54
llvm::Function::createWithDefaultAttr
static Function * createWithDefaultAttr(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
Creates a function with some attributes recorded in llvm.module.flags applied.
Definition: Function.cpp:338
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: APInt.h:32
llvm::StructType
Class to represent struct types.
Definition: DerivedTypes.h:213
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
llvm::Value::getType
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:255
llvm::ConstantDataArray::get
static Constant * get(LLVMContext &Context, ArrayRef< ElementTy > Elts)
get() constructor - Return a constant with array type with an element count and element type matching...
Definition: Constants.h:692
llvm::BasicBlock::Create
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
Definition: BasicBlock.h:97
llvm::Init
Definition: Record.h:281
llvm::StructType::getNumElements
unsigned getNumElements() const
Random access to the elements.
Definition: DerivedTypes.h:327
llvm::MD5::MD5Result
Definition: MD5.h:43
llvm::Constant::getNullValue
static Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
Definition: Constants.cpp:350
llvm::AMDGPU::SendMsg::Op
Op
Definition: SIDefines.h:348
llvm::SectionName
Definition: DWARFSection.h:21
Function.h
llvm::VFABI::setVectorVariantNames
void setVectorVariantNames(CallInst *CI, ArrayRef< std::string > VariantMappings)
Overwrite the Vector Function ABI variants attribute with the names provide in VariantMappings.
Definition: ModuleUtils.cpp:242
llvm::ReturnInst::Create
static ReturnInst * Create(LLVMContext &C, Value *retVal=nullptr, Instruction *InsertBefore=nullptr)
Definition: Instructions.h:3077
llvm::getUniqueModuleId
std::string getUniqueModuleId(Module *M)
Produce a unique identifier for this module by taking the MD5 sum of the names of the module's strong...
Definition: ModuleUtils.cpp:210
llvm::ConstantArray::get
static Constant * get(ArrayType *T, ArrayRef< Constant * > V)
Definition: Constants.cpp:1241
llvm::SmallString::str
StringRef str() const
Explicit conversion to StringRef.
Definition: SmallString.h:260
llvm::makeArrayRef
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
Definition: ArrayRef.h:475
llvm::Type::getVoidTy
static Type * getVoidTy(LLVMContext &C)
Definition: Type.cpp:222
llvm::GlobalObject::setMetadata
void setMetadata(unsigned KindID, MDNode *Node)
Set a particular kind of metadata attachment.
Definition: Metadata.cpp:1326
llvm::GlobalValue::PrivateLinkage
@ PrivateLinkage
Like Internal, but omit from symbol table.
Definition: GlobalValue.h:56
llvm::ConstantExpr::getPointerBitCastOrAddrSpaceCast
static Constant * getPointerBitCastOrAddrSpaceCast(Constant *C, Type *Ty)
Create a BitCast or AddrSpaceCast for a pointer type depending on the address space.
Definition: Constants.cpp:2029
llvm::IRBuilderBase::CreateCall
CallInst * CreateCall(FunctionType *FTy, Value *Callee, ArrayRef< Value * > Args=std::nullopt, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:2276
ModuleUtils.h
llvm::ArrayRef::size
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:164
llvm::VFABI::MappingsAttrName
static constexpr const char * MappingsAttrName
Definition: VectorUtils.h:193
llvm::Function::addFnAttr
void addFnAttr(Attribute::AttrKind Kind)
Add function attributes to this function.
Definition: Function.cpp:539
llvm::raw_svector_ostream
A raw_ostream that writes to an SmallVector or SmallString.
Definition: raw_ostream.h:659
llvm::FunctionCallee
A handy container for a FunctionType+Callee-pointer pair, which can be passed around as a single enti...
Definition: DerivedTypes.h:165
llvm::BasicBlock::getTerminator
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
Definition: BasicBlock.h:119
llvm::SmallVectorImpl
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:42
llvm::VFABI::tryDemangleForVFABI
Optional< VFInfo > tryDemangleForVFABI(StringRef MangledName, const Module &M)
Function to construct a VFInfo out of a mangled names in the following format:
Definition: VFABIDemangling.cpp:317
DerivedTypes.h
llvm::CallInst
This class represents a function call, abstracting a target machine's calling convention.
Definition: Instructions.h:1474
llvm::IRBuilderBase::getVoidTy
Type * getVoidTy()
Fetch the type representing void.
Definition: IRBuilder.h:550
appendToUsedList
static void appendToUsedList(Module &M, StringRef Name, ArrayRef< GlobalValue * > Values)
Definition: ModuleUtils.cpp:75
llvm::appendToGlobalCtors
void appendToGlobalCtors(Module &M, Function *F, int Priority, Constant *Data=nullptr)
Append F to the list of global ctors of module M with the given Priority.
Definition: ModuleUtils.cpp:67
llvm::GlobalObject::setAlignment
void setAlignment(MaybeAlign Align)
Definition: Globals.cpp:121
raw_ostream.h
n
The same transformation can work with an even modulo with the addition of a and shrink the compare RHS by the same amount Unless the target supports that transformation probably isn t worthwhile The transformation can also easily be made to work with non zero equality for n
Definition: README.txt:685
llvm::SmallPtrSetImpl::contains
bool contains(ConstPtrType Ptr) const
Definition: SmallPtrSet.h:389
llvm::SmallVectorImpl::reserve
void reserve(size_type N)
Definition: SmallVector.h:667
llvm::FunctionType
Class to represent function types.
Definition: DerivedTypes.h:103
llvm::SmallPtrSetImpl::insert
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
Definition: SmallPtrSet.h:365