Bug Summary

File:llvm/lib/IR/Instructions.cpp
Warning:line 429, column 3
Dereference of undefined pointer value

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 Instructions.cpp -analyzer-store=region -analyzer-opt-analyze-nested-blocks -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 -setup-static-analyzer -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -mthread-model posix -mframe-pointer=none -fmath-errno -fno-rounding-math -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -dwarf-column-info -fno-split-dwarf-inlining -debugger-tuning=gdb -ffunction-sections -fdata-sections -resource-dir /usr/lib/llvm-11/lib/clang/11.0.0 -D _DEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I /build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/build-llvm/lib/IR -I /build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR -I /build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/build-llvm/include -I /build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/include -U NDEBUG -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/x86_64-linux-gnu/c++/6.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/x86_64-linux-gnu/c++/6.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0/backward -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-11/lib/clang/11.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++14 -fdeprecated-macro -fdebug-compilation-dir /build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/build-llvm/lib/IR -fdebug-prefix-map=/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347=. -ferror-limit 19 -fmessage-length 0 -fvisibility-inlines-hidden -stack-protector 2 -fgnuc-version=4.2.1 -fobjc-runtime=gcc -fdiagnostics-show-option -vectorize-loops -vectorize-slp -analyzer-output=html -analyzer-config stable-report-filename=true -faddrsig -o /tmp/scan-build-2020-03-09-184146-41876-1 -x c++ /build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp
1//===- Instructions.cpp - Implement the LLVM instructions -----------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements all of the non-inline methods for the LLVM instruction
10// classes.
11//
12//===----------------------------------------------------------------------===//
13
14#include "llvm/IR/Instructions.h"
15#include "LLVMContextImpl.h"
16#include "llvm/ADT/None.h"
17#include "llvm/ADT/SmallVector.h"
18#include "llvm/ADT/Twine.h"
19#include "llvm/IR/Attributes.h"
20#include "llvm/IR/BasicBlock.h"
21#include "llvm/IR/CallSite.h"
22#include "llvm/IR/Constant.h"
23#include "llvm/IR/Constants.h"
24#include "llvm/IR/DataLayout.h"
25#include "llvm/IR/DerivedTypes.h"
26#include "llvm/IR/Function.h"
27#include "llvm/IR/InstrTypes.h"
28#include "llvm/IR/Instruction.h"
29#include "llvm/IR/Intrinsics.h"
30#include "llvm/IR/LLVMContext.h"
31#include "llvm/IR/MDBuilder.h"
32#include "llvm/IR/Metadata.h"
33#include "llvm/IR/Module.h"
34#include "llvm/IR/Operator.h"
35#include "llvm/IR/Type.h"
36#include "llvm/IR/Value.h"
37#include "llvm/Support/AtomicOrdering.h"
38#include "llvm/Support/Casting.h"
39#include "llvm/Support/ErrorHandling.h"
40#include "llvm/Support/MathExtras.h"
41#include "llvm/Support/TypeSize.h"
42#include <algorithm>
43#include <cassert>
44#include <cstdint>
45#include <vector>
46
47using namespace llvm;
48
49//===----------------------------------------------------------------------===//
50// AllocaInst Class
51//===----------------------------------------------------------------------===//
52
53Optional<uint64_t>
54AllocaInst::getAllocationSizeInBits(const DataLayout &DL) const {
55 uint64_t Size = DL.getTypeAllocSizeInBits(getAllocatedType());
56 if (isArrayAllocation()) {
57 auto C = dyn_cast<ConstantInt>(getArraySize());
58 if (!C)
59 return None;
60 Size *= C->getZExtValue();
61 }
62 return Size;
63}
64
65//===----------------------------------------------------------------------===//
66// CallSite Class
67//===----------------------------------------------------------------------===//
68
69User::op_iterator CallSite::getCallee() const {
70 return cast<CallBase>(getInstruction())->op_end() - 1;
71}
72
73//===----------------------------------------------------------------------===//
74// SelectInst Class
75//===----------------------------------------------------------------------===//
76
77/// areInvalidOperands - Return a string if the specified operands are invalid
78/// for a select operation, otherwise return null.
79const char *SelectInst::areInvalidOperands(Value *Op0, Value *Op1, Value *Op2) {
80 if (Op1->getType() != Op2->getType())
81 return "both values to select must have same type";
82
83 if (Op1->getType()->isTokenTy())
84 return "select values cannot have token type";
85
86 if (VectorType *VT = dyn_cast<VectorType>(Op0->getType())) {
87 // Vector select.
88 if (VT->getElementType() != Type::getInt1Ty(Op0->getContext()))
89 return "vector select condition element type must be i1";
90 VectorType *ET = dyn_cast<VectorType>(Op1->getType());
91 if (!ET)
92 return "selected values for vector select must be vectors";
93 if (ET->getNumElements() != VT->getNumElements())
94 return "vector select requires selected vectors to have "
95 "the same vector length as select condition";
96 } else if (Op0->getType() != Type::getInt1Ty(Op0->getContext())) {
97 return "select condition must be i1 or <n x i1>";
98 }
99 return nullptr;
100}
101
102//===----------------------------------------------------------------------===//
103// PHINode Class
104//===----------------------------------------------------------------------===//
105
106PHINode::PHINode(const PHINode &PN)
107 : Instruction(PN.getType(), Instruction::PHI, nullptr, PN.getNumOperands()),
108 ReservedSpace(PN.getNumOperands()) {
109 allocHungoffUses(PN.getNumOperands());
110 std::copy(PN.op_begin(), PN.op_end(), op_begin());
111 std::copy(PN.block_begin(), PN.block_end(), block_begin());
112 SubclassOptionalData = PN.SubclassOptionalData;
113}
114
115// removeIncomingValue - Remove an incoming value. This is useful if a
116// predecessor basic block is deleted.
117Value *PHINode::removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty) {
118 Value *Removed = getIncomingValue(Idx);
119
120 // Move everything after this operand down.
121 //
122 // FIXME: we could just swap with the end of the list, then erase. However,
123 // clients might not expect this to happen. The code as it is thrashes the
124 // use/def lists, which is kinda lame.
125 std::copy(op_begin() + Idx + 1, op_end(), op_begin() + Idx);
126 std::copy(block_begin() + Idx + 1, block_end(), block_begin() + Idx);
127
128 // Nuke the last value.
129 Op<-1>().set(nullptr);
130 setNumHungOffUseOperands(getNumOperands() - 1);
131
132 // If the PHI node is dead, because it has zero entries, nuke it now.
133 if (getNumOperands() == 0 && DeletePHIIfEmpty) {
134 // If anyone is using this PHI, make them use a dummy value instead...
135 replaceAllUsesWith(UndefValue::get(getType()));
136 eraseFromParent();
137 }
138 return Removed;
139}
140
141/// growOperands - grow operands - This grows the operand list in response
142/// to a push_back style of operation. This grows the number of ops by 1.5
143/// times.
144///
145void PHINode::growOperands() {
146 unsigned e = getNumOperands();
147 unsigned NumOps = e + e / 2;
148 if (NumOps < 2) NumOps = 2; // 2 op PHI nodes are VERY common.
149
150 ReservedSpace = NumOps;
151 growHungoffUses(ReservedSpace, /* IsPhi */ true);
152}
153
154/// hasConstantValue - If the specified PHI node always merges together the same
155/// value, return the value, otherwise return null.
156Value *PHINode::hasConstantValue() const {
157 // Exploit the fact that phi nodes always have at least one entry.
158 Value *ConstantValue = getIncomingValue(0);
159 for (unsigned i = 1, e = getNumIncomingValues(); i != e; ++i)
160 if (getIncomingValue(i) != ConstantValue && getIncomingValue(i) != this) {
161 if (ConstantValue != this)
162 return nullptr; // Incoming values not all the same.
163 // The case where the first value is this PHI.
164 ConstantValue = getIncomingValue(i);
165 }
166 if (ConstantValue == this)
167 return UndefValue::get(getType());
168 return ConstantValue;
169}
170
171/// hasConstantOrUndefValue - Whether the specified PHI node always merges
172/// together the same value, assuming that undefs result in the same value as
173/// non-undefs.
174/// Unlike \ref hasConstantValue, this does not return a value because the
175/// unique non-undef incoming value need not dominate the PHI node.
176bool PHINode::hasConstantOrUndefValue() const {
177 Value *ConstantValue = nullptr;
178 for (unsigned i = 0, e = getNumIncomingValues(); i != e; ++i) {
179 Value *Incoming = getIncomingValue(i);
180 if (Incoming != this && !isa<UndefValue>(Incoming)) {
181 if (ConstantValue && ConstantValue != Incoming)
182 return false;
183 ConstantValue = Incoming;
184 }
185 }
186 return true;
187}
188
189//===----------------------------------------------------------------------===//
190// LandingPadInst Implementation
191//===----------------------------------------------------------------------===//
192
193LandingPadInst::LandingPadInst(Type *RetTy, unsigned NumReservedValues,
194 const Twine &NameStr, Instruction *InsertBefore)
195 : Instruction(RetTy, Instruction::LandingPad, nullptr, 0, InsertBefore) {
196 init(NumReservedValues, NameStr);
197}
198
199LandingPadInst::LandingPadInst(Type *RetTy, unsigned NumReservedValues,
200 const Twine &NameStr, BasicBlock *InsertAtEnd)
201 : Instruction(RetTy, Instruction::LandingPad, nullptr, 0, InsertAtEnd) {
202 init(NumReservedValues, NameStr);
203}
204
205LandingPadInst::LandingPadInst(const LandingPadInst &LP)
206 : Instruction(LP.getType(), Instruction::LandingPad, nullptr,
207 LP.getNumOperands()),
208 ReservedSpace(LP.getNumOperands()) {
209 allocHungoffUses(LP.getNumOperands());
210 Use *OL = getOperandList();
211 const Use *InOL = LP.getOperandList();
212 for (unsigned I = 0, E = ReservedSpace; I != E; ++I)
213 OL[I] = InOL[I];
214
215 setCleanup(LP.isCleanup());
216}
217
218LandingPadInst *LandingPadInst::Create(Type *RetTy, unsigned NumReservedClauses,
219 const Twine &NameStr,
220 Instruction *InsertBefore) {
221 return new LandingPadInst(RetTy, NumReservedClauses, NameStr, InsertBefore);
222}
223
224LandingPadInst *LandingPadInst::Create(Type *RetTy, unsigned NumReservedClauses,
225 const Twine &NameStr,
226 BasicBlock *InsertAtEnd) {
227 return new LandingPadInst(RetTy, NumReservedClauses, NameStr, InsertAtEnd);
228}
229
230void LandingPadInst::init(unsigned NumReservedValues, const Twine &NameStr) {
231 ReservedSpace = NumReservedValues;
232 setNumHungOffUseOperands(0);
233 allocHungoffUses(ReservedSpace);
234 setName(NameStr);
235 setCleanup(false);
236}
237
238/// growOperands - grow operands - This grows the operand list in response to a
239/// push_back style of operation. This grows the number of ops by 2 times.
240void LandingPadInst::growOperands(unsigned Size) {
241 unsigned e = getNumOperands();
242 if (ReservedSpace >= e + Size) return;
243 ReservedSpace = (std::max(e, 1U) + Size / 2) * 2;
244 growHungoffUses(ReservedSpace);
245}
246
247void LandingPadInst::addClause(Constant *Val) {
248 unsigned OpNo = getNumOperands();
249 growOperands(1);
250 assert(OpNo < ReservedSpace && "Growing didn't work!")((OpNo < ReservedSpace && "Growing didn't work!") ?
static_cast<void> (0) : __assert_fail ("OpNo < ReservedSpace && \"Growing didn't work!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 250, __PRETTY_FUNCTION__))
;
251 setNumHungOffUseOperands(getNumOperands() + 1);
252 getOperandList()[OpNo] = Val;
253}
254
255//===----------------------------------------------------------------------===//
256// CallBase Implementation
257//===----------------------------------------------------------------------===//
258
259Function *CallBase::getCaller() { return getParent()->getParent(); }
260
261unsigned CallBase::getNumSubclassExtraOperandsDynamic() const {
262 assert(getOpcode() == Instruction::CallBr && "Unexpected opcode!")((getOpcode() == Instruction::CallBr && "Unexpected opcode!"
) ? static_cast<void> (0) : __assert_fail ("getOpcode() == Instruction::CallBr && \"Unexpected opcode!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 262, __PRETTY_FUNCTION__))
;
263 return cast<CallBrInst>(this)->getNumIndirectDests() + 1;
264}
265
266bool CallBase::isIndirectCall() const {
267 const Value *V = getCalledValue();
268 if (isa<Function>(V) || isa<Constant>(V))
269 return false;
270 if (const CallInst *CI = dyn_cast<CallInst>(this))
271 if (CI->isInlineAsm())
272 return false;
273 return true;
274}
275
276/// Tests if this call site must be tail call optimized. Only a CallInst can
277/// be tail call optimized.
278bool CallBase::isMustTailCall() const {
279 if (auto *CI = dyn_cast<CallInst>(this))
280 return CI->isMustTailCall();
281 return false;
282}
283
284/// Tests if this call site is marked as a tail call.
285bool CallBase::isTailCall() const {
286 if (auto *CI = dyn_cast<CallInst>(this))
287 return CI->isTailCall();
288 return false;
289}
290
291Intrinsic::ID CallBase::getIntrinsicID() const {
292 if (auto *F = getCalledFunction())
293 return F->getIntrinsicID();
294 return Intrinsic::not_intrinsic;
295}
296
297bool CallBase::isReturnNonNull() const {
298 if (hasRetAttr(Attribute::NonNull))
299 return true;
300
301 if (getDereferenceableBytes(AttributeList::ReturnIndex) > 0 &&
302 !NullPointerIsDefined(getCaller(),
303 getType()->getPointerAddressSpace()))
304 return true;
305
306 return false;
307}
308
309Value *CallBase::getReturnedArgOperand() const {
310 unsigned Index;
311
312 if (Attrs.hasAttrSomewhere(Attribute::Returned, &Index) && Index)
313 return getArgOperand(Index - AttributeList::FirstArgIndex);
314 if (const Function *F = getCalledFunction())
315 if (F->getAttributes().hasAttrSomewhere(Attribute::Returned, &Index) &&
316 Index)
317 return getArgOperand(Index - AttributeList::FirstArgIndex);
318
319 return nullptr;
320}
321
322bool CallBase::hasRetAttr(Attribute::AttrKind Kind) const {
323 if (Attrs.hasAttribute(AttributeList::ReturnIndex, Kind))
324 return true;
325
326 // Look at the callee, if available.
327 if (const Function *F = getCalledFunction())
328 return F->getAttributes().hasAttribute(AttributeList::ReturnIndex, Kind);
329 return false;
330}
331
332/// Determine whether the argument or parameter has the given attribute.
333bool CallBase::paramHasAttr(unsigned ArgNo, Attribute::AttrKind Kind) const {
334 assert(ArgNo < getNumArgOperands() && "Param index out of bounds!")((ArgNo < getNumArgOperands() && "Param index out of bounds!"
) ? static_cast<void> (0) : __assert_fail ("ArgNo < getNumArgOperands() && \"Param index out of bounds!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 334, __PRETTY_FUNCTION__))
;
335
336 if (Attrs.hasParamAttribute(ArgNo, Kind))
337 return true;
338 if (const Function *F = getCalledFunction())
339 return F->getAttributes().hasParamAttribute(ArgNo, Kind);
340 return false;
341}
342
343bool CallBase::hasFnAttrOnCalledFunction(Attribute::AttrKind Kind) const {
344 if (const Function *F = getCalledFunction())
345 return F->getAttributes().hasAttribute(AttributeList::FunctionIndex, Kind);
346 return false;
347}
348
349bool CallBase::hasFnAttrOnCalledFunction(StringRef Kind) const {
350 if (const Function *F = getCalledFunction())
351 return F->getAttributes().hasAttribute(AttributeList::FunctionIndex, Kind);
352 return false;
353}
354
355void CallBase::getOperandBundlesAsDefs(
356 SmallVectorImpl<OperandBundleDef> &Defs) const {
357 for (unsigned i = 0, e = getNumOperandBundles(); i != e; ++i)
358 Defs.emplace_back(getOperandBundleAt(i));
359}
360
361CallBase::op_iterator
362CallBase::populateBundleOperandInfos(ArrayRef<OperandBundleDef> Bundles,
363 const unsigned BeginIndex) {
364 auto It = op_begin() + BeginIndex;
365 for (auto &B : Bundles)
366 It = std::copy(B.input_begin(), B.input_end(), It);
367
368 auto *ContextImpl = getContext().pImpl;
369 auto BI = Bundles.begin();
370 unsigned CurrentIndex = BeginIndex;
371
372 for (auto &BOI : bundle_op_infos()) {
373 assert(BI != Bundles.end() && "Incorrect allocation?")((BI != Bundles.end() && "Incorrect allocation?") ? static_cast
<void> (0) : __assert_fail ("BI != Bundles.end() && \"Incorrect allocation?\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 373, __PRETTY_FUNCTION__))
;
374
375 BOI.Tag = ContextImpl->getOrInsertBundleTag(BI->getTag());
376 BOI.Begin = CurrentIndex;
377 BOI.End = CurrentIndex + BI->input_size();
378 CurrentIndex = BOI.End;
379 BI++;
380 }
381
382 assert(BI == Bundles.end() && "Incorrect allocation?")((BI == Bundles.end() && "Incorrect allocation?") ? static_cast
<void> (0) : __assert_fail ("BI == Bundles.end() && \"Incorrect allocation?\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 382, __PRETTY_FUNCTION__))
;
383
384 return It;
385}
386
387CallBase::BundleOpInfo &CallBase::getBundleOpInfoForOperand(unsigned OpIdx) {
388 /// When there isn't many bundles, we do a simple linear search.
389 /// Else fallback to a binary-search that use the fact that bundles usually
390 /// have similar number of argument to get faster convergence.
391 if (bundle_op_info_end() - bundle_op_info_begin() < 8) {
1
Assuming the condition is false
2
Taking false branch
392 for (auto &BOI : bundle_op_infos())
393 if (BOI.Begin <= OpIdx && OpIdx < BOI.End)
394 return BOI;
395
396 llvm_unreachable("Did not find operand bundle for operand!")::llvm::llvm_unreachable_internal("Did not find operand bundle for operand!"
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 396)
;
397 }
398
399 assert(OpIdx >= arg_size() && "the Idx is not in the operand bundles")((OpIdx >= arg_size() && "the Idx is not in the operand bundles"
) ? static_cast<void> (0) : __assert_fail ("OpIdx >= arg_size() && \"the Idx is not in the operand bundles\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 399, __PRETTY_FUNCTION__))
;
3
Assuming the condition is true
4
'?' condition is true
400 assert(bundle_op_info_end() - bundle_op_info_begin() > 0 &&((bundle_op_info_end() - bundle_op_info_begin() > 0 &&
OpIdx < std::prev(bundle_op_info_end())->End &&
"The Idx isn't in the operand bundle") ? static_cast<void
> (0) : __assert_fail ("bundle_op_info_end() - bundle_op_info_begin() > 0 && OpIdx < std::prev(bundle_op_info_end())->End && \"The Idx isn't in the operand bundle\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 402, __PRETTY_FUNCTION__))
5
Assuming the condition is true
6
Assuming 'OpIdx' is < field 'End'
7
'?' condition is true
401 OpIdx < std::prev(bundle_op_info_end())->End &&((bundle_op_info_end() - bundle_op_info_begin() > 0 &&
OpIdx < std::prev(bundle_op_info_end())->End &&
"The Idx isn't in the operand bundle") ? static_cast<void
> (0) : __assert_fail ("bundle_op_info_end() - bundle_op_info_begin() > 0 && OpIdx < std::prev(bundle_op_info_end())->End && \"The Idx isn't in the operand bundle\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 402, __PRETTY_FUNCTION__))
402 "The Idx isn't in the operand bundle")((bundle_op_info_end() - bundle_op_info_begin() > 0 &&
OpIdx < std::prev(bundle_op_info_end())->End &&
"The Idx isn't in the operand bundle") ? static_cast<void
> (0) : __assert_fail ("bundle_op_info_end() - bundle_op_info_begin() > 0 && OpIdx < std::prev(bundle_op_info_end())->End && \"The Idx isn't in the operand bundle\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 402, __PRETTY_FUNCTION__))
;
403
404 /// We need a decimal number below and to prevent using floating point numbers
405 /// we use an intergal value multiplied by this constant.
406 constexpr unsigned NumberScaling = 1024;
407
408 bundle_op_iterator Begin = bundle_op_info_begin();
409 bundle_op_iterator End = bundle_op_info_end();
410 bundle_op_iterator Current;
411
412 while (Begin != End) {
8
Loop condition is false. Execution continues on line 429
413 unsigned ScaledOperandPerBundle =
414 NumberScaling * (std::prev(End)->End - Begin->Begin) / (End - Begin);
415 Current = Begin + (((OpIdx - Begin->Begin) * NumberScaling) /
416 ScaledOperandPerBundle);
417 if (Current >= End)
418 Current = std::prev(End);
419 assert(Current < End && Current >= Begin &&((Current < End && Current >= Begin && "the operand bundle doesn't cover every value in the range"
) ? static_cast<void> (0) : __assert_fail ("Current < End && Current >= Begin && \"the operand bundle doesn't cover every value in the range\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 420, __PRETTY_FUNCTION__))
420 "the operand bundle doesn't cover every value in the range")((Current < End && Current >= Begin && "the operand bundle doesn't cover every value in the range"
) ? static_cast<void> (0) : __assert_fail ("Current < End && Current >= Begin && \"the operand bundle doesn't cover every value in the range\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 420, __PRETTY_FUNCTION__))
;
421 if (OpIdx >= Current->Begin && OpIdx < Current->End)
422 break;
423 if (OpIdx >= Current->End)
424 Begin = Current + 1;
425 else
426 End = Current;
427 }
428
429 assert(OpIdx >= Current->Begin && OpIdx < Current->End &&((OpIdx >= Current->Begin && OpIdx < Current
->End && "the operand bundle doesn't cover every value in the range"
) ? static_cast<void> (0) : __assert_fail ("OpIdx >= Current->Begin && OpIdx < Current->End && \"the operand bundle doesn't cover every value in the range\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 430, __PRETTY_FUNCTION__))
9
Dereference of undefined pointer value
430 "the operand bundle doesn't cover every value in the range")((OpIdx >= Current->Begin && OpIdx < Current
->End && "the operand bundle doesn't cover every value in the range"
) ? static_cast<void> (0) : __assert_fail ("OpIdx >= Current->Begin && OpIdx < Current->End && \"the operand bundle doesn't cover every value in the range\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 430, __PRETTY_FUNCTION__))
;
431 return *Current;
432}
433
434//===----------------------------------------------------------------------===//
435// CallInst Implementation
436//===----------------------------------------------------------------------===//
437
438void CallInst::init(FunctionType *FTy, Value *Func, ArrayRef<Value *> Args,
439 ArrayRef<OperandBundleDef> Bundles, const Twine &NameStr) {
440 this->FTy = FTy;
441 assert(getNumOperands() == Args.size() + CountBundleInputs(Bundles) + 1 &&((getNumOperands() == Args.size() + CountBundleInputs(Bundles
) + 1 && "NumOperands not set up?") ? static_cast<
void> (0) : __assert_fail ("getNumOperands() == Args.size() + CountBundleInputs(Bundles) + 1 && \"NumOperands not set up?\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 442, __PRETTY_FUNCTION__))
442 "NumOperands not set up?")((getNumOperands() == Args.size() + CountBundleInputs(Bundles
) + 1 && "NumOperands not set up?") ? static_cast<
void> (0) : __assert_fail ("getNumOperands() == Args.size() + CountBundleInputs(Bundles) + 1 && \"NumOperands not set up?\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 442, __PRETTY_FUNCTION__))
;
443 setCalledOperand(Func);
444
445#ifndef NDEBUG
446 assert((Args.size() == FTy->getNumParams() ||(((Args.size() == FTy->getNumParams() || (FTy->isVarArg
() && Args.size() > FTy->getNumParams())) &&
"Calling a function with bad signature!") ? static_cast<void
> (0) : __assert_fail ("(Args.size() == FTy->getNumParams() || (FTy->isVarArg() && Args.size() > FTy->getNumParams())) && \"Calling a function with bad signature!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 448, __PRETTY_FUNCTION__))
447 (FTy->isVarArg() && Args.size() > FTy->getNumParams())) &&(((Args.size() == FTy->getNumParams() || (FTy->isVarArg
() && Args.size() > FTy->getNumParams())) &&
"Calling a function with bad signature!") ? static_cast<void
> (0) : __assert_fail ("(Args.size() == FTy->getNumParams() || (FTy->isVarArg() && Args.size() > FTy->getNumParams())) && \"Calling a function with bad signature!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 448, __PRETTY_FUNCTION__))
448 "Calling a function with bad signature!")(((Args.size() == FTy->getNumParams() || (FTy->isVarArg
() && Args.size() > FTy->getNumParams())) &&
"Calling a function with bad signature!") ? static_cast<void
> (0) : __assert_fail ("(Args.size() == FTy->getNumParams() || (FTy->isVarArg() && Args.size() > FTy->getNumParams())) && \"Calling a function with bad signature!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 448, __PRETTY_FUNCTION__))
;
449
450 for (unsigned i = 0; i != Args.size(); ++i)
451 assert((i >= FTy->getNumParams() ||(((i >= FTy->getNumParams() || FTy->getParamType(i) ==
Args[i]->getType()) && "Calling a function with a bad signature!"
) ? static_cast<void> (0) : __assert_fail ("(i >= FTy->getNumParams() || FTy->getParamType(i) == Args[i]->getType()) && \"Calling a function with a bad signature!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 453, __PRETTY_FUNCTION__))
452 FTy->getParamType(i) == Args[i]->getType()) &&(((i >= FTy->getNumParams() || FTy->getParamType(i) ==
Args[i]->getType()) && "Calling a function with a bad signature!"
) ? static_cast<void> (0) : __assert_fail ("(i >= FTy->getNumParams() || FTy->getParamType(i) == Args[i]->getType()) && \"Calling a function with a bad signature!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 453, __PRETTY_FUNCTION__))
453 "Calling a function with a bad signature!")(((i >= FTy->getNumParams() || FTy->getParamType(i) ==
Args[i]->getType()) && "Calling a function with a bad signature!"
) ? static_cast<void> (0) : __assert_fail ("(i >= FTy->getNumParams() || FTy->getParamType(i) == Args[i]->getType()) && \"Calling a function with a bad signature!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 453, __PRETTY_FUNCTION__))
;
454#endif
455
456 llvm::copy(Args, op_begin());
457
458 auto It = populateBundleOperandInfos(Bundles, Args.size());
459 (void)It;
460 assert(It + 1 == op_end() && "Should add up!")((It + 1 == op_end() && "Should add up!") ? static_cast
<void> (0) : __assert_fail ("It + 1 == op_end() && \"Should add up!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 460, __PRETTY_FUNCTION__))
;
461
462 setName(NameStr);
463}
464
465void CallInst::init(FunctionType *FTy, Value *Func, const Twine &NameStr) {
466 this->FTy = FTy;
467 assert(getNumOperands() == 1 && "NumOperands not set up?")((getNumOperands() == 1 && "NumOperands not set up?")
? static_cast<void> (0) : __assert_fail ("getNumOperands() == 1 && \"NumOperands not set up?\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 467, __PRETTY_FUNCTION__))
;
468 setCalledOperand(Func);
469
470 assert(FTy->getNumParams() == 0 && "Calling a function with bad signature")((FTy->getNumParams() == 0 && "Calling a function with bad signature"
) ? static_cast<void> (0) : __assert_fail ("FTy->getNumParams() == 0 && \"Calling a function with bad signature\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 470, __PRETTY_FUNCTION__))
;
471
472 setName(NameStr);
473}
474
475CallInst::CallInst(FunctionType *Ty, Value *Func, const Twine &Name,
476 Instruction *InsertBefore)
477 : CallBase(Ty->getReturnType(), Instruction::Call,
478 OperandTraits<CallBase>::op_end(this) - 1, 1, InsertBefore) {
479 init(Ty, Func, Name);
480}
481
482CallInst::CallInst(FunctionType *Ty, Value *Func, const Twine &Name,
483 BasicBlock *InsertAtEnd)
484 : CallBase(Ty->getReturnType(), Instruction::Call,
485 OperandTraits<CallBase>::op_end(this) - 1, 1, InsertAtEnd) {
486 init(Ty, Func, Name);
487}
488
489CallInst::CallInst(const CallInst &CI)
490 : CallBase(CI.Attrs, CI.FTy, CI.getType(), Instruction::Call,
491 OperandTraits<CallBase>::op_end(this) - CI.getNumOperands(),
492 CI.getNumOperands()) {
493 setTailCallKind(CI.getTailCallKind());
494 setCallingConv(CI.getCallingConv());
495
496 std::copy(CI.op_begin(), CI.op_end(), op_begin());
497 std::copy(CI.bundle_op_info_begin(), CI.bundle_op_info_end(),
498 bundle_op_info_begin());
499 SubclassOptionalData = CI.SubclassOptionalData;
500}
501
502CallInst *CallInst::Create(CallInst *CI, ArrayRef<OperandBundleDef> OpB,
503 Instruction *InsertPt) {
504 std::vector<Value *> Args(CI->arg_begin(), CI->arg_end());
505
506 auto *NewCI = CallInst::Create(CI->getFunctionType(), CI->getCalledValue(),
507 Args, OpB, CI->getName(), InsertPt);
508 NewCI->setTailCallKind(CI->getTailCallKind());
509 NewCI->setCallingConv(CI->getCallingConv());
510 NewCI->SubclassOptionalData = CI->SubclassOptionalData;
511 NewCI->setAttributes(CI->getAttributes());
512 NewCI->setDebugLoc(CI->getDebugLoc());
513 return NewCI;
514}
515
516// Update profile weight for call instruction by scaling it using the ratio
517// of S/T. The meaning of "branch_weights" meta data for call instruction is
518// transfered to represent call count.
519void CallInst::updateProfWeight(uint64_t S, uint64_t T) {
520 auto *ProfileData = getMetadata(LLVMContext::MD_prof);
521 if (ProfileData == nullptr)
522 return;
523
524 auto *ProfDataName = dyn_cast<MDString>(ProfileData->getOperand(0));
525 if (!ProfDataName || (!ProfDataName->getString().equals("branch_weights") &&
526 !ProfDataName->getString().equals("VP")))
527 return;
528
529 if (T == 0) {
530 LLVM_DEBUG(dbgs() << "Attempting to update profile weights will result in "do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType
("ir")) { dbgs() << "Attempting to update profile weights will result in "
"div by 0. Ignoring. Likely the function " << getParent
()->getParent()->getName() << " has 0 entry count, and contains call instructions "
"with non-zero prof info."; } } while (false)
531 "div by 0. Ignoring. Likely the function "do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType
("ir")) { dbgs() << "Attempting to update profile weights will result in "
"div by 0. Ignoring. Likely the function " << getParent
()->getParent()->getName() << " has 0 entry count, and contains call instructions "
"with non-zero prof info."; } } while (false)
532 << getParent()->getParent()->getName()do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType
("ir")) { dbgs() << "Attempting to update profile weights will result in "
"div by 0. Ignoring. Likely the function " << getParent
()->getParent()->getName() << " has 0 entry count, and contains call instructions "
"with non-zero prof info."; } } while (false)
533 << " has 0 entry count, and contains call instructions "do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType
("ir")) { dbgs() << "Attempting to update profile weights will result in "
"div by 0. Ignoring. Likely the function " << getParent
()->getParent()->getName() << " has 0 entry count, and contains call instructions "
"with non-zero prof info."; } } while (false)
534 "with non-zero prof info.")do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType
("ir")) { dbgs() << "Attempting to update profile weights will result in "
"div by 0. Ignoring. Likely the function " << getParent
()->getParent()->getName() << " has 0 entry count, and contains call instructions "
"with non-zero prof info."; } } while (false)
;
535 return;
536 }
537
538 MDBuilder MDB(getContext());
539 SmallVector<Metadata *, 3> Vals;
540 Vals.push_back(ProfileData->getOperand(0));
541 APInt APS(128, S), APT(128, T);
542 if (ProfDataName->getString().equals("branch_weights") &&
543 ProfileData->getNumOperands() > 0) {
544 // Using APInt::div may be expensive, but most cases should fit 64 bits.
545 APInt Val(128, mdconst::dyn_extract<ConstantInt>(ProfileData->getOperand(1))
546 ->getValue()
547 .getZExtValue());
548 Val *= APS;
549 Vals.push_back(MDB.createConstant(ConstantInt::get(
550 Type::getInt64Ty(getContext()), Val.udiv(APT).getLimitedValue())));
551 } else if (ProfDataName->getString().equals("VP"))
552 for (unsigned i = 1; i < ProfileData->getNumOperands(); i += 2) {
553 // The first value is the key of the value profile, which will not change.
554 Vals.push_back(ProfileData->getOperand(i));
555 // Using APInt::div may be expensive, but most cases should fit 64 bits.
556 APInt Val(128,
557 mdconst::dyn_extract<ConstantInt>(ProfileData->getOperand(i + 1))
558 ->getValue()
559 .getZExtValue());
560 Val *= APS;
561 Vals.push_back(MDB.createConstant(
562 ConstantInt::get(Type::getInt64Ty(getContext()),
563 Val.udiv(APT).getLimitedValue())));
564 }
565 setMetadata(LLVMContext::MD_prof, MDNode::get(getContext(), Vals));
566}
567
568/// IsConstantOne - Return true only if val is constant int 1
569static bool IsConstantOne(Value *val) {
570 assert(val && "IsConstantOne does not work with nullptr val")((val && "IsConstantOne does not work with nullptr val"
) ? static_cast<void> (0) : __assert_fail ("val && \"IsConstantOne does not work with nullptr val\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 570, __PRETTY_FUNCTION__))
;
571 const ConstantInt *CVal = dyn_cast<ConstantInt>(val);
572 return CVal && CVal->isOne();
573}
574
575static Instruction *createMalloc(Instruction *InsertBefore,
576 BasicBlock *InsertAtEnd, Type *IntPtrTy,
577 Type *AllocTy, Value *AllocSize,
578 Value *ArraySize,
579 ArrayRef<OperandBundleDef> OpB,
580 Function *MallocF, const Twine &Name) {
581 assert(((!InsertBefore && InsertAtEnd) || (InsertBefore && !InsertAtEnd)) &&((((!InsertBefore && InsertAtEnd) || (InsertBefore &&
!InsertAtEnd)) && "createMalloc needs either InsertBefore or InsertAtEnd"
) ? static_cast<void> (0) : __assert_fail ("((!InsertBefore && InsertAtEnd) || (InsertBefore && !InsertAtEnd)) && \"createMalloc needs either InsertBefore or InsertAtEnd\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 582, __PRETTY_FUNCTION__))
582 "createMalloc needs either InsertBefore or InsertAtEnd")((((!InsertBefore && InsertAtEnd) || (InsertBefore &&
!InsertAtEnd)) && "createMalloc needs either InsertBefore or InsertAtEnd"
) ? static_cast<void> (0) : __assert_fail ("((!InsertBefore && InsertAtEnd) || (InsertBefore && !InsertAtEnd)) && \"createMalloc needs either InsertBefore or InsertAtEnd\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 582, __PRETTY_FUNCTION__))
;
583
584 // malloc(type) becomes:
585 // bitcast (i8* malloc(typeSize)) to type*
586 // malloc(type, arraySize) becomes:
587 // bitcast (i8* malloc(typeSize*arraySize)) to type*
588 if (!ArraySize)
589 ArraySize = ConstantInt::get(IntPtrTy, 1);
590 else if (ArraySize->getType() != IntPtrTy) {
591 if (InsertBefore)
592 ArraySize = CastInst::CreateIntegerCast(ArraySize, IntPtrTy, false,
593 "", InsertBefore);
594 else
595 ArraySize = CastInst::CreateIntegerCast(ArraySize, IntPtrTy, false,
596 "", InsertAtEnd);
597 }
598
599 if (!IsConstantOne(ArraySize)) {
600 if (IsConstantOne(AllocSize)) {
601 AllocSize = ArraySize; // Operand * 1 = Operand
602 } else if (Constant *CO = dyn_cast<Constant>(ArraySize)) {
603 Constant *Scale = ConstantExpr::getIntegerCast(CO, IntPtrTy,
604 false /*ZExt*/);
605 // Malloc arg is constant product of type size and array size
606 AllocSize = ConstantExpr::getMul(Scale, cast<Constant>(AllocSize));
607 } else {
608 // Multiply type size by the array size...
609 if (InsertBefore)
610 AllocSize = BinaryOperator::CreateMul(ArraySize, AllocSize,
611 "mallocsize", InsertBefore);
612 else
613 AllocSize = BinaryOperator::CreateMul(ArraySize, AllocSize,
614 "mallocsize", InsertAtEnd);
615 }
616 }
617
618 assert(AllocSize->getType() == IntPtrTy && "malloc arg is wrong size")((AllocSize->getType() == IntPtrTy && "malloc arg is wrong size"
) ? static_cast<void> (0) : __assert_fail ("AllocSize->getType() == IntPtrTy && \"malloc arg is wrong size\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 618, __PRETTY_FUNCTION__))
;
619 // Create the call to Malloc.
620 BasicBlock *BB = InsertBefore ? InsertBefore->getParent() : InsertAtEnd;
621 Module *M = BB->getParent()->getParent();
622 Type *BPTy = Type::getInt8PtrTy(BB->getContext());
623 FunctionCallee MallocFunc = MallocF;
624 if (!MallocFunc)
625 // prototype malloc as "void *malloc(size_t)"
626 MallocFunc = M->getOrInsertFunction("malloc", BPTy, IntPtrTy);
627 PointerType *AllocPtrType = PointerType::getUnqual(AllocTy);
628 CallInst *MCall = nullptr;
629 Instruction *Result = nullptr;
630 if (InsertBefore) {
631 MCall = CallInst::Create(MallocFunc, AllocSize, OpB, "malloccall",
632 InsertBefore);
633 Result = MCall;
634 if (Result->getType() != AllocPtrType)
635 // Create a cast instruction to convert to the right type...
636 Result = new BitCastInst(MCall, AllocPtrType, Name, InsertBefore);
637 } else {
638 MCall = CallInst::Create(MallocFunc, AllocSize, OpB, "malloccall");
639 Result = MCall;
640 if (Result->getType() != AllocPtrType) {
641 InsertAtEnd->getInstList().push_back(MCall);
642 // Create a cast instruction to convert to the right type...
643 Result = new BitCastInst(MCall, AllocPtrType, Name);
644 }
645 }
646 MCall->setTailCall();
647 if (Function *F = dyn_cast<Function>(MallocFunc.getCallee())) {
648 MCall->setCallingConv(F->getCallingConv());
649 if (!F->returnDoesNotAlias())
650 F->setReturnDoesNotAlias();
651 }
652 assert(!MCall->getType()->isVoidTy() && "Malloc has void return type")((!MCall->getType()->isVoidTy() && "Malloc has void return type"
) ? static_cast<void> (0) : __assert_fail ("!MCall->getType()->isVoidTy() && \"Malloc has void return type\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 652, __PRETTY_FUNCTION__))
;
653
654 return Result;
655}
656
657/// CreateMalloc - Generate the IR for a call to malloc:
658/// 1. Compute the malloc call's argument as the specified type's size,
659/// possibly multiplied by the array size if the array size is not
660/// constant 1.
661/// 2. Call malloc with that argument.
662/// 3. Bitcast the result of the malloc call to the specified type.
663Instruction *CallInst::CreateMalloc(Instruction *InsertBefore,
664 Type *IntPtrTy, Type *AllocTy,
665 Value *AllocSize, Value *ArraySize,
666 Function *MallocF,
667 const Twine &Name) {
668 return createMalloc(InsertBefore, nullptr, IntPtrTy, AllocTy, AllocSize,
669 ArraySize, None, MallocF, Name);
670}
671Instruction *CallInst::CreateMalloc(Instruction *InsertBefore,
672 Type *IntPtrTy, Type *AllocTy,
673 Value *AllocSize, Value *ArraySize,
674 ArrayRef<OperandBundleDef> OpB,
675 Function *MallocF,
676 const Twine &Name) {
677 return createMalloc(InsertBefore, nullptr, IntPtrTy, AllocTy, AllocSize,
678 ArraySize, OpB, MallocF, Name);
679}
680
681/// CreateMalloc - Generate the IR for a call to malloc:
682/// 1. Compute the malloc call's argument as the specified type's size,
683/// possibly multiplied by the array size if the array size is not
684/// constant 1.
685/// 2. Call malloc with that argument.
686/// 3. Bitcast the result of the malloc call to the specified type.
687/// Note: This function does not add the bitcast to the basic block, that is the
688/// responsibility of the caller.
689Instruction *CallInst::CreateMalloc(BasicBlock *InsertAtEnd,
690 Type *IntPtrTy, Type *AllocTy,
691 Value *AllocSize, Value *ArraySize,
692 Function *MallocF, const Twine &Name) {
693 return createMalloc(nullptr, InsertAtEnd, IntPtrTy, AllocTy, AllocSize,
694 ArraySize, None, MallocF, Name);
695}
696Instruction *CallInst::CreateMalloc(BasicBlock *InsertAtEnd,
697 Type *IntPtrTy, Type *AllocTy,
698 Value *AllocSize, Value *ArraySize,
699 ArrayRef<OperandBundleDef> OpB,
700 Function *MallocF, const Twine &Name) {
701 return createMalloc(nullptr, InsertAtEnd, IntPtrTy, AllocTy, AllocSize,
702 ArraySize, OpB, MallocF, Name);
703}
704
705static Instruction *createFree(Value *Source,
706 ArrayRef<OperandBundleDef> Bundles,
707 Instruction *InsertBefore,
708 BasicBlock *InsertAtEnd) {
709 assert(((!InsertBefore && InsertAtEnd) || (InsertBefore && !InsertAtEnd)) &&((((!InsertBefore && InsertAtEnd) || (InsertBefore &&
!InsertAtEnd)) && "createFree needs either InsertBefore or InsertAtEnd"
) ? static_cast<void> (0) : __assert_fail ("((!InsertBefore && InsertAtEnd) || (InsertBefore && !InsertAtEnd)) && \"createFree needs either InsertBefore or InsertAtEnd\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 710, __PRETTY_FUNCTION__))
710 "createFree needs either InsertBefore or InsertAtEnd")((((!InsertBefore && InsertAtEnd) || (InsertBefore &&
!InsertAtEnd)) && "createFree needs either InsertBefore or InsertAtEnd"
) ? static_cast<void> (0) : __assert_fail ("((!InsertBefore && InsertAtEnd) || (InsertBefore && !InsertAtEnd)) && \"createFree needs either InsertBefore or InsertAtEnd\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 710, __PRETTY_FUNCTION__))
;
711 assert(Source->getType()->isPointerTy() &&((Source->getType()->isPointerTy() && "Can not free something of nonpointer type!"
) ? static_cast<void> (0) : __assert_fail ("Source->getType()->isPointerTy() && \"Can not free something of nonpointer type!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 712, __PRETTY_FUNCTION__))
712 "Can not free something of nonpointer type!")((Source->getType()->isPointerTy() && "Can not free something of nonpointer type!"
) ? static_cast<void> (0) : __assert_fail ("Source->getType()->isPointerTy() && \"Can not free something of nonpointer type!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 712, __PRETTY_FUNCTION__))
;
713
714 BasicBlock *BB = InsertBefore ? InsertBefore->getParent() : InsertAtEnd;
715 Module *M = BB->getParent()->getParent();
716
717 Type *VoidTy = Type::getVoidTy(M->getContext());
718 Type *IntPtrTy = Type::getInt8PtrTy(M->getContext());
719 // prototype free as "void free(void*)"
720 FunctionCallee FreeFunc = M->getOrInsertFunction("free", VoidTy, IntPtrTy);
721 CallInst *Result = nullptr;
722 Value *PtrCast = Source;
723 if (InsertBefore) {
724 if (Source->getType() != IntPtrTy)
725 PtrCast = new BitCastInst(Source, IntPtrTy, "", InsertBefore);
726 Result = CallInst::Create(FreeFunc, PtrCast, Bundles, "", InsertBefore);
727 } else {
728 if (Source->getType() != IntPtrTy)
729 PtrCast = new BitCastInst(Source, IntPtrTy, "", InsertAtEnd);
730 Result = CallInst::Create(FreeFunc, PtrCast, Bundles, "");
731 }
732 Result->setTailCall();
733 if (Function *F = dyn_cast<Function>(FreeFunc.getCallee()))
734 Result->setCallingConv(F->getCallingConv());
735
736 return Result;
737}
738
739/// CreateFree - Generate the IR for a call to the builtin free function.
740Instruction *CallInst::CreateFree(Value *Source, Instruction *InsertBefore) {
741 return createFree(Source, None, InsertBefore, nullptr);
742}
743Instruction *CallInst::CreateFree(Value *Source,
744 ArrayRef<OperandBundleDef> Bundles,
745 Instruction *InsertBefore) {
746 return createFree(Source, Bundles, InsertBefore, nullptr);
747}
748
749/// CreateFree - Generate the IR for a call to the builtin free function.
750/// Note: This function does not add the call to the basic block, that is the
751/// responsibility of the caller.
752Instruction *CallInst::CreateFree(Value *Source, BasicBlock *InsertAtEnd) {
753 Instruction *FreeCall = createFree(Source, None, nullptr, InsertAtEnd);
754 assert(FreeCall && "CreateFree did not create a CallInst")((FreeCall && "CreateFree did not create a CallInst")
? static_cast<void> (0) : __assert_fail ("FreeCall && \"CreateFree did not create a CallInst\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 754, __PRETTY_FUNCTION__))
;
755 return FreeCall;
756}
757Instruction *CallInst::CreateFree(Value *Source,
758 ArrayRef<OperandBundleDef> Bundles,
759 BasicBlock *InsertAtEnd) {
760 Instruction *FreeCall = createFree(Source, Bundles, nullptr, InsertAtEnd);
761 assert(FreeCall && "CreateFree did not create a CallInst")((FreeCall && "CreateFree did not create a CallInst")
? static_cast<void> (0) : __assert_fail ("FreeCall && \"CreateFree did not create a CallInst\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 761, __PRETTY_FUNCTION__))
;
762 return FreeCall;
763}
764
765//===----------------------------------------------------------------------===//
766// InvokeInst Implementation
767//===----------------------------------------------------------------------===//
768
769void InvokeInst::init(FunctionType *FTy, Value *Fn, BasicBlock *IfNormal,
770 BasicBlock *IfException, ArrayRef<Value *> Args,
771 ArrayRef<OperandBundleDef> Bundles,
772 const Twine &NameStr) {
773 this->FTy = FTy;
774
775 assert((int)getNumOperands() ==(((int)getNumOperands() == ComputeNumOperands(Args.size(), CountBundleInputs
(Bundles)) && "NumOperands not set up?") ? static_cast
<void> (0) : __assert_fail ("(int)getNumOperands() == ComputeNumOperands(Args.size(), CountBundleInputs(Bundles)) && \"NumOperands not set up?\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 777, __PRETTY_FUNCTION__))
776 ComputeNumOperands(Args.size(), CountBundleInputs(Bundles)) &&(((int)getNumOperands() == ComputeNumOperands(Args.size(), CountBundleInputs
(Bundles)) && "NumOperands not set up?") ? static_cast
<void> (0) : __assert_fail ("(int)getNumOperands() == ComputeNumOperands(Args.size(), CountBundleInputs(Bundles)) && \"NumOperands not set up?\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 777, __PRETTY_FUNCTION__))
777 "NumOperands not set up?")(((int)getNumOperands() == ComputeNumOperands(Args.size(), CountBundleInputs
(Bundles)) && "NumOperands not set up?") ? static_cast
<void> (0) : __assert_fail ("(int)getNumOperands() == ComputeNumOperands(Args.size(), CountBundleInputs(Bundles)) && \"NumOperands not set up?\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 777, __PRETTY_FUNCTION__))
;
778 setNormalDest(IfNormal);
779 setUnwindDest(IfException);
780 setCalledOperand(Fn);
781
782#ifndef NDEBUG
783 assert(((Args.size() == FTy->getNumParams()) ||((((Args.size() == FTy->getNumParams()) || (FTy->isVarArg
() && Args.size() > FTy->getNumParams())) &&
"Invoking a function with bad signature") ? static_cast<void
> (0) : __assert_fail ("((Args.size() == FTy->getNumParams()) || (FTy->isVarArg() && Args.size() > FTy->getNumParams())) && \"Invoking a function with bad signature\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 785, __PRETTY_FUNCTION__))
784 (FTy->isVarArg() && Args.size() > FTy->getNumParams())) &&((((Args.size() == FTy->getNumParams()) || (FTy->isVarArg
() && Args.size() > FTy->getNumParams())) &&
"Invoking a function with bad signature") ? static_cast<void
> (0) : __assert_fail ("((Args.size() == FTy->getNumParams()) || (FTy->isVarArg() && Args.size() > FTy->getNumParams())) && \"Invoking a function with bad signature\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 785, __PRETTY_FUNCTION__))
785 "Invoking a function with bad signature")((((Args.size() == FTy->getNumParams()) || (FTy->isVarArg
() && Args.size() > FTy->getNumParams())) &&
"Invoking a function with bad signature") ? static_cast<void
> (0) : __assert_fail ("((Args.size() == FTy->getNumParams()) || (FTy->isVarArg() && Args.size() > FTy->getNumParams())) && \"Invoking a function with bad signature\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 785, __PRETTY_FUNCTION__))
;
786
787 for (unsigned i = 0, e = Args.size(); i != e; i++)
788 assert((i >= FTy->getNumParams() ||(((i >= FTy->getNumParams() || FTy->getParamType(i) ==
Args[i]->getType()) && "Invoking a function with a bad signature!"
) ? static_cast<void> (0) : __assert_fail ("(i >= FTy->getNumParams() || FTy->getParamType(i) == Args[i]->getType()) && \"Invoking a function with a bad signature!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 790, __PRETTY_FUNCTION__))
789 FTy->getParamType(i) == Args[i]->getType()) &&(((i >= FTy->getNumParams() || FTy->getParamType(i) ==
Args[i]->getType()) && "Invoking a function with a bad signature!"
) ? static_cast<void> (0) : __assert_fail ("(i >= FTy->getNumParams() || FTy->getParamType(i) == Args[i]->getType()) && \"Invoking a function with a bad signature!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 790, __PRETTY_FUNCTION__))
790 "Invoking a function with a bad signature!")(((i >= FTy->getNumParams() || FTy->getParamType(i) ==
Args[i]->getType()) && "Invoking a function with a bad signature!"
) ? static_cast<void> (0) : __assert_fail ("(i >= FTy->getNumParams() || FTy->getParamType(i) == Args[i]->getType()) && \"Invoking a function with a bad signature!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 790, __PRETTY_FUNCTION__))
;
791#endif
792
793 llvm::copy(Args, op_begin());
794
795 auto It = populateBundleOperandInfos(Bundles, Args.size());
796 (void)It;
797 assert(It + 3 == op_end() && "Should add up!")((It + 3 == op_end() && "Should add up!") ? static_cast
<void> (0) : __assert_fail ("It + 3 == op_end() && \"Should add up!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 797, __PRETTY_FUNCTION__))
;
798
799 setName(NameStr);
800}
801
802InvokeInst::InvokeInst(const InvokeInst &II)
803 : CallBase(II.Attrs, II.FTy, II.getType(), Instruction::Invoke,
804 OperandTraits<CallBase>::op_end(this) - II.getNumOperands(),
805 II.getNumOperands()) {
806 setCallingConv(II.getCallingConv());
807 std::copy(II.op_begin(), II.op_end(), op_begin());
808 std::copy(II.bundle_op_info_begin(), II.bundle_op_info_end(),
809 bundle_op_info_begin());
810 SubclassOptionalData = II.SubclassOptionalData;
811}
812
813InvokeInst *InvokeInst::Create(InvokeInst *II, ArrayRef<OperandBundleDef> OpB,
814 Instruction *InsertPt) {
815 std::vector<Value *> Args(II->arg_begin(), II->arg_end());
816
817 auto *NewII = InvokeInst::Create(II->getFunctionType(), II->getCalledValue(),
818 II->getNormalDest(), II->getUnwindDest(),
819 Args, OpB, II->getName(), InsertPt);
820 NewII->setCallingConv(II->getCallingConv());
821 NewII->SubclassOptionalData = II->SubclassOptionalData;
822 NewII->setAttributes(II->getAttributes());
823 NewII->setDebugLoc(II->getDebugLoc());
824 return NewII;
825}
826
827
828LandingPadInst *InvokeInst::getLandingPadInst() const {
829 return cast<LandingPadInst>(getUnwindDest()->getFirstNonPHI());
830}
831
832//===----------------------------------------------------------------------===//
833// CallBrInst Implementation
834//===----------------------------------------------------------------------===//
835
836void CallBrInst::init(FunctionType *FTy, Value *Fn, BasicBlock *Fallthrough,
837 ArrayRef<BasicBlock *> IndirectDests,
838 ArrayRef<Value *> Args,
839 ArrayRef<OperandBundleDef> Bundles,
840 const Twine &NameStr) {
841 this->FTy = FTy;
842
843 assert((int)getNumOperands() ==(((int)getNumOperands() == ComputeNumOperands(Args.size(), IndirectDests
.size(), CountBundleInputs(Bundles)) && "NumOperands not set up?"
) ? static_cast<void> (0) : __assert_fail ("(int)getNumOperands() == ComputeNumOperands(Args.size(), IndirectDests.size(), CountBundleInputs(Bundles)) && \"NumOperands not set up?\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 846, __PRETTY_FUNCTION__))
844 ComputeNumOperands(Args.size(), IndirectDests.size(),(((int)getNumOperands() == ComputeNumOperands(Args.size(), IndirectDests
.size(), CountBundleInputs(Bundles)) && "NumOperands not set up?"
) ? static_cast<void> (0) : __assert_fail ("(int)getNumOperands() == ComputeNumOperands(Args.size(), IndirectDests.size(), CountBundleInputs(Bundles)) && \"NumOperands not set up?\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 846, __PRETTY_FUNCTION__))
845 CountBundleInputs(Bundles)) &&(((int)getNumOperands() == ComputeNumOperands(Args.size(), IndirectDests
.size(), CountBundleInputs(Bundles)) && "NumOperands not set up?"
) ? static_cast<void> (0) : __assert_fail ("(int)getNumOperands() == ComputeNumOperands(Args.size(), IndirectDests.size(), CountBundleInputs(Bundles)) && \"NumOperands not set up?\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 846, __PRETTY_FUNCTION__))
846 "NumOperands not set up?")(((int)getNumOperands() == ComputeNumOperands(Args.size(), IndirectDests
.size(), CountBundleInputs(Bundles)) && "NumOperands not set up?"
) ? static_cast<void> (0) : __assert_fail ("(int)getNumOperands() == ComputeNumOperands(Args.size(), IndirectDests.size(), CountBundleInputs(Bundles)) && \"NumOperands not set up?\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 846, __PRETTY_FUNCTION__))
;
847 NumIndirectDests = IndirectDests.size();
848 setDefaultDest(Fallthrough);
849 for (unsigned i = 0; i != NumIndirectDests; ++i)
850 setIndirectDest(i, IndirectDests[i]);
851 setCalledOperand(Fn);
852
853#ifndef NDEBUG
854 assert(((Args.size() == FTy->getNumParams()) ||((((Args.size() == FTy->getNumParams()) || (FTy->isVarArg
() && Args.size() > FTy->getNumParams())) &&
"Calling a function with bad signature") ? static_cast<void
> (0) : __assert_fail ("((Args.size() == FTy->getNumParams()) || (FTy->isVarArg() && Args.size() > FTy->getNumParams())) && \"Calling a function with bad signature\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 856, __PRETTY_FUNCTION__))
855 (FTy->isVarArg() && Args.size() > FTy->getNumParams())) &&((((Args.size() == FTy->getNumParams()) || (FTy->isVarArg
() && Args.size() > FTy->getNumParams())) &&
"Calling a function with bad signature") ? static_cast<void
> (0) : __assert_fail ("((Args.size() == FTy->getNumParams()) || (FTy->isVarArg() && Args.size() > FTy->getNumParams())) && \"Calling a function with bad signature\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 856, __PRETTY_FUNCTION__))
856 "Calling a function with bad signature")((((Args.size() == FTy->getNumParams()) || (FTy->isVarArg
() && Args.size() > FTy->getNumParams())) &&
"Calling a function with bad signature") ? static_cast<void
> (0) : __assert_fail ("((Args.size() == FTy->getNumParams()) || (FTy->isVarArg() && Args.size() > FTy->getNumParams())) && \"Calling a function with bad signature\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 856, __PRETTY_FUNCTION__))
;
857
858 for (unsigned i = 0, e = Args.size(); i != e; i++)
859 assert((i >= FTy->getNumParams() ||(((i >= FTy->getNumParams() || FTy->getParamType(i) ==
Args[i]->getType()) && "Calling a function with a bad signature!"
) ? static_cast<void> (0) : __assert_fail ("(i >= FTy->getNumParams() || FTy->getParamType(i) == Args[i]->getType()) && \"Calling a function with a bad signature!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 861, __PRETTY_FUNCTION__))
860 FTy->getParamType(i) == Args[i]->getType()) &&(((i >= FTy->getNumParams() || FTy->getParamType(i) ==
Args[i]->getType()) && "Calling a function with a bad signature!"
) ? static_cast<void> (0) : __assert_fail ("(i >= FTy->getNumParams() || FTy->getParamType(i) == Args[i]->getType()) && \"Calling a function with a bad signature!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 861, __PRETTY_FUNCTION__))
861 "Calling a function with a bad signature!")(((i >= FTy->getNumParams() || FTy->getParamType(i) ==
Args[i]->getType()) && "Calling a function with a bad signature!"
) ? static_cast<void> (0) : __assert_fail ("(i >= FTy->getNumParams() || FTy->getParamType(i) == Args[i]->getType()) && \"Calling a function with a bad signature!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 861, __PRETTY_FUNCTION__))
;
862#endif
863
864 std::copy(Args.begin(), Args.end(), op_begin());
865
866 auto It = populateBundleOperandInfos(Bundles, Args.size());
867 (void)It;
868 assert(It + 2 + IndirectDests.size() == op_end() && "Should add up!")((It + 2 + IndirectDests.size() == op_end() && "Should add up!"
) ? static_cast<void> (0) : __assert_fail ("It + 2 + IndirectDests.size() == op_end() && \"Should add up!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 868, __PRETTY_FUNCTION__))
;
869
870 setName(NameStr);
871}
872
873void CallBrInst::updateArgBlockAddresses(unsigned i, BasicBlock *B) {
874 assert(getNumIndirectDests() > i && "IndirectDest # out of range for callbr")((getNumIndirectDests() > i && "IndirectDest # out of range for callbr"
) ? static_cast<void> (0) : __assert_fail ("getNumIndirectDests() > i && \"IndirectDest # out of range for callbr\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 874, __PRETTY_FUNCTION__))
;
875 if (BasicBlock *OldBB = getIndirectDest(i)) {
876 BlockAddress *Old = BlockAddress::get(OldBB);
877 BlockAddress *New = BlockAddress::get(B);
878 for (unsigned ArgNo = 0, e = getNumArgOperands(); ArgNo != e; ++ArgNo)
879 if (dyn_cast<BlockAddress>(getArgOperand(ArgNo)) == Old)
880 setArgOperand(ArgNo, New);
881 }
882}
883
884CallBrInst::CallBrInst(const CallBrInst &CBI)
885 : CallBase(CBI.Attrs, CBI.FTy, CBI.getType(), Instruction::CallBr,
886 OperandTraits<CallBase>::op_end(this) - CBI.getNumOperands(),
887 CBI.getNumOperands()) {
888 setCallingConv(CBI.getCallingConv());
889 std::copy(CBI.op_begin(), CBI.op_end(), op_begin());
890 std::copy(CBI.bundle_op_info_begin(), CBI.bundle_op_info_end(),
891 bundle_op_info_begin());
892 SubclassOptionalData = CBI.SubclassOptionalData;
893 NumIndirectDests = CBI.NumIndirectDests;
894}
895
896CallBrInst *CallBrInst::Create(CallBrInst *CBI, ArrayRef<OperandBundleDef> OpB,
897 Instruction *InsertPt) {
898 std::vector<Value *> Args(CBI->arg_begin(), CBI->arg_end());
899
900 auto *NewCBI = CallBrInst::Create(CBI->getFunctionType(),
901 CBI->getCalledValue(),
902 CBI->getDefaultDest(),
903 CBI->getIndirectDests(),
904 Args, OpB, CBI->getName(), InsertPt);
905 NewCBI->setCallingConv(CBI->getCallingConv());
906 NewCBI->SubclassOptionalData = CBI->SubclassOptionalData;
907 NewCBI->setAttributes(CBI->getAttributes());
908 NewCBI->setDebugLoc(CBI->getDebugLoc());
909 NewCBI->NumIndirectDests = CBI->NumIndirectDests;
910 return NewCBI;
911}
912
913//===----------------------------------------------------------------------===//
914// ReturnInst Implementation
915//===----------------------------------------------------------------------===//
916
917ReturnInst::ReturnInst(const ReturnInst &RI)
918 : Instruction(Type::getVoidTy(RI.getContext()), Instruction::Ret,
919 OperandTraits<ReturnInst>::op_end(this) - RI.getNumOperands(),
920 RI.getNumOperands()) {
921 if (RI.getNumOperands())
922 Op<0>() = RI.Op<0>();
923 SubclassOptionalData = RI.SubclassOptionalData;
924}
925
926ReturnInst::ReturnInst(LLVMContext &C, Value *retVal, Instruction *InsertBefore)
927 : Instruction(Type::getVoidTy(C), Instruction::Ret,
928 OperandTraits<ReturnInst>::op_end(this) - !!retVal, !!retVal,
929 InsertBefore) {
930 if (retVal)
931 Op<0>() = retVal;
932}
933
934ReturnInst::ReturnInst(LLVMContext &C, Value *retVal, BasicBlock *InsertAtEnd)
935 : Instruction(Type::getVoidTy(C), Instruction::Ret,
936 OperandTraits<ReturnInst>::op_end(this) - !!retVal, !!retVal,
937 InsertAtEnd) {
938 if (retVal)
939 Op<0>() = retVal;
940}
941
942ReturnInst::ReturnInst(LLVMContext &Context, BasicBlock *InsertAtEnd)
943 : Instruction(Type::getVoidTy(Context), Instruction::Ret,
944 OperandTraits<ReturnInst>::op_end(this), 0, InsertAtEnd) {}
945
946//===----------------------------------------------------------------------===//
947// ResumeInst Implementation
948//===----------------------------------------------------------------------===//
949
950ResumeInst::ResumeInst(const ResumeInst &RI)
951 : Instruction(Type::getVoidTy(RI.getContext()), Instruction::Resume,
952 OperandTraits<ResumeInst>::op_begin(this), 1) {
953 Op<0>() = RI.Op<0>();
954}
955
956ResumeInst::ResumeInst(Value *Exn, Instruction *InsertBefore)
957 : Instruction(Type::getVoidTy(Exn->getContext()), Instruction::Resume,
958 OperandTraits<ResumeInst>::op_begin(this), 1, InsertBefore) {
959 Op<0>() = Exn;
960}
961
962ResumeInst::ResumeInst(Value *Exn, BasicBlock *InsertAtEnd)
963 : Instruction(Type::getVoidTy(Exn->getContext()), Instruction::Resume,
964 OperandTraits<ResumeInst>::op_begin(this), 1, InsertAtEnd) {
965 Op<0>() = Exn;
966}
967
968//===----------------------------------------------------------------------===//
969// CleanupReturnInst Implementation
970//===----------------------------------------------------------------------===//
971
972CleanupReturnInst::CleanupReturnInst(const CleanupReturnInst &CRI)
973 : Instruction(CRI.getType(), Instruction::CleanupRet,
974 OperandTraits<CleanupReturnInst>::op_end(this) -
975 CRI.getNumOperands(),
976 CRI.getNumOperands()) {
977 setInstructionSubclassData(CRI.getSubclassDataFromInstruction());
978 Op<0>() = CRI.Op<0>();
979 if (CRI.hasUnwindDest())
980 Op<1>() = CRI.Op<1>();
981}
982
983void CleanupReturnInst::init(Value *CleanupPad, BasicBlock *UnwindBB) {
984 if (UnwindBB)
985 setInstructionSubclassData(getSubclassDataFromInstruction() | 1);
986
987 Op<0>() = CleanupPad;
988 if (UnwindBB)
989 Op<1>() = UnwindBB;
990}
991
992CleanupReturnInst::CleanupReturnInst(Value *CleanupPad, BasicBlock *UnwindBB,
993 unsigned Values, Instruction *InsertBefore)
994 : Instruction(Type::getVoidTy(CleanupPad->getContext()),
995 Instruction::CleanupRet,
996 OperandTraits<CleanupReturnInst>::op_end(this) - Values,
997 Values, InsertBefore) {
998 init(CleanupPad, UnwindBB);
999}
1000
1001CleanupReturnInst::CleanupReturnInst(Value *CleanupPad, BasicBlock *UnwindBB,
1002 unsigned Values, BasicBlock *InsertAtEnd)
1003 : Instruction(Type::getVoidTy(CleanupPad->getContext()),
1004 Instruction::CleanupRet,
1005 OperandTraits<CleanupReturnInst>::op_end(this) - Values,
1006 Values, InsertAtEnd) {
1007 init(CleanupPad, UnwindBB);
1008}
1009
1010//===----------------------------------------------------------------------===//
1011// CatchReturnInst Implementation
1012//===----------------------------------------------------------------------===//
1013void CatchReturnInst::init(Value *CatchPad, BasicBlock *BB) {
1014 Op<0>() = CatchPad;
1015 Op<1>() = BB;
1016}
1017
1018CatchReturnInst::CatchReturnInst(const CatchReturnInst &CRI)
1019 : Instruction(Type::getVoidTy(CRI.getContext()), Instruction::CatchRet,
1020 OperandTraits<CatchReturnInst>::op_begin(this), 2) {
1021 Op<0>() = CRI.Op<0>();
1022 Op<1>() = CRI.Op<1>();
1023}
1024
1025CatchReturnInst::CatchReturnInst(Value *CatchPad, BasicBlock *BB,
1026 Instruction *InsertBefore)
1027 : Instruction(Type::getVoidTy(BB->getContext()), Instruction::CatchRet,
1028 OperandTraits<CatchReturnInst>::op_begin(this), 2,
1029 InsertBefore) {
1030 init(CatchPad, BB);
1031}
1032
1033CatchReturnInst::CatchReturnInst(Value *CatchPad, BasicBlock *BB,
1034 BasicBlock *InsertAtEnd)
1035 : Instruction(Type::getVoidTy(BB->getContext()), Instruction::CatchRet,
1036 OperandTraits<CatchReturnInst>::op_begin(this), 2,
1037 InsertAtEnd) {
1038 init(CatchPad, BB);
1039}
1040
1041//===----------------------------------------------------------------------===//
1042// CatchSwitchInst Implementation
1043//===----------------------------------------------------------------------===//
1044
1045CatchSwitchInst::CatchSwitchInst(Value *ParentPad, BasicBlock *UnwindDest,
1046 unsigned NumReservedValues,
1047 const Twine &NameStr,
1048 Instruction *InsertBefore)
1049 : Instruction(ParentPad->getType(), Instruction::CatchSwitch, nullptr, 0,
1050 InsertBefore) {
1051 if (UnwindDest)
1052 ++NumReservedValues;
1053 init(ParentPad, UnwindDest, NumReservedValues + 1);
1054 setName(NameStr);
1055}
1056
1057CatchSwitchInst::CatchSwitchInst(Value *ParentPad, BasicBlock *UnwindDest,
1058 unsigned NumReservedValues,
1059 const Twine &NameStr, BasicBlock *InsertAtEnd)
1060 : Instruction(ParentPad->getType(), Instruction::CatchSwitch, nullptr, 0,
1061 InsertAtEnd) {
1062 if (UnwindDest)
1063 ++NumReservedValues;
1064 init(ParentPad, UnwindDest, NumReservedValues + 1);
1065 setName(NameStr);
1066}
1067
1068CatchSwitchInst::CatchSwitchInst(const CatchSwitchInst &CSI)
1069 : Instruction(CSI.getType(), Instruction::CatchSwitch, nullptr,
1070 CSI.getNumOperands()) {
1071 init(CSI.getParentPad(), CSI.getUnwindDest(), CSI.getNumOperands());
1072 setNumHungOffUseOperands(ReservedSpace);
1073 Use *OL = getOperandList();
1074 const Use *InOL = CSI.getOperandList();
1075 for (unsigned I = 1, E = ReservedSpace; I != E; ++I)
1076 OL[I] = InOL[I];
1077}
1078
1079void CatchSwitchInst::init(Value *ParentPad, BasicBlock *UnwindDest,
1080 unsigned NumReservedValues) {
1081 assert(ParentPad && NumReservedValues)((ParentPad && NumReservedValues) ? static_cast<void
> (0) : __assert_fail ("ParentPad && NumReservedValues"
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1081, __PRETTY_FUNCTION__))
;
1082
1083 ReservedSpace = NumReservedValues;
1084 setNumHungOffUseOperands(UnwindDest ? 2 : 1);
1085 allocHungoffUses(ReservedSpace);
1086
1087 Op<0>() = ParentPad;
1088 if (UnwindDest) {
1089 setInstructionSubclassData(getSubclassDataFromInstruction() | 1);
1090 setUnwindDest(UnwindDest);
1091 }
1092}
1093
1094/// growOperands - grow operands - This grows the operand list in response to a
1095/// push_back style of operation. This grows the number of ops by 2 times.
1096void CatchSwitchInst::growOperands(unsigned Size) {
1097 unsigned NumOperands = getNumOperands();
1098 assert(NumOperands >= 1)((NumOperands >= 1) ? static_cast<void> (0) : __assert_fail
("NumOperands >= 1", "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1098, __PRETTY_FUNCTION__))
;
1099 if (ReservedSpace >= NumOperands + Size)
1100 return;
1101 ReservedSpace = (NumOperands + Size / 2) * 2;
1102 growHungoffUses(ReservedSpace);
1103}
1104
1105void CatchSwitchInst::addHandler(BasicBlock *Handler) {
1106 unsigned OpNo = getNumOperands();
1107 growOperands(1);
1108 assert(OpNo < ReservedSpace && "Growing didn't work!")((OpNo < ReservedSpace && "Growing didn't work!") ?
static_cast<void> (0) : __assert_fail ("OpNo < ReservedSpace && \"Growing didn't work!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1108, __PRETTY_FUNCTION__))
;
1109 setNumHungOffUseOperands(getNumOperands() + 1);
1110 getOperandList()[OpNo] = Handler;
1111}
1112
1113void CatchSwitchInst::removeHandler(handler_iterator HI) {
1114 // Move all subsequent handlers up one.
1115 Use *EndDst = op_end() - 1;
1116 for (Use *CurDst = HI.getCurrent(); CurDst != EndDst; ++CurDst)
1117 *CurDst = *(CurDst + 1);
1118 // Null out the last handler use.
1119 *EndDst = nullptr;
1120
1121 setNumHungOffUseOperands(getNumOperands() - 1);
1122}
1123
1124//===----------------------------------------------------------------------===//
1125// FuncletPadInst Implementation
1126//===----------------------------------------------------------------------===//
1127void FuncletPadInst::init(Value *ParentPad, ArrayRef<Value *> Args,
1128 const Twine &NameStr) {
1129 assert(getNumOperands() == 1 + Args.size() && "NumOperands not set up?")((getNumOperands() == 1 + Args.size() && "NumOperands not set up?"
) ? static_cast<void> (0) : __assert_fail ("getNumOperands() == 1 + Args.size() && \"NumOperands not set up?\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1129, __PRETTY_FUNCTION__))
;
1130 llvm::copy(Args, op_begin());
1131 setParentPad(ParentPad);
1132 setName(NameStr);
1133}
1134
1135FuncletPadInst::FuncletPadInst(const FuncletPadInst &FPI)
1136 : Instruction(FPI.getType(), FPI.getOpcode(),
1137 OperandTraits<FuncletPadInst>::op_end(this) -
1138 FPI.getNumOperands(),
1139 FPI.getNumOperands()) {
1140 std::copy(FPI.op_begin(), FPI.op_end(), op_begin());
1141 setParentPad(FPI.getParentPad());
1142}
1143
1144FuncletPadInst::FuncletPadInst(Instruction::FuncletPadOps Op, Value *ParentPad,
1145 ArrayRef<Value *> Args, unsigned Values,
1146 const Twine &NameStr, Instruction *InsertBefore)
1147 : Instruction(ParentPad->getType(), Op,
1148 OperandTraits<FuncletPadInst>::op_end(this) - Values, Values,
1149 InsertBefore) {
1150 init(ParentPad, Args, NameStr);
1151}
1152
1153FuncletPadInst::FuncletPadInst(Instruction::FuncletPadOps Op, Value *ParentPad,
1154 ArrayRef<Value *> Args, unsigned Values,
1155 const Twine &NameStr, BasicBlock *InsertAtEnd)
1156 : Instruction(ParentPad->getType(), Op,
1157 OperandTraits<FuncletPadInst>::op_end(this) - Values, Values,
1158 InsertAtEnd) {
1159 init(ParentPad, Args, NameStr);
1160}
1161
1162//===----------------------------------------------------------------------===//
1163// UnreachableInst Implementation
1164//===----------------------------------------------------------------------===//
1165
1166UnreachableInst::UnreachableInst(LLVMContext &Context,
1167 Instruction *InsertBefore)
1168 : Instruction(Type::getVoidTy(Context), Instruction::Unreachable, nullptr,
1169 0, InsertBefore) {}
1170UnreachableInst::UnreachableInst(LLVMContext &Context, BasicBlock *InsertAtEnd)
1171 : Instruction(Type::getVoidTy(Context), Instruction::Unreachable, nullptr,
1172 0, InsertAtEnd) {}
1173
1174//===----------------------------------------------------------------------===//
1175// BranchInst Implementation
1176//===----------------------------------------------------------------------===//
1177
1178void BranchInst::AssertOK() {
1179 if (isConditional())
1180 assert(getCondition()->getType()->isIntegerTy(1) &&((getCondition()->getType()->isIntegerTy(1) && "May only branch on boolean predicates!"
) ? static_cast<void> (0) : __assert_fail ("getCondition()->getType()->isIntegerTy(1) && \"May only branch on boolean predicates!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1181, __PRETTY_FUNCTION__))
1181 "May only branch on boolean predicates!")((getCondition()->getType()->isIntegerTy(1) && "May only branch on boolean predicates!"
) ? static_cast<void> (0) : __assert_fail ("getCondition()->getType()->isIntegerTy(1) && \"May only branch on boolean predicates!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1181, __PRETTY_FUNCTION__))
;
1182}
1183
1184BranchInst::BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore)
1185 : Instruction(Type::getVoidTy(IfTrue->getContext()), Instruction::Br,
1186 OperandTraits<BranchInst>::op_end(this) - 1, 1,
1187 InsertBefore) {
1188 assert(IfTrue && "Branch destination may not be null!")((IfTrue && "Branch destination may not be null!") ? static_cast
<void> (0) : __assert_fail ("IfTrue && \"Branch destination may not be null!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1188, __PRETTY_FUNCTION__))
;
1189 Op<-1>() = IfTrue;
1190}
1191
1192BranchInst::BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
1193 Instruction *InsertBefore)
1194 : Instruction(Type::getVoidTy(IfTrue->getContext()), Instruction::Br,
1195 OperandTraits<BranchInst>::op_end(this) - 3, 3,
1196 InsertBefore) {
1197 Op<-1>() = IfTrue;
1198 Op<-2>() = IfFalse;
1199 Op<-3>() = Cond;
1200#ifndef NDEBUG
1201 AssertOK();
1202#endif
1203}
1204
1205BranchInst::BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd)
1206 : Instruction(Type::getVoidTy(IfTrue->getContext()), Instruction::Br,
1207 OperandTraits<BranchInst>::op_end(this) - 1, 1, InsertAtEnd) {
1208 assert(IfTrue && "Branch destination may not be null!")((IfTrue && "Branch destination may not be null!") ? static_cast
<void> (0) : __assert_fail ("IfTrue && \"Branch destination may not be null!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1208, __PRETTY_FUNCTION__))
;
1209 Op<-1>() = IfTrue;
1210}
1211
1212BranchInst::BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
1213 BasicBlock *InsertAtEnd)
1214 : Instruction(Type::getVoidTy(IfTrue->getContext()), Instruction::Br,
1215 OperandTraits<BranchInst>::op_end(this) - 3, 3, InsertAtEnd) {
1216 Op<-1>() = IfTrue;
1217 Op<-2>() = IfFalse;
1218 Op<-3>() = Cond;
1219#ifndef NDEBUG
1220 AssertOK();
1221#endif
1222}
1223
1224BranchInst::BranchInst(const BranchInst &BI)
1225 : Instruction(Type::getVoidTy(BI.getContext()), Instruction::Br,
1226 OperandTraits<BranchInst>::op_end(this) - BI.getNumOperands(),
1227 BI.getNumOperands()) {
1228 Op<-1>() = BI.Op<-1>();
1229 if (BI.getNumOperands() != 1) {
1230 assert(BI.getNumOperands() == 3 && "BR can have 1 or 3 operands!")((BI.getNumOperands() == 3 && "BR can have 1 or 3 operands!"
) ? static_cast<void> (0) : __assert_fail ("BI.getNumOperands() == 3 && \"BR can have 1 or 3 operands!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1230, __PRETTY_FUNCTION__))
;
1231 Op<-3>() = BI.Op<-3>();
1232 Op<-2>() = BI.Op<-2>();
1233 }
1234 SubclassOptionalData = BI.SubclassOptionalData;
1235}
1236
1237void BranchInst::swapSuccessors() {
1238 assert(isConditional() &&((isConditional() && "Cannot swap successors of an unconditional branch"
) ? static_cast<void> (0) : __assert_fail ("isConditional() && \"Cannot swap successors of an unconditional branch\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1239, __PRETTY_FUNCTION__))
1239 "Cannot swap successors of an unconditional branch")((isConditional() && "Cannot swap successors of an unconditional branch"
) ? static_cast<void> (0) : __assert_fail ("isConditional() && \"Cannot swap successors of an unconditional branch\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1239, __PRETTY_FUNCTION__))
;
1240 Op<-1>().swap(Op<-2>());
1241
1242 // Update profile metadata if present and it matches our structural
1243 // expectations.
1244 swapProfMetadata();
1245}
1246
1247//===----------------------------------------------------------------------===//
1248// AllocaInst Implementation
1249//===----------------------------------------------------------------------===//
1250
1251static Value *getAISize(LLVMContext &Context, Value *Amt) {
1252 if (!Amt)
1253 Amt = ConstantInt::get(Type::getInt32Ty(Context), 1);
1254 else {
1255 assert(!isa<BasicBlock>(Amt) &&((!isa<BasicBlock>(Amt) && "Passed basic block into allocation size parameter! Use other ctor"
) ? static_cast<void> (0) : __assert_fail ("!isa<BasicBlock>(Amt) && \"Passed basic block into allocation size parameter! Use other ctor\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1256, __PRETTY_FUNCTION__))
1256 "Passed basic block into allocation size parameter! Use other ctor")((!isa<BasicBlock>(Amt) && "Passed basic block into allocation size parameter! Use other ctor"
) ? static_cast<void> (0) : __assert_fail ("!isa<BasicBlock>(Amt) && \"Passed basic block into allocation size parameter! Use other ctor\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1256, __PRETTY_FUNCTION__))
;
1257 assert(Amt->getType()->isIntegerTy() &&((Amt->getType()->isIntegerTy() && "Allocation array size is not an integer!"
) ? static_cast<void> (0) : __assert_fail ("Amt->getType()->isIntegerTy() && \"Allocation array size is not an integer!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1258, __PRETTY_FUNCTION__))
1258 "Allocation array size is not an integer!")((Amt->getType()->isIntegerTy() && "Allocation array size is not an integer!"
) ? static_cast<void> (0) : __assert_fail ("Amt->getType()->isIntegerTy() && \"Allocation array size is not an integer!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1258, __PRETTY_FUNCTION__))
;
1259 }
1260 return Amt;
1261}
1262
1263AllocaInst::AllocaInst(Type *Ty, unsigned AddrSpace, const Twine &Name,
1264 Instruction *InsertBefore)
1265 : AllocaInst(Ty, AddrSpace, /*ArraySize=*/nullptr, Name, InsertBefore) {}
1266
1267AllocaInst::AllocaInst(Type *Ty, unsigned AddrSpace, const Twine &Name,
1268 BasicBlock *InsertAtEnd)
1269 : AllocaInst(Ty, AddrSpace, /*ArraySize=*/nullptr, Name, InsertAtEnd) {}
1270
1271AllocaInst::AllocaInst(Type *Ty, unsigned AddrSpace, Value *ArraySize,
1272 const Twine &Name, Instruction *InsertBefore)
1273 : AllocaInst(Ty, AddrSpace, ArraySize, /*Align=*/None, Name, InsertBefore) {
1274}
1275
1276AllocaInst::AllocaInst(Type *Ty, unsigned AddrSpace, Value *ArraySize,
1277 const Twine &Name, BasicBlock *InsertAtEnd)
1278 : AllocaInst(Ty, AddrSpace, ArraySize, /*Align=*/None, Name, InsertAtEnd) {}
1279
1280AllocaInst::AllocaInst(Type *Ty, unsigned AddrSpace, Value *ArraySize,
1281 MaybeAlign Align, const Twine &Name,
1282 Instruction *InsertBefore)
1283 : UnaryInstruction(PointerType::get(Ty, AddrSpace), Alloca,
1284 getAISize(Ty->getContext(), ArraySize), InsertBefore),
1285 AllocatedType(Ty) {
1286 setAlignment(MaybeAlign(Align));
1287 assert(!Ty->isVoidTy() && "Cannot allocate void!")((!Ty->isVoidTy() && "Cannot allocate void!") ? static_cast
<void> (0) : __assert_fail ("!Ty->isVoidTy() && \"Cannot allocate void!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1287, __PRETTY_FUNCTION__))
;
1288 setName(Name);
1289}
1290
1291AllocaInst::AllocaInst(Type *Ty, unsigned AddrSpace, Value *ArraySize,
1292 MaybeAlign Align, const Twine &Name,
1293 BasicBlock *InsertAtEnd)
1294 : UnaryInstruction(PointerType::get(Ty, AddrSpace), Alloca,
1295 getAISize(Ty->getContext(), ArraySize), InsertAtEnd),
1296 AllocatedType(Ty) {
1297 setAlignment(Align);
1298 assert(!Ty->isVoidTy() && "Cannot allocate void!")((!Ty->isVoidTy() && "Cannot allocate void!") ? static_cast
<void> (0) : __assert_fail ("!Ty->isVoidTy() && \"Cannot allocate void!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1298, __PRETTY_FUNCTION__))
;
1299 setName(Name);
1300}
1301
1302void AllocaInst::setAlignment(MaybeAlign Align) {
1303 assert((!Align || *Align <= MaximumAlignment) &&(((!Align || *Align <= MaximumAlignment) && "Alignment is greater than MaximumAlignment!"
) ? static_cast<void> (0) : __assert_fail ("(!Align || *Align <= MaximumAlignment) && \"Alignment is greater than MaximumAlignment!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1304, __PRETTY_FUNCTION__))
1304 "Alignment is greater than MaximumAlignment!")(((!Align || *Align <= MaximumAlignment) && "Alignment is greater than MaximumAlignment!"
) ? static_cast<void> (0) : __assert_fail ("(!Align || *Align <= MaximumAlignment) && \"Alignment is greater than MaximumAlignment!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1304, __PRETTY_FUNCTION__))
;
1305 setInstructionSubclassData((getSubclassDataFromInstruction() & ~31) |
1306 encode(Align));
1307 if (Align)
1308 assert(getAlignment() == Align->value() &&((getAlignment() == Align->value() && "Alignment representation error!"
) ? static_cast<void> (0) : __assert_fail ("getAlignment() == Align->value() && \"Alignment representation error!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1309, __PRETTY_FUNCTION__))
1309 "Alignment representation error!")((getAlignment() == Align->value() && "Alignment representation error!"
) ? static_cast<void> (0) : __assert_fail ("getAlignment() == Align->value() && \"Alignment representation error!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1309, __PRETTY_FUNCTION__))
;
1310 else
1311 assert(getAlignment() == 0 && "Alignment representation error!")((getAlignment() == 0 && "Alignment representation error!"
) ? static_cast<void> (0) : __assert_fail ("getAlignment() == 0 && \"Alignment representation error!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1311, __PRETTY_FUNCTION__))
;
1312}
1313
1314bool AllocaInst::isArrayAllocation() const {
1315 if (ConstantInt *CI = dyn_cast<ConstantInt>(getOperand(0)))
1316 return !CI->isOne();
1317 return true;
1318}
1319
1320/// isStaticAlloca - Return true if this alloca is in the entry block of the
1321/// function and is a constant size. If so, the code generator will fold it
1322/// into the prolog/epilog code, so it is basically free.
1323bool AllocaInst::isStaticAlloca() const {
1324 // Must be constant size.
1325 if (!isa<ConstantInt>(getArraySize())) return false;
1326
1327 // Must be in the entry block.
1328 const BasicBlock *Parent = getParent();
1329 return Parent == &Parent->getParent()->front() && !isUsedWithInAlloca();
1330}
1331
1332//===----------------------------------------------------------------------===//
1333// LoadInst Implementation
1334//===----------------------------------------------------------------------===//
1335
1336void LoadInst::AssertOK() {
1337 assert(getOperand(0)->getType()->isPointerTy() &&((getOperand(0)->getType()->isPointerTy() && "Ptr must have pointer type."
) ? static_cast<void> (0) : __assert_fail ("getOperand(0)->getType()->isPointerTy() && \"Ptr must have pointer type.\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1338, __PRETTY_FUNCTION__))
1338 "Ptr must have pointer type.")((getOperand(0)->getType()->isPointerTy() && "Ptr must have pointer type."
) ? static_cast<void> (0) : __assert_fail ("getOperand(0)->getType()->isPointerTy() && \"Ptr must have pointer type.\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1338, __PRETTY_FUNCTION__))
;
1339 assert(!(isAtomic() && getAlignment() == 0) &&((!(isAtomic() && getAlignment() == 0) && "Alignment required for atomic load"
) ? static_cast<void> (0) : __assert_fail ("!(isAtomic() && getAlignment() == 0) && \"Alignment required for atomic load\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1340, __PRETTY_FUNCTION__))
1340 "Alignment required for atomic load")((!(isAtomic() && getAlignment() == 0) && "Alignment required for atomic load"
) ? static_cast<void> (0) : __assert_fail ("!(isAtomic() && getAlignment() == 0) && \"Alignment required for atomic load\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1340, __PRETTY_FUNCTION__))
;
1341}
1342
1343LoadInst::LoadInst(Type *Ty, Value *Ptr, const Twine &Name,
1344 Instruction *InsertBef)
1345 : LoadInst(Ty, Ptr, Name, /*isVolatile=*/false, InsertBef) {}
1346
1347LoadInst::LoadInst(Type *Ty, Value *Ptr, const Twine &Name,
1348 BasicBlock *InsertAE)
1349 : LoadInst(Ty, Ptr, Name, /*isVolatile=*/false, InsertAE) {}
1350
1351LoadInst::LoadInst(Type *Ty, Value *Ptr, const Twine &Name, bool isVolatile,
1352 Instruction *InsertBef)
1353 : LoadInst(Ty, Ptr, Name, isVolatile, /*Align=*/None, InsertBef) {}
1354
1355LoadInst::LoadInst(Type *Ty, Value *Ptr, const Twine &Name, bool isVolatile,
1356 BasicBlock *InsertAE)
1357 : LoadInst(Ty, Ptr, Name, isVolatile, /*Align=*/None, InsertAE) {}
1358
1359LoadInst::LoadInst(Type *Ty, Value *Ptr, const Twine &Name, bool isVolatile,
1360 MaybeAlign Align, Instruction *InsertBef)
1361 : LoadInst(Ty, Ptr, Name, isVolatile, Align, AtomicOrdering::NotAtomic,
1362 SyncScope::System, InsertBef) {}
1363
1364LoadInst::LoadInst(Type *Ty, Value *Ptr, const Twine &Name, bool isVolatile,
1365 MaybeAlign Align, BasicBlock *InsertAE)
1366 : LoadInst(Ty, Ptr, Name, isVolatile, Align, AtomicOrdering::NotAtomic,
1367 SyncScope::System, InsertAE) {}
1368
1369LoadInst::LoadInst(Type *Ty, Value *Ptr, const Twine &Name, bool isVolatile,
1370 MaybeAlign Align, AtomicOrdering Order, SyncScope::ID SSID,
1371 Instruction *InsertBef)
1372 : UnaryInstruction(Ty, Load, Ptr, InsertBef) {
1373 assert(Ty == cast<PointerType>(Ptr->getType())->getElementType())((Ty == cast<PointerType>(Ptr->getType())->getElementType
()) ? static_cast<void> (0) : __assert_fail ("Ty == cast<PointerType>(Ptr->getType())->getElementType()"
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1373, __PRETTY_FUNCTION__))
;
1374 setVolatile(isVolatile);
1375 setAlignment(MaybeAlign(Align));
1376 setAtomic(Order, SSID);
1377 AssertOK();
1378 setName(Name);
1379}
1380
1381LoadInst::LoadInst(Type *Ty, Value *Ptr, const Twine &Name, bool isVolatile,
1382 MaybeAlign Align, AtomicOrdering Order, SyncScope::ID SSID,
1383 BasicBlock *InsertAE)
1384 : UnaryInstruction(Ty, Load, Ptr, InsertAE) {
1385 assert(Ty == cast<PointerType>(Ptr->getType())->getElementType())((Ty == cast<PointerType>(Ptr->getType())->getElementType
()) ? static_cast<void> (0) : __assert_fail ("Ty == cast<PointerType>(Ptr->getType())->getElementType()"
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1385, __PRETTY_FUNCTION__))
;
1386 setVolatile(isVolatile);
1387 setAlignment(Align);
1388 setAtomic(Order, SSID);
1389 AssertOK();
1390 setName(Name);
1391}
1392
1393void LoadInst::setAlignment(MaybeAlign Align) {
1394 assert((!Align || *Align <= MaximumAlignment) &&(((!Align || *Align <= MaximumAlignment) && "Alignment is greater than MaximumAlignment!"
) ? static_cast<void> (0) : __assert_fail ("(!Align || *Align <= MaximumAlignment) && \"Alignment is greater than MaximumAlignment!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1395, __PRETTY_FUNCTION__))
1395 "Alignment is greater than MaximumAlignment!")(((!Align || *Align <= MaximumAlignment) && "Alignment is greater than MaximumAlignment!"
) ? static_cast<void> (0) : __assert_fail ("(!Align || *Align <= MaximumAlignment) && \"Alignment is greater than MaximumAlignment!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1395, __PRETTY_FUNCTION__))
;
1396 setInstructionSubclassData((getSubclassDataFromInstruction() & ~(31 << 1)) |
1397 (encode(Align) << 1));
1398 assert(getAlign() == Align && "Alignment representation error!")((getAlign() == Align && "Alignment representation error!"
) ? static_cast<void> (0) : __assert_fail ("getAlign() == Align && \"Alignment representation error!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1398, __PRETTY_FUNCTION__))
;
1399}
1400
1401//===----------------------------------------------------------------------===//
1402// StoreInst Implementation
1403//===----------------------------------------------------------------------===//
1404
1405void StoreInst::AssertOK() {
1406 assert(getOperand(0) && getOperand(1) && "Both operands must be non-null!")((getOperand(0) && getOperand(1) && "Both operands must be non-null!"
) ? static_cast<void> (0) : __assert_fail ("getOperand(0) && getOperand(1) && \"Both operands must be non-null!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1406, __PRETTY_FUNCTION__))
;
1407 assert(getOperand(1)->getType()->isPointerTy() &&((getOperand(1)->getType()->isPointerTy() && "Ptr must have pointer type!"
) ? static_cast<void> (0) : __assert_fail ("getOperand(1)->getType()->isPointerTy() && \"Ptr must have pointer type!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1408, __PRETTY_FUNCTION__))
1408 "Ptr must have pointer type!")((getOperand(1)->getType()->isPointerTy() && "Ptr must have pointer type!"
) ? static_cast<void> (0) : __assert_fail ("getOperand(1)->getType()->isPointerTy() && \"Ptr must have pointer type!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1408, __PRETTY_FUNCTION__))
;
1409 assert(getOperand(0)->getType() ==((getOperand(0)->getType() == cast<PointerType>(getOperand
(1)->getType())->getElementType() && "Ptr must be a pointer to Val type!"
) ? static_cast<void> (0) : __assert_fail ("getOperand(0)->getType() == cast<PointerType>(getOperand(1)->getType())->getElementType() && \"Ptr must be a pointer to Val type!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1411, __PRETTY_FUNCTION__))
1410 cast<PointerType>(getOperand(1)->getType())->getElementType()((getOperand(0)->getType() == cast<PointerType>(getOperand
(1)->getType())->getElementType() && "Ptr must be a pointer to Val type!"
) ? static_cast<void> (0) : __assert_fail ("getOperand(0)->getType() == cast<PointerType>(getOperand(1)->getType())->getElementType() && \"Ptr must be a pointer to Val type!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1411, __PRETTY_FUNCTION__))
1411 && "Ptr must be a pointer to Val type!")((getOperand(0)->getType() == cast<PointerType>(getOperand
(1)->getType())->getElementType() && "Ptr must be a pointer to Val type!"
) ? static_cast<void> (0) : __assert_fail ("getOperand(0)->getType() == cast<PointerType>(getOperand(1)->getType())->getElementType() && \"Ptr must be a pointer to Val type!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1411, __PRETTY_FUNCTION__))
;
1412 assert(!(isAtomic() && getAlignment() == 0) &&((!(isAtomic() && getAlignment() == 0) && "Alignment required for atomic store"
) ? static_cast<void> (0) : __assert_fail ("!(isAtomic() && getAlignment() == 0) && \"Alignment required for atomic store\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1413, __PRETTY_FUNCTION__))
1413 "Alignment required for atomic store")((!(isAtomic() && getAlignment() == 0) && "Alignment required for atomic store"
) ? static_cast<void> (0) : __assert_fail ("!(isAtomic() && getAlignment() == 0) && \"Alignment required for atomic store\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1413, __PRETTY_FUNCTION__))
;
1414}
1415
1416StoreInst::StoreInst(Value *val, Value *addr, Instruction *InsertBefore)
1417 : StoreInst(val, addr, /*isVolatile=*/false, InsertBefore) {}
1418
1419StoreInst::StoreInst(Value *val, Value *addr, BasicBlock *InsertAtEnd)
1420 : StoreInst(val, addr, /*isVolatile=*/false, InsertAtEnd) {}
1421
1422StoreInst::StoreInst(Value *val, Value *addr, bool isVolatile,
1423 Instruction *InsertBefore)
1424 : StoreInst(val, addr, isVolatile, /*Align=*/None, InsertBefore) {}
1425
1426StoreInst::StoreInst(Value *val, Value *addr, bool isVolatile,
1427 BasicBlock *InsertAtEnd)
1428 : StoreInst(val, addr, isVolatile, /*Align=*/None, InsertAtEnd) {}
1429
1430StoreInst::StoreInst(Value *val, Value *addr, bool isVolatile, MaybeAlign Align,
1431 Instruction *InsertBefore)
1432 : StoreInst(val, addr, isVolatile, Align, AtomicOrdering::NotAtomic,
1433 SyncScope::System, InsertBefore) {}
1434
1435StoreInst::StoreInst(Value *val, Value *addr, bool isVolatile, MaybeAlign Align,
1436 BasicBlock *InsertAtEnd)
1437 : StoreInst(val, addr, isVolatile, Align, AtomicOrdering::NotAtomic,
1438 SyncScope::System, InsertAtEnd) {}
1439
1440StoreInst::StoreInst(Value *val, Value *addr, bool isVolatile, MaybeAlign Align,
1441 AtomicOrdering Order, SyncScope::ID SSID,
1442 Instruction *InsertBefore)
1443 : Instruction(Type::getVoidTy(val->getContext()), Store,
1444 OperandTraits<StoreInst>::op_begin(this),
1445 OperandTraits<StoreInst>::operands(this), InsertBefore) {
1446 Op<0>() = val;
1447 Op<1>() = addr;
1448 setVolatile(isVolatile);
1449 setAlignment(Align);
1450 setAtomic(Order, SSID);
1451 AssertOK();
1452}
1453
1454StoreInst::StoreInst(Value *val, Value *addr, bool isVolatile, MaybeAlign Align,
1455 AtomicOrdering Order, SyncScope::ID SSID,
1456 BasicBlock *InsertAtEnd)
1457 : Instruction(Type::getVoidTy(val->getContext()), Store,
1458 OperandTraits<StoreInst>::op_begin(this),
1459 OperandTraits<StoreInst>::operands(this), InsertAtEnd) {
1460 Op<0>() = val;
1461 Op<1>() = addr;
1462 setVolatile(isVolatile);
1463 setAlignment(Align);
1464 setAtomic(Order, SSID);
1465 AssertOK();
1466}
1467
1468void StoreInst::setAlignment(MaybeAlign Alignment) {
1469 assert((!Alignment || *Alignment <= MaximumAlignment) &&(((!Alignment || *Alignment <= MaximumAlignment) &&
"Alignment is greater than MaximumAlignment!") ? static_cast
<void> (0) : __assert_fail ("(!Alignment || *Alignment <= MaximumAlignment) && \"Alignment is greater than MaximumAlignment!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1470, __PRETTY_FUNCTION__))
1470 "Alignment is greater than MaximumAlignment!")(((!Alignment || *Alignment <= MaximumAlignment) &&
"Alignment is greater than MaximumAlignment!") ? static_cast
<void> (0) : __assert_fail ("(!Alignment || *Alignment <= MaximumAlignment) && \"Alignment is greater than MaximumAlignment!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1470, __PRETTY_FUNCTION__))
;
1471 setInstructionSubclassData((getSubclassDataFromInstruction() & ~(31 << 1)) |
1472 (encode(Alignment) << 1));
1473 assert(getAlign() == Alignment && "Alignment representation error!")((getAlign() == Alignment && "Alignment representation error!"
) ? static_cast<void> (0) : __assert_fail ("getAlign() == Alignment && \"Alignment representation error!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1473, __PRETTY_FUNCTION__))
;
1474}
1475
1476//===----------------------------------------------------------------------===//
1477// AtomicCmpXchgInst Implementation
1478//===----------------------------------------------------------------------===//
1479
1480void AtomicCmpXchgInst::Init(Value *Ptr, Value *Cmp, Value *NewVal,
1481 AtomicOrdering SuccessOrdering,
1482 AtomicOrdering FailureOrdering,
1483 SyncScope::ID SSID) {
1484 Op<0>() = Ptr;
1485 Op<1>() = Cmp;
1486 Op<2>() = NewVal;
1487 setSuccessOrdering(SuccessOrdering);
1488 setFailureOrdering(FailureOrdering);
1489 setSyncScopeID(SSID);
1490
1491 assert(getOperand(0) && getOperand(1) && getOperand(2) &&((getOperand(0) && getOperand(1) && getOperand
(2) && "All operands must be non-null!") ? static_cast
<void> (0) : __assert_fail ("getOperand(0) && getOperand(1) && getOperand(2) && \"All operands must be non-null!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1492, __PRETTY_FUNCTION__))
1492 "All operands must be non-null!")((getOperand(0) && getOperand(1) && getOperand
(2) && "All operands must be non-null!") ? static_cast
<void> (0) : __assert_fail ("getOperand(0) && getOperand(1) && getOperand(2) && \"All operands must be non-null!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1492, __PRETTY_FUNCTION__))
;
1493 assert(getOperand(0)->getType()->isPointerTy() &&((getOperand(0)->getType()->isPointerTy() && "Ptr must have pointer type!"
) ? static_cast<void> (0) : __assert_fail ("getOperand(0)->getType()->isPointerTy() && \"Ptr must have pointer type!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1494, __PRETTY_FUNCTION__))
1494 "Ptr must have pointer type!")((getOperand(0)->getType()->isPointerTy() && "Ptr must have pointer type!"
) ? static_cast<void> (0) : __assert_fail ("getOperand(0)->getType()->isPointerTy() && \"Ptr must have pointer type!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1494, __PRETTY_FUNCTION__))
;
1495 assert(getOperand(1)->getType() ==((getOperand(1)->getType() == cast<PointerType>(getOperand
(0)->getType())->getElementType() && "Ptr must be a pointer to Cmp type!"
) ? static_cast<void> (0) : __assert_fail ("getOperand(1)->getType() == cast<PointerType>(getOperand(0)->getType())->getElementType() && \"Ptr must be a pointer to Cmp type!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1497, __PRETTY_FUNCTION__))
1496 cast<PointerType>(getOperand(0)->getType())->getElementType()((getOperand(1)->getType() == cast<PointerType>(getOperand
(0)->getType())->getElementType() && "Ptr must be a pointer to Cmp type!"
) ? static_cast<void> (0) : __assert_fail ("getOperand(1)->getType() == cast<PointerType>(getOperand(0)->getType())->getElementType() && \"Ptr must be a pointer to Cmp type!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1497, __PRETTY_FUNCTION__))
1497 && "Ptr must be a pointer to Cmp type!")((getOperand(1)->getType() == cast<PointerType>(getOperand
(0)->getType())->getElementType() && "Ptr must be a pointer to Cmp type!"
) ? static_cast<void> (0) : __assert_fail ("getOperand(1)->getType() == cast<PointerType>(getOperand(0)->getType())->getElementType() && \"Ptr must be a pointer to Cmp type!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1497, __PRETTY_FUNCTION__))
;
1498 assert(getOperand(2)->getType() ==((getOperand(2)->getType() == cast<PointerType>(getOperand
(0)->getType())->getElementType() && "Ptr must be a pointer to NewVal type!"
) ? static_cast<void> (0) : __assert_fail ("getOperand(2)->getType() == cast<PointerType>(getOperand(0)->getType())->getElementType() && \"Ptr must be a pointer to NewVal type!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1500, __PRETTY_FUNCTION__))
1499 cast<PointerType>(getOperand(0)->getType())->getElementType()((getOperand(2)->getType() == cast<PointerType>(getOperand
(0)->getType())->getElementType() && "Ptr must be a pointer to NewVal type!"
) ? static_cast<void> (0) : __assert_fail ("getOperand(2)->getType() == cast<PointerType>(getOperand(0)->getType())->getElementType() && \"Ptr must be a pointer to NewVal type!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1500, __PRETTY_FUNCTION__))
1500 && "Ptr must be a pointer to NewVal type!")((getOperand(2)->getType() == cast<PointerType>(getOperand
(0)->getType())->getElementType() && "Ptr must be a pointer to NewVal type!"
) ? static_cast<void> (0) : __assert_fail ("getOperand(2)->getType() == cast<PointerType>(getOperand(0)->getType())->getElementType() && \"Ptr must be a pointer to NewVal type!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1500, __PRETTY_FUNCTION__))
;
1501 assert(SuccessOrdering != AtomicOrdering::NotAtomic &&((SuccessOrdering != AtomicOrdering::NotAtomic && "AtomicCmpXchg instructions must be atomic!"
) ? static_cast<void> (0) : __assert_fail ("SuccessOrdering != AtomicOrdering::NotAtomic && \"AtomicCmpXchg instructions must be atomic!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1502, __PRETTY_FUNCTION__))
1502 "AtomicCmpXchg instructions must be atomic!")((SuccessOrdering != AtomicOrdering::NotAtomic && "AtomicCmpXchg instructions must be atomic!"
) ? static_cast<void> (0) : __assert_fail ("SuccessOrdering != AtomicOrdering::NotAtomic && \"AtomicCmpXchg instructions must be atomic!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1502, __PRETTY_FUNCTION__))
;
1503 assert(FailureOrdering != AtomicOrdering::NotAtomic &&((FailureOrdering != AtomicOrdering::NotAtomic && "AtomicCmpXchg instructions must be atomic!"
) ? static_cast<void> (0) : __assert_fail ("FailureOrdering != AtomicOrdering::NotAtomic && \"AtomicCmpXchg instructions must be atomic!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1504, __PRETTY_FUNCTION__))
1504 "AtomicCmpXchg instructions must be atomic!")((FailureOrdering != AtomicOrdering::NotAtomic && "AtomicCmpXchg instructions must be atomic!"
) ? static_cast<void> (0) : __assert_fail ("FailureOrdering != AtomicOrdering::NotAtomic && \"AtomicCmpXchg instructions must be atomic!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1504, __PRETTY_FUNCTION__))
;
1505 assert(!isStrongerThan(FailureOrdering, SuccessOrdering) &&((!isStrongerThan(FailureOrdering, SuccessOrdering) &&
"AtomicCmpXchg failure argument shall be no stronger than the success "
"argument") ? static_cast<void> (0) : __assert_fail ("!isStrongerThan(FailureOrdering, SuccessOrdering) && \"AtomicCmpXchg failure argument shall be no stronger than the success \" \"argument\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1507, __PRETTY_FUNCTION__))
1506 "AtomicCmpXchg failure argument shall be no stronger than the success "((!isStrongerThan(FailureOrdering, SuccessOrdering) &&
"AtomicCmpXchg failure argument shall be no stronger than the success "
"argument") ? static_cast<void> (0) : __assert_fail ("!isStrongerThan(FailureOrdering, SuccessOrdering) && \"AtomicCmpXchg failure argument shall be no stronger than the success \" \"argument\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1507, __PRETTY_FUNCTION__))
1507 "argument")((!isStrongerThan(FailureOrdering, SuccessOrdering) &&
"AtomicCmpXchg failure argument shall be no stronger than the success "
"argument") ? static_cast<void> (0) : __assert_fail ("!isStrongerThan(FailureOrdering, SuccessOrdering) && \"AtomicCmpXchg failure argument shall be no stronger than the success \" \"argument\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1507, __PRETTY_FUNCTION__))
;
1508 assert(FailureOrdering != AtomicOrdering::Release &&((FailureOrdering != AtomicOrdering::Release && FailureOrdering
!= AtomicOrdering::AcquireRelease && "AtomicCmpXchg failure ordering cannot include release semantics"
) ? static_cast<void> (0) : __assert_fail ("FailureOrdering != AtomicOrdering::Release && FailureOrdering != AtomicOrdering::AcquireRelease && \"AtomicCmpXchg failure ordering cannot include release semantics\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1510, __PRETTY_FUNCTION__))
1509 FailureOrdering != AtomicOrdering::AcquireRelease &&((FailureOrdering != AtomicOrdering::Release && FailureOrdering
!= AtomicOrdering::AcquireRelease && "AtomicCmpXchg failure ordering cannot include release semantics"
) ? static_cast<void> (0) : __assert_fail ("FailureOrdering != AtomicOrdering::Release && FailureOrdering != AtomicOrdering::AcquireRelease && \"AtomicCmpXchg failure ordering cannot include release semantics\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1510, __PRETTY_FUNCTION__))
1510 "AtomicCmpXchg failure ordering cannot include release semantics")((FailureOrdering != AtomicOrdering::Release && FailureOrdering
!= AtomicOrdering::AcquireRelease && "AtomicCmpXchg failure ordering cannot include release semantics"
) ? static_cast<void> (0) : __assert_fail ("FailureOrdering != AtomicOrdering::Release && FailureOrdering != AtomicOrdering::AcquireRelease && \"AtomicCmpXchg failure ordering cannot include release semantics\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1510, __PRETTY_FUNCTION__))
;
1511}
1512
1513AtomicCmpXchgInst::AtomicCmpXchgInst(Value *Ptr, Value *Cmp, Value *NewVal,
1514 AtomicOrdering SuccessOrdering,
1515 AtomicOrdering FailureOrdering,
1516 SyncScope::ID SSID,
1517 Instruction *InsertBefore)
1518 : Instruction(
1519 StructType::get(Cmp->getType(), Type::getInt1Ty(Cmp->getContext())),
1520 AtomicCmpXchg, OperandTraits<AtomicCmpXchgInst>::op_begin(this),
1521 OperandTraits<AtomicCmpXchgInst>::operands(this), InsertBefore) {
1522 Init(Ptr, Cmp, NewVal, SuccessOrdering, FailureOrdering, SSID);
1523}
1524
1525AtomicCmpXchgInst::AtomicCmpXchgInst(Value *Ptr, Value *Cmp, Value *NewVal,
1526 AtomicOrdering SuccessOrdering,
1527 AtomicOrdering FailureOrdering,
1528 SyncScope::ID SSID,
1529 BasicBlock *InsertAtEnd)
1530 : Instruction(
1531 StructType::get(Cmp->getType(), Type::getInt1Ty(Cmp->getContext())),
1532 AtomicCmpXchg, OperandTraits<AtomicCmpXchgInst>::op_begin(this),
1533 OperandTraits<AtomicCmpXchgInst>::operands(this), InsertAtEnd) {
1534 Init(Ptr, Cmp, NewVal, SuccessOrdering, FailureOrdering, SSID);
1535}
1536
1537//===----------------------------------------------------------------------===//
1538// AtomicRMWInst Implementation
1539//===----------------------------------------------------------------------===//
1540
1541void AtomicRMWInst::Init(BinOp Operation, Value *Ptr, Value *Val,
1542 AtomicOrdering Ordering,
1543 SyncScope::ID SSID) {
1544 Op<0>() = Ptr;
1545 Op<1>() = Val;
1546 setOperation(Operation);
1547 setOrdering(Ordering);
1548 setSyncScopeID(SSID);
1549
1550 assert(getOperand(0) && getOperand(1) &&((getOperand(0) && getOperand(1) && "All operands must be non-null!"
) ? static_cast<void> (0) : __assert_fail ("getOperand(0) && getOperand(1) && \"All operands must be non-null!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1551, __PRETTY_FUNCTION__))
1551 "All operands must be non-null!")((getOperand(0) && getOperand(1) && "All operands must be non-null!"
) ? static_cast<void> (0) : __assert_fail ("getOperand(0) && getOperand(1) && \"All operands must be non-null!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1551, __PRETTY_FUNCTION__))
;
1552 assert(getOperand(0)->getType()->isPointerTy() &&((getOperand(0)->getType()->isPointerTy() && "Ptr must have pointer type!"
) ? static_cast<void> (0) : __assert_fail ("getOperand(0)->getType()->isPointerTy() && \"Ptr must have pointer type!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1553, __PRETTY_FUNCTION__))
1553 "Ptr must have pointer type!")((getOperand(0)->getType()->isPointerTy() && "Ptr must have pointer type!"
) ? static_cast<void> (0) : __assert_fail ("getOperand(0)->getType()->isPointerTy() && \"Ptr must have pointer type!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1553, __PRETTY_FUNCTION__))
;
1554 assert(getOperand(1)->getType() ==((getOperand(1)->getType() == cast<PointerType>(getOperand
(0)->getType())->getElementType() && "Ptr must be a pointer to Val type!"
) ? static_cast<void> (0) : __assert_fail ("getOperand(1)->getType() == cast<PointerType>(getOperand(0)->getType())->getElementType() && \"Ptr must be a pointer to Val type!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1556, __PRETTY_FUNCTION__))
1555 cast<PointerType>(getOperand(0)->getType())->getElementType()((getOperand(1)->getType() == cast<PointerType>(getOperand
(0)->getType())->getElementType() && "Ptr must be a pointer to Val type!"
) ? static_cast<void> (0) : __assert_fail ("getOperand(1)->getType() == cast<PointerType>(getOperand(0)->getType())->getElementType() && \"Ptr must be a pointer to Val type!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1556, __PRETTY_FUNCTION__))
1556 && "Ptr must be a pointer to Val type!")((getOperand(1)->getType() == cast<PointerType>(getOperand
(0)->getType())->getElementType() && "Ptr must be a pointer to Val type!"
) ? static_cast<void> (0) : __assert_fail ("getOperand(1)->getType() == cast<PointerType>(getOperand(0)->getType())->getElementType() && \"Ptr must be a pointer to Val type!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1556, __PRETTY_FUNCTION__))
;
1557 assert(Ordering != AtomicOrdering::NotAtomic &&((Ordering != AtomicOrdering::NotAtomic && "AtomicRMW instructions must be atomic!"
) ? static_cast<void> (0) : __assert_fail ("Ordering != AtomicOrdering::NotAtomic && \"AtomicRMW instructions must be atomic!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1558, __PRETTY_FUNCTION__))
1558 "AtomicRMW instructions must be atomic!")((Ordering != AtomicOrdering::NotAtomic && "AtomicRMW instructions must be atomic!"
) ? static_cast<void> (0) : __assert_fail ("Ordering != AtomicOrdering::NotAtomic && \"AtomicRMW instructions must be atomic!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1558, __PRETTY_FUNCTION__))
;
1559}
1560
1561AtomicRMWInst::AtomicRMWInst(BinOp Operation, Value *Ptr, Value *Val,
1562 AtomicOrdering Ordering,
1563 SyncScope::ID SSID,
1564 Instruction *InsertBefore)
1565 : Instruction(Val->getType(), AtomicRMW,
1566 OperandTraits<AtomicRMWInst>::op_begin(this),
1567 OperandTraits<AtomicRMWInst>::operands(this),
1568 InsertBefore) {
1569 Init(Operation, Ptr, Val, Ordering, SSID);
1570}
1571
1572AtomicRMWInst::AtomicRMWInst(BinOp Operation, Value *Ptr, Value *Val,
1573 AtomicOrdering Ordering,
1574 SyncScope::ID SSID,
1575 BasicBlock *InsertAtEnd)
1576 : Instruction(Val->getType(), AtomicRMW,
1577 OperandTraits<AtomicRMWInst>::op_begin(this),
1578 OperandTraits<AtomicRMWInst>::operands(this),
1579 InsertAtEnd) {
1580 Init(Operation, Ptr, Val, Ordering, SSID);
1581}
1582
1583StringRef AtomicRMWInst::getOperationName(BinOp Op) {
1584 switch (Op) {
1585 case AtomicRMWInst::Xchg:
1586 return "xchg";
1587 case AtomicRMWInst::Add:
1588 return "add";
1589 case AtomicRMWInst::Sub:
1590 return "sub";
1591 case AtomicRMWInst::And:
1592 return "and";
1593 case AtomicRMWInst::Nand:
1594 return "nand";
1595 case AtomicRMWInst::Or:
1596 return "or";
1597 case AtomicRMWInst::Xor:
1598 return "xor";
1599 case AtomicRMWInst::Max:
1600 return "max";
1601 case AtomicRMWInst::Min:
1602 return "min";
1603 case AtomicRMWInst::UMax:
1604 return "umax";
1605 case AtomicRMWInst::UMin:
1606 return "umin";
1607 case AtomicRMWInst::FAdd:
1608 return "fadd";
1609 case AtomicRMWInst::FSub:
1610 return "fsub";
1611 case AtomicRMWInst::BAD_BINOP:
1612 return "<invalid operation>";
1613 }
1614
1615 llvm_unreachable("invalid atomicrmw operation")::llvm::llvm_unreachable_internal("invalid atomicrmw operation"
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1615)
;
1616}
1617
1618//===----------------------------------------------------------------------===//
1619// FenceInst Implementation
1620//===----------------------------------------------------------------------===//
1621
1622FenceInst::FenceInst(LLVMContext &C, AtomicOrdering Ordering,
1623 SyncScope::ID SSID,
1624 Instruction *InsertBefore)
1625 : Instruction(Type::getVoidTy(C), Fence, nullptr, 0, InsertBefore) {
1626 setOrdering(Ordering);
1627 setSyncScopeID(SSID);
1628}
1629
1630FenceInst::FenceInst(LLVMContext &C, AtomicOrdering Ordering,
1631 SyncScope::ID SSID,
1632 BasicBlock *InsertAtEnd)
1633 : Instruction(Type::getVoidTy(C), Fence, nullptr, 0, InsertAtEnd) {
1634 setOrdering(Ordering);
1635 setSyncScopeID(SSID);
1636}
1637
1638//===----------------------------------------------------------------------===//
1639// GetElementPtrInst Implementation
1640//===----------------------------------------------------------------------===//
1641
1642void GetElementPtrInst::init(Value *Ptr, ArrayRef<Value *> IdxList,
1643 const Twine &Name) {
1644 assert(getNumOperands() == 1 + IdxList.size() &&((getNumOperands() == 1 + IdxList.size() && "NumOperands not initialized?"
) ? static_cast<void> (0) : __assert_fail ("getNumOperands() == 1 + IdxList.size() && \"NumOperands not initialized?\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1645, __PRETTY_FUNCTION__))
1645 "NumOperands not initialized?")((getNumOperands() == 1 + IdxList.size() && "NumOperands not initialized?"
) ? static_cast<void> (0) : __assert_fail ("getNumOperands() == 1 + IdxList.size() && \"NumOperands not initialized?\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1645, __PRETTY_FUNCTION__))
;
1646 Op<0>() = Ptr;
1647 llvm::copy(IdxList, op_begin() + 1);
1648 setName(Name);
1649}
1650
1651GetElementPtrInst::GetElementPtrInst(const GetElementPtrInst &GEPI)
1652 : Instruction(GEPI.getType(), GetElementPtr,
1653 OperandTraits<GetElementPtrInst>::op_end(this) -
1654 GEPI.getNumOperands(),
1655 GEPI.getNumOperands()),
1656 SourceElementType(GEPI.SourceElementType),
1657 ResultElementType(GEPI.ResultElementType) {
1658 std::copy(GEPI.op_begin(), GEPI.op_end(), op_begin());
1659 SubclassOptionalData = GEPI.SubclassOptionalData;
1660}
1661
1662/// getIndexedType - Returns the type of the element that would be accessed with
1663/// a gep instruction with the specified parameters.
1664///
1665/// The Idxs pointer should point to a continuous piece of memory containing the
1666/// indices, either as Value* or uint64_t.
1667///
1668/// A null type is returned if the indices are invalid for the specified
1669/// pointer type.
1670///
1671template <typename IndexTy>
1672static Type *getIndexedTypeInternal(Type *Agg, ArrayRef<IndexTy> IdxList) {
1673 // Handle the special case of the empty set index set, which is always valid.
1674 if (IdxList.empty())
1675 return Agg;
1676
1677 // If there is at least one index, the top level type must be sized, otherwise
1678 // it cannot be 'stepped over'.
1679 if (!Agg->isSized())
1680 return nullptr;
1681
1682 unsigned CurIdx = 1;
1683 for (; CurIdx != IdxList.size(); ++CurIdx) {
1684 CompositeType *CT = dyn_cast<CompositeType>(Agg);
1685 if (!CT || CT->isPointerTy()) return nullptr;
1686 IndexTy Index = IdxList[CurIdx];
1687 if (!CT->indexValid(Index)) return nullptr;
1688 Agg = CT->getTypeAtIndex(Index);
1689 }
1690 return CurIdx == IdxList.size() ? Agg : nullptr;
1691}
1692
1693Type *GetElementPtrInst::getIndexedType(Type *Ty, ArrayRef<Value *> IdxList) {
1694 return getIndexedTypeInternal(Ty, IdxList);
1695}
1696
1697Type *GetElementPtrInst::getIndexedType(Type *Ty,
1698 ArrayRef<Constant *> IdxList) {
1699 return getIndexedTypeInternal(Ty, IdxList);
1700}
1701
1702Type *GetElementPtrInst::getIndexedType(Type *Ty, ArrayRef<uint64_t> IdxList) {
1703 return getIndexedTypeInternal(Ty, IdxList);
1704}
1705
1706/// hasAllZeroIndices - Return true if all of the indices of this GEP are
1707/// zeros. If so, the result pointer and the first operand have the same
1708/// value, just potentially different types.
1709bool GetElementPtrInst::hasAllZeroIndices() const {
1710 for (unsigned i = 1, e = getNumOperands(); i != e; ++i) {
1711 if (ConstantInt *CI = dyn_cast<ConstantInt>(getOperand(i))) {
1712 if (!CI->isZero()) return false;
1713 } else {
1714 return false;
1715 }
1716 }
1717 return true;
1718}
1719
1720/// hasAllConstantIndices - Return true if all of the indices of this GEP are
1721/// constant integers. If so, the result pointer and the first operand have
1722/// a constant offset between them.
1723bool GetElementPtrInst::hasAllConstantIndices() const {
1724 for (unsigned i = 1, e = getNumOperands(); i != e; ++i) {
1725 if (!isa<ConstantInt>(getOperand(i)))
1726 return false;
1727 }
1728 return true;
1729}
1730
1731void GetElementPtrInst::setIsInBounds(bool B) {
1732 cast<GEPOperator>(this)->setIsInBounds(B);
1733}
1734
1735bool GetElementPtrInst::isInBounds() const {
1736 return cast<GEPOperator>(this)->isInBounds();
1737}
1738
1739bool GetElementPtrInst::accumulateConstantOffset(const DataLayout &DL,
1740 APInt &Offset) const {
1741 // Delegate to the generic GEPOperator implementation.
1742 return cast<GEPOperator>(this)->accumulateConstantOffset(DL, Offset);
1743}
1744
1745//===----------------------------------------------------------------------===//
1746// ExtractElementInst Implementation
1747//===----------------------------------------------------------------------===//
1748
1749ExtractElementInst::ExtractElementInst(Value *Val, Value *Index,
1750 const Twine &Name,
1751 Instruction *InsertBef)
1752 : Instruction(cast<VectorType>(Val->getType())->getElementType(),
1753 ExtractElement,
1754 OperandTraits<ExtractElementInst>::op_begin(this),
1755 2, InsertBef) {
1756 assert(isValidOperands(Val, Index) &&((isValidOperands(Val, Index) && "Invalid extractelement instruction operands!"
) ? static_cast<void> (0) : __assert_fail ("isValidOperands(Val, Index) && \"Invalid extractelement instruction operands!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1757, __PRETTY_FUNCTION__))
1757 "Invalid extractelement instruction operands!")((isValidOperands(Val, Index) && "Invalid extractelement instruction operands!"
) ? static_cast<void> (0) : __assert_fail ("isValidOperands(Val, Index) && \"Invalid extractelement instruction operands!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1757, __PRETTY_FUNCTION__))
;
1758 Op<0>() = Val;
1759 Op<1>() = Index;
1760 setName(Name);
1761}
1762
1763ExtractElementInst::ExtractElementInst(Value *Val, Value *Index,
1764 const Twine &Name,
1765 BasicBlock *InsertAE)
1766 : Instruction(cast<VectorType>(Val->getType())->getElementType(),
1767 ExtractElement,
1768 OperandTraits<ExtractElementInst>::op_begin(this),
1769 2, InsertAE) {
1770 assert(isValidOperands(Val, Index) &&((isValidOperands(Val, Index) && "Invalid extractelement instruction operands!"
) ? static_cast<void> (0) : __assert_fail ("isValidOperands(Val, Index) && \"Invalid extractelement instruction operands!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1771, __PRETTY_FUNCTION__))
1771 "Invalid extractelement instruction operands!")((isValidOperands(Val, Index) && "Invalid extractelement instruction operands!"
) ? static_cast<void> (0) : __assert_fail ("isValidOperands(Val, Index) && \"Invalid extractelement instruction operands!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1771, __PRETTY_FUNCTION__))
;
1772
1773 Op<0>() = Val;
1774 Op<1>() = Index;
1775 setName(Name);
1776}
1777
1778bool ExtractElementInst::isValidOperands(const Value *Val, const Value *Index) {
1779 if (!Val->getType()->isVectorTy() || !Index->getType()->isIntegerTy())
1780 return false;
1781 return true;
1782}
1783
1784//===----------------------------------------------------------------------===//
1785// InsertElementInst Implementation
1786//===----------------------------------------------------------------------===//
1787
1788InsertElementInst::InsertElementInst(Value *Vec, Value *Elt, Value *Index,
1789 const Twine &Name,
1790 Instruction *InsertBef)
1791 : Instruction(Vec->getType(), InsertElement,
1792 OperandTraits<InsertElementInst>::op_begin(this),
1793 3, InsertBef) {
1794 assert(isValidOperands(Vec, Elt, Index) &&((isValidOperands(Vec, Elt, Index) && "Invalid insertelement instruction operands!"
) ? static_cast<void> (0) : __assert_fail ("isValidOperands(Vec, Elt, Index) && \"Invalid insertelement instruction operands!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1795, __PRETTY_FUNCTION__))
1795 "Invalid insertelement instruction operands!")((isValidOperands(Vec, Elt, Index) && "Invalid insertelement instruction operands!"
) ? static_cast<void> (0) : __assert_fail ("isValidOperands(Vec, Elt, Index) && \"Invalid insertelement instruction operands!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1795, __PRETTY_FUNCTION__))
;
1796 Op<0>() = Vec;
1797 Op<1>() = Elt;
1798 Op<2>() = Index;
1799 setName(Name);
1800}
1801
1802InsertElementInst::InsertElementInst(Value *Vec, Value *Elt, Value *Index,
1803 const Twine &Name,
1804 BasicBlock *InsertAE)
1805 : Instruction(Vec->getType(), InsertElement,
1806 OperandTraits<InsertElementInst>::op_begin(this),
1807 3, InsertAE) {
1808 assert(isValidOperands(Vec, Elt, Index) &&((isValidOperands(Vec, Elt, Index) && "Invalid insertelement instruction operands!"
) ? static_cast<void> (0) : __assert_fail ("isValidOperands(Vec, Elt, Index) && \"Invalid insertelement instruction operands!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1809, __PRETTY_FUNCTION__))
1809 "Invalid insertelement instruction operands!")((isValidOperands(Vec, Elt, Index) && "Invalid insertelement instruction operands!"
) ? static_cast<void> (0) : __assert_fail ("isValidOperands(Vec, Elt, Index) && \"Invalid insertelement instruction operands!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1809, __PRETTY_FUNCTION__))
;
1810
1811 Op<0>() = Vec;
1812 Op<1>() = Elt;
1813 Op<2>() = Index;
1814 setName(Name);
1815}
1816
1817bool InsertElementInst::isValidOperands(const Value *Vec, const Value *Elt,
1818 const Value *Index) {
1819 if (!Vec->getType()->isVectorTy())
1820 return false; // First operand of insertelement must be vector type.
1821
1822 if (Elt->getType() != cast<VectorType>(Vec->getType())->getElementType())
1823 return false;// Second operand of insertelement must be vector element type.
1824
1825 if (!Index->getType()->isIntegerTy())
1826 return false; // Third operand of insertelement must be i32.
1827 return true;
1828}
1829
1830//===----------------------------------------------------------------------===//
1831// ShuffleVectorInst Implementation
1832//===----------------------------------------------------------------------===//
1833
1834ShuffleVectorInst::ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1835 const Twine &Name,
1836 Instruction *InsertBefore)
1837: Instruction(VectorType::get(cast<VectorType>(V1->getType())->getElementType(),
1838 cast<VectorType>(Mask->getType())->getElementCount()),
1839 ShuffleVector,
1840 OperandTraits<ShuffleVectorInst>::op_begin(this),
1841 OperandTraits<ShuffleVectorInst>::operands(this),
1842 InsertBefore) {
1843 assert(isValidOperands(V1, V2, Mask) &&((isValidOperands(V1, V2, Mask) && "Invalid shuffle vector instruction operands!"
) ? static_cast<void> (0) : __assert_fail ("isValidOperands(V1, V2, Mask) && \"Invalid shuffle vector instruction operands!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1844, __PRETTY_FUNCTION__))
1844 "Invalid shuffle vector instruction operands!")((isValidOperands(V1, V2, Mask) && "Invalid shuffle vector instruction operands!"
) ? static_cast<void> (0) : __assert_fail ("isValidOperands(V1, V2, Mask) && \"Invalid shuffle vector instruction operands!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1844, __PRETTY_FUNCTION__))
;
1845 Op<0>() = V1;
1846 Op<1>() = V2;
1847 Op<2>() = Mask;
1848 setName(Name);
1849}
1850
1851ShuffleVectorInst::ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1852 const Twine &Name,
1853 BasicBlock *InsertAtEnd)
1854: Instruction(VectorType::get(cast<VectorType>(V1->getType())->getElementType(),
1855 cast<VectorType>(Mask->getType())->getElementCount()),
1856 ShuffleVector,
1857 OperandTraits<ShuffleVectorInst>::op_begin(this),
1858 OperandTraits<ShuffleVectorInst>::operands(this),
1859 InsertAtEnd) {
1860 assert(isValidOperands(V1, V2, Mask) &&((isValidOperands(V1, V2, Mask) && "Invalid shuffle vector instruction operands!"
) ? static_cast<void> (0) : __assert_fail ("isValidOperands(V1, V2, Mask) && \"Invalid shuffle vector instruction operands!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1861, __PRETTY_FUNCTION__))
1861 "Invalid shuffle vector instruction operands!")((isValidOperands(V1, V2, Mask) && "Invalid shuffle vector instruction operands!"
) ? static_cast<void> (0) : __assert_fail ("isValidOperands(V1, V2, Mask) && \"Invalid shuffle vector instruction operands!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1861, __PRETTY_FUNCTION__))
;
1862
1863 Op<0>() = V1;
1864 Op<1>() = V2;
1865 Op<2>() = Mask;
1866 setName(Name);
1867}
1868
1869void ShuffleVectorInst::commute() {
1870 int NumOpElts = Op<0>()->getType()->getVectorNumElements();
1871 int NumMaskElts = getMask()->getType()->getVectorNumElements();
1872 SmallVector<Constant*, 16> NewMask(NumMaskElts);
1873 Type *Int32Ty = Type::getInt32Ty(getContext());
1874 for (int i = 0; i != NumMaskElts; ++i) {
1875 int MaskElt = getMaskValue(i);
1876 if (MaskElt == -1) {
1877 NewMask[i] = UndefValue::get(Int32Ty);
1878 continue;
1879 }
1880 assert(MaskElt >= 0 && MaskElt < 2 * NumOpElts && "Out-of-range mask")((MaskElt >= 0 && MaskElt < 2 * NumOpElts &&
"Out-of-range mask") ? static_cast<void> (0) : __assert_fail
("MaskElt >= 0 && MaskElt < 2 * NumOpElts && \"Out-of-range mask\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1880, __PRETTY_FUNCTION__))
;
1881 MaskElt = (MaskElt < NumOpElts) ? MaskElt + NumOpElts : MaskElt - NumOpElts;
1882 NewMask[i] = ConstantInt::get(Int32Ty, MaskElt);
1883 }
1884 Op<2>() = ConstantVector::get(NewMask);
1885 Op<0>().swap(Op<1>());
1886}
1887
1888bool ShuffleVectorInst::isValidOperands(const Value *V1, const Value *V2,
1889 const Value *Mask) {
1890 // V1 and V2 must be vectors of the same type.
1891 if (!V1->getType()->isVectorTy() || V1->getType() != V2->getType())
1892 return false;
1893
1894 // Mask must be vector of i32.
1895 auto *MaskTy = dyn_cast<VectorType>(Mask->getType());
1896 if (!MaskTy || !MaskTy->getElementType()->isIntegerTy(32))
1897 return false;
1898
1899 // Check to see if Mask is valid.
1900 if (isa<UndefValue>(Mask) || isa<ConstantAggregateZero>(Mask))
1901 return true;
1902
1903 if (const auto *MV = dyn_cast<ConstantVector>(Mask)) {
1904 unsigned V1Size = cast<VectorType>(V1->getType())->getNumElements();
1905 for (Value *Op : MV->operands()) {
1906 if (auto *CI = dyn_cast<ConstantInt>(Op)) {
1907 if (CI->uge(V1Size*2))
1908 return false;
1909 } else if (!isa<UndefValue>(Op)) {
1910 return false;
1911 }
1912 }
1913 return true;
1914 }
1915
1916 if (const auto *CDS = dyn_cast<ConstantDataSequential>(Mask)) {
1917 unsigned V1Size = cast<VectorType>(V1->getType())->getNumElements();
1918 for (unsigned i = 0, e = MaskTy->getNumElements(); i != e; ++i)
1919 if (CDS->getElementAsInteger(i) >= V1Size*2)
1920 return false;
1921 return true;
1922 }
1923
1924 // The bitcode reader can create a place holder for a forward reference
1925 // used as the shuffle mask. When this occurs, the shuffle mask will
1926 // fall into this case and fail. To avoid this error, do this bit of
1927 // ugliness to allow such a mask pass.
1928 if (const auto *CE = dyn_cast<ConstantExpr>(Mask))
1929 if (CE->getOpcode() == Instruction::UserOp1)
1930 return true;
1931
1932 return false;
1933}
1934
1935int ShuffleVectorInst::getMaskValue(const Constant *Mask, unsigned i) {
1936 assert(i < Mask->getType()->getVectorNumElements() && "Index out of range")((i < Mask->getType()->getVectorNumElements() &&
"Index out of range") ? static_cast<void> (0) : __assert_fail
("i < Mask->getType()->getVectorNumElements() && \"Index out of range\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1936, __PRETTY_FUNCTION__))
;
1937 assert(!Mask->getType()->getVectorElementCount().Scalable &&((!Mask->getType()->getVectorElementCount().Scalable &&
"Length of scalable vectors unknown at compile time") ? static_cast
<void> (0) : __assert_fail ("!Mask->getType()->getVectorElementCount().Scalable && \"Length of scalable vectors unknown at compile time\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1938, __PRETTY_FUNCTION__))
1938 "Length of scalable vectors unknown at compile time")((!Mask->getType()->getVectorElementCount().Scalable &&
"Length of scalable vectors unknown at compile time") ? static_cast
<void> (0) : __assert_fail ("!Mask->getType()->getVectorElementCount().Scalable && \"Length of scalable vectors unknown at compile time\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1938, __PRETTY_FUNCTION__))
;
1939 if (auto *CDS = dyn_cast<ConstantDataSequential>(Mask))
1940 return CDS->getElementAsInteger(i);
1941 Constant *C = Mask->getAggregateElement(i);
1942 if (isa<UndefValue>(C))
1943 return -1;
1944 return cast<ConstantInt>(C)->getZExtValue();
1945}
1946
1947void ShuffleVectorInst::getShuffleMask(const Constant *Mask,
1948 SmallVectorImpl<int> &Result) {
1949 assert(!Mask->getType()->getVectorElementCount().Scalable &&((!Mask->getType()->getVectorElementCount().Scalable &&
"Length of scalable vectors unknown at compile time") ? static_cast
<void> (0) : __assert_fail ("!Mask->getType()->getVectorElementCount().Scalable && \"Length of scalable vectors unknown at compile time\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1950, __PRETTY_FUNCTION__))
1950 "Length of scalable vectors unknown at compile time")((!Mask->getType()->getVectorElementCount().Scalable &&
"Length of scalable vectors unknown at compile time") ? static_cast
<void> (0) : __assert_fail ("!Mask->getType()->getVectorElementCount().Scalable && \"Length of scalable vectors unknown at compile time\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1950, __PRETTY_FUNCTION__))
;
1951 unsigned NumElts = Mask->getType()->getVectorNumElements();
1952
1953 if (auto *CDS = dyn_cast<ConstantDataSequential>(Mask)) {
1954 for (unsigned i = 0; i != NumElts; ++i)
1955 Result.push_back(CDS->getElementAsInteger(i));
1956 return;
1957 }
1958 for (unsigned i = 0; i != NumElts; ++i) {
1959 Constant *C = Mask->getAggregateElement(i);
1960 Result.push_back(isa<UndefValue>(C) ? -1 :
1961 cast<ConstantInt>(C)->getZExtValue());
1962 }
1963}
1964
1965static bool isSingleSourceMaskImpl(ArrayRef<int> Mask, int NumOpElts) {
1966 assert(!Mask.empty() && "Shuffle mask must contain elements")((!Mask.empty() && "Shuffle mask must contain elements"
) ? static_cast<void> (0) : __assert_fail ("!Mask.empty() && \"Shuffle mask must contain elements\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1966, __PRETTY_FUNCTION__))
;
1967 bool UsesLHS = false;
1968 bool UsesRHS = false;
1969 for (int i = 0, NumMaskElts = Mask.size(); i < NumMaskElts; ++i) {
1970 if (Mask[i] == -1)
1971 continue;
1972 assert(Mask[i] >= 0 && Mask[i] < (NumOpElts * 2) &&((Mask[i] >= 0 && Mask[i] < (NumOpElts * 2) &&
"Out-of-bounds shuffle mask element") ? static_cast<void>
(0) : __assert_fail ("Mask[i] >= 0 && Mask[i] < (NumOpElts * 2) && \"Out-of-bounds shuffle mask element\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1973, __PRETTY_FUNCTION__))
1973 "Out-of-bounds shuffle mask element")((Mask[i] >= 0 && Mask[i] < (NumOpElts * 2) &&
"Out-of-bounds shuffle mask element") ? static_cast<void>
(0) : __assert_fail ("Mask[i] >= 0 && Mask[i] < (NumOpElts * 2) && \"Out-of-bounds shuffle mask element\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1973, __PRETTY_FUNCTION__))
;
1974 UsesLHS |= (Mask[i] < NumOpElts);
1975 UsesRHS |= (Mask[i] >= NumOpElts);
1976 if (UsesLHS && UsesRHS)
1977 return false;
1978 }
1979 assert((UsesLHS ^ UsesRHS) && "Should have selected from exactly 1 source")(((UsesLHS ^ UsesRHS) && "Should have selected from exactly 1 source"
) ? static_cast<void> (0) : __assert_fail ("(UsesLHS ^ UsesRHS) && \"Should have selected from exactly 1 source\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 1979, __PRETTY_FUNCTION__))
;
1980 return true;
1981}
1982
1983bool ShuffleVectorInst::isSingleSourceMask(ArrayRef<int> Mask) {
1984 // We don't have vector operand size information, so assume operands are the
1985 // same size as the mask.
1986 return isSingleSourceMaskImpl(Mask, Mask.size());
1987}
1988
1989static bool isIdentityMaskImpl(ArrayRef<int> Mask, int NumOpElts) {
1990 if (!isSingleSourceMaskImpl(Mask, NumOpElts))
1991 return false;
1992 for (int i = 0, NumMaskElts = Mask.size(); i < NumMaskElts; ++i) {
1993 if (Mask[i] == -1)
1994 continue;
1995 if (Mask[i] != i && Mask[i] != (NumOpElts + i))
1996 return false;
1997 }
1998 return true;
1999}
2000
2001bool ShuffleVectorInst::isIdentityMask(ArrayRef<int> Mask) {
2002 // We don't have vector operand size information, so assume operands are the
2003 // same size as the mask.
2004 return isIdentityMaskImpl(Mask, Mask.size());
2005}
2006
2007bool ShuffleVectorInst::isReverseMask(ArrayRef<int> Mask) {
2008 if (!isSingleSourceMask(Mask))
2009 return false;
2010 for (int i = 0, NumElts = Mask.size(); i < NumElts; ++i) {
2011 if (Mask[i] == -1)
2012 continue;
2013 if (Mask[i] != (NumElts - 1 - i) && Mask[i] != (NumElts + NumElts - 1 - i))
2014 return false;
2015 }
2016 return true;
2017}
2018
2019bool ShuffleVectorInst::isZeroEltSplatMask(ArrayRef<int> Mask) {
2020 if (!isSingleSourceMask(Mask))
2021 return false;
2022 for (int i = 0, NumElts = Mask.size(); i < NumElts; ++i) {
2023 if (Mask[i] == -1)
2024 continue;
2025 if (Mask[i] != 0 && Mask[i] != NumElts)
2026 return false;
2027 }
2028 return true;
2029}
2030
2031bool ShuffleVectorInst::isSelectMask(ArrayRef<int> Mask) {
2032 // Select is differentiated from identity. It requires using both sources.
2033 if (isSingleSourceMask(Mask))
2034 return false;
2035 for (int i = 0, NumElts = Mask.size(); i < NumElts; ++i) {
2036 if (Mask[i] == -1)
2037 continue;
2038 if (Mask[i] != i && Mask[i] != (NumElts + i))
2039 return false;
2040 }
2041 return true;
2042}
2043
2044bool ShuffleVectorInst::isTransposeMask(ArrayRef<int> Mask) {
2045 // Example masks that will return true:
2046 // v1 = <a, b, c, d>
2047 // v2 = <e, f, g, h>
2048 // trn1 = shufflevector v1, v2 <0, 4, 2, 6> = <a, e, c, g>
2049 // trn2 = shufflevector v1, v2 <1, 5, 3, 7> = <b, f, d, h>
2050
2051 // 1. The number of elements in the mask must be a power-of-2 and at least 2.
2052 int NumElts = Mask.size();
2053 if (NumElts < 2 || !isPowerOf2_32(NumElts))
2054 return false;
2055
2056 // 2. The first element of the mask must be either a 0 or a 1.
2057 if (Mask[0] != 0 && Mask[0] != 1)
2058 return false;
2059
2060 // 3. The difference between the first 2 elements must be equal to the
2061 // number of elements in the mask.
2062 if ((Mask[1] - Mask[0]) != NumElts)
2063 return false;
2064
2065 // 4. The difference between consecutive even-numbered and odd-numbered
2066 // elements must be equal to 2.
2067 for (int i = 2; i < NumElts; ++i) {
2068 int MaskEltVal = Mask[i];
2069 if (MaskEltVal == -1)
2070 return false;
2071 int MaskEltPrevVal = Mask[i - 2];
2072 if (MaskEltVal - MaskEltPrevVal != 2)
2073 return false;
2074 }
2075 return true;
2076}
2077
2078bool ShuffleVectorInst::isExtractSubvectorMask(ArrayRef<int> Mask,
2079 int NumSrcElts, int &Index) {
2080 // Must extract from a single source.
2081 if (!isSingleSourceMaskImpl(Mask, NumSrcElts))
2082 return false;
2083
2084 // Must be smaller (else this is an Identity shuffle).
2085 if (NumSrcElts <= (int)Mask.size())
2086 return false;
2087
2088 // Find start of extraction, accounting that we may start with an UNDEF.
2089 int SubIndex = -1;
2090 for (int i = 0, e = Mask.size(); i != e; ++i) {
2091 int M = Mask[i];
2092 if (M < 0)
2093 continue;
2094 int Offset = (M % NumSrcElts) - i;
2095 if (0 <= SubIndex && SubIndex != Offset)
2096 return false;
2097 SubIndex = Offset;
2098 }
2099
2100 if (0 <= SubIndex && SubIndex + (int)Mask.size() <= NumSrcElts) {
2101 Index = SubIndex;
2102 return true;
2103 }
2104 return false;
2105}
2106
2107bool ShuffleVectorInst::isIdentityWithPadding() const {
2108 int NumOpElts = Op<0>()->getType()->getVectorNumElements();
2109 int NumMaskElts = getType()->getVectorNumElements();
2110 if (NumMaskElts <= NumOpElts)
2111 return false;
2112
2113 // The first part of the mask must choose elements from exactly 1 source op.
2114 SmallVector<int, 16> Mask = getShuffleMask();
2115 if (!isIdentityMaskImpl(Mask, NumOpElts))
2116 return false;
2117
2118 // All extending must be with undef elements.
2119 for (int i = NumOpElts; i < NumMaskElts; ++i)
2120 if (Mask[i] != -1)
2121 return false;
2122
2123 return true;
2124}
2125
2126bool ShuffleVectorInst::isIdentityWithExtract() const {
2127 int NumOpElts = Op<0>()->getType()->getVectorNumElements();
2128 int NumMaskElts = getType()->getVectorNumElements();
2129 if (NumMaskElts >= NumOpElts)
2130 return false;
2131
2132 return isIdentityMaskImpl(getShuffleMask(), NumOpElts);
2133}
2134
2135bool ShuffleVectorInst::isConcat() const {
2136 // Vector concatenation is differentiated from identity with padding.
2137 if (isa<UndefValue>(Op<0>()) || isa<UndefValue>(Op<1>()))
2138 return false;
2139
2140 int NumOpElts = Op<0>()->getType()->getVectorNumElements();
2141 int NumMaskElts = getType()->getVectorNumElements();
2142 if (NumMaskElts != NumOpElts * 2)
2143 return false;
2144
2145 // Use the mask length rather than the operands' vector lengths here. We
2146 // already know that the shuffle returns a vector twice as long as the inputs,
2147 // and neither of the inputs are undef vectors. If the mask picks consecutive
2148 // elements from both inputs, then this is a concatenation of the inputs.
2149 return isIdentityMaskImpl(getShuffleMask(), NumMaskElts);
2150}
2151
2152//===----------------------------------------------------------------------===//
2153// InsertValueInst Class
2154//===----------------------------------------------------------------------===//
2155
2156void InsertValueInst::init(Value *Agg, Value *Val, ArrayRef<unsigned> Idxs,
2157 const Twine &Name) {
2158 assert(getNumOperands() == 2 && "NumOperands not initialized?")((getNumOperands() == 2 && "NumOperands not initialized?"
) ? static_cast<void> (0) : __assert_fail ("getNumOperands() == 2 && \"NumOperands not initialized?\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2158, __PRETTY_FUNCTION__))
;
2159
2160 // There's no fundamental reason why we require at least one index
2161 // (other than weirdness with &*IdxBegin being invalid; see
2162 // getelementptr's init routine for example). But there's no
2163 // present need to support it.
2164 assert(!Idxs.empty() && "InsertValueInst must have at least one index")((!Idxs.empty() && "InsertValueInst must have at least one index"
) ? static_cast<void> (0) : __assert_fail ("!Idxs.empty() && \"InsertValueInst must have at least one index\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2164, __PRETTY_FUNCTION__))
;
2165
2166 assert(ExtractValueInst::getIndexedType(Agg->getType(), Idxs) ==((ExtractValueInst::getIndexedType(Agg->getType(), Idxs) ==
Val->getType() && "Inserted value must match indexed type!"
) ? static_cast<void> (0) : __assert_fail ("ExtractValueInst::getIndexedType(Agg->getType(), Idxs) == Val->getType() && \"Inserted value must match indexed type!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2167, __PRETTY_FUNCTION__))
2167 Val->getType() && "Inserted value must match indexed type!")((ExtractValueInst::getIndexedType(Agg->getType(), Idxs) ==
Val->getType() && "Inserted value must match indexed type!"
) ? static_cast<void> (0) : __assert_fail ("ExtractValueInst::getIndexedType(Agg->getType(), Idxs) == Val->getType() && \"Inserted value must match indexed type!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2167, __PRETTY_FUNCTION__))
;
2168 Op<0>() = Agg;
2169 Op<1>() = Val;
2170
2171 Indices.append(Idxs.begin(), Idxs.end());
2172 setName(Name);
2173}
2174
2175InsertValueInst::InsertValueInst(const InsertValueInst &IVI)
2176 : Instruction(IVI.getType(), InsertValue,
2177 OperandTraits<InsertValueInst>::op_begin(this), 2),
2178 Indices(IVI.Indices) {
2179 Op<0>() = IVI.getOperand(0);
2180 Op<1>() = IVI.getOperand(1);
2181 SubclassOptionalData = IVI.SubclassOptionalData;
2182}
2183
2184//===----------------------------------------------------------------------===//
2185// ExtractValueInst Class
2186//===----------------------------------------------------------------------===//
2187
2188void ExtractValueInst::init(ArrayRef<unsigned> Idxs, const Twine &Name) {
2189 assert(getNumOperands() == 1 && "NumOperands not initialized?")((getNumOperands() == 1 && "NumOperands not initialized?"
) ? static_cast<void> (0) : __assert_fail ("getNumOperands() == 1 && \"NumOperands not initialized?\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2189, __PRETTY_FUNCTION__))
;
2190
2191 // There's no fundamental reason why we require at least one index.
2192 // But there's no present need to support it.
2193 assert(!Idxs.empty() && "ExtractValueInst must have at least one index")((!Idxs.empty() && "ExtractValueInst must have at least one index"
) ? static_cast<void> (0) : __assert_fail ("!Idxs.empty() && \"ExtractValueInst must have at least one index\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2193, __PRETTY_FUNCTION__))
;
2194
2195 Indices.append(Idxs.begin(), Idxs.end());
2196 setName(Name);
2197}
2198
2199ExtractValueInst::ExtractValueInst(const ExtractValueInst &EVI)
2200 : UnaryInstruction(EVI.getType(), ExtractValue, EVI.getOperand(0)),
2201 Indices(EVI.Indices) {
2202 SubclassOptionalData = EVI.SubclassOptionalData;
2203}
2204
2205// getIndexedType - Returns the type of the element that would be extracted
2206// with an extractvalue instruction with the specified parameters.
2207//
2208// A null type is returned if the indices are invalid for the specified
2209// pointer type.
2210//
2211Type *ExtractValueInst::getIndexedType(Type *Agg,
2212 ArrayRef<unsigned> Idxs) {
2213 for (unsigned Index : Idxs) {
2214 // We can't use CompositeType::indexValid(Index) here.
2215 // indexValid() always returns true for arrays because getelementptr allows
2216 // out-of-bounds indices. Since we don't allow those for extractvalue and
2217 // insertvalue we need to check array indexing manually.
2218 // Since the only other types we can index into are struct types it's just
2219 // as easy to check those manually as well.
2220 if (ArrayType *AT = dyn_cast<ArrayType>(Agg)) {
2221 if (Index >= AT->getNumElements())
2222 return nullptr;
2223 } else if (StructType *ST = dyn_cast<StructType>(Agg)) {
2224 if (Index >= ST->getNumElements())
2225 return nullptr;
2226 } else {
2227 // Not a valid type to index into.
2228 return nullptr;
2229 }
2230
2231 Agg = cast<CompositeType>(Agg)->getTypeAtIndex(Index);
2232 }
2233 return const_cast<Type*>(Agg);
2234}
2235
2236//===----------------------------------------------------------------------===//
2237// UnaryOperator Class
2238//===----------------------------------------------------------------------===//
2239
2240UnaryOperator::UnaryOperator(UnaryOps iType, Value *S,
2241 Type *Ty, const Twine &Name,
2242 Instruction *InsertBefore)
2243 : UnaryInstruction(Ty, iType, S, InsertBefore) {
2244 Op<0>() = S;
2245 setName(Name);
2246 AssertOK();
2247}
2248
2249UnaryOperator::UnaryOperator(UnaryOps iType, Value *S,
2250 Type *Ty, const Twine &Name,
2251 BasicBlock *InsertAtEnd)
2252 : UnaryInstruction(Ty, iType, S, InsertAtEnd) {
2253 Op<0>() = S;
2254 setName(Name);
2255 AssertOK();
2256}
2257
2258UnaryOperator *UnaryOperator::Create(UnaryOps Op, Value *S,
2259 const Twine &Name,
2260 Instruction *InsertBefore) {
2261 return new UnaryOperator(Op, S, S->getType(), Name, InsertBefore);
2262}
2263
2264UnaryOperator *UnaryOperator::Create(UnaryOps Op, Value *S,
2265 const Twine &Name,
2266 BasicBlock *InsertAtEnd) {
2267 UnaryOperator *Res = Create(Op, S, Name);
2268 InsertAtEnd->getInstList().push_back(Res);
2269 return Res;
2270}
2271
2272void UnaryOperator::AssertOK() {
2273 Value *LHS = getOperand(0);
2274 (void)LHS; // Silence warnings.
2275#ifndef NDEBUG
2276 switch (getOpcode()) {
2277 case FNeg:
2278 assert(getType() == LHS->getType() &&((getType() == LHS->getType() && "Unary operation should return same type as operand!"
) ? static_cast<void> (0) : __assert_fail ("getType() == LHS->getType() && \"Unary operation should return same type as operand!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2279, __PRETTY_FUNCTION__))
2279 "Unary operation should return same type as operand!")((getType() == LHS->getType() && "Unary operation should return same type as operand!"
) ? static_cast<void> (0) : __assert_fail ("getType() == LHS->getType() && \"Unary operation should return same type as operand!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2279, __PRETTY_FUNCTION__))
;
2280 assert(getType()->isFPOrFPVectorTy() &&((getType()->isFPOrFPVectorTy() && "Tried to create a floating-point operation on a "
"non-floating-point type!") ? static_cast<void> (0) : __assert_fail
("getType()->isFPOrFPVectorTy() && \"Tried to create a floating-point operation on a \" \"non-floating-point type!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2282, __PRETTY_FUNCTION__))
2281 "Tried to create a floating-point operation on a "((getType()->isFPOrFPVectorTy() && "Tried to create a floating-point operation on a "
"non-floating-point type!") ? static_cast<void> (0) : __assert_fail
("getType()->isFPOrFPVectorTy() && \"Tried to create a floating-point operation on a \" \"non-floating-point type!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2282, __PRETTY_FUNCTION__))
2282 "non-floating-point type!")((getType()->isFPOrFPVectorTy() && "Tried to create a floating-point operation on a "
"non-floating-point type!") ? static_cast<void> (0) : __assert_fail
("getType()->isFPOrFPVectorTy() && \"Tried to create a floating-point operation on a \" \"non-floating-point type!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2282, __PRETTY_FUNCTION__))
;
2283 break;
2284 default: llvm_unreachable("Invalid opcode provided")::llvm::llvm_unreachable_internal("Invalid opcode provided", "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2284)
;
2285 }
2286#endif
2287}
2288
2289//===----------------------------------------------------------------------===//
2290// BinaryOperator Class
2291//===----------------------------------------------------------------------===//
2292
2293BinaryOperator::BinaryOperator(BinaryOps iType, Value *S1, Value *S2,
2294 Type *Ty, const Twine &Name,
2295 Instruction *InsertBefore)
2296 : Instruction(Ty, iType,
2297 OperandTraits<BinaryOperator>::op_begin(this),
2298 OperandTraits<BinaryOperator>::operands(this),
2299 InsertBefore) {
2300 Op<0>() = S1;
2301 Op<1>() = S2;
2302 setName(Name);
2303 AssertOK();
2304}
2305
2306BinaryOperator::BinaryOperator(BinaryOps iType, Value *S1, Value *S2,
2307 Type *Ty, const Twine &Name,
2308 BasicBlock *InsertAtEnd)
2309 : Instruction(Ty, iType,
2310 OperandTraits<BinaryOperator>::op_begin(this),
2311 OperandTraits<BinaryOperator>::operands(this),
2312 InsertAtEnd) {
2313 Op<0>() = S1;
2314 Op<1>() = S2;
2315 setName(Name);
2316 AssertOK();
2317}
2318
2319void BinaryOperator::AssertOK() {
2320 Value *LHS = getOperand(0), *RHS = getOperand(1);
2321 (void)LHS; (void)RHS; // Silence warnings.
2322 assert(LHS->getType() == RHS->getType() &&((LHS->getType() == RHS->getType() && "Binary operator operand types must match!"
) ? static_cast<void> (0) : __assert_fail ("LHS->getType() == RHS->getType() && \"Binary operator operand types must match!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2323, __PRETTY_FUNCTION__))
2323 "Binary operator operand types must match!")((LHS->getType() == RHS->getType() && "Binary operator operand types must match!"
) ? static_cast<void> (0) : __assert_fail ("LHS->getType() == RHS->getType() && \"Binary operator operand types must match!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2323, __PRETTY_FUNCTION__))
;
2324#ifndef NDEBUG
2325 switch (getOpcode()) {
2326 case Add: case Sub:
2327 case Mul:
2328 assert(getType() == LHS->getType() &&((getType() == LHS->getType() && "Arithmetic operation should return same type as operands!"
) ? static_cast<void> (0) : __assert_fail ("getType() == LHS->getType() && \"Arithmetic operation should return same type as operands!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2329, __PRETTY_FUNCTION__))
2329 "Arithmetic operation should return same type as operands!")((getType() == LHS->getType() && "Arithmetic operation should return same type as operands!"
) ? static_cast<void> (0) : __assert_fail ("getType() == LHS->getType() && \"Arithmetic operation should return same type as operands!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2329, __PRETTY_FUNCTION__))
;
2330 assert(getType()->isIntOrIntVectorTy() &&((getType()->isIntOrIntVectorTy() && "Tried to create an integer operation on a non-integer type!"
) ? static_cast<void> (0) : __assert_fail ("getType()->isIntOrIntVectorTy() && \"Tried to create an integer operation on a non-integer type!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2331, __PRETTY_FUNCTION__))
2331 "Tried to create an integer operation on a non-integer type!")((getType()->isIntOrIntVectorTy() && "Tried to create an integer operation on a non-integer type!"
) ? static_cast<void> (0) : __assert_fail ("getType()->isIntOrIntVectorTy() && \"Tried to create an integer operation on a non-integer type!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2331, __PRETTY_FUNCTION__))
;
2332 break;
2333 case FAdd: case FSub:
2334 case FMul:
2335 assert(getType() == LHS->getType() &&((getType() == LHS->getType() && "Arithmetic operation should return same type as operands!"
) ? static_cast<void> (0) : __assert_fail ("getType() == LHS->getType() && \"Arithmetic operation should return same type as operands!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2336, __PRETTY_FUNCTION__))
2336 "Arithmetic operation should return same type as operands!")((getType() == LHS->getType() && "Arithmetic operation should return same type as operands!"
) ? static_cast<void> (0) : __assert_fail ("getType() == LHS->getType() && \"Arithmetic operation should return same type as operands!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2336, __PRETTY_FUNCTION__))
;
2337 assert(getType()->isFPOrFPVectorTy() &&((getType()->isFPOrFPVectorTy() && "Tried to create a floating-point operation on a "
"non-floating-point type!") ? static_cast<void> (0) : __assert_fail
("getType()->isFPOrFPVectorTy() && \"Tried to create a floating-point operation on a \" \"non-floating-point type!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2339, __PRETTY_FUNCTION__))
2338 "Tried to create a floating-point operation on a "((getType()->isFPOrFPVectorTy() && "Tried to create a floating-point operation on a "
"non-floating-point type!") ? static_cast<void> (0) : __assert_fail
("getType()->isFPOrFPVectorTy() && \"Tried to create a floating-point operation on a \" \"non-floating-point type!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2339, __PRETTY_FUNCTION__))
2339 "non-floating-point type!")((getType()->isFPOrFPVectorTy() && "Tried to create a floating-point operation on a "
"non-floating-point type!") ? static_cast<void> (0) : __assert_fail
("getType()->isFPOrFPVectorTy() && \"Tried to create a floating-point operation on a \" \"non-floating-point type!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2339, __PRETTY_FUNCTION__))
;
2340 break;
2341 case UDiv:
2342 case SDiv:
2343 assert(getType() == LHS->getType() &&((getType() == LHS->getType() && "Arithmetic operation should return same type as operands!"
) ? static_cast<void> (0) : __assert_fail ("getType() == LHS->getType() && \"Arithmetic operation should return same type as operands!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2344, __PRETTY_FUNCTION__))
2344 "Arithmetic operation should return same type as operands!")((getType() == LHS->getType() && "Arithmetic operation should return same type as operands!"
) ? static_cast<void> (0) : __assert_fail ("getType() == LHS->getType() && \"Arithmetic operation should return same type as operands!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2344, __PRETTY_FUNCTION__))
;
2345 assert(getType()->isIntOrIntVectorTy() &&((getType()->isIntOrIntVectorTy() && "Incorrect operand type (not integer) for S/UDIV"
) ? static_cast<void> (0) : __assert_fail ("getType()->isIntOrIntVectorTy() && \"Incorrect operand type (not integer) for S/UDIV\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2346, __PRETTY_FUNCTION__))
2346 "Incorrect operand type (not integer) for S/UDIV")((getType()->isIntOrIntVectorTy() && "Incorrect operand type (not integer) for S/UDIV"
) ? static_cast<void> (0) : __assert_fail ("getType()->isIntOrIntVectorTy() && \"Incorrect operand type (not integer) for S/UDIV\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2346, __PRETTY_FUNCTION__))
;
2347 break;
2348 case FDiv:
2349 assert(getType() == LHS->getType() &&((getType() == LHS->getType() && "Arithmetic operation should return same type as operands!"
) ? static_cast<void> (0) : __assert_fail ("getType() == LHS->getType() && \"Arithmetic operation should return same type as operands!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2350, __PRETTY_FUNCTION__))
2350 "Arithmetic operation should return same type as operands!")((getType() == LHS->getType() && "Arithmetic operation should return same type as operands!"
) ? static_cast<void> (0) : __assert_fail ("getType() == LHS->getType() && \"Arithmetic operation should return same type as operands!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2350, __PRETTY_FUNCTION__))
;
2351 assert(getType()->isFPOrFPVectorTy() &&((getType()->isFPOrFPVectorTy() && "Incorrect operand type (not floating point) for FDIV"
) ? static_cast<void> (0) : __assert_fail ("getType()->isFPOrFPVectorTy() && \"Incorrect operand type (not floating point) for FDIV\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2352, __PRETTY_FUNCTION__))
2352 "Incorrect operand type (not floating point) for FDIV")((getType()->isFPOrFPVectorTy() && "Incorrect operand type (not floating point) for FDIV"
) ? static_cast<void> (0) : __assert_fail ("getType()->isFPOrFPVectorTy() && \"Incorrect operand type (not floating point) for FDIV\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2352, __PRETTY_FUNCTION__))
;
2353 break;
2354 case URem:
2355 case SRem:
2356 assert(getType() == LHS->getType() &&((getType() == LHS->getType() && "Arithmetic operation should return same type as operands!"
) ? static_cast<void> (0) : __assert_fail ("getType() == LHS->getType() && \"Arithmetic operation should return same type as operands!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2357, __PRETTY_FUNCTION__))
2357 "Arithmetic operation should return same type as operands!")((getType() == LHS->getType() && "Arithmetic operation should return same type as operands!"
) ? static_cast<void> (0) : __assert_fail ("getType() == LHS->getType() && \"Arithmetic operation should return same type as operands!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2357, __PRETTY_FUNCTION__))
;
2358 assert(getType()->isIntOrIntVectorTy() &&((getType()->isIntOrIntVectorTy() && "Incorrect operand type (not integer) for S/UREM"
) ? static_cast<void> (0) : __assert_fail ("getType()->isIntOrIntVectorTy() && \"Incorrect operand type (not integer) for S/UREM\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2359, __PRETTY_FUNCTION__))
2359 "Incorrect operand type (not integer) for S/UREM")((getType()->isIntOrIntVectorTy() && "Incorrect operand type (not integer) for S/UREM"
) ? static_cast<void> (0) : __assert_fail ("getType()->isIntOrIntVectorTy() && \"Incorrect operand type (not integer) for S/UREM\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2359, __PRETTY_FUNCTION__))
;
2360 break;
2361 case FRem:
2362 assert(getType() == LHS->getType() &&((getType() == LHS->getType() && "Arithmetic operation should return same type as operands!"
) ? static_cast<void> (0) : __assert_fail ("getType() == LHS->getType() && \"Arithmetic operation should return same type as operands!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2363, __PRETTY_FUNCTION__))
2363 "Arithmetic operation should return same type as operands!")((getType() == LHS->getType() && "Arithmetic operation should return same type as operands!"
) ? static_cast<void> (0) : __assert_fail ("getType() == LHS->getType() && \"Arithmetic operation should return same type as operands!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2363, __PRETTY_FUNCTION__))
;
2364 assert(getType()->isFPOrFPVectorTy() &&((getType()->isFPOrFPVectorTy() && "Incorrect operand type (not floating point) for FREM"
) ? static_cast<void> (0) : __assert_fail ("getType()->isFPOrFPVectorTy() && \"Incorrect operand type (not floating point) for FREM\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2365, __PRETTY_FUNCTION__))
2365 "Incorrect operand type (not floating point) for FREM")((getType()->isFPOrFPVectorTy() && "Incorrect operand type (not floating point) for FREM"
) ? static_cast<void> (0) : __assert_fail ("getType()->isFPOrFPVectorTy() && \"Incorrect operand type (not floating point) for FREM\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2365, __PRETTY_FUNCTION__))
;
2366 break;
2367 case Shl:
2368 case LShr:
2369 case AShr:
2370 assert(getType() == LHS->getType() &&((getType() == LHS->getType() && "Shift operation should return same type as operands!"
) ? static_cast<void> (0) : __assert_fail ("getType() == LHS->getType() && \"Shift operation should return same type as operands!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2371, __PRETTY_FUNCTION__))
2371 "Shift operation should return same type as operands!")((getType() == LHS->getType() && "Shift operation should return same type as operands!"
) ? static_cast<void> (0) : __assert_fail ("getType() == LHS->getType() && \"Shift operation should return same type as operands!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2371, __PRETTY_FUNCTION__))
;
2372 assert(getType()->isIntOrIntVectorTy() &&((getType()->isIntOrIntVectorTy() && "Tried to create a shift operation on a non-integral type!"
) ? static_cast<void> (0) : __assert_fail ("getType()->isIntOrIntVectorTy() && \"Tried to create a shift operation on a non-integral type!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2373, __PRETTY_FUNCTION__))
2373 "Tried to create a shift operation on a non-integral type!")((getType()->isIntOrIntVectorTy() && "Tried to create a shift operation on a non-integral type!"
) ? static_cast<void> (0) : __assert_fail ("getType()->isIntOrIntVectorTy() && \"Tried to create a shift operation on a non-integral type!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2373, __PRETTY_FUNCTION__))
;
2374 break;
2375 case And: case Or:
2376 case Xor:
2377 assert(getType() == LHS->getType() &&((getType() == LHS->getType() && "Logical operation should return same type as operands!"
) ? static_cast<void> (0) : __assert_fail ("getType() == LHS->getType() && \"Logical operation should return same type as operands!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2378, __PRETTY_FUNCTION__))
2378 "Logical operation should return same type as operands!")((getType() == LHS->getType() && "Logical operation should return same type as operands!"
) ? static_cast<void> (0) : __assert_fail ("getType() == LHS->getType() && \"Logical operation should return same type as operands!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2378, __PRETTY_FUNCTION__))
;
2379 assert(getType()->isIntOrIntVectorTy() &&((getType()->isIntOrIntVectorTy() && "Tried to create a logical operation on a non-integral type!"
) ? static_cast<void> (0) : __assert_fail ("getType()->isIntOrIntVectorTy() && \"Tried to create a logical operation on a non-integral type!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2380, __PRETTY_FUNCTION__))
2380 "Tried to create a logical operation on a non-integral type!")((getType()->isIntOrIntVectorTy() && "Tried to create a logical operation on a non-integral type!"
) ? static_cast<void> (0) : __assert_fail ("getType()->isIntOrIntVectorTy() && \"Tried to create a logical operation on a non-integral type!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2380, __PRETTY_FUNCTION__))
;
2381 break;
2382 default: llvm_unreachable("Invalid opcode provided")::llvm::llvm_unreachable_internal("Invalid opcode provided", "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2382)
;
2383 }
2384#endif
2385}
2386
2387BinaryOperator *BinaryOperator::Create(BinaryOps Op, Value *S1, Value *S2,
2388 const Twine &Name,
2389 Instruction *InsertBefore) {
2390 assert(S1->getType() == S2->getType() &&((S1->getType() == S2->getType() && "Cannot create binary operator with two operands of differing type!"
) ? static_cast<void> (0) : __assert_fail ("S1->getType() == S2->getType() && \"Cannot create binary operator with two operands of differing type!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2391, __PRETTY_FUNCTION__))
2391 "Cannot create binary operator with two operands of differing type!")((S1->getType() == S2->getType() && "Cannot create binary operator with two operands of differing type!"
) ? static_cast<void> (0) : __assert_fail ("S1->getType() == S2->getType() && \"Cannot create binary operator with two operands of differing type!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2391, __PRETTY_FUNCTION__))
;
2392 return new BinaryOperator(Op, S1, S2, S1->getType(), Name, InsertBefore);
2393}
2394
2395BinaryOperator *BinaryOperator::Create(BinaryOps Op, Value *S1, Value *S2,
2396 const Twine &Name,
2397 BasicBlock *InsertAtEnd) {
2398 BinaryOperator *Res = Create(Op, S1, S2, Name);
2399 InsertAtEnd->getInstList().push_back(Res);
2400 return Res;
2401}
2402
2403BinaryOperator *BinaryOperator::CreateNeg(Value *Op, const Twine &Name,
2404 Instruction *InsertBefore) {
2405 Value *zero = ConstantFP::getZeroValueForNegation(Op->getType());
2406 return new BinaryOperator(Instruction::Sub,
2407 zero, Op,
2408 Op->getType(), Name, InsertBefore);
2409}
2410
2411BinaryOperator *BinaryOperator::CreateNeg(Value *Op, const Twine &Name,
2412 BasicBlock *InsertAtEnd) {
2413 Value *zero = ConstantFP::getZeroValueForNegation(Op->getType());
2414 return new BinaryOperator(Instruction::Sub,
2415 zero, Op,
2416 Op->getType(), Name, InsertAtEnd);
2417}
2418
2419BinaryOperator *BinaryOperator::CreateNSWNeg(Value *Op, const Twine &Name,
2420 Instruction *InsertBefore) {
2421 Value *zero = ConstantFP::getZeroValueForNegation(Op->getType());
2422 return BinaryOperator::CreateNSWSub(zero, Op, Name, InsertBefore);
2423}
2424
2425BinaryOperator *BinaryOperator::CreateNSWNeg(Value *Op, const Twine &Name,
2426 BasicBlock *InsertAtEnd) {
2427 Value *zero = ConstantFP::getZeroValueForNegation(Op->getType());
2428 return BinaryOperator::CreateNSWSub(zero, Op, Name, InsertAtEnd);
2429}
2430
2431BinaryOperator *BinaryOperator::CreateNUWNeg(Value *Op, const Twine &Name,
2432 Instruction *InsertBefore) {
2433 Value *zero = ConstantFP::getZeroValueForNegation(Op->getType());
2434 return BinaryOperator::CreateNUWSub(zero, Op, Name, InsertBefore);
2435}
2436
2437BinaryOperator *BinaryOperator::CreateNUWNeg(Value *Op, const Twine &Name,
2438 BasicBlock *InsertAtEnd) {
2439 Value *zero = ConstantFP::getZeroValueForNegation(Op->getType());
2440 return BinaryOperator::CreateNUWSub(zero, Op, Name, InsertAtEnd);
2441}
2442
2443BinaryOperator *BinaryOperator::CreateNot(Value *Op, const Twine &Name,
2444 Instruction *InsertBefore) {
2445 Constant *C = Constant::getAllOnesValue(Op->getType());
2446 return new BinaryOperator(Instruction::Xor, Op, C,
2447 Op->getType(), Name, InsertBefore);
2448}
2449
2450BinaryOperator *BinaryOperator::CreateNot(Value *Op, const Twine &Name,
2451 BasicBlock *InsertAtEnd) {
2452 Constant *AllOnes = Constant::getAllOnesValue(Op->getType());
2453 return new BinaryOperator(Instruction::Xor, Op, AllOnes,
2454 Op->getType(), Name, InsertAtEnd);
2455}
2456
2457// Exchange the two operands to this instruction. This instruction is safe to
2458// use on any binary instruction and does not modify the semantics of the
2459// instruction. If the instruction is order-dependent (SetLT f.e.), the opcode
2460// is changed.
2461bool BinaryOperator::swapOperands() {
2462 if (!isCommutative())
2463 return true; // Can't commute operands
2464 Op<0>().swap(Op<1>());
2465 return false;
2466}
2467
2468//===----------------------------------------------------------------------===//
2469// FPMathOperator Class
2470//===----------------------------------------------------------------------===//
2471
2472float FPMathOperator::getFPAccuracy() const {
2473 const MDNode *MD =
2474 cast<Instruction>(this)->getMetadata(LLVMContext::MD_fpmath);
2475 if (!MD)
2476 return 0.0;
2477 ConstantFP *Accuracy = mdconst::extract<ConstantFP>(MD->getOperand(0));
2478 return Accuracy->getValueAPF().convertToFloat();
2479}
2480
2481//===----------------------------------------------------------------------===//
2482// CastInst Class
2483//===----------------------------------------------------------------------===//
2484
2485// Just determine if this cast only deals with integral->integral conversion.
2486bool CastInst::isIntegerCast() const {
2487 switch (getOpcode()) {
2488 default: return false;
2489 case Instruction::ZExt:
2490 case Instruction::SExt:
2491 case Instruction::Trunc:
2492 return true;
2493 case Instruction::BitCast:
2494 return getOperand(0)->getType()->isIntegerTy() &&
2495 getType()->isIntegerTy();
2496 }
2497}
2498
2499bool CastInst::isLosslessCast() const {
2500 // Only BitCast can be lossless, exit fast if we're not BitCast
2501 if (getOpcode() != Instruction::BitCast)
2502 return false;
2503
2504 // Identity cast is always lossless
2505 Type *SrcTy = getOperand(0)->getType();
2506 Type *DstTy = getType();
2507 if (SrcTy == DstTy)
2508 return true;
2509
2510 // Pointer to pointer is always lossless.
2511 if (SrcTy->isPointerTy())
2512 return DstTy->isPointerTy();
2513 return false; // Other types have no identity values
2514}
2515
2516/// This function determines if the CastInst does not require any bits to be
2517/// changed in order to effect the cast. Essentially, it identifies cases where
2518/// no code gen is necessary for the cast, hence the name no-op cast. For
2519/// example, the following are all no-op casts:
2520/// # bitcast i32* %x to i8*
2521/// # bitcast <2 x i32> %x to <4 x i16>
2522/// # ptrtoint i32* %x to i32 ; on 32-bit plaforms only
2523/// Determine if the described cast is a no-op.
2524bool CastInst::isNoopCast(Instruction::CastOps Opcode,
2525 Type *SrcTy,
2526 Type *DestTy,
2527 const DataLayout &DL) {
2528 switch (Opcode) {
2529 default: llvm_unreachable("Invalid CastOp")::llvm::llvm_unreachable_internal("Invalid CastOp", "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2529)
;
2530 case Instruction::Trunc:
2531 case Instruction::ZExt:
2532 case Instruction::SExt:
2533 case Instruction::FPTrunc:
2534 case Instruction::FPExt:
2535 case Instruction::UIToFP:
2536 case Instruction::SIToFP:
2537 case Instruction::FPToUI:
2538 case Instruction::FPToSI:
2539 case Instruction::AddrSpaceCast:
2540 // TODO: Target informations may give a more accurate answer here.
2541 return false;
2542 case Instruction::BitCast:
2543 return true; // BitCast never modifies bits.
2544 case Instruction::PtrToInt:
2545 return DL.getIntPtrType(SrcTy)->getScalarSizeInBits() ==
2546 DestTy->getScalarSizeInBits();
2547 case Instruction::IntToPtr:
2548 return DL.getIntPtrType(DestTy)->getScalarSizeInBits() ==
2549 SrcTy->getScalarSizeInBits();
2550 }
2551}
2552
2553bool CastInst::isNoopCast(const DataLayout &DL) const {
2554 return isNoopCast(getOpcode(), getOperand(0)->getType(), getType(), DL);
2555}
2556
2557/// This function determines if a pair of casts can be eliminated and what
2558/// opcode should be used in the elimination. This assumes that there are two
2559/// instructions like this:
2560/// * %F = firstOpcode SrcTy %x to MidTy
2561/// * %S = secondOpcode MidTy %F to DstTy
2562/// The function returns a resultOpcode so these two casts can be replaced with:
2563/// * %Replacement = resultOpcode %SrcTy %x to DstTy
2564/// If no such cast is permitted, the function returns 0.
2565unsigned CastInst::isEliminableCastPair(
2566 Instruction::CastOps firstOp, Instruction::CastOps secondOp,
2567 Type *SrcTy, Type *MidTy, Type *DstTy, Type *SrcIntPtrTy, Type *MidIntPtrTy,
2568 Type *DstIntPtrTy) {
2569 // Define the 144 possibilities for these two cast instructions. The values
2570 // in this matrix determine what to do in a given situation and select the
2571 // case in the switch below. The rows correspond to firstOp, the columns
2572 // correspond to secondOp. In looking at the table below, keep in mind
2573 // the following cast properties:
2574 //
2575 // Size Compare Source Destination
2576 // Operator Src ? Size Type Sign Type Sign
2577 // -------- ------------ ------------------- ---------------------
2578 // TRUNC > Integer Any Integral Any
2579 // ZEXT < Integral Unsigned Integer Any
2580 // SEXT < Integral Signed Integer Any
2581 // FPTOUI n/a FloatPt n/a Integral Unsigned
2582 // FPTOSI n/a FloatPt n/a Integral Signed
2583 // UITOFP n/a Integral Unsigned FloatPt n/a
2584 // SITOFP n/a Integral Signed FloatPt n/a
2585 // FPTRUNC > FloatPt n/a FloatPt n/a
2586 // FPEXT < FloatPt n/a FloatPt n/a
2587 // PTRTOINT n/a Pointer n/a Integral Unsigned
2588 // INTTOPTR n/a Integral Unsigned Pointer n/a
2589 // BITCAST = FirstClass n/a FirstClass n/a
2590 // ADDRSPCST n/a Pointer n/a Pointer n/a
2591 //
2592 // NOTE: some transforms are safe, but we consider them to be non-profitable.
2593 // For example, we could merge "fptoui double to i32" + "zext i32 to i64",
2594 // into "fptoui double to i64", but this loses information about the range
2595 // of the produced value (we no longer know the top-part is all zeros).
2596 // Further this conversion is often much more expensive for typical hardware,
2597 // and causes issues when building libgcc. We disallow fptosi+sext for the
2598 // same reason.
2599 const unsigned numCastOps =
2600 Instruction::CastOpsEnd - Instruction::CastOpsBegin;
2601 static const uint8_t CastResults[numCastOps][numCastOps] = {
2602 // T F F U S F F P I B A -+
2603 // R Z S P P I I T P 2 N T S |
2604 // U E E 2 2 2 2 R E I T C C +- secondOp
2605 // N X X U S F F N X N 2 V V |
2606 // C T T I I P P C T T P T T -+
2607 { 1, 0, 0,99,99, 0, 0,99,99,99, 0, 3, 0}, // Trunc -+
2608 { 8, 1, 9,99,99, 2,17,99,99,99, 2, 3, 0}, // ZExt |
2609 { 8, 0, 1,99,99, 0, 2,99,99,99, 0, 3, 0}, // SExt |
2610 { 0, 0, 0,99,99, 0, 0,99,99,99, 0, 3, 0}, // FPToUI |
2611 { 0, 0, 0,99,99, 0, 0,99,99,99, 0, 3, 0}, // FPToSI |
2612 { 99,99,99, 0, 0,99,99, 0, 0,99,99, 4, 0}, // UIToFP +- firstOp
2613 { 99,99,99, 0, 0,99,99, 0, 0,99,99, 4, 0}, // SIToFP |
2614 { 99,99,99, 0, 0,99,99, 0, 0,99,99, 4, 0}, // FPTrunc |
2615 { 99,99,99, 2, 2,99,99, 8, 2,99,99, 4, 0}, // FPExt |
2616 { 1, 0, 0,99,99, 0, 0,99,99,99, 7, 3, 0}, // PtrToInt |
2617 { 99,99,99,99,99,99,99,99,99,11,99,15, 0}, // IntToPtr |
2618 { 5, 5, 5, 6, 6, 5, 5, 6, 6,16, 5, 1,14}, // BitCast |
2619 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,13,12}, // AddrSpaceCast -+
2620 };
2621
2622 // TODO: This logic could be encoded into the table above and handled in the
2623 // switch below.
2624 // If either of the casts are a bitcast from scalar to vector, disallow the
2625 // merging. However, any pair of bitcasts are allowed.
2626 bool IsFirstBitcast = (firstOp == Instruction::BitCast);
2627 bool IsSecondBitcast = (secondOp == Instruction::BitCast);
2628 bool AreBothBitcasts = IsFirstBitcast && IsSecondBitcast;
2629
2630 // Check if any of the casts convert scalars <-> vectors.
2631 if ((IsFirstBitcast && isa<VectorType>(SrcTy) != isa<VectorType>(MidTy)) ||
2632 (IsSecondBitcast && isa<VectorType>(MidTy) != isa<VectorType>(DstTy)))
2633 if (!AreBothBitcasts)
2634 return 0;
2635
2636 int ElimCase = CastResults[firstOp-Instruction::CastOpsBegin]
2637 [secondOp-Instruction::CastOpsBegin];
2638 switch (ElimCase) {
2639 case 0:
2640 // Categorically disallowed.
2641 return 0;
2642 case 1:
2643 // Allowed, use first cast's opcode.
2644 return firstOp;
2645 case 2:
2646 // Allowed, use second cast's opcode.
2647 return secondOp;
2648 case 3:
2649 // No-op cast in second op implies firstOp as long as the DestTy
2650 // is integer and we are not converting between a vector and a
2651 // non-vector type.
2652 if (!SrcTy->isVectorTy() && DstTy->isIntegerTy())
2653 return firstOp;
2654 return 0;
2655 case 4:
2656 // No-op cast in second op implies firstOp as long as the DestTy
2657 // is floating point.
2658 if (DstTy->isFloatingPointTy())
2659 return firstOp;
2660 return 0;
2661 case 5:
2662 // No-op cast in first op implies secondOp as long as the SrcTy
2663 // is an integer.
2664 if (SrcTy->isIntegerTy())
2665 return secondOp;
2666 return 0;
2667 case 6:
2668 // No-op cast in first op implies secondOp as long as the SrcTy
2669 // is a floating point.
2670 if (SrcTy->isFloatingPointTy())
2671 return secondOp;
2672 return 0;
2673 case 7: {
2674 // Cannot simplify if address spaces are different!
2675 if (SrcTy->getPointerAddressSpace() != DstTy->getPointerAddressSpace())
2676 return 0;
2677
2678 unsigned MidSize = MidTy->getScalarSizeInBits();
2679 // We can still fold this without knowing the actual sizes as long we
2680 // know that the intermediate pointer is the largest possible
2681 // pointer size.
2682 // FIXME: Is this always true?
2683 if (MidSize == 64)
2684 return Instruction::BitCast;
2685
2686 // ptrtoint, inttoptr -> bitcast (ptr -> ptr) if int size is >= ptr size.
2687 if (!SrcIntPtrTy || DstIntPtrTy != SrcIntPtrTy)
2688 return 0;
2689 unsigned PtrSize = SrcIntPtrTy->getScalarSizeInBits();
2690 if (MidSize >= PtrSize)
2691 return Instruction::BitCast;
2692 return 0;
2693 }
2694 case 8: {
2695 // ext, trunc -> bitcast, if the SrcTy and DstTy are same size
2696 // ext, trunc -> ext, if sizeof(SrcTy) < sizeof(DstTy)
2697 // ext, trunc -> trunc, if sizeof(SrcTy) > sizeof(DstTy)
2698 unsigned SrcSize = SrcTy->getScalarSizeInBits();
2699 unsigned DstSize = DstTy->getScalarSizeInBits();
2700 if (SrcSize == DstSize)
2701 return Instruction::BitCast;
2702 else if (SrcSize < DstSize)
2703 return firstOp;
2704 return secondOp;
2705 }
2706 case 9:
2707 // zext, sext -> zext, because sext can't sign extend after zext
2708 return Instruction::ZExt;
2709 case 11: {
2710 // inttoptr, ptrtoint -> bitcast if SrcSize<=PtrSize and SrcSize==DstSize
2711 if (!MidIntPtrTy)
2712 return 0;
2713 unsigned PtrSize = MidIntPtrTy->getScalarSizeInBits();
2714 unsigned SrcSize = SrcTy->getScalarSizeInBits();
2715 unsigned DstSize = DstTy->getScalarSizeInBits();
2716 if (SrcSize <= PtrSize && SrcSize == DstSize)
2717 return Instruction::BitCast;
2718 return 0;
2719 }
2720 case 12:
2721 // addrspacecast, addrspacecast -> bitcast, if SrcAS == DstAS
2722 // addrspacecast, addrspacecast -> addrspacecast, if SrcAS != DstAS
2723 if (SrcTy->getPointerAddressSpace() != DstTy->getPointerAddressSpace())
2724 return Instruction::AddrSpaceCast;
2725 return Instruction::BitCast;
2726 case 13:
2727 // FIXME: this state can be merged with (1), but the following assert
2728 // is useful to check the correcteness of the sequence due to semantic
2729 // change of bitcast.
2730 assert(((SrcTy->isPtrOrPtrVectorTy() && MidTy->isPtrOrPtrVectorTy
() && DstTy->isPtrOrPtrVectorTy() && SrcTy
->getPointerAddressSpace() != MidTy->getPointerAddressSpace
() && MidTy->getPointerAddressSpace() == DstTy->
getPointerAddressSpace() && "Illegal addrspacecast, bitcast sequence!"
) ? static_cast<void> (0) : __assert_fail ("SrcTy->isPtrOrPtrVectorTy() && MidTy->isPtrOrPtrVectorTy() && DstTy->isPtrOrPtrVectorTy() && SrcTy->getPointerAddressSpace() != MidTy->getPointerAddressSpace() && MidTy->getPointerAddressSpace() == DstTy->getPointerAddressSpace() && \"Illegal addrspacecast, bitcast sequence!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2736, __PRETTY_FUNCTION__))
2731 SrcTy->isPtrOrPtrVectorTy() &&((SrcTy->isPtrOrPtrVectorTy() && MidTy->isPtrOrPtrVectorTy
() && DstTy->isPtrOrPtrVectorTy() && SrcTy
->getPointerAddressSpace() != MidTy->getPointerAddressSpace
() && MidTy->getPointerAddressSpace() == DstTy->
getPointerAddressSpace() && "Illegal addrspacecast, bitcast sequence!"
) ? static_cast<void> (0) : __assert_fail ("SrcTy->isPtrOrPtrVectorTy() && MidTy->isPtrOrPtrVectorTy() && DstTy->isPtrOrPtrVectorTy() && SrcTy->getPointerAddressSpace() != MidTy->getPointerAddressSpace() && MidTy->getPointerAddressSpace() == DstTy->getPointerAddressSpace() && \"Illegal addrspacecast, bitcast sequence!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2736, __PRETTY_FUNCTION__))
2732 MidTy->isPtrOrPtrVectorTy() &&((SrcTy->isPtrOrPtrVectorTy() && MidTy->isPtrOrPtrVectorTy
() && DstTy->isPtrOrPtrVectorTy() && SrcTy
->getPointerAddressSpace() != MidTy->getPointerAddressSpace
() && MidTy->getPointerAddressSpace() == DstTy->
getPointerAddressSpace() && "Illegal addrspacecast, bitcast sequence!"
) ? static_cast<void> (0) : __assert_fail ("SrcTy->isPtrOrPtrVectorTy() && MidTy->isPtrOrPtrVectorTy() && DstTy->isPtrOrPtrVectorTy() && SrcTy->getPointerAddressSpace() != MidTy->getPointerAddressSpace() && MidTy->getPointerAddressSpace() == DstTy->getPointerAddressSpace() && \"Illegal addrspacecast, bitcast sequence!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2736, __PRETTY_FUNCTION__))
2733 DstTy->isPtrOrPtrVectorTy() &&((SrcTy->isPtrOrPtrVectorTy() && MidTy->isPtrOrPtrVectorTy
() && DstTy->isPtrOrPtrVectorTy() && SrcTy
->getPointerAddressSpace() != MidTy->getPointerAddressSpace
() && MidTy->getPointerAddressSpace() == DstTy->
getPointerAddressSpace() && "Illegal addrspacecast, bitcast sequence!"
) ? static_cast<void> (0) : __assert_fail ("SrcTy->isPtrOrPtrVectorTy() && MidTy->isPtrOrPtrVectorTy() && DstTy->isPtrOrPtrVectorTy() && SrcTy->getPointerAddressSpace() != MidTy->getPointerAddressSpace() && MidTy->getPointerAddressSpace() == DstTy->getPointerAddressSpace() && \"Illegal addrspacecast, bitcast sequence!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2736, __PRETTY_FUNCTION__))
2734 SrcTy->getPointerAddressSpace() != MidTy->getPointerAddressSpace() &&((SrcTy->isPtrOrPtrVectorTy() && MidTy->isPtrOrPtrVectorTy
() && DstTy->isPtrOrPtrVectorTy() && SrcTy
->getPointerAddressSpace() != MidTy->getPointerAddressSpace
() && MidTy->getPointerAddressSpace() == DstTy->
getPointerAddressSpace() && "Illegal addrspacecast, bitcast sequence!"
) ? static_cast<void> (0) : __assert_fail ("SrcTy->isPtrOrPtrVectorTy() && MidTy->isPtrOrPtrVectorTy() && DstTy->isPtrOrPtrVectorTy() && SrcTy->getPointerAddressSpace() != MidTy->getPointerAddressSpace() && MidTy->getPointerAddressSpace() == DstTy->getPointerAddressSpace() && \"Illegal addrspacecast, bitcast sequence!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2736, __PRETTY_FUNCTION__))
2735 MidTy->getPointerAddressSpace() == DstTy->getPointerAddressSpace() &&((SrcTy->isPtrOrPtrVectorTy() && MidTy->isPtrOrPtrVectorTy
() && DstTy->isPtrOrPtrVectorTy() && SrcTy
->getPointerAddressSpace() != MidTy->getPointerAddressSpace
() && MidTy->getPointerAddressSpace() == DstTy->
getPointerAddressSpace() && "Illegal addrspacecast, bitcast sequence!"
) ? static_cast<void> (0) : __assert_fail ("SrcTy->isPtrOrPtrVectorTy() && MidTy->isPtrOrPtrVectorTy() && DstTy->isPtrOrPtrVectorTy() && SrcTy->getPointerAddressSpace() != MidTy->getPointerAddressSpace() && MidTy->getPointerAddressSpace() == DstTy->getPointerAddressSpace() && \"Illegal addrspacecast, bitcast sequence!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2736, __PRETTY_FUNCTION__))
2736 "Illegal addrspacecast, bitcast sequence!")((SrcTy->isPtrOrPtrVectorTy() && MidTy->isPtrOrPtrVectorTy
() && DstTy->isPtrOrPtrVectorTy() && SrcTy
->getPointerAddressSpace() != MidTy->getPointerAddressSpace
() && MidTy->getPointerAddressSpace() == DstTy->
getPointerAddressSpace() && "Illegal addrspacecast, bitcast sequence!"
) ? static_cast<void> (0) : __assert_fail ("SrcTy->isPtrOrPtrVectorTy() && MidTy->isPtrOrPtrVectorTy() && DstTy->isPtrOrPtrVectorTy() && SrcTy->getPointerAddressSpace() != MidTy->getPointerAddressSpace() && MidTy->getPointerAddressSpace() == DstTy->getPointerAddressSpace() && \"Illegal addrspacecast, bitcast sequence!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2736, __PRETTY_FUNCTION__))
;
2737 // Allowed, use first cast's opcode
2738 return firstOp;
2739 case 14:
2740 // bitcast, addrspacecast -> addrspacecast if the element type of
2741 // bitcast's source is the same as that of addrspacecast's destination.
2742 if (SrcTy->getScalarType()->getPointerElementType() ==
2743 DstTy->getScalarType()->getPointerElementType())
2744 return Instruction::AddrSpaceCast;
2745 return 0;
2746 case 15:
2747 // FIXME: this state can be merged with (1), but the following assert
2748 // is useful to check the correcteness of the sequence due to semantic
2749 // change of bitcast.
2750 assert(((SrcTy->isIntOrIntVectorTy() && MidTy->isPtrOrPtrVectorTy
() && DstTy->isPtrOrPtrVectorTy() && MidTy
->getPointerAddressSpace() == DstTy->getPointerAddressSpace
() && "Illegal inttoptr, bitcast sequence!") ? static_cast
<void> (0) : __assert_fail ("SrcTy->isIntOrIntVectorTy() && MidTy->isPtrOrPtrVectorTy() && DstTy->isPtrOrPtrVectorTy() && MidTy->getPointerAddressSpace() == DstTy->getPointerAddressSpace() && \"Illegal inttoptr, bitcast sequence!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2755, __PRETTY_FUNCTION__))
2751 SrcTy->isIntOrIntVectorTy() &&((SrcTy->isIntOrIntVectorTy() && MidTy->isPtrOrPtrVectorTy
() && DstTy->isPtrOrPtrVectorTy() && MidTy
->getPointerAddressSpace() == DstTy->getPointerAddressSpace
() && "Illegal inttoptr, bitcast sequence!") ? static_cast
<void> (0) : __assert_fail ("SrcTy->isIntOrIntVectorTy() && MidTy->isPtrOrPtrVectorTy() && DstTy->isPtrOrPtrVectorTy() && MidTy->getPointerAddressSpace() == DstTy->getPointerAddressSpace() && \"Illegal inttoptr, bitcast sequence!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2755, __PRETTY_FUNCTION__))
2752 MidTy->isPtrOrPtrVectorTy() &&((SrcTy->isIntOrIntVectorTy() && MidTy->isPtrOrPtrVectorTy
() && DstTy->isPtrOrPtrVectorTy() && MidTy
->getPointerAddressSpace() == DstTy->getPointerAddressSpace
() && "Illegal inttoptr, bitcast sequence!") ? static_cast
<void> (0) : __assert_fail ("SrcTy->isIntOrIntVectorTy() && MidTy->isPtrOrPtrVectorTy() && DstTy->isPtrOrPtrVectorTy() && MidTy->getPointerAddressSpace() == DstTy->getPointerAddressSpace() && \"Illegal inttoptr, bitcast sequence!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2755, __PRETTY_FUNCTION__))
2753 DstTy->isPtrOrPtrVectorTy() &&((SrcTy->isIntOrIntVectorTy() && MidTy->isPtrOrPtrVectorTy
() && DstTy->isPtrOrPtrVectorTy() && MidTy
->getPointerAddressSpace() == DstTy->getPointerAddressSpace
() && "Illegal inttoptr, bitcast sequence!") ? static_cast
<void> (0) : __assert_fail ("SrcTy->isIntOrIntVectorTy() && MidTy->isPtrOrPtrVectorTy() && DstTy->isPtrOrPtrVectorTy() && MidTy->getPointerAddressSpace() == DstTy->getPointerAddressSpace() && \"Illegal inttoptr, bitcast sequence!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2755, __PRETTY_FUNCTION__))
2754 MidTy->getPointerAddressSpace() == DstTy->getPointerAddressSpace() &&((SrcTy->isIntOrIntVectorTy() && MidTy->isPtrOrPtrVectorTy
() && DstTy->isPtrOrPtrVectorTy() && MidTy
->getPointerAddressSpace() == DstTy->getPointerAddressSpace
() && "Illegal inttoptr, bitcast sequence!") ? static_cast
<void> (0) : __assert_fail ("SrcTy->isIntOrIntVectorTy() && MidTy->isPtrOrPtrVectorTy() && DstTy->isPtrOrPtrVectorTy() && MidTy->getPointerAddressSpace() == DstTy->getPointerAddressSpace() && \"Illegal inttoptr, bitcast sequence!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2755, __PRETTY_FUNCTION__))
2755 "Illegal inttoptr, bitcast sequence!")((SrcTy->isIntOrIntVectorTy() && MidTy->isPtrOrPtrVectorTy
() && DstTy->isPtrOrPtrVectorTy() && MidTy
->getPointerAddressSpace() == DstTy->getPointerAddressSpace
() && "Illegal inttoptr, bitcast sequence!") ? static_cast
<void> (0) : __assert_fail ("SrcTy->isIntOrIntVectorTy() && MidTy->isPtrOrPtrVectorTy() && DstTy->isPtrOrPtrVectorTy() && MidTy->getPointerAddressSpace() == DstTy->getPointerAddressSpace() && \"Illegal inttoptr, bitcast sequence!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2755, __PRETTY_FUNCTION__))
;
2756 // Allowed, use first cast's opcode
2757 return firstOp;
2758 case 16:
2759 // FIXME: this state can be merged with (2), but the following assert
2760 // is useful to check the correcteness of the sequence due to semantic
2761 // change of bitcast.
2762 assert(((SrcTy->isPtrOrPtrVectorTy() && MidTy->isPtrOrPtrVectorTy
() && DstTy->isIntOrIntVectorTy() && SrcTy
->getPointerAddressSpace() == MidTy->getPointerAddressSpace
() && "Illegal bitcast, ptrtoint sequence!") ? static_cast
<void> (0) : __assert_fail ("SrcTy->isPtrOrPtrVectorTy() && MidTy->isPtrOrPtrVectorTy() && DstTy->isIntOrIntVectorTy() && SrcTy->getPointerAddressSpace() == MidTy->getPointerAddressSpace() && \"Illegal bitcast, ptrtoint sequence!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2767, __PRETTY_FUNCTION__))
2763 SrcTy->isPtrOrPtrVectorTy() &&((SrcTy->isPtrOrPtrVectorTy() && MidTy->isPtrOrPtrVectorTy
() && DstTy->isIntOrIntVectorTy() && SrcTy
->getPointerAddressSpace() == MidTy->getPointerAddressSpace
() && "Illegal bitcast, ptrtoint sequence!") ? static_cast
<void> (0) : __assert_fail ("SrcTy->isPtrOrPtrVectorTy() && MidTy->isPtrOrPtrVectorTy() && DstTy->isIntOrIntVectorTy() && SrcTy->getPointerAddressSpace() == MidTy->getPointerAddressSpace() && \"Illegal bitcast, ptrtoint sequence!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2767, __PRETTY_FUNCTION__))
2764 MidTy->isPtrOrPtrVectorTy() &&((SrcTy->isPtrOrPtrVectorTy() && MidTy->isPtrOrPtrVectorTy
() && DstTy->isIntOrIntVectorTy() && SrcTy
->getPointerAddressSpace() == MidTy->getPointerAddressSpace
() && "Illegal bitcast, ptrtoint sequence!") ? static_cast
<void> (0) : __assert_fail ("SrcTy->isPtrOrPtrVectorTy() && MidTy->isPtrOrPtrVectorTy() && DstTy->isIntOrIntVectorTy() && SrcTy->getPointerAddressSpace() == MidTy->getPointerAddressSpace() && \"Illegal bitcast, ptrtoint sequence!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2767, __PRETTY_FUNCTION__))
2765 DstTy->isIntOrIntVectorTy() &&((SrcTy->isPtrOrPtrVectorTy() && MidTy->isPtrOrPtrVectorTy
() && DstTy->isIntOrIntVectorTy() && SrcTy
->getPointerAddressSpace() == MidTy->getPointerAddressSpace
() && "Illegal bitcast, ptrtoint sequence!") ? static_cast
<void> (0) : __assert_fail ("SrcTy->isPtrOrPtrVectorTy() && MidTy->isPtrOrPtrVectorTy() && DstTy->isIntOrIntVectorTy() && SrcTy->getPointerAddressSpace() == MidTy->getPointerAddressSpace() && \"Illegal bitcast, ptrtoint sequence!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2767, __PRETTY_FUNCTION__))
2766 SrcTy->getPointerAddressSpace() == MidTy->getPointerAddressSpace() &&((SrcTy->isPtrOrPtrVectorTy() && MidTy->isPtrOrPtrVectorTy
() && DstTy->isIntOrIntVectorTy() && SrcTy
->getPointerAddressSpace() == MidTy->getPointerAddressSpace
() && "Illegal bitcast, ptrtoint sequence!") ? static_cast
<void> (0) : __assert_fail ("SrcTy->isPtrOrPtrVectorTy() && MidTy->isPtrOrPtrVectorTy() && DstTy->isIntOrIntVectorTy() && SrcTy->getPointerAddressSpace() == MidTy->getPointerAddressSpace() && \"Illegal bitcast, ptrtoint sequence!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2767, __PRETTY_FUNCTION__))
2767 "Illegal bitcast, ptrtoint sequence!")((SrcTy->isPtrOrPtrVectorTy() && MidTy->isPtrOrPtrVectorTy
() && DstTy->isIntOrIntVectorTy() && SrcTy
->getPointerAddressSpace() == MidTy->getPointerAddressSpace
() && "Illegal bitcast, ptrtoint sequence!") ? static_cast
<void> (0) : __assert_fail ("SrcTy->isPtrOrPtrVectorTy() && MidTy->isPtrOrPtrVectorTy() && DstTy->isIntOrIntVectorTy() && SrcTy->getPointerAddressSpace() == MidTy->getPointerAddressSpace() && \"Illegal bitcast, ptrtoint sequence!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2767, __PRETTY_FUNCTION__))
;
2768 // Allowed, use second cast's opcode
2769 return secondOp;
2770 case 17:
2771 // (sitofp (zext x)) -> (uitofp x)
2772 return Instruction::UIToFP;
2773 case 99:
2774 // Cast combination can't happen (error in input). This is for all cases
2775 // where the MidTy is not the same for the two cast instructions.
2776 llvm_unreachable("Invalid Cast Combination")::llvm::llvm_unreachable_internal("Invalid Cast Combination",
"/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2776)
;
2777 default:
2778 llvm_unreachable("Error in CastResults table!!!")::llvm::llvm_unreachable_internal("Error in CastResults table!!!"
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2778)
;
2779 }
2780}
2781
2782CastInst *CastInst::Create(Instruction::CastOps op, Value *S, Type *Ty,
2783 const Twine &Name, Instruction *InsertBefore) {
2784 assert(castIsValid(op, S, Ty) && "Invalid cast!")((castIsValid(op, S, Ty) && "Invalid cast!") ? static_cast
<void> (0) : __assert_fail ("castIsValid(op, S, Ty) && \"Invalid cast!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2784, __PRETTY_FUNCTION__))
;
2785 // Construct and return the appropriate CastInst subclass
2786 switch (op) {
2787 case Trunc: return new TruncInst (S, Ty, Name, InsertBefore);
2788 case ZExt: return new ZExtInst (S, Ty, Name, InsertBefore);
2789 case SExt: return new SExtInst (S, Ty, Name, InsertBefore);
2790 case FPTrunc: return new FPTruncInst (S, Ty, Name, InsertBefore);
2791 case FPExt: return new FPExtInst (S, Ty, Name, InsertBefore);
2792 case UIToFP: return new UIToFPInst (S, Ty, Name, InsertBefore);
2793 case SIToFP: return new SIToFPInst (S, Ty, Name, InsertBefore);
2794 case FPToUI: return new FPToUIInst (S, Ty, Name, InsertBefore);
2795 case FPToSI: return new FPToSIInst (S, Ty, Name, InsertBefore);
2796 case PtrToInt: return new PtrToIntInst (S, Ty, Name, InsertBefore);
2797 case IntToPtr: return new IntToPtrInst (S, Ty, Name, InsertBefore);
2798 case BitCast: return new BitCastInst (S, Ty, Name, InsertBefore);
2799 case AddrSpaceCast: return new AddrSpaceCastInst (S, Ty, Name, InsertBefore);
2800 default: llvm_unreachable("Invalid opcode provided")::llvm::llvm_unreachable_internal("Invalid opcode provided", "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2800)
;
2801 }
2802}
2803
2804CastInst *CastInst::Create(Instruction::CastOps op, Value *S, Type *Ty,
2805 const Twine &Name, BasicBlock *InsertAtEnd) {
2806 assert(castIsValid(op, S, Ty) && "Invalid cast!")((castIsValid(op, S, Ty) && "Invalid cast!") ? static_cast
<void> (0) : __assert_fail ("castIsValid(op, S, Ty) && \"Invalid cast!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2806, __PRETTY_FUNCTION__))
;
2807 // Construct and return the appropriate CastInst subclass
2808 switch (op) {
2809 case Trunc: return new TruncInst (S, Ty, Name, InsertAtEnd);
2810 case ZExt: return new ZExtInst (S, Ty, Name, InsertAtEnd);
2811 case SExt: return new SExtInst (S, Ty, Name, InsertAtEnd);
2812 case FPTrunc: return new FPTruncInst (S, Ty, Name, InsertAtEnd);
2813 case FPExt: return new FPExtInst (S, Ty, Name, InsertAtEnd);
2814 case UIToFP: return new UIToFPInst (S, Ty, Name, InsertAtEnd);
2815 case SIToFP: return new SIToFPInst (S, Ty, Name, InsertAtEnd);
2816 case FPToUI: return new FPToUIInst (S, Ty, Name, InsertAtEnd);
2817 case FPToSI: return new FPToSIInst (S, Ty, Name, InsertAtEnd);
2818 case PtrToInt: return new PtrToIntInst (S, Ty, Name, InsertAtEnd);
2819 case IntToPtr: return new IntToPtrInst (S, Ty, Name, InsertAtEnd);
2820 case BitCast: return new BitCastInst (S, Ty, Name, InsertAtEnd);
2821 case AddrSpaceCast: return new AddrSpaceCastInst (S, Ty, Name, InsertAtEnd);
2822 default: llvm_unreachable("Invalid opcode provided")::llvm::llvm_unreachable_internal("Invalid opcode provided", "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2822)
;
2823 }
2824}
2825
2826CastInst *CastInst::CreateZExtOrBitCast(Value *S, Type *Ty,
2827 const Twine &Name,
2828 Instruction *InsertBefore) {
2829 if (S->getType()->getScalarSizeInBits() == Ty->getScalarSizeInBits())
2830 return Create(Instruction::BitCast, S, Ty, Name, InsertBefore);
2831 return Create(Instruction::ZExt, S, Ty, Name, InsertBefore);
2832}
2833
2834CastInst *CastInst::CreateZExtOrBitCast(Value *S, Type *Ty,
2835 const Twine &Name,
2836 BasicBlock *InsertAtEnd) {
2837 if (S->getType()->getScalarSizeInBits() == Ty->getScalarSizeInBits())
2838 return Create(Instruction::BitCast, S, Ty, Name, InsertAtEnd);
2839 return Create(Instruction::ZExt, S, Ty, Name, InsertAtEnd);
2840}
2841
2842CastInst *CastInst::CreateSExtOrBitCast(Value *S, Type *Ty,
2843 const Twine &Name,
2844 Instruction *InsertBefore) {
2845 if (S->getType()->getScalarSizeInBits() == Ty->getScalarSizeInBits())
2846 return Create(Instruction::BitCast, S, Ty, Name, InsertBefore);
2847 return Create(Instruction::SExt, S, Ty, Name, InsertBefore);
2848}
2849
2850CastInst *CastInst::CreateSExtOrBitCast(Value *S, Type *Ty,
2851 const Twine &Name,
2852 BasicBlock *InsertAtEnd) {
2853 if (S->getType()->getScalarSizeInBits() == Ty->getScalarSizeInBits())
2854 return Create(Instruction::BitCast, S, Ty, Name, InsertAtEnd);
2855 return Create(Instruction::SExt, S, Ty, Name, InsertAtEnd);
2856}
2857
2858CastInst *CastInst::CreateTruncOrBitCast(Value *S, Type *Ty,
2859 const Twine &Name,
2860 Instruction *InsertBefore) {
2861 if (S->getType()->getScalarSizeInBits() == Ty->getScalarSizeInBits())
2862 return Create(Instruction::BitCast, S, Ty, Name, InsertBefore);
2863 return Create(Instruction::Trunc, S, Ty, Name, InsertBefore);
2864}
2865
2866CastInst *CastInst::CreateTruncOrBitCast(Value *S, Type *Ty,
2867 const Twine &Name,
2868 BasicBlock *InsertAtEnd) {
2869 if (S->getType()->getScalarSizeInBits() == Ty->getScalarSizeInBits())
2870 return Create(Instruction::BitCast, S, Ty, Name, InsertAtEnd);
2871 return Create(Instruction::Trunc, S, Ty, Name, InsertAtEnd);
2872}
2873
2874CastInst *CastInst::CreatePointerCast(Value *S, Type *Ty,
2875 const Twine &Name,
2876 BasicBlock *InsertAtEnd) {
2877 assert(S->getType()->isPtrOrPtrVectorTy() && "Invalid cast")((S->getType()->isPtrOrPtrVectorTy() && "Invalid cast"
) ? static_cast<void> (0) : __assert_fail ("S->getType()->isPtrOrPtrVectorTy() && \"Invalid cast\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2877, __PRETTY_FUNCTION__))
;
2878 assert((Ty->isIntOrIntVectorTy() || Ty->isPtrOrPtrVectorTy()) &&(((Ty->isIntOrIntVectorTy() || Ty->isPtrOrPtrVectorTy()
) && "Invalid cast") ? static_cast<void> (0) : __assert_fail
("(Ty->isIntOrIntVectorTy() || Ty->isPtrOrPtrVectorTy()) && \"Invalid cast\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2879, __PRETTY_FUNCTION__))
2879 "Invalid cast")(((Ty->isIntOrIntVectorTy() || Ty->isPtrOrPtrVectorTy()
) && "Invalid cast") ? static_cast<void> (0) : __assert_fail
("(Ty->isIntOrIntVectorTy() || Ty->isPtrOrPtrVectorTy()) && \"Invalid cast\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2879, __PRETTY_FUNCTION__))
;
2880 assert(Ty->isVectorTy() == S->getType()->isVectorTy() && "Invalid cast")((Ty->isVectorTy() == S->getType()->isVectorTy() &&
"Invalid cast") ? static_cast<void> (0) : __assert_fail
("Ty->isVectorTy() == S->getType()->isVectorTy() && \"Invalid cast\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2880, __PRETTY_FUNCTION__))
;
2881 assert((!Ty->isVectorTy() ||(((!Ty->isVectorTy() || Ty->getVectorNumElements() == S
->getType()->getVectorNumElements()) && "Invalid cast"
) ? static_cast<void> (0) : __assert_fail ("(!Ty->isVectorTy() || Ty->getVectorNumElements() == S->getType()->getVectorNumElements()) && \"Invalid cast\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2883, __PRETTY_FUNCTION__))
2882 Ty->getVectorNumElements() == S->getType()->getVectorNumElements()) &&(((!Ty->isVectorTy() || Ty->getVectorNumElements() == S
->getType()->getVectorNumElements()) && "Invalid cast"
) ? static_cast<void> (0) : __assert_fail ("(!Ty->isVectorTy() || Ty->getVectorNumElements() == S->getType()->getVectorNumElements()) && \"Invalid cast\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2883, __PRETTY_FUNCTION__))
2883 "Invalid cast")(((!Ty->isVectorTy() || Ty->getVectorNumElements() == S
->getType()->getVectorNumElements()) && "Invalid cast"
) ? static_cast<void> (0) : __assert_fail ("(!Ty->isVectorTy() || Ty->getVectorNumElements() == S->getType()->getVectorNumElements()) && \"Invalid cast\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2883, __PRETTY_FUNCTION__))
;
2884
2885 if (Ty->isIntOrIntVectorTy())
2886 return Create(Instruction::PtrToInt, S, Ty, Name, InsertAtEnd);
2887
2888 return CreatePointerBitCastOrAddrSpaceCast(S, Ty, Name, InsertAtEnd);
2889}
2890
2891/// Create a BitCast or a PtrToInt cast instruction
2892CastInst *CastInst::CreatePointerCast(Value *S, Type *Ty,
2893 const Twine &Name,
2894 Instruction *InsertBefore) {
2895 assert(S->getType()->isPtrOrPtrVectorTy() && "Invalid cast")((S->getType()->isPtrOrPtrVectorTy() && "Invalid cast"
) ? static_cast<void> (0) : __assert_fail ("S->getType()->isPtrOrPtrVectorTy() && \"Invalid cast\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2895, __PRETTY_FUNCTION__))
;
2896 assert((Ty->isIntOrIntVectorTy() || Ty->isPtrOrPtrVectorTy()) &&(((Ty->isIntOrIntVectorTy() || Ty->isPtrOrPtrVectorTy()
) && "Invalid cast") ? static_cast<void> (0) : __assert_fail
("(Ty->isIntOrIntVectorTy() || Ty->isPtrOrPtrVectorTy()) && \"Invalid cast\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2897, __PRETTY_FUNCTION__))
2897 "Invalid cast")(((Ty->isIntOrIntVectorTy() || Ty->isPtrOrPtrVectorTy()
) && "Invalid cast") ? static_cast<void> (0) : __assert_fail
("(Ty->isIntOrIntVectorTy() || Ty->isPtrOrPtrVectorTy()) && \"Invalid cast\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2897, __PRETTY_FUNCTION__))
;
2898 assert(Ty->isVectorTy() == S->getType()->isVectorTy() && "Invalid cast")((Ty->isVectorTy() == S->getType()->isVectorTy() &&
"Invalid cast") ? static_cast<void> (0) : __assert_fail
("Ty->isVectorTy() == S->getType()->isVectorTy() && \"Invalid cast\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2898, __PRETTY_FUNCTION__))
;
2899 assert((!Ty->isVectorTy() ||(((!Ty->isVectorTy() || Ty->getVectorNumElements() == S
->getType()->getVectorNumElements()) && "Invalid cast"
) ? static_cast<void> (0) : __assert_fail ("(!Ty->isVectorTy() || Ty->getVectorNumElements() == S->getType()->getVectorNumElements()) && \"Invalid cast\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2901, __PRETTY_FUNCTION__))
2900 Ty->getVectorNumElements() == S->getType()->getVectorNumElements()) &&(((!Ty->isVectorTy() || Ty->getVectorNumElements() == S
->getType()->getVectorNumElements()) && "Invalid cast"
) ? static_cast<void> (0) : __assert_fail ("(!Ty->isVectorTy() || Ty->getVectorNumElements() == S->getType()->getVectorNumElements()) && \"Invalid cast\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2901, __PRETTY_FUNCTION__))
2901 "Invalid cast")(((!Ty->isVectorTy() || Ty->getVectorNumElements() == S
->getType()->getVectorNumElements()) && "Invalid cast"
) ? static_cast<void> (0) : __assert_fail ("(!Ty->isVectorTy() || Ty->getVectorNumElements() == S->getType()->getVectorNumElements()) && \"Invalid cast\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2901, __PRETTY_FUNCTION__))
;
2902
2903 if (Ty->isIntOrIntVectorTy())
2904 return Create(Instruction::PtrToInt, S, Ty, Name, InsertBefore);
2905
2906 return CreatePointerBitCastOrAddrSpaceCast(S, Ty, Name, InsertBefore);
2907}
2908
2909CastInst *CastInst::CreatePointerBitCastOrAddrSpaceCast(
2910 Value *S, Type *Ty,
2911 const Twine &Name,
2912 BasicBlock *InsertAtEnd) {
2913 assert(S->getType()->isPtrOrPtrVectorTy() && "Invalid cast")((S->getType()->isPtrOrPtrVectorTy() && "Invalid cast"
) ? static_cast<void> (0) : __assert_fail ("S->getType()->isPtrOrPtrVectorTy() && \"Invalid cast\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2913, __PRETTY_FUNCTION__))
;
2914 assert(Ty->isPtrOrPtrVectorTy() && "Invalid cast")((Ty->isPtrOrPtrVectorTy() && "Invalid cast") ? static_cast
<void> (0) : __assert_fail ("Ty->isPtrOrPtrVectorTy() && \"Invalid cast\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2914, __PRETTY_FUNCTION__))
;
2915
2916 if (S->getType()->getPointerAddressSpace() != Ty->getPointerAddressSpace())
2917 return Create(Instruction::AddrSpaceCast, S, Ty, Name, InsertAtEnd);
2918
2919 return Create(Instruction::BitCast, S, Ty, Name, InsertAtEnd);
2920}
2921
2922CastInst *CastInst::CreatePointerBitCastOrAddrSpaceCast(
2923 Value *S, Type *Ty,
2924 const Twine &Name,
2925 Instruction *InsertBefore) {
2926 assert(S->getType()->isPtrOrPtrVectorTy() && "Invalid cast")((S->getType()->isPtrOrPtrVectorTy() && "Invalid cast"
) ? static_cast<void> (0) : __assert_fail ("S->getType()->isPtrOrPtrVectorTy() && \"Invalid cast\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2926, __PRETTY_FUNCTION__))
;
2927 assert(Ty->isPtrOrPtrVectorTy() && "Invalid cast")((Ty->isPtrOrPtrVectorTy() && "Invalid cast") ? static_cast
<void> (0) : __assert_fail ("Ty->isPtrOrPtrVectorTy() && \"Invalid cast\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2927, __PRETTY_FUNCTION__))
;
2928
2929 if (S->getType()->getPointerAddressSpace() != Ty->getPointerAddressSpace())
2930 return Create(Instruction::AddrSpaceCast, S, Ty, Name, InsertBefore);
2931
2932 return Create(Instruction::BitCast, S, Ty, Name, InsertBefore);
2933}
2934
2935CastInst *CastInst::CreateBitOrPointerCast(Value *S, Type *Ty,
2936 const Twine &Name,
2937 Instruction *InsertBefore) {
2938 if (S->getType()->isPointerTy() && Ty->isIntegerTy())
2939 return Create(Instruction::PtrToInt, S, Ty, Name, InsertBefore);
2940 if (S->getType()->isIntegerTy() && Ty->isPointerTy())
2941 return Create(Instruction::IntToPtr, S, Ty, Name, InsertBefore);
2942
2943 return Create(Instruction::BitCast, S, Ty, Name, InsertBefore);
2944}
2945
2946CastInst *CastInst::CreateIntegerCast(Value *C, Type *Ty,
2947 bool isSigned, const Twine &Name,
2948 Instruction *InsertBefore) {
2949 assert(C->getType()->isIntOrIntVectorTy() && Ty->isIntOrIntVectorTy() &&((C->getType()->isIntOrIntVectorTy() && Ty->
isIntOrIntVectorTy() && "Invalid integer cast") ? static_cast
<void> (0) : __assert_fail ("C->getType()->isIntOrIntVectorTy() && Ty->isIntOrIntVectorTy() && \"Invalid integer cast\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2950, __PRETTY_FUNCTION__))
2950 "Invalid integer cast")((C->getType()->isIntOrIntVectorTy() && Ty->
isIntOrIntVectorTy() && "Invalid integer cast") ? static_cast
<void> (0) : __assert_fail ("C->getType()->isIntOrIntVectorTy() && Ty->isIntOrIntVectorTy() && \"Invalid integer cast\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2950, __PRETTY_FUNCTION__))
;
2951 unsigned SrcBits = C->getType()->getScalarSizeInBits();
2952 unsigned DstBits = Ty->getScalarSizeInBits();
2953 Instruction::CastOps opcode =
2954 (SrcBits == DstBits ? Instruction::BitCast :
2955 (SrcBits > DstBits ? Instruction::Trunc :
2956 (isSigned ? Instruction::SExt : Instruction::ZExt)));
2957 return Create(opcode, C, Ty, Name, InsertBefore);
2958}
2959
2960CastInst *CastInst::CreateIntegerCast(Value *C, Type *Ty,
2961 bool isSigned, const Twine &Name,
2962 BasicBlock *InsertAtEnd) {
2963 assert(C->getType()->isIntOrIntVectorTy() && Ty->isIntOrIntVectorTy() &&((C->getType()->isIntOrIntVectorTy() && Ty->
isIntOrIntVectorTy() && "Invalid cast") ? static_cast
<void> (0) : __assert_fail ("C->getType()->isIntOrIntVectorTy() && Ty->isIntOrIntVectorTy() && \"Invalid cast\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2964, __PRETTY_FUNCTION__))
2964 "Invalid cast")((C->getType()->isIntOrIntVectorTy() && Ty->
isIntOrIntVectorTy() && "Invalid cast") ? static_cast
<void> (0) : __assert_fail ("C->getType()->isIntOrIntVectorTy() && Ty->isIntOrIntVectorTy() && \"Invalid cast\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2964, __PRETTY_FUNCTION__))
;
2965 unsigned SrcBits = C->getType()->getScalarSizeInBits();
2966 unsigned DstBits = Ty->getScalarSizeInBits();
2967 Instruction::CastOps opcode =
2968 (SrcBits == DstBits ? Instruction::BitCast :
2969 (SrcBits > DstBits ? Instruction::Trunc :
2970 (isSigned ? Instruction::SExt : Instruction::ZExt)));
2971 return Create(opcode, C, Ty, Name, InsertAtEnd);
2972}
2973
2974CastInst *CastInst::CreateFPCast(Value *C, Type *Ty,
2975 const Twine &Name,
2976 Instruction *InsertBefore) {
2977 assert(C->getType()->isFPOrFPVectorTy() && Ty->isFPOrFPVectorTy() &&((C->getType()->isFPOrFPVectorTy() && Ty->isFPOrFPVectorTy
() && "Invalid cast") ? static_cast<void> (0) :
__assert_fail ("C->getType()->isFPOrFPVectorTy() && Ty->isFPOrFPVectorTy() && \"Invalid cast\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2978, __PRETTY_FUNCTION__))
2978 "Invalid cast")((C->getType()->isFPOrFPVectorTy() && Ty->isFPOrFPVectorTy
() && "Invalid cast") ? static_cast<void> (0) :
__assert_fail ("C->getType()->isFPOrFPVectorTy() && Ty->isFPOrFPVectorTy() && \"Invalid cast\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2978, __PRETTY_FUNCTION__))
;
2979 unsigned SrcBits = C->getType()->getScalarSizeInBits();
2980 unsigned DstBits = Ty->getScalarSizeInBits();
2981 Instruction::CastOps opcode =
2982 (SrcBits == DstBits ? Instruction::BitCast :
2983 (SrcBits > DstBits ? Instruction::FPTrunc : Instruction::FPExt));
2984 return Create(opcode, C, Ty, Name, InsertBefore);
2985}
2986
2987CastInst *CastInst::CreateFPCast(Value *C, Type *Ty,
2988 const Twine &Name,
2989 BasicBlock *InsertAtEnd) {
2990 assert(C->getType()->isFPOrFPVectorTy() && Ty->isFPOrFPVectorTy() &&((C->getType()->isFPOrFPVectorTy() && Ty->isFPOrFPVectorTy
() && "Invalid cast") ? static_cast<void> (0) :
__assert_fail ("C->getType()->isFPOrFPVectorTy() && Ty->isFPOrFPVectorTy() && \"Invalid cast\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2991, __PRETTY_FUNCTION__))
2991 "Invalid cast")((C->getType()->isFPOrFPVectorTy() && Ty->isFPOrFPVectorTy
() && "Invalid cast") ? static_cast<void> (0) :
__assert_fail ("C->getType()->isFPOrFPVectorTy() && Ty->isFPOrFPVectorTy() && \"Invalid cast\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 2991, __PRETTY_FUNCTION__))
;
2992 unsigned SrcBits = C->getType()->getScalarSizeInBits();
2993 unsigned DstBits = Ty->getScalarSizeInBits();
2994 Instruction::CastOps opcode =
2995 (SrcBits == DstBits ? Instruction::BitCast :
2996 (SrcBits > DstBits ? Instruction::FPTrunc : Instruction::FPExt));
2997 return Create(opcode, C, Ty, Name, InsertAtEnd);
2998}
2999
3000// Check whether it is valid to call getCastOpcode for these types.
3001// This routine must be kept in sync with getCastOpcode.
3002bool CastInst::isCastable(Type *SrcTy, Type *DestTy) {
3003 if (!SrcTy->isFirstClassType() || !DestTy->isFirstClassType())
3004 return false;
3005
3006 if (SrcTy == DestTy)
3007 return true;
3008
3009 if (VectorType *SrcVecTy = dyn_cast<VectorType>(SrcTy))
3010 if (VectorType *DestVecTy = dyn_cast<VectorType>(DestTy))
3011 if (SrcVecTy->getNumElements() == DestVecTy->getNumElements()) {
3012 // An element by element cast. Valid if casting the elements is valid.
3013 SrcTy = SrcVecTy->getElementType();
3014 DestTy = DestVecTy->getElementType();
3015 }
3016
3017 // Get the bit sizes, we'll need these
3018 TypeSize SrcBits = SrcTy->getPrimitiveSizeInBits(); // 0 for ptr
3019 TypeSize DestBits = DestTy->getPrimitiveSizeInBits(); // 0 for ptr
3020
3021 // Run through the possibilities ...
3022 if (DestTy->isIntegerTy()) { // Casting to integral
3023 if (SrcTy->isIntegerTy()) // Casting from integral
3024 return true;
3025 if (SrcTy->isFloatingPointTy()) // Casting from floating pt
3026 return true;
3027 if (SrcTy->isVectorTy()) // Casting from vector
3028 return DestBits == SrcBits;
3029 // Casting from something else
3030 return SrcTy->isPointerTy();
3031 }
3032 if (DestTy->isFloatingPointTy()) { // Casting to floating pt
3033 if (SrcTy->isIntegerTy()) // Casting from integral
3034 return true;
3035 if (SrcTy->isFloatingPointTy()) // Casting from floating pt
3036 return true;
3037 if (SrcTy->isVectorTy()) // Casting from vector
3038 return DestBits == SrcBits;
3039 // Casting from something else
3040 return false;
3041 }
3042 if (DestTy->isVectorTy()) // Casting to vector
3043 return DestBits == SrcBits;
3044 if (DestTy->isPointerTy()) { // Casting to pointer
3045 if (SrcTy->isPointerTy()) // Casting from pointer
3046 return true;
3047 return SrcTy->isIntegerTy(); // Casting from integral
3048 }
3049 if (DestTy->isX86_MMXTy()) {
3050 if (SrcTy->isVectorTy())
3051 return DestBits == SrcBits; // 64-bit vector to MMX
3052 return false;
3053 } // Casting to something else
3054 return false;
3055}
3056
3057bool CastInst::isBitCastable(Type *SrcTy, Type *DestTy) {
3058 if (!SrcTy->isFirstClassType() || !DestTy->isFirstClassType())
3059 return false;
3060
3061 if (SrcTy == DestTy)
3062 return true;
3063
3064 if (VectorType *SrcVecTy = dyn_cast<VectorType>(SrcTy)) {
3065 if (VectorType *DestVecTy = dyn_cast<VectorType>(DestTy)) {
3066 if (SrcVecTy->getElementCount() == DestVecTy->getElementCount()) {
3067 // An element by element cast. Valid if casting the elements is valid.
3068 SrcTy = SrcVecTy->getElementType();
3069 DestTy = DestVecTy->getElementType();
3070 }
3071 }
3072 }
3073
3074 if (PointerType *DestPtrTy = dyn_cast<PointerType>(DestTy)) {
3075 if (PointerType *SrcPtrTy = dyn_cast<PointerType>(SrcTy)) {
3076 return SrcPtrTy->getAddressSpace() == DestPtrTy->getAddressSpace();
3077 }
3078 }
3079
3080 TypeSize SrcBits = SrcTy->getPrimitiveSizeInBits(); // 0 for ptr
3081 TypeSize DestBits = DestTy->getPrimitiveSizeInBits(); // 0 for ptr
3082
3083 // Could still have vectors of pointers if the number of elements doesn't
3084 // match
3085 if (SrcBits.getKnownMinSize() == 0 || DestBits.getKnownMinSize() == 0)
3086 return false;
3087
3088 if (SrcBits != DestBits)
3089 return false;
3090
3091 if (DestTy->isX86_MMXTy() || SrcTy->isX86_MMXTy())
3092 return false;
3093
3094 return true;
3095}
3096
3097bool CastInst::isBitOrNoopPointerCastable(Type *SrcTy, Type *DestTy,
3098 const DataLayout &DL) {
3099 // ptrtoint and inttoptr are not allowed on non-integral pointers
3100 if (auto *PtrTy = dyn_cast<PointerType>(SrcTy))
3101 if (auto *IntTy = dyn_cast<IntegerType>(DestTy))
3102 return (IntTy->getBitWidth() == DL.getPointerTypeSizeInBits(PtrTy) &&
3103 !DL.isNonIntegralPointerType(PtrTy));
3104 if (auto *PtrTy = dyn_cast<PointerType>(DestTy))
3105 if (auto *IntTy = dyn_cast<IntegerType>(SrcTy))
3106 return (IntTy->getBitWidth() == DL.getPointerTypeSizeInBits(PtrTy) &&
3107 !DL.isNonIntegralPointerType(PtrTy));
3108
3109 return isBitCastable(SrcTy, DestTy);
3110}
3111
3112// Provide a way to get a "cast" where the cast opcode is inferred from the
3113// types and size of the operand. This, basically, is a parallel of the
3114// logic in the castIsValid function below. This axiom should hold:
3115// castIsValid( getCastOpcode(Val, Ty), Val, Ty)
3116// should not assert in castIsValid. In other words, this produces a "correct"
3117// casting opcode for the arguments passed to it.
3118// This routine must be kept in sync with isCastable.
3119Instruction::CastOps
3120CastInst::getCastOpcode(
3121 const Value *Src, bool SrcIsSigned, Type *DestTy, bool DestIsSigned) {
3122 Type *SrcTy = Src->getType();
3123
3124 assert(SrcTy->isFirstClassType() && DestTy->isFirstClassType() &&((SrcTy->isFirstClassType() && DestTy->isFirstClassType
() && "Only first class types are castable!") ? static_cast
<void> (0) : __assert_fail ("SrcTy->isFirstClassType() && DestTy->isFirstClassType() && \"Only first class types are castable!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 3125, __PRETTY_FUNCTION__))
3125 "Only first class types are castable!")((SrcTy->isFirstClassType() && DestTy->isFirstClassType
() && "Only first class types are castable!") ? static_cast
<void> (0) : __assert_fail ("SrcTy->isFirstClassType() && DestTy->isFirstClassType() && \"Only first class types are castable!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 3125, __PRETTY_FUNCTION__))
;
3126
3127 if (SrcTy == DestTy)
3128 return BitCast;
3129
3130 // FIXME: Check address space sizes here
3131 if (VectorType *SrcVecTy = dyn_cast<VectorType>(SrcTy))
3132 if (VectorType *DestVecTy = dyn_cast<VectorType>(DestTy))
3133 if (SrcVecTy->getNumElements() == DestVecTy->getNumElements()) {
3134 // An element by element cast. Find the appropriate opcode based on the
3135 // element types.
3136 SrcTy = SrcVecTy->getElementType();
3137 DestTy = DestVecTy->getElementType();
3138 }
3139
3140 // Get the bit sizes, we'll need these
3141 unsigned SrcBits = SrcTy->getPrimitiveSizeInBits(); // 0 for ptr
3142 unsigned DestBits = DestTy->getPrimitiveSizeInBits(); // 0 for ptr
3143
3144 // Run through the possibilities ...
3145 if (DestTy->isIntegerTy()) { // Casting to integral
3146 if (SrcTy->isIntegerTy()) { // Casting from integral
3147 if (DestBits < SrcBits)
3148 return Trunc; // int -> smaller int
3149 else if (DestBits > SrcBits) { // its an extension
3150 if (SrcIsSigned)
3151 return SExt; // signed -> SEXT
3152 else
3153 return ZExt; // unsigned -> ZEXT
3154 } else {
3155 return BitCast; // Same size, No-op cast
3156 }
3157 } else if (SrcTy->isFloatingPointTy()) { // Casting from floating pt
3158 if (DestIsSigned)
3159 return FPToSI; // FP -> sint
3160 else
3161 return FPToUI; // FP -> uint
3162 } else if (SrcTy->isVectorTy()) {
3163 assert(DestBits == SrcBits &&((DestBits == SrcBits && "Casting vector to integer of different width"
) ? static_cast<void> (0) : __assert_fail ("DestBits == SrcBits && \"Casting vector to integer of different width\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 3164, __PRETTY_FUNCTION__))
3164 "Casting vector to integer of different width")((DestBits == SrcBits && "Casting vector to integer of different width"
) ? static_cast<void> (0) : __assert_fail ("DestBits == SrcBits && \"Casting vector to integer of different width\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 3164, __PRETTY_FUNCTION__))
;
3165 return BitCast; // Same size, no-op cast
3166 } else {
3167 assert(SrcTy->isPointerTy() &&((SrcTy->isPointerTy() && "Casting from a value that is not first-class type"
) ? static_cast<void> (0) : __assert_fail ("SrcTy->isPointerTy() && \"Casting from a value that is not first-class type\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 3168, __PRETTY_FUNCTION__))
3168 "Casting from a value that is not first-class type")((SrcTy->isPointerTy() && "Casting from a value that is not first-class type"
) ? static_cast<void> (0) : __assert_fail ("SrcTy->isPointerTy() && \"Casting from a value that is not first-class type\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 3168, __PRETTY_FUNCTION__))
;
3169 return PtrToInt; // ptr -> int
3170 }
3171 } else if (DestTy->isFloatingPointTy()) { // Casting to floating pt
3172 if (SrcTy->isIntegerTy()) { // Casting from integral
3173 if (SrcIsSigned)
3174 return SIToFP; // sint -> FP
3175 else
3176 return UIToFP; // uint -> FP
3177 } else if (SrcTy->isFloatingPointTy()) { // Casting from floating pt
3178 if (DestBits < SrcBits) {
3179 return FPTrunc; // FP -> smaller FP
3180 } else if (DestBits > SrcBits) {
3181 return FPExt; // FP -> larger FP
3182 } else {
3183 return BitCast; // same size, no-op cast
3184 }
3185 } else if (SrcTy->isVectorTy()) {
3186 assert(DestBits == SrcBits &&((DestBits == SrcBits && "Casting vector to floating point of different width"
) ? static_cast<void> (0) : __assert_fail ("DestBits == SrcBits && \"Casting vector to floating point of different width\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 3187, __PRETTY_FUNCTION__))
3187 "Casting vector to floating point of different width")((DestBits == SrcBits && "Casting vector to floating point of different width"
) ? static_cast<void> (0) : __assert_fail ("DestBits == SrcBits && \"Casting vector to floating point of different width\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 3187, __PRETTY_FUNCTION__))
;
3188 return BitCast; // same size, no-op cast
3189 }
3190 llvm_unreachable("Casting pointer or non-first class to float")::llvm::llvm_unreachable_internal("Casting pointer or non-first class to float"
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 3190)
;
3191 } else if (DestTy->isVectorTy()) {
3192 assert(DestBits == SrcBits &&((DestBits == SrcBits && "Illegal cast to vector (wrong type or size)"
) ? static_cast<void> (0) : __assert_fail ("DestBits == SrcBits && \"Illegal cast to vector (wrong type or size)\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 3193, __PRETTY_FUNCTION__))
3193 "Illegal cast to vector (wrong type or size)")((DestBits == SrcBits && "Illegal cast to vector (wrong type or size)"
) ? static_cast<void> (0) : __assert_fail ("DestBits == SrcBits && \"Illegal cast to vector (wrong type or size)\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 3193, __PRETTY_FUNCTION__))
;
3194 return BitCast;
3195 } else if (DestTy->isPointerTy()) {
3196 if (SrcTy->isPointerTy()) {
3197 if (DestTy->getPointerAddressSpace() != SrcTy->getPointerAddressSpace())
3198 return AddrSpaceCast;
3199 return BitCast; // ptr -> ptr
3200 } else if (SrcTy->isIntegerTy()) {
3201 return IntToPtr; // int -> ptr
3202 }
3203 llvm_unreachable("Casting pointer to other than pointer or int")::llvm::llvm_unreachable_internal("Casting pointer to other than pointer or int"
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 3203)
;
3204 } else if (DestTy->isX86_MMXTy()) {
3205 if (SrcTy->isVectorTy()) {
3206 assert(DestBits == SrcBits && "Casting vector of wrong width to X86_MMX")((DestBits == SrcBits && "Casting vector of wrong width to X86_MMX"
) ? static_cast<void> (0) : __assert_fail ("DestBits == SrcBits && \"Casting vector of wrong width to X86_MMX\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 3206, __PRETTY_FUNCTION__))
;
3207 return BitCast; // 64-bit vector to MMX
3208 }
3209 llvm_unreachable("Illegal cast to X86_MMX")::llvm::llvm_unreachable_internal("Illegal cast to X86_MMX", "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 3209)
;
3210 }
3211 llvm_unreachable("Casting to type that is not first-class")::llvm::llvm_unreachable_internal("Casting to type that is not first-class"
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 3211)
;
3212}
3213
3214//===----------------------------------------------------------------------===//
3215// CastInst SubClass Constructors
3216//===----------------------------------------------------------------------===//
3217
3218/// Check that the construction parameters for a CastInst are correct. This
3219/// could be broken out into the separate constructors but it is useful to have
3220/// it in one place and to eliminate the redundant code for getting the sizes
3221/// of the types involved.
3222bool
3223CastInst::castIsValid(Instruction::CastOps op, Value *S, Type *DstTy) {
3224 // Check for type sanity on the arguments
3225 Type *SrcTy = S->getType();
3226
3227 if (!SrcTy->isFirstClassType() || !DstTy->isFirstClassType() ||
3228 SrcTy->isAggregateType() || DstTy->isAggregateType())
3229 return false;
3230
3231 // Get the size of the types in bits, we'll need this later
3232 unsigned SrcBitSize = SrcTy->getScalarSizeInBits();
3233 unsigned DstBitSize = DstTy->getScalarSizeInBits();
3234
3235 // If these are vector types, get the lengths of the vectors (using zero for
3236 // scalar types means that checking that vector lengths match also checks that
3237 // scalars are not being converted to vectors or vectors to scalars).
3238 unsigned SrcLength = SrcTy->isVectorTy() ?
3239 cast<VectorType>(SrcTy)->getNumElements() : 0;
3240 unsigned DstLength = DstTy->isVectorTy() ?
3241 cast<VectorType>(DstTy)->getNumElements() : 0;
3242
3243 // Switch on the opcode provided
3244 switch (op) {
3245 default: return false; // This is an input error
3246 case Instruction::Trunc:
3247 return SrcTy->isIntOrIntVectorTy() && DstTy->isIntOrIntVectorTy() &&
3248 SrcLength == DstLength && SrcBitSize > DstBitSize;
3249 case Instruction::ZExt:
3250 return SrcTy->isIntOrIntVectorTy() && DstTy->isIntOrIntVectorTy() &&
3251 SrcLength == DstLength && SrcBitSize < DstBitSize;
3252 case Instruction::SExt:
3253 return SrcTy->isIntOrIntVectorTy() && DstTy->isIntOrIntVectorTy() &&
3254 SrcLength == DstLength && SrcBitSize < DstBitSize;
3255 case Instruction::FPTrunc:
3256 return SrcTy->isFPOrFPVectorTy() && DstTy->isFPOrFPVectorTy() &&
3257 SrcLength == DstLength && SrcBitSize > DstBitSize;
3258 case Instruction::FPExt:
3259 return SrcTy->isFPOrFPVectorTy() && DstTy->isFPOrFPVectorTy() &&
3260 SrcLength == DstLength && SrcBitSize < DstBitSize;
3261 case Instruction::UIToFP:
3262 case Instruction::SIToFP:
3263 return SrcTy->isIntOrIntVectorTy() && DstTy->isFPOrFPVectorTy() &&
3264 SrcLength == DstLength;
3265 case Instruction::FPToUI:
3266 case Instruction::FPToSI:
3267 return SrcTy->isFPOrFPVectorTy() && DstTy->isIntOrIntVectorTy() &&
3268 SrcLength == DstLength;
3269 case Instruction::PtrToInt:
3270 if (isa<VectorType>(SrcTy) != isa<VectorType>(DstTy))
3271 return false;
3272 if (VectorType *VT = dyn_cast<VectorType>(SrcTy))
3273 if (VT->getNumElements() != cast<VectorType>(DstTy)->getNumElements())
3274 return false;
3275 return SrcTy->isPtrOrPtrVectorTy() && DstTy->isIntOrIntVectorTy();
3276 case Instruction::IntToPtr:
3277 if (isa<VectorType>(SrcTy) != isa<VectorType>(DstTy))
3278 return false;
3279 if (VectorType *VT = dyn_cast<VectorType>(SrcTy))
3280 if (VT->getNumElements() != cast<VectorType>(DstTy)->getNumElements())
3281 return false;
3282 return SrcTy->isIntOrIntVectorTy() && DstTy->isPtrOrPtrVectorTy();
3283 case Instruction::BitCast: {
3284 PointerType *SrcPtrTy = dyn_cast<PointerType>(SrcTy->getScalarType());
3285 PointerType *DstPtrTy = dyn_cast<PointerType>(DstTy->getScalarType());
3286
3287 // BitCast implies a no-op cast of type only. No bits change.
3288 // However, you can't cast pointers to anything but pointers.
3289 if (!SrcPtrTy != !DstPtrTy)
3290 return false;
3291
3292 // For non-pointer cases, the cast is okay if the source and destination bit
3293 // widths are identical.
3294 if (!SrcPtrTy)
3295 return SrcTy->getPrimitiveSizeInBits() == DstTy->getPrimitiveSizeInBits();
3296
3297 // If both are pointers then the address spaces must match.
3298 if (SrcPtrTy->getAddressSpace() != DstPtrTy->getAddressSpace())
3299 return false;
3300
3301 // A vector of pointers must have the same number of elements.
3302 VectorType *SrcVecTy = dyn_cast<VectorType>(SrcTy);
3303 VectorType *DstVecTy = dyn_cast<VectorType>(DstTy);
3304 if (SrcVecTy && DstVecTy)
3305 return (SrcVecTy->getNumElements() == DstVecTy->getNumElements());
3306 if (SrcVecTy)
3307 return SrcVecTy->getNumElements() == 1;
3308 if (DstVecTy)
3309 return DstVecTy->getNumElements() == 1;
3310
3311 return true;
3312 }
3313 case Instruction::AddrSpaceCast: {
3314 PointerType *SrcPtrTy = dyn_cast<PointerType>(SrcTy->getScalarType());
3315 if (!SrcPtrTy)
3316 return false;
3317
3318 PointerType *DstPtrTy = dyn_cast<PointerType>(DstTy->getScalarType());
3319 if (!DstPtrTy)
3320 return false;
3321
3322 if (SrcPtrTy->getAddressSpace() == DstPtrTy->getAddressSpace())
3323 return false;
3324
3325 if (VectorType *SrcVecTy = dyn_cast<VectorType>(SrcTy)) {
3326 if (VectorType *DstVecTy = dyn_cast<VectorType>(DstTy))
3327 return (SrcVecTy->getNumElements() == DstVecTy->getNumElements());
3328
3329 return false;
3330 }
3331
3332 return true;
3333 }
3334 }
3335}
3336
3337TruncInst::TruncInst(
3338 Value *S, Type *Ty, const Twine &Name, Instruction *InsertBefore
3339) : CastInst(Ty, Trunc, S, Name, InsertBefore) {
3340 assert(castIsValid(getOpcode(), S, Ty) && "Illegal Trunc")((castIsValid(getOpcode(), S, Ty) && "Illegal Trunc")
? static_cast<void> (0) : __assert_fail ("castIsValid(getOpcode(), S, Ty) && \"Illegal Trunc\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 3340, __PRETTY_FUNCTION__))
;
3341}
3342
3343TruncInst::TruncInst(
3344 Value *S, Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd
3345) : CastInst(Ty, Trunc, S, Name, InsertAtEnd) {
3346 assert(castIsValid(getOpcode(), S, Ty) && "Illegal Trunc")((castIsValid(getOpcode(), S, Ty) && "Illegal Trunc")
? static_cast<void> (0) : __assert_fail ("castIsValid(getOpcode(), S, Ty) && \"Illegal Trunc\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 3346, __PRETTY_FUNCTION__))
;
3347}
3348
3349ZExtInst::ZExtInst(
3350 Value *S, Type *Ty, const Twine &Name, Instruction *InsertBefore
3351) : CastInst(Ty, ZExt, S, Name, InsertBefore) {
3352 assert(castIsValid(getOpcode(), S, Ty) && "Illegal ZExt")((castIsValid(getOpcode(), S, Ty) && "Illegal ZExt") ?
static_cast<void> (0) : __assert_fail ("castIsValid(getOpcode(), S, Ty) && \"Illegal ZExt\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 3352, __PRETTY_FUNCTION__))
;
3353}
3354
3355ZExtInst::ZExtInst(
3356 Value *S, Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd
3357) : CastInst(Ty, ZExt, S, Name, InsertAtEnd) {
3358 assert(castIsValid(getOpcode(), S, Ty) && "Illegal ZExt")((castIsValid(getOpcode(), S, Ty) && "Illegal ZExt") ?
static_cast<void> (0) : __assert_fail ("castIsValid(getOpcode(), S, Ty) && \"Illegal ZExt\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 3358, __PRETTY_FUNCTION__))
;
3359}
3360SExtInst::SExtInst(
3361 Value *S, Type *Ty, const Twine &Name, Instruction *InsertBefore
3362) : CastInst(Ty, SExt, S, Name, InsertBefore) {
3363 assert(castIsValid(getOpcode(), S, Ty) && "Illegal SExt")((castIsValid(getOpcode(), S, Ty) && "Illegal SExt") ?
static_cast<void> (0) : __assert_fail ("castIsValid(getOpcode(), S, Ty) && \"Illegal SExt\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 3363, __PRETTY_FUNCTION__))
;
3364}
3365
3366SExtInst::SExtInst(
3367 Value *S, Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd
3368) : CastInst(Ty, SExt, S, Name, InsertAtEnd) {
3369 assert(castIsValid(getOpcode(), S, Ty) && "Illegal SExt")((castIsValid(getOpcode(), S, Ty) && "Illegal SExt") ?
static_cast<void> (0) : __assert_fail ("castIsValid(getOpcode(), S, Ty) && \"Illegal SExt\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 3369, __PRETTY_FUNCTION__))
;
3370}
3371
3372FPTruncInst::FPTruncInst(
3373 Value *S, Type *Ty, const Twine &Name, Instruction *InsertBefore
3374) : CastInst(Ty, FPTrunc, S, Name, InsertBefore) {
3375 assert(castIsValid(getOpcode(), S, Ty) && "Illegal FPTrunc")((castIsValid(getOpcode(), S, Ty) && "Illegal FPTrunc"
) ? static_cast<void> (0) : __assert_fail ("castIsValid(getOpcode(), S, Ty) && \"Illegal FPTrunc\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 3375, __PRETTY_FUNCTION__))
;
3376}
3377
3378FPTruncInst::FPTruncInst(
3379 Value *S, Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd
3380) : CastInst(Ty, FPTrunc, S, Name, InsertAtEnd) {
3381 assert(castIsValid(getOpcode(), S, Ty) && "Illegal FPTrunc")((castIsValid(getOpcode(), S, Ty) && "Illegal FPTrunc"
) ? static_cast<void> (0) : __assert_fail ("castIsValid(getOpcode(), S, Ty) && \"Illegal FPTrunc\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 3381, __PRETTY_FUNCTION__))
;
3382}
3383
3384FPExtInst::FPExtInst(
3385 Value *S, Type *Ty, const Twine &Name, Instruction *InsertBefore
3386) : CastInst(Ty, FPExt, S, Name, InsertBefore) {
3387 assert(castIsValid(getOpcode(), S, Ty) && "Illegal FPExt")((castIsValid(getOpcode(), S, Ty) && "Illegal FPExt")
? static_cast<void> (0) : __assert_fail ("castIsValid(getOpcode(), S, Ty) && \"Illegal FPExt\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 3387, __PRETTY_FUNCTION__))
;
3388}
3389
3390FPExtInst::FPExtInst(
3391 Value *S, Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd
3392) : CastInst(Ty, FPExt, S, Name, InsertAtEnd) {
3393 assert(castIsValid(getOpcode(), S, Ty) && "Illegal FPExt")((castIsValid(getOpcode(), S, Ty) && "Illegal FPExt")
? static_cast<void> (0) : __assert_fail ("castIsValid(getOpcode(), S, Ty) && \"Illegal FPExt\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 3393, __PRETTY_FUNCTION__))
;
3394}
3395
3396UIToFPInst::UIToFPInst(
3397 Value *S, Type *Ty, const Twine &Name, Instruction *InsertBefore
3398) : CastInst(Ty, UIToFP, S, Name, InsertBefore) {
3399 assert(castIsValid(getOpcode(), S, Ty) && "Illegal UIToFP")((castIsValid(getOpcode(), S, Ty) && "Illegal UIToFP"
) ? static_cast<void> (0) : __assert_fail ("castIsValid(getOpcode(), S, Ty) && \"Illegal UIToFP\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 3399, __PRETTY_FUNCTION__))
;
3400}
3401
3402UIToFPInst::UIToFPInst(
3403 Value *S, Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd
3404) : CastInst(Ty, UIToFP, S, Name, InsertAtEnd) {
3405 assert(castIsValid(getOpcode(), S, Ty) && "Illegal UIToFP")((castIsValid(getOpcode(), S, Ty) && "Illegal UIToFP"
) ? static_cast<void> (0) : __assert_fail ("castIsValid(getOpcode(), S, Ty) && \"Illegal UIToFP\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 3405, __PRETTY_FUNCTION__))
;
3406}
3407
3408SIToFPInst::SIToFPInst(
3409 Value *S, Type *Ty, const Twine &Name, Instruction *InsertBefore
3410) : CastInst(Ty, SIToFP, S, Name, InsertBefore) {
3411 assert(castIsValid(getOpcode(), S, Ty) && "Illegal SIToFP")((castIsValid(getOpcode(), S, Ty) && "Illegal SIToFP"
) ? static_cast<void> (0) : __assert_fail ("castIsValid(getOpcode(), S, Ty) && \"Illegal SIToFP\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 3411, __PRETTY_FUNCTION__))
;
3412}
3413
3414SIToFPInst::SIToFPInst(
3415 Value *S, Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd
3416) : CastInst(Ty, SIToFP, S, Name, InsertAtEnd) {
3417 assert(castIsValid(getOpcode(), S, Ty) && "Illegal SIToFP")((castIsValid(getOpcode(), S, Ty) && "Illegal SIToFP"
) ? static_cast<void> (0) : __assert_fail ("castIsValid(getOpcode(), S, Ty) && \"Illegal SIToFP\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 3417, __PRETTY_FUNCTION__))
;
3418}
3419
3420FPToUIInst::FPToUIInst(
3421 Value *S, Type *Ty, const Twine &Name, Instruction *InsertBefore
3422) : CastInst(Ty, FPToUI, S, Name, InsertBefore) {
3423 assert(castIsValid(getOpcode(), S, Ty) && "Illegal FPToUI")((castIsValid(getOpcode(), S, Ty) && "Illegal FPToUI"
) ? static_cast<void> (0) : __assert_fail ("castIsValid(getOpcode(), S, Ty) && \"Illegal FPToUI\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 3423, __PRETTY_FUNCTION__))
;
3424}
3425
3426FPToUIInst::FPToUIInst(
3427 Value *S, Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd
3428) : CastInst(Ty, FPToUI, S, Name, InsertAtEnd) {
3429 assert(castIsValid(getOpcode(), S, Ty) && "Illegal FPToUI")((castIsValid(getOpcode(), S, Ty) && "Illegal FPToUI"
) ? static_cast<void> (0) : __assert_fail ("castIsValid(getOpcode(), S, Ty) && \"Illegal FPToUI\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 3429, __PRETTY_FUNCTION__))
;
3430}
3431
3432FPToSIInst::FPToSIInst(
3433 Value *S, Type *Ty, const Twine &Name, Instruction *InsertBefore
3434) : CastInst(Ty, FPToSI, S, Name, InsertBefore) {
3435 assert(castIsValid(getOpcode(), S, Ty) && "Illegal FPToSI")((castIsValid(getOpcode(), S, Ty) && "Illegal FPToSI"
) ? static_cast<void> (0) : __assert_fail ("castIsValid(getOpcode(), S, Ty) && \"Illegal FPToSI\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 3435, __PRETTY_FUNCTION__))
;
3436}
3437
3438FPToSIInst::FPToSIInst(
3439 Value *S, Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd
3440) : CastInst(Ty, FPToSI, S, Name, InsertAtEnd) {
3441 assert(castIsValid(getOpcode(), S, Ty) && "Illegal FPToSI")((castIsValid(getOpcode(), S, Ty) && "Illegal FPToSI"
) ? static_cast<void> (0) : __assert_fail ("castIsValid(getOpcode(), S, Ty) && \"Illegal FPToSI\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 3441, __PRETTY_FUNCTION__))
;
3442}
3443
3444PtrToIntInst::PtrToIntInst(
3445 Value *S, Type *Ty, const Twine &Name, Instruction *InsertBefore
3446) : CastInst(Ty, PtrToInt, S, Name, InsertBefore) {
3447 assert(castIsValid(getOpcode(), S, Ty) && "Illegal PtrToInt")((castIsValid(getOpcode(), S, Ty) && "Illegal PtrToInt"
) ? static_cast<void> (0) : __assert_fail ("castIsValid(getOpcode(), S, Ty) && \"Illegal PtrToInt\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 3447, __PRETTY_FUNCTION__))
;
3448}
3449
3450PtrToIntInst::PtrToIntInst(
3451 Value *S, Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd
3452) : CastInst(Ty, PtrToInt, S, Name, InsertAtEnd) {
3453 assert(castIsValid(getOpcode(), S, Ty) && "Illegal PtrToInt")((castIsValid(getOpcode(), S, Ty) && "Illegal PtrToInt"
) ? static_cast<void> (0) : __assert_fail ("castIsValid(getOpcode(), S, Ty) && \"Illegal PtrToInt\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 3453, __PRETTY_FUNCTION__))
;
3454}
3455
3456IntToPtrInst::IntToPtrInst(
3457 Value *S, Type *Ty, const Twine &Name, Instruction *InsertBefore
3458) : CastInst(Ty, IntToPtr, S, Name, InsertBefore) {
3459 assert(castIsValid(getOpcode(), S, Ty) && "Illegal IntToPtr")((castIsValid(getOpcode(), S, Ty) && "Illegal IntToPtr"
) ? static_cast<void> (0) : __assert_fail ("castIsValid(getOpcode(), S, Ty) && \"Illegal IntToPtr\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 3459, __PRETTY_FUNCTION__))
;
3460}
3461
3462IntToPtrInst::IntToPtrInst(
3463 Value *S, Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd
3464) : CastInst(Ty, IntToPtr, S, Name, InsertAtEnd) {
3465 assert(castIsValid(getOpcode(), S, Ty) && "Illegal IntToPtr")((castIsValid(getOpcode(), S, Ty) && "Illegal IntToPtr"
) ? static_cast<void> (0) : __assert_fail ("castIsValid(getOpcode(), S, Ty) && \"Illegal IntToPtr\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 3465, __PRETTY_FUNCTION__))
;
3466}
3467
3468BitCastInst::BitCastInst(
3469 Value *S, Type *Ty, const Twine &Name, Instruction *InsertBefore
3470) : CastInst(Ty, BitCast, S, Name, InsertBefore) {
3471 assert(castIsValid(getOpcode(), S, Ty) && "Illegal BitCast")((castIsValid(getOpcode(), S, Ty) && "Illegal BitCast"
) ? static_cast<void> (0) : __assert_fail ("castIsValid(getOpcode(), S, Ty) && \"Illegal BitCast\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 3471, __PRETTY_FUNCTION__))
;
3472}
3473
3474BitCastInst::BitCastInst(
3475 Value *S, Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd
3476) : CastInst(Ty, BitCast, S, Name, InsertAtEnd) {
3477 assert(castIsValid(getOpcode(), S, Ty) && "Illegal BitCast")((castIsValid(getOpcode(), S, Ty) && "Illegal BitCast"
) ? static_cast<void> (0) : __assert_fail ("castIsValid(getOpcode(), S, Ty) && \"Illegal BitCast\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 3477, __PRETTY_FUNCTION__))
;
3478}
3479
3480AddrSpaceCastInst::AddrSpaceCastInst(
3481 Value *S, Type *Ty, const Twine &Name, Instruction *InsertBefore
3482) : CastInst(Ty, AddrSpaceCast, S, Name, InsertBefore) {
3483 assert(castIsValid(getOpcode(), S, Ty) && "Illegal AddrSpaceCast")((castIsValid(getOpcode(), S, Ty) && "Illegal AddrSpaceCast"
) ? static_cast<void> (0) : __assert_fail ("castIsValid(getOpcode(), S, Ty) && \"Illegal AddrSpaceCast\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 3483, __PRETTY_FUNCTION__))
;
3484}
3485
3486AddrSpaceCastInst::AddrSpaceCastInst(
3487 Value *S, Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd
3488) : CastInst(Ty, AddrSpaceCast, S, Name, InsertAtEnd) {
3489 assert(castIsValid(getOpcode(), S, Ty) && "Illegal AddrSpaceCast")((castIsValid(getOpcode(), S, Ty) && "Illegal AddrSpaceCast"
) ? static_cast<void> (0) : __assert_fail ("castIsValid(getOpcode(), S, Ty) && \"Illegal AddrSpaceCast\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 3489, __PRETTY_FUNCTION__))
;
3490}
3491
3492//===----------------------------------------------------------------------===//
3493// CmpInst Classes
3494//===----------------------------------------------------------------------===//
3495
3496CmpInst::CmpInst(Type *ty, OtherOps op, Predicate predicate, Value *LHS,
3497 Value *RHS, const Twine &Name, Instruction *InsertBefore,
3498 Instruction *FlagsSource)
3499 : Instruction(ty, op,
3500 OperandTraits<CmpInst>::op_begin(this),
3501 OperandTraits<CmpInst>::operands(this),
3502 InsertBefore) {
3503 Op<0>() = LHS;
3504 Op<1>() = RHS;
3505 setPredicate((Predicate)predicate);
3506 setName(Name);
3507 if (FlagsSource)
3508 copyIRFlags(FlagsSource);
3509}
3510
3511CmpInst::CmpInst(Type *ty, OtherOps op, Predicate predicate, Value *LHS,
3512 Value *RHS, const Twine &Name, BasicBlock *InsertAtEnd)
3513 : Instruction(ty, op,
3514 OperandTraits<CmpInst>::op_begin(this),
3515 OperandTraits<CmpInst>::operands(this),
3516 InsertAtEnd) {
3517 Op<0>() = LHS;
3518 Op<1>() = RHS;
3519 setPredicate((Predicate)predicate);
3520 setName(Name);
3521}
3522
3523CmpInst *
3524CmpInst::Create(OtherOps Op, Predicate predicate, Value *S1, Value *S2,
3525 const Twine &Name, Instruction *InsertBefore) {
3526 if (Op == Instruction::ICmp) {
3527 if (InsertBefore)
3528 return new ICmpInst(InsertBefore, CmpInst::Predicate(predicate),
3529 S1, S2, Name);
3530 else
3531 return new ICmpInst(CmpInst::Predicate(predicate),
3532 S1, S2, Name);
3533 }
3534
3535 if (InsertBefore)
3536 return new FCmpInst(InsertBefore, CmpInst::Predicate(predicate),
3537 S1, S2, Name);
3538 else
3539 return new FCmpInst(CmpInst::Predicate(predicate),
3540 S1, S2, Name);
3541}
3542
3543CmpInst *
3544CmpInst::Create(OtherOps Op, Predicate predicate, Value *S1, Value *S2,
3545 const Twine &Name, BasicBlock *InsertAtEnd) {
3546 if (Op == Instruction::ICmp) {
3547 return new ICmpInst(*InsertAtEnd, CmpInst::Predicate(predicate),
3548 S1, S2, Name);
3549 }
3550 return new FCmpInst(*InsertAtEnd, CmpInst::Predicate(predicate),
3551 S1, S2, Name);
3552}
3553
3554void CmpInst::swapOperands() {
3555 if (ICmpInst *IC = dyn_cast<ICmpInst>(this))
3556 IC->swapOperands();
3557 else
3558 cast<FCmpInst>(this)->swapOperands();
3559}
3560
3561bool CmpInst::isCommutative() const {
3562 if (const ICmpInst *IC = dyn_cast<ICmpInst>(this))
3563 return IC->isCommutative();
3564 return cast<FCmpInst>(this)->isCommutative();
3565}
3566
3567bool CmpInst::isEquality() const {
3568 if (const ICmpInst *IC = dyn_cast<ICmpInst>(this))
3569 return IC->isEquality();
3570 return cast<FCmpInst>(this)->isEquality();
3571}
3572
3573CmpInst::Predicate CmpInst::getInversePredicate(Predicate pred) {
3574 switch (pred) {
3575 default: llvm_unreachable("Unknown cmp predicate!")::llvm::llvm_unreachable_internal("Unknown cmp predicate!", "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 3575)
;
3576 case ICMP_EQ: return ICMP_NE;
3577 case ICMP_NE: return ICMP_EQ;
3578 case ICMP_UGT: return ICMP_ULE;
3579 case ICMP_ULT: return ICMP_UGE;
3580 case ICMP_UGE: return ICMP_ULT;
3581 case ICMP_ULE: return ICMP_UGT;
3582 case ICMP_SGT: return ICMP_SLE;
3583 case ICMP_SLT: return ICMP_SGE;
3584 case ICMP_SGE: return ICMP_SLT;
3585 case ICMP_SLE: return ICMP_SGT;
3586
3587 case FCMP_OEQ: return FCMP_UNE;
3588 case FCMP_ONE: return FCMP_UEQ;
3589 case FCMP_OGT: return FCMP_ULE;
3590 case FCMP_OLT: return FCMP_UGE;
3591 case FCMP_OGE: return FCMP_ULT;
3592 case FCMP_OLE: return FCMP_UGT;
3593 case FCMP_UEQ: return FCMP_ONE;
3594 case FCMP_UNE: return FCMP_OEQ;
3595 case FCMP_UGT: return FCMP_OLE;
3596 case FCMP_ULT: return FCMP_OGE;
3597 case FCMP_UGE: return FCMP_OLT;
3598 case FCMP_ULE: return FCMP_OGT;
3599 case FCMP_ORD: return FCMP_UNO;
3600 case FCMP_UNO: return FCMP_ORD;
3601 case FCMP_TRUE: return FCMP_FALSE;
3602 case FCMP_FALSE: return FCMP_TRUE;
3603 }
3604}
3605
3606StringRef CmpInst::getPredicateName(Predicate Pred) {
3607 switch (Pred) {
3608 default: return "unknown";
3609 case FCmpInst::FCMP_FALSE: return "false";
3610 case FCmpInst::FCMP_OEQ: return "oeq";
3611 case FCmpInst::FCMP_OGT: return "ogt";
3612 case FCmpInst::FCMP_OGE: return "oge";
3613 case FCmpInst::FCMP_OLT: return "olt";
3614 case FCmpInst::FCMP_OLE: return "ole";
3615 case FCmpInst::FCMP_ONE: return "one";
3616 case FCmpInst::FCMP_ORD: return "ord";
3617 case FCmpInst::FCMP_UNO: return "uno";
3618 case FCmpInst::FCMP_UEQ: return "ueq";
3619 case FCmpInst::FCMP_UGT: return "ugt";
3620 case FCmpInst::FCMP_UGE: return "uge";
3621 case FCmpInst::FCMP_ULT: return "ult";
3622 case FCmpInst::FCMP_ULE: return "ule";
3623 case FCmpInst::FCMP_UNE: return "une";
3624 case FCmpInst::FCMP_TRUE: return "true";
3625 case ICmpInst::ICMP_EQ: return "eq";
3626 case ICmpInst::ICMP_NE: return "ne";
3627 case ICmpInst::ICMP_SGT: return "sgt";
3628 case ICmpInst::ICMP_SGE: return "sge";
3629 case ICmpInst::ICMP_SLT: return "slt";
3630 case ICmpInst::ICMP_SLE: return "sle";
3631 case ICmpInst::ICMP_UGT: return "ugt";
3632 case ICmpInst::ICMP_UGE: return "uge";
3633 case ICmpInst::ICMP_ULT: return "ult";
3634 case ICmpInst::ICMP_ULE: return "ule";
3635 }
3636}
3637
3638ICmpInst::Predicate ICmpInst::getSignedPredicate(Predicate pred) {
3639 switch (pred) {
3640 default: llvm_unreachable("Unknown icmp predicate!")::llvm::llvm_unreachable_internal("Unknown icmp predicate!", "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 3640)
;
3641 case ICMP_EQ: case ICMP_NE:
3642 case ICMP_SGT: case ICMP_SLT: case ICMP_SGE: case ICMP_SLE:
3643 return pred;
3644 case ICMP_UGT: return ICMP_SGT;
3645 case ICMP_ULT: return ICMP_SLT;
3646 case ICMP_UGE: return ICMP_SGE;
3647 case ICMP_ULE: return ICMP_SLE;
3648 }
3649}
3650
3651ICmpInst::Predicate ICmpInst::getUnsignedPredicate(Predicate pred) {
3652 switch (pred) {
3653 default: llvm_unreachable("Unknown icmp predicate!")::llvm::llvm_unreachable_internal("Unknown icmp predicate!", "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 3653)
;
3654 case ICMP_EQ: case ICMP_NE:
3655 case ICMP_UGT: case ICMP_ULT: case ICMP_UGE: case ICMP_ULE:
3656 return pred;
3657 case ICMP_SGT: return ICMP_UGT;
3658 case ICMP_SLT: return ICMP_ULT;
3659 case ICMP_SGE: return ICMP_UGE;
3660 case ICMP_SLE: return ICMP_ULE;
3661 }
3662}
3663
3664CmpInst::Predicate CmpInst::getFlippedStrictnessPredicate(Predicate pred) {
3665 switch (pred) {
3666 default: llvm_unreachable("Unknown or unsupported cmp predicate!")::llvm::llvm_unreachable_internal("Unknown or unsupported cmp predicate!"
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 3666)
;
3667 case ICMP_SGT: return ICMP_SGE;
3668 case ICMP_SLT: return ICMP_SLE;
3669 case ICMP_SGE: return ICMP_SGT;
3670 case ICMP_SLE: return ICMP_SLT;
3671 case ICMP_UGT: return ICMP_UGE;
3672 case ICMP_ULT: return ICMP_ULE;
3673 case ICMP_UGE: return ICMP_UGT;
3674 case ICMP_ULE: return ICMP_ULT;
3675
3676 case FCMP_OGT: return FCMP_OGE;
3677 case FCMP_OLT: return FCMP_OLE;
3678 case FCMP_OGE: return FCMP_OGT;
3679 case FCMP_OLE: return FCMP_OLT;
3680 case FCMP_UGT: return FCMP_UGE;
3681 case FCMP_ULT: return FCMP_ULE;
3682 case FCMP_UGE: return FCMP_UGT;
3683 case FCMP_ULE: return FCMP_ULT;
3684 }
3685}
3686
3687CmpInst::Predicate CmpInst::getSwappedPredicate(Predicate pred) {
3688 switch (pred) {
3689 default: llvm_unreachable("Unknown cmp predicate!")::llvm::llvm_unreachable_internal("Unknown cmp predicate!", "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 3689)
;
3690 case ICMP_EQ: case ICMP_NE:
3691 return pred;
3692 case ICMP_SGT: return ICMP_SLT;
3693 case ICMP_SLT: return ICMP_SGT;
3694 case ICMP_SGE: return ICMP_SLE;
3695 case ICMP_SLE: return ICMP_SGE;
3696 case ICMP_UGT: return ICMP_ULT;
3697 case ICMP_ULT: return ICMP_UGT;
3698 case ICMP_UGE: return ICMP_ULE;
3699 case ICMP_ULE: return ICMP_UGE;
3700
3701 case FCMP_FALSE: case FCMP_TRUE:
3702 case FCMP_OEQ: case FCMP_ONE:
3703 case FCMP_UEQ: case FCMP_UNE:
3704 case FCMP_ORD: case FCMP_UNO:
3705 return pred;
3706 case FCMP_OGT: return FCMP_OLT;
3707 case FCMP_OLT: return FCMP_OGT;
3708 case FCMP_OGE: return FCMP_OLE;
3709 case FCMP_OLE: return FCMP_OGE;
3710 case FCMP_UGT: return FCMP_ULT;
3711 case FCMP_ULT: return FCMP_UGT;
3712 case FCMP_UGE: return FCMP_ULE;
3713 case FCMP_ULE: return FCMP_UGE;
3714 }
3715}
3716
3717CmpInst::Predicate CmpInst::getNonStrictPredicate(Predicate pred) {
3718 switch (pred) {
3719 case ICMP_SGT: return ICMP_SGE;
3720 case ICMP_SLT: return ICMP_SLE;
3721 case ICMP_UGT: return ICMP_UGE;
3722 case ICMP_ULT: return ICMP_ULE;
3723 case FCMP_OGT: return FCMP_OGE;
3724 case FCMP_OLT: return FCMP_OLE;
3725 case FCMP_UGT: return FCMP_UGE;
3726 case FCMP_ULT: return FCMP_ULE;
3727 default: return pred;
3728 }
3729}
3730
3731CmpInst::Predicate CmpInst::getSignedPredicate(Predicate pred) {
3732 assert(CmpInst::isUnsigned(pred) && "Call only with signed predicates!")((CmpInst::isUnsigned(pred) && "Call only with signed predicates!"
) ? static_cast<void> (0) : __assert_fail ("CmpInst::isUnsigned(pred) && \"Call only with signed predicates!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 3732, __PRETTY_FUNCTION__))
;
3733
3734 switch (pred) {
3735 default:
3736 llvm_unreachable("Unknown predicate!")::llvm::llvm_unreachable_internal("Unknown predicate!", "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 3736)
;
3737 case CmpInst::ICMP_ULT:
3738 return CmpInst::ICMP_SLT;
3739 case CmpInst::ICMP_ULE:
3740 return CmpInst::ICMP_SLE;
3741 case CmpInst::ICMP_UGT:
3742 return CmpInst::ICMP_SGT;
3743 case CmpInst::ICMP_UGE:
3744 return CmpInst::ICMP_SGE;
3745 }
3746}
3747
3748bool CmpInst::isUnsigned(Predicate predicate) {
3749 switch (predicate) {
3750 default: return false;
3751 case ICmpInst::ICMP_ULT: case ICmpInst::ICMP_ULE: case ICmpInst::ICMP_UGT:
3752 case ICmpInst::ICMP_UGE: return true;
3753 }
3754}
3755
3756bool CmpInst::isSigned(Predicate predicate) {
3757 switch (predicate) {
3758 default: return false;
3759 case ICmpInst::ICMP_SLT: case ICmpInst::ICMP_SLE: case ICmpInst::ICMP_SGT:
3760 case ICmpInst::ICMP_SGE: return true;
3761 }
3762}
3763
3764bool CmpInst::isOrdered(Predicate predicate) {
3765 switch (predicate) {
3766 default: return false;
3767 case FCmpInst::FCMP_OEQ: case FCmpInst::FCMP_ONE: case FCmpInst::FCMP_OGT:
3768 case FCmpInst::FCMP_OLT: case FCmpInst::FCMP_OGE: case FCmpInst::FCMP_OLE:
3769 case FCmpInst::FCMP_ORD: return true;
3770 }
3771}
3772
3773bool CmpInst::isUnordered(Predicate predicate) {
3774 switch (predicate) {
3775 default: return false;
3776 case FCmpInst::FCMP_UEQ: case FCmpInst::FCMP_UNE: case FCmpInst::FCMP_UGT:
3777 case FCmpInst::FCMP_ULT: case FCmpInst::FCMP_UGE: case FCmpInst::FCMP_ULE:
3778 case FCmpInst::FCMP_UNO: return true;
3779 }
3780}
3781
3782bool CmpInst::isTrueWhenEqual(Predicate predicate) {
3783 switch(predicate) {
3784 default: return false;
3785 case ICMP_EQ: case ICMP_UGE: case ICMP_ULE: case ICMP_SGE: case ICMP_SLE:
3786 case FCMP_TRUE: case FCMP_UEQ: case FCMP_UGE: case FCMP_ULE: return true;
3787 }
3788}
3789
3790bool CmpInst::isFalseWhenEqual(Predicate predicate) {
3791 switch(predicate) {
3792 case ICMP_NE: case ICMP_UGT: case ICMP_ULT: case ICMP_SGT: case ICMP_SLT:
3793 case FCMP_FALSE: case FCMP_ONE: case FCMP_OGT: case FCMP_OLT: return true;
3794 default: return false;
3795 }
3796}
3797
3798bool CmpInst::isImpliedTrueByMatchingCmp(Predicate Pred1, Predicate Pred2) {
3799 // If the predicates match, then we know the first condition implies the
3800 // second is true.
3801 if (Pred1 == Pred2)
3802 return true;
3803
3804 switch (Pred1) {
3805 default:
3806 break;
3807 case ICMP_EQ:
3808 // A == B implies A >=u B, A <=u B, A >=s B, and A <=s B are true.
3809 return Pred2 == ICMP_UGE || Pred2 == ICMP_ULE || Pred2 == ICMP_SGE ||
3810 Pred2 == ICMP_SLE;
3811 case ICMP_UGT: // A >u B implies A != B and A >=u B are true.
3812 return Pred2 == ICMP_NE || Pred2 == ICMP_UGE;
3813 case ICMP_ULT: // A <u B implies A != B and A <=u B are true.
3814 return Pred2 == ICMP_NE || Pred2 == ICMP_ULE;
3815 case ICMP_SGT: // A >s B implies A != B and A >=s B are true.
3816 return Pred2 == ICMP_NE || Pred2 == ICMP_SGE;
3817 case ICMP_SLT: // A <s B implies A != B and A <=s B are true.
3818 return Pred2 == ICMP_NE || Pred2 == ICMP_SLE;
3819 }
3820 return false;
3821}
3822
3823bool CmpInst::isImpliedFalseByMatchingCmp(Predicate Pred1, Predicate Pred2) {
3824 return isImpliedTrueByMatchingCmp(Pred1, getInversePredicate(Pred2));
3825}
3826
3827//===----------------------------------------------------------------------===//
3828// SwitchInst Implementation
3829//===----------------------------------------------------------------------===//
3830
3831void SwitchInst::init(Value *Value, BasicBlock *Default, unsigned NumReserved) {
3832 assert(Value && Default && NumReserved)((Value && Default && NumReserved) ? static_cast
<void> (0) : __assert_fail ("Value && Default && NumReserved"
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 3832, __PRETTY_FUNCTION__))
;
3833 ReservedSpace = NumReserved;
3834 setNumHungOffUseOperands(2);
3835 allocHungoffUses(ReservedSpace);
3836
3837 Op<0>() = Value;
3838 Op<1>() = Default;
3839}
3840
3841/// SwitchInst ctor - Create a new switch instruction, specifying a value to
3842/// switch on and a default destination. The number of additional cases can
3843/// be specified here to make memory allocation more efficient. This
3844/// constructor can also autoinsert before another instruction.
3845SwitchInst::SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
3846 Instruction *InsertBefore)
3847 : Instruction(Type::getVoidTy(Value->getContext()), Instruction::Switch,
3848 nullptr, 0, InsertBefore) {
3849 init(Value, Default, 2+NumCases*2);
3850}
3851
3852/// SwitchInst ctor - Create a new switch instruction, specifying a value to
3853/// switch on and a default destination. The number of additional cases can
3854/// be specified here to make memory allocation more efficient. This
3855/// constructor also autoinserts at the end of the specified BasicBlock.
3856SwitchInst::SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
3857 BasicBlock *InsertAtEnd)
3858 : Instruction(Type::getVoidTy(Value->getContext()), Instruction::Switch,
3859 nullptr, 0, InsertAtEnd) {
3860 init(Value, Default, 2+NumCases*2);
3861}
3862
3863SwitchInst::SwitchInst(const SwitchInst &SI)
3864 : Instruction(SI.getType(), Instruction::Switch, nullptr, 0) {
3865 init(SI.getCondition(), SI.getDefaultDest(), SI.getNumOperands());
3866 setNumHungOffUseOperands(SI.getNumOperands());
3867 Use *OL = getOperandList();
3868 const Use *InOL = SI.getOperandList();
3869 for (unsigned i = 2, E = SI.getNumOperands(); i != E; i += 2) {
3870 OL[i] = InOL[i];
3871 OL[i+1] = InOL[i+1];
3872 }
3873 SubclassOptionalData = SI.SubclassOptionalData;
3874}
3875
3876/// addCase - Add an entry to the switch instruction...
3877///
3878void SwitchInst::addCase(ConstantInt *OnVal, BasicBlock *Dest) {
3879 unsigned NewCaseIdx = getNumCases();
3880 unsigned OpNo = getNumOperands();
3881 if (OpNo+2 > ReservedSpace)
3882 growOperands(); // Get more space!
3883 // Initialize some new operands.
3884 assert(OpNo+1 < ReservedSpace && "Growing didn't work!")((OpNo+1 < ReservedSpace && "Growing didn't work!"
) ? static_cast<void> (0) : __assert_fail ("OpNo+1 < ReservedSpace && \"Growing didn't work!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 3884, __PRETTY_FUNCTION__))
;
3885 setNumHungOffUseOperands(OpNo+2);
3886 CaseHandle Case(this, NewCaseIdx);
3887 Case.setValue(OnVal);
3888 Case.setSuccessor(Dest);
3889}
3890
3891/// removeCase - This method removes the specified case and its successor
3892/// from the switch instruction.
3893SwitchInst::CaseIt SwitchInst::removeCase(CaseIt I) {
3894 unsigned idx = I->getCaseIndex();
3895
3896 assert(2 + idx*2 < getNumOperands() && "Case index out of range!!!")((2 + idx*2 < getNumOperands() && "Case index out of range!!!"
) ? static_cast<void> (0) : __assert_fail ("2 + idx*2 < getNumOperands() && \"Case index out of range!!!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 3896, __PRETTY_FUNCTION__))
;
3897
3898 unsigned NumOps = getNumOperands();
3899 Use *OL = getOperandList();
3900
3901 // Overwrite this case with the end of the list.
3902 if (2 + (idx + 1) * 2 != NumOps) {
3903 OL[2 + idx * 2] = OL[NumOps - 2];
3904 OL[2 + idx * 2 + 1] = OL[NumOps - 1];
3905 }
3906
3907 // Nuke the last value.
3908 OL[NumOps-2].set(nullptr);
3909 OL[NumOps-2+1].set(nullptr);
3910 setNumHungOffUseOperands(NumOps-2);
3911
3912 return CaseIt(this, idx);
3913}
3914
3915/// growOperands - grow operands - This grows the operand list in response
3916/// to a push_back style of operation. This grows the number of ops by 3 times.
3917///
3918void SwitchInst::growOperands() {
3919 unsigned e = getNumOperands();
3920 unsigned NumOps = e*3;
3921
3922 ReservedSpace = NumOps;
3923 growHungoffUses(ReservedSpace);
3924}
3925
3926MDNode *
3927SwitchInstProfUpdateWrapper::getProfBranchWeightsMD(const SwitchInst &SI) {
3928 if (MDNode *ProfileData = SI.getMetadata(LLVMContext::MD_prof))
3929 if (auto *MDName = dyn_cast<MDString>(ProfileData->getOperand(0)))
3930 if (MDName->getString() == "branch_weights")
3931 return ProfileData;
3932 return nullptr;
3933}
3934
3935MDNode *SwitchInstProfUpdateWrapper::buildProfBranchWeightsMD() {
3936 assert(Changed && "called only if metadata has changed")((Changed && "called only if metadata has changed") ?
static_cast<void> (0) : __assert_fail ("Changed && \"called only if metadata has changed\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 3936, __PRETTY_FUNCTION__))
;
3937
3938 if (!Weights)
3939 return nullptr;
3940
3941 assert(SI.getNumSuccessors() == Weights->size() &&((SI.getNumSuccessors() == Weights->size() && "num of prof branch_weights must accord with num of successors"
) ? static_cast<void> (0) : __assert_fail ("SI.getNumSuccessors() == Weights->size() && \"num of prof branch_weights must accord with num of successors\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 3942, __PRETTY_FUNCTION__))
3942 "num of prof branch_weights must accord with num of successors")((SI.getNumSuccessors() == Weights->size() && "num of prof branch_weights must accord with num of successors"
) ? static_cast<void> (0) : __assert_fail ("SI.getNumSuccessors() == Weights->size() && \"num of prof branch_weights must accord with num of successors\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 3942, __PRETTY_FUNCTION__))
;
3943
3944 bool AllZeroes =
3945 all_of(Weights.getValue(), [](uint32_t W) { return W == 0; });
3946
3947 if (AllZeroes || Weights.getValue().size() < 2)
3948 return nullptr;
3949
3950 return MDBuilder(SI.getParent()->getContext()).createBranchWeights(*Weights);
3951}
3952
3953void SwitchInstProfUpdateWrapper::init() {
3954 MDNode *ProfileData = getProfBranchWeightsMD(SI);
3955 if (!ProfileData)
3956 return;
3957
3958 if (ProfileData->getNumOperands() != SI.getNumSuccessors() + 1) {
3959 llvm_unreachable("number of prof branch_weights metadata operands does "::llvm::llvm_unreachable_internal("number of prof branch_weights metadata operands does "
"not correspond to number of succesors", "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 3960)
3960 "not correspond to number of succesors")::llvm::llvm_unreachable_internal("number of prof branch_weights metadata operands does "
"not correspond to number of succesors", "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 3960)
;
3961 }
3962
3963 SmallVector<uint32_t, 8> Weights;
3964 for (unsigned CI = 1, CE = SI.getNumSuccessors(); CI <= CE; ++CI) {
3965 ConstantInt *C = mdconst::extract<ConstantInt>(ProfileData->getOperand(CI));
3966 uint32_t CW = C->getValue().getZExtValue();
3967 Weights.push_back(CW);
3968 }
3969 this->Weights = std::move(Weights);
3970}
3971
3972SwitchInst::CaseIt
3973SwitchInstProfUpdateWrapper::removeCase(SwitchInst::CaseIt I) {
3974 if (Weights) {
3975 assert(SI.getNumSuccessors() == Weights->size() &&((SI.getNumSuccessors() == Weights->size() && "num of prof branch_weights must accord with num of successors"
) ? static_cast<void> (0) : __assert_fail ("SI.getNumSuccessors() == Weights->size() && \"num of prof branch_weights must accord with num of successors\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 3976, __PRETTY_FUNCTION__))
3976 "num of prof branch_weights must accord with num of successors")((SI.getNumSuccessors() == Weights->size() && "num of prof branch_weights must accord with num of successors"
) ? static_cast<void> (0) : __assert_fail ("SI.getNumSuccessors() == Weights->size() && \"num of prof branch_weights must accord with num of successors\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 3976, __PRETTY_FUNCTION__))
;
3977 Changed = true;
3978 // Copy the last case to the place of the removed one and shrink.
3979 // This is tightly coupled with the way SwitchInst::removeCase() removes
3980 // the cases in SwitchInst::removeCase(CaseIt).
3981 Weights.getValue()[I->getCaseIndex() + 1] = Weights.getValue().back();
3982 Weights.getValue().pop_back();
3983 }
3984 return SI.removeCase(I);
3985}
3986
3987void SwitchInstProfUpdateWrapper::addCase(
3988 ConstantInt *OnVal, BasicBlock *Dest,
3989 SwitchInstProfUpdateWrapper::CaseWeightOpt W) {
3990 SI.addCase(OnVal, Dest);
3991
3992 if (!Weights && W && *W) {
3993 Changed = true;
3994 Weights = SmallVector<uint32_t, 8>(SI.getNumSuccessors(), 0);
3995 Weights.getValue()[SI.getNumSuccessors() - 1] = *W;
3996 } else if (Weights) {
3997 Changed = true;
3998 Weights.getValue().push_back(W ? *W : 0);
3999 }
4000 if (Weights)
4001 assert(SI.getNumSuccessors() == Weights->size() &&((SI.getNumSuccessors() == Weights->size() && "num of prof branch_weights must accord with num of successors"
) ? static_cast<void> (0) : __assert_fail ("SI.getNumSuccessors() == Weights->size() && \"num of prof branch_weights must accord with num of successors\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 4002, __PRETTY_FUNCTION__))
4002 "num of prof branch_weights must accord with num of successors")((SI.getNumSuccessors() == Weights->size() && "num of prof branch_weights must accord with num of successors"
) ? static_cast<void> (0) : __assert_fail ("SI.getNumSuccessors() == Weights->size() && \"num of prof branch_weights must accord with num of successors\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 4002, __PRETTY_FUNCTION__))
;
4003}
4004
4005SymbolTableList<Instruction>::iterator
4006SwitchInstProfUpdateWrapper::eraseFromParent() {
4007 // Instruction is erased. Mark as unchanged to not touch it in the destructor.
4008 Changed = false;
4009 if (Weights)
4010 Weights->resize(0);
4011 return SI.eraseFromParent();
4012}
4013
4014SwitchInstProfUpdateWrapper::CaseWeightOpt
4015SwitchInstProfUpdateWrapper::getSuccessorWeight(unsigned idx) {
4016 if (!Weights)
4017 return None;
4018 return Weights.getValue()[idx];
4019}
4020
4021void SwitchInstProfUpdateWrapper::setSuccessorWeight(
4022 unsigned idx, SwitchInstProfUpdateWrapper::CaseWeightOpt W) {
4023 if (!W)
4024 return;
4025
4026 if (!Weights && *W)
4027 Weights = SmallVector<uint32_t, 8>(SI.getNumSuccessors(), 0);
4028
4029 if (Weights) {
4030 auto &OldW = Weights.getValue()[idx];
4031 if (*W != OldW) {
4032 Changed = true;
4033 OldW = *W;
4034 }
4035 }
4036}
4037
4038SwitchInstProfUpdateWrapper::CaseWeightOpt
4039SwitchInstProfUpdateWrapper::getSuccessorWeight(const SwitchInst &SI,
4040 unsigned idx) {
4041 if (MDNode *ProfileData = getProfBranchWeightsMD(SI))
4042 if (ProfileData->getNumOperands() == SI.getNumSuccessors() + 1)
4043 return mdconst::extract<ConstantInt>(ProfileData->getOperand(idx + 1))
4044 ->getValue()
4045 .getZExtValue();
4046
4047 return None;
4048}
4049
4050//===----------------------------------------------------------------------===//
4051// IndirectBrInst Implementation
4052//===----------------------------------------------------------------------===//
4053
4054void IndirectBrInst::init(Value *Address, unsigned NumDests) {
4055 assert(Address && Address->getType()->isPointerTy() &&((Address && Address->getType()->isPointerTy() &&
"Address of indirectbr must be a pointer") ? static_cast<
void> (0) : __assert_fail ("Address && Address->getType()->isPointerTy() && \"Address of indirectbr must be a pointer\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 4056, __PRETTY_FUNCTION__))
4056 "Address of indirectbr must be a pointer")((Address && Address->getType()->isPointerTy() &&
"Address of indirectbr must be a pointer") ? static_cast<
void> (0) : __assert_fail ("Address && Address->getType()->isPointerTy() && \"Address of indirectbr must be a pointer\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 4056, __PRETTY_FUNCTION__))
;
4057 ReservedSpace = 1+NumDests;
4058 setNumHungOffUseOperands(1);
4059 allocHungoffUses(ReservedSpace);
4060
4061 Op<0>() = Address;
4062}
4063
4064
4065/// growOperands - grow operands - This grows the operand list in response
4066/// to a push_back style of operation. This grows the number of ops by 2 times.
4067///
4068void IndirectBrInst::growOperands() {
4069 unsigned e = getNumOperands();
4070 unsigned NumOps = e*2;
4071
4072 ReservedSpace = NumOps;
4073 growHungoffUses(ReservedSpace);
4074}
4075
4076IndirectBrInst::IndirectBrInst(Value *Address, unsigned NumCases,
4077 Instruction *InsertBefore)
4078 : Instruction(Type::getVoidTy(Address->getContext()),
4079 Instruction::IndirectBr, nullptr, 0, InsertBefore) {
4080 init(Address, NumCases);
4081}
4082
4083IndirectBrInst::IndirectBrInst(Value *Address, unsigned NumCases,
4084 BasicBlock *InsertAtEnd)
4085 : Instruction(Type::getVoidTy(Address->getContext()),
4086 Instruction::IndirectBr, nullptr, 0, InsertAtEnd) {
4087 init(Address, NumCases);
4088}
4089
4090IndirectBrInst::IndirectBrInst(const IndirectBrInst &IBI)
4091 : Instruction(Type::getVoidTy(IBI.getContext()), Instruction::IndirectBr,
4092 nullptr, IBI.getNumOperands()) {
4093 allocHungoffUses(IBI.getNumOperands());
4094 Use *OL = getOperandList();
4095 const Use *InOL = IBI.getOperandList();
4096 for (unsigned i = 0, E = IBI.getNumOperands(); i != E; ++i)
4097 OL[i] = InOL[i];
4098 SubclassOptionalData = IBI.SubclassOptionalData;
4099}
4100
4101/// addDestination - Add a destination.
4102///
4103void IndirectBrInst::addDestination(BasicBlock *DestBB) {
4104 unsigned OpNo = getNumOperands();
4105 if (OpNo+1 > ReservedSpace)
4106 growOperands(); // Get more space!
4107 // Initialize some new operands.
4108 assert(OpNo < ReservedSpace && "Growing didn't work!")((OpNo < ReservedSpace && "Growing didn't work!") ?
static_cast<void> (0) : __assert_fail ("OpNo < ReservedSpace && \"Growing didn't work!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 4108, __PRETTY_FUNCTION__))
;
4109 setNumHungOffUseOperands(OpNo+1);
4110 getOperandList()[OpNo] = DestBB;
4111}
4112
4113/// removeDestination - This method removes the specified successor from the
4114/// indirectbr instruction.
4115void IndirectBrInst::removeDestination(unsigned idx) {
4116 assert(idx < getNumOperands()-1 && "Successor index out of range!")((idx < getNumOperands()-1 && "Successor index out of range!"
) ? static_cast<void> (0) : __assert_fail ("idx < getNumOperands()-1 && \"Successor index out of range!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/IR/Instructions.cpp"
, 4116, __PRETTY_FUNCTION__))
;
4117
4118 unsigned NumOps = getNumOperands();
4119 Use *OL = getOperandList();
4120
4121 // Replace this value with the last one.
4122 OL[idx+1] = OL[NumOps-1];
4123
4124 // Nuke the last value.
4125 OL[NumOps-1].set(nullptr);
4126 setNumHungOffUseOperands(NumOps-1);
4127}
4128
4129//===----------------------------------------------------------------------===//
4130// FreezeInst Implementation
4131//===----------------------------------------------------------------------===//
4132
4133FreezeInst::FreezeInst(Value *S,
4134 const Twine &Name, Instruction *InsertBefore)
4135 : UnaryInstruction(S->getType(), Freeze, S, InsertBefore) {
4136 setName(Name);
4137}
4138
4139FreezeInst::FreezeInst(Value *S,
4140 const Twine &Name, BasicBlock *InsertAtEnd)
4141 : UnaryInstruction(S->getType(), Freeze, S, InsertAtEnd) {
4142 setName(Name);
4143}
4144
4145//===----------------------------------------------------------------------===//
4146// cloneImpl() implementations
4147//===----------------------------------------------------------------------===//
4148
4149// Define these methods here so vtables don't get emitted into every translation
4150// unit that uses these classes.
4151
4152GetElementPtrInst *GetElementPtrInst::cloneImpl() const {
4153 return new (getNumOperands()) GetElementPtrInst(*this);
4154}
4155
4156UnaryOperator *UnaryOperator::cloneImpl() const {
4157 return Create(getOpcode(), Op<0>());
4158}
4159
4160BinaryOperator *BinaryOperator::cloneImpl() const {
4161 return Create(getOpcode(), Op<0>(), Op<1>());
4162}
4163
4164FCmpInst *FCmpInst::cloneImpl() const {
4165 return new FCmpInst(getPredicate(), Op<0>(), Op<1>());
4166}
4167
4168ICmpInst *ICmpInst::cloneImpl() const {
4169 return new ICmpInst(getPredicate(), Op<0>(), Op<1>());
4170}
4171
4172ExtractValueInst *ExtractValueInst::cloneImpl() const {
4173 return new ExtractValueInst(*this);
4174}
4175
4176InsertValueInst *InsertValueInst::cloneImpl() const {
4177 return new InsertValueInst(*this);
4178}
4179
4180AllocaInst *AllocaInst::cloneImpl() const {
4181 AllocaInst *Result =
4182 new AllocaInst(getAllocatedType(), getType()->getAddressSpace(),
4183 (Value *)getOperand(0), MaybeAlign(getAlignment()));
4184 Result->setUsedWithInAlloca(isUsedWithInAlloca());
4185 Result->setSwiftError(isSwiftError());
4186 return Result;
4187}
4188
4189LoadInst *LoadInst::cloneImpl() const {
4190 return new LoadInst(getType(), getOperand(0), Twine(), isVolatile(),
4191 MaybeAlign(getAlignment()), getOrdering(),
4192 getSyncScopeID());
4193}
4194
4195StoreInst *StoreInst::cloneImpl() const {
4196 return new StoreInst(getOperand(0), getOperand(1), isVolatile(),
4197 MaybeAlign(getAlignment()), getOrdering(),
4198 getSyncScopeID());
4199}
4200
4201AtomicCmpXchgInst *AtomicCmpXchgInst::cloneImpl() const {
4202 AtomicCmpXchgInst *Result =
4203 new AtomicCmpXchgInst(getOperand(0), getOperand(1), getOperand(2),
4204 getSuccessOrdering(), getFailureOrdering(),
4205 getSyncScopeID());
4206 Result->setVolatile(isVolatile());
4207 Result->setWeak(isWeak());
4208 return Result;
4209}
4210
4211AtomicRMWInst *AtomicRMWInst::cloneImpl() const {
4212 AtomicRMWInst *Result =
4213 new AtomicRMWInst(getOperation(), getOperand(0), getOperand(1),
4214 getOrdering(), getSyncScopeID());
4215 Result->setVolatile(isVolatile());
4216 return Result;
4217}
4218
4219FenceInst *FenceInst::cloneImpl() const {
4220 return new FenceInst(getContext(), getOrdering(), getSyncScopeID());
4221}
4222
4223TruncInst *TruncInst::cloneImpl() const {
4224 return new TruncInst(getOperand(0), getType());
4225}
4226
4227ZExtInst *ZExtInst::cloneImpl() const {
4228 return new ZExtInst(getOperand(0), getType());
4229}
4230
4231SExtInst *SExtInst::cloneImpl() const {
4232 return new SExtInst(getOperand(0), getType());
4233}
4234
4235FPTruncInst *FPTruncInst::cloneImpl() const {
4236 return new FPTruncInst(getOperand(0), getType());
4237}
4238
4239FPExtInst *FPExtInst::cloneImpl() const {
4240 return new FPExtInst(getOperand(0), getType());
4241}
4242
4243UIToFPInst *UIToFPInst::cloneImpl() const {
4244 return new UIToFPInst(getOperand(0), getType());
4245}
4246
4247SIToFPInst *SIToFPInst::cloneImpl() const {
4248 return new SIToFPInst(getOperand(0), getType());
4249}
4250
4251FPToUIInst *FPToUIInst::cloneImpl() const {
4252 return new FPToUIInst(getOperand(0), getType());
4253}
4254
4255FPToSIInst *FPToSIInst::cloneImpl() const {
4256 return new FPToSIInst(getOperand(0), getType());
4257}
4258
4259PtrToIntInst *PtrToIntInst::cloneImpl() const {
4260 return new PtrToIntInst(getOperand(0), getType());
4261}
4262
4263IntToPtrInst *IntToPtrInst::cloneImpl() const {
4264 return new IntToPtrInst(getOperand(0), getType());
4265}
4266
4267BitCastInst *BitCastInst::cloneImpl() const {
4268 return new BitCastInst(getOperand(0), getType());
4269}
4270
4271AddrSpaceCastInst *AddrSpaceCastInst::cloneImpl() const {
4272 return new AddrSpaceCastInst(getOperand(0), getType());
4273}
4274
4275CallInst *CallInst::cloneImpl() const {
4276 if (hasOperandBundles()) {
4277 unsigned DescriptorBytes = getNumOperandBundles() * sizeof(BundleOpInfo);
4278 return new(getNumOperands(), DescriptorBytes) CallInst(*this);
4279 }
4280 return new(getNumOperands()) CallInst(*this);
4281}
4282
4283SelectInst *SelectInst::cloneImpl() const {
4284 return SelectInst::Create(getOperand(0), getOperand(1), getOperand(2));
4285}
4286
4287VAArgInst *VAArgInst::cloneImpl() const {
4288 return new VAArgInst(getOperand(0), getType());
4289}
4290
4291ExtractElementInst *ExtractElementInst::cloneImpl() const {
4292 return ExtractElementInst::Create(getOperand(0), getOperand(1));
4293}
4294
4295InsertElementInst *InsertElementInst::cloneImpl() const {
4296 return InsertElementInst::Create(getOperand(0), getOperand(1), getOperand(2));
4297}
4298
4299ShuffleVectorInst *ShuffleVectorInst::cloneImpl() const {
4300 return new ShuffleVectorInst(getOperand(0), getOperand(1), getOperand(2));
4301}
4302
4303PHINode *PHINode::cloneImpl() const { return new PHINode(*this); }
4304
4305LandingPadInst *LandingPadInst::cloneImpl() const {
4306 return new LandingPadInst(*this);
4307}
4308
4309ReturnInst *ReturnInst::cloneImpl() const {
4310 return new(getNumOperands()) ReturnInst(*this);
4311}
4312
4313BranchInst *BranchInst::cloneImpl() const {
4314 return new(getNumOperands()) BranchInst(*this);
4315}
4316
4317SwitchInst *SwitchInst::cloneImpl() const { return new SwitchInst(*this); }
4318
4319IndirectBrInst *IndirectBrInst::cloneImpl() const {
4320 return new IndirectBrInst(*this);
4321}
4322
4323InvokeInst *InvokeInst::cloneImpl() const {
4324 if (hasOperandBundles()) {
4325 unsigned DescriptorBytes = getNumOperandBundles() * sizeof(BundleOpInfo);
4326 return new(getNumOperands(), DescriptorBytes) InvokeInst(*this);
4327 }
4328 return new(getNumOperands()) InvokeInst(*this);
4329}
4330
4331CallBrInst *CallBrInst::cloneImpl() const {
4332 if (hasOperandBundles()) {
4333 unsigned DescriptorBytes = getNumOperandBundles() * sizeof(BundleOpInfo);
4334 return new (getNumOperands(), DescriptorBytes) CallBrInst(*this);
4335 }
4336 return new (getNumOperands()) CallBrInst(*this);
4337}
4338
4339ResumeInst *ResumeInst::cloneImpl() const { return new (1) ResumeInst(*this); }
4340
4341CleanupReturnInst *CleanupReturnInst::cloneImpl() const {
4342 return new (getNumOperands()) CleanupReturnInst(*this);
4343}
4344
4345CatchReturnInst *CatchReturnInst::cloneImpl() const {
4346 return new (getNumOperands()) CatchReturnInst(*this);
4347}
4348
4349CatchSwitchInst *CatchSwitchInst::cloneImpl() const {
4350 return new CatchSwitchInst(*this);
4351}
4352
4353FuncletPadInst *FuncletPadInst::cloneImpl() const {
4354 return new (getNumOperands()) FuncletPadInst(*this);
4355}
4356
4357UnreachableInst *UnreachableInst::cloneImpl() const {
4358 LLVMContext &Context = getContext();
4359 return new UnreachableInst(Context);
4360}
4361
4362FreezeInst *FreezeInst::cloneImpl() const {
4363 return new FreezeInst(getOperand(0));
4364}