LLVM 22.0.0git
FunctionComparator.cpp
Go to the documentation of this file.
1//===- FunctionComparator.h - Function Comparator -------------------------===//
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 the FunctionComparator and GlobalNumberState classes
10// which are used by the MergeFunctions pass for comparing functions.
11//
12//===----------------------------------------------------------------------===//
13
15#include "llvm/ADT/APFloat.h"
16#include "llvm/ADT/APInt.h"
17#include "llvm/ADT/ArrayRef.h"
20#include "llvm/IR/Attributes.h"
21#include "llvm/IR/BasicBlock.h"
22#include "llvm/IR/Constant.h"
23#include "llvm/IR/Constants.h"
24#include "llvm/IR/DataLayout.h"
26#include "llvm/IR/Function.h"
27#include "llvm/IR/GlobalValue.h"
28#include "llvm/IR/InlineAsm.h"
29#include "llvm/IR/InstrTypes.h"
30#include "llvm/IR/Instruction.h"
32#include "llvm/IR/LLVMContext.h"
33#include "llvm/IR/Metadata.h"
34#include "llvm/IR/Module.h"
35#include "llvm/IR/Operator.h"
36#include "llvm/IR/Type.h"
37#include "llvm/IR/Value.h"
40#include "llvm/Support/Debug.h"
43#include <cassert>
44#include <cstddef>
45#include <cstdint>
46#include <utility>
47
48using namespace llvm;
49
50#define DEBUG_TYPE "functioncomparator"
51
53 if (L < R)
54 return -1;
55 if (L > R)
56 return 1;
57 return 0;
58}
59
61 if (L.value() < R.value())
62 return -1;
63 if (L.value() > R.value())
64 return 1;
65 return 0;
66}
67
68int FunctionComparator::cmpOrderings(AtomicOrdering L, AtomicOrdering R) const {
69 if ((int)L < (int)R)
70 return -1;
71 if ((int)L > (int)R)
72 return 1;
73 return 0;
74}
75
76int FunctionComparator::cmpAPInts(const APInt &L, const APInt &R) const {
77 if (int Res = cmpNumbers(L.getBitWidth(), R.getBitWidth()))
78 return Res;
79 if (L.ugt(R))
80 return 1;
81 if (R.ugt(L))
82 return -1;
83 return 0;
84}
85
87 const ConstantRange &R) const {
88 if (int Res = cmpAPInts(L.getLower(), R.getLower()))
89 return Res;
90 return cmpAPInts(L.getUpper(), R.getUpper());
91}
92
93int FunctionComparator::cmpAPFloats(const APFloat &L, const APFloat &R) const {
94 // Floats are ordered first by semantics (i.e. float, double, half, etc.),
95 // then by value interpreted as a bitstring (aka APInt).
96 const fltSemantics &SL = L.getSemantics(), &SR = R.getSemantics();
99 return Res;
102 return Res;
105 return Res;
108 return Res;
109 return cmpAPInts(L.bitcastToAPInt(), R.bitcastToAPInt());
110}
111
113 // Prevent heavy comparison, compare sizes first.
114 if (int Res = cmpNumbers(L.size(), R.size()))
115 return Res;
116
117 // Compare strings lexicographically only when it is necessary: only when
118 // strings are equal in size.
119 return std::clamp(L.compare(R), -1, 1);
120}
121
122int FunctionComparator::cmpAttrs(const AttributeList L,
123 const AttributeList R) const {
124 if (int Res = cmpNumbers(L.getNumAttrSets(), R.getNumAttrSets()))
125 return Res;
126
127 for (unsigned i : L.indexes()) {
128 AttributeSet LAS = L.getAttributes(i);
129 AttributeSet RAS = R.getAttributes(i);
130 AttributeSet::iterator LI = LAS.begin(), LE = LAS.end();
131 AttributeSet::iterator RI = RAS.begin(), RE = RAS.end();
132 for (; LI != LE && RI != RE; ++LI, ++RI) {
133 Attribute LA = *LI;
134 Attribute RA = *RI;
135 if (LA.isTypeAttribute() && RA.isTypeAttribute()) {
136 if (LA.getKindAsEnum() != RA.getKindAsEnum())
137 return cmpNumbers(LA.getKindAsEnum(), RA.getKindAsEnum());
138
139 Type *TyL = LA.getValueAsType();
140 Type *TyR = RA.getValueAsType();
141 if (TyL && TyR) {
142 if (int Res = cmpTypes(TyL, TyR))
143 return Res;
144 continue;
145 }
146
147 // Two pointers, at least one null, so the comparison result is
148 // independent of the value of a real pointer.
149 if (int Res = cmpNumbers((uint64_t)TyL, (uint64_t)TyR))
150 return Res;
151 continue;
152 } else if (LA.isConstantRangeAttribute() &&
153 RA.isConstantRangeAttribute()) {
154 if (LA.getKindAsEnum() != RA.getKindAsEnum())
155 return cmpNumbers(LA.getKindAsEnum(), RA.getKindAsEnum());
156
157 if (int Res = cmpConstantRanges(LA.getRange(), RA.getRange()))
158 return Res;
159 continue;
160 } else if (LA.isConstantRangeListAttribute() &&
161 RA.isConstantRangeListAttribute()) {
162 if (LA.getKindAsEnum() != RA.getKindAsEnum())
163 return cmpNumbers(LA.getKindAsEnum(), RA.getKindAsEnum());
164
166 ArrayRef<ConstantRange> CRR = RA.getValueAsConstantRangeList();
167 if (int Res = cmpNumbers(CRL.size(), CRR.size()))
168 return Res;
169
170 for (const auto &[L, R] : zip(CRL, CRR))
171 if (int Res = cmpConstantRanges(L, R))
172 return Res;
173 continue;
174 }
175 if (LA < RA)
176 return -1;
177 if (RA < LA)
178 return 1;
179 }
180 if (LI != LE)
181 return 1;
182 if (RI != RE)
183 return -1;
184 }
185 return 0;
186}
187
188int FunctionComparator::cmpMetadata(const Metadata *L,
189 const Metadata *R) const {
190 // TODO: the following routine coerce the metadata contents into constants
191 // or MDStrings before comparison.
192 // It ignores any other cases, so that the metadata nodes are considered
193 // equal even though this is not correct.
194 // We should structurally compare the metadata nodes to be perfect here.
195
196 auto *MDStringL = dyn_cast<MDString>(L);
197 auto *MDStringR = dyn_cast<MDString>(R);
198 if (MDStringL && MDStringR) {
199 if (MDStringL == MDStringR)
200 return 0;
201 return MDStringL->getString().compare(MDStringR->getString());
202 }
203 if (MDStringR)
204 return -1;
205 if (MDStringL)
206 return 1;
207
208 auto *CL = dyn_cast<ConstantAsMetadata>(L);
209 auto *CR = dyn_cast<ConstantAsMetadata>(R);
210 if (CL == CR)
211 return 0;
212 if (!CL)
213 return -1;
214 if (!CR)
215 return 1;
216 return cmpConstants(CL->getValue(), CR->getValue());
217}
218
219int FunctionComparator::cmpMDNode(const MDNode *L, const MDNode *R) const {
220 if (L == R)
221 return 0;
222 if (!L)
223 return -1;
224 if (!R)
225 return 1;
226 // TODO: Note that as this is metadata, it is possible to drop and/or merge
227 // this data when considering functions to merge. Thus this comparison would
228 // return 0 (i.e. equivalent), but merging would become more complicated
229 // because the ranges would need to be unioned. It is not likely that
230 // functions differ ONLY in this metadata if they are actually the same
231 // function semantically.
232 if (int Res = cmpNumbers(L->getNumOperands(), R->getNumOperands()))
233 return Res;
234 for (size_t I = 0; I < L->getNumOperands(); ++I)
235 if (int Res = cmpMetadata(L->getOperand(I), R->getOperand(I)))
236 return Res;
237 return 0;
238}
239
240int FunctionComparator::cmpInstMetadata(Instruction const *L,
241 Instruction const *R) const {
242 /// These metadata affects the other optimization passes by making assertions
243 /// or constraints.
244 /// Values that carry different expectations should be considered different.
246 L->getAllMetadataOtherThanDebugLoc(MDL);
247 R->getAllMetadataOtherThanDebugLoc(MDR);
248 if (MDL.size() > MDR.size())
249 return 1;
250 else if (MDL.size() < MDR.size())
251 return -1;
252 for (size_t I = 0, N = MDL.size(); I < N; ++I) {
253 auto const [KeyL, ML] = MDL[I];
254 auto const [KeyR, MR] = MDR[I];
255 if (int Res = cmpNumbers(KeyL, KeyR))
256 return Res;
257 if (int Res = cmpMDNode(ML, MR))
258 return Res;
259 }
260 return 0;
261}
262
263int FunctionComparator::cmpOperandBundlesSchema(const CallBase &LCS,
264 const CallBase &RCS) const {
265 assert(LCS.getOpcode() == RCS.getOpcode() && "Can't compare otherwise!");
266
267 if (int Res =
269 return Res;
270
271 for (unsigned I = 0, E = LCS.getNumOperandBundles(); I != E; ++I) {
272 auto OBL = LCS.getOperandBundleAt(I);
273 auto OBR = RCS.getOperandBundleAt(I);
274
275 if (int Res = OBL.getTagName().compare(OBR.getTagName()))
276 return Res;
277
278 if (int Res = cmpNumbers(OBL.Inputs.size(), OBR.Inputs.size()))
279 return Res;
280 }
281
282 return 0;
283}
284
285/// Constants comparison:
286/// 1. Check whether type of L constant could be losslessly bitcasted to R
287/// type.
288/// 2. Compare constant contents.
289/// For more details see declaration comments.
291 const Constant *R) const {
292 Type *TyL = L->getType();
293 Type *TyR = R->getType();
294
295 // Check whether types are bitcastable. This part is just re-factored
296 // Type::canLosslesslyBitCastTo method, but instead of returning true/false,
297 // we also pack into result which type is "less" for us.
298 int TypesRes = cmpTypes(TyL, TyR);
299 if (TypesRes != 0) {
300 // Types are different, but check whether we can bitcast them.
301 if (!TyL->isFirstClassType()) {
302 if (TyR->isFirstClassType())
303 return -1;
304 // Neither TyL nor TyR are values of first class type. Return the result
305 // of comparing the types
306 return TypesRes;
307 }
308 if (!TyR->isFirstClassType()) {
309 if (TyL->isFirstClassType())
310 return 1;
311 return TypesRes;
312 }
313
314 // Vector -> Vector conversions are always lossless if the two vector types
315 // have the same size, otherwise not.
316 unsigned TyLWidth = 0;
317 unsigned TyRWidth = 0;
318
319 if (auto *VecTyL = dyn_cast<VectorType>(TyL))
320 TyLWidth = VecTyL->getPrimitiveSizeInBits().getFixedValue();
321 if (auto *VecTyR = dyn_cast<VectorType>(TyR))
322 TyRWidth = VecTyR->getPrimitiveSizeInBits().getFixedValue();
323
324 if (TyLWidth != TyRWidth)
325 return cmpNumbers(TyLWidth, TyRWidth);
326
327 // Zero bit-width means neither TyL nor TyR are vectors.
328 if (!TyLWidth) {
331 if (PTyL && PTyR) {
332 unsigned AddrSpaceL = PTyL->getAddressSpace();
333 unsigned AddrSpaceR = PTyR->getAddressSpace();
334 if (int Res = cmpNumbers(AddrSpaceL, AddrSpaceR))
335 return Res;
336 }
337 if (PTyL)
338 return 1;
339 if (PTyR)
340 return -1;
341
342 // TyL and TyR aren't vectors, nor pointers. We don't know how to
343 // bitcast them.
344 return TypesRes;
345 }
346 }
347
348 // OK, types are bitcastable, now check constant contents.
349
350 if (L->isNullValue() && R->isNullValue())
351 return TypesRes;
352 if (L->isNullValue() && !R->isNullValue())
353 return 1;
354 if (!L->isNullValue() && R->isNullValue())
355 return -1;
356
357 auto GlobalValueL = const_cast<GlobalValue *>(dyn_cast<GlobalValue>(L));
358 auto GlobalValueR = const_cast<GlobalValue *>(dyn_cast<GlobalValue>(R));
359 if (GlobalValueL && GlobalValueR) {
360 return cmpGlobalValues(GlobalValueL, GlobalValueR);
361 }
362
363 if (int Res = cmpNumbers(L->getValueID(), R->getValueID()))
364 return Res;
365
366 if (const auto *SeqL = dyn_cast<ConstantDataSequential>(L)) {
367 const auto *SeqR = cast<ConstantDataSequential>(R);
368 // This handles ConstantDataArray and ConstantDataVector. Note that we
369 // compare the two raw data arrays, which might differ depending on the host
370 // endianness. This isn't a problem though, because the endiness of a module
371 // will affect the order of the constants, but this order is the same
372 // for a given input module and host platform.
373 return cmpMem(SeqL->getRawDataValues(), SeqR->getRawDataValues());
374 }
375
376 switch (L->getValueID()) {
377 case Value::UndefValueVal:
378 case Value::PoisonValueVal:
379 case Value::ConstantTokenNoneVal:
380 return TypesRes;
381 case Value::ConstantIntVal: {
382 const APInt &LInt = cast<ConstantInt>(L)->getValue();
383 const APInt &RInt = cast<ConstantInt>(R)->getValue();
384 return cmpAPInts(LInt, RInt);
385 }
386 case Value::ConstantFPVal: {
387 const APFloat &LAPF = cast<ConstantFP>(L)->getValueAPF();
388 const APFloat &RAPF = cast<ConstantFP>(R)->getValueAPF();
389 return cmpAPFloats(LAPF, RAPF);
390 }
391 case Value::ConstantArrayVal: {
392 const ConstantArray *LA = cast<ConstantArray>(L);
394 uint64_t NumElementsL = cast<ArrayType>(TyL)->getNumElements();
395 uint64_t NumElementsR = cast<ArrayType>(TyR)->getNumElements();
396 if (int Res = cmpNumbers(NumElementsL, NumElementsR))
397 return Res;
398 for (uint64_t i = 0; i < NumElementsL; ++i) {
399 if (int Res = cmpConstants(cast<Constant>(LA->getOperand(i)),
400 cast<Constant>(RA->getOperand(i))))
401 return Res;
402 }
403 return 0;
404 }
405 case Value::ConstantStructVal: {
408 unsigned NumElementsL = cast<StructType>(TyL)->getNumElements();
409 unsigned NumElementsR = cast<StructType>(TyR)->getNumElements();
410 if (int Res = cmpNumbers(NumElementsL, NumElementsR))
411 return Res;
412 for (unsigned i = 0; i != NumElementsL; ++i) {
413 if (int Res = cmpConstants(cast<Constant>(LS->getOperand(i)),
414 cast<Constant>(RS->getOperand(i))))
415 return Res;
416 }
417 return 0;
418 }
419 case Value::ConstantVectorVal: {
422 unsigned NumElementsL = cast<FixedVectorType>(TyL)->getNumElements();
423 unsigned NumElementsR = cast<FixedVectorType>(TyR)->getNumElements();
424 if (int Res = cmpNumbers(NumElementsL, NumElementsR))
425 return Res;
426 for (uint64_t i = 0; i < NumElementsL; ++i) {
427 if (int Res = cmpConstants(cast<Constant>(LV->getOperand(i)),
428 cast<Constant>(RV->getOperand(i))))
429 return Res;
430 }
431 return 0;
432 }
433 case Value::ConstantExprVal: {
434 const ConstantExpr *LE = cast<ConstantExpr>(L);
435 const ConstantExpr *RE = cast<ConstantExpr>(R);
436 if (int Res = cmpNumbers(LE->getOpcode(), RE->getOpcode()))
437 return Res;
438 unsigned NumOperandsL = LE->getNumOperands();
439 unsigned NumOperandsR = RE->getNumOperands();
440 if (int Res = cmpNumbers(NumOperandsL, NumOperandsR))
441 return Res;
442 for (unsigned i = 0; i < NumOperandsL; ++i) {
443 if (int Res = cmpConstants(cast<Constant>(LE->getOperand(i)),
444 cast<Constant>(RE->getOperand(i))))
445 return Res;
446 }
447 if (auto *GEPL = dyn_cast<GEPOperator>(LE)) {
448 auto *GEPR = cast<GEPOperator>(RE);
449 if (int Res = cmpTypes(GEPL->getSourceElementType(),
450 GEPR->getSourceElementType()))
451 return Res;
452 if (int Res = cmpNumbers(GEPL->getNoWrapFlags().getRaw(),
453 GEPR->getNoWrapFlags().getRaw()))
454 return Res;
455
456 std::optional<ConstantRange> InRangeL = GEPL->getInRange();
457 std::optional<ConstantRange> InRangeR = GEPR->getInRange();
458 if (InRangeL) {
459 if (!InRangeR)
460 return 1;
461 if (int Res = cmpConstantRanges(*InRangeL, *InRangeR))
462 return Res;
463 } else if (InRangeR) {
464 return -1;
465 }
466 }
468 auto *OBOR = cast<OverflowingBinaryOperator>(RE);
469 if (int Res =
470 cmpNumbers(OBOL->hasNoUnsignedWrap(), OBOR->hasNoUnsignedWrap()))
471 return Res;
472 if (int Res =
473 cmpNumbers(OBOL->hasNoSignedWrap(), OBOR->hasNoSignedWrap()))
474 return Res;
475 }
476 return 0;
477 }
478 case Value::BlockAddressVal: {
479 const BlockAddress *LBA = cast<BlockAddress>(L);
480 const BlockAddress *RBA = cast<BlockAddress>(R);
481 if (int Res = cmpValues(LBA->getFunction(), RBA->getFunction()))
482 return Res;
483 if (LBA->getFunction() == RBA->getFunction()) {
484 // They are BBs in the same function. Order by which comes first in the
485 // BB order of the function. This order is deterministic.
486 Function *F = LBA->getFunction();
487 BasicBlock *LBB = LBA->getBasicBlock();
488 BasicBlock *RBB = RBA->getBasicBlock();
489 if (LBB == RBB)
490 return 0;
491 for (BasicBlock &BB : *F) {
492 if (&BB == LBB) {
493 assert(&BB != RBB);
494 return -1;
495 }
496 if (&BB == RBB)
497 return 1;
498 }
499 llvm_unreachable("Basic Block Address does not point to a basic block in "
500 "its function.");
501 return -1;
502 } else {
503 // cmpValues said the functions are the same. So because they aren't
504 // literally the same pointer, they must respectively be the left and
505 // right functions.
506 assert(LBA->getFunction() == FnL && RBA->getFunction() == FnR);
507 // cmpValues will tell us if these are equivalent BasicBlocks, in the
508 // context of their respective functions.
509 return cmpValues(LBA->getBasicBlock(), RBA->getBasicBlock());
510 }
511 }
512 case Value::DSOLocalEquivalentVal: {
513 // dso_local_equivalent is functionally equivalent to whatever it points to.
514 // This means the behavior of the IR should be the exact same as if the
515 // function was referenced directly rather than through a
516 // dso_local_equivalent.
517 const auto *LEquiv = cast<DSOLocalEquivalent>(L);
518 const auto *REquiv = cast<DSOLocalEquivalent>(R);
519 return cmpGlobalValues(LEquiv->getGlobalValue(), REquiv->getGlobalValue());
520 }
521 case Value::ConstantPtrAuthVal: {
522 // Handle authenticated pointer constants produced by ConstantPtrAuth::get.
525 if (int Res = cmpConstants(LPA->getPointer(), RPA->getPointer()))
526 return Res;
527 if (int Res = cmpConstants(LPA->getKey(), RPA->getKey()))
528 return Res;
529 if (int Res =
531 return Res;
533 RPA->getAddrDiscriminator());
534 }
535 default: // Unknown constant, abort.
536 LLVM_DEBUG(dbgs() << "Looking at valueID " << L->getValueID() << "\n");
537 llvm_unreachable("Constant ValueID not recognized.");
538 return -1;
539 }
540}
541
543 uint64_t LNumber = GlobalNumbers->getNumber(L);
544 uint64_t RNumber = GlobalNumbers->getNumber(R);
545 return cmpNumbers(LNumber, RNumber);
546}
547
548/// cmpType - compares two types,
549/// defines total ordering among the types set.
550/// See method declaration comments for more details.
554
555 const DataLayout &DL = FnL->getDataLayout();
556 if (PTyL && PTyL->getAddressSpace() == 0)
557 TyL = DL.getIntPtrType(TyL);
558 if (PTyR && PTyR->getAddressSpace() == 0)
559 TyR = DL.getIntPtrType(TyR);
560
561 if (TyL == TyR)
562 return 0;
563
564 if (int Res = cmpNumbers(TyL->getTypeID(), TyR->getTypeID()))
565 return Res;
566
567 switch (TyL->getTypeID()) {
568 default:
569 llvm_unreachable("Unknown type!");
573 // TyL == TyR would have returned true earlier, because types are uniqued.
574 case Type::VoidTyID:
575 case Type::FloatTyID:
576 case Type::DoubleTyID:
578 case Type::FP128TyID:
580 case Type::LabelTyID:
582 case Type::TokenTyID:
583 return 0;
584
586 assert(PTyL && PTyR && "Both types must be pointers here.");
587 return cmpNumbers(PTyL->getAddressSpace(), PTyR->getAddressSpace());
588
589 case Type::StructTyID: {
590 StructType *STyL = cast<StructType>(TyL);
591 StructType *STyR = cast<StructType>(TyR);
592 if (STyL->getNumElements() != STyR->getNumElements())
593 return cmpNumbers(STyL->getNumElements(), STyR->getNumElements());
594
595 if (STyL->isPacked() != STyR->isPacked())
596 return cmpNumbers(STyL->isPacked(), STyR->isPacked());
597
598 for (unsigned i = 0, e = STyL->getNumElements(); i != e; ++i) {
599 if (int Res = cmpTypes(STyL->getElementType(i), STyR->getElementType(i)))
600 return Res;
601 }
602 return 0;
603 }
604
605 case Type::FunctionTyID: {
606 FunctionType *FTyL = cast<FunctionType>(TyL);
607 FunctionType *FTyR = cast<FunctionType>(TyR);
608 if (FTyL->getNumParams() != FTyR->getNumParams())
609 return cmpNumbers(FTyL->getNumParams(), FTyR->getNumParams());
610
611 if (FTyL->isVarArg() != FTyR->isVarArg())
612 return cmpNumbers(FTyL->isVarArg(), FTyR->isVarArg());
613
614 if (int Res = cmpTypes(FTyL->getReturnType(), FTyR->getReturnType()))
615 return Res;
616
617 for (unsigned i = 0, e = FTyL->getNumParams(); i != e; ++i) {
618 if (int Res = cmpTypes(FTyL->getParamType(i), FTyR->getParamType(i)))
619 return Res;
620 }
621 return 0;
622 }
623
624 case Type::ArrayTyID: {
625 auto *STyL = cast<ArrayType>(TyL);
626 auto *STyR = cast<ArrayType>(TyR);
627 if (STyL->getNumElements() != STyR->getNumElements())
628 return cmpNumbers(STyL->getNumElements(), STyR->getNumElements());
629 return cmpTypes(STyL->getElementType(), STyR->getElementType());
630 }
633 auto *STyL = cast<VectorType>(TyL);
634 auto *STyR = cast<VectorType>(TyR);
635 if (STyL->getElementCount().isScalable() !=
636 STyR->getElementCount().isScalable())
637 return cmpNumbers(STyL->getElementCount().isScalable(),
638 STyR->getElementCount().isScalable());
639 if (STyL->getElementCount() != STyR->getElementCount())
640 return cmpNumbers(STyL->getElementCount().getKnownMinValue(),
641 STyR->getElementCount().getKnownMinValue());
642 return cmpTypes(STyL->getElementType(), STyR->getElementType());
643 }
644 }
645}
646
647// Determine whether the two operations are the same except that pointer-to-A
648// and pointer-to-B are equivalent. This should be kept in sync with
649// Instruction::isSameOperationAs.
650// Read method declaration comments for more details.
652 const Instruction *R,
653 bool &needToCmpOperands) const {
654 needToCmpOperands = true;
655 if (int Res = cmpValues(L, R))
656 return Res;
657
658 // Differences from Instruction::isSameOperationAs:
659 // * replace type comparison with calls to cmpTypes.
660 // * we test for I->getRawSubclassOptionalData (nuw/nsw/tail) at the top.
661 // * because of the above, we don't test for the tail bit on calls later on.
662 if (int Res = cmpNumbers(L->getOpcode(), R->getOpcode()))
663 return Res;
664
665 if (const GetElementPtrInst *GEPL = dyn_cast<GetElementPtrInst>(L)) {
666 needToCmpOperands = false;
668 if (int Res =
669 cmpValues(GEPL->getPointerOperand(), GEPR->getPointerOperand()))
670 return Res;
671 return cmpGEPs(GEPL, GEPR);
672 }
673
674 if (int Res = cmpNumbers(L->getNumOperands(), R->getNumOperands()))
675 return Res;
676
677 if (int Res = cmpTypes(L->getType(), R->getType()))
678 return Res;
679
680 if (int Res = cmpNumbers(L->getRawSubclassOptionalData(),
681 R->getRawSubclassOptionalData()))
682 return Res;
683
684 // We have two instructions of identical opcode and #operands. Check to see
685 // if all operands are the same type
686 for (unsigned i = 0, e = L->getNumOperands(); i != e; ++i) {
687 if (int Res =
688 cmpTypes(L->getOperand(i)->getType(), R->getOperand(i)->getType()))
689 return Res;
690 }
691
692 // Check special state that is a part of some instructions.
693 if (const AllocaInst *AI = dyn_cast<AllocaInst>(L)) {
694 if (int Res = cmpTypes(AI->getAllocatedType(),
695 cast<AllocaInst>(R)->getAllocatedType()))
696 return Res;
697 return cmpAligns(AI->getAlign(), cast<AllocaInst>(R)->getAlign());
698 }
699 if (const LoadInst *LI = dyn_cast<LoadInst>(L)) {
700 if (int Res = cmpNumbers(LI->isVolatile(), cast<LoadInst>(R)->isVolatile()))
701 return Res;
702 if (int Res = cmpAligns(LI->getAlign(), cast<LoadInst>(R)->getAlign()))
703 return Res;
704 if (int Res =
705 cmpOrderings(LI->getOrdering(), cast<LoadInst>(R)->getOrdering()))
706 return Res;
707 if (int Res = cmpNumbers(LI->getSyncScopeID(),
708 cast<LoadInst>(R)->getSyncScopeID()))
709 return Res;
710 return cmpInstMetadata(L, R);
711 }
712 if (const StoreInst *SI = dyn_cast<StoreInst>(L)) {
713 if (int Res =
714 cmpNumbers(SI->isVolatile(), cast<StoreInst>(R)->isVolatile()))
715 return Res;
716 if (int Res = cmpAligns(SI->getAlign(), cast<StoreInst>(R)->getAlign()))
717 return Res;
718 if (int Res =
719 cmpOrderings(SI->getOrdering(), cast<StoreInst>(R)->getOrdering()))
720 return Res;
721 return cmpNumbers(SI->getSyncScopeID(),
722 cast<StoreInst>(R)->getSyncScopeID());
723 }
724 if (const CmpInst *CI = dyn_cast<CmpInst>(L))
725 return cmpNumbers(CI->getPredicate(), cast<CmpInst>(R)->getPredicate());
726 if (auto *CBL = dyn_cast<CallBase>(L)) {
727 auto *CBR = cast<CallBase>(R);
728 if (int Res = cmpNumbers(CBL->getCallingConv(), CBR->getCallingConv()))
729 return Res;
730 if (int Res = cmpAttrs(CBL->getAttributes(), CBR->getAttributes()))
731 return Res;
732 if (int Res = cmpOperandBundlesSchema(*CBL, *CBR))
733 return Res;
734 if (const CallInst *CI = dyn_cast<CallInst>(L))
735 if (int Res = cmpNumbers(CI->getTailCallKind(),
736 cast<CallInst>(R)->getTailCallKind()))
737 return Res;
738 return cmpMDNode(L->getMetadata(LLVMContext::MD_range),
739 R->getMetadata(LLVMContext::MD_range));
740 }
741 if (const SwitchInst *SI = dyn_cast<SwitchInst>(L)) {
742 for (auto [LCase, RCase] : zip(SI->cases(), cast<SwitchInst>(R)->cases()))
743 if (int Res = cmpConstants(LCase.getCaseValue(), RCase.getCaseValue()))
744 return Res;
745 return 0;
746 }
747 if (const InsertValueInst *IVI = dyn_cast<InsertValueInst>(L)) {
748 ArrayRef<unsigned> LIndices = IVI->getIndices();
749 ArrayRef<unsigned> RIndices = cast<InsertValueInst>(R)->getIndices();
750 if (int Res = cmpNumbers(LIndices.size(), RIndices.size()))
751 return Res;
752 for (size_t i = 0, e = LIndices.size(); i != e; ++i) {
753 if (int Res = cmpNumbers(LIndices[i], RIndices[i]))
754 return Res;
755 }
756 return 0;
757 }
758 if (const ExtractValueInst *EVI = dyn_cast<ExtractValueInst>(L)) {
759 ArrayRef<unsigned> LIndices = EVI->getIndices();
760 ArrayRef<unsigned> RIndices = cast<ExtractValueInst>(R)->getIndices();
761 if (int Res = cmpNumbers(LIndices.size(), RIndices.size()))
762 return Res;
763 for (size_t i = 0, e = LIndices.size(); i != e; ++i) {
764 if (int Res = cmpNumbers(LIndices[i], RIndices[i]))
765 return Res;
766 }
767 }
768 if (const FenceInst *FI = dyn_cast<FenceInst>(L)) {
769 if (int Res =
770 cmpOrderings(FI->getOrdering(), cast<FenceInst>(R)->getOrdering()))
771 return Res;
772 return cmpNumbers(FI->getSyncScopeID(),
773 cast<FenceInst>(R)->getSyncScopeID());
774 }
776 if (int Res = cmpNumbers(CXI->isVolatile(),
777 cast<AtomicCmpXchgInst>(R)->isVolatile()))
778 return Res;
779 if (int Res =
780 cmpNumbers(CXI->isWeak(), cast<AtomicCmpXchgInst>(R)->isWeak()))
781 return Res;
782 if (int Res =
783 cmpOrderings(CXI->getSuccessOrdering(),
784 cast<AtomicCmpXchgInst>(R)->getSuccessOrdering()))
785 return Res;
786 if (int Res =
787 cmpOrderings(CXI->getFailureOrdering(),
788 cast<AtomicCmpXchgInst>(R)->getFailureOrdering()))
789 return Res;
790 return cmpNumbers(CXI->getSyncScopeID(),
791 cast<AtomicCmpXchgInst>(R)->getSyncScopeID());
792 }
793 if (const AtomicRMWInst *RMWI = dyn_cast<AtomicRMWInst>(L)) {
794 if (int Res = cmpNumbers(RMWI->getOperation(),
795 cast<AtomicRMWInst>(R)->getOperation()))
796 return Res;
797 if (int Res = cmpNumbers(RMWI->isVolatile(),
798 cast<AtomicRMWInst>(R)->isVolatile()))
799 return Res;
800 if (int Res = cmpOrderings(RMWI->getOrdering(),
801 cast<AtomicRMWInst>(R)->getOrdering()))
802 return Res;
803 return cmpNumbers(RMWI->getSyncScopeID(),
804 cast<AtomicRMWInst>(R)->getSyncScopeID());
805 }
807 ArrayRef<int> LMask = SVI->getShuffleMask();
808 ArrayRef<int> RMask = cast<ShuffleVectorInst>(R)->getShuffleMask();
809 if (int Res = cmpNumbers(LMask.size(), RMask.size()))
810 return Res;
811 for (size_t i = 0, e = LMask.size(); i != e; ++i) {
812 if (int Res = cmpNumbers(LMask[i], RMask[i]))
813 return Res;
814 }
815 }
816 if (const PHINode *PNL = dyn_cast<PHINode>(L)) {
817 const PHINode *PNR = cast<PHINode>(R);
818 // Ensure that in addition to the incoming values being identical
819 // (checked by the caller of this function), the incoming blocks
820 // are also identical.
821 for (unsigned i = 0, e = PNL->getNumIncomingValues(); i != e; ++i) {
822 if (int Res =
823 cmpValues(PNL->getIncomingBlock(i), PNR->getIncomingBlock(i)))
824 return Res;
825 }
826 }
827 return 0;
828}
829
830// Determine whether two GEP operations perform the same underlying arithmetic.
831// Read method declaration comments for more details.
832int FunctionComparator::cmpGEPs(const GEPOperator *GEPL,
833 const GEPOperator *GEPR) const {
834 unsigned int ASL = GEPL->getPointerAddressSpace();
835 unsigned int ASR = GEPR->getPointerAddressSpace();
836
837 if (int Res = cmpNumbers(ASL, ASR))
838 return Res;
839
840 // When we have target data, we can reduce the GEP down to the value in bytes
841 // added to the address.
842 const DataLayout &DL = FnL->getDataLayout();
843 unsigned OffsetBitWidth = DL.getIndexSizeInBits(ASL);
844 APInt OffsetL(OffsetBitWidth, 0), OffsetR(OffsetBitWidth, 0);
845 if (GEPL->accumulateConstantOffset(DL, OffsetL) &&
846 GEPR->accumulateConstantOffset(DL, OffsetR))
847 return cmpAPInts(OffsetL, OffsetR);
848 if (int Res =
850 return Res;
851
852 if (int Res = cmpNumbers(GEPL->getNumOperands(), GEPR->getNumOperands()))
853 return Res;
854
855 for (unsigned i = 0, e = GEPL->getNumOperands(); i != e; ++i) {
856 if (int Res = cmpValues(GEPL->getOperand(i), GEPR->getOperand(i)))
857 return Res;
858 }
859
860 return 0;
861}
862
863int FunctionComparator::cmpInlineAsm(const InlineAsm *L,
864 const InlineAsm *R) const {
865 // InlineAsm's are uniqued. If they are the same pointer, obviously they are
866 // the same, otherwise compare the fields.
867 if (L == R)
868 return 0;
869 if (int Res = cmpTypes(L->getFunctionType(), R->getFunctionType()))
870 return Res;
871 if (int Res = cmpMem(L->getAsmString(), R->getAsmString()))
872 return Res;
873 if (int Res = cmpMem(L->getConstraintString(), R->getConstraintString()))
874 return Res;
875 if (int Res = cmpNumbers(L->hasSideEffects(), R->hasSideEffects()))
876 return Res;
877 if (int Res = cmpNumbers(L->isAlignStack(), R->isAlignStack()))
878 return Res;
879 if (int Res = cmpNumbers(L->getDialect(), R->getDialect()))
880 return Res;
881 assert(L->getFunctionType() != R->getFunctionType());
882 return 0;
883}
884
885/// Compare two values used by the two functions under pair-wise comparison. If
886/// this is the first time the values are seen, they're added to the mapping so
887/// that we will detect mismatches on next use.
888/// See comments in declaration for more details.
889int FunctionComparator::cmpValues(const Value *L, const Value *R) const {
890 // Catch self-reference case.
891 if (L == FnL) {
892 if (R == FnR)
893 return 0;
894 return -1;
895 }
896 if (R == FnR) {
897 if (L == FnL)
898 return 0;
899 return 1;
900 }
901
902 const Constant *ConstL = dyn_cast<Constant>(L);
903 const Constant *ConstR = dyn_cast<Constant>(R);
904 if (ConstL && ConstR) {
905 if (L == R)
906 return 0;
907 return cmpConstants(ConstL, ConstR);
908 }
909
910 if (ConstL)
911 return 1;
912 if (ConstR)
913 return -1;
914
915 const MetadataAsValue *MetadataValueL = dyn_cast<MetadataAsValue>(L);
916 const MetadataAsValue *MetadataValueR = dyn_cast<MetadataAsValue>(R);
917 if (MetadataValueL && MetadataValueR) {
918 if (MetadataValueL == MetadataValueR)
919 return 0;
920
921 return cmpMetadata(MetadataValueL->getMetadata(),
922 MetadataValueR->getMetadata());
923 }
924
925 if (MetadataValueL)
926 return 1;
927 if (MetadataValueR)
928 return -1;
929
930 const InlineAsm *InlineAsmL = dyn_cast<InlineAsm>(L);
931 const InlineAsm *InlineAsmR = dyn_cast<InlineAsm>(R);
932
933 if (InlineAsmL && InlineAsmR)
934 return cmpInlineAsm(InlineAsmL, InlineAsmR);
935 if (InlineAsmL)
936 return 1;
937 if (InlineAsmR)
938 return -1;
939
940 auto LeftSN = sn_mapL.insert(std::make_pair(L, sn_mapL.size())),
941 RightSN = sn_mapR.insert(std::make_pair(R, sn_mapR.size()));
942
943 return cmpNumbers(LeftSN.first->second, RightSN.first->second);
944}
945
946// Test whether two basic blocks have equivalent behaviour.
948 const BasicBlock *BBR) const {
949 BasicBlock::const_iterator InstL = BBL->begin(), InstLE = BBL->end();
950 BasicBlock::const_iterator InstR = BBR->begin(), InstRE = BBR->end();
951
952 do {
953 bool needToCmpOperands = true;
954 if (int Res = cmpOperations(&*InstL, &*InstR, needToCmpOperands))
955 return Res;
956 if (needToCmpOperands) {
957 assert(InstL->getNumOperands() == InstR->getNumOperands());
958
959 for (unsigned i = 0, e = InstL->getNumOperands(); i != e; ++i) {
960 Value *OpL = InstL->getOperand(i);
961 Value *OpR = InstR->getOperand(i);
962 if (int Res = cmpValues(OpL, OpR))
963 return Res;
964 // cmpValues should ensure this is true.
965 assert(cmpTypes(OpL->getType(), OpR->getType()) == 0);
966 }
967 }
968
969 ++InstL;
970 ++InstR;
971 } while (InstL != InstLE && InstR != InstRE);
972
973 if (InstL != InstLE && InstR == InstRE)
974 return 1;
975 if (InstL == InstLE && InstR != InstRE)
976 return -1;
977 return 0;
978}
979
981 if (int Res = cmpAttrs(FnL->getAttributes(), FnR->getAttributes()))
982 return Res;
983
984 if (int Res = cmpNumbers(FnL->hasGC(), FnR->hasGC()))
985 return Res;
986
987 if (FnL->hasGC()) {
988 if (int Res = cmpMem(FnL->getGC(), FnR->getGC()))
989 return Res;
990 }
991
992 if (int Res = cmpNumbers(FnL->hasSection(), FnR->hasSection()))
993 return Res;
994
995 if (FnL->hasSection()) {
996 if (int Res = cmpMem(FnL->getSection(), FnR->getSection()))
997 return Res;
998 }
999
1000 if (int Res = cmpNumbers(FnL->isVarArg(), FnR->isVarArg()))
1001 return Res;
1002
1003 // TODO: if it's internal and only used in direct calls, we could handle this
1004 // case too.
1005 if (int Res = cmpNumbers(FnL->getCallingConv(), FnR->getCallingConv()))
1006 return Res;
1007
1008 if (int Res = cmpTypes(FnL->getFunctionType(), FnR->getFunctionType()))
1009 return Res;
1010
1011 assert(FnL->arg_size() == FnR->arg_size() &&
1012 "Identically typed functions have different numbers of args!");
1013
1014 // Visit the arguments so that they get enumerated in the order they're
1015 // passed in.
1016 for (Function::const_arg_iterator ArgLI = FnL->arg_begin(),
1017 ArgRI = FnR->arg_begin(),
1018 ArgLE = FnL->arg_end();
1019 ArgLI != ArgLE; ++ArgLI, ++ArgRI) {
1020 if (cmpValues(&*ArgLI, &*ArgRI) != 0)
1021 llvm_unreachable("Arguments repeat!");
1022 }
1023 return 0;
1024}
1025
1026// Test whether the two functions have equivalent behaviour.
1028 beginCompare();
1029
1030 if (int Res = compareSignature())
1031 return Res;
1032
1033 // We do a CFG-ordered walk since the actual ordering of the blocks in the
1034 // linked list is immaterial. Our walk starts at the entry block for both
1035 // functions, then takes each block from each terminator in order. As an
1036 // artifact, this also means that unreachable blocks are ignored.
1038 SmallPtrSet<const BasicBlock *, 32> VisitedBBs; // in terms of F1.
1039
1040 FnLBBs.push_back(&FnL->getEntryBlock());
1041 FnRBBs.push_back(&FnR->getEntryBlock());
1042
1043 VisitedBBs.insert(FnLBBs[0]);
1044 while (!FnLBBs.empty()) {
1045 const BasicBlock *BBL = FnLBBs.pop_back_val();
1046 const BasicBlock *BBR = FnRBBs.pop_back_val();
1047
1048 if (int Res = cmpValues(BBL, BBR))
1049 return Res;
1050
1051 if (int Res = cmpBasicBlocks(BBL, BBR))
1052 return Res;
1053
1054 const Instruction *TermL = BBL->getTerminator();
1055 const Instruction *TermR = BBR->getTerminator();
1056
1057 assert(TermL->getNumSuccessors() == TermR->getNumSuccessors());
1058 for (unsigned i = 0, e = TermL->getNumSuccessors(); i != e; ++i) {
1059 if (!VisitedBBs.insert(TermL->getSuccessor(i)).second)
1060 continue;
1061
1062 FnLBBs.push_back(TermL->getSuccessor(i));
1063 FnRBBs.push_back(TermR->getSuccessor(i));
1064 }
1065 }
1066 return 0;
1067}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file declares a class to represent arbitrary precision floating point values and provide a varie...
This file implements a class to represent arbitrary precision integral constant values and operations...
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
This file contains the simple types necessary to represent the attributes associated with functions a...
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Module.h This file contains the declarations for the Module class.
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
This file contains the declarations for metadata subclasses.
SI optimize exec mask operations pre RA
This file defines the SmallPtrSet class.
This file defines the SmallVector class.
#define LLVM_DEBUG(...)
Definition Debug.h:114
static unsigned getBitWidth(Type *Ty, const DataLayout &DL)
Returns the bitwidth of the given scalar or pointer type.
static LLVM_ABI ExponentType semanticsMinExponent(const fltSemantics &)
Definition APFloat.cpp:298
static LLVM_ABI unsigned int semanticsSizeInBits(const fltSemantics &)
Definition APFloat.cpp:301
static LLVM_ABI ExponentType semanticsMaxExponent(const fltSemantics &)
Definition APFloat.cpp:294
static LLVM_ABI unsigned int semanticsPrecision(const fltSemantics &)
Definition APFloat.cpp:290
Class for arbitrary precision integers.
Definition APInt.h:78
an instruction to allocate memory on the stack
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
size_t size() const
size - Get the array size.
Definition ArrayRef.h:142
An instruction that atomically checks whether a specified value is in a memory location,...
an instruction that atomically reads a memory location, combines it with another value,...
This class holds the attributes for a particular argument, parameter, function, or return value.
Definition Attributes.h:361
const Attribute * iterator
Definition Attributes.h:469
LLVM_ABI iterator begin() const
LLVM_ABI iterator end() const
Functions, function parameters, and return types can have attributes to indicate how they should be t...
Definition Attributes.h:69
LLVM_ABI const ConstantRange & getRange() const
Returns the value of the range attribute.
LLVM_ABI bool isConstantRangeAttribute() const
Return true if the attribute is a ConstantRange attribute.
LLVM_ABI Attribute::AttrKind getKindAsEnum() const
Return the attribute's kind as an enum (Attribute::AttrKind).
LLVM_ABI ArrayRef< ConstantRange > getValueAsConstantRangeList() const
Return the attribute's value as a ConstantRange array.
LLVM_ABI bool isTypeAttribute() const
Return true if the attribute is a type attribute.
LLVM_ABI bool isConstantRangeListAttribute() const
Return true if the attribute is a ConstantRangeList attribute.
LLVM_ABI Type * getValueAsType() const
Return the attribute's value as a Type.
LLVM Basic Block Representation.
Definition BasicBlock.h:62
iterator end()
Definition BasicBlock.h:472
iterator begin()
Instruction iterator methods.
Definition BasicBlock.h:459
InstListType::const_iterator const_iterator
Definition BasicBlock.h:171
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
Definition BasicBlock.h:233
The address of a basic block.
Definition Constants.h:907
Function * getFunction() const
Definition Constants.h:943
BasicBlock * getBasicBlock() const
Definition Constants.h:942
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
OperandBundleUse getOperandBundleAt(unsigned Index) const
Return the operand bundle at a specific index.
unsigned getNumOperandBundles() const
Return the number of operand bundles associated with this User.
This class represents a function call, abstracting a target machine's calling convention.
This class is the base class for the comparison instructions.
Definition InstrTypes.h:664
ConstantArray - Constant Array Declarations.
Definition Constants.h:441
A constant value that is initialized with an expression using other constant values.
Definition Constants.h:1133
unsigned getOpcode() const
Return the opcode at the root of this constant expression.
Definition Constants.h:1340
A signed pointer, in the ptrauth sense.
Definition Constants.h:1040
Constant * getAddrDiscriminator() const
The address discriminator if any, or the null constant.
Definition Constants.h:1081
Constant * getPointer() const
The pointer that is signed in this ptrauth signed pointer.
Definition Constants.h:1068
ConstantInt * getKey() const
The Key ID, an i32 constant.
Definition Constants.h:1071
ConstantInt * getDiscriminator() const
The integer discriminator, an i64 constant, or 0.
Definition Constants.h:1074
This class represents a range of values.
Constant Vector Declarations.
Definition Constants.h:525
This is an important base class in LLVM.
Definition Constant.h:43
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
This instruction extracts a struct member or array element value from an aggregate value.
An instruction for ordering other memory operations.
LLVM_ABI int cmpBasicBlocks(const BasicBlock *BBL, const BasicBlock *BBR) const
Test whether two basic blocks have equivalent behaviour.
LLVM_ABI int cmpConstantRanges(const ConstantRange &L, const ConstantRange &R) const
LLVM_ABI int compareSignature() const
Compares the signature and other general attributes of the two functions.
LLVM_ABI int cmpMem(StringRef L, StringRef R) const
LLVM_ABI int compare()
Test whether the two functions have equivalent behaviour.
LLVM_ABI int cmpAPFloats(const APFloat &L, const APFloat &R) const
LLVM_ABI int cmpTypes(Type *TyL, Type *TyR) const
cmpType - compares two types, defines total ordering among the types set.
LLVM_ABI int cmpOperations(const Instruction *L, const Instruction *R, bool &needToCmpOperands) const
Compare two Instructions for equivalence, similar to Instruction::isSameOperationAs.
LLVM_ABI int cmpNumbers(uint64_t L, uint64_t R) const
LLVM_ABI int cmpAligns(Align L, Align R) const
void beginCompare()
Start the comparison.
LLVM_ABI int cmpValues(const Value *L, const Value *R) const
Assign or look up previously assigned numbers for the two values, and return whether the numbers are ...
LLVM_ABI int cmpGlobalValues(GlobalValue *L, GlobalValue *R) const
Compares two global values by number.
LLVM_ABI int cmpConstants(const Constant *L, const Constant *R) const
Constants comparison.
LLVM_ABI int cmpAPInts(const APInt &L, const APInt &R) const
Class to represent function types.
unsigned getNumParams() const
Return the number of fixed parameters this function type requires.
Type * getParamType(unsigned i) const
Parameter type accessors.
bool isVarArg() const
Type * getReturnType() const
const DataLayout & getDataLayout() const
Get the data layout of the module this function belongs to.
Definition Function.cpp:363
const Argument * const_arg_iterator
Definition Function.h:73
LLVM_ABI Type * getSourceElementType() const
Definition Operator.cpp:71
LLVM_ABI bool accumulateConstantOffset(const DataLayout &DL, APInt &Offset, function_ref< bool(Value &, APInt &)> ExternalAnalysis=nullptr) const
Accumulate the constant address offset of this GEP if possible.
Definition Operator.cpp:114
unsigned getPointerAddressSpace() const
Method to return the address space of the pointer operand.
Definition Operator.h:476
an instruction for type-safe pointer arithmetic to access elements of arrays and structs
This instruction inserts a struct field of array element value into an aggregate value.
LLVM_ABI unsigned getNumSuccessors() const LLVM_READONLY
Return the number of successors that this instruction has.
LLVM_ABI BasicBlock * getSuccessor(unsigned Idx) const LLVM_READONLY
Return the specified successor. This instruction must be a terminator.
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
An instruction for reading from memory.
Metadata node.
Definition Metadata.h:1078
Metadata wrapper in the Value hierarchy.
Definition Metadata.h:183
Metadata * getMetadata() const
Definition Metadata.h:201
Root of the metadata hierarchy.
Definition Metadata.h:64
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
Class to represent pointers.
unsigned getAddressSpace() const
Return the address space of the Pointer type.
This instruction constructs a fixed permutation of two input vectors.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
An instruction for storing to memory.
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
Class to represent struct types.
bool isPacked() const
unsigned getNumElements() const
Random access to the elements.
Type * getElementType(unsigned N) const
Multiway switch.
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:45
@ FunctionTyID
Functions.
Definition Type.h:71
@ ArrayTyID
Arrays.
Definition Type.h:74
@ VoidTyID
type with no size
Definition Type.h:63
@ ScalableVectorTyID
Scalable SIMD vector type.
Definition Type.h:76
@ LabelTyID
Labels.
Definition Type.h:64
@ FloatTyID
32-bit floating point type
Definition Type.h:58
@ StructTyID
Structures.
Definition Type.h:73
@ IntegerTyID
Arbitrary bit width integers.
Definition Type.h:70
@ FixedVectorTyID
Fixed width SIMD vector type.
Definition Type.h:75
@ DoubleTyID
64-bit floating point type
Definition Type.h:59
@ X86_FP80TyID
80-bit floating point type (X87)
Definition Type.h:60
@ PPC_FP128TyID
128-bit floating point type (two 64-bits, PowerPC)
Definition Type.h:62
@ MetadataTyID
Metadata.
Definition Type.h:65
@ TokenTyID
Tokens.
Definition Type.h:67
@ PointerTyID
Pointers.
Definition Type.h:72
@ FP128TyID
128-bit floating point type (112-bit significand)
Definition Type.h:61
LLVM_ABI bool isFirstClassType() const
Return true if the type is "first class", meaning it is a valid type for a Value.
Definition Type.cpp:249
TypeID getTypeID() const
Return the type id for the type.
Definition Type.h:136
Value * getOperand(unsigned i) const
Definition User.h:233
unsigned getNumOperands() const
Definition User.h:255
LLVM Value Representation.
Definition Value.h:75
Type * getType() const
All values are typed, get the type of this value.
Definition Value.h:256
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This is an optimization pass for GlobalISel generic memory operations.
detail::zippy< detail::zip_shortest, T, U, Args... > zip(T &&t, U &&u, Args &&...args)
zip iterator for two or more iteratable types.
Definition STLExtras.h:829
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:207
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
AtomicOrdering
Atomic ordering for LLVM's memory model.
ArrayRef(const T &OneElt) -> ArrayRef< T >
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
#define N
#define OBOL
Definition regex2.h:80
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39