Bug Summary

File:lib/CodeGen/StackProtector.cpp
Warning:line 211, column 36
Called C++ object pointer is null

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name StackProtector.cpp -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-eagerly-assume -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -mrelocation-model pic -pic-level 2 -mthread-model posix -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -momit-leaf-frame-pointer -ffunction-sections -fdata-sections -resource-dir /usr/lib/llvm-7/lib/clang/7.0.0 -D _DEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I /build/llvm-toolchain-snapshot-7~svn325118/build-llvm/lib/CodeGen -I /build/llvm-toolchain-snapshot-7~svn325118/lib/CodeGen -I /build/llvm-toolchain-snapshot-7~svn325118/build-llvm/include -I /build/llvm-toolchain-snapshot-7~svn325118/include -U NDEBUG -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/c++/7.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/x86_64-linux-gnu/c++/7.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/x86_64-linux-gnu/c++/7.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/c++/7.3.0/backward -internal-isystem /usr/include/clang/7.0.0/include/ -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-7/lib/clang/7.0.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wno-maybe-uninitialized -Wno-comment -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /build/llvm-toolchain-snapshot-7~svn325118/build-llvm/lib/CodeGen -ferror-limit 19 -fmessage-length 0 -fvisibility-inlines-hidden -fobjc-runtime=gcc -fdiagnostics-show-option -vectorize-loops -vectorize-slp -analyzer-checker optin.performance.Padding -analyzer-output=html -analyzer-config stable-report-filename=true -o /tmp/scan-build-2018-02-14-150435-17243-1 -x c++ /build/llvm-toolchain-snapshot-7~svn325118/lib/CodeGen/StackProtector.cpp

/build/llvm-toolchain-snapshot-7~svn325118/lib/CodeGen/StackProtector.cpp

1//===- StackProtector.cpp - Stack Protector Insertion ---------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This pass inserts stack protectors into functions which need them. A variable
11// with a random value in it is stored onto the stack before the local variables
12// are allocated. Upon exiting the block, the stored value is checked. If it's
13// changed, then there was some sort of violation and the program aborts.
14//
15//===----------------------------------------------------------------------===//
16
17#include "llvm/CodeGen/StackProtector.h"
18#include "llvm/ADT/SmallPtrSet.h"
19#include "llvm/ADT/Statistic.h"
20#include "llvm/Analysis/BranchProbabilityInfo.h"
21#include "llvm/Analysis/EHPersonalities.h"
22#include "llvm/Analysis/OptimizationRemarkEmitter.h"
23#include "llvm/CodeGen/Passes.h"
24#include "llvm/CodeGen/TargetLowering.h"
25#include "llvm/CodeGen/TargetPassConfig.h"
26#include "llvm/CodeGen/TargetSubtargetInfo.h"
27#include "llvm/IR/Attributes.h"
28#include "llvm/IR/BasicBlock.h"
29#include "llvm/IR/Constants.h"
30#include "llvm/IR/DataLayout.h"
31#include "llvm/IR/DebugInfo.h"
32#include "llvm/IR/DebugLoc.h"
33#include "llvm/IR/DerivedTypes.h"
34#include "llvm/IR/Dominators.h"
35#include "llvm/IR/Function.h"
36#include "llvm/IR/IRBuilder.h"
37#include "llvm/IR/Instruction.h"
38#include "llvm/IR/Instructions.h"
39#include "llvm/IR/Intrinsics.h"
40#include "llvm/IR/MDBuilder.h"
41#include "llvm/IR/Module.h"
42#include "llvm/IR/Type.h"
43#include "llvm/IR/User.h"
44#include "llvm/Pass.h"
45#include "llvm/Support/Casting.h"
46#include "llvm/Support/CommandLine.h"
47#include "llvm/Target/TargetMachine.h"
48#include "llvm/Target/TargetOptions.h"
49#include <utility>
50
51using namespace llvm;
52
53#define DEBUG_TYPE"stack-protector" "stack-protector"
54
55STATISTIC(NumFunProtected, "Number of functions protected")static llvm::Statistic NumFunProtected = {"stack-protector", "NumFunProtected"
, "Number of functions protected", {0}, {false}}
;
56STATISTIC(NumAddrTaken, "Number of local variables that have their address"static llvm::Statistic NumAddrTaken = {"stack-protector", "NumAddrTaken"
, "Number of local variables that have their address" " taken."
, {0}, {false}}
57 " taken.")static llvm::Statistic NumAddrTaken = {"stack-protector", "NumAddrTaken"
, "Number of local variables that have their address" " taken."
, {0}, {false}}
;
58
59static cl::opt<bool> EnableSelectionDAGSP("enable-selectiondag-sp",
60 cl::init(true), cl::Hidden);
61
62char StackProtector::ID = 0;
63
64INITIALIZE_PASS_BEGIN(StackProtector, DEBUG_TYPE,static void *initializeStackProtectorPassOnce(PassRegistry &
Registry) {
65 "Insert stack protectors", false, true)static void *initializeStackProtectorPassOnce(PassRegistry &
Registry) {
66INITIALIZE_PASS_DEPENDENCY(TargetPassConfig)initializeTargetPassConfigPass(Registry);
67INITIALIZE_PASS_END(StackProtector, DEBUG_TYPE,PassInfo *PI = new PassInfo( "Insert stack protectors", "stack-protector"
, &StackProtector::ID, PassInfo::NormalCtor_t(callDefaultCtor
<StackProtector>), false, true); Registry.registerPass(
*PI, true); return PI; } static llvm::once_flag InitializeStackProtectorPassFlag
; void llvm::initializeStackProtectorPass(PassRegistry &Registry
) { llvm::call_once(InitializeStackProtectorPassFlag, initializeStackProtectorPassOnce
, std::ref(Registry)); }
68 "Insert stack protectors", false, true)PassInfo *PI = new PassInfo( "Insert stack protectors", "stack-protector"
, &StackProtector::ID, PassInfo::NormalCtor_t(callDefaultCtor
<StackProtector>), false, true); Registry.registerPass(
*PI, true); return PI; } static llvm::once_flag InitializeStackProtectorPassFlag
; void llvm::initializeStackProtectorPass(PassRegistry &Registry
) { llvm::call_once(InitializeStackProtectorPassFlag, initializeStackProtectorPassOnce
, std::ref(Registry)); }
69
70FunctionPass *llvm::createStackProtectorPass() { return new StackProtector(); }
71
72StackProtector::SSPLayoutKind
73StackProtector::getSSPLayout(const AllocaInst *AI) const {
74 return AI ? Layout.lookup(AI) : SSPLK_None;
75}
76
77void StackProtector::adjustForColoring(const AllocaInst *From,
78 const AllocaInst *To) {
79 // When coloring replaces one alloca with another, transfer the SSPLayoutKind
80 // tag from the remapped to the target alloca. The remapped alloca should
81 // have a size smaller than or equal to the replacement alloca.
82 SSPLayoutMap::iterator I = Layout.find(From);
83 if (I != Layout.end()) {
84 SSPLayoutKind Kind = I->second;
85 Layout.erase(I);
86
87 // Transfer the tag, but make sure that SSPLK_AddrOf does not overwrite
88 // SSPLK_SmallArray or SSPLK_LargeArray, and make sure that
89 // SSPLK_SmallArray does not overwrite SSPLK_LargeArray.
90 I = Layout.find(To);
91 if (I == Layout.end())
92 Layout.insert(std::make_pair(To, Kind));
93 else if (I->second != SSPLK_LargeArray && Kind != SSPLK_AddrOf)
94 I->second = Kind;
95 }
96}
97
98void StackProtector::getAnalysisUsage(AnalysisUsage &AU) const {
99 AU.addRequired<TargetPassConfig>();
100 AU.addPreserved<DominatorTreeWrapperPass>();
101}
102
103bool StackProtector::runOnFunction(Function &Fn) {
104 F = &Fn;
105 M = F->getParent();
106 DominatorTreeWrapperPass *DTWP =
107 getAnalysisIfAvailable<DominatorTreeWrapperPass>();
108 DT = DTWP ? &DTWP->getDomTree() : nullptr;
1
Assuming 'DTWP' is null
2
'?' condition is false
109 TM = &getAnalysis<TargetPassConfig>().getTM<TargetMachine>();
110 Trip = TM->getTargetTriple();
111 TLI = TM->getSubtargetImpl(Fn)->getTargetLowering();
112 HasPrologue = false;
113 HasIRCheck = false;
114
115 Attribute Attr = Fn.getFnAttribute("stack-protector-buffer-size");
116 if (Attr.isStringAttribute() &&
3
Assuming the condition is false
4
Taking false branch
117 Attr.getValueAsString().getAsInteger(10, SSPBufferSize))
118 return false; // Invalid integer string
119
120 if (!RequiresStackProtector())
5
Assuming the condition is false
6
Taking false branch
121 return false;
122
123 // TODO(etienneb): Functions with funclets are not correctly supported now.
124 // Do nothing if this is funclet-based personality.
125 if (Fn.hasPersonalityFn()) {
7
Assuming the condition is false
8
Taking false branch
126 EHPersonality Personality = classifyEHPersonality(Fn.getPersonalityFn());
127 if (isFuncletEHPersonality(Personality))
128 return false;
129 }
130
131 ++NumFunProtected;
132 return InsertStackProtectors();
9
Calling 'StackProtector::InsertStackProtectors'
133}
134
135/// \param [out] IsLarge is set to true if a protectable array is found and
136/// it is "large" ( >= ssp-buffer-size). In the case of a structure with
137/// multiple arrays, this gets set if any of them is large.
138bool StackProtector::ContainsProtectableArray(Type *Ty, bool &IsLarge,
139 bool Strong,
140 bool InStruct) const {
141 if (!Ty)
142 return false;
143 if (ArrayType *AT = dyn_cast<ArrayType>(Ty)) {
144 if (!AT->getElementType()->isIntegerTy(8)) {
145 // If we're on a non-Darwin platform or we're inside of a structure, don't
146 // add stack protectors unless the array is a character array.
147 // However, in strong mode any array, regardless of type and size,
148 // triggers a protector.
149 if (!Strong && (InStruct || !Trip.isOSDarwin()))
150 return false;
151 }
152
153 // If an array has more than SSPBufferSize bytes of allocated space, then we
154 // emit stack protectors.
155 if (SSPBufferSize <= M->getDataLayout().getTypeAllocSize(AT)) {
156 IsLarge = true;
157 return true;
158 }
159
160 if (Strong)
161 // Require a protector for all arrays in strong mode
162 return true;
163 }
164
165 const StructType *ST = dyn_cast<StructType>(Ty);
166 if (!ST)
167 return false;
168
169 bool NeedsProtector = false;
170 for (StructType::element_iterator I = ST->element_begin(),
171 E = ST->element_end();
172 I != E; ++I)
173 if (ContainsProtectableArray(*I, IsLarge, Strong, true)) {
174 // If the element is a protectable array and is large (>= SSPBufferSize)
175 // then we are done. If the protectable array is not large, then
176 // keep looking in case a subsequent element is a large array.
177 if (IsLarge)
178 return true;
179 NeedsProtector = true;
180 }
181
182 return NeedsProtector;
183}
184
185bool StackProtector::HasAddressTaken(const Instruction *AI) {
186 for (const User *U : AI->users()) {
187 if (const StoreInst *SI = dyn_cast<StoreInst>(U)) {
188 if (AI == SI->getValueOperand())
189 return true;
190 } else if (const PtrToIntInst *SI = dyn_cast<PtrToIntInst>(U)) {
191 if (AI == SI->getOperand(0))
192 return true;
193 } else if (isa<CallInst>(U)) {
194 return true;
195 } else if (isa<InvokeInst>(U)) {
196 return true;
197 } else if (const SelectInst *SI = dyn_cast<SelectInst>(U)) {
198 if (HasAddressTaken(SI))
199 return true;
200 } else if (const PHINode *PN = dyn_cast<PHINode>(U)) {
201 // Keep track of what PHI nodes we have already visited to ensure
202 // they are only visited once.
203 if (VisitedPHIs.insert(PN).second)
204 if (HasAddressTaken(PN))
205 return true;
206 } else if (const GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(U)) {
207 if (HasAddressTaken(GEP))
208 return true;
209 } else if (const BitCastInst *BI = dyn_cast<BitCastInst>(U)) {
210 if (HasAddressTaken(BI))
211 return true;
212 }
213 }
214 return false;
215}
216
217/// \brief Check whether or not this function needs a stack protector based
218/// upon the stack protector level.
219///
220/// We use two heuristics: a standard (ssp) and strong (sspstrong).
221/// The standard heuristic which will add a guard variable to functions that
222/// call alloca with a either a variable size or a size >= SSPBufferSize,
223/// functions with character buffers larger than SSPBufferSize, and functions
224/// with aggregates containing character buffers larger than SSPBufferSize. The
225/// strong heuristic will add a guard variables to functions that call alloca
226/// regardless of size, functions with any buffer regardless of type and size,
227/// functions with aggregates that contain any buffer regardless of type and
228/// size, and functions that contain stack-based variables that have had their
229/// address taken.
230bool StackProtector::RequiresStackProtector() {
231 bool Strong = false;
232 bool NeedsProtector = false;
233 for (const BasicBlock &BB : *F)
234 for (const Instruction &I : BB)
235 if (const CallInst *CI = dyn_cast<CallInst>(&I))
236 if (CI->getCalledFunction() ==
237 Intrinsic::getDeclaration(F->getParent(),
238 Intrinsic::stackprotector))
239 HasPrologue = true;
240
241 if (F->hasFnAttribute(Attribute::SafeStack))
242 return false;
243
244 // We are constructing the OptimizationRemarkEmitter on the fly rather than
245 // using the analysis pass to avoid building DominatorTree and LoopInfo which
246 // are not available this late in the IR pipeline.
247 OptimizationRemarkEmitter ORE(F);
248
249 if (F->hasFnAttribute(Attribute::StackProtectReq)) {
250 ORE.emit([&]() {
251 return OptimizationRemark(DEBUG_TYPE"stack-protector", "StackProtectorRequested", F)
252 << "Stack protection applied to function "
253 << ore::NV("Function", F)
254 << " due to a function attribute or command-line switch";
255 });
256 NeedsProtector = true;
257 Strong = true; // Use the same heuristic as strong to determine SSPLayout
258 } else if (F->hasFnAttribute(Attribute::StackProtectStrong))
259 Strong = true;
260 else if (HasPrologue)
261 NeedsProtector = true;
262 else if (!F->hasFnAttribute(Attribute::StackProtect))
263 return false;
264
265 for (const BasicBlock &BB : *F) {
266 for (const Instruction &I : BB) {
267 if (const AllocaInst *AI = dyn_cast<AllocaInst>(&I)) {
268 if (AI->isArrayAllocation()) {
269 auto RemarkBuilder = [&]() {
270 return OptimizationRemark(DEBUG_TYPE"stack-protector", "StackProtectorAllocaOrArray",
271 &I)
272 << "Stack protection applied to function "
273 << ore::NV("Function", F)
274 << " due to a call to alloca or use of a variable length "
275 "array";
276 };
277 if (const auto *CI = dyn_cast<ConstantInt>(AI->getArraySize())) {
278 if (CI->getLimitedValue(SSPBufferSize) >= SSPBufferSize) {
279 // A call to alloca with size >= SSPBufferSize requires
280 // stack protectors.
281 Layout.insert(std::make_pair(AI, SSPLK_LargeArray));
282 ORE.emit(RemarkBuilder);
283 NeedsProtector = true;
284 } else if (Strong) {
285 // Require protectors for all alloca calls in strong mode.
286 Layout.insert(std::make_pair(AI, SSPLK_SmallArray));
287 ORE.emit(RemarkBuilder);
288 NeedsProtector = true;
289 }
290 } else {
291 // A call to alloca with a variable size requires protectors.
292 Layout.insert(std::make_pair(AI, SSPLK_LargeArray));
293 ORE.emit(RemarkBuilder);
294 NeedsProtector = true;
295 }
296 continue;
297 }
298
299 bool IsLarge = false;
300 if (ContainsProtectableArray(AI->getAllocatedType(), IsLarge, Strong)) {
301 Layout.insert(std::make_pair(AI, IsLarge ? SSPLK_LargeArray
302 : SSPLK_SmallArray));
303 ORE.emit([&]() {
304 return OptimizationRemark(DEBUG_TYPE"stack-protector", "StackProtectorBuffer", &I)
305 << "Stack protection applied to function "
306 << ore::NV("Function", F)
307 << " due to a stack allocated buffer or struct containing a "
308 "buffer";
309 });
310 NeedsProtector = true;
311 continue;
312 }
313
314 if (Strong && HasAddressTaken(AI)) {
315 ++NumAddrTaken;
316 Layout.insert(std::make_pair(AI, SSPLK_AddrOf));
317 ORE.emit([&]() {
318 return OptimizationRemark(DEBUG_TYPE"stack-protector", "StackProtectorAddressTaken",
319 &I)
320 << "Stack protection applied to function "
321 << ore::NV("Function", F)
322 << " due to the address of a local variable being taken";
323 });
324 NeedsProtector = true;
325 }
326 }
327 }
328 }
329
330 return NeedsProtector;
331}
332
333/// Create a stack guard loading and populate whether SelectionDAG SSP is
334/// supported.
335static Value *getStackGuard(const TargetLoweringBase *TLI, Module *M,
336 IRBuilder<> &B,
337 bool *SupportsSelectionDAGSP = nullptr) {
338 if (Value *Guard = TLI->getIRStackGuard(B))
339 return B.CreateLoad(Guard, true, "StackGuard");
340
341 // Use SelectionDAG SSP handling, since there isn't an IR guard.
342 //
343 // This is more or less weird, since we optionally output whether we
344 // should perform a SelectionDAG SP here. The reason is that it's strictly
345 // defined as !TLI->getIRStackGuard(B), where getIRStackGuard is also
346 // mutating. There is no way to get this bit without mutating the IR, so
347 // getting this bit has to happen in this right time.
348 //
349 // We could have define a new function TLI::supportsSelectionDAGSP(), but that
350 // will put more burden on the backends' overriding work, especially when it
351 // actually conveys the same information getIRStackGuard() already gives.
352 if (SupportsSelectionDAGSP)
353 *SupportsSelectionDAGSP = true;
354 TLI->insertSSPDeclarations(*M);
355 return B.CreateCall(Intrinsic::getDeclaration(M, Intrinsic::stackguard));
356}
357
358/// Insert code into the entry block that stores the stack guard
359/// variable onto the stack:
360///
361/// entry:
362/// StackGuardSlot = alloca i8*
363/// StackGuard = <stack guard>
364/// call void @llvm.stackprotector(StackGuard, StackGuardSlot)
365///
366/// Returns true if the platform/triple supports the stackprotectorcreate pseudo
367/// node.
368static bool CreatePrologue(Function *F, Module *M, ReturnInst *RI,
369 const TargetLoweringBase *TLI, AllocaInst *&AI) {
370 bool SupportsSelectionDAGSP = false;
371 IRBuilder<> B(&F->getEntryBlock().front());
372 PointerType *PtrTy = Type::getInt8PtrTy(RI->getContext());
373 AI = B.CreateAlloca(PtrTy, nullptr, "StackGuardSlot");
374
375 Value *GuardSlot = getStackGuard(TLI, M, B, &SupportsSelectionDAGSP);
376 B.CreateCall(Intrinsic::getDeclaration(M, Intrinsic::stackprotector),
377 {GuardSlot, AI});
378 return SupportsSelectionDAGSP;
379}
380
381/// InsertStackProtectors - Insert code into the prologue and epilogue of the
382/// function.
383///
384/// - The prologue code loads and stores the stack guard onto the stack.
385/// - The epilogue checks the value stored in the prologue against the original
386/// value. It calls __stack_chk_fail if they differ.
387bool StackProtector::InsertStackProtectors() {
388 // If the target wants to XOR the frame pointer into the guard value, it's
389 // impossible to emit the check in IR, so the target *must* support stack
390 // protection in SDAG.
391 bool SupportsSelectionDAGSP =
392 TLI->useStackGuardXorFP() ||
10
Assuming the condition is false
393 (EnableSelectionDAGSP && !TM->Options.EnableFastISel);
11
Assuming the condition is false
394 AllocaInst *AI = nullptr; // Place on stack that stores the stack guard.
12
'AI' initialized to a null pointer value
395
396 for (Function::iterator I = F->begin(), E = F->end(); I != E;) {
13
Loop condition is true. Entering loop body
16
Loop condition is true. Entering loop body
19
Loop condition is true. Entering loop body
22
Loop condition is true. Entering loop body
397 BasicBlock *BB = &*I++;
398 ReturnInst *RI = dyn_cast<ReturnInst>(BB->getTerminator());
399 if (!RI)
14
Taking true branch
17
Taking true branch
20
Taking true branch
23
Assuming 'RI' is non-null
24
Taking false branch
400 continue;
15
Execution continues on line 396
18
Execution continues on line 396
21
Execution continues on line 396
401
402 // Generate prologue instrumentation if not already generated.
403 if (!HasPrologue) {
25
Assuming the condition is false
26
Taking false branch
404 HasPrologue = true;
405 SupportsSelectionDAGSP &= CreatePrologue(F, M, RI, TLI, AI);
406 }
407
408 // SelectionDAG based code generation. Nothing else needs to be done here.
409 // The epilogue instrumentation is postponed to SelectionDAG.
410 if (SupportsSelectionDAGSP)
27
Taking false branch
411 break;
412
413 // Set HasIRCheck to true, so that SelectionDAG will not generate its own
414 // version. SelectionDAG called 'shouldEmitSDCheck' to check whether
415 // instrumentation has already been generated.
416 HasIRCheck = true;
417
418 // Generate epilogue instrumentation. The epilogue intrumentation can be
419 // function-based or inlined depending on which mechanism the target is
420 // providing.
421 if (Value* GuardCheck = TLI->getSSPStackGuardCheck(*M)) {
28
Assuming 'GuardCheck' is null
29
Taking false branch
422 // Generate the function-based epilogue instrumentation.
423 // The target provides a guard check function, generate a call to it.
424 IRBuilder<> B(RI);
425 LoadInst *Guard = B.CreateLoad(AI, true, "Guard");
426 CallInst *Call = B.CreateCall(GuardCheck, {Guard});
427 llvm::Function *Function = cast<llvm::Function>(GuardCheck);
428 Call->setAttributes(Function->getAttributes());
429 Call->setCallingConv(Function->getCallingConv());
430 } else {
431 // Generate the epilogue with inline instrumentation.
432 // If we do not support SelectionDAG based tail calls, generate IR level
433 // tail calls.
434 //
435 // For each block with a return instruction, convert this:
436 //
437 // return:
438 // ...
439 // ret ...
440 //
441 // into this:
442 //
443 // return:
444 // ...
445 // %1 = <stack guard>
446 // %2 = load StackGuardSlot
447 // %3 = cmp i1 %1, %2
448 // br i1 %3, label %SP_return, label %CallStackCheckFailBlk
449 //
450 // SP_return:
451 // ret ...
452 //
453 // CallStackCheckFailBlk:
454 // call void @__stack_chk_fail()
455 // unreachable
456
457 // Create the FailBB. We duplicate the BB every time since the MI tail
458 // merge pass will merge together all of the various BB into one including
459 // fail BB generated by the stack protector pseudo instruction.
460 BasicBlock *FailBB = CreateFailBB();
461
462 // Split the basic block before the return instruction.
463 BasicBlock *NewBB = BB->splitBasicBlock(RI->getIterator(), "SP_return");
464
465 // Update the dominator tree if we need to.
466 if (DT && DT->isReachableFromEntry(BB)) {
30
Assuming the condition is false
467 DT->addNewBlock(NewBB, BB);
468 DT->addNewBlock(FailBB, BB);
469 }
470
471 // Remove default branch instruction to the new BB.
472 BB->getTerminator()->eraseFromParent();
473
474 // Move the newly created basic block to the point right after the old
475 // basic block so that it's in the "fall through" position.
476 NewBB->moveAfter(BB);
477
478 // Generate the stack protector instructions in the old basic block.
479 IRBuilder<> B(BB);
480 Value *Guard = getStackGuard(TLI, M, B);
481 LoadInst *LI2 = B.CreateLoad(AI, true);
31
Passing null pointer value via 1st parameter 'Ptr'
32
Calling 'IRBuilder::CreateLoad'
482 Value *Cmp = B.CreateICmpEQ(Guard, LI2);
483 auto SuccessProb =
484 BranchProbabilityInfo::getBranchProbStackProtector(true);
485 auto FailureProb =
486 BranchProbabilityInfo::getBranchProbStackProtector(false);
487 MDNode *Weights = MDBuilder(F->getContext())
488 .createBranchWeights(SuccessProb.getNumerator(),
489 FailureProb.getNumerator());
490 B.CreateCondBr(Cmp, NewBB, FailBB, Weights);
491 }
492 }
493
494 // Return if we didn't modify any basic blocks. i.e., there are no return
495 // statements in the function.
496 return HasPrologue;
497}
498
499/// CreateFailBB - Create a basic block to jump to when the stack protector
500/// check fails.
501BasicBlock *StackProtector::CreateFailBB() {
502 LLVMContext &Context = F->getContext();
503 BasicBlock *FailBB = BasicBlock::Create(Context, "CallStackCheckFailBlk", F);
504 IRBuilder<> B(FailBB);
505 B.SetCurrentDebugLocation(DebugLoc::get(0, 0, F->getSubprogram()));
506 if (Trip.isOSOpenBSD()) {
507 Constant *StackChkFail =
508 M->getOrInsertFunction("__stack_smash_handler",
509 Type::getVoidTy(Context),
510 Type::getInt8PtrTy(Context));
511
512 B.CreateCall(StackChkFail, B.CreateGlobalStringPtr(F->getName(), "SSH"));
513 } else {
514 Constant *StackChkFail =
515 M->getOrInsertFunction("__stack_chk_fail", Type::getVoidTy(Context));
516
517 B.CreateCall(StackChkFail, {});
518 }
519 B.CreateUnreachable();
520 return FailBB;
521}
522
523bool StackProtector::shouldEmitSDCheck(const BasicBlock &BB) const {
524 return HasPrologue && !HasIRCheck && dyn_cast<ReturnInst>(BB.getTerminator());
525}

/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/IRBuilder.h

1//===---- llvm/IRBuilder.h - Builder for LLVM Instructions ------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file defines the IRBuilder class, which is used as a convenient way
11// to create LLVM instructions with a consistent and simplified interface.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_IR_IRBUILDER_H
16#define LLVM_IR_IRBUILDER_H
17
18#include "llvm-c/Types.h"
19#include "llvm/ADT/ArrayRef.h"
20#include "llvm/ADT/None.h"
21#include "llvm/ADT/StringRef.h"
22#include "llvm/ADT/Twine.h"
23#include "llvm/IR/BasicBlock.h"
24#include "llvm/IR/Constant.h"
25#include "llvm/IR/ConstantFolder.h"
26#include "llvm/IR/Constants.h"
27#include "llvm/IR/DataLayout.h"
28#include "llvm/IR/DebugLoc.h"
29#include "llvm/IR/DerivedTypes.h"
30#include "llvm/IR/Function.h"
31#include "llvm/IR/GlobalVariable.h"
32#include "llvm/IR/InstrTypes.h"
33#include "llvm/IR/Instruction.h"
34#include "llvm/IR/Instructions.h"
35#include "llvm/IR/Intrinsics.h"
36#include "llvm/IR/LLVMContext.h"
37#include "llvm/IR/Module.h"
38#include "llvm/IR/Operator.h"
39#include "llvm/IR/Type.h"
40#include "llvm/IR/Value.h"
41#include "llvm/IR/ValueHandle.h"
42#include "llvm/Support/AtomicOrdering.h"
43#include "llvm/Support/CBindingWrapping.h"
44#include "llvm/Support/Casting.h"
45#include <algorithm>
46#include <cassert>
47#include <cstddef>
48#include <cstdint>
49#include <functional>
50
51namespace llvm {
52
53class APInt;
54class MDNode;
55class Module;
56class Use;
57
58/// \brief This provides the default implementation of the IRBuilder
59/// 'InsertHelper' method that is called whenever an instruction is created by
60/// IRBuilder and needs to be inserted.
61///
62/// By default, this inserts the instruction at the insertion point.
63class IRBuilderDefaultInserter {
64protected:
65 void InsertHelper(Instruction *I, const Twine &Name,
66 BasicBlock *BB, BasicBlock::iterator InsertPt) const {
67 if (BB) BB->getInstList().insert(InsertPt, I);
68 I->setName(Name);
69 }
70};
71
72/// Provides an 'InsertHelper' that calls a user-provided callback after
73/// performing the default insertion.
74class IRBuilderCallbackInserter : IRBuilderDefaultInserter {
75 std::function<void(Instruction *)> Callback;
76
77public:
78 IRBuilderCallbackInserter(std::function<void(Instruction *)> Callback)
79 : Callback(std::move(Callback)) {}
80
81protected:
82 void InsertHelper(Instruction *I, const Twine &Name,
83 BasicBlock *BB, BasicBlock::iterator InsertPt) const {
84 IRBuilderDefaultInserter::InsertHelper(I, Name, BB, InsertPt);
85 Callback(I);
86 }
87};
88
89/// \brief Common base class shared among various IRBuilders.
90class IRBuilderBase {
91 DebugLoc CurDbgLocation;
92
93protected:
94 BasicBlock *BB;
95 BasicBlock::iterator InsertPt;
96 LLVMContext &Context;
97
98 MDNode *DefaultFPMathTag;
99 FastMathFlags FMF;
100
101 ArrayRef<OperandBundleDef> DefaultOperandBundles;
102
103public:
104 IRBuilderBase(LLVMContext &context, MDNode *FPMathTag = nullptr,
105 ArrayRef<OperandBundleDef> OpBundles = None)
106 : Context(context), DefaultFPMathTag(FPMathTag),
107 DefaultOperandBundles(OpBundles) {
108 ClearInsertionPoint();
109 }
110
111 //===--------------------------------------------------------------------===//
112 // Builder configuration methods
113 //===--------------------------------------------------------------------===//
114
115 /// \brief Clear the insertion point: created instructions will not be
116 /// inserted into a block.
117 void ClearInsertionPoint() {
118 BB = nullptr;
119 InsertPt = BasicBlock::iterator();
120 }
121
122 BasicBlock *GetInsertBlock() const { return BB; }
123 BasicBlock::iterator GetInsertPoint() const { return InsertPt; }
124 LLVMContext &getContext() const { return Context; }
125
126 /// \brief This specifies that created instructions should be appended to the
127 /// end of the specified block.
128 void SetInsertPoint(BasicBlock *TheBB) {
129 BB = TheBB;
130 InsertPt = BB->end();
131 }
132
133 /// \brief This specifies that created instructions should be inserted before
134 /// the specified instruction.
135 void SetInsertPoint(Instruction *I) {
136 BB = I->getParent();
137 InsertPt = I->getIterator();
138 assert(InsertPt != BB->end() && "Can't read debug loc from end()")(static_cast <bool> (InsertPt != BB->end() &&
"Can't read debug loc from end()") ? void (0) : __assert_fail
("InsertPt != BB->end() && \"Can't read debug loc from end()\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/IRBuilder.h"
, 138, __extension__ __PRETTY_FUNCTION__))
;
139 SetCurrentDebugLocation(I->getDebugLoc());
140 }
141
142 /// \brief This specifies that created instructions should be inserted at the
143 /// specified point.
144 void SetInsertPoint(BasicBlock *TheBB, BasicBlock::iterator IP) {
145 BB = TheBB;
146 InsertPt = IP;
147 if (IP != TheBB->end())
148 SetCurrentDebugLocation(IP->getDebugLoc());
149 }
150
151 /// \brief Set location information used by debugging information.
152 void SetCurrentDebugLocation(DebugLoc L) { CurDbgLocation = std::move(L); }
153
154 /// \brief Get location information used by debugging information.
155 const DebugLoc &getCurrentDebugLocation() const { return CurDbgLocation; }
156
157 /// \brief If this builder has a current debug location, set it on the
158 /// specified instruction.
159 void SetInstDebugLocation(Instruction *I) const {
160 if (CurDbgLocation)
161 I->setDebugLoc(CurDbgLocation);
162 }
163
164 /// \brief Get the return type of the current function that we're emitting
165 /// into.
166 Type *getCurrentFunctionReturnType() const;
167
168 /// InsertPoint - A saved insertion point.
169 class InsertPoint {
170 BasicBlock *Block = nullptr;
171 BasicBlock::iterator Point;
172
173 public:
174 /// \brief Creates a new insertion point which doesn't point to anything.
175 InsertPoint() = default;
176
177 /// \brief Creates a new insertion point at the given location.
178 InsertPoint(BasicBlock *InsertBlock, BasicBlock::iterator InsertPoint)
179 : Block(InsertBlock), Point(InsertPoint) {}
180
181 /// \brief Returns true if this insert point is set.
182 bool isSet() const { return (Block != nullptr); }
183
184 BasicBlock *getBlock() const { return Block; }
185 BasicBlock::iterator getPoint() const { return Point; }
186 };
187
188 /// \brief Returns the current insert point.
189 InsertPoint saveIP() const {
190 return InsertPoint(GetInsertBlock(), GetInsertPoint());
191 }
192
193 /// \brief Returns the current insert point, clearing it in the process.
194 InsertPoint saveAndClearIP() {
195 InsertPoint IP(GetInsertBlock(), GetInsertPoint());
196 ClearInsertionPoint();
197 return IP;
198 }
199
200 /// \brief Sets the current insert point to a previously-saved location.
201 void restoreIP(InsertPoint IP) {
202 if (IP.isSet())
203 SetInsertPoint(IP.getBlock(), IP.getPoint());
204 else
205 ClearInsertionPoint();
206 }
207
208 /// \brief Get the floating point math metadata being used.
209 MDNode *getDefaultFPMathTag() const { return DefaultFPMathTag; }
210
211 /// \brief Get the flags to be applied to created floating point ops
212 FastMathFlags getFastMathFlags() const { return FMF; }
213
214 /// \brief Clear the fast-math flags.
215 void clearFastMathFlags() { FMF.clear(); }
216
217 /// \brief Set the floating point math metadata to be used.
218 void setDefaultFPMathTag(MDNode *FPMathTag) { DefaultFPMathTag = FPMathTag; }
219
220 /// \brief Set the fast-math flags to be used with generated fp-math operators
221 void setFastMathFlags(FastMathFlags NewFMF) { FMF = NewFMF; }
222
223 //===--------------------------------------------------------------------===//
224 // RAII helpers.
225 //===--------------------------------------------------------------------===//
226
227 // \brief RAII object that stores the current insertion point and restores it
228 // when the object is destroyed. This includes the debug location.
229 class InsertPointGuard {
230 IRBuilderBase &Builder;
231 AssertingVH<BasicBlock> Block;
232 BasicBlock::iterator Point;
233 DebugLoc DbgLoc;
234
235 public:
236 InsertPointGuard(IRBuilderBase &B)
237 : Builder(B), Block(B.GetInsertBlock()), Point(B.GetInsertPoint()),
238 DbgLoc(B.getCurrentDebugLocation()) {}
239
240 InsertPointGuard(const InsertPointGuard &) = delete;
241 InsertPointGuard &operator=(const InsertPointGuard &) = delete;
242
243 ~InsertPointGuard() {
244 Builder.restoreIP(InsertPoint(Block, Point));
245 Builder.SetCurrentDebugLocation(DbgLoc);
246 }
247 };
248
249 // \brief RAII object that stores the current fast math settings and restores
250 // them when the object is destroyed.
251 class FastMathFlagGuard {
252 IRBuilderBase &Builder;
253 FastMathFlags FMF;
254 MDNode *FPMathTag;
255
256 public:
257 FastMathFlagGuard(IRBuilderBase &B)
258 : Builder(B), FMF(B.FMF), FPMathTag(B.DefaultFPMathTag) {}
259
260 FastMathFlagGuard(const FastMathFlagGuard &) = delete;
261 FastMathFlagGuard &operator=(const FastMathFlagGuard &) = delete;
262
263 ~FastMathFlagGuard() {
264 Builder.FMF = FMF;
265 Builder.DefaultFPMathTag = FPMathTag;
266 }
267 };
268
269 //===--------------------------------------------------------------------===//
270 // Miscellaneous creation methods.
271 //===--------------------------------------------------------------------===//
272
273 /// \brief Make a new global variable with initializer type i8*
274 ///
275 /// Make a new global variable with an initializer that has array of i8 type
276 /// filled in with the null terminated string value specified. The new global
277 /// variable will be marked mergable with any others of the same contents. If
278 /// Name is specified, it is the name of the global variable created.
279 GlobalVariable *CreateGlobalString(StringRef Str, const Twine &Name = "",
280 unsigned AddressSpace = 0);
281
282 /// \brief Get a constant value representing either true or false.
283 ConstantInt *getInt1(bool V) {
284 return ConstantInt::get(getInt1Ty(), V);
285 }
286
287 /// \brief Get the constant value for i1 true.
288 ConstantInt *getTrue() {
289 return ConstantInt::getTrue(Context);
290 }
291
292 /// \brief Get the constant value for i1 false.
293 ConstantInt *getFalse() {
294 return ConstantInt::getFalse(Context);
295 }
296
297 /// \brief Get a constant 8-bit value.
298 ConstantInt *getInt8(uint8_t C) {
299 return ConstantInt::get(getInt8Ty(), C);
300 }
301
302 /// \brief Get a constant 16-bit value.
303 ConstantInt *getInt16(uint16_t C) {
304 return ConstantInt::get(getInt16Ty(), C);
305 }
306
307 /// \brief Get a constant 32-bit value.
308 ConstantInt *getInt32(uint32_t C) {
309 return ConstantInt::get(getInt32Ty(), C);
310 }
311
312 /// \brief Get a constant 64-bit value.
313 ConstantInt *getInt64(uint64_t C) {
314 return ConstantInt::get(getInt64Ty(), C);
315 }
316
317 /// \brief Get a constant N-bit value, zero extended or truncated from
318 /// a 64-bit value.
319 ConstantInt *getIntN(unsigned N, uint64_t C) {
320 return ConstantInt::get(getIntNTy(N), C);
321 }
322
323 /// \brief Get a constant integer value.
324 ConstantInt *getInt(const APInt &AI) {
325 return ConstantInt::get(Context, AI);
326 }
327
328 //===--------------------------------------------------------------------===//
329 // Type creation methods
330 //===--------------------------------------------------------------------===//
331
332 /// \brief Fetch the type representing a single bit
333 IntegerType *getInt1Ty() {
334 return Type::getInt1Ty(Context);
335 }
336
337 /// \brief Fetch the type representing an 8-bit integer.
338 IntegerType *getInt8Ty() {
339 return Type::getInt8Ty(Context);
340 }
341
342 /// \brief Fetch the type representing a 16-bit integer.
343 IntegerType *getInt16Ty() {
344 return Type::getInt16Ty(Context);
345 }
346
347 /// \brief Fetch the type representing a 32-bit integer.
348 IntegerType *getInt32Ty() {
349 return Type::getInt32Ty(Context);
350 }
351
352 /// \brief Fetch the type representing a 64-bit integer.
353 IntegerType *getInt64Ty() {
354 return Type::getInt64Ty(Context);
355 }
356
357 /// \brief Fetch the type representing a 128-bit integer.
358 IntegerType *getInt128Ty() { return Type::getInt128Ty(Context); }
359
360 /// \brief Fetch the type representing an N-bit integer.
361 IntegerType *getIntNTy(unsigned N) {
362 return Type::getIntNTy(Context, N);
363 }
364
365 /// \brief Fetch the type representing a 16-bit floating point value.
366 Type *getHalfTy() {
367 return Type::getHalfTy(Context);
368 }
369
370 /// \brief Fetch the type representing a 32-bit floating point value.
371 Type *getFloatTy() {
372 return Type::getFloatTy(Context);
373 }
374
375 /// \brief Fetch the type representing a 64-bit floating point value.
376 Type *getDoubleTy() {
377 return Type::getDoubleTy(Context);
378 }
379
380 /// \brief Fetch the type representing void.
381 Type *getVoidTy() {
382 return Type::getVoidTy(Context);
383 }
384
385 /// \brief Fetch the type representing a pointer to an 8-bit integer value.
386 PointerType *getInt8PtrTy(unsigned AddrSpace = 0) {
387 return Type::getInt8PtrTy(Context, AddrSpace);
388 }
389
390 /// \brief Fetch the type representing a pointer to an integer value.
391 IntegerType *getIntPtrTy(const DataLayout &DL, unsigned AddrSpace = 0) {
392 return DL.getIntPtrType(Context, AddrSpace);
393 }
394
395 //===--------------------------------------------------------------------===//
396 // Intrinsic creation methods
397 //===--------------------------------------------------------------------===//
398
399 /// \brief Create and insert a memset to the specified pointer and the
400 /// specified value.
401 ///
402 /// If the pointer isn't an i8*, it will be converted. If a TBAA tag is
403 /// specified, it will be added to the instruction. Likewise with alias.scope
404 /// and noalias tags.
405 CallInst *CreateMemSet(Value *Ptr, Value *Val, uint64_t Size, unsigned Align,
406 bool isVolatile = false, MDNode *TBAATag = nullptr,
407 MDNode *ScopeTag = nullptr,
408 MDNode *NoAliasTag = nullptr) {
409 return CreateMemSet(Ptr, Val, getInt64(Size), Align, isVolatile,
410 TBAATag, ScopeTag, NoAliasTag);
411 }
412
413 CallInst *CreateMemSet(Value *Ptr, Value *Val, Value *Size, unsigned Align,
414 bool isVolatile = false, MDNode *TBAATag = nullptr,
415 MDNode *ScopeTag = nullptr,
416 MDNode *NoAliasTag = nullptr);
417
418 /// \brief Create and insert a memcpy between the specified pointers.
419 ///
420 /// If the pointers aren't i8*, they will be converted. If a TBAA tag is
421 /// specified, it will be added to the instruction. Likewise with alias.scope
422 /// and noalias tags.
423 CallInst *CreateMemCpy(Value *Dst, unsigned DstAlign, Value *Src,
424 unsigned SrcAlign, uint64_t Size,
425 bool isVolatile = false, MDNode *TBAATag = nullptr,
426 MDNode *TBAAStructTag = nullptr,
427 MDNode *ScopeTag = nullptr,
428 MDNode *NoAliasTag = nullptr) {
429 return CreateMemCpy(Dst, DstAlign, Src, SrcAlign, getInt64(Size),
430 isVolatile, TBAATag, TBAAStructTag, ScopeTag,
431 NoAliasTag);
432 }
433
434 CallInst *CreateMemCpy(Value *Dst, unsigned DstAlign, Value *Src,
435 unsigned SrcAlign, Value *Size,
436 bool isVolatile = false, MDNode *TBAATag = nullptr,
437 MDNode *TBAAStructTag = nullptr,
438 MDNode *ScopeTag = nullptr,
439 MDNode *NoAliasTag = nullptr);
440
441 // TODO: Old API. Remove this when no longer used.
442 CallInst *CreateMemCpy(Value *Dst, Value *Src, uint64_t Size, unsigned Align,
443 bool isVolatile = false, MDNode *TBAATag = nullptr,
444 MDNode *TBAAStructTag = nullptr,
445 MDNode *ScopeTag = nullptr,
446 MDNode *NoAliasTag = nullptr) {
447 return CreateMemCpy(Dst, Align, Src, Align, getInt64(Size), isVolatile, TBAATag,
448 TBAAStructTag, ScopeTag, NoAliasTag);
449 }
450 // TODO: Old API. Remove this when no longer used.
451 CallInst *CreateMemCpy(Value *Dst, Value *Src, Value *Size, unsigned Align,
452 bool isVolatile = false, MDNode *TBAATag = nullptr,
453 MDNode *TBAAStructTag = nullptr,
454 MDNode *ScopeTag = nullptr,
455 MDNode *NoAliasTag = nullptr) {
456 return CreateMemCpy(Dst, Align, Src, Align, Size, isVolatile, TBAATag,
457 TBAAStructTag, ScopeTag, NoAliasTag);
458 }
459
460 /// \brief Create and insert an element unordered-atomic memcpy between the
461 /// specified pointers.
462 ///
463 /// DstAlign/SrcAlign are the alignments of the Dst/Src pointers, respectively.
464 ///
465 /// If the pointers aren't i8*, they will be converted. If a TBAA tag is
466 /// specified, it will be added to the instruction. Likewise with alias.scope
467 /// and noalias tags.
468 CallInst *CreateElementUnorderedAtomicMemCpy(
469 Value *Dst, unsigned DstAlign, Value *Src, unsigned SrcAlign,
470 uint64_t Size, uint32_t ElementSize, MDNode *TBAATag = nullptr,
471 MDNode *TBAAStructTag = nullptr, MDNode *ScopeTag = nullptr,
472 MDNode *NoAliasTag = nullptr) {
473 return CreateElementUnorderedAtomicMemCpy(
474 Dst, DstAlign, Src, SrcAlign, getInt64(Size), ElementSize, TBAATag,
475 TBAAStructTag, ScopeTag, NoAliasTag);
476 }
477
478 CallInst *CreateElementUnorderedAtomicMemCpy(
479 Value *Dst, unsigned DstAlign, Value *Src, unsigned SrcAlign, Value *Size,
480 uint32_t ElementSize, MDNode *TBAATag = nullptr,
481 MDNode *TBAAStructTag = nullptr, MDNode *ScopeTag = nullptr,
482 MDNode *NoAliasTag = nullptr);
483
484 /// \brief Create and insert a memmove between the specified
485 /// pointers.
486 ///
487 /// If the pointers aren't i8*, they will be converted. If a TBAA tag is
488 /// specified, it will be added to the instruction. Likewise with alias.scope
489 /// and noalias tags.
490 CallInst *CreateMemMove(Value *Dst, unsigned DstAlign, Value *Src, unsigned SrcAlign,
491 uint64_t Size, bool isVolatile = false,
492 MDNode *TBAATag = nullptr, MDNode *ScopeTag = nullptr,
493 MDNode *NoAliasTag = nullptr) {
494 return CreateMemMove(Dst, DstAlign, Src, SrcAlign, getInt64(Size), isVolatile,
495 TBAATag, ScopeTag, NoAliasTag);
496 }
497
498 CallInst *CreateMemMove(Value *Dst, unsigned DstAlign, Value *Src, unsigned SrcAlign,
499 Value *Size, bool isVolatile = false, MDNode *TBAATag = nullptr,
500 MDNode *ScopeTag = nullptr,
501 MDNode *NoAliasTag = nullptr);
502
503 // TODO: Old API. Remove this when no longer used.
504 CallInst *CreateMemMove(Value *Dst, Value *Src, uint64_t Size, unsigned Align,
505 bool isVolatile = false, MDNode *TBAATag = nullptr,
506 MDNode *ScopeTag = nullptr,
507 MDNode *NoAliasTag = nullptr) {
508 return CreateMemMove(Dst, Align, Src, Align, getInt64(Size), isVolatile,
509 TBAATag, ScopeTag, NoAliasTag);
510 }
511 // TODO: Old API. Remove this when no longer used.
512 CallInst *CreateMemMove(Value *Dst, Value *Src, Value *Size, unsigned Align,
513 bool isVolatile = false, MDNode *TBAATag = nullptr,
514 MDNode *ScopeTag = nullptr,
515 MDNode *NoAliasTag = nullptr) {
516 return CreateMemMove(Dst, Align, Src, Align, Size, isVolatile, TBAATag,
517 ScopeTag, NoAliasTag);
518 }
519
520 /// \brief Create a vector fadd reduction intrinsic of the source vector.
521 /// The first parameter is a scalar accumulator value for ordered reductions.
522 CallInst *CreateFAddReduce(Value *Acc, Value *Src);
523
524 /// \brief Create a vector fmul reduction intrinsic of the source vector.
525 /// The first parameter is a scalar accumulator value for ordered reductions.
526 CallInst *CreateFMulReduce(Value *Acc, Value *Src);
527
528 /// \brief Create a vector int add reduction intrinsic of the source vector.
529 CallInst *CreateAddReduce(Value *Src);
530
531 /// \brief Create a vector int mul reduction intrinsic of the source vector.
532 CallInst *CreateMulReduce(Value *Src);
533
534 /// \brief Create a vector int AND reduction intrinsic of the source vector.
535 CallInst *CreateAndReduce(Value *Src);
536
537 /// \brief Create a vector int OR reduction intrinsic of the source vector.
538 CallInst *CreateOrReduce(Value *Src);
539
540 /// \brief Create a vector int XOR reduction intrinsic of the source vector.
541 CallInst *CreateXorReduce(Value *Src);
542
543 /// \brief Create a vector integer max reduction intrinsic of the source
544 /// vector.
545 CallInst *CreateIntMaxReduce(Value *Src, bool IsSigned = false);
546
547 /// \brief Create a vector integer min reduction intrinsic of the source
548 /// vector.
549 CallInst *CreateIntMinReduce(Value *Src, bool IsSigned = false);
550
551 /// \brief Create a vector float max reduction intrinsic of the source
552 /// vector.
553 CallInst *CreateFPMaxReduce(Value *Src, bool NoNaN = false);
554
555 /// \brief Create a vector float min reduction intrinsic of the source
556 /// vector.
557 CallInst *CreateFPMinReduce(Value *Src, bool NoNaN = false);
558
559 /// \brief Create a lifetime.start intrinsic.
560 ///
561 /// If the pointer isn't i8* it will be converted.
562 CallInst *CreateLifetimeStart(Value *Ptr, ConstantInt *Size = nullptr);
563
564 /// \brief Create a lifetime.end intrinsic.
565 ///
566 /// If the pointer isn't i8* it will be converted.
567 CallInst *CreateLifetimeEnd(Value *Ptr, ConstantInt *Size = nullptr);
568
569 /// Create a call to invariant.start intrinsic.
570 ///
571 /// If the pointer isn't i8* it will be converted.
572 CallInst *CreateInvariantStart(Value *Ptr, ConstantInt *Size = nullptr);
573
574 /// \brief Create a call to Masked Load intrinsic
575 CallInst *CreateMaskedLoad(Value *Ptr, unsigned Align, Value *Mask,
576 Value *PassThru = nullptr, const Twine &Name = "");
577
578 /// \brief Create a call to Masked Store intrinsic
579 CallInst *CreateMaskedStore(Value *Val, Value *Ptr, unsigned Align,
580 Value *Mask);
581
582 /// \brief Create a call to Masked Gather intrinsic
583 CallInst *CreateMaskedGather(Value *Ptrs, unsigned Align,
584 Value *Mask = nullptr,
585 Value *PassThru = nullptr,
586 const Twine& Name = "");
587
588 /// \brief Create a call to Masked Scatter intrinsic
589 CallInst *CreateMaskedScatter(Value *Val, Value *Ptrs, unsigned Align,
590 Value *Mask = nullptr);
591
592 /// \brief Create an assume intrinsic call that allows the optimizer to
593 /// assume that the provided condition will be true.
594 CallInst *CreateAssumption(Value *Cond);
595
596 /// \brief Create a call to the experimental.gc.statepoint intrinsic to
597 /// start a new statepoint sequence.
598 CallInst *CreateGCStatepointCall(uint64_t ID, uint32_t NumPatchBytes,
599 Value *ActualCallee,
600 ArrayRef<Value *> CallArgs,
601 ArrayRef<Value *> DeoptArgs,
602 ArrayRef<Value *> GCArgs,
603 const Twine &Name = "");
604
605 /// \brief Create a call to the experimental.gc.statepoint intrinsic to
606 /// start a new statepoint sequence.
607 CallInst *CreateGCStatepointCall(uint64_t ID, uint32_t NumPatchBytes,
608 Value *ActualCallee, uint32_t Flags,
609 ArrayRef<Use> CallArgs,
610 ArrayRef<Use> TransitionArgs,
611 ArrayRef<Use> DeoptArgs,
612 ArrayRef<Value *> GCArgs,
613 const Twine &Name = "");
614
615 // \brief Conveninence function for the common case when CallArgs are filled
616 // in using makeArrayRef(CS.arg_begin(), CS.arg_end()); Use needs to be
617 // .get()'ed to get the Value pointer.
618 CallInst *CreateGCStatepointCall(uint64_t ID, uint32_t NumPatchBytes,
619 Value *ActualCallee, ArrayRef<Use> CallArgs,
620 ArrayRef<Value *> DeoptArgs,
621 ArrayRef<Value *> GCArgs,
622 const Twine &Name = "");
623
624 /// brief Create an invoke to the experimental.gc.statepoint intrinsic to
625 /// start a new statepoint sequence.
626 InvokeInst *
627 CreateGCStatepointInvoke(uint64_t ID, uint32_t NumPatchBytes,
628 Value *ActualInvokee, BasicBlock *NormalDest,
629 BasicBlock *UnwindDest, ArrayRef<Value *> InvokeArgs,
630 ArrayRef<Value *> DeoptArgs,
631 ArrayRef<Value *> GCArgs, const Twine &Name = "");
632
633 /// brief Create an invoke to the experimental.gc.statepoint intrinsic to
634 /// start a new statepoint sequence.
635 InvokeInst *CreateGCStatepointInvoke(
636 uint64_t ID, uint32_t NumPatchBytes, Value *ActualInvokee,
637 BasicBlock *NormalDest, BasicBlock *UnwindDest, uint32_t Flags,
638 ArrayRef<Use> InvokeArgs, ArrayRef<Use> TransitionArgs,
639 ArrayRef<Use> DeoptArgs, ArrayRef<Value *> GCArgs,
640 const Twine &Name = "");
641
642 // Conveninence function for the common case when CallArgs are filled in using
643 // makeArrayRef(CS.arg_begin(), CS.arg_end()); Use needs to be .get()'ed to
644 // get the Value *.
645 InvokeInst *
646 CreateGCStatepointInvoke(uint64_t ID, uint32_t NumPatchBytes,
647 Value *ActualInvokee, BasicBlock *NormalDest,
648 BasicBlock *UnwindDest, ArrayRef<Use> InvokeArgs,
649 ArrayRef<Value *> DeoptArgs,
650 ArrayRef<Value *> GCArgs, const Twine &Name = "");
651
652 /// \brief Create a call to the experimental.gc.result intrinsic to extract
653 /// the result from a call wrapped in a statepoint.
654 CallInst *CreateGCResult(Instruction *Statepoint,
655 Type *ResultType,
656 const Twine &Name = "");
657
658 /// \brief Create a call to the experimental.gc.relocate intrinsics to
659 /// project the relocated value of one pointer from the statepoint.
660 CallInst *CreateGCRelocate(Instruction *Statepoint,
661 int BaseOffset,
662 int DerivedOffset,
663 Type *ResultType,
664 const Twine &Name = "");
665
666 /// Create a call to intrinsic \p ID with 2 operands which is mangled on the
667 /// first type.
668 CallInst *CreateBinaryIntrinsic(Intrinsic::ID ID,
669 Value *LHS, Value *RHS,
670 const Twine &Name = "");
671
672 /// Create call to the minnum intrinsic.
673 CallInst *CreateMinNum(Value *LHS, Value *RHS, const Twine &Name = "") {
674 return CreateBinaryIntrinsic(Intrinsic::minnum, LHS, RHS, Name);
675 }
676
677 /// Create call to the maxnum intrinsic.
678 CallInst *CreateMaxNum(Value *LHS, Value *RHS, const Twine &Name = "") {
679 return CreateBinaryIntrinsic(Intrinsic::minnum, LHS, RHS, Name);
680 }
681
682private:
683 /// \brief Create a call to a masked intrinsic with given Id.
684 CallInst *CreateMaskedIntrinsic(Intrinsic::ID Id, ArrayRef<Value *> Ops,
685 ArrayRef<Type *> OverloadedTypes,
686 const Twine &Name = "");
687
688 Value *getCastedInt8PtrValue(Value *Ptr);
689};
690
691/// \brief This provides a uniform API for creating instructions and inserting
692/// them into a basic block: either at the end of a BasicBlock, or at a specific
693/// iterator location in a block.
694///
695/// Note that the builder does not expose the full generality of LLVM
696/// instructions. For access to extra instruction properties, use the mutators
697/// (e.g. setVolatile) on the instructions after they have been
698/// created. Convenience state exists to specify fast-math flags and fp-math
699/// tags.
700///
701/// The first template argument specifies a class to use for creating constants.
702/// This defaults to creating minimally folded constants. The second template
703/// argument allows clients to specify custom insertion hooks that are called on
704/// every newly created insertion.
705template <typename T = ConstantFolder,
706 typename Inserter = IRBuilderDefaultInserter>
707class IRBuilder : public IRBuilderBase, public Inserter {
708 T Folder;
709
710public:
711 IRBuilder(LLVMContext &C, const T &F, Inserter I = Inserter(),
712 MDNode *FPMathTag = nullptr,
713 ArrayRef<OperandBundleDef> OpBundles = None)
714 : IRBuilderBase(C, FPMathTag, OpBundles), Inserter(std::move(I)),
715 Folder(F) {}
716
717 explicit IRBuilder(LLVMContext &C, MDNode *FPMathTag = nullptr,
718 ArrayRef<OperandBundleDef> OpBundles = None)
719 : IRBuilderBase(C, FPMathTag, OpBundles), Folder() {}
720
721 explicit IRBuilder(BasicBlock *TheBB, const T &F, MDNode *FPMathTag = nullptr,
722 ArrayRef<OperandBundleDef> OpBundles = None)
723 : IRBuilderBase(TheBB->getContext(), FPMathTag, OpBundles), Folder(F) {
724 SetInsertPoint(TheBB);
725 }
726
727 explicit IRBuilder(BasicBlock *TheBB, MDNode *FPMathTag = nullptr,
728 ArrayRef<OperandBundleDef> OpBundles = None)
729 : IRBuilderBase(TheBB->getContext(), FPMathTag, OpBundles), Folder() {
730 SetInsertPoint(TheBB);
731 }
732
733 explicit IRBuilder(Instruction *IP, MDNode *FPMathTag = nullptr,
734 ArrayRef<OperandBundleDef> OpBundles = None)
735 : IRBuilderBase(IP->getContext(), FPMathTag, OpBundles), Folder() {
736 SetInsertPoint(IP);
737 }
738
739 IRBuilder(BasicBlock *TheBB, BasicBlock::iterator IP, const T &F,
740 MDNode *FPMathTag = nullptr,
741 ArrayRef<OperandBundleDef> OpBundles = None)
742 : IRBuilderBase(TheBB->getContext(), FPMathTag, OpBundles), Folder(F) {
743 SetInsertPoint(TheBB, IP);
744 }
745
746 IRBuilder(BasicBlock *TheBB, BasicBlock::iterator IP,
747 MDNode *FPMathTag = nullptr,
748 ArrayRef<OperandBundleDef> OpBundles = None)
749 : IRBuilderBase(TheBB->getContext(), FPMathTag, OpBundles), Folder() {
750 SetInsertPoint(TheBB, IP);
751 }
752
753 /// \brief Get the constant folder being used.
754 const T &getFolder() { return Folder; }
755
756 /// \brief Insert and return the specified instruction.
757 template<typename InstTy>
758 InstTy *Insert(InstTy *I, const Twine &Name = "") const {
759 this->InsertHelper(I, Name, BB, InsertPt);
760 this->SetInstDebugLocation(I);
761 return I;
762 }
763
764 /// \brief No-op overload to handle constants.
765 Constant *Insert(Constant *C, const Twine& = "") const {
766 return C;
767 }
768
769 //===--------------------------------------------------------------------===//
770 // Instruction creation methods: Terminators
771 //===--------------------------------------------------------------------===//
772
773private:
774 /// \brief Helper to add branch weight and unpredictable metadata onto an
775 /// instruction.
776 /// \returns The annotated instruction.
777 template <typename InstTy>
778 InstTy *addBranchMetadata(InstTy *I, MDNode *Weights, MDNode *Unpredictable) {
779 if (Weights)
780 I->setMetadata(LLVMContext::MD_prof, Weights);
781 if (Unpredictable)
782 I->setMetadata(LLVMContext::MD_unpredictable, Unpredictable);
783 return I;
784 }
785
786public:
787 /// \brief Create a 'ret void' instruction.
788 ReturnInst *CreateRetVoid() {
789 return Insert(ReturnInst::Create(Context));
790 }
791
792 /// \brief Create a 'ret <val>' instruction.
793 ReturnInst *CreateRet(Value *V) {
794 return Insert(ReturnInst::Create(Context, V));
795 }
796
797 /// \brief Create a sequence of N insertvalue instructions,
798 /// with one Value from the retVals array each, that build a aggregate
799 /// return value one value at a time, and a ret instruction to return
800 /// the resulting aggregate value.
801 ///
802 /// This is a convenience function for code that uses aggregate return values
803 /// as a vehicle for having multiple return values.
804 ReturnInst *CreateAggregateRet(Value *const *retVals, unsigned N) {
805 Value *V = UndefValue::get(getCurrentFunctionReturnType());
806 for (unsigned i = 0; i != N; ++i)
807 V = CreateInsertValue(V, retVals[i], i, "mrv");
808 return Insert(ReturnInst::Create(Context, V));
809 }
810
811 /// \brief Create an unconditional 'br label X' instruction.
812 BranchInst *CreateBr(BasicBlock *Dest) {
813 return Insert(BranchInst::Create(Dest));
814 }
815
816 /// \brief Create a conditional 'br Cond, TrueDest, FalseDest'
817 /// instruction.
818 BranchInst *CreateCondBr(Value *Cond, BasicBlock *True, BasicBlock *False,
819 MDNode *BranchWeights = nullptr,
820 MDNode *Unpredictable = nullptr) {
821 return Insert(addBranchMetadata(BranchInst::Create(True, False, Cond),
822 BranchWeights, Unpredictable));
823 }
824
825 /// \brief Create a conditional 'br Cond, TrueDest, FalseDest'
826 /// instruction. Copy branch meta data if available.
827 BranchInst *CreateCondBr(Value *Cond, BasicBlock *True, BasicBlock *False,
828 Instruction *MDSrc) {
829 BranchInst *Br = BranchInst::Create(True, False, Cond);
830 if (MDSrc) {
831 unsigned WL[4] = {LLVMContext::MD_prof, LLVMContext::MD_unpredictable,
832 LLVMContext::MD_make_implicit, LLVMContext::MD_dbg};
833 Br->copyMetadata(*MDSrc, makeArrayRef(&WL[0], 4));
834 }
835 return Insert(Br);
836 }
837
838 /// \brief Create a switch instruction with the specified value, default dest,
839 /// and with a hint for the number of cases that will be added (for efficient
840 /// allocation).
841 SwitchInst *CreateSwitch(Value *V, BasicBlock *Dest, unsigned NumCases = 10,
842 MDNode *BranchWeights = nullptr,
843 MDNode *Unpredictable = nullptr) {
844 return Insert(addBranchMetadata(SwitchInst::Create(V, Dest, NumCases),
845 BranchWeights, Unpredictable));
846 }
847
848 /// \brief Create an indirect branch instruction with the specified address
849 /// operand, with an optional hint for the number of destinations that will be
850 /// added (for efficient allocation).
851 IndirectBrInst *CreateIndirectBr(Value *Addr, unsigned NumDests = 10) {
852 return Insert(IndirectBrInst::Create(Addr, NumDests));
853 }
854
855 /// \brief Create an invoke instruction.
856 InvokeInst *CreateInvoke(Value *Callee, BasicBlock *NormalDest,
857 BasicBlock *UnwindDest,
858 ArrayRef<Value *> Args = None,
859 const Twine &Name = "") {
860 return Insert(InvokeInst::Create(Callee, NormalDest, UnwindDest, Args),
861 Name);
862 }
863 InvokeInst *CreateInvoke(Value *Callee, BasicBlock *NormalDest,
864 BasicBlock *UnwindDest, ArrayRef<Value *> Args,
865 ArrayRef<OperandBundleDef> OpBundles,
866 const Twine &Name = "") {
867 return Insert(InvokeInst::Create(Callee, NormalDest, UnwindDest, Args,
868 OpBundles), Name);
869 }
870
871 ResumeInst *CreateResume(Value *Exn) {
872 return Insert(ResumeInst::Create(Exn));
873 }
874
875 CleanupReturnInst *CreateCleanupRet(CleanupPadInst *CleanupPad,
876 BasicBlock *UnwindBB = nullptr) {
877 return Insert(CleanupReturnInst::Create(CleanupPad, UnwindBB));
878 }
879
880 CatchSwitchInst *CreateCatchSwitch(Value *ParentPad, BasicBlock *UnwindBB,
881 unsigned NumHandlers,
882 const Twine &Name = "") {
883 return Insert(CatchSwitchInst::Create(ParentPad, UnwindBB, NumHandlers),
884 Name);
885 }
886
887 CatchPadInst *CreateCatchPad(Value *ParentPad, ArrayRef<Value *> Args,
888 const Twine &Name = "") {
889 return Insert(CatchPadInst::Create(ParentPad, Args), Name);
890 }
891
892 CleanupPadInst *CreateCleanupPad(Value *ParentPad,
893 ArrayRef<Value *> Args = None,
894 const Twine &Name = "") {
895 return Insert(CleanupPadInst::Create(ParentPad, Args), Name);
896 }
897
898 CatchReturnInst *CreateCatchRet(CatchPadInst *CatchPad, BasicBlock *BB) {
899 return Insert(CatchReturnInst::Create(CatchPad, BB));
900 }
901
902 UnreachableInst *CreateUnreachable() {
903 return Insert(new UnreachableInst(Context));
904 }
905
906 //===--------------------------------------------------------------------===//
907 // Instruction creation methods: Binary Operators
908 //===--------------------------------------------------------------------===//
909private:
910 BinaryOperator *CreateInsertNUWNSWBinOp(BinaryOperator::BinaryOps Opc,
911 Value *LHS, Value *RHS,
912 const Twine &Name,
913 bool HasNUW, bool HasNSW) {
914 BinaryOperator *BO = Insert(BinaryOperator::Create(Opc, LHS, RHS), Name);
915 if (HasNUW) BO->setHasNoUnsignedWrap();
916 if (HasNSW) BO->setHasNoSignedWrap();
917 return BO;
918 }
919
920 Instruction *AddFPMathAttributes(Instruction *I,
921 MDNode *FPMathTag,
922 FastMathFlags FMF) const {
923 if (!FPMathTag)
924 FPMathTag = DefaultFPMathTag;
925 if (FPMathTag)
926 I->setMetadata(LLVMContext::MD_fpmath, FPMathTag);
927 I->setFastMathFlags(FMF);
928 return I;
929 }
930
931public:
932 Value *CreateAdd(Value *LHS, Value *RHS, const Twine &Name = "",
933 bool HasNUW = false, bool HasNSW = false) {
934 if (Constant *LC = dyn_cast<Constant>(LHS))
935 if (Constant *RC = dyn_cast<Constant>(RHS))
936 return Insert(Folder.CreateAdd(LC, RC, HasNUW, HasNSW), Name);
937 return CreateInsertNUWNSWBinOp(Instruction::Add, LHS, RHS, Name,
938 HasNUW, HasNSW);
939 }
940 Value *CreateNSWAdd(Value *LHS, Value *RHS, const Twine &Name = "") {
941 return CreateAdd(LHS, RHS, Name, false, true);
942 }
943 Value *CreateNUWAdd(Value *LHS, Value *RHS, const Twine &Name = "") {
944 return CreateAdd(LHS, RHS, Name, true, false);
945 }
946 Value *CreateFAdd(Value *LHS, Value *RHS, const Twine &Name = "",
947 MDNode *FPMathTag = nullptr) {
948 if (Constant *LC = dyn_cast<Constant>(LHS))
949 if (Constant *RC = dyn_cast<Constant>(RHS))
950 return Insert(Folder.CreateFAdd(LC, RC), Name);
951 return Insert(AddFPMathAttributes(BinaryOperator::CreateFAdd(LHS, RHS),
952 FPMathTag, FMF), Name);
953 }
954 Value *CreateSub(Value *LHS, Value *RHS, const Twine &Name = "",
955 bool HasNUW = false, bool HasNSW = false) {
956 if (Constant *LC = dyn_cast<Constant>(LHS))
957 if (Constant *RC = dyn_cast<Constant>(RHS))
958 return Insert(Folder.CreateSub(LC, RC, HasNUW, HasNSW), Name);
959 return CreateInsertNUWNSWBinOp(Instruction::Sub, LHS, RHS, Name,
960 HasNUW, HasNSW);
961 }
962 Value *CreateNSWSub(Value *LHS, Value *RHS, const Twine &Name = "") {
963 return CreateSub(LHS, RHS, Name, false, true);
964 }
965 Value *CreateNUWSub(Value *LHS, Value *RHS, const Twine &Name = "") {
966 return CreateSub(LHS, RHS, Name, true, false);
967 }
968 Value *CreateFSub(Value *LHS, Value *RHS, const Twine &Name = "",
969 MDNode *FPMathTag = nullptr) {
970 if (Constant *LC = dyn_cast<Constant>(LHS))
971 if (Constant *RC = dyn_cast<Constant>(RHS))
972 return Insert(Folder.CreateFSub(LC, RC), Name);
973 return Insert(AddFPMathAttributes(BinaryOperator::CreateFSub(LHS, RHS),
974 FPMathTag, FMF), Name);
975 }
976 Value *CreateMul(Value *LHS, Value *RHS, const Twine &Name = "",
977 bool HasNUW = false, bool HasNSW = false) {
978 if (Constant *LC = dyn_cast<Constant>(LHS))
979 if (Constant *RC = dyn_cast<Constant>(RHS))
980 return Insert(Folder.CreateMul(LC, RC, HasNUW, HasNSW), Name);
981 return CreateInsertNUWNSWBinOp(Instruction::Mul, LHS, RHS, Name,
982 HasNUW, HasNSW);
983 }
984 Value *CreateNSWMul(Value *LHS, Value *RHS, const Twine &Name = "") {
985 return CreateMul(LHS, RHS, Name, false, true);
986 }
987 Value *CreateNUWMul(Value *LHS, Value *RHS, const Twine &Name = "") {
988 return CreateMul(LHS, RHS, Name, true, false);
989 }
990 Value *CreateFMul(Value *LHS, Value *RHS, const Twine &Name = "",
991 MDNode *FPMathTag = nullptr) {
992 if (Constant *LC = dyn_cast<Constant>(LHS))
993 if (Constant *RC = dyn_cast<Constant>(RHS))
994 return Insert(Folder.CreateFMul(LC, RC), Name);
995 return Insert(AddFPMathAttributes(BinaryOperator::CreateFMul(LHS, RHS),
996 FPMathTag, FMF), Name);
997 }
998 Value *CreateUDiv(Value *LHS, Value *RHS, const Twine &Name = "",
999 bool isExact = false) {
1000 if (Constant *LC = dyn_cast<Constant>(LHS))
1001 if (Constant *RC = dyn_cast<Constant>(RHS))
1002 return Insert(Folder.CreateUDiv(LC, RC, isExact), Name);
1003 if (!isExact)
1004 return Insert(BinaryOperator::CreateUDiv(LHS, RHS), Name);
1005 return Insert(BinaryOperator::CreateExactUDiv(LHS, RHS), Name);
1006 }
1007 Value *CreateExactUDiv(Value *LHS, Value *RHS, const Twine &Name = "") {
1008 return CreateUDiv(LHS, RHS, Name, true);
1009 }
1010 Value *CreateSDiv(Value *LHS, Value *RHS, const Twine &Name = "",
1011 bool isExact = false) {
1012 if (Constant *LC = dyn_cast<Constant>(LHS))
1013 if (Constant *RC = dyn_cast<Constant>(RHS))
1014 return Insert(Folder.CreateSDiv(LC, RC, isExact), Name);
1015 if (!isExact)
1016 return Insert(BinaryOperator::CreateSDiv(LHS, RHS), Name);
1017 return Insert(BinaryOperator::CreateExactSDiv(LHS, RHS), Name);
1018 }
1019 Value *CreateExactSDiv(Value *LHS, Value *RHS, const Twine &Name = "") {
1020 return CreateSDiv(LHS, RHS, Name, true);
1021 }
1022 Value *CreateFDiv(Value *LHS, Value *RHS, const Twine &Name = "",
1023 MDNode *FPMathTag = nullptr) {
1024 if (Constant *LC = dyn_cast<Constant>(LHS))
1025 if (Constant *RC = dyn_cast<Constant>(RHS))
1026 return Insert(Folder.CreateFDiv(LC, RC), Name);
1027 return Insert(AddFPMathAttributes(BinaryOperator::CreateFDiv(LHS, RHS),
1028 FPMathTag, FMF), Name);
1029 }
1030 Value *CreateURem(Value *LHS, Value *RHS, const Twine &Name = "") {
1031 if (Constant *LC = dyn_cast<Constant>(LHS))
1032 if (Constant *RC = dyn_cast<Constant>(RHS))
1033 return Insert(Folder.CreateURem(LC, RC), Name);
1034 return Insert(BinaryOperator::CreateURem(LHS, RHS), Name);
1035 }
1036 Value *CreateSRem(Value *LHS, Value *RHS, const Twine &Name = "") {
1037 if (Constant *LC = dyn_cast<Constant>(LHS))
1038 if (Constant *RC = dyn_cast<Constant>(RHS))
1039 return Insert(Folder.CreateSRem(LC, RC), Name);
1040 return Insert(BinaryOperator::CreateSRem(LHS, RHS), Name);
1041 }
1042 Value *CreateFRem(Value *LHS, Value *RHS, const Twine &Name = "",
1043 MDNode *FPMathTag = nullptr) {
1044 if (Constant *LC = dyn_cast<Constant>(LHS))
1045 if (Constant *RC = dyn_cast<Constant>(RHS))
1046 return Insert(Folder.CreateFRem(LC, RC), Name);
1047 return Insert(AddFPMathAttributes(BinaryOperator::CreateFRem(LHS, RHS),
1048 FPMathTag, FMF), Name);
1049 }
1050
1051 Value *CreateShl(Value *LHS, Value *RHS, const Twine &Name = "",
1052 bool HasNUW = false, bool HasNSW = false) {
1053 if (Constant *LC = dyn_cast<Constant>(LHS))
1054 if (Constant *RC = dyn_cast<Constant>(RHS))
1055 return Insert(Folder.CreateShl(LC, RC, HasNUW, HasNSW), Name);
1056 return CreateInsertNUWNSWBinOp(Instruction::Shl, LHS, RHS, Name,
1057 HasNUW, HasNSW);
1058 }
1059 Value *CreateShl(Value *LHS, const APInt &RHS, const Twine &Name = "",
1060 bool HasNUW = false, bool HasNSW = false) {
1061 return CreateShl(LHS, ConstantInt::get(LHS->getType(), RHS), Name,
1062 HasNUW, HasNSW);
1063 }
1064 Value *CreateShl(Value *LHS, uint64_t RHS, const Twine &Name = "",
1065 bool HasNUW = false, bool HasNSW = false) {
1066 return CreateShl(LHS, ConstantInt::get(LHS->getType(), RHS), Name,
1067 HasNUW, HasNSW);
1068 }
1069
1070 Value *CreateLShr(Value *LHS, Value *RHS, const Twine &Name = "",
1071 bool isExact = false) {
1072 if (Constant *LC = dyn_cast<Constant>(LHS))
1073 if (Constant *RC = dyn_cast<Constant>(RHS))
1074 return Insert(Folder.CreateLShr(LC, RC, isExact), Name);
1075 if (!isExact)
1076 return Insert(BinaryOperator::CreateLShr(LHS, RHS), Name);
1077 return Insert(BinaryOperator::CreateExactLShr(LHS, RHS), Name);
1078 }
1079 Value *CreateLShr(Value *LHS, const APInt &RHS, const Twine &Name = "",
1080 bool isExact = false) {
1081 return CreateLShr(LHS, ConstantInt::get(LHS->getType(), RHS), Name,isExact);
1082 }
1083 Value *CreateLShr(Value *LHS, uint64_t RHS, const Twine &Name = "",
1084 bool isExact = false) {
1085 return CreateLShr(LHS, ConstantInt::get(LHS->getType(), RHS), Name,isExact);
1086 }
1087
1088 Value *CreateAShr(Value *LHS, Value *RHS, const Twine &Name = "",
1089 bool isExact = false) {
1090 if (Constant *LC = dyn_cast<Constant>(LHS))
1091 if (Constant *RC = dyn_cast<Constant>(RHS))
1092 return Insert(Folder.CreateAShr(LC, RC, isExact), Name);
1093 if (!isExact)
1094 return Insert(BinaryOperator::CreateAShr(LHS, RHS), Name);
1095 return Insert(BinaryOperator::CreateExactAShr(LHS, RHS), Name);
1096 }
1097 Value *CreateAShr(Value *LHS, const APInt &RHS, const Twine &Name = "",
1098 bool isExact = false) {
1099 return CreateAShr(LHS, ConstantInt::get(LHS->getType(), RHS), Name,isExact);
1100 }
1101 Value *CreateAShr(Value *LHS, uint64_t RHS, const Twine &Name = "",
1102 bool isExact = false) {
1103 return CreateAShr(LHS, ConstantInt::get(LHS->getType(), RHS), Name,isExact);
1104 }
1105
1106 Value *CreateAnd(Value *LHS, Value *RHS, const Twine &Name = "") {
1107 if (Constant *RC = dyn_cast<Constant>(RHS)) {
1108 if (isa<ConstantInt>(RC) && cast<ConstantInt>(RC)->isMinusOne())
1109 return LHS; // LHS & -1 -> LHS
1110 if (Constant *LC = dyn_cast<Constant>(LHS))
1111 return Insert(Folder.CreateAnd(LC, RC), Name);
1112 }
1113 return Insert(BinaryOperator::CreateAnd(LHS, RHS), Name);
1114 }
1115 Value *CreateAnd(Value *LHS, const APInt &RHS, const Twine &Name = "") {
1116 return CreateAnd(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
1117 }
1118 Value *CreateAnd(Value *LHS, uint64_t RHS, const Twine &Name = "") {
1119 return CreateAnd(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
1120 }
1121
1122 Value *CreateOr(Value *LHS, Value *RHS, const Twine &Name = "") {
1123 if (Constant *RC = dyn_cast<Constant>(RHS)) {
1124 if (RC->isNullValue())
1125 return LHS; // LHS | 0 -> LHS
1126 if (Constant *LC = dyn_cast<Constant>(LHS))
1127 return Insert(Folder.CreateOr(LC, RC), Name);
1128 }
1129 return Insert(BinaryOperator::CreateOr(LHS, RHS), Name);
1130 }
1131 Value *CreateOr(Value *LHS, const APInt &RHS, const Twine &Name = "") {
1132 return CreateOr(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
1133 }
1134 Value *CreateOr(Value *LHS, uint64_t RHS, const Twine &Name = "") {
1135 return CreateOr(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
1136 }
1137
1138 Value *CreateXor(Value *LHS, Value *RHS, const Twine &Name = "") {
1139 if (Constant *LC = dyn_cast<Constant>(LHS))
1140 if (Constant *RC = dyn_cast<Constant>(RHS))
1141 return Insert(Folder.CreateXor(LC, RC), Name);
1142 return Insert(BinaryOperator::CreateXor(LHS, RHS), Name);
1143 }
1144 Value *CreateXor(Value *LHS, const APInt &RHS, const Twine &Name = "") {
1145 return CreateXor(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
1146 }
1147 Value *CreateXor(Value *LHS, uint64_t RHS, const Twine &Name = "") {
1148 return CreateXor(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
1149 }
1150
1151 Value *CreateBinOp(Instruction::BinaryOps Opc,
1152 Value *LHS, Value *RHS, const Twine &Name = "",
1153 MDNode *FPMathTag = nullptr) {
1154 if (Constant *LC = dyn_cast<Constant>(LHS))
1155 if (Constant *RC = dyn_cast<Constant>(RHS))
1156 return Insert(Folder.CreateBinOp(Opc, LC, RC), Name);
1157 Instruction *BinOp = BinaryOperator::Create(Opc, LHS, RHS);
1158 if (isa<FPMathOperator>(BinOp))
1159 BinOp = AddFPMathAttributes(BinOp, FPMathTag, FMF);
1160 return Insert(BinOp, Name);
1161 }
1162
1163 Value *CreateNeg(Value *V, const Twine &Name = "",
1164 bool HasNUW = false, bool HasNSW = false) {
1165 if (Constant *VC = dyn_cast<Constant>(V))
1166 return Insert(Folder.CreateNeg(VC, HasNUW, HasNSW), Name);
1167 BinaryOperator *BO = Insert(BinaryOperator::CreateNeg(V), Name);
1168 if (HasNUW) BO->setHasNoUnsignedWrap();
1169 if (HasNSW) BO->setHasNoSignedWrap();
1170 return BO;
1171 }
1172 Value *CreateNSWNeg(Value *V, const Twine &Name = "") {
1173 return CreateNeg(V, Name, false, true);
1174 }
1175 Value *CreateNUWNeg(Value *V, const Twine &Name = "") {
1176 return CreateNeg(V, Name, true, false);
1177 }
1178 Value *CreateFNeg(Value *V, const Twine &Name = "",
1179 MDNode *FPMathTag = nullptr) {
1180 if (Constant *VC = dyn_cast<Constant>(V))
1181 return Insert(Folder.CreateFNeg(VC), Name);
1182 return Insert(AddFPMathAttributes(BinaryOperator::CreateFNeg(V),
1183 FPMathTag, FMF), Name);
1184 }
1185 Value *CreateNot(Value *V, const Twine &Name = "") {
1186 if (Constant *VC = dyn_cast<Constant>(V))
1187 return Insert(Folder.CreateNot(VC), Name);
1188 return Insert(BinaryOperator::CreateNot(V), Name);
1189 }
1190
1191 //===--------------------------------------------------------------------===//
1192 // Instruction creation methods: Memory Instructions
1193 //===--------------------------------------------------------------------===//
1194
1195 AllocaInst *CreateAlloca(Type *Ty, unsigned AddrSpace,
1196 Value *ArraySize = nullptr, const Twine &Name = "") {
1197 return Insert(new AllocaInst(Ty, AddrSpace, ArraySize), Name);
1198 }
1199
1200 AllocaInst *CreateAlloca(Type *Ty, Value *ArraySize = nullptr,
1201 const Twine &Name = "") {
1202 const DataLayout &DL = BB->getParent()->getParent()->getDataLayout();
1203 return Insert(new AllocaInst(Ty, DL.getAllocaAddrSpace(), ArraySize), Name);
1204 }
1205 // \brief Provided to resolve 'CreateLoad(Ptr, "...")' correctly, instead of
1206 // converting the string to 'bool' for the isVolatile parameter.
1207 LoadInst *CreateLoad(Value *Ptr, const char *Name) {
1208 return Insert(new LoadInst(Ptr), Name);
1209 }
1210 LoadInst *CreateLoad(Value *Ptr, const Twine &Name = "") {
1211 return Insert(new LoadInst(Ptr), Name);
1212 }
1213 LoadInst *CreateLoad(Type *Ty, Value *Ptr, const Twine &Name = "") {
1214 return Insert(new LoadInst(Ty, Ptr), Name);
1215 }
1216 LoadInst *CreateLoad(Value *Ptr, bool isVolatile, const Twine &Name = "") {
1217 return Insert(new LoadInst(Ptr, nullptr, isVolatile), Name);
33
Passing null pointer value via 1st parameter 'Ptr'
34
Calling constructor for 'LoadInst'
1218 }
1219 StoreInst *CreateStore(Value *Val, Value *Ptr, bool isVolatile = false) {
1220 return Insert(new StoreInst(Val, Ptr, isVolatile));
1221 }
1222 // \brief Provided to resolve 'CreateAlignedLoad(Ptr, Align, "...")'
1223 // correctly, instead of converting the string to 'bool' for the isVolatile
1224 // parameter.
1225 LoadInst *CreateAlignedLoad(Value *Ptr, unsigned Align, const char *Name) {
1226 LoadInst *LI = CreateLoad(Ptr, Name);
1227 LI->setAlignment(Align);
1228 return LI;
1229 }
1230 LoadInst *CreateAlignedLoad(Value *Ptr, unsigned Align,
1231 const Twine &Name = "") {
1232 LoadInst *LI = CreateLoad(Ptr, Name);
1233 LI->setAlignment(Align);
1234 return LI;
1235 }
1236 LoadInst *CreateAlignedLoad(Value *Ptr, unsigned Align, bool isVolatile,
1237 const Twine &Name = "") {
1238 LoadInst *LI = CreateLoad(Ptr, isVolatile, Name);
1239 LI->setAlignment(Align);
1240 return LI;
1241 }
1242 StoreInst *CreateAlignedStore(Value *Val, Value *Ptr, unsigned Align,
1243 bool isVolatile = false) {
1244 StoreInst *SI = CreateStore(Val, Ptr, isVolatile);
1245 SI->setAlignment(Align);
1246 return SI;
1247 }
1248 FenceInst *CreateFence(AtomicOrdering Ordering,
1249 SyncScope::ID SSID = SyncScope::System,
1250 const Twine &Name = "") {
1251 return Insert(new FenceInst(Context, Ordering, SSID), Name);
1252 }
1253 AtomicCmpXchgInst *
1254 CreateAtomicCmpXchg(Value *Ptr, Value *Cmp, Value *New,
1255 AtomicOrdering SuccessOrdering,
1256 AtomicOrdering FailureOrdering,
1257 SyncScope::ID SSID = SyncScope::System) {
1258 return Insert(new AtomicCmpXchgInst(Ptr, Cmp, New, SuccessOrdering,
1259 FailureOrdering, SSID));
1260 }
1261 AtomicRMWInst *CreateAtomicRMW(AtomicRMWInst::BinOp Op, Value *Ptr, Value *Val,
1262 AtomicOrdering Ordering,
1263 SyncScope::ID SSID = SyncScope::System) {
1264 return Insert(new AtomicRMWInst(Op, Ptr, Val, Ordering, SSID));
1265 }
1266 Value *CreateGEP(Value *Ptr, ArrayRef<Value *> IdxList,
1267 const Twine &Name = "") {
1268 return CreateGEP(nullptr, Ptr, IdxList, Name);
1269 }
1270 Value *CreateGEP(Type *Ty, Value *Ptr, ArrayRef<Value *> IdxList,
1271 const Twine &Name = "") {
1272 if (Constant *PC = dyn_cast<Constant>(Ptr)) {
1273 // Every index must be constant.
1274 size_t i, e;
1275 for (i = 0, e = IdxList.size(); i != e; ++i)
1276 if (!isa<Constant>(IdxList[i]))
1277 break;
1278 if (i == e)
1279 return Insert(Folder.CreateGetElementPtr(Ty, PC, IdxList), Name);
1280 }
1281 return Insert(GetElementPtrInst::Create(Ty, Ptr, IdxList), Name);
1282 }
1283 Value *CreateInBoundsGEP(Value *Ptr, ArrayRef<Value *> IdxList,
1284 const Twine &Name = "") {
1285 return CreateInBoundsGEP(nullptr, Ptr, IdxList, Name);
1286 }
1287 Value *CreateInBoundsGEP(Type *Ty, Value *Ptr, ArrayRef<Value *> IdxList,
1288 const Twine &Name = "") {
1289 if (Constant *PC = dyn_cast<Constant>(Ptr)) {
1290 // Every index must be constant.
1291 size_t i, e;
1292 for (i = 0, e = IdxList.size(); i != e; ++i)
1293 if (!isa<Constant>(IdxList[i]))
1294 break;
1295 if (i == e)
1296 return Insert(Folder.CreateInBoundsGetElementPtr(Ty, PC, IdxList),
1297 Name);
1298 }
1299 return Insert(GetElementPtrInst::CreateInBounds(Ty, Ptr, IdxList), Name);
1300 }
1301 Value *CreateGEP(Value *Ptr, Value *Idx, const Twine &Name = "") {
1302 return CreateGEP(nullptr, Ptr, Idx, Name);
1303 }
1304 Value *CreateGEP(Type *Ty, Value *Ptr, Value *Idx, const Twine &Name = "") {
1305 if (Constant *PC = dyn_cast<Constant>(Ptr))
1306 if (Constant *IC = dyn_cast<Constant>(Idx))
1307 return Insert(Folder.CreateGetElementPtr(Ty, PC, IC), Name);
1308 return Insert(GetElementPtrInst::Create(Ty, Ptr, Idx), Name);
1309 }
1310 Value *CreateInBoundsGEP(Type *Ty, Value *Ptr, Value *Idx,
1311 const Twine &Name = "") {
1312 if (Constant *PC = dyn_cast<Constant>(Ptr))
1313 if (Constant *IC = dyn_cast<Constant>(Idx))
1314 return Insert(Folder.CreateInBoundsGetElementPtr(Ty, PC, IC), Name);
1315 return Insert(GetElementPtrInst::CreateInBounds(Ty, Ptr, Idx), Name);
1316 }
1317 Value *CreateConstGEP1_32(Value *Ptr, unsigned Idx0, const Twine &Name = "") {
1318 return CreateConstGEP1_32(nullptr, Ptr, Idx0, Name);
1319 }
1320 Value *CreateConstGEP1_32(Type *Ty, Value *Ptr, unsigned Idx0,
1321 const Twine &Name = "") {
1322 Value *Idx = ConstantInt::get(Type::getInt32Ty(Context), Idx0);
1323
1324 if (Constant *PC = dyn_cast<Constant>(Ptr))
1325 return Insert(Folder.CreateGetElementPtr(Ty, PC, Idx), Name);
1326
1327 return Insert(GetElementPtrInst::Create(Ty, Ptr, Idx), Name);
1328 }
1329 Value *CreateConstInBoundsGEP1_32(Type *Ty, Value *Ptr, unsigned Idx0,
1330 const Twine &Name = "") {
1331 Value *Idx = ConstantInt::get(Type::getInt32Ty(Context), Idx0);
1332
1333 if (Constant *PC = dyn_cast<Constant>(Ptr))
1334 return Insert(Folder.CreateInBoundsGetElementPtr(Ty, PC, Idx), Name);
1335
1336 return Insert(GetElementPtrInst::CreateInBounds(Ty, Ptr, Idx), Name);
1337 }
1338 Value *CreateConstGEP2_32(Type *Ty, Value *Ptr, unsigned Idx0, unsigned Idx1,
1339 const Twine &Name = "") {
1340 Value *Idxs[] = {
1341 ConstantInt::get(Type::getInt32Ty(Context), Idx0),
1342 ConstantInt::get(Type::getInt32Ty(Context), Idx1)
1343 };
1344
1345 if (Constant *PC = dyn_cast<Constant>(Ptr))
1346 return Insert(Folder.CreateGetElementPtr(Ty, PC, Idxs), Name);
1347
1348 return Insert(GetElementPtrInst::Create(Ty, Ptr, Idxs), Name);
1349 }
1350 Value *CreateConstInBoundsGEP2_32(Type *Ty, Value *Ptr, unsigned Idx0,
1351 unsigned Idx1, const Twine &Name = "") {
1352 Value *Idxs[] = {
1353 ConstantInt::get(Type::getInt32Ty(Context), Idx0),
1354 ConstantInt::get(Type::getInt32Ty(Context), Idx1)
1355 };
1356
1357 if (Constant *PC = dyn_cast<Constant>(Ptr))
1358 return Insert(Folder.CreateInBoundsGetElementPtr(Ty, PC, Idxs), Name);
1359
1360 return Insert(GetElementPtrInst::CreateInBounds(Ty, Ptr, Idxs), Name);
1361 }
1362 Value *CreateConstGEP1_64(Value *Ptr, uint64_t Idx0, const Twine &Name = "") {
1363 Value *Idx = ConstantInt::get(Type::getInt64Ty(Context), Idx0);
1364
1365 if (Constant *PC = dyn_cast<Constant>(Ptr))
1366 return Insert(Folder.CreateGetElementPtr(nullptr, PC, Idx), Name);
1367
1368 return Insert(GetElementPtrInst::Create(nullptr, Ptr, Idx), Name);
1369 }
1370 Value *CreateConstInBoundsGEP1_64(Value *Ptr, uint64_t Idx0,
1371 const Twine &Name = "") {
1372 Value *Idx = ConstantInt::get(Type::getInt64Ty(Context), Idx0);
1373
1374 if (Constant *PC = dyn_cast<Constant>(Ptr))
1375 return Insert(Folder.CreateInBoundsGetElementPtr(nullptr, PC, Idx), Name);
1376
1377 return Insert(GetElementPtrInst::CreateInBounds(nullptr, Ptr, Idx), Name);
1378 }
1379 Value *CreateConstGEP2_64(Value *Ptr, uint64_t Idx0, uint64_t Idx1,
1380 const Twine &Name = "") {
1381 Value *Idxs[] = {
1382 ConstantInt::get(Type::getInt64Ty(Context), Idx0),
1383 ConstantInt::get(Type::getInt64Ty(Context), Idx1)
1384 };
1385
1386 if (Constant *PC = dyn_cast<Constant>(Ptr))
1387 return Insert(Folder.CreateGetElementPtr(nullptr, PC, Idxs), Name);
1388
1389 return Insert(GetElementPtrInst::Create(nullptr, Ptr, Idxs), Name);
1390 }
1391 Value *CreateConstInBoundsGEP2_64(Value *Ptr, uint64_t Idx0, uint64_t Idx1,
1392 const Twine &Name = "") {
1393 Value *Idxs[] = {
1394 ConstantInt::get(Type::getInt64Ty(Context), Idx0),
1395 ConstantInt::get(Type::getInt64Ty(Context), Idx1)
1396 };
1397
1398 if (Constant *PC = dyn_cast<Constant>(Ptr))
1399 return Insert(Folder.CreateInBoundsGetElementPtr(nullptr, PC, Idxs),
1400 Name);
1401
1402 return Insert(GetElementPtrInst::CreateInBounds(nullptr, Ptr, Idxs), Name);
1403 }
1404 Value *CreateStructGEP(Type *Ty, Value *Ptr, unsigned Idx,
1405 const Twine &Name = "") {
1406 return CreateConstInBoundsGEP2_32(Ty, Ptr, 0, Idx, Name);
1407 }
1408
1409 /// \brief Same as CreateGlobalString, but return a pointer with "i8*" type
1410 /// instead of a pointer to array of i8.
1411 Value *CreateGlobalStringPtr(StringRef Str, const Twine &Name = "",
1412 unsigned AddressSpace = 0) {
1413 GlobalVariable *gv = CreateGlobalString(Str, Name, AddressSpace);
1414 Value *zero = ConstantInt::get(Type::getInt32Ty(Context), 0);
1415 Value *Args[] = { zero, zero };
1416 return CreateInBoundsGEP(gv->getValueType(), gv, Args, Name);
1417 }
1418
1419 //===--------------------------------------------------------------------===//
1420 // Instruction creation methods: Cast/Conversion Operators
1421 //===--------------------------------------------------------------------===//
1422
1423 Value *CreateTrunc(Value *V, Type *DestTy, const Twine &Name = "") {
1424 return CreateCast(Instruction::Trunc, V, DestTy, Name);
1425 }
1426 Value *CreateZExt(Value *V, Type *DestTy, const Twine &Name = "") {
1427 return CreateCast(Instruction::ZExt, V, DestTy, Name);
1428 }
1429 Value *CreateSExt(Value *V, Type *DestTy, const Twine &Name = "") {
1430 return CreateCast(Instruction::SExt, V, DestTy, Name);
1431 }
1432 /// \brief Create a ZExt or Trunc from the integer value V to DestTy. Return
1433 /// the value untouched if the type of V is already DestTy.
1434 Value *CreateZExtOrTrunc(Value *V, Type *DestTy,
1435 const Twine &Name = "") {
1436 assert(V->getType()->isIntOrIntVectorTy() &&(static_cast <bool> (V->getType()->isIntOrIntVectorTy
() && DestTy->isIntOrIntVectorTy() && "Can only zero extend/truncate integers!"
) ? void (0) : __assert_fail ("V->getType()->isIntOrIntVectorTy() && DestTy->isIntOrIntVectorTy() && \"Can only zero extend/truncate integers!\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/IRBuilder.h"
, 1438, __extension__ __PRETTY_FUNCTION__))
1437 DestTy->isIntOrIntVectorTy() &&(static_cast <bool> (V->getType()->isIntOrIntVectorTy
() && DestTy->isIntOrIntVectorTy() && "Can only zero extend/truncate integers!"
) ? void (0) : __assert_fail ("V->getType()->isIntOrIntVectorTy() && DestTy->isIntOrIntVectorTy() && \"Can only zero extend/truncate integers!\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/IRBuilder.h"
, 1438, __extension__ __PRETTY_FUNCTION__))
1438 "Can only zero extend/truncate integers!")(static_cast <bool> (V->getType()->isIntOrIntVectorTy
() && DestTy->isIntOrIntVectorTy() && "Can only zero extend/truncate integers!"
) ? void (0) : __assert_fail ("V->getType()->isIntOrIntVectorTy() && DestTy->isIntOrIntVectorTy() && \"Can only zero extend/truncate integers!\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/IRBuilder.h"
, 1438, __extension__ __PRETTY_FUNCTION__))
;
1439 Type *VTy = V->getType();
1440 if (VTy->getScalarSizeInBits() < DestTy->getScalarSizeInBits())
1441 return CreateZExt(V, DestTy, Name);
1442 if (VTy->getScalarSizeInBits() > DestTy->getScalarSizeInBits())
1443 return CreateTrunc(V, DestTy, Name);
1444 return V;
1445 }
1446 /// \brief Create a SExt or Trunc from the integer value V to DestTy. Return
1447 /// the value untouched if the type of V is already DestTy.
1448 Value *CreateSExtOrTrunc(Value *V, Type *DestTy,
1449 const Twine &Name = "") {
1450 assert(V->getType()->isIntOrIntVectorTy() &&(static_cast <bool> (V->getType()->isIntOrIntVectorTy
() && DestTy->isIntOrIntVectorTy() && "Can only sign extend/truncate integers!"
) ? void (0) : __assert_fail ("V->getType()->isIntOrIntVectorTy() && DestTy->isIntOrIntVectorTy() && \"Can only sign extend/truncate integers!\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/IRBuilder.h"
, 1452, __extension__ __PRETTY_FUNCTION__))
1451 DestTy->isIntOrIntVectorTy() &&(static_cast <bool> (V->getType()->isIntOrIntVectorTy
() && DestTy->isIntOrIntVectorTy() && "Can only sign extend/truncate integers!"
) ? void (0) : __assert_fail ("V->getType()->isIntOrIntVectorTy() && DestTy->isIntOrIntVectorTy() && \"Can only sign extend/truncate integers!\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/IRBuilder.h"
, 1452, __extension__ __PRETTY_FUNCTION__))
1452 "Can only sign extend/truncate integers!")(static_cast <bool> (V->getType()->isIntOrIntVectorTy
() && DestTy->isIntOrIntVectorTy() && "Can only sign extend/truncate integers!"
) ? void (0) : __assert_fail ("V->getType()->isIntOrIntVectorTy() && DestTy->isIntOrIntVectorTy() && \"Can only sign extend/truncate integers!\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/IRBuilder.h"
, 1452, __extension__ __PRETTY_FUNCTION__))
;
1453 Type *VTy = V->getType();
1454 if (VTy->getScalarSizeInBits() < DestTy->getScalarSizeInBits())
1455 return CreateSExt(V, DestTy, Name);
1456 if (VTy->getScalarSizeInBits() > DestTy->getScalarSizeInBits())
1457 return CreateTrunc(V, DestTy, Name);
1458 return V;
1459 }
1460 Value *CreateFPToUI(Value *V, Type *DestTy, const Twine &Name = ""){
1461 return CreateCast(Instruction::FPToUI, V, DestTy, Name);
1462 }
1463 Value *CreateFPToSI(Value *V, Type *DestTy, const Twine &Name = ""){
1464 return CreateCast(Instruction::FPToSI, V, DestTy, Name);
1465 }
1466 Value *CreateUIToFP(Value *V, Type *DestTy, const Twine &Name = ""){
1467 return CreateCast(Instruction::UIToFP, V, DestTy, Name);
1468 }
1469 Value *CreateSIToFP(Value *V, Type *DestTy, const Twine &Name = ""){
1470 return CreateCast(Instruction::SIToFP, V, DestTy, Name);
1471 }
1472 Value *CreateFPTrunc(Value *V, Type *DestTy,
1473 const Twine &Name = "") {
1474 return CreateCast(Instruction::FPTrunc, V, DestTy, Name);
1475 }
1476 Value *CreateFPExt(Value *V, Type *DestTy, const Twine &Name = "") {
1477 return CreateCast(Instruction::FPExt, V, DestTy, Name);
1478 }
1479 Value *CreatePtrToInt(Value *V, Type *DestTy,
1480 const Twine &Name = "") {
1481 return CreateCast(Instruction::PtrToInt, V, DestTy, Name);
1482 }
1483 Value *CreateIntToPtr(Value *V, Type *DestTy,
1484 const Twine &Name = "") {
1485 return CreateCast(Instruction::IntToPtr, V, DestTy, Name);
1486 }
1487 Value *CreateBitCast(Value *V, Type *DestTy,
1488 const Twine &Name = "") {
1489 return CreateCast(Instruction::BitCast, V, DestTy, Name);
1490 }
1491 Value *CreateAddrSpaceCast(Value *V, Type *DestTy,
1492 const Twine &Name = "") {
1493 return CreateCast(Instruction::AddrSpaceCast, V, DestTy, Name);
1494 }
1495 Value *CreateZExtOrBitCast(Value *V, Type *DestTy,
1496 const Twine &Name = "") {
1497 if (V->getType() == DestTy)
1498 return V;
1499 if (Constant *VC = dyn_cast<Constant>(V))
1500 return Insert(Folder.CreateZExtOrBitCast(VC, DestTy), Name);
1501 return Insert(CastInst::CreateZExtOrBitCast(V, DestTy), Name);
1502 }
1503 Value *CreateSExtOrBitCast(Value *V, Type *DestTy,
1504 const Twine &Name = "") {
1505 if (V->getType() == DestTy)
1506 return V;
1507 if (Constant *VC = dyn_cast<Constant>(V))
1508 return Insert(Folder.CreateSExtOrBitCast(VC, DestTy), Name);
1509 return Insert(CastInst::CreateSExtOrBitCast(V, DestTy), Name);
1510 }
1511 Value *CreateTruncOrBitCast(Value *V, Type *DestTy,
1512 const Twine &Name = "") {
1513 if (V->getType() == DestTy)
1514 return V;
1515 if (Constant *VC = dyn_cast<Constant>(V))
1516 return Insert(Folder.CreateTruncOrBitCast(VC, DestTy), Name);
1517 return Insert(CastInst::CreateTruncOrBitCast(V, DestTy), Name);
1518 }
1519 Value *CreateCast(Instruction::CastOps Op, Value *V, Type *DestTy,
1520 const Twine &Name = "") {
1521 if (V->getType() == DestTy)
1522 return V;
1523 if (Constant *VC = dyn_cast<Constant>(V))
1524 return Insert(Folder.CreateCast(Op, VC, DestTy), Name);
1525 return Insert(CastInst::Create(Op, V, DestTy), Name);
1526 }
1527 Value *CreatePointerCast(Value *V, Type *DestTy,
1528 const Twine &Name = "") {
1529 if (V->getType() == DestTy)
1530 return V;
1531 if (Constant *VC = dyn_cast<Constant>(V))
1532 return Insert(Folder.CreatePointerCast(VC, DestTy), Name);
1533 return Insert(CastInst::CreatePointerCast(V, DestTy), Name);
1534 }
1535
1536 Value *CreatePointerBitCastOrAddrSpaceCast(Value *V, Type *DestTy,
1537 const Twine &Name = "") {
1538 if (V->getType() == DestTy)
1539 return V;
1540
1541 if (Constant *VC = dyn_cast<Constant>(V)) {
1542 return Insert(Folder.CreatePointerBitCastOrAddrSpaceCast(VC, DestTy),
1543 Name);
1544 }
1545
1546 return Insert(CastInst::CreatePointerBitCastOrAddrSpaceCast(V, DestTy),
1547 Name);
1548 }
1549
1550 Value *CreateIntCast(Value *V, Type *DestTy, bool isSigned,
1551 const Twine &Name = "") {
1552 if (V->getType() == DestTy)
1553 return V;
1554 if (Constant *VC = dyn_cast<Constant>(V))
1555 return Insert(Folder.CreateIntCast(VC, DestTy, isSigned), Name);
1556 return Insert(CastInst::CreateIntegerCast(V, DestTy, isSigned), Name);
1557 }
1558
1559 Value *CreateBitOrPointerCast(Value *V, Type *DestTy,
1560 const Twine &Name = "") {
1561 if (V->getType() == DestTy)
1562 return V;
1563 if (V->getType()->isPtrOrPtrVectorTy() && DestTy->isIntOrIntVectorTy())
1564 return CreatePtrToInt(V, DestTy, Name);
1565 if (V->getType()->isIntOrIntVectorTy() && DestTy->isPtrOrPtrVectorTy())
1566 return CreateIntToPtr(V, DestTy, Name);
1567
1568 return CreateBitCast(V, DestTy, Name);
1569 }
1570
1571public:
1572 Value *CreateFPCast(Value *V, Type *DestTy, const Twine &Name = "") {
1573 if (V->getType() == DestTy)
1574 return V;
1575 if (Constant *VC = dyn_cast<Constant>(V))
1576 return Insert(Folder.CreateFPCast(VC, DestTy), Name);
1577 return Insert(CastInst::CreateFPCast(V, DestTy), Name);
1578 }
1579
1580 // \brief Provided to resolve 'CreateIntCast(Ptr, Ptr, "...")', giving a
1581 // compile time error, instead of converting the string to bool for the
1582 // isSigned parameter.
1583 Value *CreateIntCast(Value *, Type *, const char *) = delete;
1584
1585 //===--------------------------------------------------------------------===//
1586 // Instruction creation methods: Compare Instructions
1587 //===--------------------------------------------------------------------===//
1588
1589 Value *CreateICmpEQ(Value *LHS, Value *RHS, const Twine &Name = "") {
1590 return CreateICmp(ICmpInst::ICMP_EQ, LHS, RHS, Name);
1591 }
1592 Value *CreateICmpNE(Value *LHS, Value *RHS, const Twine &Name = "") {
1593 return CreateICmp(ICmpInst::ICMP_NE, LHS, RHS, Name);
1594 }
1595 Value *CreateICmpUGT(Value *LHS, Value *RHS, const Twine &Name = "") {
1596 return CreateICmp(ICmpInst::ICMP_UGT, LHS, RHS, Name);
1597 }
1598 Value *CreateICmpUGE(Value *LHS, Value *RHS, const Twine &Name = "") {
1599 return CreateICmp(ICmpInst::ICMP_UGE, LHS, RHS, Name);
1600 }
1601 Value *CreateICmpULT(Value *LHS, Value *RHS, const Twine &Name = "") {
1602 return CreateICmp(ICmpInst::ICMP_ULT, LHS, RHS, Name);
1603 }
1604 Value *CreateICmpULE(Value *LHS, Value *RHS, const Twine &Name = "") {
1605 return CreateICmp(ICmpInst::ICMP_ULE, LHS, RHS, Name);
1606 }
1607 Value *CreateICmpSGT(Value *LHS, Value *RHS, const Twine &Name = "") {
1608 return CreateICmp(ICmpInst::ICMP_SGT, LHS, RHS, Name);
1609 }
1610 Value *CreateICmpSGE(Value *LHS, Value *RHS, const Twine &Name = "") {
1611 return CreateICmp(ICmpInst::ICMP_SGE, LHS, RHS, Name);
1612 }
1613 Value *CreateICmpSLT(Value *LHS, Value *RHS, const Twine &Name = "") {
1614 return CreateICmp(ICmpInst::ICMP_SLT, LHS, RHS, Name);
1615 }
1616 Value *CreateICmpSLE(Value *LHS, Value *RHS, const Twine &Name = "") {
1617 return CreateICmp(ICmpInst::ICMP_SLE, LHS, RHS, Name);
1618 }
1619
1620 Value *CreateFCmpOEQ(Value *LHS, Value *RHS, const Twine &Name = "",
1621 MDNode *FPMathTag = nullptr) {
1622 return CreateFCmp(FCmpInst::FCMP_OEQ, LHS, RHS, Name, FPMathTag);
1623 }
1624 Value *CreateFCmpOGT(Value *LHS, Value *RHS, const Twine &Name = "",
1625 MDNode *FPMathTag = nullptr) {
1626 return CreateFCmp(FCmpInst::FCMP_OGT, LHS, RHS, Name, FPMathTag);
1627 }
1628 Value *CreateFCmpOGE(Value *LHS, Value *RHS, const Twine &Name = "",
1629 MDNode *FPMathTag = nullptr) {
1630 return CreateFCmp(FCmpInst::FCMP_OGE, LHS, RHS, Name, FPMathTag);
1631 }
1632 Value *CreateFCmpOLT(Value *LHS, Value *RHS, const Twine &Name = "",
1633 MDNode *FPMathTag = nullptr) {
1634 return CreateFCmp(FCmpInst::FCMP_OLT, LHS, RHS, Name, FPMathTag);
1635 }
1636 Value *CreateFCmpOLE(Value *LHS, Value *RHS, const Twine &Name = "",
1637 MDNode *FPMathTag = nullptr) {
1638 return CreateFCmp(FCmpInst::FCMP_OLE, LHS, RHS, Name, FPMathTag);
1639 }
1640 Value *CreateFCmpONE(Value *LHS, Value *RHS, const Twine &Name = "",
1641 MDNode *FPMathTag = nullptr) {
1642 return CreateFCmp(FCmpInst::FCMP_ONE, LHS, RHS, Name, FPMathTag);
1643 }
1644 Value *CreateFCmpORD(Value *LHS, Value *RHS, const Twine &Name = "",
1645 MDNode *FPMathTag = nullptr) {
1646 return CreateFCmp(FCmpInst::FCMP_ORD, LHS, RHS, Name, FPMathTag);
1647 }
1648 Value *CreateFCmpUNO(Value *LHS, Value *RHS, const Twine &Name = "",
1649 MDNode *FPMathTag = nullptr) {
1650 return CreateFCmp(FCmpInst::FCMP_UNO, LHS, RHS, Name, FPMathTag);
1651 }
1652 Value *CreateFCmpUEQ(Value *LHS, Value *RHS, const Twine &Name = "",
1653 MDNode *FPMathTag = nullptr) {
1654 return CreateFCmp(FCmpInst::FCMP_UEQ, LHS, RHS, Name, FPMathTag);
1655 }
1656 Value *CreateFCmpUGT(Value *LHS, Value *RHS, const Twine &Name = "",
1657 MDNode *FPMathTag = nullptr) {
1658 return CreateFCmp(FCmpInst::FCMP_UGT, LHS, RHS, Name, FPMathTag);
1659 }
1660 Value *CreateFCmpUGE(Value *LHS, Value *RHS, const Twine &Name = "",
1661 MDNode *FPMathTag = nullptr) {
1662 return CreateFCmp(FCmpInst::FCMP_UGE, LHS, RHS, Name, FPMathTag);
1663 }
1664 Value *CreateFCmpULT(Value *LHS, Value *RHS, const Twine &Name = "",
1665 MDNode *FPMathTag = nullptr) {
1666 return CreateFCmp(FCmpInst::FCMP_ULT, LHS, RHS, Name, FPMathTag);
1667 }
1668 Value *CreateFCmpULE(Value *LHS, Value *RHS, const Twine &Name = "",
1669 MDNode *FPMathTag = nullptr) {
1670 return CreateFCmp(FCmpInst::FCMP_ULE, LHS, RHS, Name, FPMathTag);
1671 }
1672 Value *CreateFCmpUNE(Value *LHS, Value *RHS, const Twine &Name = "",
1673 MDNode *FPMathTag = nullptr) {
1674 return CreateFCmp(FCmpInst::FCMP_UNE, LHS, RHS, Name, FPMathTag);
1675 }
1676
1677 Value *CreateICmp(CmpInst::Predicate P, Value *LHS, Value *RHS,
1678 const Twine &Name = "") {
1679 if (Constant *LC = dyn_cast<Constant>(LHS))
1680 if (Constant *RC = dyn_cast<Constant>(RHS))
1681 return Insert(Folder.CreateICmp(P, LC, RC), Name);
1682 return Insert(new ICmpInst(P, LHS, RHS), Name);
1683 }
1684 Value *CreateFCmp(CmpInst::Predicate P, Value *LHS, Value *RHS,
1685 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
1686 if (Constant *LC = dyn_cast<Constant>(LHS))
1687 if (Constant *RC = dyn_cast<Constant>(RHS))
1688 return Insert(Folder.CreateFCmp(P, LC, RC), Name);
1689 return Insert(AddFPMathAttributes(new FCmpInst(P, LHS, RHS),
1690 FPMathTag, FMF), Name);
1691 }
1692
1693 //===--------------------------------------------------------------------===//
1694 // Instruction creation methods: Other Instructions
1695 //===--------------------------------------------------------------------===//
1696
1697 PHINode *CreatePHI(Type *Ty, unsigned NumReservedValues,
1698 const Twine &Name = "") {
1699 return Insert(PHINode::Create(Ty, NumReservedValues), Name);
1700 }
1701
1702 CallInst *CreateCall(Value *Callee, ArrayRef<Value *> Args = None,
1703 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
1704 PointerType *PTy = cast<PointerType>(Callee->getType());
1705 FunctionType *FTy = cast<FunctionType>(PTy->getElementType());
1706 return CreateCall(FTy, Callee, Args, Name, FPMathTag);
1707 }
1708
1709 CallInst *CreateCall(FunctionType *FTy, Value *Callee,
1710 ArrayRef<Value *> Args, const Twine &Name = "",
1711 MDNode *FPMathTag = nullptr) {
1712 CallInst *CI = CallInst::Create(FTy, Callee, Args, DefaultOperandBundles);
1713 if (isa<FPMathOperator>(CI))
1714 CI = cast<CallInst>(AddFPMathAttributes(CI, FPMathTag, FMF));
1715 return Insert(CI, Name);
1716 }
1717
1718 CallInst *CreateCall(Value *Callee, ArrayRef<Value *> Args,
1719 ArrayRef<OperandBundleDef> OpBundles,
1720 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
1721 CallInst *CI = CallInst::Create(Callee, Args, OpBundles);
1722 if (isa<FPMathOperator>(CI))
1723 CI = cast<CallInst>(AddFPMathAttributes(CI, FPMathTag, FMF));
1724 return Insert(CI, Name);
1725 }
1726
1727 CallInst *CreateCall(Function *Callee, ArrayRef<Value *> Args,
1728 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
1729 return CreateCall(Callee->getFunctionType(), Callee, Args, Name, FPMathTag);
1730 }
1731
1732 Value *CreateSelect(Value *C, Value *True, Value *False,
1733 const Twine &Name = "", Instruction *MDFrom = nullptr) {
1734 if (Constant *CC = dyn_cast<Constant>(C))
1735 if (Constant *TC = dyn_cast<Constant>(True))
1736 if (Constant *FC = dyn_cast<Constant>(False))
1737 return Insert(Folder.CreateSelect(CC, TC, FC), Name);
1738
1739 SelectInst *Sel = SelectInst::Create(C, True, False);
1740 if (MDFrom) {
1741 MDNode *Prof = MDFrom->getMetadata(LLVMContext::MD_prof);
1742 MDNode *Unpred = MDFrom->getMetadata(LLVMContext::MD_unpredictable);
1743 Sel = addBranchMetadata(Sel, Prof, Unpred);
1744 }
1745 return Insert(Sel, Name);
1746 }
1747
1748 VAArgInst *CreateVAArg(Value *List, Type *Ty, const Twine &Name = "") {
1749 return Insert(new VAArgInst(List, Ty), Name);
1750 }
1751
1752 Value *CreateExtractElement(Value *Vec, Value *Idx,
1753 const Twine &Name = "") {
1754 if (Constant *VC = dyn_cast<Constant>(Vec))
1755 if (Constant *IC = dyn_cast<Constant>(Idx))
1756 return Insert(Folder.CreateExtractElement(VC, IC), Name);
1757 return Insert(ExtractElementInst::Create(Vec, Idx), Name);
1758 }
1759
1760 Value *CreateExtractElement(Value *Vec, uint64_t Idx,
1761 const Twine &Name = "") {
1762 return CreateExtractElement(Vec, getInt64(Idx), Name);
1763 }
1764
1765 Value *CreateInsertElement(Value *Vec, Value *NewElt, Value *Idx,
1766 const Twine &Name = "") {
1767 if (Constant *VC = dyn_cast<Constant>(Vec))
1768 if (Constant *NC = dyn_cast<Constant>(NewElt))
1769 if (Constant *IC = dyn_cast<Constant>(Idx))
1770 return Insert(Folder.CreateInsertElement(VC, NC, IC), Name);
1771 return Insert(InsertElementInst::Create(Vec, NewElt, Idx), Name);
1772 }
1773
1774 Value *CreateInsertElement(Value *Vec, Value *NewElt, uint64_t Idx,
1775 const Twine &Name = "") {
1776 return CreateInsertElement(Vec, NewElt, getInt64(Idx), Name);
1777 }
1778
1779 Value *CreateShuffleVector(Value *V1, Value *V2, Value *Mask,
1780 const Twine &Name = "") {
1781 if (Constant *V1C = dyn_cast<Constant>(V1))
1782 if (Constant *V2C = dyn_cast<Constant>(V2))
1783 if (Constant *MC = dyn_cast<Constant>(Mask))
1784 return Insert(Folder.CreateShuffleVector(V1C, V2C, MC), Name);
1785 return Insert(new ShuffleVectorInst(V1, V2, Mask), Name);
1786 }
1787
1788 Value *CreateShuffleVector(Value *V1, Value *V2, ArrayRef<uint32_t> IntMask,
1789 const Twine &Name = "") {
1790 Value *Mask = ConstantDataVector::get(Context, IntMask);
1791 return CreateShuffleVector(V1, V2, Mask, Name);
1792 }
1793
1794 Value *CreateExtractValue(Value *Agg,
1795 ArrayRef<unsigned> Idxs,
1796 const Twine &Name = "") {
1797 if (Constant *AggC = dyn_cast<Constant>(Agg))
1798 return Insert(Folder.CreateExtractValue(AggC, Idxs), Name);
1799 return Insert(ExtractValueInst::Create(Agg, Idxs), Name);
1800 }
1801
1802 Value *CreateInsertValue(Value *Agg, Value *Val,
1803 ArrayRef<unsigned> Idxs,
1804 const Twine &Name = "") {
1805 if (Constant *AggC = dyn_cast<Constant>(Agg))
1806 if (Constant *ValC = dyn_cast<Constant>(Val))
1807 return Insert(Folder.CreateInsertValue(AggC, ValC, Idxs), Name);
1808 return Insert(InsertValueInst::Create(Agg, Val, Idxs), Name);
1809 }
1810
1811 LandingPadInst *CreateLandingPad(Type *Ty, unsigned NumClauses,
1812 const Twine &Name = "") {
1813 return Insert(LandingPadInst::Create(Ty, NumClauses), Name);
1814 }
1815
1816 //===--------------------------------------------------------------------===//
1817 // Utility creation methods
1818 //===--------------------------------------------------------------------===//
1819
1820 /// \brief Return an i1 value testing if \p Arg is null.
1821 Value *CreateIsNull(Value *Arg, const Twine &Name = "") {
1822 return CreateICmpEQ(Arg, Constant::getNullValue(Arg->getType()),
1823 Name);
1824 }
1825
1826 /// \brief Return an i1 value testing if \p Arg is not null.
1827 Value *CreateIsNotNull(Value *Arg, const Twine &Name = "") {
1828 return CreateICmpNE(Arg, Constant::getNullValue(Arg->getType()),
1829 Name);
1830 }
1831
1832 /// \brief Return the i64 difference between two pointer values, dividing out
1833 /// the size of the pointed-to objects.
1834 ///
1835 /// This is intended to implement C-style pointer subtraction. As such, the
1836 /// pointers must be appropriately aligned for their element types and
1837 /// pointing into the same object.
1838 Value *CreatePtrDiff(Value *LHS, Value *RHS, const Twine &Name = "") {
1839 assert(LHS->getType() == RHS->getType() &&(static_cast <bool> (LHS->getType() == RHS->getType
() && "Pointer subtraction operand types must match!"
) ? void (0) : __assert_fail ("LHS->getType() == RHS->getType() && \"Pointer subtraction operand types must match!\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/IRBuilder.h"
, 1840, __extension__ __PRETTY_FUNCTION__))
1840 "Pointer subtraction operand types must match!")(static_cast <bool> (LHS->getType() == RHS->getType
() && "Pointer subtraction operand types must match!"
) ? void (0) : __assert_fail ("LHS->getType() == RHS->getType() && \"Pointer subtraction operand types must match!\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/IRBuilder.h"
, 1840, __extension__ __PRETTY_FUNCTION__))
;
1841 PointerType *ArgType = cast<PointerType>(LHS->getType());
1842 Value *LHS_int = CreatePtrToInt(LHS, Type::getInt64Ty(Context));
1843 Value *RHS_int = CreatePtrToInt(RHS, Type::getInt64Ty(Context));
1844 Value *Difference = CreateSub(LHS_int, RHS_int);
1845 return CreateExactSDiv(Difference,
1846 ConstantExpr::getSizeOf(ArgType->getElementType()),
1847 Name);
1848 }
1849
1850 /// \brief Create an invariant.group.barrier intrinsic call, that stops
1851 /// optimizer to propagate equality using invariant.group metadata.
1852 /// If Ptr type is different from pointer to i8, it's casted to pointer to i8
1853 /// in the same address space before call and casted back to Ptr type after
1854 /// call.
1855 Value *CreateInvariantGroupBarrier(Value *Ptr) {
1856 assert(isa<PointerType>(Ptr->getType()) &&(static_cast <bool> (isa<PointerType>(Ptr->getType
()) && "invariant.group.barrier only applies to pointers."
) ? void (0) : __assert_fail ("isa<PointerType>(Ptr->getType()) && \"invariant.group.barrier only applies to pointers.\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/IRBuilder.h"
, 1857, __extension__ __PRETTY_FUNCTION__))
1857 "invariant.group.barrier only applies to pointers.")(static_cast <bool> (isa<PointerType>(Ptr->getType
()) && "invariant.group.barrier only applies to pointers."
) ? void (0) : __assert_fail ("isa<PointerType>(Ptr->getType()) && \"invariant.group.barrier only applies to pointers.\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/IRBuilder.h"
, 1857, __extension__ __PRETTY_FUNCTION__))
;
1858 auto *PtrType = Ptr->getType();
1859 auto *Int8PtrTy = getInt8PtrTy(PtrType->getPointerAddressSpace());
1860 if (PtrType != Int8PtrTy)
1861 Ptr = CreateBitCast(Ptr, Int8PtrTy);
1862 Module *M = BB->getParent()->getParent();
1863 Function *FnInvariantGroupBarrier = Intrinsic::getDeclaration(
1864 M, Intrinsic::invariant_group_barrier, {Int8PtrTy});
1865
1866 assert(FnInvariantGroupBarrier->getReturnType() == Int8PtrTy &&(static_cast <bool> (FnInvariantGroupBarrier->getReturnType
() == Int8PtrTy && FnInvariantGroupBarrier->getFunctionType
()->getParamType(0) == Int8PtrTy && "InvariantGroupBarrier should take and return the same type"
) ? void (0) : __assert_fail ("FnInvariantGroupBarrier->getReturnType() == Int8PtrTy && FnInvariantGroupBarrier->getFunctionType()->getParamType(0) == Int8PtrTy && \"InvariantGroupBarrier should take and return the same type\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/IRBuilder.h"
, 1869, __extension__ __PRETTY_FUNCTION__))
1867 FnInvariantGroupBarrier->getFunctionType()->getParamType(0) ==(static_cast <bool> (FnInvariantGroupBarrier->getReturnType
() == Int8PtrTy && FnInvariantGroupBarrier->getFunctionType
()->getParamType(0) == Int8PtrTy && "InvariantGroupBarrier should take and return the same type"
) ? void (0) : __assert_fail ("FnInvariantGroupBarrier->getReturnType() == Int8PtrTy && FnInvariantGroupBarrier->getFunctionType()->getParamType(0) == Int8PtrTy && \"InvariantGroupBarrier should take and return the same type\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/IRBuilder.h"
, 1869, __extension__ __PRETTY_FUNCTION__))
1868 Int8PtrTy &&(static_cast <bool> (FnInvariantGroupBarrier->getReturnType
() == Int8PtrTy && FnInvariantGroupBarrier->getFunctionType
()->getParamType(0) == Int8PtrTy && "InvariantGroupBarrier should take and return the same type"
) ? void (0) : __assert_fail ("FnInvariantGroupBarrier->getReturnType() == Int8PtrTy && FnInvariantGroupBarrier->getFunctionType()->getParamType(0) == Int8PtrTy && \"InvariantGroupBarrier should take and return the same type\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/IRBuilder.h"
, 1869, __extension__ __PRETTY_FUNCTION__))
1869 "InvariantGroupBarrier should take and return the same type")(static_cast <bool> (FnInvariantGroupBarrier->getReturnType
() == Int8PtrTy && FnInvariantGroupBarrier->getFunctionType
()->getParamType(0) == Int8PtrTy && "InvariantGroupBarrier should take and return the same type"
) ? void (0) : __assert_fail ("FnInvariantGroupBarrier->getReturnType() == Int8PtrTy && FnInvariantGroupBarrier->getFunctionType()->getParamType(0) == Int8PtrTy && \"InvariantGroupBarrier should take and return the same type\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/IRBuilder.h"
, 1869, __extension__ __PRETTY_FUNCTION__))
;
1870
1871 CallInst *Fn = CreateCall(FnInvariantGroupBarrier, {Ptr});
1872
1873 if (PtrType != Int8PtrTy)
1874 return CreateBitCast(Fn, PtrType);
1875 return Fn;
1876 }
1877
1878 /// \brief Return a vector value that contains \arg V broadcasted to \p
1879 /// NumElts elements.
1880 Value *CreateVectorSplat(unsigned NumElts, Value *V, const Twine &Name = "") {
1881 assert(NumElts > 0 && "Cannot splat to an empty vector!")(static_cast <bool> (NumElts > 0 && "Cannot splat to an empty vector!"
) ? void (0) : __assert_fail ("NumElts > 0 && \"Cannot splat to an empty vector!\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/IRBuilder.h"
, 1881, __extension__ __PRETTY_FUNCTION__))
;
1882
1883 // First insert it into an undef vector so we can shuffle it.
1884 Type *I32Ty = getInt32Ty();
1885 Value *Undef = UndefValue::get(VectorType::get(V->getType(), NumElts));
1886 V = CreateInsertElement(Undef, V, ConstantInt::get(I32Ty, 0),
1887 Name + ".splatinsert");
1888
1889 // Shuffle the value across the desired number of elements.
1890 Value *Zeros = ConstantAggregateZero::get(VectorType::get(I32Ty, NumElts));
1891 return CreateShuffleVector(V, Undef, Zeros, Name + ".splat");
1892 }
1893
1894 /// \brief Return a value that has been extracted from a larger integer type.
1895 Value *CreateExtractInteger(const DataLayout &DL, Value *From,
1896 IntegerType *ExtractedTy, uint64_t Offset,
1897 const Twine &Name) {
1898 IntegerType *IntTy = cast<IntegerType>(From->getType());
1899 assert(DL.getTypeStoreSize(ExtractedTy) + Offset <=(static_cast <bool> (DL.getTypeStoreSize(ExtractedTy) +
Offset <= DL.getTypeStoreSize(IntTy) && "Element extends past full value"
) ? void (0) : __assert_fail ("DL.getTypeStoreSize(ExtractedTy) + Offset <= DL.getTypeStoreSize(IntTy) && \"Element extends past full value\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/IRBuilder.h"
, 1901, __extension__ __PRETTY_FUNCTION__))
1900 DL.getTypeStoreSize(IntTy) &&(static_cast <bool> (DL.getTypeStoreSize(ExtractedTy) +
Offset <= DL.getTypeStoreSize(IntTy) && "Element extends past full value"
) ? void (0) : __assert_fail ("DL.getTypeStoreSize(ExtractedTy) + Offset <= DL.getTypeStoreSize(IntTy) && \"Element extends past full value\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/IRBuilder.h"
, 1901, __extension__ __PRETTY_FUNCTION__))
1901 "Element extends past full value")(static_cast <bool> (DL.getTypeStoreSize(ExtractedTy) +
Offset <= DL.getTypeStoreSize(IntTy) && "Element extends past full value"
) ? void (0) : __assert_fail ("DL.getTypeStoreSize(ExtractedTy) + Offset <= DL.getTypeStoreSize(IntTy) && \"Element extends past full value\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/IRBuilder.h"
, 1901, __extension__ __PRETTY_FUNCTION__))
;
1902 uint64_t ShAmt = 8 * Offset;
1903 Value *V = From;
1904 if (DL.isBigEndian())
1905 ShAmt = 8 * (DL.getTypeStoreSize(IntTy) -
1906 DL.getTypeStoreSize(ExtractedTy) - Offset);
1907 if (ShAmt) {
1908 V = CreateLShr(V, ShAmt, Name + ".shift");
1909 }
1910 assert(ExtractedTy->getBitWidth() <= IntTy->getBitWidth() &&(static_cast <bool> (ExtractedTy->getBitWidth() <=
IntTy->getBitWidth() && "Cannot extract to a larger integer!"
) ? void (0) : __assert_fail ("ExtractedTy->getBitWidth() <= IntTy->getBitWidth() && \"Cannot extract to a larger integer!\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/IRBuilder.h"
, 1911, __extension__ __PRETTY_FUNCTION__))
1911 "Cannot extract to a larger integer!")(static_cast <bool> (ExtractedTy->getBitWidth() <=
IntTy->getBitWidth() && "Cannot extract to a larger integer!"
) ? void (0) : __assert_fail ("ExtractedTy->getBitWidth() <= IntTy->getBitWidth() && \"Cannot extract to a larger integer!\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/IRBuilder.h"
, 1911, __extension__ __PRETTY_FUNCTION__))
;
1912 if (ExtractedTy != IntTy) {
1913 V = CreateTrunc(V, ExtractedTy, Name + ".trunc");
1914 }
1915 return V;
1916 }
1917
1918private:
1919 /// \brief Helper function that creates an assume intrinsic call that
1920 /// represents an alignment assumption on the provided Ptr, Mask, Type
1921 /// and Offset.
1922 CallInst *CreateAlignmentAssumptionHelper(const DataLayout &DL,
1923 Value *PtrValue, Value *Mask,
1924 Type *IntPtrTy,
1925 Value *OffsetValue) {
1926 Value *PtrIntValue = CreatePtrToInt(PtrValue, IntPtrTy, "ptrint");
1927
1928 if (OffsetValue) {
1929 bool IsOffsetZero = false;
1930 if (ConstantInt *CI = dyn_cast<ConstantInt>(OffsetValue))
1931 IsOffsetZero = CI->isZero();
1932
1933 if (!IsOffsetZero) {
1934 if (OffsetValue->getType() != IntPtrTy)
1935 OffsetValue = CreateIntCast(OffsetValue, IntPtrTy, /*isSigned*/ true,
1936 "offsetcast");
1937 PtrIntValue = CreateSub(PtrIntValue, OffsetValue, "offsetptr");
1938 }
1939 }
1940
1941 Value *Zero = ConstantInt::get(IntPtrTy, 0);
1942 Value *MaskedPtr = CreateAnd(PtrIntValue, Mask, "maskedptr");
1943 Value *InvCond = CreateICmpEQ(MaskedPtr, Zero, "maskcond");
1944 return CreateAssumption(InvCond);
1945 }
1946
1947public:
1948 /// \brief Create an assume intrinsic call that represents an alignment
1949 /// assumption on the provided pointer.
1950 ///
1951 /// An optional offset can be provided, and if it is provided, the offset
1952 /// must be subtracted from the provided pointer to get the pointer with the
1953 /// specified alignment.
1954 CallInst *CreateAlignmentAssumption(const DataLayout &DL, Value *PtrValue,
1955 unsigned Alignment,
1956 Value *OffsetValue = nullptr) {
1957 assert(isa<PointerType>(PtrValue->getType()) &&(static_cast <bool> (isa<PointerType>(PtrValue->
getType()) && "trying to create an alignment assumption on a non-pointer?"
) ? void (0) : __assert_fail ("isa<PointerType>(PtrValue->getType()) && \"trying to create an alignment assumption on a non-pointer?\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/IRBuilder.h"
, 1958, __extension__ __PRETTY_FUNCTION__))
1958 "trying to create an alignment assumption on a non-pointer?")(static_cast <bool> (isa<PointerType>(PtrValue->
getType()) && "trying to create an alignment assumption on a non-pointer?"
) ? void (0) : __assert_fail ("isa<PointerType>(PtrValue->getType()) && \"trying to create an alignment assumption on a non-pointer?\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/IRBuilder.h"
, 1958, __extension__ __PRETTY_FUNCTION__))
;
1959 PointerType *PtrTy = cast<PointerType>(PtrValue->getType());
1960 Type *IntPtrTy = getIntPtrTy(DL, PtrTy->getAddressSpace());
1961
1962 Value *Mask = ConstantInt::get(IntPtrTy, Alignment > 0 ? Alignment - 1 : 0);
1963 return CreateAlignmentAssumptionHelper(DL, PtrValue, Mask, IntPtrTy,
1964 OffsetValue);
1965 }
1966 //
1967 /// \brief Create an assume intrinsic call that represents an alignment
1968 /// assumption on the provided pointer.
1969 ///
1970 /// An optional offset can be provided, and if it is provided, the offset
1971 /// must be subtracted from the provided pointer to get the pointer with the
1972 /// specified alignment.
1973 ///
1974 /// This overload handles the condition where the Alignment is dependent
1975 /// on an existing value rather than a static value.
1976 CallInst *CreateAlignmentAssumption(const DataLayout &DL, Value *PtrValue,
1977 Value *Alignment,
1978 Value *OffsetValue = nullptr) {
1979 assert(isa<PointerType>(PtrValue->getType()) &&(static_cast <bool> (isa<PointerType>(PtrValue->
getType()) && "trying to create an alignment assumption on a non-pointer?"
) ? void (0) : __assert_fail ("isa<PointerType>(PtrValue->getType()) && \"trying to create an alignment assumption on a non-pointer?\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/IRBuilder.h"
, 1980, __extension__ __PRETTY_FUNCTION__))
1980 "trying to create an alignment assumption on a non-pointer?")(static_cast <bool> (isa<PointerType>(PtrValue->
getType()) && "trying to create an alignment assumption on a non-pointer?"
) ? void (0) : __assert_fail ("isa<PointerType>(PtrValue->getType()) && \"trying to create an alignment assumption on a non-pointer?\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/IRBuilder.h"
, 1980, __extension__ __PRETTY_FUNCTION__))
;
1981 PointerType *PtrTy = cast<PointerType>(PtrValue->getType());
1982 Type *IntPtrTy = getIntPtrTy(DL, PtrTy->getAddressSpace());
1983
1984 if (Alignment->getType() != IntPtrTy)
1985 Alignment = CreateIntCast(Alignment, IntPtrTy, /*isSigned*/ true,
1986 "alignmentcast");
1987 Value *IsPositive =
1988 CreateICmp(CmpInst::ICMP_SGT, Alignment,
1989 ConstantInt::get(Alignment->getType(), 0), "ispositive");
1990 Value *PositiveMask =
1991 CreateSub(Alignment, ConstantInt::get(IntPtrTy, 1), "positivemask");
1992 Value *Mask = CreateSelect(IsPositive, PositiveMask,
1993 ConstantInt::get(IntPtrTy, 0), "mask");
1994
1995 return CreateAlignmentAssumptionHelper(DL, PtrValue, Mask, IntPtrTy,
1996 OffsetValue);
1997 }
1998};
1999
2000// Create wrappers for C Binding types (see CBindingWrapping.h).
2001DEFINE_SIMPLE_CONVERSION_FUNCTIONS(IRBuilder<>, LLVMBuilderRef)inline IRBuilder<> *unwrap(LLVMBuilderRef P) { return reinterpret_cast
<IRBuilder<>*>(P); } inline LLVMBuilderRef wrap(const
IRBuilder<> *P) { return reinterpret_cast<LLVMBuilderRef
>(const_cast<IRBuilder<>*>(P)); }
2002
2003} // end namespace llvm
2004
2005#endif // LLVM_IR_IRBUILDER_H

/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h

1//===- llvm/Instructions.h - Instruction subclass definitions ---*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file exposes the class definitions of all of the subclasses of the
11// Instruction class. This is meant to be an easy way to get access to all
12// instruction subclasses.
13//
14//===----------------------------------------------------------------------===//
15
16#ifndef LLVM_IR_INSTRUCTIONS_H
17#define LLVM_IR_INSTRUCTIONS_H
18
19#include "llvm/ADT/ArrayRef.h"
20#include "llvm/ADT/None.h"
21#include "llvm/ADT/STLExtras.h"
22#include "llvm/ADT/SmallVector.h"
23#include "llvm/ADT/StringRef.h"
24#include "llvm/ADT/Twine.h"
25#include "llvm/ADT/iterator.h"
26#include "llvm/ADT/iterator_range.h"
27#include "llvm/IR/Attributes.h"
28#include "llvm/IR/BasicBlock.h"
29#include "llvm/IR/CallingConv.h"
30#include "llvm/IR/Constant.h"
31#include "llvm/IR/DerivedTypes.h"
32#include "llvm/IR/Function.h"
33#include "llvm/IR/InstrTypes.h"
34#include "llvm/IR/Instruction.h"
35#include "llvm/IR/OperandTraits.h"
36#include "llvm/IR/Type.h"
37#include "llvm/IR/Use.h"
38#include "llvm/IR/User.h"
39#include "llvm/IR/Value.h"
40#include "llvm/Support/AtomicOrdering.h"
41#include "llvm/Support/Casting.h"
42#include "llvm/Support/ErrorHandling.h"
43#include <cassert>
44#include <cstddef>
45#include <cstdint>
46#include <iterator>
47
48namespace llvm {
49
50class APInt;
51class ConstantInt;
52class DataLayout;
53class LLVMContext;
54
55//===----------------------------------------------------------------------===//
56// AllocaInst Class
57//===----------------------------------------------------------------------===//
58
59/// an instruction to allocate memory on the stack
60class AllocaInst : public UnaryInstruction {
61 Type *AllocatedType;
62
63protected:
64 // Note: Instruction needs to be a friend here to call cloneImpl.
65 friend class Instruction;
66
67 AllocaInst *cloneImpl() const;
68
69public:
70 explicit AllocaInst(Type *Ty, unsigned AddrSpace,
71 Value *ArraySize = nullptr,
72 const Twine &Name = "",
73 Instruction *InsertBefore = nullptr);
74 AllocaInst(Type *Ty, unsigned AddrSpace, Value *ArraySize,
75 const Twine &Name, BasicBlock *InsertAtEnd);
76
77 AllocaInst(Type *Ty, unsigned AddrSpace,
78 const Twine &Name, Instruction *InsertBefore = nullptr);
79 AllocaInst(Type *Ty, unsigned AddrSpace,
80 const Twine &Name, BasicBlock *InsertAtEnd);
81
82 AllocaInst(Type *Ty, unsigned AddrSpace, Value *ArraySize, unsigned Align,
83 const Twine &Name = "", Instruction *InsertBefore = nullptr);
84 AllocaInst(Type *Ty, unsigned AddrSpace, Value *ArraySize, unsigned Align,
85 const Twine &Name, BasicBlock *InsertAtEnd);
86
87 /// Return true if there is an allocation size parameter to the allocation
88 /// instruction that is not 1.
89 bool isArrayAllocation() const;
90
91 /// Get the number of elements allocated. For a simple allocation of a single
92 /// element, this will return a constant 1 value.
93 const Value *getArraySize() const { return getOperand(0); }
94 Value *getArraySize() { return getOperand(0); }
95
96 /// Overload to return most specific pointer type.
97 PointerType *getType() const {
98 return cast<PointerType>(Instruction::getType());
99 }
100
101 /// Return the type that is being allocated by the instruction.
102 Type *getAllocatedType() const { return AllocatedType; }
103 /// for use only in special circumstances that need to generically
104 /// transform a whole instruction (eg: IR linking and vectorization).
105 void setAllocatedType(Type *Ty) { AllocatedType = Ty; }
106
107 /// Return the alignment of the memory that is being allocated by the
108 /// instruction.
109 unsigned getAlignment() const {
110 return (1u << (getSubclassDataFromInstruction() & 31)) >> 1;
111 }
112 void setAlignment(unsigned Align);
113
114 /// Return true if this alloca is in the entry block of the function and is a
115 /// constant size. If so, the code generator will fold it into the
116 /// prolog/epilog code, so it is basically free.
117 bool isStaticAlloca() const;
118
119 /// Return true if this alloca is used as an inalloca argument to a call. Such
120 /// allocas are never considered static even if they are in the entry block.
121 bool isUsedWithInAlloca() const {
122 return getSubclassDataFromInstruction() & 32;
123 }
124
125 /// Specify whether this alloca is used to represent the arguments to a call.
126 void setUsedWithInAlloca(bool V) {
127 setInstructionSubclassData((getSubclassDataFromInstruction() & ~32) |
128 (V ? 32 : 0));
129 }
130
131 /// Return true if this alloca is used as a swifterror argument to a call.
132 bool isSwiftError() const {
133 return getSubclassDataFromInstruction() & 64;
134 }
135
136 /// Specify whether this alloca is used to represent a swifterror.
137 void setSwiftError(bool V) {
138 setInstructionSubclassData((getSubclassDataFromInstruction() & ~64) |
139 (V ? 64 : 0));
140 }
141
142 // Methods for support type inquiry through isa, cast, and dyn_cast:
143 static bool classof(const Instruction *I) {
144 return (I->getOpcode() == Instruction::Alloca);
145 }
146 static bool classof(const Value *V) {
147 return isa<Instruction>(V) && classof(cast<Instruction>(V));
148 }
149
150private:
151 // Shadow Instruction::setInstructionSubclassData with a private forwarding
152 // method so that subclasses cannot accidentally use it.
153 void setInstructionSubclassData(unsigned short D) {
154 Instruction::setInstructionSubclassData(D);
155 }
156};
157
158//===----------------------------------------------------------------------===//
159// LoadInst Class
160//===----------------------------------------------------------------------===//
161
162/// An instruction for reading from memory. This uses the SubclassData field in
163/// Value to store whether or not the load is volatile.
164class LoadInst : public UnaryInstruction {
165 void AssertOK();
166
167protected:
168 // Note: Instruction needs to be a friend here to call cloneImpl.
169 friend class Instruction;
170
171 LoadInst *cloneImpl() const;
172
173public:
174 LoadInst(Value *Ptr, const Twine &NameStr, Instruction *InsertBefore);
175 LoadInst(Value *Ptr, const Twine &NameStr, BasicBlock *InsertAtEnd);
176 LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr, bool isVolatile = false,
177 Instruction *InsertBefore = nullptr);
178 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile = false,
179 Instruction *InsertBefore = nullptr)
180 : LoadInst(cast<PointerType>(Ptr->getType())->getElementType(), Ptr,
181 NameStr, isVolatile, InsertBefore) {}
182 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
183 BasicBlock *InsertAtEnd);
184 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile, unsigned Align,
185 Instruction *InsertBefore = nullptr)
186 : LoadInst(cast<PointerType>(Ptr->getType())->getElementType(), Ptr,
187 NameStr, isVolatile, Align, InsertBefore) {}
188 LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr, bool isVolatile,
189 unsigned Align, Instruction *InsertBefore = nullptr);
190 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
191 unsigned Align, BasicBlock *InsertAtEnd);
192 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile, unsigned Align,
193 AtomicOrdering Order, SyncScope::ID SSID = SyncScope::System,
194 Instruction *InsertBefore = nullptr)
195 : LoadInst(cast<PointerType>(Ptr->getType())->getElementType(), Ptr,
196 NameStr, isVolatile, Align, Order, SSID, InsertBefore) {}
197 LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr, bool isVolatile,
198 unsigned Align, AtomicOrdering Order,
199 SyncScope::ID SSID = SyncScope::System,
200 Instruction *InsertBefore = nullptr);
201 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
202 unsigned Align, AtomicOrdering Order, SyncScope::ID SSID,
203 BasicBlock *InsertAtEnd);
204 LoadInst(Value *Ptr, const char *NameStr, Instruction *InsertBefore);
205 LoadInst(Value *Ptr, const char *NameStr, BasicBlock *InsertAtEnd);
206 LoadInst(Type *Ty, Value *Ptr, const char *NameStr = nullptr,
207 bool isVolatile = false, Instruction *InsertBefore = nullptr);
208 explicit LoadInst(Value *Ptr, const char *NameStr = nullptr,
209 bool isVolatile = false,
210 Instruction *InsertBefore = nullptr)
211 : LoadInst(cast<PointerType>(Ptr->getType())->getElementType(), Ptr,
35
Called C++ object pointer is null
212 NameStr, isVolatile, InsertBefore) {}
213 LoadInst(Value *Ptr, const char *NameStr, bool isVolatile,
214 BasicBlock *InsertAtEnd);
215
216 /// Return true if this is a load from a volatile memory location.
217 bool isVolatile() const { return getSubclassDataFromInstruction() & 1; }
218
219 /// Specify whether this is a volatile load or not.
220 void setVolatile(bool V) {
221 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
222 (V ? 1 : 0));
223 }
224
225 /// Return the alignment of the access that is being performed.
226 unsigned getAlignment() const {
227 return (1 << ((getSubclassDataFromInstruction() >> 1) & 31)) >> 1;
228 }
229
230 void setAlignment(unsigned Align);
231
232 /// Returns the ordering constraint of this load instruction.
233 AtomicOrdering getOrdering() const {
234 return AtomicOrdering((getSubclassDataFromInstruction() >> 7) & 7);
235 }
236
237 /// Sets the ordering constraint of this load instruction. May not be Release
238 /// or AcquireRelease.
239 void setOrdering(AtomicOrdering Ordering) {
240 setInstructionSubclassData((getSubclassDataFromInstruction() & ~(7 << 7)) |
241 ((unsigned)Ordering << 7));
242 }
243
244 /// Returns the synchronization scope ID of this load instruction.
245 SyncScope::ID getSyncScopeID() const {
246 return SSID;
247 }
248
249 /// Sets the synchronization scope ID of this load instruction.
250 void setSyncScopeID(SyncScope::ID SSID) {
251 this->SSID = SSID;
252 }
253
254 /// Sets the ordering constraint and the synchronization scope ID of this load
255 /// instruction.
256 void setAtomic(AtomicOrdering Ordering,
257 SyncScope::ID SSID = SyncScope::System) {
258 setOrdering(Ordering);
259 setSyncScopeID(SSID);
260 }
261
262 bool isSimple() const { return !isAtomic() && !isVolatile(); }
263
264 bool isUnordered() const {
265 return (getOrdering() == AtomicOrdering::NotAtomic ||
266 getOrdering() == AtomicOrdering::Unordered) &&
267 !isVolatile();
268 }
269
270 Value *getPointerOperand() { return getOperand(0); }
271 const Value *getPointerOperand() const { return getOperand(0); }
272 static unsigned getPointerOperandIndex() { return 0U; }
273 Type *getPointerOperandType() const { return getPointerOperand()->getType(); }
274
275 /// Returns the address space of the pointer operand.
276 unsigned getPointerAddressSpace() const {
277 return getPointerOperandType()->getPointerAddressSpace();
278 }
279
280 // Methods for support type inquiry through isa, cast, and dyn_cast:
281 static bool classof(const Instruction *I) {
282 return I->getOpcode() == Instruction::Load;
283 }
284 static bool classof(const Value *V) {
285 return isa<Instruction>(V) && classof(cast<Instruction>(V));
286 }
287
288private:
289 // Shadow Instruction::setInstructionSubclassData with a private forwarding
290 // method so that subclasses cannot accidentally use it.
291 void setInstructionSubclassData(unsigned short D) {
292 Instruction::setInstructionSubclassData(D);
293 }
294
295 /// The synchronization scope ID of this load instruction. Not quite enough
296 /// room in SubClassData for everything, so synchronization scope ID gets its
297 /// own field.
298 SyncScope::ID SSID;
299};
300
301//===----------------------------------------------------------------------===//
302// StoreInst Class
303//===----------------------------------------------------------------------===//
304
305/// An instruction for storing to memory.
306class StoreInst : public Instruction {
307 void AssertOK();
308
309protected:
310 // Note: Instruction needs to be a friend here to call cloneImpl.
311 friend class Instruction;
312
313 StoreInst *cloneImpl() const;
314
315public:
316 StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore);
317 StoreInst(Value *Val, Value *Ptr, BasicBlock *InsertAtEnd);
318 StoreInst(Value *Val, Value *Ptr, bool isVolatile = false,
319 Instruction *InsertBefore = nullptr);
320 StoreInst(Value *Val, Value *Ptr, bool isVolatile, BasicBlock *InsertAtEnd);
321 StoreInst(Value *Val, Value *Ptr, bool isVolatile,
322 unsigned Align, Instruction *InsertBefore = nullptr);
323 StoreInst(Value *Val, Value *Ptr, bool isVolatile,
324 unsigned Align, BasicBlock *InsertAtEnd);
325 StoreInst(Value *Val, Value *Ptr, bool isVolatile,
326 unsigned Align, AtomicOrdering Order,
327 SyncScope::ID SSID = SyncScope::System,
328 Instruction *InsertBefore = nullptr);
329 StoreInst(Value *Val, Value *Ptr, bool isVolatile,
330 unsigned Align, AtomicOrdering Order, SyncScope::ID SSID,
331 BasicBlock *InsertAtEnd);
332
333 // allocate space for exactly two operands
334 void *operator new(size_t s) {
335 return User::operator new(s, 2);
336 }
337
338 /// Return true if this is a store to a volatile memory location.
339 bool isVolatile() const { return getSubclassDataFromInstruction() & 1; }
340
341 /// Specify whether this is a volatile store or not.
342 void setVolatile(bool V) {
343 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
344 (V ? 1 : 0));
345 }
346
347 /// Transparently provide more efficient getOperand methods.
348 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)public: inline Value *getOperand(unsigned) const; inline void
setOperand(unsigned, Value*); inline op_iterator op_begin();
inline const_op_iterator op_begin() const; inline op_iterator
op_end(); inline const_op_iterator op_end() const; protected
: template <int> inline Use &Op(); template <int
> inline const Use &Op() const; public: inline unsigned
getNumOperands() const
;
349
350 /// Return the alignment of the access that is being performed
351 unsigned getAlignment() const {
352 return (1 << ((getSubclassDataFromInstruction() >> 1) & 31)) >> 1;
353 }
354
355 void setAlignment(unsigned Align);
356
357 /// Returns the ordering constraint of this store instruction.
358 AtomicOrdering getOrdering() const {
359 return AtomicOrdering((getSubclassDataFromInstruction() >> 7) & 7);
360 }
361
362 /// Sets the ordering constraint of this store instruction. May not be
363 /// Acquire or AcquireRelease.
364 void setOrdering(AtomicOrdering Ordering) {
365 setInstructionSubclassData((getSubclassDataFromInstruction() & ~(7 << 7)) |
366 ((unsigned)Ordering << 7));
367 }
368
369 /// Returns the synchronization scope ID of this store instruction.
370 SyncScope::ID getSyncScopeID() const {
371 return SSID;
372 }
373
374 /// Sets the synchronization scope ID of this store instruction.
375 void setSyncScopeID(SyncScope::ID SSID) {
376 this->SSID = SSID;
377 }
378
379 /// Sets the ordering constraint and the synchronization scope ID of this
380 /// store instruction.
381 void setAtomic(AtomicOrdering Ordering,
382 SyncScope::ID SSID = SyncScope::System) {
383 setOrdering(Ordering);
384 setSyncScopeID(SSID);
385 }
386
387 bool isSimple() const { return !isAtomic() && !isVolatile(); }
388
389 bool isUnordered() const {
390 return (getOrdering() == AtomicOrdering::NotAtomic ||
391 getOrdering() == AtomicOrdering::Unordered) &&
392 !isVolatile();
393 }
394
395 Value *getValueOperand() { return getOperand(0); }
396 const Value *getValueOperand() const { return getOperand(0); }
397
398 Value *getPointerOperand() { return getOperand(1); }
399 const Value *getPointerOperand() const { return getOperand(1); }
400 static unsigned getPointerOperandIndex() { return 1U; }
401 Type *getPointerOperandType() const { return getPointerOperand()->getType(); }
402
403 /// Returns the address space of the pointer operand.
404 unsigned getPointerAddressSpace() const {
405 return getPointerOperandType()->getPointerAddressSpace();
406 }
407
408 // Methods for support type inquiry through isa, cast, and dyn_cast:
409 static bool classof(const Instruction *I) {
410 return I->getOpcode() == Instruction::Store;
411 }
412 static bool classof(const Value *V) {
413 return isa<Instruction>(V) && classof(cast<Instruction>(V));
414 }
415
416private:
417 // Shadow Instruction::setInstructionSubclassData with a private forwarding
418 // method so that subclasses cannot accidentally use it.
419 void setInstructionSubclassData(unsigned short D) {
420 Instruction::setInstructionSubclassData(D);
421 }
422
423 /// The synchronization scope ID of this store instruction. Not quite enough
424 /// room in SubClassData for everything, so synchronization scope ID gets its
425 /// own field.
426 SyncScope::ID SSID;
427};
428
429template <>
430struct OperandTraits<StoreInst> : public FixedNumOperandTraits<StoreInst, 2> {
431};
432
433DEFINE_TRANSPARENT_OPERAND_ACCESSORS(StoreInst, Value)StoreInst::op_iterator StoreInst::op_begin() { return OperandTraits
<StoreInst>::op_begin(this); } StoreInst::const_op_iterator
StoreInst::op_begin() const { return OperandTraits<StoreInst
>::op_begin(const_cast<StoreInst*>(this)); } StoreInst
::op_iterator StoreInst::op_end() { return OperandTraits<StoreInst
>::op_end(this); } StoreInst::const_op_iterator StoreInst::
op_end() const { return OperandTraits<StoreInst>::op_end
(const_cast<StoreInst*>(this)); } Value *StoreInst::getOperand
(unsigned i_nocapture) const { (static_cast <bool> (i_nocapture
< OperandTraits<StoreInst>::operands(this) &&
"getOperand() out of range!") ? void (0) : __assert_fail ("i_nocapture < OperandTraits<StoreInst>::operands(this) && \"getOperand() out of range!\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 433, __extension__ __PRETTY_FUNCTION__)); return cast_or_null
<Value>( OperandTraits<StoreInst>::op_begin(const_cast
<StoreInst*>(this))[i_nocapture].get()); } void StoreInst
::setOperand(unsigned i_nocapture, Value *Val_nocapture) { (static_cast
<bool> (i_nocapture < OperandTraits<StoreInst>
::operands(this) && "setOperand() out of range!") ? void
(0) : __assert_fail ("i_nocapture < OperandTraits<StoreInst>::operands(this) && \"setOperand() out of range!\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 433, __extension__ __PRETTY_FUNCTION__)); OperandTraits<
StoreInst>::op_begin(this)[i_nocapture] = Val_nocapture; }
unsigned StoreInst::getNumOperands() const { return OperandTraits
<StoreInst>::operands(this); } template <int Idx_nocapture
> Use &StoreInst::Op() { return this->OpFrom<Idx_nocapture
>(this); } template <int Idx_nocapture> const Use &
StoreInst::Op() const { return this->OpFrom<Idx_nocapture
>(this); }
434
435//===----------------------------------------------------------------------===//
436// FenceInst Class
437//===----------------------------------------------------------------------===//
438
439/// An instruction for ordering other memory operations.
440class FenceInst : public Instruction {
441 void Init(AtomicOrdering Ordering, SyncScope::ID SSID);
442
443protected:
444 // Note: Instruction needs to be a friend here to call cloneImpl.
445 friend class Instruction;
446
447 FenceInst *cloneImpl() const;
448
449public:
450 // Ordering may only be Acquire, Release, AcquireRelease, or
451 // SequentiallyConsistent.
452 FenceInst(LLVMContext &C, AtomicOrdering Ordering,
453 SyncScope::ID SSID = SyncScope::System,
454 Instruction *InsertBefore = nullptr);
455 FenceInst(LLVMContext &C, AtomicOrdering Ordering, SyncScope::ID SSID,
456 BasicBlock *InsertAtEnd);
457
458 // allocate space for exactly zero operands
459 void *operator new(size_t s) {
460 return User::operator new(s, 0);
461 }
462
463 /// Returns the ordering constraint of this fence instruction.
464 AtomicOrdering getOrdering() const {
465 return AtomicOrdering(getSubclassDataFromInstruction() >> 1);
466 }
467
468 /// Sets the ordering constraint of this fence instruction. May only be
469 /// Acquire, Release, AcquireRelease, or SequentiallyConsistent.
470 void setOrdering(AtomicOrdering Ordering) {
471 setInstructionSubclassData((getSubclassDataFromInstruction() & 1) |
472 ((unsigned)Ordering << 1));
473 }
474
475 /// Returns the synchronization scope ID of this fence instruction.
476 SyncScope::ID getSyncScopeID() const {
477 return SSID;
478 }
479
480 /// Sets the synchronization scope ID of this fence instruction.
481 void setSyncScopeID(SyncScope::ID SSID) {
482 this->SSID = SSID;
483 }
484
485 // Methods for support type inquiry through isa, cast, and dyn_cast:
486 static bool classof(const Instruction *I) {
487 return I->getOpcode() == Instruction::Fence;
488 }
489 static bool classof(const Value *V) {
490 return isa<Instruction>(V) && classof(cast<Instruction>(V));
491 }
492
493private:
494 // Shadow Instruction::setInstructionSubclassData with a private forwarding
495 // method so that subclasses cannot accidentally use it.
496 void setInstructionSubclassData(unsigned short D) {
497 Instruction::setInstructionSubclassData(D);
498 }
499
500 /// The synchronization scope ID of this fence instruction. Not quite enough
501 /// room in SubClassData for everything, so synchronization scope ID gets its
502 /// own field.
503 SyncScope::ID SSID;
504};
505
506//===----------------------------------------------------------------------===//
507// AtomicCmpXchgInst Class
508//===----------------------------------------------------------------------===//
509
510/// an instruction that atomically checks whether a
511/// specified value is in a memory location, and, if it is, stores a new value
512/// there. Returns the value that was loaded.
513///
514class AtomicCmpXchgInst : public Instruction {
515 void Init(Value *Ptr, Value *Cmp, Value *NewVal,
516 AtomicOrdering SuccessOrdering, AtomicOrdering FailureOrdering,
517 SyncScope::ID SSID);
518
519protected:
520 // Note: Instruction needs to be a friend here to call cloneImpl.
521 friend class Instruction;
522
523 AtomicCmpXchgInst *cloneImpl() const;
524
525public:
526 AtomicCmpXchgInst(Value *Ptr, Value *Cmp, Value *NewVal,
527 AtomicOrdering SuccessOrdering,
528 AtomicOrdering FailureOrdering,
529 SyncScope::ID SSID, Instruction *InsertBefore = nullptr);
530 AtomicCmpXchgInst(Value *Ptr, Value *Cmp, Value *NewVal,
531 AtomicOrdering SuccessOrdering,
532 AtomicOrdering FailureOrdering,
533 SyncScope::ID SSID, BasicBlock *InsertAtEnd);
534
535 // allocate space for exactly three operands
536 void *operator new(size_t s) {
537 return User::operator new(s, 3);
538 }
539
540 /// Return true if this is a cmpxchg from a volatile memory
541 /// location.
542 ///
543 bool isVolatile() const {
544 return getSubclassDataFromInstruction() & 1;
545 }
546
547 /// Specify whether this is a volatile cmpxchg.
548 ///
549 void setVolatile(bool V) {
550 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
551 (unsigned)V);
552 }
553
554 /// Return true if this cmpxchg may spuriously fail.
555 bool isWeak() const {
556 return getSubclassDataFromInstruction() & 0x100;
557 }
558
559 void setWeak(bool IsWeak) {
560 setInstructionSubclassData((getSubclassDataFromInstruction() & ~0x100) |
561 (IsWeak << 8));
562 }
563
564 /// Transparently provide more efficient getOperand methods.
565 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)public: inline Value *getOperand(unsigned) const; inline void
setOperand(unsigned, Value*); inline op_iterator op_begin();
inline const_op_iterator op_begin() const; inline op_iterator
op_end(); inline const_op_iterator op_end() const; protected
: template <int> inline Use &Op(); template <int
> inline const Use &Op() const; public: inline unsigned
getNumOperands() const
;
566
567 /// Returns the success ordering constraint of this cmpxchg instruction.
568 AtomicOrdering getSuccessOrdering() const {
569 return AtomicOrdering((getSubclassDataFromInstruction() >> 2) & 7);
570 }
571
572 /// Sets the success ordering constraint of this cmpxchg instruction.
573 void setSuccessOrdering(AtomicOrdering Ordering) {
574 assert(Ordering != AtomicOrdering::NotAtomic &&(static_cast <bool> (Ordering != AtomicOrdering::NotAtomic
&& "CmpXchg instructions can only be atomic.") ? void
(0) : __assert_fail ("Ordering != AtomicOrdering::NotAtomic && \"CmpXchg instructions can only be atomic.\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 575, __extension__ __PRETTY_FUNCTION__))
575 "CmpXchg instructions can only be atomic.")(static_cast <bool> (Ordering != AtomicOrdering::NotAtomic
&& "CmpXchg instructions can only be atomic.") ? void
(0) : __assert_fail ("Ordering != AtomicOrdering::NotAtomic && \"CmpXchg instructions can only be atomic.\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 575, __extension__ __PRETTY_FUNCTION__))
;
576 setInstructionSubclassData((getSubclassDataFromInstruction() & ~0x1c) |
577 ((unsigned)Ordering << 2));
578 }
579
580 /// Returns the failure ordering constraint of this cmpxchg instruction.
581 AtomicOrdering getFailureOrdering() const {
582 return AtomicOrdering((getSubclassDataFromInstruction() >> 5) & 7);
583 }
584
585 /// Sets the failure ordering constraint of this cmpxchg instruction.
586 void setFailureOrdering(AtomicOrdering Ordering) {
587 assert(Ordering != AtomicOrdering::NotAtomic &&(static_cast <bool> (Ordering != AtomicOrdering::NotAtomic
&& "CmpXchg instructions can only be atomic.") ? void
(0) : __assert_fail ("Ordering != AtomicOrdering::NotAtomic && \"CmpXchg instructions can only be atomic.\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 588, __extension__ __PRETTY_FUNCTION__))
588 "CmpXchg instructions can only be atomic.")(static_cast <bool> (Ordering != AtomicOrdering::NotAtomic
&& "CmpXchg instructions can only be atomic.") ? void
(0) : __assert_fail ("Ordering != AtomicOrdering::NotAtomic && \"CmpXchg instructions can only be atomic.\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 588, __extension__ __PRETTY_FUNCTION__))
;
589 setInstructionSubclassData((getSubclassDataFromInstruction() & ~0xe0) |
590 ((unsigned)Ordering << 5));
591 }
592
593 /// Returns the synchronization scope ID of this cmpxchg instruction.
594 SyncScope::ID getSyncScopeID() const {
595 return SSID;
596 }
597
598 /// Sets the synchronization scope ID of this cmpxchg instruction.
599 void setSyncScopeID(SyncScope::ID SSID) {
600 this->SSID = SSID;
601 }
602
603 Value *getPointerOperand() { return getOperand(0); }
604 const Value *getPointerOperand() const { return getOperand(0); }
605 static unsigned getPointerOperandIndex() { return 0U; }
606
607 Value *getCompareOperand() { return getOperand(1); }
608 const Value *getCompareOperand() const { return getOperand(1); }
609
610 Value *getNewValOperand() { return getOperand(2); }
611 const Value *getNewValOperand() const { return getOperand(2); }
612
613 /// Returns the address space of the pointer operand.
614 unsigned getPointerAddressSpace() const {
615 return getPointerOperand()->getType()->getPointerAddressSpace();
616 }
617
618 /// Returns the strongest permitted ordering on failure, given the
619 /// desired ordering on success.
620 ///
621 /// If the comparison in a cmpxchg operation fails, there is no atomic store
622 /// so release semantics cannot be provided. So this function drops explicit
623 /// Release requests from the AtomicOrdering. A SequentiallyConsistent
624 /// operation would remain SequentiallyConsistent.
625 static AtomicOrdering
626 getStrongestFailureOrdering(AtomicOrdering SuccessOrdering) {
627 switch (SuccessOrdering) {
628 default:
629 llvm_unreachable("invalid cmpxchg success ordering")::llvm::llvm_unreachable_internal("invalid cmpxchg success ordering"
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 629)
;
630 case AtomicOrdering::Release:
631 case AtomicOrdering::Monotonic:
632 return AtomicOrdering::Monotonic;
633 case AtomicOrdering::AcquireRelease:
634 case AtomicOrdering::Acquire:
635 return AtomicOrdering::Acquire;
636 case AtomicOrdering::SequentiallyConsistent:
637 return AtomicOrdering::SequentiallyConsistent;
638 }
639 }
640
641 // Methods for support type inquiry through isa, cast, and dyn_cast:
642 static bool classof(const Instruction *I) {
643 return I->getOpcode() == Instruction::AtomicCmpXchg;
644 }
645 static bool classof(const Value *V) {
646 return isa<Instruction>(V) && classof(cast<Instruction>(V));
647 }
648
649private:
650 // Shadow Instruction::setInstructionSubclassData with a private forwarding
651 // method so that subclasses cannot accidentally use it.
652 void setInstructionSubclassData(unsigned short D) {
653 Instruction::setInstructionSubclassData(D);
654 }
655
656 /// The synchronization scope ID of this cmpxchg instruction. Not quite
657 /// enough room in SubClassData for everything, so synchronization scope ID
658 /// gets its own field.
659 SyncScope::ID SSID;
660};
661
662template <>
663struct OperandTraits<AtomicCmpXchgInst> :
664 public FixedNumOperandTraits<AtomicCmpXchgInst, 3> {
665};
666
667DEFINE_TRANSPARENT_OPERAND_ACCESSORS(AtomicCmpXchgInst, Value)AtomicCmpXchgInst::op_iterator AtomicCmpXchgInst::op_begin() {
return OperandTraits<AtomicCmpXchgInst>::op_begin(this
); } AtomicCmpXchgInst::const_op_iterator AtomicCmpXchgInst::
op_begin() const { return OperandTraits<AtomicCmpXchgInst>
::op_begin(const_cast<AtomicCmpXchgInst*>(this)); } AtomicCmpXchgInst
::op_iterator AtomicCmpXchgInst::op_end() { return OperandTraits
<AtomicCmpXchgInst>::op_end(this); } AtomicCmpXchgInst::
const_op_iterator AtomicCmpXchgInst::op_end() const { return OperandTraits
<AtomicCmpXchgInst>::op_end(const_cast<AtomicCmpXchgInst
*>(this)); } Value *AtomicCmpXchgInst::getOperand(unsigned
i_nocapture) const { (static_cast <bool> (i_nocapture <
OperandTraits<AtomicCmpXchgInst>::operands(this) &&
"getOperand() out of range!") ? void (0) : __assert_fail ("i_nocapture < OperandTraits<AtomicCmpXchgInst>::operands(this) && \"getOperand() out of range!\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 667, __extension__ __PRETTY_FUNCTION__)); return cast_or_null
<Value>( OperandTraits<AtomicCmpXchgInst>::op_begin
(const_cast<AtomicCmpXchgInst*>(this))[i_nocapture].get
()); } void AtomicCmpXchgInst::setOperand(unsigned i_nocapture
, Value *Val_nocapture) { (static_cast <bool> (i_nocapture
< OperandTraits<AtomicCmpXchgInst>::operands(this) &&
"setOperand() out of range!") ? void (0) : __assert_fail ("i_nocapture < OperandTraits<AtomicCmpXchgInst>::operands(this) && \"setOperand() out of range!\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 667, __extension__ __PRETTY_FUNCTION__)); OperandTraits<
AtomicCmpXchgInst>::op_begin(this)[i_nocapture] = Val_nocapture
; } unsigned AtomicCmpXchgInst::getNumOperands() const { return
OperandTraits<AtomicCmpXchgInst>::operands(this); } template
<int Idx_nocapture> Use &AtomicCmpXchgInst::Op() {
return this->OpFrom<Idx_nocapture>(this); } template
<int Idx_nocapture> const Use &AtomicCmpXchgInst::
Op() const { return this->OpFrom<Idx_nocapture>(this
); }
668
669//===----------------------------------------------------------------------===//
670// AtomicRMWInst Class
671//===----------------------------------------------------------------------===//
672
673/// an instruction that atomically reads a memory location,
674/// combines it with another value, and then stores the result back. Returns
675/// the old value.
676///
677class AtomicRMWInst : public Instruction {
678protected:
679 // Note: Instruction needs to be a friend here to call cloneImpl.
680 friend class Instruction;
681
682 AtomicRMWInst *cloneImpl() const;
683
684public:
685 /// This enumeration lists the possible modifications atomicrmw can make. In
686 /// the descriptions, 'p' is the pointer to the instruction's memory location,
687 /// 'old' is the initial value of *p, and 'v' is the other value passed to the
688 /// instruction. These instructions always return 'old'.
689 enum BinOp {
690 /// *p = v
691 Xchg,
692 /// *p = old + v
693 Add,
694 /// *p = old - v
695 Sub,
696 /// *p = old & v
697 And,
698 /// *p = ~(old & v)
699 Nand,
700 /// *p = old | v
701 Or,
702 /// *p = old ^ v
703 Xor,
704 /// *p = old >signed v ? old : v
705 Max,
706 /// *p = old <signed v ? old : v
707 Min,
708 /// *p = old >unsigned v ? old : v
709 UMax,
710 /// *p = old <unsigned v ? old : v
711 UMin,
712
713 FIRST_BINOP = Xchg,
714 LAST_BINOP = UMin,
715 BAD_BINOP
716 };
717
718 AtomicRMWInst(BinOp Operation, Value *Ptr, Value *Val,
719 AtomicOrdering Ordering, SyncScope::ID SSID,
720 Instruction *InsertBefore = nullptr);
721 AtomicRMWInst(BinOp Operation, Value *Ptr, Value *Val,
722 AtomicOrdering Ordering, SyncScope::ID SSID,
723 BasicBlock *InsertAtEnd);
724
725 // allocate space for exactly two operands
726 void *operator new(size_t s) {
727 return User::operator new(s, 2);
728 }
729
730 BinOp getOperation() const {
731 return static_cast<BinOp>(getSubclassDataFromInstruction() >> 5);
732 }
733
734 void setOperation(BinOp Operation) {
735 unsigned short SubclassData = getSubclassDataFromInstruction();
736 setInstructionSubclassData((SubclassData & 31) |
737 (Operation << 5));
738 }
739
740 /// Return true if this is a RMW on a volatile memory location.
741 ///
742 bool isVolatile() const {
743 return getSubclassDataFromInstruction() & 1;
744 }
745
746 /// Specify whether this is a volatile RMW or not.
747 ///
748 void setVolatile(bool V) {
749 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
750 (unsigned)V);
751 }
752
753 /// Transparently provide more efficient getOperand methods.
754 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)public: inline Value *getOperand(unsigned) const; inline void
setOperand(unsigned, Value*); inline op_iterator op_begin();
inline const_op_iterator op_begin() const; inline op_iterator
op_end(); inline const_op_iterator op_end() const; protected
: template <int> inline Use &Op(); template <int
> inline const Use &Op() const; public: inline unsigned
getNumOperands() const
;
755
756 /// Returns the ordering constraint of this rmw instruction.
757 AtomicOrdering getOrdering() const {
758 return AtomicOrdering((getSubclassDataFromInstruction() >> 2) & 7);
759 }
760
761 /// Sets the ordering constraint of this rmw instruction.
762 void setOrdering(AtomicOrdering Ordering) {
763 assert(Ordering != AtomicOrdering::NotAtomic &&(static_cast <bool> (Ordering != AtomicOrdering::NotAtomic
&& "atomicrmw instructions can only be atomic.") ? void
(0) : __assert_fail ("Ordering != AtomicOrdering::NotAtomic && \"atomicrmw instructions can only be atomic.\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 764, __extension__ __PRETTY_FUNCTION__))
764 "atomicrmw instructions can only be atomic.")(static_cast <bool> (Ordering != AtomicOrdering::NotAtomic
&& "atomicrmw instructions can only be atomic.") ? void
(0) : __assert_fail ("Ordering != AtomicOrdering::NotAtomic && \"atomicrmw instructions can only be atomic.\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 764, __extension__ __PRETTY_FUNCTION__))
;
765 setInstructionSubclassData((getSubclassDataFromInstruction() & ~(7 << 2)) |
766 ((unsigned)Ordering << 2));
767 }
768
769 /// Returns the synchronization scope ID of this rmw instruction.
770 SyncScope::ID getSyncScopeID() const {
771 return SSID;
772 }
773
774 /// Sets the synchronization scope ID of this rmw instruction.
775 void setSyncScopeID(SyncScope::ID SSID) {
776 this->SSID = SSID;
777 }
778
779 Value *getPointerOperand() { return getOperand(0); }
780 const Value *getPointerOperand() const { return getOperand(0); }
781 static unsigned getPointerOperandIndex() { return 0U; }
782
783 Value *getValOperand() { return getOperand(1); }
784 const Value *getValOperand() const { return getOperand(1); }
785
786 /// Returns the address space of the pointer operand.
787 unsigned getPointerAddressSpace() const {
788 return getPointerOperand()->getType()->getPointerAddressSpace();
789 }
790
791 // Methods for support type inquiry through isa, cast, and dyn_cast:
792 static bool classof(const Instruction *I) {
793 return I->getOpcode() == Instruction::AtomicRMW;
794 }
795 static bool classof(const Value *V) {
796 return isa<Instruction>(V) && classof(cast<Instruction>(V));
797 }
798
799private:
800 void Init(BinOp Operation, Value *Ptr, Value *Val,
801 AtomicOrdering Ordering, SyncScope::ID SSID);
802
803 // Shadow Instruction::setInstructionSubclassData with a private forwarding
804 // method so that subclasses cannot accidentally use it.
805 void setInstructionSubclassData(unsigned short D) {
806 Instruction::setInstructionSubclassData(D);
807 }
808
809 /// The synchronization scope ID of this rmw instruction. Not quite enough
810 /// room in SubClassData for everything, so synchronization scope ID gets its
811 /// own field.
812 SyncScope::ID SSID;
813};
814
815template <>
816struct OperandTraits<AtomicRMWInst>
817 : public FixedNumOperandTraits<AtomicRMWInst,2> {
818};
819
820DEFINE_TRANSPARENT_OPERAND_ACCESSORS(AtomicRMWInst, Value)AtomicRMWInst::op_iterator AtomicRMWInst::op_begin() { return
OperandTraits<AtomicRMWInst>::op_begin(this); } AtomicRMWInst
::const_op_iterator AtomicRMWInst::op_begin() const { return OperandTraits
<AtomicRMWInst>::op_begin(const_cast<AtomicRMWInst*>
(this)); } AtomicRMWInst::op_iterator AtomicRMWInst::op_end()
{ return OperandTraits<AtomicRMWInst>::op_end(this); }
AtomicRMWInst::const_op_iterator AtomicRMWInst::op_end() const
{ return OperandTraits<AtomicRMWInst>::op_end(const_cast
<AtomicRMWInst*>(this)); } Value *AtomicRMWInst::getOperand
(unsigned i_nocapture) const { (static_cast <bool> (i_nocapture
< OperandTraits<AtomicRMWInst>::operands(this) &&
"getOperand() out of range!") ? void (0) : __assert_fail ("i_nocapture < OperandTraits<AtomicRMWInst>::operands(this) && \"getOperand() out of range!\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 820, __extension__ __PRETTY_FUNCTION__)); return cast_or_null
<Value>( OperandTraits<AtomicRMWInst>::op_begin(const_cast
<AtomicRMWInst*>(this))[i_nocapture].get()); } void AtomicRMWInst
::setOperand(unsigned i_nocapture, Value *Val_nocapture) { (static_cast
<bool> (i_nocapture < OperandTraits<AtomicRMWInst
>::operands(this) && "setOperand() out of range!")
? void (0) : __assert_fail ("i_nocapture < OperandTraits<AtomicRMWInst>::operands(this) && \"setOperand() out of range!\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 820, __extension__ __PRETTY_FUNCTION__)); OperandTraits<
AtomicRMWInst>::op_begin(this)[i_nocapture] = Val_nocapture
; } unsigned AtomicRMWInst::getNumOperands() const { return OperandTraits
<AtomicRMWInst>::operands(this); } template <int Idx_nocapture
> Use &AtomicRMWInst::Op() { return this->OpFrom<
Idx_nocapture>(this); } template <int Idx_nocapture>
const Use &AtomicRMWInst::Op() const { return this->OpFrom
<Idx_nocapture>(this); }
821
822//===----------------------------------------------------------------------===//
823// GetElementPtrInst Class
824//===----------------------------------------------------------------------===//
825
826// checkGEPType - Simple wrapper function to give a better assertion failure
827// message on bad indexes for a gep instruction.
828//
829inline Type *checkGEPType(Type *Ty) {
830 assert(Ty && "Invalid GetElementPtrInst indices for type!")(static_cast <bool> (Ty && "Invalid GetElementPtrInst indices for type!"
) ? void (0) : __assert_fail ("Ty && \"Invalid GetElementPtrInst indices for type!\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 830, __extension__ __PRETTY_FUNCTION__))
;
831 return Ty;
832}
833
834/// an instruction for type-safe pointer arithmetic to
835/// access elements of arrays and structs
836///
837class GetElementPtrInst : public Instruction {
838 Type *SourceElementType;
839 Type *ResultElementType;
840
841 GetElementPtrInst(const GetElementPtrInst &GEPI);
842
843 /// Constructors - Create a getelementptr instruction with a base pointer an
844 /// list of indices. The first ctor can optionally insert before an existing
845 /// instruction, the second appends the new instruction to the specified
846 /// BasicBlock.
847 inline GetElementPtrInst(Type *PointeeType, Value *Ptr,
848 ArrayRef<Value *> IdxList, unsigned Values,
849 const Twine &NameStr, Instruction *InsertBefore);
850 inline GetElementPtrInst(Type *PointeeType, Value *Ptr,
851 ArrayRef<Value *> IdxList, unsigned Values,
852 const Twine &NameStr, BasicBlock *InsertAtEnd);
853
854 void init(Value *Ptr, ArrayRef<Value *> IdxList, const Twine &NameStr);
855
856protected:
857 // Note: Instruction needs to be a friend here to call cloneImpl.
858 friend class Instruction;
859
860 GetElementPtrInst *cloneImpl() const;
861
862public:
863 static GetElementPtrInst *Create(Type *PointeeType, Value *Ptr,
864 ArrayRef<Value *> IdxList,
865 const Twine &NameStr = "",
866 Instruction *InsertBefore = nullptr) {
867 unsigned Values = 1 + unsigned(IdxList.size());
868 if (!PointeeType)
869 PointeeType =
870 cast<PointerType>(Ptr->getType()->getScalarType())->getElementType();
871 else
872 assert((static_cast <bool> (PointeeType == cast<PointerType
>(Ptr->getType()->getScalarType())->getElementType
()) ? void (0) : __assert_fail ("PointeeType == cast<PointerType>(Ptr->getType()->getScalarType())->getElementType()"
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 874, __extension__ __PRETTY_FUNCTION__))
873 PointeeType ==(static_cast <bool> (PointeeType == cast<PointerType
>(Ptr->getType()->getScalarType())->getElementType
()) ? void (0) : __assert_fail ("PointeeType == cast<PointerType>(Ptr->getType()->getScalarType())->getElementType()"
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 874, __extension__ __PRETTY_FUNCTION__))
874 cast<PointerType>(Ptr->getType()->getScalarType())->getElementType())(static_cast <bool> (PointeeType == cast<PointerType
>(Ptr->getType()->getScalarType())->getElementType
()) ? void (0) : __assert_fail ("PointeeType == cast<PointerType>(Ptr->getType()->getScalarType())->getElementType()"
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 874, __extension__ __PRETTY_FUNCTION__))
;
875 return new (Values) GetElementPtrInst(PointeeType, Ptr, IdxList, Values,
876 NameStr, InsertBefore);
877 }
878
879 static GetElementPtrInst *Create(Type *PointeeType, Value *Ptr,
880 ArrayRef<Value *> IdxList,
881 const Twine &NameStr,
882 BasicBlock *InsertAtEnd) {
883 unsigned Values = 1 + unsigned(IdxList.size());
884 if (!PointeeType)
885 PointeeType =
886 cast<PointerType>(Ptr->getType()->getScalarType())->getElementType();
887 else
888 assert((static_cast <bool> (PointeeType == cast<PointerType
>(Ptr->getType()->getScalarType())->getElementType
()) ? void (0) : __assert_fail ("PointeeType == cast<PointerType>(Ptr->getType()->getScalarType())->getElementType()"
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 890, __extension__ __PRETTY_FUNCTION__))
889 PointeeType ==(static_cast <bool> (PointeeType == cast<PointerType
>(Ptr->getType()->getScalarType())->getElementType
()) ? void (0) : __assert_fail ("PointeeType == cast<PointerType>(Ptr->getType()->getScalarType())->getElementType()"
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 890, __extension__ __PRETTY_FUNCTION__))
890 cast<PointerType>(Ptr->getType()->getScalarType())->getElementType())(static_cast <bool> (PointeeType == cast<PointerType
>(Ptr->getType()->getScalarType())->getElementType
()) ? void (0) : __assert_fail ("PointeeType == cast<PointerType>(Ptr->getType()->getScalarType())->getElementType()"
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 890, __extension__ __PRETTY_FUNCTION__))
;
891 return new (Values) GetElementPtrInst(PointeeType, Ptr, IdxList, Values,
892 NameStr, InsertAtEnd);
893 }
894
895 /// Create an "inbounds" getelementptr. See the documentation for the
896 /// "inbounds" flag in LangRef.html for details.
897 static GetElementPtrInst *CreateInBounds(Value *Ptr,
898 ArrayRef<Value *> IdxList,
899 const Twine &NameStr = "",
900 Instruction *InsertBefore = nullptr){
901 return CreateInBounds(nullptr, Ptr, IdxList, NameStr, InsertBefore);
902 }
903
904 static GetElementPtrInst *
905 CreateInBounds(Type *PointeeType, Value *Ptr, ArrayRef<Value *> IdxList,
906 const Twine &NameStr = "",
907 Instruction *InsertBefore = nullptr) {
908 GetElementPtrInst *GEP =
909 Create(PointeeType, Ptr, IdxList, NameStr, InsertBefore);
910 GEP->setIsInBounds(true);
911 return GEP;
912 }
913
914 static GetElementPtrInst *CreateInBounds(Value *Ptr,
915 ArrayRef<Value *> IdxList,
916 const Twine &NameStr,
917 BasicBlock *InsertAtEnd) {
918 return CreateInBounds(nullptr, Ptr, IdxList, NameStr, InsertAtEnd);
919 }
920
921 static GetElementPtrInst *CreateInBounds(Type *PointeeType, Value *Ptr,
922 ArrayRef<Value *> IdxList,
923 const Twine &NameStr,
924 BasicBlock *InsertAtEnd) {
925 GetElementPtrInst *GEP =
926 Create(PointeeType, Ptr, IdxList, NameStr, InsertAtEnd);
927 GEP->setIsInBounds(true);
928 return GEP;
929 }
930
931 /// Transparently provide more efficient getOperand methods.
932 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)public: inline Value *getOperand(unsigned) const; inline void
setOperand(unsigned, Value*); inline op_iterator op_begin();
inline const_op_iterator op_begin() const; inline op_iterator
op_end(); inline const_op_iterator op_end() const; protected
: template <int> inline Use &Op(); template <int
> inline const Use &Op() const; public: inline unsigned
getNumOperands() const
;
933
934 Type *getSourceElementType() const { return SourceElementType; }
935
936 void setSourceElementType(Type *Ty) { SourceElementType = Ty; }
937 void setResultElementType(Type *Ty) { ResultElementType = Ty; }
938
939 Type *getResultElementType() const {
940 assert(ResultElementType ==(static_cast <bool> (ResultElementType == cast<PointerType
>(getType()->getScalarType())->getElementType()) ? void
(0) : __assert_fail ("ResultElementType == cast<PointerType>(getType()->getScalarType())->getElementType()"
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 941, __extension__ __PRETTY_FUNCTION__))
941 cast<PointerType>(getType()->getScalarType())->getElementType())(static_cast <bool> (ResultElementType == cast<PointerType
>(getType()->getScalarType())->getElementType()) ? void
(0) : __assert_fail ("ResultElementType == cast<PointerType>(getType()->getScalarType())->getElementType()"
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 941, __extension__ __PRETTY_FUNCTION__))
;
942 return ResultElementType;
943 }
944
945 /// Returns the address space of this instruction's pointer type.
946 unsigned getAddressSpace() const {
947 // Note that this is always the same as the pointer operand's address space
948 // and that is cheaper to compute, so cheat here.
949 return getPointerAddressSpace();
950 }
951
952 /// Returns the type of the element that would be loaded with
953 /// a load instruction with the specified parameters.
954 ///
955 /// Null is returned if the indices are invalid for the specified
956 /// pointer type.
957 ///
958 static Type *getIndexedType(Type *Ty, ArrayRef<Value *> IdxList);
959 static Type *getIndexedType(Type *Ty, ArrayRef<Constant *> IdxList);
960 static Type *getIndexedType(Type *Ty, ArrayRef<uint64_t> IdxList);
961
962 inline op_iterator idx_begin() { return op_begin()+1; }
963 inline const_op_iterator idx_begin() const { return op_begin()+1; }
964 inline op_iterator idx_end() { return op_end(); }
965 inline const_op_iterator idx_end() const { return op_end(); }
966
967 inline iterator_range<op_iterator> indices() {
968 return make_range(idx_begin(), idx_end());
969 }
970
971 inline iterator_range<const_op_iterator> indices() const {
972 return make_range(idx_begin(), idx_end());
973 }
974
975 Value *getPointerOperand() {
976 return getOperand(0);
977 }
978 const Value *getPointerOperand() const {
979 return getOperand(0);
980 }
981 static unsigned getPointerOperandIndex() {
982 return 0U; // get index for modifying correct operand.
983 }
984
985 /// Method to return the pointer operand as a
986 /// PointerType.
987 Type *getPointerOperandType() const {
988 return getPointerOperand()->getType();
989 }
990
991 /// Returns the address space of the pointer operand.
992 unsigned getPointerAddressSpace() const {
993 return getPointerOperandType()->getPointerAddressSpace();
994 }
995
996 /// Returns the pointer type returned by the GEP
997 /// instruction, which may be a vector of pointers.
998 static Type *getGEPReturnType(Value *Ptr, ArrayRef<Value *> IdxList) {
999 return getGEPReturnType(
1000 cast<PointerType>(Ptr->getType()->getScalarType())->getElementType(),
1001 Ptr, IdxList);
1002 }
1003 static Type *getGEPReturnType(Type *ElTy, Value *Ptr,
1004 ArrayRef<Value *> IdxList) {
1005 Type *PtrTy = PointerType::get(checkGEPType(getIndexedType(ElTy, IdxList)),
1006 Ptr->getType()->getPointerAddressSpace());
1007 // Vector GEP
1008 if (Ptr->getType()->isVectorTy()) {
1009 unsigned NumElem = Ptr->getType()->getVectorNumElements();
1010 return VectorType::get(PtrTy, NumElem);
1011 }
1012 for (Value *Index : IdxList)
1013 if (Index->getType()->isVectorTy()) {
1014 unsigned NumElem = Index->getType()->getVectorNumElements();
1015 return VectorType::get(PtrTy, NumElem);
1016 }
1017 // Scalar GEP
1018 return PtrTy;
1019 }
1020
1021 unsigned getNumIndices() const { // Note: always non-negative
1022 return getNumOperands() - 1;
1023 }
1024
1025 bool hasIndices() const {
1026 return getNumOperands() > 1;
1027 }
1028
1029 /// Return true if all of the indices of this GEP are
1030 /// zeros. If so, the result pointer and the first operand have the same
1031 /// value, just potentially different types.
1032 bool hasAllZeroIndices() const;
1033
1034 /// Return true if all of the indices of this GEP are
1035 /// constant integers. If so, the result pointer and the first operand have
1036 /// a constant offset between them.
1037 bool hasAllConstantIndices() const;
1038
1039 /// Set or clear the inbounds flag on this GEP instruction.
1040 /// See LangRef.html for the meaning of inbounds on a getelementptr.
1041 void setIsInBounds(bool b = true);
1042
1043 /// Determine whether the GEP has the inbounds flag.
1044 bool isInBounds() const;
1045
1046 /// Accumulate the constant address offset of this GEP if possible.
1047 ///
1048 /// This routine accepts an APInt into which it will accumulate the constant
1049 /// offset of this GEP if the GEP is in fact constant. If the GEP is not
1050 /// all-constant, it returns false and the value of the offset APInt is
1051 /// undefined (it is *not* preserved!). The APInt passed into this routine
1052 /// must be at least as wide as the IntPtr type for the address space of
1053 /// the base GEP pointer.
1054 bool accumulateConstantOffset(const DataLayout &DL, APInt &Offset) const;
1055
1056 // Methods for support type inquiry through isa, cast, and dyn_cast:
1057 static bool classof(const Instruction *I) {
1058 return (I->getOpcode() == Instruction::GetElementPtr);
1059 }
1060 static bool classof(const Value *V) {
1061 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1062 }
1063};
1064
1065template <>
1066struct OperandTraits<GetElementPtrInst> :
1067 public VariadicOperandTraits<GetElementPtrInst, 1> {
1068};
1069
1070GetElementPtrInst::GetElementPtrInst(Type *PointeeType, Value *Ptr,
1071 ArrayRef<Value *> IdxList, unsigned Values,
1072 const Twine &NameStr,
1073 Instruction *InsertBefore)
1074 : Instruction(getGEPReturnType(PointeeType, Ptr, IdxList), GetElementPtr,
1075 OperandTraits<GetElementPtrInst>::op_end(this) - Values,
1076 Values, InsertBefore),
1077 SourceElementType(PointeeType),
1078 ResultElementType(getIndexedType(PointeeType, IdxList)) {
1079 assert(ResultElementType ==(static_cast <bool> (ResultElementType == cast<PointerType
>(getType()->getScalarType())->getElementType()) ? void
(0) : __assert_fail ("ResultElementType == cast<PointerType>(getType()->getScalarType())->getElementType()"
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 1080, __extension__ __PRETTY_FUNCTION__))
1080 cast<PointerType>(getType()->getScalarType())->getElementType())(static_cast <bool> (ResultElementType == cast<PointerType
>(getType()->getScalarType())->getElementType()) ? void
(0) : __assert_fail ("ResultElementType == cast<PointerType>(getType()->getScalarType())->getElementType()"
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 1080, __extension__ __PRETTY_FUNCTION__))
;
1081 init(Ptr, IdxList, NameStr);
1082}
1083
1084GetElementPtrInst::GetElementPtrInst(Type *PointeeType, Value *Ptr,
1085 ArrayRef<Value *> IdxList, unsigned Values,
1086 const Twine &NameStr,
1087 BasicBlock *InsertAtEnd)
1088 : Instruction(getGEPReturnType(PointeeType, Ptr, IdxList), GetElementPtr,
1089 OperandTraits<GetElementPtrInst>::op_end(this) - Values,
1090 Values, InsertAtEnd),
1091 SourceElementType(PointeeType),
1092 ResultElementType(getIndexedType(PointeeType, IdxList)) {
1093 assert(ResultElementType ==(static_cast <bool> (ResultElementType == cast<PointerType
>(getType()->getScalarType())->getElementType()) ? void
(0) : __assert_fail ("ResultElementType == cast<PointerType>(getType()->getScalarType())->getElementType()"
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 1094, __extension__ __PRETTY_FUNCTION__))
1094 cast<PointerType>(getType()->getScalarType())->getElementType())(static_cast <bool> (ResultElementType == cast<PointerType
>(getType()->getScalarType())->getElementType()) ? void
(0) : __assert_fail ("ResultElementType == cast<PointerType>(getType()->getScalarType())->getElementType()"
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 1094, __extension__ __PRETTY_FUNCTION__))
;
1095 init(Ptr, IdxList, NameStr);
1096}
1097
1098DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GetElementPtrInst, Value)GetElementPtrInst::op_iterator GetElementPtrInst::op_begin() {
return OperandTraits<GetElementPtrInst>::op_begin(this
); } GetElementPtrInst::const_op_iterator GetElementPtrInst::
op_begin() const { return OperandTraits<GetElementPtrInst>
::op_begin(const_cast<GetElementPtrInst*>(this)); } GetElementPtrInst
::op_iterator GetElementPtrInst::op_end() { return OperandTraits
<GetElementPtrInst>::op_end(this); } GetElementPtrInst::
const_op_iterator GetElementPtrInst::op_end() const { return OperandTraits
<GetElementPtrInst>::op_end(const_cast<GetElementPtrInst
*>(this)); } Value *GetElementPtrInst::getOperand(unsigned
i_nocapture) const { (static_cast <bool> (i_nocapture <
OperandTraits<GetElementPtrInst>::operands(this) &&
"getOperand() out of range!") ? void (0) : __assert_fail ("i_nocapture < OperandTraits<GetElementPtrInst>::operands(this) && \"getOperand() out of range!\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 1098, __extension__ __PRETTY_FUNCTION__)); return cast_or_null
<Value>( OperandTraits<GetElementPtrInst>::op_begin
(const_cast<GetElementPtrInst*>(this))[i_nocapture].get
()); } void GetElementPtrInst::setOperand(unsigned i_nocapture
, Value *Val_nocapture) { (static_cast <bool> (i_nocapture
< OperandTraits<GetElementPtrInst>::operands(this) &&
"setOperand() out of range!") ? void (0) : __assert_fail ("i_nocapture < OperandTraits<GetElementPtrInst>::operands(this) && \"setOperand() out of range!\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 1098, __extension__ __PRETTY_FUNCTION__)); OperandTraits<
GetElementPtrInst>::op_begin(this)[i_nocapture] = Val_nocapture
; } unsigned GetElementPtrInst::getNumOperands() const { return
OperandTraits<GetElementPtrInst>::operands(this); } template
<int Idx_nocapture> Use &GetElementPtrInst::Op() {
return this->OpFrom<Idx_nocapture>(this); } template
<int Idx_nocapture> const Use &GetElementPtrInst::
Op() const { return this->OpFrom<Idx_nocapture>(this
); }
1099
1100//===----------------------------------------------------------------------===//
1101// ICmpInst Class
1102//===----------------------------------------------------------------------===//
1103
1104/// This instruction compares its operands according to the predicate given
1105/// to the constructor. It only operates on integers or pointers. The operands
1106/// must be identical types.
1107/// Represent an integer comparison operator.
1108class ICmpInst: public CmpInst {
1109 void AssertOK() {
1110 assert(isIntPredicate() &&(static_cast <bool> (isIntPredicate() && "Invalid ICmp predicate value"
) ? void (0) : __assert_fail ("isIntPredicate() && \"Invalid ICmp predicate value\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 1111, __extension__ __PRETTY_FUNCTION__))
1111 "Invalid ICmp predicate value")(static_cast <bool> (isIntPredicate() && "Invalid ICmp predicate value"
) ? void (0) : __assert_fail ("isIntPredicate() && \"Invalid ICmp predicate value\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 1111, __extension__ __PRETTY_FUNCTION__))
;
1112 assert(getOperand(0)->getType() == getOperand(1)->getType() &&(static_cast <bool> (getOperand(0)->getType() == getOperand
(1)->getType() && "Both operands to ICmp instruction are not of the same type!"
) ? void (0) : __assert_fail ("getOperand(0)->getType() == getOperand(1)->getType() && \"Both operands to ICmp instruction are not of the same type!\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 1113, __extension__ __PRETTY_FUNCTION__))
1113 "Both operands to ICmp instruction are not of the same type!")(static_cast <bool> (getOperand(0)->getType() == getOperand
(1)->getType() && "Both operands to ICmp instruction are not of the same type!"
) ? void (0) : __assert_fail ("getOperand(0)->getType() == getOperand(1)->getType() && \"Both operands to ICmp instruction are not of the same type!\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 1113, __extension__ __PRETTY_FUNCTION__))
;
1114 // Check that the operands are the right type
1115 assert((getOperand(0)->getType()->isIntOrIntVectorTy() ||(static_cast <bool> ((getOperand(0)->getType()->isIntOrIntVectorTy
() || getOperand(0)->getType()->isPtrOrPtrVectorTy()) &&
"Invalid operand types for ICmp instruction") ? void (0) : __assert_fail
("(getOperand(0)->getType()->isIntOrIntVectorTy() || getOperand(0)->getType()->isPtrOrPtrVectorTy()) && \"Invalid operand types for ICmp instruction\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 1117, __extension__ __PRETTY_FUNCTION__))
1116 getOperand(0)->getType()->isPtrOrPtrVectorTy()) &&(static_cast <bool> ((getOperand(0)->getType()->isIntOrIntVectorTy
() || getOperand(0)->getType()->isPtrOrPtrVectorTy()) &&
"Invalid operand types for ICmp instruction") ? void (0) : __assert_fail
("(getOperand(0)->getType()->isIntOrIntVectorTy() || getOperand(0)->getType()->isPtrOrPtrVectorTy()) && \"Invalid operand types for ICmp instruction\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 1117, __extension__ __PRETTY_FUNCTION__))
1117 "Invalid operand types for ICmp instruction")(static_cast <bool> ((getOperand(0)->getType()->isIntOrIntVectorTy
() || getOperand(0)->getType()->isPtrOrPtrVectorTy()) &&
"Invalid operand types for ICmp instruction") ? void (0) : __assert_fail
("(getOperand(0)->getType()->isIntOrIntVectorTy() || getOperand(0)->getType()->isPtrOrPtrVectorTy()) && \"Invalid operand types for ICmp instruction\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 1117, __extension__ __PRETTY_FUNCTION__))
;
1118 }
1119
1120protected:
1121 // Note: Instruction needs to be a friend here to call cloneImpl.
1122 friend class Instruction;
1123
1124 /// Clone an identical ICmpInst
1125 ICmpInst *cloneImpl() const;
1126
1127public:
1128 /// Constructor with insert-before-instruction semantics.
1129 ICmpInst(
1130 Instruction *InsertBefore, ///< Where to insert
1131 Predicate pred, ///< The predicate to use for the comparison
1132 Value *LHS, ///< The left-hand-side of the expression
1133 Value *RHS, ///< The right-hand-side of the expression
1134 const Twine &NameStr = "" ///< Name of the instruction
1135 ) : CmpInst(makeCmpResultType(LHS->getType()),
1136 Instruction::ICmp, pred, LHS, RHS, NameStr,
1137 InsertBefore) {
1138#ifndef NDEBUG
1139 AssertOK();
1140#endif
1141 }
1142
1143 /// Constructor with insert-at-end semantics.
1144 ICmpInst(
1145 BasicBlock &InsertAtEnd, ///< Block to insert into.
1146 Predicate pred, ///< The predicate to use for the comparison
1147 Value *LHS, ///< The left-hand-side of the expression
1148 Value *RHS, ///< The right-hand-side of the expression
1149 const Twine &NameStr = "" ///< Name of the instruction
1150 ) : CmpInst(makeCmpResultType(LHS->getType()),
1151 Instruction::ICmp, pred, LHS, RHS, NameStr,
1152 &InsertAtEnd) {
1153#ifndef NDEBUG
1154 AssertOK();
1155#endif
1156 }
1157
1158 /// Constructor with no-insertion semantics
1159 ICmpInst(
1160 Predicate pred, ///< The predicate to use for the comparison
1161 Value *LHS, ///< The left-hand-side of the expression
1162 Value *RHS, ///< The right-hand-side of the expression
1163 const Twine &NameStr = "" ///< Name of the instruction
1164 ) : CmpInst(makeCmpResultType(LHS->getType()),
1165 Instruction::ICmp, pred, LHS, RHS, NameStr) {
1166#ifndef NDEBUG
1167 AssertOK();
1168#endif
1169 }
1170
1171 /// For example, EQ->EQ, SLE->SLE, UGT->SGT, etc.
1172 /// @returns the predicate that would be the result if the operand were
1173 /// regarded as signed.
1174 /// Return the signed version of the predicate
1175 Predicate getSignedPredicate() const {
1176 return getSignedPredicate(getPredicate());
1177 }
1178
1179 /// This is a static version that you can use without an instruction.
1180 /// Return the signed version of the predicate.
1181 static Predicate getSignedPredicate(Predicate pred);
1182
1183 /// For example, EQ->EQ, SLE->ULE, UGT->UGT, etc.
1184 /// @returns the predicate that would be the result if the operand were
1185 /// regarded as unsigned.
1186 /// Return the unsigned version of the predicate
1187 Predicate getUnsignedPredicate() const {
1188 return getUnsignedPredicate(getPredicate());
1189 }
1190
1191 /// This is a static version that you can use without an instruction.
1192 /// Return the unsigned version of the predicate.
1193 static Predicate getUnsignedPredicate(Predicate pred);
1194
1195 /// Return true if this predicate is either EQ or NE. This also
1196 /// tests for commutativity.
1197 static bool isEquality(Predicate P) {
1198 return P == ICMP_EQ || P == ICMP_NE;
1199 }
1200
1201 /// Return true if this predicate is either EQ or NE. This also
1202 /// tests for commutativity.
1203 bool isEquality() const {
1204 return isEquality(getPredicate());
1205 }
1206
1207 /// @returns true if the predicate of this ICmpInst is commutative
1208 /// Determine if this relation is commutative.
1209 bool isCommutative() const { return isEquality(); }
1210
1211 /// Return true if the predicate is relational (not EQ or NE).
1212 ///
1213 bool isRelational() const {
1214 return !isEquality();
1215 }
1216
1217 /// Return true if the predicate is relational (not EQ or NE).
1218 ///
1219 static bool isRelational(Predicate P) {
1220 return !isEquality(P);
1221 }
1222
1223 /// Exchange the two operands to this instruction in such a way that it does
1224 /// not modify the semantics of the instruction. The predicate value may be
1225 /// changed to retain the same result if the predicate is order dependent
1226 /// (e.g. ult).
1227 /// Swap operands and adjust predicate.
1228 void swapOperands() {
1229 setPredicate(getSwappedPredicate());
1230 Op<0>().swap(Op<1>());
1231 }
1232
1233 // Methods for support type inquiry through isa, cast, and dyn_cast:
1234 static bool classof(const Instruction *I) {
1235 return I->getOpcode() == Instruction::ICmp;
1236 }
1237 static bool classof(const Value *V) {
1238 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1239 }
1240};
1241
1242//===----------------------------------------------------------------------===//
1243// FCmpInst Class
1244//===----------------------------------------------------------------------===//
1245
1246/// This instruction compares its operands according to the predicate given
1247/// to the constructor. It only operates on floating point values or packed
1248/// vectors of floating point values. The operands must be identical types.
1249/// Represents a floating point comparison operator.
1250class FCmpInst: public CmpInst {
1251 void AssertOK() {
1252 assert(isFPPredicate() && "Invalid FCmp predicate value")(static_cast <bool> (isFPPredicate() && "Invalid FCmp predicate value"
) ? void (0) : __assert_fail ("isFPPredicate() && \"Invalid FCmp predicate value\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 1252, __extension__ __PRETTY_FUNCTION__))
;
1253 assert(getOperand(0)->getType() == getOperand(1)->getType() &&(static_cast <bool> (getOperand(0)->getType() == getOperand
(1)->getType() && "Both operands to FCmp instruction are not of the same type!"
) ? void (0) : __assert_fail ("getOperand(0)->getType() == getOperand(1)->getType() && \"Both operands to FCmp instruction are not of the same type!\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 1254, __extension__ __PRETTY_FUNCTION__))
1254 "Both operands to FCmp instruction are not of the same type!")(static_cast <bool> (getOperand(0)->getType() == getOperand
(1)->getType() && "Both operands to FCmp instruction are not of the same type!"
) ? void (0) : __assert_fail ("getOperand(0)->getType() == getOperand(1)->getType() && \"Both operands to FCmp instruction are not of the same type!\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 1254, __extension__ __PRETTY_FUNCTION__))
;
1255 // Check that the operands are the right type
1256 assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&(static_cast <bool> (getOperand(0)->getType()->isFPOrFPVectorTy
() && "Invalid operand types for FCmp instruction") ?
void (0) : __assert_fail ("getOperand(0)->getType()->isFPOrFPVectorTy() && \"Invalid operand types for FCmp instruction\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 1257, __extension__ __PRETTY_FUNCTION__))
1257 "Invalid operand types for FCmp instruction")(static_cast <bool> (getOperand(0)->getType()->isFPOrFPVectorTy
() && "Invalid operand types for FCmp instruction") ?
void (0) : __assert_fail ("getOperand(0)->getType()->isFPOrFPVectorTy() && \"Invalid operand types for FCmp instruction\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 1257, __extension__ __PRETTY_FUNCTION__))
;
1258 }
1259
1260protected:
1261 // Note: Instruction needs to be a friend here to call cloneImpl.
1262 friend class Instruction;
1263
1264 /// Clone an identical FCmpInst
1265 FCmpInst *cloneImpl() const;
1266
1267public:
1268 /// Constructor with insert-before-instruction semantics.
1269 FCmpInst(
1270 Instruction *InsertBefore, ///< Where to insert
1271 Predicate pred, ///< The predicate to use for the comparison
1272 Value *LHS, ///< The left-hand-side of the expression
1273 Value *RHS, ///< The right-hand-side of the expression
1274 const Twine &NameStr = "" ///< Name of the instruction
1275 ) : CmpInst(makeCmpResultType(LHS->getType()),
1276 Instruction::FCmp, pred, LHS, RHS, NameStr,
1277 InsertBefore) {
1278 AssertOK();
1279 }
1280
1281 /// Constructor with insert-at-end semantics.
1282 FCmpInst(
1283 BasicBlock &InsertAtEnd, ///< Block to insert into.
1284 Predicate pred, ///< The predicate to use for the comparison
1285 Value *LHS, ///< The left-hand-side of the expression
1286 Value *RHS, ///< The right-hand-side of the expression
1287 const Twine &NameStr = "" ///< Name of the instruction
1288 ) : CmpInst(makeCmpResultType(LHS->getType()),
1289 Instruction::FCmp, pred, LHS, RHS, NameStr,
1290 &InsertAtEnd) {
1291 AssertOK();
1292 }
1293
1294 /// Constructor with no-insertion semantics
1295 FCmpInst(
1296 Predicate pred, ///< The predicate to use for the comparison
1297 Value *LHS, ///< The left-hand-side of the expression
1298 Value *RHS, ///< The right-hand-side of the expression
1299 const Twine &NameStr = "" ///< Name of the instruction
1300 ) : CmpInst(makeCmpResultType(LHS->getType()),
1301 Instruction::FCmp, pred, LHS, RHS, NameStr) {
1302 AssertOK();
1303 }
1304
1305 /// @returns true if the predicate of this instruction is EQ or NE.
1306 /// Determine if this is an equality predicate.
1307 static bool isEquality(Predicate Pred) {
1308 return Pred == FCMP_OEQ || Pred == FCMP_ONE || Pred == FCMP_UEQ ||
1309 Pred == FCMP_UNE;
1310 }
1311
1312 /// @returns true if the predicate of this instruction is EQ or NE.
1313 /// Determine if this is an equality predicate.
1314 bool isEquality() const { return isEquality(getPredicate()); }
1315
1316 /// @returns true if the predicate of this instruction is commutative.
1317 /// Determine if this is a commutative predicate.
1318 bool isCommutative() const {
1319 return isEquality() ||
1320 getPredicate() == FCMP_FALSE ||
1321 getPredicate() == FCMP_TRUE ||
1322 getPredicate() == FCMP_ORD ||
1323 getPredicate() == FCMP_UNO;
1324 }
1325
1326 /// @returns true if the predicate is relational (not EQ or NE).
1327 /// Determine if this a relational predicate.
1328 bool isRelational() const { return !isEquality(); }
1329
1330 /// Exchange the two operands to this instruction in such a way that it does
1331 /// not modify the semantics of the instruction. The predicate value may be
1332 /// changed to retain the same result if the predicate is order dependent
1333 /// (e.g. ult).
1334 /// Swap operands and adjust predicate.
1335 void swapOperands() {
1336 setPredicate(getSwappedPredicate());
1337 Op<0>().swap(Op<1>());
1338 }
1339
1340 /// Methods for support type inquiry through isa, cast, and dyn_cast:
1341 static bool classof(const Instruction *I) {
1342 return I->getOpcode() == Instruction::FCmp;
1343 }
1344 static bool classof(const Value *V) {
1345 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1346 }
1347};
1348
1349//===----------------------------------------------------------------------===//
1350/// This class represents a function call, abstracting a target
1351/// machine's calling convention. This class uses low bit of the SubClassData
1352/// field to indicate whether or not this is a tail call. The rest of the bits
1353/// hold the calling convention of the call.
1354///
1355class CallInst : public Instruction,
1356 public OperandBundleUser<CallInst, User::op_iterator> {
1357 friend class OperandBundleUser<CallInst, User::op_iterator>;
1358
1359 AttributeList Attrs; ///< parameter attributes for call
1360 FunctionType *FTy;
1361
1362 CallInst(const CallInst &CI);
1363
1364 /// Construct a CallInst given a range of arguments.
1365 /// Construct a CallInst from a range of arguments
1366 inline CallInst(FunctionType *Ty, Value *Func, ArrayRef<Value *> Args,
1367 ArrayRef<OperandBundleDef> Bundles, const Twine &NameStr,
1368 Instruction *InsertBefore);
1369
1370 inline CallInst(Value *Func, ArrayRef<Value *> Args,
1371 ArrayRef<OperandBundleDef> Bundles, const Twine &NameStr,
1372 Instruction *InsertBefore)
1373 : CallInst(cast<FunctionType>(
1374 cast<PointerType>(Func->getType())->getElementType()),
1375 Func, Args, Bundles, NameStr, InsertBefore) {}
1376
1377 inline CallInst(Value *Func, ArrayRef<Value *> Args, const Twine &NameStr,
1378 Instruction *InsertBefore)
1379 : CallInst(Func, Args, None, NameStr, InsertBefore) {}
1380
1381 /// Construct a CallInst given a range of arguments.
1382 /// Construct a CallInst from a range of arguments
1383 inline CallInst(Value *Func, ArrayRef<Value *> Args,
1384 ArrayRef<OperandBundleDef> Bundles, const Twine &NameStr,
1385 BasicBlock *InsertAtEnd);
1386
1387 explicit CallInst(Value *F, const Twine &NameStr,
1388 Instruction *InsertBefore);
1389
1390 CallInst(Value *F, const Twine &NameStr, BasicBlock *InsertAtEnd);
1391
1392 void init(Value *Func, ArrayRef<Value *> Args,
1393 ArrayRef<OperandBundleDef> Bundles, const Twine &NameStr) {
1394 init(cast<FunctionType>(
1395 cast<PointerType>(Func->getType())->getElementType()),
1396 Func, Args, Bundles, NameStr);
1397 }
1398 void init(FunctionType *FTy, Value *Func, ArrayRef<Value *> Args,
1399 ArrayRef<OperandBundleDef> Bundles, const Twine &NameStr);
1400 void init(Value *Func, const Twine &NameStr);
1401
1402 bool hasDescriptor() const { return HasDescriptor; }
1403
1404protected:
1405 // Note: Instruction needs to be a friend here to call cloneImpl.
1406 friend class Instruction;
1407
1408 CallInst *cloneImpl() const;
1409
1410public:
1411 static CallInst *Create(Value *Func, ArrayRef<Value *> Args,
1412 ArrayRef<OperandBundleDef> Bundles = None,
1413 const Twine &NameStr = "",
1414 Instruction *InsertBefore = nullptr) {
1415 return Create(cast<FunctionType>(
1416 cast<PointerType>(Func->getType())->getElementType()),
1417 Func, Args, Bundles, NameStr, InsertBefore);
1418 }
1419
1420 static CallInst *Create(Value *Func, ArrayRef<Value *> Args,
1421 const Twine &NameStr,
1422 Instruction *InsertBefore = nullptr) {
1423 return Create(cast<FunctionType>(
1424 cast<PointerType>(Func->getType())->getElementType()),
1425 Func, Args, None, NameStr, InsertBefore);
1426 }
1427
1428 static CallInst *Create(FunctionType *Ty, Value *Func, ArrayRef<Value *> Args,
1429 const Twine &NameStr,
1430 Instruction *InsertBefore = nullptr) {
1431 return new (unsigned(Args.size() + 1))
1432 CallInst(Ty, Func, Args, None, NameStr, InsertBefore);
1433 }
1434
1435 static CallInst *Create(FunctionType *Ty, Value *Func, ArrayRef<Value *> Args,
1436 ArrayRef<OperandBundleDef> Bundles = None,
1437 const Twine &NameStr = "",
1438 Instruction *InsertBefore = nullptr) {
1439 const unsigned TotalOps =
1440 unsigned(Args.size()) + CountBundleInputs(Bundles) + 1;
1441 const unsigned DescriptorBytes = Bundles.size() * sizeof(BundleOpInfo);
1442
1443 return new (TotalOps, DescriptorBytes)
1444 CallInst(Ty, Func, Args, Bundles, NameStr, InsertBefore);
1445 }
1446
1447 static CallInst *Create(Value *Func, ArrayRef<Value *> Args,
1448 ArrayRef<OperandBundleDef> Bundles,
1449 const Twine &NameStr, BasicBlock *InsertAtEnd) {
1450 const unsigned TotalOps =
1451 unsigned(Args.size()) + CountBundleInputs(Bundles) + 1;
1452 const unsigned DescriptorBytes = Bundles.size() * sizeof(BundleOpInfo);
1453
1454 return new (TotalOps, DescriptorBytes)
1455 CallInst(Func, Args, Bundles, NameStr, InsertAtEnd);
1456 }
1457
1458 static CallInst *Create(Value *Func, ArrayRef<Value *> Args,
1459 const Twine &NameStr, BasicBlock *InsertAtEnd) {
1460 return new (unsigned(Args.size() + 1))
1461 CallInst(Func, Args, None, NameStr, InsertAtEnd);
1462 }
1463
1464 static CallInst *Create(Value *F, const Twine &NameStr = "",
1465 Instruction *InsertBefore = nullptr) {
1466 return new(1) CallInst(F, NameStr, InsertBefore);
1467 }
1468
1469 static CallInst *Create(Value *F, const Twine &NameStr,
1470 BasicBlock *InsertAtEnd) {
1471 return new(1) CallInst(F, NameStr, InsertAtEnd);
1472 }
1473
1474 /// Create a clone of \p CI with a different set of operand bundles and
1475 /// insert it before \p InsertPt.
1476 ///
1477 /// The returned call instruction is identical \p CI in every way except that
1478 /// the operand bundles for the new instruction are set to the operand bundles
1479 /// in \p Bundles.
1480 static CallInst *Create(CallInst *CI, ArrayRef<OperandBundleDef> Bundles,
1481 Instruction *InsertPt = nullptr);
1482
1483 /// Generate the IR for a call to malloc:
1484 /// 1. Compute the malloc call's argument as the specified type's size,
1485 /// possibly multiplied by the array size if the array size is not
1486 /// constant 1.
1487 /// 2. Call malloc with that argument.
1488 /// 3. Bitcast the result of the malloc call to the specified type.
1489 static Instruction *CreateMalloc(Instruction *InsertBefore,
1490 Type *IntPtrTy, Type *AllocTy,
1491 Value *AllocSize, Value *ArraySize = nullptr,
1492 Function* MallocF = nullptr,
1493 const Twine &Name = "");
1494 static Instruction *CreateMalloc(BasicBlock *InsertAtEnd,
1495 Type *IntPtrTy, Type *AllocTy,
1496 Value *AllocSize, Value *ArraySize = nullptr,
1497 Function* MallocF = nullptr,
1498 const Twine &Name = "");
1499 static Instruction *CreateMalloc(Instruction *InsertBefore,
1500 Type *IntPtrTy, Type *AllocTy,
1501 Value *AllocSize, Value *ArraySize = nullptr,
1502 ArrayRef<OperandBundleDef> Bundles = None,
1503 Function* MallocF = nullptr,
1504 const Twine &Name = "");
1505 static Instruction *CreateMalloc(BasicBlock *InsertAtEnd,
1506 Type *IntPtrTy, Type *AllocTy,
1507 Value *AllocSize, Value *ArraySize = nullptr,
1508 ArrayRef<OperandBundleDef> Bundles = None,
1509 Function* MallocF = nullptr,
1510 const Twine &Name = "");
1511 /// Generate the IR for a call to the builtin free function.
1512 static Instruction *CreateFree(Value *Source,
1513 Instruction *InsertBefore);
1514 static Instruction *CreateFree(Value *Source,
1515 BasicBlock *InsertAtEnd);
1516 static Instruction *CreateFree(Value *Source,
1517 ArrayRef<OperandBundleDef> Bundles,
1518 Instruction *InsertBefore);
1519 static Instruction *CreateFree(Value *Source,
1520 ArrayRef<OperandBundleDef> Bundles,
1521 BasicBlock *InsertAtEnd);
1522
1523 FunctionType *getFunctionType() const { return FTy; }
1524
1525 void mutateFunctionType(FunctionType *FTy) {
1526 mutateType(FTy->getReturnType());
1527 this->FTy = FTy;
1528 }
1529
1530 // Note that 'musttail' implies 'tail'.
1531 enum TailCallKind { TCK_None = 0, TCK_Tail = 1, TCK_MustTail = 2,
1532 TCK_NoTail = 3 };
1533 TailCallKind getTailCallKind() const {
1534 return TailCallKind(getSubclassDataFromInstruction() & 3);
1535 }
1536
1537 bool isTailCall() const {
1538 unsigned Kind = getSubclassDataFromInstruction() & 3;
1539 return Kind == TCK_Tail || Kind == TCK_MustTail;
1540 }
1541
1542 bool isMustTailCall() const {
1543 return (getSubclassDataFromInstruction() & 3) == TCK_MustTail;
1544 }
1545
1546 bool isNoTailCall() const {
1547 return (getSubclassDataFromInstruction() & 3) == TCK_NoTail;
1548 }
1549
1550 void setTailCall(bool isTC = true) {
1551 setInstructionSubclassData((getSubclassDataFromInstruction() & ~3) |
1552 unsigned(isTC ? TCK_Tail : TCK_None));
1553 }
1554
1555 void setTailCallKind(TailCallKind TCK) {
1556 setInstructionSubclassData((getSubclassDataFromInstruction() & ~3) |
1557 unsigned(TCK));
1558 }
1559
1560 /// Provide fast operand accessors
1561 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)public: inline Value *getOperand(unsigned) const; inline void
setOperand(unsigned, Value*); inline op_iterator op_begin();
inline const_op_iterator op_begin() const; inline op_iterator
op_end(); inline const_op_iterator op_end() const; protected
: template <int> inline Use &Op(); template <int
> inline const Use &Op() const; public: inline unsigned
getNumOperands() const
;
1562
1563 /// Return the number of call arguments.
1564 ///
1565 unsigned getNumArgOperands() const {
1566 return getNumOperands() - getNumTotalBundleOperands() - 1;
1567 }
1568
1569 /// getArgOperand/setArgOperand - Return/set the i-th call argument.
1570 ///
1571 Value *getArgOperand(unsigned i) const {
1572 assert(i < getNumArgOperands() && "Out of bounds!")(static_cast <bool> (i < getNumArgOperands() &&
"Out of bounds!") ? void (0) : __assert_fail ("i < getNumArgOperands() && \"Out of bounds!\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 1572, __extension__ __PRETTY_FUNCTION__))
;
1573 return getOperand(i);
1574 }
1575 void setArgOperand(unsigned i, Value *v) {
1576 assert(i < getNumArgOperands() && "Out of bounds!")(static_cast <bool> (i < getNumArgOperands() &&
"Out of bounds!") ? void (0) : __assert_fail ("i < getNumArgOperands() && \"Out of bounds!\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 1576, __extension__ __PRETTY_FUNCTION__))
;
1577 setOperand(i, v);
1578 }
1579
1580 /// Return the iterator pointing to the beginning of the argument list.
1581 op_iterator arg_begin() { return op_begin(); }
1582
1583 /// Return the iterator pointing to the end of the argument list.
1584 op_iterator arg_end() {
1585 // [ call args ], [ operand bundles ], callee
1586 return op_end() - getNumTotalBundleOperands() - 1;
1587 }
1588
1589 /// Iteration adapter for range-for loops.
1590 iterator_range<op_iterator> arg_operands() {
1591 return make_range(arg_begin(), arg_end());
1592 }
1593
1594 /// Return the iterator pointing to the beginning of the argument list.
1595 const_op_iterator arg_begin() const { return op_begin(); }
1596
1597 /// Return the iterator pointing to the end of the argument list.
1598 const_op_iterator arg_end() const {
1599 // [ call args ], [ operand bundles ], callee
1600 return op_end() - getNumTotalBundleOperands() - 1;
1601 }
1602
1603 /// Iteration adapter for range-for loops.
1604 iterator_range<const_op_iterator> arg_operands() const {
1605 return make_range(arg_begin(), arg_end());
1606 }
1607
1608 /// Wrappers for getting the \c Use of a call argument.
1609 const Use &getArgOperandUse(unsigned i) const {
1610 assert(i < getNumArgOperands() && "Out of bounds!")(static_cast <bool> (i < getNumArgOperands() &&
"Out of bounds!") ? void (0) : __assert_fail ("i < getNumArgOperands() && \"Out of bounds!\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 1610, __extension__ __PRETTY_FUNCTION__))
;
1611 return getOperandUse(i);
1612 }
1613 Use &getArgOperandUse(unsigned i) {
1614 assert(i < getNumArgOperands() && "Out of bounds!")(static_cast <bool> (i < getNumArgOperands() &&
"Out of bounds!") ? void (0) : __assert_fail ("i < getNumArgOperands() && \"Out of bounds!\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 1614, __extension__ __PRETTY_FUNCTION__))
;
1615 return getOperandUse(i);
1616 }
1617
1618 /// If one of the arguments has the 'returned' attribute, return its
1619 /// operand value. Otherwise, return nullptr.
1620 Value *getReturnedArgOperand() const;
1621
1622 /// getCallingConv/setCallingConv - Get or set the calling convention of this
1623 /// function call.
1624 CallingConv::ID getCallingConv() const {
1625 return static_cast<CallingConv::ID>(getSubclassDataFromInstruction() >> 2);
1626 }
1627 void setCallingConv(CallingConv::ID CC) {
1628 auto ID = static_cast<unsigned>(CC);
1629 assert(!(ID & ~CallingConv::MaxID) && "Unsupported calling convention")(static_cast <bool> (!(ID & ~CallingConv::MaxID) &&
"Unsupported calling convention") ? void (0) : __assert_fail
("!(ID & ~CallingConv::MaxID) && \"Unsupported calling convention\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 1629, __extension__ __PRETTY_FUNCTION__))
;
1630 setInstructionSubclassData((getSubclassDataFromInstruction() & 3) |
1631 (ID << 2));
1632 }
1633
1634 /// Return the parameter attributes for this call.
1635 ///
1636 AttributeList getAttributes() const { return Attrs; }
1637
1638 /// Set the parameter attributes for this call.
1639 ///
1640 void setAttributes(AttributeList A) { Attrs = A; }
1641
1642 /// adds the attribute to the list of attributes.
1643 void addAttribute(unsigned i, Attribute::AttrKind Kind);
1644
1645 /// adds the attribute to the list of attributes.
1646 void addAttribute(unsigned i, Attribute Attr);
1647
1648 /// Adds the attribute to the indicated argument
1649 void addParamAttr(unsigned ArgNo, Attribute::AttrKind Kind);
1650
1651 /// Adds the attribute to the indicated argument
1652 void addParamAttr(unsigned ArgNo, Attribute Attr);
1653
1654 /// removes the attribute from the list of attributes.
1655 void removeAttribute(unsigned i, Attribute::AttrKind Kind);
1656
1657 /// removes the attribute from the list of attributes.
1658 void removeAttribute(unsigned i, StringRef Kind);
1659
1660 /// Removes the attribute from the given argument
1661 void removeParamAttr(unsigned ArgNo, Attribute::AttrKind Kind);
1662
1663 /// Removes the attribute from the given argument
1664 void removeParamAttr(unsigned ArgNo, StringRef Kind);
1665
1666 /// adds the dereferenceable attribute to the list of attributes.
1667 void addDereferenceableAttr(unsigned i, uint64_t Bytes);
1668
1669 /// adds the dereferenceable_or_null attribute to the list of
1670 /// attributes.
1671 void addDereferenceableOrNullAttr(unsigned i, uint64_t Bytes);
1672
1673 /// Determine whether this call has the given attribute.
1674 bool hasFnAttr(Attribute::AttrKind Kind) const {
1675 assert(Kind != Attribute::NoBuiltin &&(static_cast <bool> (Kind != Attribute::NoBuiltin &&
"Use CallInst::isNoBuiltin() to check for Attribute::NoBuiltin"
) ? void (0) : __assert_fail ("Kind != Attribute::NoBuiltin && \"Use CallInst::isNoBuiltin() to check for Attribute::NoBuiltin\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 1676, __extension__ __PRETTY_FUNCTION__))
1676 "Use CallInst::isNoBuiltin() to check for Attribute::NoBuiltin")(static_cast <bool> (Kind != Attribute::NoBuiltin &&
"Use CallInst::isNoBuiltin() to check for Attribute::NoBuiltin"
) ? void (0) : __assert_fail ("Kind != Attribute::NoBuiltin && \"Use CallInst::isNoBuiltin() to check for Attribute::NoBuiltin\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 1676, __extension__ __PRETTY_FUNCTION__))
;
1677 return hasFnAttrImpl(Kind);
1678 }
1679
1680 /// Determine whether this call has the given attribute.
1681 bool hasFnAttr(StringRef Kind) const {
1682 return hasFnAttrImpl(Kind);
1683 }
1684
1685 /// Determine whether the return value has the given attribute.
1686 bool hasRetAttr(Attribute::AttrKind Kind) const;
1687
1688 /// Determine whether the argument or parameter has the given attribute.
1689 bool paramHasAttr(unsigned ArgNo, Attribute::AttrKind Kind) const;
1690
1691 /// Get the attribute of a given kind at a position.
1692 Attribute getAttribute(unsigned i, Attribute::AttrKind Kind) const {
1693 return getAttributes().getAttribute(i, Kind);
1694 }
1695
1696 /// Get the attribute of a given kind at a position.
1697 Attribute getAttribute(unsigned i, StringRef Kind) const {
1698 return getAttributes().getAttribute(i, Kind);
1699 }
1700
1701 /// Get the attribute of a given kind from a given arg
1702 Attribute getParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) const {
1703 assert(ArgNo < getNumArgOperands() && "Out of bounds")(static_cast <bool> (ArgNo < getNumArgOperands() &&
"Out of bounds") ? void (0) : __assert_fail ("ArgNo < getNumArgOperands() && \"Out of bounds\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 1703, __extension__ __PRETTY_FUNCTION__))
;
1704 return getAttributes().getParamAttr(ArgNo, Kind);
1705 }
1706
1707 /// Get the attribute of a given kind from a given arg
1708 Attribute getParamAttr(unsigned ArgNo, StringRef Kind) const {
1709 assert(ArgNo < getNumArgOperands() && "Out of bounds")(static_cast <bool> (ArgNo < getNumArgOperands() &&
"Out of bounds") ? void (0) : __assert_fail ("ArgNo < getNumArgOperands() && \"Out of bounds\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 1709, __extension__ __PRETTY_FUNCTION__))
;
1710 return getAttributes().getParamAttr(ArgNo, Kind);
1711 }
1712
1713 /// Return true if the data operand at index \p i has the attribute \p
1714 /// A.
1715 ///
1716 /// Data operands include call arguments and values used in operand bundles,
1717 /// but does not include the callee operand. This routine dispatches to the
1718 /// underlying AttributeList or the OperandBundleUser as appropriate.
1719 ///
1720 /// The index \p i is interpreted as
1721 ///
1722 /// \p i == Attribute::ReturnIndex -> the return value
1723 /// \p i in [1, arg_size + 1) -> argument number (\p i - 1)
1724 /// \p i in [arg_size + 1, data_operand_size + 1) -> bundle operand at index
1725 /// (\p i - 1) in the operand list.
1726 bool dataOperandHasImpliedAttr(unsigned i, Attribute::AttrKind Kind) const;
1727
1728 /// Extract the alignment of the return value.
1729 unsigned getRetAlignment() const { return Attrs.getRetAlignment(); }
1730
1731 /// Extract the alignment for a call or parameter (0=unknown).
1732 unsigned getParamAlignment(unsigned ArgNo) const {
1733 return Attrs.getParamAlignment(ArgNo);
1734 }
1735
1736 /// Extract the number of dereferenceable bytes for a call or
1737 /// parameter (0=unknown).
1738 uint64_t getDereferenceableBytes(unsigned i) const {
1739 return Attrs.getDereferenceableBytes(i);
1740 }
1741
1742 /// Extract the number of dereferenceable_or_null bytes for a call or
1743 /// parameter (0=unknown).
1744 uint64_t getDereferenceableOrNullBytes(unsigned i) const {
1745 return Attrs.getDereferenceableOrNullBytes(i);
1746 }
1747
1748 /// @brief Determine if the return value is marked with NoAlias attribute.
1749 bool returnDoesNotAlias() const {
1750 return Attrs.hasAttribute(AttributeList::ReturnIndex, Attribute::NoAlias);
1751 }
1752
1753 /// Return true if the call should not be treated as a call to a
1754 /// builtin.
1755 bool isNoBuiltin() const {
1756 return hasFnAttrImpl(Attribute::NoBuiltin) &&
1757 !hasFnAttrImpl(Attribute::Builtin);
1758 }
1759
1760 /// Determine if the call requires strict floating point semantics.
1761 bool isStrictFP() const { return hasFnAttr(Attribute::StrictFP); }
1762
1763 /// Return true if the call should not be inlined.
1764 bool isNoInline() const { return hasFnAttr(Attribute::NoInline); }
1765 void setIsNoInline() {
1766 addAttribute(AttributeList::FunctionIndex, Attribute::NoInline);
1767 }
1768
1769 /// Return true if the call can return twice
1770 bool canReturnTwice() const {
1771 return hasFnAttr(Attribute::ReturnsTwice);
1772 }
1773 void setCanReturnTwice() {
1774 addAttribute(AttributeList::FunctionIndex, Attribute::ReturnsTwice);
1775 }
1776
1777 /// Determine if the call does not access memory.
1778 bool doesNotAccessMemory() const {
1779 return hasFnAttr(Attribute::ReadNone);
1780 }
1781 void setDoesNotAccessMemory() {
1782 addAttribute(AttributeList::FunctionIndex, Attribute::ReadNone);
1783 }
1784
1785 /// Determine if the call does not access or only reads memory.
1786 bool onlyReadsMemory() const {
1787 return doesNotAccessMemory() || hasFnAttr(Attribute::ReadOnly);
1788 }
1789 void setOnlyReadsMemory() {
1790 addAttribute(AttributeList::FunctionIndex, Attribute::ReadOnly);
1791 }
1792
1793 /// Determine if the call does not access or only writes memory.
1794 bool doesNotReadMemory() const {
1795 return doesNotAccessMemory() || hasFnAttr(Attribute::WriteOnly);
1796 }
1797 void setDoesNotReadMemory() {
1798 addAttribute(AttributeList::FunctionIndex, Attribute::WriteOnly);
1799 }
1800
1801 /// @brief Determine if the call can access memmory only using pointers based
1802 /// on its arguments.
1803 bool onlyAccessesArgMemory() const {
1804 return hasFnAttr(Attribute::ArgMemOnly);
1805 }
1806 void setOnlyAccessesArgMemory() {
1807 addAttribute(AttributeList::FunctionIndex, Attribute::ArgMemOnly);
1808 }
1809
1810 /// @brief Determine if the function may only access memory that is
1811 /// inaccessible from the IR.
1812 bool onlyAccessesInaccessibleMemory() const {
1813 return hasFnAttr(Attribute::InaccessibleMemOnly);
1814 }
1815 void setOnlyAccessesInaccessibleMemory() {
1816 addAttribute(AttributeList::FunctionIndex, Attribute::InaccessibleMemOnly);
1817 }
1818
1819 /// @brief Determine if the function may only access memory that is
1820 /// either inaccessible from the IR or pointed to by its arguments.
1821 bool onlyAccessesInaccessibleMemOrArgMem() const {
1822 return hasFnAttr(Attribute::InaccessibleMemOrArgMemOnly);
1823 }
1824 void setOnlyAccessesInaccessibleMemOrArgMem() {
1825 addAttribute(AttributeList::FunctionIndex, Attribute::InaccessibleMemOrArgMemOnly);
1826 }
1827
1828 /// Determine if the call cannot return.
1829 bool doesNotReturn() const { return hasFnAttr(Attribute::NoReturn); }
1830 void setDoesNotReturn() {
1831 addAttribute(AttributeList::FunctionIndex, Attribute::NoReturn);
1832 }
1833
1834 /// Determine if the call cannot unwind.
1835 bool doesNotThrow() const { return hasFnAttr(Attribute::NoUnwind); }
1836 void setDoesNotThrow() {
1837 addAttribute(AttributeList::FunctionIndex, Attribute::NoUnwind);
1838 }
1839
1840 /// Determine if the call cannot be duplicated.
1841 bool cannotDuplicate() const {return hasFnAttr(Attribute::NoDuplicate); }
1842 void setCannotDuplicate() {
1843 addAttribute(AttributeList::FunctionIndex, Attribute::NoDuplicate);
1844 }
1845
1846 /// Determine if the call is convergent
1847 bool isConvergent() const { return hasFnAttr(Attribute::Convergent); }
1848 void setConvergent() {
1849 addAttribute(AttributeList::FunctionIndex, Attribute::Convergent);
1850 }
1851 void setNotConvergent() {
1852 removeAttribute(AttributeList::FunctionIndex, Attribute::Convergent);
1853 }
1854
1855 /// Determine if the call returns a structure through first
1856 /// pointer argument.
1857 bool hasStructRetAttr() const {
1858 if (getNumArgOperands() == 0)
1859 return false;
1860
1861 // Be friendly and also check the callee.
1862 return paramHasAttr(0, Attribute::StructRet);
1863 }
1864
1865 /// Determine if any call argument is an aggregate passed by value.
1866 bool hasByValArgument() const {
1867 return Attrs.hasAttrSomewhere(Attribute::ByVal);
1868 }
1869
1870 /// Return the function called, or null if this is an
1871 /// indirect function invocation.
1872 ///
1873 Function *getCalledFunction() const {
1874 return dyn_cast<Function>(Op<-1>());
1875 }
1876
1877 /// Get a pointer to the function that is invoked by this
1878 /// instruction.
1879 const Value *getCalledValue() const { return Op<-1>(); }
1880 Value *getCalledValue() { return Op<-1>(); }
1881
1882 /// Set the function called.
1883 void setCalledFunction(Value* Fn) {
1884 setCalledFunction(
1885 cast<FunctionType>(cast<PointerType>(Fn->getType())->getElementType()),
1886 Fn);
1887 }
1888 void setCalledFunction(FunctionType *FTy, Value *Fn) {
1889 this->FTy = FTy;
1890 assert(FTy == cast<FunctionType>((static_cast <bool> (FTy == cast<FunctionType>( cast
<PointerType>(Fn->getType())->getElementType())) ?
void (0) : __assert_fail ("FTy == cast<FunctionType>( cast<PointerType>(Fn->getType())->getElementType())"
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 1891, __extension__ __PRETTY_FUNCTION__))
1891 cast<PointerType>(Fn->getType())->getElementType()))(static_cast <bool> (FTy == cast<FunctionType>( cast
<PointerType>(Fn->getType())->getElementType())) ?
void (0) : __assert_fail ("FTy == cast<FunctionType>( cast<PointerType>(Fn->getType())->getElementType())"
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 1891, __extension__ __PRETTY_FUNCTION__))
;
1892 Op<-1>() = Fn;
1893 }
1894
1895 /// Check if this call is an inline asm statement.
1896 bool isInlineAsm() const {
1897 return isa<InlineAsm>(Op<-1>());
1898 }
1899
1900 // Methods for support type inquiry through isa, cast, and dyn_cast:
1901 static bool classof(const Instruction *I) {
1902 return I->getOpcode() == Instruction::Call;
1903 }
1904 static bool classof(const Value *V) {
1905 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1906 }
1907
1908private:
1909 template <typename AttrKind> bool hasFnAttrImpl(AttrKind Kind) const {
1910 if (Attrs.hasAttribute(AttributeList::FunctionIndex, Kind))
1911 return true;
1912
1913 // Operand bundles override attributes on the called function, but don't
1914 // override attributes directly present on the call instruction.
1915 if (isFnAttrDisallowedByOpBundle(Kind))
1916 return false;
1917
1918 if (const Function *F = getCalledFunction())
1919 return F->getAttributes().hasAttribute(AttributeList::FunctionIndex,
1920 Kind);
1921 return false;
1922 }
1923
1924 // Shadow Instruction::setInstructionSubclassData with a private forwarding
1925 // method so that subclasses cannot accidentally use it.
1926 void setInstructionSubclassData(unsigned short D) {
1927 Instruction::setInstructionSubclassData(D);
1928 }
1929};
1930
1931template <>
1932struct OperandTraits<CallInst> : public VariadicOperandTraits<CallInst, 1> {
1933};
1934
1935CallInst::CallInst(Value *Func, ArrayRef<Value *> Args,
1936 ArrayRef<OperandBundleDef> Bundles, const Twine &NameStr,
1937 BasicBlock *InsertAtEnd)
1938 : Instruction(
1939 cast<FunctionType>(cast<PointerType>(Func->getType())
1940 ->getElementType())->getReturnType(),
1941 Instruction::Call, OperandTraits<CallInst>::op_end(this) -
1942 (Args.size() + CountBundleInputs(Bundles) + 1),
1943 unsigned(Args.size() + CountBundleInputs(Bundles) + 1), InsertAtEnd) {
1944 init(Func, Args, Bundles, NameStr);
1945}
1946
1947CallInst::CallInst(FunctionType *Ty, Value *Func, ArrayRef<Value *> Args,
1948 ArrayRef<OperandBundleDef> Bundles, const Twine &NameStr,
1949 Instruction *InsertBefore)
1950 : Instruction(Ty->getReturnType(), Instruction::Call,
1951 OperandTraits<CallInst>::op_end(this) -
1952 (Args.size() + CountBundleInputs(Bundles) + 1),
1953 unsigned(Args.size() + CountBundleInputs(Bundles) + 1),
1954 InsertBefore) {
1955 init(Ty, Func, Args, Bundles, NameStr);
1956}
1957
1958// Note: if you get compile errors about private methods then
1959// please update your code to use the high-level operand
1960// interfaces. See line 943 above.
1961DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CallInst, Value)CallInst::op_iterator CallInst::op_begin() { return OperandTraits
<CallInst>::op_begin(this); } CallInst::const_op_iterator
CallInst::op_begin() const { return OperandTraits<CallInst
>::op_begin(const_cast<CallInst*>(this)); } CallInst
::op_iterator CallInst::op_end() { return OperandTraits<CallInst
>::op_end(this); } CallInst::const_op_iterator CallInst::op_end
() const { return OperandTraits<CallInst>::op_end(const_cast
<CallInst*>(this)); } Value *CallInst::getOperand(unsigned
i_nocapture) const { (static_cast <bool> (i_nocapture <
OperandTraits<CallInst>::operands(this) && "getOperand() out of range!"
) ? void (0) : __assert_fail ("i_nocapture < OperandTraits<CallInst>::operands(this) && \"getOperand() out of range!\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 1961, __extension__ __PRETTY_FUNCTION__)); return cast_or_null
<Value>( OperandTraits<CallInst>::op_begin(const_cast
<CallInst*>(this))[i_nocapture].get()); } void CallInst
::setOperand(unsigned i_nocapture, Value *Val_nocapture) { (static_cast
<bool> (i_nocapture < OperandTraits<CallInst>
::operands(this) && "setOperand() out of range!") ? void
(0) : __assert_fail ("i_nocapture < OperandTraits<CallInst>::operands(this) && \"setOperand() out of range!\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 1961, __extension__ __PRETTY_FUNCTION__)); OperandTraits<
CallInst>::op_begin(this)[i_nocapture] = Val_nocapture; } unsigned
CallInst::getNumOperands() const { return OperandTraits<CallInst
>::operands(this); } template <int Idx_nocapture> Use
&CallInst::Op() { return this->OpFrom<Idx_nocapture
>(this); } template <int Idx_nocapture> const Use &
CallInst::Op() const { return this->OpFrom<Idx_nocapture
>(this); }
1962
1963//===----------------------------------------------------------------------===//
1964// SelectInst Class
1965//===----------------------------------------------------------------------===//
1966
1967/// This class represents the LLVM 'select' instruction.
1968///
1969class SelectInst : public Instruction {
1970 SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr,
1971 Instruction *InsertBefore)
1972 : Instruction(S1->getType(), Instruction::Select,
1973 &Op<0>(), 3, InsertBefore) {
1974 init(C, S1, S2);
1975 setName(NameStr);
1976 }
1977
1978 SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr,
1979 BasicBlock *InsertAtEnd)
1980 : Instruction(S1->getType(), Instruction::Select,
1981 &Op<0>(), 3, InsertAtEnd) {
1982 init(C, S1, S2);
1983 setName(NameStr);
1984 }
1985
1986 void init(Value *C, Value *S1, Value *S2) {
1987 assert(!areInvalidOperands(C, S1, S2) && "Invalid operands for select")(static_cast <bool> (!areInvalidOperands(C, S1, S2) &&
"Invalid operands for select") ? void (0) : __assert_fail ("!areInvalidOperands(C, S1, S2) && \"Invalid operands for select\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 1987, __extension__ __PRETTY_FUNCTION__))
;
1988 Op<0>() = C;
1989 Op<1>() = S1;
1990 Op<2>() = S2;
1991 }
1992
1993protected:
1994 // Note: Instruction needs to be a friend here to call cloneImpl.
1995 friend class Instruction;
1996
1997 SelectInst *cloneImpl() const;
1998
1999public:
2000 static SelectInst *Create(Value *C, Value *S1, Value *S2,
2001 const Twine &NameStr = "",
2002 Instruction *InsertBefore = nullptr,
2003 Instruction *MDFrom = nullptr) {
2004 SelectInst *Sel = new(3) SelectInst(C, S1, S2, NameStr, InsertBefore);
2005 if (MDFrom)
2006 Sel->copyMetadata(*MDFrom);
2007 return Sel;
2008 }
2009
2010 static SelectInst *Create(Value *C, Value *S1, Value *S2,
2011 const Twine &NameStr,
2012 BasicBlock *InsertAtEnd) {
2013 return new(3) SelectInst(C, S1, S2, NameStr, InsertAtEnd);
2014 }
2015
2016 const Value *getCondition() const { return Op<0>(); }
2017 const Value *getTrueValue() const { return Op<1>(); }
2018 const Value *getFalseValue() const { return Op<2>(); }
2019 Value *getCondition() { return Op<0>(); }
2020 Value *getTrueValue() { return Op<1>(); }
2021 Value *getFalseValue() { return Op<2>(); }
2022
2023 void setCondition(Value *V) { Op<0>() = V; }
2024 void setTrueValue(Value *V) { Op<1>() = V; }
2025 void setFalseValue(Value *V) { Op<2>() = V; }
2026
2027 /// Return a string if the specified operands are invalid
2028 /// for a select operation, otherwise return null.
2029 static const char *areInvalidOperands(Value *Cond, Value *True, Value *False);
2030
2031 /// Transparently provide more efficient getOperand methods.
2032 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)public: inline Value *getOperand(unsigned) const; inline void
setOperand(unsigned, Value*); inline op_iterator op_begin();
inline const_op_iterator op_begin() const; inline op_iterator
op_end(); inline const_op_iterator op_end() const; protected
: template <int> inline Use &Op(); template <int
> inline const Use &Op() const; public: inline unsigned
getNumOperands() const
;
2033
2034 OtherOps getOpcode() const {
2035 return static_cast<OtherOps>(Instruction::getOpcode());
2036 }
2037
2038 // Methods for support type inquiry through isa, cast, and dyn_cast:
2039 static bool classof(const Instruction *I) {
2040 return I->getOpcode() == Instruction::Select;
2041 }
2042 static bool classof(const Value *V) {
2043 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2044 }
2045};
2046
2047template <>
2048struct OperandTraits<SelectInst> : public FixedNumOperandTraits<SelectInst, 3> {
2049};
2050
2051DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SelectInst, Value)SelectInst::op_iterator SelectInst::op_begin() { return OperandTraits
<SelectInst>::op_begin(this); } SelectInst::const_op_iterator
SelectInst::op_begin() const { return OperandTraits<SelectInst
>::op_begin(const_cast<SelectInst*>(this)); } SelectInst
::op_iterator SelectInst::op_end() { return OperandTraits<
SelectInst>::op_end(this); } SelectInst::const_op_iterator
SelectInst::op_end() const { return OperandTraits<SelectInst
>::op_end(const_cast<SelectInst*>(this)); } Value *SelectInst
::getOperand(unsigned i_nocapture) const { (static_cast <bool
> (i_nocapture < OperandTraits<SelectInst>::operands
(this) && "getOperand() out of range!") ? void (0) : __assert_fail
("i_nocapture < OperandTraits<SelectInst>::operands(this) && \"getOperand() out of range!\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 2051, __extension__ __PRETTY_FUNCTION__)); return cast_or_null
<Value>( OperandTraits<SelectInst>::op_begin(const_cast
<SelectInst*>(this))[i_nocapture].get()); } void SelectInst
::setOperand(unsigned i_nocapture, Value *Val_nocapture) { (static_cast
<bool> (i_nocapture < OperandTraits<SelectInst>
::operands(this) && "setOperand() out of range!") ? void
(0) : __assert_fail ("i_nocapture < OperandTraits<SelectInst>::operands(this) && \"setOperand() out of range!\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 2051, __extension__ __PRETTY_FUNCTION__)); OperandTraits<
SelectInst>::op_begin(this)[i_nocapture] = Val_nocapture; }
unsigned SelectInst::getNumOperands() const { return OperandTraits
<SelectInst>::operands(this); } template <int Idx_nocapture
> Use &SelectInst::Op() { return this->OpFrom<Idx_nocapture
>(this); } template <int Idx_nocapture> const Use &
SelectInst::Op() const { return this->OpFrom<Idx_nocapture
>(this); }
2052
2053//===----------------------------------------------------------------------===//
2054// VAArgInst Class
2055//===----------------------------------------------------------------------===//
2056
2057/// This class represents the va_arg llvm instruction, which returns
2058/// an argument of the specified type given a va_list and increments that list
2059///
2060class VAArgInst : public UnaryInstruction {
2061protected:
2062 // Note: Instruction needs to be a friend here to call cloneImpl.
2063 friend class Instruction;
2064
2065 VAArgInst *cloneImpl() const;
2066
2067public:
2068 VAArgInst(Value *List, Type *Ty, const Twine &NameStr = "",
2069 Instruction *InsertBefore = nullptr)
2070 : UnaryInstruction(Ty, VAArg, List, InsertBefore) {
2071 setName(NameStr);
2072 }
2073
2074 VAArgInst(Value *List, Type *Ty, const Twine &NameStr,
2075 BasicBlock *InsertAtEnd)
2076 : UnaryInstruction(Ty, VAArg, List, InsertAtEnd) {
2077 setName(NameStr);
2078 }
2079
2080 Value *getPointerOperand() { return getOperand(0); }
2081 const Value *getPointerOperand() const { return getOperand(0); }
2082 static unsigned getPointerOperandIndex() { return 0U; }
2083
2084 // Methods for support type inquiry through isa, cast, and dyn_cast:
2085 static bool classof(const Instruction *I) {
2086 return I->getOpcode() == VAArg;
2087 }
2088 static bool classof(const Value *V) {
2089 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2090 }
2091};
2092
2093//===----------------------------------------------------------------------===//
2094// ExtractElementInst Class
2095//===----------------------------------------------------------------------===//
2096
2097/// This instruction extracts a single (scalar)
2098/// element from a VectorType value
2099///
2100class ExtractElementInst : public Instruction {
2101 ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr = "",
2102 Instruction *InsertBefore = nullptr);
2103 ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr,
2104 BasicBlock *InsertAtEnd);
2105
2106protected:
2107 // Note: Instruction needs to be a friend here to call cloneImpl.
2108 friend class Instruction;
2109
2110 ExtractElementInst *cloneImpl() const;
2111
2112public:
2113 static ExtractElementInst *Create(Value *Vec, Value *Idx,
2114 const Twine &NameStr = "",
2115 Instruction *InsertBefore = nullptr) {
2116 return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertBefore);
2117 }
2118
2119 static ExtractElementInst *Create(Value *Vec, Value *Idx,
2120 const Twine &NameStr,
2121 BasicBlock *InsertAtEnd) {
2122 return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertAtEnd);
2123 }
2124
2125 /// Return true if an extractelement instruction can be
2126 /// formed with the specified operands.
2127 static bool isValidOperands(const Value *Vec, const Value *Idx);
2128
2129 Value *getVectorOperand() { return Op<0>(); }
2130 Value *getIndexOperand() { return Op<1>(); }
2131 const Value *getVectorOperand() const { return Op<0>(); }
2132 const Value *getIndexOperand() const { return Op<1>(); }
2133
2134 VectorType *getVectorOperandType() const {
2135 return cast<VectorType>(getVectorOperand()->getType());
2136 }
2137
2138 /// Transparently provide more efficient getOperand methods.
2139 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)public: inline Value *getOperand(unsigned) const; inline void
setOperand(unsigned, Value*); inline op_iterator op_begin();
inline const_op_iterator op_begin() const; inline op_iterator
op_end(); inline const_op_iterator op_end() const; protected
: template <int> inline Use &Op(); template <int
> inline const Use &Op() const; public: inline unsigned
getNumOperands() const
;
2140
2141 // Methods for support type inquiry through isa, cast, and dyn_cast:
2142 static bool classof(const Instruction *I) {
2143 return I->getOpcode() == Instruction::ExtractElement;
2144 }
2145 static bool classof(const Value *V) {
2146 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2147 }
2148};
2149
2150template <>
2151struct OperandTraits<ExtractElementInst> :
2152 public FixedNumOperandTraits<ExtractElementInst, 2> {
2153};
2154
2155DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ExtractElementInst, Value)ExtractElementInst::op_iterator ExtractElementInst::op_begin(
) { return OperandTraits<ExtractElementInst>::op_begin(
this); } ExtractElementInst::const_op_iterator ExtractElementInst
::op_begin() const { return OperandTraits<ExtractElementInst
>::op_begin(const_cast<ExtractElementInst*>(this)); }
ExtractElementInst::op_iterator ExtractElementInst::op_end()
{ return OperandTraits<ExtractElementInst>::op_end(this
); } ExtractElementInst::const_op_iterator ExtractElementInst
::op_end() const { return OperandTraits<ExtractElementInst
>::op_end(const_cast<ExtractElementInst*>(this)); } Value
*ExtractElementInst::getOperand(unsigned i_nocapture) const {
(static_cast <bool> (i_nocapture < OperandTraits<
ExtractElementInst>::operands(this) && "getOperand() out of range!"
) ? void (0) : __assert_fail ("i_nocapture < OperandTraits<ExtractElementInst>::operands(this) && \"getOperand() out of range!\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 2155, __extension__ __PRETTY_FUNCTION__)); return cast_or_null
<Value>( OperandTraits<ExtractElementInst>::op_begin
(const_cast<ExtractElementInst*>(this))[i_nocapture].get
()); } void ExtractElementInst::setOperand(unsigned i_nocapture
, Value *Val_nocapture) { (static_cast <bool> (i_nocapture
< OperandTraits<ExtractElementInst>::operands(this)
&& "setOperand() out of range!") ? void (0) : __assert_fail
("i_nocapture < OperandTraits<ExtractElementInst>::operands(this) && \"setOperand() out of range!\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 2155, __extension__ __PRETTY_FUNCTION__)); OperandTraits<
ExtractElementInst>::op_begin(this)[i_nocapture] = Val_nocapture
; } unsigned ExtractElementInst::getNumOperands() const { return
OperandTraits<ExtractElementInst>::operands(this); } template
<int Idx_nocapture> Use &ExtractElementInst::Op() {
return this->OpFrom<Idx_nocapture>(this); } template
<int Idx_nocapture> const Use &ExtractElementInst::
Op() const { return this->OpFrom<Idx_nocapture>(this
); }
2156
2157//===----------------------------------------------------------------------===//
2158// InsertElementInst Class
2159//===----------------------------------------------------------------------===//
2160
2161/// This instruction inserts a single (scalar)
2162/// element into a VectorType value
2163///
2164class InsertElementInst : public Instruction {
2165 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
2166 const Twine &NameStr = "",
2167 Instruction *InsertBefore = nullptr);
2168 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx, const Twine &NameStr,
2169 BasicBlock *InsertAtEnd);
2170
2171protected:
2172 // Note: Instruction needs to be a friend here to call cloneImpl.
2173 friend class Instruction;
2174
2175 InsertElementInst *cloneImpl() const;
2176
2177public:
2178 static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
2179 const Twine &NameStr = "",
2180 Instruction *InsertBefore = nullptr) {
2181 return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertBefore);
2182 }
2183
2184 static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
2185 const Twine &NameStr,
2186 BasicBlock *InsertAtEnd) {
2187 return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertAtEnd);
2188 }
2189
2190 /// Return true if an insertelement instruction can be
2191 /// formed with the specified operands.
2192 static bool isValidOperands(const Value *Vec, const Value *NewElt,
2193 const Value *Idx);
2194
2195 /// Overload to return most specific vector type.
2196 ///
2197 VectorType *getType() const {
2198 return cast<VectorType>(Instruction::getType());
2199 }
2200
2201 /// Transparently provide more efficient getOperand methods.
2202 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)public: inline Value *getOperand(unsigned) const; inline void
setOperand(unsigned, Value*); inline op_iterator op_begin();
inline const_op_iterator op_begin() const; inline op_iterator
op_end(); inline const_op_iterator op_end() const; protected
: template <int> inline Use &Op(); template <int
> inline const Use &Op() const; public: inline unsigned
getNumOperands() const
;
2203
2204 // Methods for support type inquiry through isa, cast, and dyn_cast:
2205 static bool classof(const Instruction *I) {
2206 return I->getOpcode() == Instruction::InsertElement;
2207 }
2208 static bool classof(const Value *V) {
2209 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2210 }
2211};
2212
2213template <>
2214struct OperandTraits<InsertElementInst> :
2215 public FixedNumOperandTraits<InsertElementInst, 3> {
2216};
2217
2218DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertElementInst, Value)InsertElementInst::op_iterator InsertElementInst::op_begin() {
return OperandTraits<InsertElementInst>::op_begin(this
); } InsertElementInst::const_op_iterator InsertElementInst::
op_begin() const { return OperandTraits<InsertElementInst>
::op_begin(const_cast<InsertElementInst*>(this)); } InsertElementInst
::op_iterator InsertElementInst::op_end() { return OperandTraits
<InsertElementInst>::op_end(this); } InsertElementInst::
const_op_iterator InsertElementInst::op_end() const { return OperandTraits
<InsertElementInst>::op_end(const_cast<InsertElementInst
*>(this)); } Value *InsertElementInst::getOperand(unsigned
i_nocapture) const { (static_cast <bool> (i_nocapture <
OperandTraits<InsertElementInst>::operands(this) &&
"getOperand() out of range!") ? void (0) : __assert_fail ("i_nocapture < OperandTraits<InsertElementInst>::operands(this) && \"getOperand() out of range!\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 2218, __extension__ __PRETTY_FUNCTION__)); return cast_or_null
<Value>( OperandTraits<InsertElementInst>::op_begin
(const_cast<InsertElementInst*>(this))[i_nocapture].get
()); } void InsertElementInst::setOperand(unsigned i_nocapture
, Value *Val_nocapture) { (static_cast <bool> (i_nocapture
< OperandTraits<InsertElementInst>::operands(this) &&
"setOperand() out of range!") ? void (0) : __assert_fail ("i_nocapture < OperandTraits<InsertElementInst>::operands(this) && \"setOperand() out of range!\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 2218, __extension__ __PRETTY_FUNCTION__)); OperandTraits<
InsertElementInst>::op_begin(this)[i_nocapture] = Val_nocapture
; } unsigned InsertElementInst::getNumOperands() const { return
OperandTraits<InsertElementInst>::operands(this); } template
<int Idx_nocapture> Use &InsertElementInst::Op() {
return this->OpFrom<Idx_nocapture>(this); } template
<int Idx_nocapture> const Use &InsertElementInst::
Op() const { return this->OpFrom<Idx_nocapture>(this
); }
2219
2220//===----------------------------------------------------------------------===//
2221// ShuffleVectorInst Class
2222//===----------------------------------------------------------------------===//
2223
2224/// This instruction constructs a fixed permutation of two
2225/// input vectors.
2226///
2227class ShuffleVectorInst : public Instruction {
2228protected:
2229 // Note: Instruction needs to be a friend here to call cloneImpl.
2230 friend class Instruction;
2231
2232 ShuffleVectorInst *cloneImpl() const;
2233
2234public:
2235 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
2236 const Twine &NameStr = "",
2237 Instruction *InsertBefor = nullptr);
2238 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
2239 const Twine &NameStr, BasicBlock *InsertAtEnd);
2240
2241 // allocate space for exactly three operands
2242 void *operator new(size_t s) {
2243 return User::operator new(s, 3);
2244 }
2245
2246 /// Return true if a shufflevector instruction can be
2247 /// formed with the specified operands.
2248 static bool isValidOperands(const Value *V1, const Value *V2,
2249 const Value *Mask);
2250
2251 /// Overload to return most specific vector type.
2252 ///
2253 VectorType *getType() const {
2254 return cast<VectorType>(Instruction::getType());
2255 }
2256
2257 /// Transparently provide more efficient getOperand methods.
2258 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)public: inline Value *getOperand(unsigned) const; inline void
setOperand(unsigned, Value*); inline op_iterator op_begin();
inline const_op_iterator op_begin() const; inline op_iterator
op_end(); inline const_op_iterator op_end() const; protected
: template <int> inline Use &Op(); template <int
> inline const Use &Op() const; public: inline unsigned
getNumOperands() const
;
2259
2260 Constant *getMask() const {
2261 return cast<Constant>(getOperand(2));
2262 }
2263
2264 /// Return the shuffle mask value for the specified element of the mask.
2265 /// Return -1 if the element is undef.
2266 static int getMaskValue(Constant *Mask, unsigned Elt);
2267
2268 /// Return the shuffle mask value of this instruction for the given element
2269 /// index. Return -1 if the element is undef.
2270 int getMaskValue(unsigned Elt) const {
2271 return getMaskValue(getMask(), Elt);
2272 }
2273
2274 /// Convert the input shuffle mask operand to a vector of integers. Undefined
2275 /// elements of the mask are returned as -1.
2276 static void getShuffleMask(Constant *Mask, SmallVectorImpl<int> &Result);
2277
2278 /// Return the mask for this instruction as a vector of integers. Undefined
2279 /// elements of the mask are returned as -1.
2280 void getShuffleMask(SmallVectorImpl<int> &Result) const {
2281 return getShuffleMask(getMask(), Result);
2282 }
2283
2284 SmallVector<int, 16> getShuffleMask() const {
2285 SmallVector<int, 16> Mask;
2286 getShuffleMask(Mask);
2287 return Mask;
2288 }
2289
2290 /// Change values in a shuffle permute mask assuming the two vector operands
2291 /// of length InVecNumElts have swapped position.
2292 static void commuteShuffleMask(MutableArrayRef<int> Mask,
2293 unsigned InVecNumElts) {
2294 for (int &Idx : Mask) {
2295 if (Idx == -1)
2296 continue;
2297 Idx = Idx < (int)InVecNumElts ? Idx + InVecNumElts : Idx - InVecNumElts;
2298 assert(Idx >= 0 && Idx < (int)InVecNumElts * 2 &&(static_cast <bool> (Idx >= 0 && Idx < (int
)InVecNumElts * 2 && "shufflevector mask index out of range"
) ? void (0) : __assert_fail ("Idx >= 0 && Idx < (int)InVecNumElts * 2 && \"shufflevector mask index out of range\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 2299, __extension__ __PRETTY_FUNCTION__))
2299 "shufflevector mask index out of range")(static_cast <bool> (Idx >= 0 && Idx < (int
)InVecNumElts * 2 && "shufflevector mask index out of range"
) ? void (0) : __assert_fail ("Idx >= 0 && Idx < (int)InVecNumElts * 2 && \"shufflevector mask index out of range\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 2299, __extension__ __PRETTY_FUNCTION__))
;
2300 }
2301 }
2302
2303 // Methods for support type inquiry through isa, cast, and dyn_cast:
2304 static bool classof(const Instruction *I) {
2305 return I->getOpcode() == Instruction::ShuffleVector;
2306 }
2307 static bool classof(const Value *V) {
2308 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2309 }
2310};
2311
2312template <>
2313struct OperandTraits<ShuffleVectorInst> :
2314 public FixedNumOperandTraits<ShuffleVectorInst, 3> {
2315};
2316
2317DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ShuffleVectorInst, Value)ShuffleVectorInst::op_iterator ShuffleVectorInst::op_begin() {
return OperandTraits<ShuffleVectorInst>::op_begin(this
); } ShuffleVectorInst::const_op_iterator ShuffleVectorInst::
op_begin() const { return OperandTraits<ShuffleVectorInst>
::op_begin(const_cast<ShuffleVectorInst*>(this)); } ShuffleVectorInst
::op_iterator ShuffleVectorInst::op_end() { return OperandTraits
<ShuffleVectorInst>::op_end(this); } ShuffleVectorInst::
const_op_iterator ShuffleVectorInst::op_end() const { return OperandTraits
<ShuffleVectorInst>::op_end(const_cast<ShuffleVectorInst
*>(this)); } Value *ShuffleVectorInst::getOperand(unsigned
i_nocapture) const { (static_cast <bool> (i_nocapture <
OperandTraits<ShuffleVectorInst>::operands(this) &&
"getOperand() out of range!") ? void (0) : __assert_fail ("i_nocapture < OperandTraits<ShuffleVectorInst>::operands(this) && \"getOperand() out of range!\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 2317, __extension__ __PRETTY_FUNCTION__)); return cast_or_null
<Value>( OperandTraits<ShuffleVectorInst>::op_begin
(const_cast<ShuffleVectorInst*>(this))[i_nocapture].get
()); } void ShuffleVectorInst::setOperand(unsigned i_nocapture
, Value *Val_nocapture) { (static_cast <bool> (i_nocapture
< OperandTraits<ShuffleVectorInst>::operands(this) &&
"setOperand() out of range!") ? void (0) : __assert_fail ("i_nocapture < OperandTraits<ShuffleVectorInst>::operands(this) && \"setOperand() out of range!\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 2317, __extension__ __PRETTY_FUNCTION__)); OperandTraits<
ShuffleVectorInst>::op_begin(this)[i_nocapture] = Val_nocapture
; } unsigned ShuffleVectorInst::getNumOperands() const { return
OperandTraits<ShuffleVectorInst>::operands(this); } template
<int Idx_nocapture> Use &ShuffleVectorInst::Op() {
return this->OpFrom<Idx_nocapture>(this); } template
<int Idx_nocapture> const Use &ShuffleVectorInst::
Op() const { return this->OpFrom<Idx_nocapture>(this
); }
2318
2319//===----------------------------------------------------------------------===//
2320// ExtractValueInst Class
2321//===----------------------------------------------------------------------===//
2322
2323/// This instruction extracts a struct member or array
2324/// element value from an aggregate value.
2325///
2326class ExtractValueInst : public UnaryInstruction {
2327 SmallVector<unsigned, 4> Indices;
2328
2329 ExtractValueInst(const ExtractValueInst &EVI);
2330
2331 /// Constructors - Create a extractvalue instruction with a base aggregate
2332 /// value and a list of indices. The first ctor can optionally insert before
2333 /// an existing instruction, the second appends the new instruction to the
2334 /// specified BasicBlock.
2335 inline ExtractValueInst(Value *Agg,
2336 ArrayRef<unsigned> Idxs,
2337 const Twine &NameStr,
2338 Instruction *InsertBefore);
2339 inline ExtractValueInst(Value *Agg,
2340 ArrayRef<unsigned> Idxs,
2341 const Twine &NameStr, BasicBlock *InsertAtEnd);
2342
2343 void init(ArrayRef<unsigned> Idxs, const Twine &NameStr);
2344
2345protected:
2346 // Note: Instruction needs to be a friend here to call cloneImpl.
2347 friend class Instruction;
2348
2349 ExtractValueInst *cloneImpl() const;
2350
2351public:
2352 static ExtractValueInst *Create(Value *Agg,
2353 ArrayRef<unsigned> Idxs,
2354 const Twine &NameStr = "",
2355 Instruction *InsertBefore = nullptr) {
2356 return new
2357 ExtractValueInst(Agg, Idxs, NameStr, InsertBefore);
2358 }
2359
2360 static ExtractValueInst *Create(Value *Agg,
2361 ArrayRef<unsigned> Idxs,
2362 const Twine &NameStr,
2363 BasicBlock *InsertAtEnd) {
2364 return new ExtractValueInst(Agg, Idxs, NameStr, InsertAtEnd);
2365 }
2366
2367 /// Returns the type of the element that would be extracted
2368 /// with an extractvalue instruction with the specified parameters.
2369 ///
2370 /// Null is returned if the indices are invalid for the specified type.
2371 static Type *getIndexedType(Type *Agg, ArrayRef<unsigned> Idxs);
2372
2373 using idx_iterator = const unsigned*;
2374
2375 inline idx_iterator idx_begin() const { return Indices.begin(); }
2376 inline idx_iterator idx_end() const { return Indices.end(); }
2377 inline iterator_range<idx_iterator> indices() const {
2378 return make_range(idx_begin(), idx_end());
2379 }
2380
2381 Value *getAggregateOperand() {
2382 return getOperand(0);
2383 }
2384 const Value *getAggregateOperand() const {
2385 return getOperand(0);
2386 }
2387 static unsigned getAggregateOperandIndex() {
2388 return 0U; // get index for modifying correct operand
2389 }
2390
2391 ArrayRef<unsigned> getIndices() const {
2392 return Indices;
2393 }
2394
2395 unsigned getNumIndices() const {
2396 return (unsigned)Indices.size();
2397 }
2398
2399 bool hasIndices() const {
2400 return true;
2401 }
2402
2403 // Methods for support type inquiry through isa, cast, and dyn_cast:
2404 static bool classof(const Instruction *I) {
2405 return I->getOpcode() == Instruction::ExtractValue;
2406 }
2407 static bool classof(const Value *V) {
2408 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2409 }
2410};
2411
2412ExtractValueInst::ExtractValueInst(Value *Agg,
2413 ArrayRef<unsigned> Idxs,
2414 const Twine &NameStr,
2415 Instruction *InsertBefore)
2416 : UnaryInstruction(checkGEPType(getIndexedType(Agg->getType(), Idxs)),
2417 ExtractValue, Agg, InsertBefore) {
2418 init(Idxs, NameStr);
2419}
2420
2421ExtractValueInst::ExtractValueInst(Value *Agg,
2422 ArrayRef<unsigned> Idxs,
2423 const Twine &NameStr,
2424 BasicBlock *InsertAtEnd)
2425 : UnaryInstruction(checkGEPType(getIndexedType(Agg->getType(), Idxs)),
2426 ExtractValue, Agg, InsertAtEnd) {
2427 init(Idxs, NameStr);
2428}
2429
2430//===----------------------------------------------------------------------===//
2431// InsertValueInst Class
2432//===----------------------------------------------------------------------===//
2433
2434/// This instruction inserts a struct field of array element
2435/// value into an aggregate value.
2436///
2437class InsertValueInst : public Instruction {
2438 SmallVector<unsigned, 4> Indices;
2439
2440 InsertValueInst(const InsertValueInst &IVI);
2441
2442 /// Constructors - Create a insertvalue instruction with a base aggregate
2443 /// value, a value to insert, and a list of indices. The first ctor can
2444 /// optionally insert before an existing instruction, the second appends
2445 /// the new instruction to the specified BasicBlock.
2446 inline InsertValueInst(Value *Agg, Value *Val,
2447 ArrayRef<unsigned> Idxs,
2448 const Twine &NameStr,
2449 Instruction *InsertBefore);
2450 inline InsertValueInst(Value *Agg, Value *Val,
2451 ArrayRef<unsigned> Idxs,
2452 const Twine &NameStr, BasicBlock *InsertAtEnd);
2453
2454 /// Constructors - These two constructors are convenience methods because one
2455 /// and two index insertvalue instructions are so common.
2456 InsertValueInst(Value *Agg, Value *Val, unsigned Idx,
2457 const Twine &NameStr = "",
2458 Instruction *InsertBefore = nullptr);
2459 InsertValueInst(Value *Agg, Value *Val, unsigned Idx, const Twine &NameStr,
2460 BasicBlock *InsertAtEnd);
2461
2462 void init(Value *Agg, Value *Val, ArrayRef<unsigned> Idxs,
2463 const Twine &NameStr);
2464
2465protected:
2466 // Note: Instruction needs to be a friend here to call cloneImpl.
2467 friend class Instruction;
2468
2469 InsertValueInst *cloneImpl() const;
2470
2471public:
2472 // allocate space for exactly two operands
2473 void *operator new(size_t s) {
2474 return User::operator new(s, 2);
2475 }
2476
2477 static InsertValueInst *Create(Value *Agg, Value *Val,
2478 ArrayRef<unsigned> Idxs,
2479 const Twine &NameStr = "",
2480 Instruction *InsertBefore = nullptr) {
2481 return new InsertValueInst(Agg, Val, Idxs, NameStr, InsertBefore);
2482 }
2483
2484 static InsertValueInst *Create(Value *Agg, Value *Val,
2485 ArrayRef<unsigned> Idxs,
2486 const Twine &NameStr,
2487 BasicBlock *InsertAtEnd) {
2488 return new InsertValueInst(Agg, Val, Idxs, NameStr, InsertAtEnd);
2489 }
2490
2491 /// Transparently provide more efficient getOperand methods.
2492 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)public: inline Value *getOperand(unsigned) const; inline void
setOperand(unsigned, Value*); inline op_iterator op_begin();
inline const_op_iterator op_begin() const; inline op_iterator
op_end(); inline const_op_iterator op_end() const; protected
: template <int> inline Use &Op(); template <int
> inline const Use &Op() const; public: inline unsigned
getNumOperands() const
;
2493
2494 using idx_iterator = const unsigned*;
2495
2496 inline idx_iterator idx_begin() const { return Indices.begin(); }
2497 inline idx_iterator idx_end() const { return Indices.end(); }
2498 inline iterator_range<idx_iterator> indices() const {
2499 return make_range(idx_begin(), idx_end());
2500 }
2501
2502 Value *getAggregateOperand() {
2503 return getOperand(0);
2504 }
2505 const Value *getAggregateOperand() const {
2506 return getOperand(0);
2507 }
2508 static unsigned getAggregateOperandIndex() {
2509 return 0U; // get index for modifying correct operand
2510 }
2511
2512 Value *getInsertedValueOperand() {
2513 return getOperand(1);
2514 }
2515 const Value *getInsertedValueOperand() const {
2516 return getOperand(1);
2517 }
2518 static unsigned getInsertedValueOperandIndex() {
2519 return 1U; // get index for modifying correct operand
2520 }
2521
2522 ArrayRef<unsigned> getIndices() const {
2523 return Indices;
2524 }
2525
2526 unsigned getNumIndices() const {
2527 return (unsigned)Indices.size();
2528 }
2529
2530 bool hasIndices() const {
2531 return true;
2532 }
2533
2534 // Methods for support type inquiry through isa, cast, and dyn_cast:
2535 static bool classof(const Instruction *I) {
2536 return I->getOpcode() == Instruction::InsertValue;
2537 }
2538 static bool classof(const Value *V) {
2539 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2540 }
2541};
2542
2543template <>
2544struct OperandTraits<InsertValueInst> :
2545 public FixedNumOperandTraits<InsertValueInst, 2> {
2546};
2547
2548InsertValueInst::InsertValueInst(Value *Agg,
2549 Value *Val,
2550 ArrayRef<unsigned> Idxs,
2551 const Twine &NameStr,
2552 Instruction *InsertBefore)
2553 : Instruction(Agg->getType(), InsertValue,
2554 OperandTraits<InsertValueInst>::op_begin(this),
2555 2, InsertBefore) {
2556 init(Agg, Val, Idxs, NameStr);
2557}
2558
2559InsertValueInst::InsertValueInst(Value *Agg,
2560 Value *Val,
2561 ArrayRef<unsigned> Idxs,
2562 const Twine &NameStr,
2563 BasicBlock *InsertAtEnd)
2564 : Instruction(Agg->getType(), InsertValue,
2565 OperandTraits<InsertValueInst>::op_begin(this),
2566 2, InsertAtEnd) {
2567 init(Agg, Val, Idxs, NameStr);
2568}
2569
2570DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertValueInst, Value)InsertValueInst::op_iterator InsertValueInst::op_begin() { return
OperandTraits<InsertValueInst>::op_begin(this); } InsertValueInst
::const_op_iterator InsertValueInst::op_begin() const { return
OperandTraits<InsertValueInst>::op_begin(const_cast<
InsertValueInst*>(this)); } InsertValueInst::op_iterator InsertValueInst
::op_end() { return OperandTraits<InsertValueInst>::op_end
(this); } InsertValueInst::const_op_iterator InsertValueInst::
op_end() const { return OperandTraits<InsertValueInst>::
op_end(const_cast<InsertValueInst*>(this)); } Value *InsertValueInst
::getOperand(unsigned i_nocapture) const { (static_cast <bool
> (i_nocapture < OperandTraits<InsertValueInst>::
operands(this) && "getOperand() out of range!") ? void
(0) : __assert_fail ("i_nocapture < OperandTraits<InsertValueInst>::operands(this) && \"getOperand() out of range!\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 2570, __extension__ __PRETTY_FUNCTION__)); return cast_or_null
<Value>( OperandTraits<InsertValueInst>::op_begin
(const_cast<InsertValueInst*>(this))[i_nocapture].get()
); } void InsertValueInst::setOperand(unsigned i_nocapture, Value
*Val_nocapture) { (static_cast <bool> (i_nocapture <
OperandTraits<InsertValueInst>::operands(this) &&
"setOperand() out of range!") ? void (0) : __assert_fail ("i_nocapture < OperandTraits<InsertValueInst>::operands(this) && \"setOperand() out of range!\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 2570, __extension__ __PRETTY_FUNCTION__)); OperandTraits<
InsertValueInst>::op_begin(this)[i_nocapture] = Val_nocapture
; } unsigned InsertValueInst::getNumOperands() const { return
OperandTraits<InsertValueInst>::operands(this); } template
<int Idx_nocapture> Use &InsertValueInst::Op() { return
this->OpFrom<Idx_nocapture>(this); } template <int
Idx_nocapture> const Use &InsertValueInst::Op() const
{ return this->OpFrom<Idx_nocapture>(this); }
2571
2572//===----------------------------------------------------------------------===//
2573// PHINode Class
2574//===----------------------------------------------------------------------===//
2575
2576// PHINode - The PHINode class is used to represent the magical mystical PHI
2577// node, that can not exist in nature, but can be synthesized in a computer
2578// scientist's overactive imagination.
2579//
2580class PHINode : public Instruction {
2581 /// The number of operands actually allocated. NumOperands is
2582 /// the number actually in use.
2583 unsigned ReservedSpace;
2584
2585 PHINode(const PHINode &PN);
2586
2587 explicit PHINode(Type *Ty, unsigned NumReservedValues,
2588 const Twine &NameStr = "",
2589 Instruction *InsertBefore = nullptr)
2590 : Instruction(Ty, Instruction::PHI, nullptr, 0, InsertBefore),
2591 ReservedSpace(NumReservedValues) {
2592 setName(NameStr);
2593 allocHungoffUses(ReservedSpace);
2594 }
2595
2596 PHINode(Type *Ty, unsigned NumReservedValues, const Twine &NameStr,
2597 BasicBlock *InsertAtEnd)
2598 : Instruction(Ty, Instruction::PHI, nullptr, 0, InsertAtEnd),
2599 ReservedSpace(NumReservedValues) {
2600 setName(NameStr);
2601 allocHungoffUses(ReservedSpace);
2602 }
2603
2604protected:
2605 // Note: Instruction needs to be a friend here to call cloneImpl.
2606 friend class Instruction;
2607
2608 PHINode *cloneImpl() const;
2609
2610 // allocHungoffUses - this is more complicated than the generic
2611 // User::allocHungoffUses, because we have to allocate Uses for the incoming
2612 // values and pointers to the incoming blocks, all in one allocation.
2613 void allocHungoffUses(unsigned N) {
2614 User::allocHungoffUses(N, /* IsPhi */ true);
2615 }
2616
2617public:
2618 /// Constructors - NumReservedValues is a hint for the number of incoming
2619 /// edges that this phi node will have (use 0 if you really have no idea).
2620 static PHINode *Create(Type *Ty, unsigned NumReservedValues,
2621 const Twine &NameStr = "",
2622 Instruction *InsertBefore = nullptr) {
2623 return new PHINode(Ty, NumReservedValues, NameStr, InsertBefore);
2624 }
2625
2626 static PHINode *Create(Type *Ty, unsigned NumReservedValues,
2627 const Twine &NameStr, BasicBlock *InsertAtEnd) {
2628 return new PHINode(Ty, NumReservedValues, NameStr, InsertAtEnd);
2629 }
2630
2631 /// Provide fast operand accessors
2632 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)public: inline Value *getOperand(unsigned) const; inline void
setOperand(unsigned, Value*); inline op_iterator op_begin();
inline const_op_iterator op_begin() const; inline op_iterator
op_end(); inline const_op_iterator op_end() const; protected
: template <int> inline Use &Op(); template <int
> inline const Use &Op() const; public: inline unsigned
getNumOperands() const
;
2633
2634 // Block iterator interface. This provides access to the list of incoming
2635 // basic blocks, which parallels the list of incoming values.
2636
2637 using block_iterator = BasicBlock **;
2638 using const_block_iterator = BasicBlock * const *;
2639
2640 block_iterator block_begin() {
2641 Use::UserRef *ref =
2642 reinterpret_cast<Use::UserRef*>(op_begin() + ReservedSpace);
2643 return reinterpret_cast<block_iterator>(ref + 1);
2644 }
2645
2646 const_block_iterator block_begin() const {
2647 const Use::UserRef *ref =
2648 reinterpret_cast<const Use::UserRef*>(op_begin() + ReservedSpace);
2649 return reinterpret_cast<const_block_iterator>(ref + 1);
2650 }
2651
2652 block_iterator block_end() {
2653 return block_begin() + getNumOperands();
2654 }
2655
2656 const_block_iterator block_end() const {
2657 return block_begin() + getNumOperands();
2658 }
2659
2660 iterator_range<block_iterator> blocks() {
2661 return make_range(block_begin(), block_end());
2662 }
2663
2664 iterator_range<const_block_iterator> blocks() const {
2665 return make_range(block_begin(), block_end());
2666 }
2667
2668 op_range incoming_values() { return operands(); }
2669
2670 const_op_range incoming_values() const { return operands(); }
2671
2672 /// Return the number of incoming edges
2673 ///
2674 unsigned getNumIncomingValues() const { return getNumOperands(); }
2675
2676 /// Return incoming value number x
2677 ///
2678 Value *getIncomingValue(unsigned i) const {
2679 return getOperand(i);
2680 }
2681 void setIncomingValue(unsigned i, Value *V) {
2682 assert(V && "PHI node got a null value!")(static_cast <bool> (V && "PHI node got a null value!"
) ? void (0) : __assert_fail ("V && \"PHI node got a null value!\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 2682, __extension__ __PRETTY_FUNCTION__))
;
2683 assert(getType() == V->getType() &&(static_cast <bool> (getType() == V->getType() &&
"All operands to PHI node must be the same type as the PHI node!"
) ? void (0) : __assert_fail ("getType() == V->getType() && \"All operands to PHI node must be the same type as the PHI node!\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 2684, __extension__ __PRETTY_FUNCTION__))
2684 "All operands to PHI node must be the same type as the PHI node!")(static_cast <bool> (getType() == V->getType() &&
"All operands to PHI node must be the same type as the PHI node!"
) ? void (0) : __assert_fail ("getType() == V->getType() && \"All operands to PHI node must be the same type as the PHI node!\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 2684, __extension__ __PRETTY_FUNCTION__))
;
2685 setOperand(i, V);
2686 }
2687
2688 static unsigned getOperandNumForIncomingValue(unsigned i) {
2689 return i;
2690 }
2691
2692 static unsigned getIncomingValueNumForOperand(unsigned i) {
2693 return i;
2694 }
2695
2696 /// Return incoming basic block number @p i.
2697 ///
2698 BasicBlock *getIncomingBlock(unsigned i) const {
2699 return block_begin()[i];
2700 }
2701
2702 /// Return incoming basic block corresponding
2703 /// to an operand of the PHI.
2704 ///
2705 BasicBlock *getIncomingBlock(const Use &U) const {
2706 assert(this == U.getUser() && "Iterator doesn't point to PHI's Uses?")(static_cast <bool> (this == U.getUser() && "Iterator doesn't point to PHI's Uses?"
) ? void (0) : __assert_fail ("this == U.getUser() && \"Iterator doesn't point to PHI's Uses?\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 2706, __extension__ __PRETTY_FUNCTION__))
;
2707 return getIncomingBlock(unsigned(&U - op_begin()));
2708 }
2709
2710 /// Return incoming basic block corresponding
2711 /// to value use iterator.
2712 ///
2713 BasicBlock *getIncomingBlock(Value::const_user_iterator I) const {
2714 return getIncomingBlock(I.getUse());
2715 }
2716
2717 void setIncomingBlock(unsigned i, BasicBlock *BB) {
2718 assert(BB && "PHI node got a null basic block!")(static_cast <bool> (BB && "PHI node got a null basic block!"
) ? void (0) : __assert_fail ("BB && \"PHI node got a null basic block!\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 2718, __extension__ __PRETTY_FUNCTION__))
;
2719 block_begin()[i] = BB;
2720 }
2721
2722 /// Add an incoming value to the end of the PHI list
2723 ///
2724 void addIncoming(Value *V, BasicBlock *BB) {
2725 if (getNumOperands() == ReservedSpace)
2726 growOperands(); // Get more space!
2727 // Initialize some new operands.
2728 setNumHungOffUseOperands(getNumOperands() + 1);
2729 setIncomingValue(getNumOperands() - 1, V);
2730 setIncomingBlock(getNumOperands() - 1, BB);
2731 }
2732
2733 /// Remove an incoming value. This is useful if a
2734 /// predecessor basic block is deleted. The value removed is returned.
2735 ///
2736 /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
2737 /// is true), the PHI node is destroyed and any uses of it are replaced with
2738 /// dummy values. The only time there should be zero incoming values to a PHI
2739 /// node is when the block is dead, so this strategy is sound.
2740 ///
2741 Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
2742
2743 Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty=true) {
2744 int Idx = getBasicBlockIndex(BB);
2745 assert(Idx >= 0 && "Invalid basic block argument to remove!")(static_cast <bool> (Idx >= 0 && "Invalid basic block argument to remove!"
) ? void (0) : __assert_fail ("Idx >= 0 && \"Invalid basic block argument to remove!\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 2745, __extension__ __PRETTY_FUNCTION__))
;
2746 return removeIncomingValue(Idx, DeletePHIIfEmpty);
2747 }
2748
2749 /// Return the first index of the specified basic
2750 /// block in the value list for this PHI. Returns -1 if no instance.
2751 ///
2752 int getBasicBlockIndex(const BasicBlock *BB) const {
2753 for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
2754 if (block_begin()[i] == BB)
2755 return i;
2756 return -1;
2757 }
2758
2759 Value *getIncomingValueForBlock(const BasicBlock *BB) const {
2760 int Idx = getBasicBlockIndex(BB);
2761 assert(Idx >= 0 && "Invalid basic block argument!")(static_cast <bool> (Idx >= 0 && "Invalid basic block argument!"
) ? void (0) : __assert_fail ("Idx >= 0 && \"Invalid basic block argument!\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 2761, __extension__ __PRETTY_FUNCTION__))
;
2762 return getIncomingValue(Idx);
2763 }
2764
2765 /// If the specified PHI node always merges together the
2766 /// same value, return the value, otherwise return null.
2767 Value *hasConstantValue() const;
2768
2769 /// Whether the specified PHI node always merges
2770 /// together the same value, assuming undefs are equal to a unique
2771 /// non-undef value.
2772 bool hasConstantOrUndefValue() const;
2773
2774 /// Methods for support type inquiry through isa, cast, and dyn_cast:
2775 static bool classof(const Instruction *I) {
2776 return I->getOpcode() == Instruction::PHI;
2777 }
2778 static bool classof(const Value *V) {
2779 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2780 }
2781
2782private:
2783 void growOperands();
2784};
2785
2786template <>
2787struct OperandTraits<PHINode> : public HungoffOperandTraits<2> {
2788};
2789
2790DEFINE_TRANSPARENT_OPERAND_ACCESSORS(PHINode, Value)PHINode::op_iterator PHINode::op_begin() { return OperandTraits
<PHINode>::op_begin(this); } PHINode::const_op_iterator
PHINode::op_begin() const { return OperandTraits<PHINode>
::op_begin(const_cast<PHINode*>(this)); } PHINode::op_iterator
PHINode::op_end() { return OperandTraits<PHINode>::op_end
(this); } PHINode::const_op_iterator PHINode::op_end() const {
return OperandTraits<PHINode>::op_end(const_cast<PHINode
*>(this)); } Value *PHINode::getOperand(unsigned i_nocapture
) const { (static_cast <bool> (i_nocapture < OperandTraits
<PHINode>::operands(this) && "getOperand() out of range!"
) ? void (0) : __assert_fail ("i_nocapture < OperandTraits<PHINode>::operands(this) && \"getOperand() out of range!\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 2790, __extension__ __PRETTY_FUNCTION__)); return cast_or_null
<Value>( OperandTraits<PHINode>::op_begin(const_cast
<PHINode*>(this))[i_nocapture].get()); } void PHINode::
setOperand(unsigned i_nocapture, Value *Val_nocapture) { (static_cast
<bool> (i_nocapture < OperandTraits<PHINode>::
operands(this) && "setOperand() out of range!") ? void
(0) : __assert_fail ("i_nocapture < OperandTraits<PHINode>::operands(this) && \"setOperand() out of range!\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 2790, __extension__ __PRETTY_FUNCTION__)); OperandTraits<
PHINode>::op_begin(this)[i_nocapture] = Val_nocapture; } unsigned
PHINode::getNumOperands() const { return OperandTraits<PHINode
>::operands(this); } template <int Idx_nocapture> Use
&PHINode::Op() { return this->OpFrom<Idx_nocapture
>(this); } template <int Idx_nocapture> const Use &
PHINode::Op() const { return this->OpFrom<Idx_nocapture
>(this); }
2791
2792//===----------------------------------------------------------------------===//
2793// LandingPadInst Class
2794//===----------------------------------------------------------------------===//
2795
2796//===---------------------------------------------------------------------------
2797/// The landingpad instruction holds all of the information
2798/// necessary to generate correct exception handling. The landingpad instruction
2799/// cannot be moved from the top of a landing pad block, which itself is
2800/// accessible only from the 'unwind' edge of an invoke. This uses the
2801/// SubclassData field in Value to store whether or not the landingpad is a
2802/// cleanup.
2803///
2804class LandingPadInst : public Instruction {
2805 /// The number of operands actually allocated. NumOperands is
2806 /// the number actually in use.
2807 unsigned ReservedSpace;
2808
2809 LandingPadInst(const LandingPadInst &LP);
2810
2811public:
2812 enum ClauseType { Catch, Filter };
2813
2814private:
2815 explicit LandingPadInst(Type *RetTy, unsigned NumReservedValues,
2816 const Twine &NameStr, Instruction *InsertBefore);
2817 explicit LandingPadInst(Type *RetTy, unsigned NumReservedValues,
2818 const Twine &NameStr, BasicBlock *InsertAtEnd);
2819
2820 // Allocate space for exactly zero operands.
2821 void *operator new(size_t s) {
2822 return User::operator new(s);
2823 }
2824
2825 void growOperands(unsigned Size);
2826 void init(unsigned NumReservedValues, const Twine &NameStr);
2827
2828protected:
2829 // Note: Instruction needs to be a friend here to call cloneImpl.
2830 friend class Instruction;
2831
2832 LandingPadInst *cloneImpl() const;
2833
2834public:
2835 /// Constructors - NumReservedClauses is a hint for the number of incoming
2836 /// clauses that this landingpad will have (use 0 if you really have no idea).
2837 static LandingPadInst *Create(Type *RetTy, unsigned NumReservedClauses,
2838 const Twine &NameStr = "",
2839 Instruction *InsertBefore = nullptr);
2840 static LandingPadInst *Create(Type *RetTy, unsigned NumReservedClauses,
2841 const Twine &NameStr, BasicBlock *InsertAtEnd);
2842
2843 /// Provide fast operand accessors
2844 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)public: inline Value *getOperand(unsigned) const; inline void
setOperand(unsigned, Value*); inline op_iterator op_begin();
inline const_op_iterator op_begin() const; inline op_iterator
op_end(); inline const_op_iterator op_end() const; protected
: template <int> inline Use &Op(); template <int
> inline const Use &Op() const; public: inline unsigned
getNumOperands() const
;
2845
2846 /// Return 'true' if this landingpad instruction is a
2847 /// cleanup. I.e., it should be run when unwinding even if its landing pad
2848 /// doesn't catch the exception.
2849 bool isCleanup() const { return getSubclassDataFromInstruction() & 1; }
2850
2851 /// Indicate that this landingpad instruction is a cleanup.
2852 void setCleanup(bool V) {
2853 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
2854 (V ? 1 : 0));
2855 }
2856
2857 /// Add a catch or filter clause to the landing pad.
2858 void addClause(Constant *ClauseVal);
2859
2860 /// Get the value of the clause at index Idx. Use isCatch/isFilter to
2861 /// determine what type of clause this is.
2862 Constant *getClause(unsigned Idx) const {
2863 return cast<Constant>(getOperandList()[Idx]);
2864 }
2865
2866 /// Return 'true' if the clause and index Idx is a catch clause.
2867 bool isCatch(unsigned Idx) const {
2868 return !isa<ArrayType>(getOperandList()[Idx]->getType());
2869 }
2870
2871 /// Return 'true' if the clause and index Idx is a filter clause.
2872 bool isFilter(unsigned Idx) const {
2873 return isa<ArrayType>(getOperandList()[Idx]->getType());
2874 }
2875
2876 /// Get the number of clauses for this landing pad.
2877 unsigned getNumClauses() const { return getNumOperands(); }
2878
2879 /// Grow the size of the operand list to accommodate the new
2880 /// number of clauses.
2881 void reserveClauses(unsigned Size) { growOperands(Size); }
2882
2883 // Methods for support type inquiry through isa, cast, and dyn_cast:
2884 static bool classof(const Instruction *I) {
2885 return I->getOpcode() == Instruction::LandingPad;
2886 }
2887 static bool classof(const Value *V) {
2888 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2889 }
2890};
2891
2892template <>
2893struct OperandTraits<LandingPadInst> : public HungoffOperandTraits<1> {
2894};
2895
2896DEFINE_TRANSPARENT_OPERAND_ACCESSORS(LandingPadInst, Value)LandingPadInst::op_iterator LandingPadInst::op_begin() { return
OperandTraits<LandingPadInst>::op_begin(this); } LandingPadInst
::const_op_iterator LandingPadInst::op_begin() const { return
OperandTraits<LandingPadInst>::op_begin(const_cast<
LandingPadInst*>(this)); } LandingPadInst::op_iterator LandingPadInst
::op_end() { return OperandTraits<LandingPadInst>::op_end
(this); } LandingPadInst::const_op_iterator LandingPadInst::op_end
() const { return OperandTraits<LandingPadInst>::op_end
(const_cast<LandingPadInst*>(this)); } Value *LandingPadInst
::getOperand(unsigned i_nocapture) const { (static_cast <bool
> (i_nocapture < OperandTraits<LandingPadInst>::operands
(this) && "getOperand() out of range!") ? void (0) : __assert_fail
("i_nocapture < OperandTraits<LandingPadInst>::operands(this) && \"getOperand() out of range!\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 2896, __extension__ __PRETTY_FUNCTION__)); return cast_or_null
<Value>( OperandTraits<LandingPadInst>::op_begin(
const_cast<LandingPadInst*>(this))[i_nocapture].get());
} void LandingPadInst::setOperand(unsigned i_nocapture, Value
*Val_nocapture) { (static_cast <bool> (i_nocapture <
OperandTraits<LandingPadInst>::operands(this) &&
"setOperand() out of range!") ? void (0) : __assert_fail ("i_nocapture < OperandTraits<LandingPadInst>::operands(this) && \"setOperand() out of range!\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 2896, __extension__ __PRETTY_FUNCTION__)); OperandTraits<
LandingPadInst>::op_begin(this)[i_nocapture] = Val_nocapture
; } unsigned LandingPadInst::getNumOperands() const { return OperandTraits
<LandingPadInst>::operands(this); } template <int Idx_nocapture
> Use &LandingPadInst::Op() { return this->OpFrom<
Idx_nocapture>(this); } template <int Idx_nocapture>
const Use &LandingPadInst::Op() const { return this->
OpFrom<Idx_nocapture>(this); }
2897
2898//===----------------------------------------------------------------------===//
2899// ReturnInst Class
2900//===----------------------------------------------------------------------===//
2901
2902//===---------------------------------------------------------------------------
2903/// Return a value (possibly void), from a function. Execution
2904/// does not continue in this function any longer.
2905///
2906class ReturnInst : public TerminatorInst {
2907 ReturnInst(const ReturnInst &RI);
2908
2909private:
2910 // ReturnInst constructors:
2911 // ReturnInst() - 'ret void' instruction
2912 // ReturnInst( null) - 'ret void' instruction
2913 // ReturnInst(Value* X) - 'ret X' instruction
2914 // ReturnInst( null, Inst *I) - 'ret void' instruction, insert before I
2915 // ReturnInst(Value* X, Inst *I) - 'ret X' instruction, insert before I
2916 // ReturnInst( null, BB *B) - 'ret void' instruction, insert @ end of B
2917 // ReturnInst(Value* X, BB *B) - 'ret X' instruction, insert @ end of B
2918 //
2919 // NOTE: If the Value* passed is of type void then the constructor behaves as
2920 // if it was passed NULL.
2921 explicit ReturnInst(LLVMContext &C, Value *retVal = nullptr,
2922 Instruction *InsertBefore = nullptr);
2923 ReturnInst(LLVMContext &C, Value *retVal, BasicBlock *InsertAtEnd);
2924 explicit ReturnInst(LLVMContext &C, BasicBlock *InsertAtEnd);
2925
2926protected:
2927 // Note: Instruction needs to be a friend here to call cloneImpl.
2928 friend class Instruction;
2929
2930 ReturnInst *cloneImpl() const;
2931
2932public:
2933 static ReturnInst* Create(LLVMContext &C, Value *retVal = nullptr,
2934 Instruction *InsertBefore = nullptr) {
2935 return new(!!retVal) ReturnInst(C, retVal, InsertBefore);
2936 }
2937
2938 static ReturnInst* Create(LLVMContext &C, Value *retVal,
2939 BasicBlock *InsertAtEnd) {
2940 return new(!!retVal) ReturnInst(C, retVal, InsertAtEnd);
2941 }
2942
2943 static ReturnInst* Create(LLVMContext &C, BasicBlock *InsertAtEnd) {
2944 return new(0) ReturnInst(C, InsertAtEnd);
2945 }
2946
2947 /// Provide fast operand accessors
2948 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)public: inline Value *getOperand(unsigned) const; inline void
setOperand(unsigned, Value*); inline op_iterator op_begin();
inline const_op_iterator op_begin() const; inline op_iterator
op_end(); inline const_op_iterator op_end() const; protected
: template <int> inline Use &Op(); template <int
> inline const Use &Op() const; public: inline unsigned
getNumOperands() const
;
2949
2950 /// Convenience accessor. Returns null if there is no return value.
2951 Value *getReturnValue() const {
2952 return getNumOperands() != 0 ? getOperand(0) : nullptr;
2953 }
2954
2955 unsigned getNumSuccessors() const { return 0; }
2956
2957 // Methods for support type inquiry through isa, cast, and dyn_cast:
2958 static bool classof(const Instruction *I) {
2959 return (I->getOpcode() == Instruction::Ret);
2960 }
2961 static bool classof(const Value *V) {
2962 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2963 }
2964
2965private:
2966 friend TerminatorInst;
2967
2968 BasicBlock *getSuccessor(unsigned idx) const {
2969 llvm_unreachable("ReturnInst has no successors!")::llvm::llvm_unreachable_internal("ReturnInst has no successors!"
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 2969)
;
2970 }
2971
2972 void setSuccessor(unsigned idx, BasicBlock *B) {
2973 llvm_unreachable("ReturnInst has no successors!")::llvm::llvm_unreachable_internal("ReturnInst has no successors!"
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 2973)
;
2974 }
2975};
2976
2977template <>
2978struct OperandTraits<ReturnInst> : public VariadicOperandTraits<ReturnInst> {
2979};
2980
2981DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ReturnInst, Value)ReturnInst::op_iterator ReturnInst::op_begin() { return OperandTraits
<ReturnInst>::op_begin(this); } ReturnInst::const_op_iterator
ReturnInst::op_begin() const { return OperandTraits<ReturnInst
>::op_begin(const_cast<ReturnInst*>(this)); } ReturnInst
::op_iterator ReturnInst::op_end() { return OperandTraits<
ReturnInst>::op_end(this); } ReturnInst::const_op_iterator
ReturnInst::op_end() const { return OperandTraits<ReturnInst
>::op_end(const_cast<ReturnInst*>(this)); } Value *ReturnInst
::getOperand(unsigned i_nocapture) const { (static_cast <bool
> (i_nocapture < OperandTraits<ReturnInst>::operands
(this) && "getOperand() out of range!") ? void (0) : __assert_fail
("i_nocapture < OperandTraits<ReturnInst>::operands(this) && \"getOperand() out of range!\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 2981, __extension__ __PRETTY_FUNCTION__)); return cast_or_null
<Value>( OperandTraits<ReturnInst>::op_begin(const_cast
<ReturnInst*>(this))[i_nocapture].get()); } void ReturnInst
::setOperand(unsigned i_nocapture, Value *Val_nocapture) { (static_cast
<bool> (i_nocapture < OperandTraits<ReturnInst>
::operands(this) && "setOperand() out of range!") ? void
(0) : __assert_fail ("i_nocapture < OperandTraits<ReturnInst>::operands(this) && \"setOperand() out of range!\""
, "/build/llvm-toolchain-snapshot-7~svn325118/include/llvm/IR/Instructions.h"
, 2981, __extension__ __PRETTY_FUNCTION__)); OperandTraits<
ReturnInst>::op_begin(this)[i_nocapture] = Val_nocapture; }
unsigned ReturnInst::getNumOperands() const { return OperandTraits
<ReturnInst>::operands(this); } template <int Idx_nocapture
> Use &ReturnInst::Op() { return this->OpFrom<Idx_nocapture
>(this); } template <int Idx_nocapture> const Use &
ReturnInst::Op() const { return this->OpFrom<Idx_nocapture
>(this); }
2982
2983//===----------------------------------------------------------------------===//
2984// BranchInst Class
2985//===----------------------------------------------------------------------===//
2986
2987//===---------------------------------------------------------------------------
2988/// Conditional or Unconditional Branch instruction.
2989///
2990class BranchInst : public TerminatorInst {
2991 /// Ops list - Branches are strange. The operands are ordered:
2992 /// [Cond, FalseDest,] TrueDest. This makes some accessors faster because
2993 /// they don't have to check for cond/uncond branchness. These are mostly
2994 /// accessed relative from op_end().
2995 BranchInst(const BranchInst &BI);
2996 // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
2997 // BranchInst(BB *B) - 'br B'
2998 // BranchInst(BB* T, BB *F, Value *C) - 'br C, T, F'
2999 // BranchInst(BB* B, Inst *I) - 'br B' insert before I
3000 // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
3001 // BranchInst(BB* B, BB *I) - 'br B' insert at end
3002 // BranchInst(BB* T, BB *F, Value *C, BB *I) - 'br C, T, F', insert at end
3003 explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = nullptr);
3004 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
3005 Instruction *InsertBefore = nullptr);
3006 BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd);
3007 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
3008 BasicBlock *InsertAtEnd);
3009
3010 void AssertOK();
3011
3012protected:
3013 // Note: I