LLVM  4.0.0
FunctionComparator.cpp
Go to the documentation of this file.
1 //===- FunctionComparator.h - Function Comparator -------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements the FunctionComparator and GlobalNumberState classes
11 // which are used by the MergeFunctions pass for comparing functions.
12 //
13 //===----------------------------------------------------------------------===//
14 
16 #include "llvm/ADT/SmallSet.h"
17 #include "llvm/IR/CallSite.h"
18 #include "llvm/IR/Instructions.h"
19 #include "llvm/IR/InlineAsm.h"
20 #include "llvm/IR/Module.h"
21 #include "llvm/Support/Debug.h"
23 
24 using namespace llvm;
25 
26 #define DEBUG_TYPE "functioncomparator"
27 
28 int FunctionComparator::cmpNumbers(uint64_t L, uint64_t R) const {
29  if (L < R) return -1;
30  if (L > R) return 1;
31  return 0;
32 }
33 
34 int FunctionComparator::cmpOrderings(AtomicOrdering L, AtomicOrdering R) const {
35  if ((int)L < (int)R) return -1;
36  if ((int)L > (int)R) return 1;
37  return 0;
38 }
39 
40 int FunctionComparator::cmpAPInts(const APInt &L, const APInt &R) const {
41  if (int Res = cmpNumbers(L.getBitWidth(), R.getBitWidth()))
42  return Res;
43  if (L.ugt(R)) return 1;
44  if (R.ugt(L)) return -1;
45  return 0;
46 }
47 
48 int FunctionComparator::cmpAPFloats(const APFloat &L, const APFloat &R) const {
49  // Floats are ordered first by semantics (i.e. float, double, half, etc.),
50  // then by value interpreted as a bitstring (aka APInt).
51  const fltSemantics &SL = L.getSemantics(), &SR = R.getSemantics();
52  if (int Res = cmpNumbers(APFloat::semanticsPrecision(SL),
54  return Res;
55  if (int Res = cmpNumbers(APFloat::semanticsMaxExponent(SL),
57  return Res;
58  if (int Res = cmpNumbers(APFloat::semanticsMinExponent(SL),
60  return Res;
61  if (int Res = cmpNumbers(APFloat::semanticsSizeInBits(SL),
63  return Res;
64  return cmpAPInts(L.bitcastToAPInt(), R.bitcastToAPInt());
65 }
66 
68  // Prevent heavy comparison, compare sizes first.
69  if (int Res = cmpNumbers(L.size(), R.size()))
70  return Res;
71 
72  // Compare strings lexicographically only when it is necessary: only when
73  // strings are equal in size.
74  return L.compare(R);
75 }
76 
77 int FunctionComparator::cmpAttrs(const AttributeSet L,
78  const AttributeSet R) const {
79  if (int Res = cmpNumbers(L.getNumSlots(), R.getNumSlots()))
80  return Res;
81 
82  for (unsigned i = 0, e = L.getNumSlots(); i != e; ++i) {
83  AttributeSet::iterator LI = L.begin(i), LE = L.end(i), RI = R.begin(i),
84  RE = R.end(i);
85  for (; LI != LE && RI != RE; ++LI, ++RI) {
86  Attribute LA = *LI;
87  Attribute RA = *RI;
88  if (LA < RA)
89  return -1;
90  if (RA < LA)
91  return 1;
92  }
93  if (LI != LE)
94  return 1;
95  if (RI != RE)
96  return -1;
97  }
98  return 0;
99 }
100 
101 int FunctionComparator::cmpRangeMetadata(const MDNode *L,
102  const MDNode *R) const {
103  if (L == R)
104  return 0;
105  if (!L)
106  return -1;
107  if (!R)
108  return 1;
109  // Range metadata is a sequence of numbers. Make sure they are the same
110  // sequence.
111  // TODO: Note that as this is metadata, it is possible to drop and/or merge
112  // this data when considering functions to merge. Thus this comparison would
113  // return 0 (i.e. equivalent), but merging would become more complicated
114  // because the ranges would need to be unioned. It is not likely that
115  // functions differ ONLY in this metadata if they are actually the same
116  // function semantically.
117  if (int Res = cmpNumbers(L->getNumOperands(), R->getNumOperands()))
118  return Res;
119  for (size_t I = 0; I < L->getNumOperands(); ++I) {
120  ConstantInt *LLow = mdconst::extract<ConstantInt>(L->getOperand(I));
121  ConstantInt *RLow = mdconst::extract<ConstantInt>(R->getOperand(I));
122  if (int Res = cmpAPInts(LLow->getValue(), RLow->getValue()))
123  return Res;
124  }
125  return 0;
126 }
127 
128 int FunctionComparator::cmpOperandBundlesSchema(const Instruction *L,
129  const Instruction *R) const {
130  ImmutableCallSite LCS(L);
131  ImmutableCallSite RCS(R);
132 
133  assert(LCS && RCS && "Must be calls or invokes!");
134  assert(LCS.isCall() == RCS.isCall() && "Can't compare otherwise!");
135 
136  if (int Res =
137  cmpNumbers(LCS.getNumOperandBundles(), RCS.getNumOperandBundles()))
138  return Res;
139 
140  for (unsigned i = 0, e = LCS.getNumOperandBundles(); i != e; ++i) {
141  auto OBL = LCS.getOperandBundleAt(i);
142  auto OBR = RCS.getOperandBundleAt(i);
143 
144  if (int Res = OBL.getTagName().compare(OBR.getTagName()))
145  return Res;
146 
147  if (int Res = cmpNumbers(OBL.Inputs.size(), OBR.Inputs.size()))
148  return Res;
149  }
150 
151  return 0;
152 }
153 
154 /// Constants comparison:
155 /// 1. Check whether type of L constant could be losslessly bitcasted to R
156 /// type.
157 /// 2. Compare constant contents.
158 /// For more details see declaration comments.
160  const Constant *R) const {
161 
162  Type *TyL = L->getType();
163  Type *TyR = R->getType();
164 
165  // Check whether types are bitcastable. This part is just re-factored
166  // Type::canLosslesslyBitCastTo method, but instead of returning true/false,
167  // we also pack into result which type is "less" for us.
168  int TypesRes = cmpTypes(TyL, TyR);
169  if (TypesRes != 0) {
170  // Types are different, but check whether we can bitcast them.
171  if (!TyL->isFirstClassType()) {
172  if (TyR->isFirstClassType())
173  return -1;
174  // Neither TyL nor TyR are values of first class type. Return the result
175  // of comparing the types
176  return TypesRes;
177  }
178  if (!TyR->isFirstClassType()) {
179  if (TyL->isFirstClassType())
180  return 1;
181  return TypesRes;
182  }
183 
184  // Vector -> Vector conversions are always lossless if the two vector types
185  // have the same size, otherwise not.
186  unsigned TyLWidth = 0;
187  unsigned TyRWidth = 0;
188 
189  if (auto *VecTyL = dyn_cast<VectorType>(TyL))
190  TyLWidth = VecTyL->getBitWidth();
191  if (auto *VecTyR = dyn_cast<VectorType>(TyR))
192  TyRWidth = VecTyR->getBitWidth();
193 
194  if (TyLWidth != TyRWidth)
195  return cmpNumbers(TyLWidth, TyRWidth);
196 
197  // Zero bit-width means neither TyL nor TyR are vectors.
198  if (!TyLWidth) {
199  PointerType *PTyL = dyn_cast<PointerType>(TyL);
200  PointerType *PTyR = dyn_cast<PointerType>(TyR);
201  if (PTyL && PTyR) {
202  unsigned AddrSpaceL = PTyL->getAddressSpace();
203  unsigned AddrSpaceR = PTyR->getAddressSpace();
204  if (int Res = cmpNumbers(AddrSpaceL, AddrSpaceR))
205  return Res;
206  }
207  if (PTyL)
208  return 1;
209  if (PTyR)
210  return -1;
211 
212  // TyL and TyR aren't vectors, nor pointers. We don't know how to
213  // bitcast them.
214  return TypesRes;
215  }
216  }
217 
218  // OK, types are bitcastable, now check constant contents.
219 
220  if (L->isNullValue() && R->isNullValue())
221  return TypesRes;
222  if (L->isNullValue() && !R->isNullValue())
223  return 1;
224  if (!L->isNullValue() && R->isNullValue())
225  return -1;
226 
227  auto GlobalValueL = const_cast<GlobalValue*>(dyn_cast<GlobalValue>(L));
228  auto GlobalValueR = const_cast<GlobalValue*>(dyn_cast<GlobalValue>(R));
229  if (GlobalValueL && GlobalValueR) {
230  return cmpGlobalValues(GlobalValueL, GlobalValueR);
231  }
232 
233  if (int Res = cmpNumbers(L->getValueID(), R->getValueID()))
234  return Res;
235 
236  if (const auto *SeqL = dyn_cast<ConstantDataSequential>(L)) {
237  const auto *SeqR = cast<ConstantDataSequential>(R);
238  // This handles ConstantDataArray and ConstantDataVector. Note that we
239  // compare the two raw data arrays, which might differ depending on the host
240  // endianness. This isn't a problem though, because the endiness of a module
241  // will affect the order of the constants, but this order is the same
242  // for a given input module and host platform.
243  return cmpMem(SeqL->getRawDataValues(), SeqR->getRawDataValues());
244  }
245 
246  switch (L->getValueID()) {
247  case Value::UndefValueVal:
248  case Value::ConstantTokenNoneVal:
249  return TypesRes;
250  case Value::ConstantIntVal: {
251  const APInt &LInt = cast<ConstantInt>(L)->getValue();
252  const APInt &RInt = cast<ConstantInt>(R)->getValue();
253  return cmpAPInts(LInt, RInt);
254  }
255  case Value::ConstantFPVal: {
256  const APFloat &LAPF = cast<ConstantFP>(L)->getValueAPF();
257  const APFloat &RAPF = cast<ConstantFP>(R)->getValueAPF();
258  return cmpAPFloats(LAPF, RAPF);
259  }
260  case Value::ConstantArrayVal: {
261  const ConstantArray *LA = cast<ConstantArray>(L);
262  const ConstantArray *RA = cast<ConstantArray>(R);
263  uint64_t NumElementsL = cast<ArrayType>(TyL)->getNumElements();
264  uint64_t NumElementsR = cast<ArrayType>(TyR)->getNumElements();
265  if (int Res = cmpNumbers(NumElementsL, NumElementsR))
266  return Res;
267  for (uint64_t i = 0; i < NumElementsL; ++i) {
268  if (int Res = cmpConstants(cast<Constant>(LA->getOperand(i)),
269  cast<Constant>(RA->getOperand(i))))
270  return Res;
271  }
272  return 0;
273  }
274  case Value::ConstantStructVal: {
275  const ConstantStruct *LS = cast<ConstantStruct>(L);
276  const ConstantStruct *RS = cast<ConstantStruct>(R);
277  unsigned NumElementsL = cast<StructType>(TyL)->getNumElements();
278  unsigned NumElementsR = cast<StructType>(TyR)->getNumElements();
279  if (int Res = cmpNumbers(NumElementsL, NumElementsR))
280  return Res;
281  for (unsigned i = 0; i != NumElementsL; ++i) {
282  if (int Res = cmpConstants(cast<Constant>(LS->getOperand(i)),
283  cast<Constant>(RS->getOperand(i))))
284  return Res;
285  }
286  return 0;
287  }
288  case Value::ConstantVectorVal: {
289  const ConstantVector *LV = cast<ConstantVector>(L);
290  const ConstantVector *RV = cast<ConstantVector>(R);
291  unsigned NumElementsL = cast<VectorType>(TyL)->getNumElements();
292  unsigned NumElementsR = cast<VectorType>(TyR)->getNumElements();
293  if (int Res = cmpNumbers(NumElementsL, NumElementsR))
294  return Res;
295  for (uint64_t i = 0; i < NumElementsL; ++i) {
296  if (int Res = cmpConstants(cast<Constant>(LV->getOperand(i)),
297  cast<Constant>(RV->getOperand(i))))
298  return Res;
299  }
300  return 0;
301  }
302  case Value::ConstantExprVal: {
303  const ConstantExpr *LE = cast<ConstantExpr>(L);
304  const ConstantExpr *RE = cast<ConstantExpr>(R);
305  unsigned NumOperandsL = LE->getNumOperands();
306  unsigned NumOperandsR = RE->getNumOperands();
307  if (int Res = cmpNumbers(NumOperandsL, NumOperandsR))
308  return Res;
309  for (unsigned i = 0; i < NumOperandsL; ++i) {
310  if (int Res = cmpConstants(cast<Constant>(LE->getOperand(i)),
311  cast<Constant>(RE->getOperand(i))))
312  return Res;
313  }
314  return 0;
315  }
316  case Value::BlockAddressVal: {
317  const BlockAddress *LBA = cast<BlockAddress>(L);
318  const BlockAddress *RBA = cast<BlockAddress>(R);
319  if (int Res = cmpValues(LBA->getFunction(), RBA->getFunction()))
320  return Res;
321  if (LBA->getFunction() == RBA->getFunction()) {
322  // They are BBs in the same function. Order by which comes first in the
323  // BB order of the function. This order is deterministic.
324  Function* F = LBA->getFunction();
325  BasicBlock *LBB = LBA->getBasicBlock();
326  BasicBlock *RBB = RBA->getBasicBlock();
327  if (LBB == RBB)
328  return 0;
329  for(BasicBlock &BB : F->getBasicBlockList()) {
330  if (&BB == LBB) {
331  assert(&BB != RBB);
332  return -1;
333  }
334  if (&BB == RBB)
335  return 1;
336  }
337  llvm_unreachable("Basic Block Address does not point to a basic block in "
338  "its function.");
339  return -1;
340  } else {
341  // cmpValues said the functions are the same. So because they aren't
342  // literally the same pointer, they must respectively be the left and
343  // right functions.
344  assert(LBA->getFunction() == FnL && RBA->getFunction() == FnR);
345  // cmpValues will tell us if these are equivalent BasicBlocks, in the
346  // context of their respective functions.
347  return cmpValues(LBA->getBasicBlock(), RBA->getBasicBlock());
348  }
349  }
350  default: // Unknown constant, abort.
351  DEBUG(dbgs() << "Looking at valueID " << L->getValueID() << "\n");
352  llvm_unreachable("Constant ValueID not recognized.");
353  return -1;
354  }
355 }
356 
358  uint64_t LNumber = GlobalNumbers->getNumber(L);
359  uint64_t RNumber = GlobalNumbers->getNumber(R);
360  return cmpNumbers(LNumber, RNumber);
361 }
362 
363 /// cmpType - compares two types,
364 /// defines total ordering among the types set.
365 /// See method declaration comments for more details.
366 int FunctionComparator::cmpTypes(Type *TyL, Type *TyR) const {
367  PointerType *PTyL = dyn_cast<PointerType>(TyL);
368  PointerType *PTyR = dyn_cast<PointerType>(TyR);
369 
370  const DataLayout &DL = FnL->getParent()->getDataLayout();
371  if (PTyL && PTyL->getAddressSpace() == 0)
372  TyL = DL.getIntPtrType(TyL);
373  if (PTyR && PTyR->getAddressSpace() == 0)
374  TyR = DL.getIntPtrType(TyR);
375 
376  if (TyL == TyR)
377  return 0;
378 
379  if (int Res = cmpNumbers(TyL->getTypeID(), TyR->getTypeID()))
380  return Res;
381 
382  switch (TyL->getTypeID()) {
383  default:
384  llvm_unreachable("Unknown type!");
385  // Fall through in Release mode.
387  case Type::IntegerTyID:
388  return cmpNumbers(cast<IntegerType>(TyL)->getBitWidth(),
389  cast<IntegerType>(TyR)->getBitWidth());
390  // TyL == TyR would have returned true earlier, because types are uniqued.
391  case Type::VoidTyID:
392  case Type::FloatTyID:
393  case Type::DoubleTyID:
394  case Type::X86_FP80TyID:
395  case Type::FP128TyID:
396  case Type::PPC_FP128TyID:
397  case Type::LabelTyID:
398  case Type::MetadataTyID:
399  case Type::TokenTyID:
400  return 0;
401 
402  case Type::PointerTyID: {
403  assert(PTyL && PTyR && "Both types must be pointers here.");
404  return cmpNumbers(PTyL->getAddressSpace(), PTyR->getAddressSpace());
405  }
406 
407  case Type::StructTyID: {
408  StructType *STyL = cast<StructType>(TyL);
409  StructType *STyR = cast<StructType>(TyR);
410  if (STyL->getNumElements() != STyR->getNumElements())
411  return cmpNumbers(STyL->getNumElements(), STyR->getNumElements());
412 
413  if (STyL->isPacked() != STyR->isPacked())
414  return cmpNumbers(STyL->isPacked(), STyR->isPacked());
415 
416  for (unsigned i = 0, e = STyL->getNumElements(); i != e; ++i) {
417  if (int Res = cmpTypes(STyL->getElementType(i), STyR->getElementType(i)))
418  return Res;
419  }
420  return 0;
421  }
422 
423  case Type::FunctionTyID: {
424  FunctionType *FTyL = cast<FunctionType>(TyL);
425  FunctionType *FTyR = cast<FunctionType>(TyR);
426  if (FTyL->getNumParams() != FTyR->getNumParams())
427  return cmpNumbers(FTyL->getNumParams(), FTyR->getNumParams());
428 
429  if (FTyL->isVarArg() != FTyR->isVarArg())
430  return cmpNumbers(FTyL->isVarArg(), FTyR->isVarArg());
431 
432  if (int Res = cmpTypes(FTyL->getReturnType(), FTyR->getReturnType()))
433  return Res;
434 
435  for (unsigned i = 0, e = FTyL->getNumParams(); i != e; ++i) {
436  if (int Res = cmpTypes(FTyL->getParamType(i), FTyR->getParamType(i)))
437  return Res;
438  }
439  return 0;
440  }
441 
442  case Type::ArrayTyID:
443  case Type::VectorTyID: {
444  auto *STyL = cast<SequentialType>(TyL);
445  auto *STyR = cast<SequentialType>(TyR);
446  if (STyL->getNumElements() != STyR->getNumElements())
447  return cmpNumbers(STyL->getNumElements(), STyR->getNumElements());
448  return cmpTypes(STyL->getElementType(), STyR->getElementType());
449  }
450  }
451 }
452 
453 // Determine whether the two operations are the same except that pointer-to-A
454 // and pointer-to-B are equivalent. This should be kept in sync with
455 // Instruction::isSameOperationAs.
456 // Read method declaration comments for more details.
458  const Instruction *R,
459  bool &needToCmpOperands) const {
460  needToCmpOperands = true;
461  if (int Res = cmpValues(L, R))
462  return Res;
463 
464  // Differences from Instruction::isSameOperationAs:
465  // * replace type comparison with calls to cmpTypes.
466  // * we test for I->getRawSubclassOptionalData (nuw/nsw/tail) at the top.
467  // * because of the above, we don't test for the tail bit on calls later on.
468  if (int Res = cmpNumbers(L->getOpcode(), R->getOpcode()))
469  return Res;
470 
471  if (const GetElementPtrInst *GEPL = dyn_cast<GetElementPtrInst>(L)) {
472  needToCmpOperands = false;
473  const GetElementPtrInst *GEPR = cast<GetElementPtrInst>(R);
474  if (int Res =
475  cmpValues(GEPL->getPointerOperand(), GEPR->getPointerOperand()))
476  return Res;
477  return cmpGEPs(GEPL, GEPR);
478  }
479 
480  if (int Res = cmpNumbers(L->getNumOperands(), R->getNumOperands()))
481  return Res;
482 
483  if (int Res = cmpTypes(L->getType(), R->getType()))
484  return Res;
485 
486  if (int Res = cmpNumbers(L->getRawSubclassOptionalData(),
488  return Res;
489 
490  // We have two instructions of identical opcode and #operands. Check to see
491  // if all operands are the same type
492  for (unsigned i = 0, e = L->getNumOperands(); i != e; ++i) {
493  if (int Res =
494  cmpTypes(L->getOperand(i)->getType(), R->getOperand(i)->getType()))
495  return Res;
496  }
497 
498  // Check special state that is a part of some instructions.
499  if (const AllocaInst *AI = dyn_cast<AllocaInst>(L)) {
500  if (int Res = cmpTypes(AI->getAllocatedType(),
501  cast<AllocaInst>(R)->getAllocatedType()))
502  return Res;
503  return cmpNumbers(AI->getAlignment(), cast<AllocaInst>(R)->getAlignment());
504  }
505  if (const LoadInst *LI = dyn_cast<LoadInst>(L)) {
506  if (int Res = cmpNumbers(LI->isVolatile(), cast<LoadInst>(R)->isVolatile()))
507  return Res;
508  if (int Res =
509  cmpNumbers(LI->getAlignment(), cast<LoadInst>(R)->getAlignment()))
510  return Res;
511  if (int Res =
512  cmpOrderings(LI->getOrdering(), cast<LoadInst>(R)->getOrdering()))
513  return Res;
514  if (int Res =
515  cmpNumbers(LI->getSynchScope(), cast<LoadInst>(R)->getSynchScope()))
516  return Res;
517  return cmpRangeMetadata(LI->getMetadata(LLVMContext::MD_range),
518  cast<LoadInst>(R)->getMetadata(LLVMContext::MD_range));
519  }
520  if (const StoreInst *SI = dyn_cast<StoreInst>(L)) {
521  if (int Res =
522  cmpNumbers(SI->isVolatile(), cast<StoreInst>(R)->isVolatile()))
523  return Res;
524  if (int Res =
525  cmpNumbers(SI->getAlignment(), cast<StoreInst>(R)->getAlignment()))
526  return Res;
527  if (int Res =
528  cmpOrderings(SI->getOrdering(), cast<StoreInst>(R)->getOrdering()))
529  return Res;
530  return cmpNumbers(SI->getSynchScope(), cast<StoreInst>(R)->getSynchScope());
531  }
532  if (const CmpInst *CI = dyn_cast<CmpInst>(L))
533  return cmpNumbers(CI->getPredicate(), cast<CmpInst>(R)->getPredicate());
534  if (const CallInst *CI = dyn_cast<CallInst>(L)) {
535  if (int Res = cmpNumbers(CI->getCallingConv(),
536  cast<CallInst>(R)->getCallingConv()))
537  return Res;
538  if (int Res =
539  cmpAttrs(CI->getAttributes(), cast<CallInst>(R)->getAttributes()))
540  return Res;
541  if (int Res = cmpOperandBundlesSchema(CI, R))
542  return Res;
543  return cmpRangeMetadata(
544  CI->getMetadata(LLVMContext::MD_range),
545  cast<CallInst>(R)->getMetadata(LLVMContext::MD_range));
546  }
547  if (const InvokeInst *II = dyn_cast<InvokeInst>(L)) {
548  if (int Res = cmpNumbers(II->getCallingConv(),
549  cast<InvokeInst>(R)->getCallingConv()))
550  return Res;
551  if (int Res =
552  cmpAttrs(II->getAttributes(), cast<InvokeInst>(R)->getAttributes()))
553  return Res;
554  if (int Res = cmpOperandBundlesSchema(II, R))
555  return Res;
556  return cmpRangeMetadata(
557  II->getMetadata(LLVMContext::MD_range),
558  cast<InvokeInst>(R)->getMetadata(LLVMContext::MD_range));
559  }
560  if (const InsertValueInst *IVI = dyn_cast<InsertValueInst>(L)) {
561  ArrayRef<unsigned> LIndices = IVI->getIndices();
562  ArrayRef<unsigned> RIndices = cast<InsertValueInst>(R)->getIndices();
563  if (int Res = cmpNumbers(LIndices.size(), RIndices.size()))
564  return Res;
565  for (size_t i = 0, e = LIndices.size(); i != e; ++i) {
566  if (int Res = cmpNumbers(LIndices[i], RIndices[i]))
567  return Res;
568  }
569  return 0;
570  }
571  if (const ExtractValueInst *EVI = dyn_cast<ExtractValueInst>(L)) {
572  ArrayRef<unsigned> LIndices = EVI->getIndices();
573  ArrayRef<unsigned> RIndices = cast<ExtractValueInst>(R)->getIndices();
574  if (int Res = cmpNumbers(LIndices.size(), RIndices.size()))
575  return Res;
576  for (size_t i = 0, e = LIndices.size(); i != e; ++i) {
577  if (int Res = cmpNumbers(LIndices[i], RIndices[i]))
578  return Res;
579  }
580  }
581  if (const FenceInst *FI = dyn_cast<FenceInst>(L)) {
582  if (int Res =
583  cmpOrderings(FI->getOrdering(), cast<FenceInst>(R)->getOrdering()))
584  return Res;
585  return cmpNumbers(FI->getSynchScope(), cast<FenceInst>(R)->getSynchScope());
586  }
587  if (const AtomicCmpXchgInst *CXI = dyn_cast<AtomicCmpXchgInst>(L)) {
588  if (int Res = cmpNumbers(CXI->isVolatile(),
589  cast<AtomicCmpXchgInst>(R)->isVolatile()))
590  return Res;
591  if (int Res = cmpNumbers(CXI->isWeak(),
592  cast<AtomicCmpXchgInst>(R)->isWeak()))
593  return Res;
594  if (int Res =
595  cmpOrderings(CXI->getSuccessOrdering(),
596  cast<AtomicCmpXchgInst>(R)->getSuccessOrdering()))
597  return Res;
598  if (int Res =
599  cmpOrderings(CXI->getFailureOrdering(),
600  cast<AtomicCmpXchgInst>(R)->getFailureOrdering()))
601  return Res;
602  return cmpNumbers(CXI->getSynchScope(),
603  cast<AtomicCmpXchgInst>(R)->getSynchScope());
604  }
605  if (const AtomicRMWInst *RMWI = dyn_cast<AtomicRMWInst>(L)) {
606  if (int Res = cmpNumbers(RMWI->getOperation(),
607  cast<AtomicRMWInst>(R)->getOperation()))
608  return Res;
609  if (int Res = cmpNumbers(RMWI->isVolatile(),
610  cast<AtomicRMWInst>(R)->isVolatile()))
611  return Res;
612  if (int Res = cmpOrderings(RMWI->getOrdering(),
613  cast<AtomicRMWInst>(R)->getOrdering()))
614  return Res;
615  return cmpNumbers(RMWI->getSynchScope(),
616  cast<AtomicRMWInst>(R)->getSynchScope());
617  }
618  if (const PHINode *PNL = dyn_cast<PHINode>(L)) {
619  const PHINode *PNR = cast<PHINode>(R);
620  // Ensure that in addition to the incoming values being identical
621  // (checked by the caller of this function), the incoming blocks
622  // are also identical.
623  for (unsigned i = 0, e = PNL->getNumIncomingValues(); i != e; ++i) {
624  if (int Res =
625  cmpValues(PNL->getIncomingBlock(i), PNR->getIncomingBlock(i)))
626  return Res;
627  }
628  }
629  return 0;
630 }
631 
632 // Determine whether two GEP operations perform the same underlying arithmetic.
633 // Read method declaration comments for more details.
634 int FunctionComparator::cmpGEPs(const GEPOperator *GEPL,
635  const GEPOperator *GEPR) const {
636 
637  unsigned int ASL = GEPL->getPointerAddressSpace();
638  unsigned int ASR = GEPR->getPointerAddressSpace();
639 
640  if (int Res = cmpNumbers(ASL, ASR))
641  return Res;
642 
643  // When we have target data, we can reduce the GEP down to the value in bytes
644  // added to the address.
645  const DataLayout &DL = FnL->getParent()->getDataLayout();
646  unsigned BitWidth = DL.getPointerSizeInBits(ASL);
647  APInt OffsetL(BitWidth, 0), OffsetR(BitWidth, 0);
648  if (GEPL->accumulateConstantOffset(DL, OffsetL) &&
649  GEPR->accumulateConstantOffset(DL, OffsetR))
650  return cmpAPInts(OffsetL, OffsetR);
651  if (int Res = cmpTypes(GEPL->getSourceElementType(),
652  GEPR->getSourceElementType()))
653  return Res;
654 
655  if (int Res = cmpNumbers(GEPL->getNumOperands(), GEPR->getNumOperands()))
656  return Res;
657 
658  for (unsigned i = 0, e = GEPL->getNumOperands(); i != e; ++i) {
659  if (int Res = cmpValues(GEPL->getOperand(i), GEPR->getOperand(i)))
660  return Res;
661  }
662 
663  return 0;
664 }
665 
666 int FunctionComparator::cmpInlineAsm(const InlineAsm *L,
667  const InlineAsm *R) const {
668  // InlineAsm's are uniqued. If they are the same pointer, obviously they are
669  // the same, otherwise compare the fields.
670  if (L == R)
671  return 0;
672  if (int Res = cmpTypes(L->getFunctionType(), R->getFunctionType()))
673  return Res;
674  if (int Res = cmpMem(L->getAsmString(), R->getAsmString()))
675  return Res;
676  if (int Res = cmpMem(L->getConstraintString(), R->getConstraintString()))
677  return Res;
678  if (int Res = cmpNumbers(L->hasSideEffects(), R->hasSideEffects()))
679  return Res;
680  if (int Res = cmpNumbers(L->isAlignStack(), R->isAlignStack()))
681  return Res;
682  if (int Res = cmpNumbers(L->getDialect(), R->getDialect()))
683  return Res;
684  llvm_unreachable("InlineAsm blocks were not uniqued.");
685  return 0;
686 }
687 
688 /// Compare two values used by the two functions under pair-wise comparison. If
689 /// this is the first time the values are seen, they're added to the mapping so
690 /// that we will detect mismatches on next use.
691 /// See comments in declaration for more details.
692 int FunctionComparator::cmpValues(const Value *L, const Value *R) const {
693  // Catch self-reference case.
694  if (L == FnL) {
695  if (R == FnR)
696  return 0;
697  return -1;
698  }
699  if (R == FnR) {
700  if (L == FnL)
701  return 0;
702  return 1;
703  }
704 
705  const Constant *ConstL = dyn_cast<Constant>(L);
706  const Constant *ConstR = dyn_cast<Constant>(R);
707  if (ConstL && ConstR) {
708  if (L == R)
709  return 0;
710  return cmpConstants(ConstL, ConstR);
711  }
712 
713  if (ConstL)
714  return 1;
715  if (ConstR)
716  return -1;
717 
718  const InlineAsm *InlineAsmL = dyn_cast<InlineAsm>(L);
719  const InlineAsm *InlineAsmR = dyn_cast<InlineAsm>(R);
720 
721  if (InlineAsmL && InlineAsmR)
722  return cmpInlineAsm(InlineAsmL, InlineAsmR);
723  if (InlineAsmL)
724  return 1;
725  if (InlineAsmR)
726  return -1;
727 
728  auto LeftSN = sn_mapL.insert(std::make_pair(L, sn_mapL.size())),
729  RightSN = sn_mapR.insert(std::make_pair(R, sn_mapR.size()));
730 
731  return cmpNumbers(LeftSN.first->second, RightSN.first->second);
732 }
733 
734 // Test whether two basic blocks have equivalent behaviour.
736  const BasicBlock *BBR) const {
737  BasicBlock::const_iterator InstL = BBL->begin(), InstLE = BBL->end();
738  BasicBlock::const_iterator InstR = BBR->begin(), InstRE = BBR->end();
739 
740  do {
741  bool needToCmpOperands = true;
742  if (int Res = cmpOperations(&*InstL, &*InstR, needToCmpOperands))
743  return Res;
744  if (needToCmpOperands) {
745  assert(InstL->getNumOperands() == InstR->getNumOperands());
746 
747  for (unsigned i = 0, e = InstL->getNumOperands(); i != e; ++i) {
748  Value *OpL = InstL->getOperand(i);
749  Value *OpR = InstR->getOperand(i);
750  if (int Res = cmpValues(OpL, OpR))
751  return Res;
752  // cmpValues should ensure this is true.
753  assert(cmpTypes(OpL->getType(), OpR->getType()) == 0);
754  }
755  }
756 
757  ++InstL;
758  ++InstR;
759  } while (InstL != InstLE && InstR != InstRE);
760 
761  if (InstL != InstLE && InstR == InstRE)
762  return 1;
763  if (InstL == InstLE && InstR != InstRE)
764  return -1;
765  return 0;
766 }
767 
769  if (int Res = cmpAttrs(FnL->getAttributes(), FnR->getAttributes()))
770  return Res;
771 
772  if (int Res = cmpNumbers(FnL->hasGC(), FnR->hasGC()))
773  return Res;
774 
775  if (FnL->hasGC()) {
776  if (int Res = cmpMem(FnL->getGC(), FnR->getGC()))
777  return Res;
778  }
779 
780  if (int Res = cmpNumbers(FnL->hasSection(), FnR->hasSection()))
781  return Res;
782 
783  if (FnL->hasSection()) {
784  if (int Res = cmpMem(FnL->getSection(), FnR->getSection()))
785  return Res;
786  }
787 
788  if (int Res = cmpNumbers(FnL->isVarArg(), FnR->isVarArg()))
789  return Res;
790 
791  // TODO: if it's internal and only used in direct calls, we could handle this
792  // case too.
793  if (int Res = cmpNumbers(FnL->getCallingConv(), FnR->getCallingConv()))
794  return Res;
795 
796  if (int Res = cmpTypes(FnL->getFunctionType(), FnR->getFunctionType()))
797  return Res;
798 
799  assert(FnL->arg_size() == FnR->arg_size() &&
800  "Identically typed functions have different numbers of args!");
801 
802  // Visit the arguments so that they get enumerated in the order they're
803  // passed in.
805  ArgRI = FnR->arg_begin(),
806  ArgLE = FnL->arg_end();
807  ArgLI != ArgLE; ++ArgLI, ++ArgRI) {
808  if (cmpValues(&*ArgLI, &*ArgRI) != 0)
809  llvm_unreachable("Arguments repeat!");
810  }
811  return 0;
812 }
813 
814 // Test whether the two functions have equivalent behaviour.
816  beginCompare();
817 
818  if (int Res = compareSignature())
819  return Res;
820 
821  // We do a CFG-ordered walk since the actual ordering of the blocks in the
822  // linked list is immaterial. Our walk starts at the entry block for both
823  // functions, then takes each block from each terminator in order. As an
824  // artifact, this also means that unreachable blocks are ignored.
825  SmallVector<const BasicBlock *, 8> FnLBBs, FnRBBs;
826  SmallPtrSet<const BasicBlock *, 32> VisitedBBs; // in terms of F1.
827 
828  FnLBBs.push_back(&FnL->getEntryBlock());
829  FnRBBs.push_back(&FnR->getEntryBlock());
830 
831  VisitedBBs.insert(FnLBBs[0]);
832  while (!FnLBBs.empty()) {
833  const BasicBlock *BBL = FnLBBs.pop_back_val();
834  const BasicBlock *BBR = FnRBBs.pop_back_val();
835 
836  if (int Res = cmpValues(BBL, BBR))
837  return Res;
838 
839  if (int Res = cmpBasicBlocks(BBL, BBR))
840  return Res;
841 
842  const TerminatorInst *TermL = BBL->getTerminator();
843  const TerminatorInst *TermR = BBR->getTerminator();
844 
845  assert(TermL->getNumSuccessors() == TermR->getNumSuccessors());
846  for (unsigned i = 0, e = TermL->getNumSuccessors(); i != e; ++i) {
847  if (!VisitedBBs.insert(TermL->getSuccessor(i)).second)
848  continue;
849 
850  FnLBBs.push_back(TermL->getSuccessor(i));
851  FnRBBs.push_back(TermR->getSuccessor(i));
852  }
853  }
854  return 0;
855 }
856 
857 namespace {
858 
859 // Accumulate the hash of a sequence of 64-bit integers. This is similar to a
860 // hash of a sequence of 64bit ints, but the entire input does not need to be
861 // available at once. This interface is necessary for functionHash because it
862 // needs to accumulate the hash as the structure of the function is traversed
863 // without saving these values to an intermediate buffer. This form of hashing
864 // is not often needed, as usually the object to hash is just read from a
865 // buffer.
866 class HashAccumulator64 {
867  uint64_t Hash;
868 public:
869  // Initialize to random constant, so the state isn't zero.
870  HashAccumulator64() { Hash = 0x6acaa36bef8325c5ULL; }
871  void add(uint64_t V) {
873  }
874  // No finishing is required, because the entire hash value is used.
875  uint64_t getHash() { return Hash; }
876 };
877 } // end anonymous namespace
878 
879 // A function hash is calculated by considering only the number of arguments and
880 // whether a function is varargs, the order of basic blocks (given by the
881 // successors of each basic block in depth first order), and the order of
882 // opcodes of each instruction within each of these basic blocks. This mirrors
883 // the strategy compare() uses to compare functions by walking the BBs in depth
884 // first order and comparing each instruction in sequence. Because this hash
885 // does not look at the operands, it is insensitive to things such as the
886 // target of calls and the constants used in the function, which makes it useful
887 // when possibly merging functions which are the same modulo constants and call
888 // targets.
890  HashAccumulator64 H;
891  H.add(F.isVarArg());
892  H.add(F.arg_size());
893 
896 
897  // Walk the blocks in the same order as FunctionComparator::cmpBasicBlocks(),
898  // accumulating the hash of the function "structure." (BB and opcode sequence)
899  BBs.push_back(&F.getEntryBlock());
900  VisitedBBs.insert(BBs[0]);
901  while (!BBs.empty()) {
902  const BasicBlock *BB = BBs.pop_back_val();
903  // This random value acts as a block header, as otherwise the partition of
904  // opcodes into BBs wouldn't affect the hash, only the order of the opcodes
905  H.add(45798);
906  for (auto &Inst : *BB) {
907  H.add(Inst.getOpcode());
908  }
909  const TerminatorInst *Term = BB->getTerminator();
910  for (unsigned i = 0, e = Term->getNumSuccessors(); i != e; ++i) {
911  if (!VisitedBBs.insert(Term->getSuccessor(i)).second)
912  continue;
913  BBs.push_back(Term->getSuccessor(i));
914  }
915  }
916  return H.getHash();
917 }
918 
919 
MachineLoop * L
static unsigned getBitWidth(Type *Ty, const DataLayout &DL)
Returns the bitwidth of the given scalar or pointer type (if unknown returns 0).
Type * getSourceElementType() const
Definition: Operator.cpp:9
7: Labels
Definition: Type.h:63
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:102
AsmDialect getDialect() const
Definition: InlineAsm.h:70
This class is the base class for the comparison instructions.
Definition: InstrTypes.h:870
This instruction extracts a struct member or array element value from an aggregate value...
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 ...
size_t i
unsigned getNumParams() const
Return the number of fixed parameters this function type requires.
Definition: DerivedTypes.h:137
2: 32-bit floating point type
Definition: Type.h:58
An instruction for ordering other memory operations.
Definition: Instructions.h:430
an instruction that atomically checks whether a specified value is in a memory location, and, if it is, stores a new value there.
Definition: Instructions.h:504
unsigned getNumOperands() const
Definition: User.h:167
unsigned getNumOperands() const
Return number of MDNode operands.
Definition: Metadata.h:1040
This class represents a function call, abstracting a target machine's calling convention.
const std::string & getAsmString() const
Definition: InlineAsm.h:82
iterator begin(unsigned Slot) const
const std::string & getConstraintString() const
Definition: InlineAsm.h:83
arg_iterator arg_end()
Definition: Function.h:559
13: Structures
Definition: Type.h:72
unsigned getAlignment() const
Returns the alignment field of an attribute as a byte alignment value.
Definition: Attributes.cpp:194
Metadata node.
Definition: Metadata.h:830
4: 80-bit floating point type (X87)
Definition: Type.h:60
unsigned getAddressSpace() const
Return the address space of the Pointer type.
Definition: DerivedTypes.h:471
An instruction for reading from memory.
Definition: Instructions.h:164
an instruction that atomically reads a memory location, combines it with another value, and then stores the result back.
Definition: Instructions.h:669
int cmpAPInts(const APInt &L, const APInt &R) const
15: Pointers
Definition: Type.h:74
12: Functions
Definition: Type.h:71
int cmpOperations(const Instruction *L, const Instruction *R, bool &needToCmpOperands) const
Compare two Instructions for equivalence, similar to Instruction::isSameOperationAs.
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
Definition: Function.h:165
size_t arg_size() const
Definition: Function.cpp:327
iterator begin()
Instruction iterator methods.
Definition: BasicBlock.h:228
The address of a basic block.
Definition: Constants.h:822
bool isPacked() const
Definition: DerivedTypes.h:245
int cmpGlobalValues(GlobalValue *L, GlobalValue *R) const
Compares two global values by number.
bool hasGC() const
hasGC/getGC/setGC/clearGC - The name of the garbage collection algorithm to use during code generatio...
Definition: Function.h:250
const APInt & getValue() const
Return the constant as an APInt value reference.
Definition: Constants.h:143
Class to represent struct types.
Definition: DerivedTypes.h:199
APInt bitcastToAPInt() const
Definition: APFloat.h:1012
static ExponentType semanticsMaxExponent(const fltSemantics &)
Definition: APFloat.cpp:140
LLVM_NODISCARD bool empty() const
Definition: SmallVector.h:60
AtomicOrdering
Atomic ordering for LLVM's memory model.
void beginCompare()
Start the comparison.
Class to represent function types.
Definition: DerivedTypes.h:102
A constant value that is initialized with an expression using other constant values.
Definition: Constants.h:873
static unsigned getAlignment(GlobalVariable *GV)
#define F(x, y, z)
Definition: MD5.cpp:51
bool accumulateConstantOffset(const DataLayout &DL, APInt &Offset) const
Accumulate the constant address offset of this GEP if possible.
Definition: Operator.cpp:21
static unsigned int semanticsSizeInBits(const fltSemantics &)
Definition: APFloat.cpp:147
static bool add(uint64_t *dest, const uint64_t *x, const uint64_t *y, unsigned len)
This function adds the integer array x to the integer array Y and places the result in dest...
Definition: APInt.cpp:239
bool isFirstClassType() const
Return true if the type is "first class", meaning it is a valid type for a Value. ...
Definition: Type.h:233
StringRef getSection() const
Get the custom section of this global if it has one.
Definition: GlobalObject.h:81
TypeID getTypeID() const
Return the type id for the type.
Definition: Type.h:136
uint64_t hash_16_bytes(uint64_t low, uint64_t high)
Definition: Hashing.h:179
An instruction for storing to memory.
Definition: Instructions.h:300
uint64_t getNumber(GlobalValue *Global)
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
Definition: StringRef.h:135
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:141
static ExponentType semanticsMinExponent(const fltSemantics &)
Definition: APFloat.cpp:144
Class to represent pointers.
Definition: DerivedTypes.h:443
static FunctionHash functionHash(Function &)
11: Arbitrary bit width integers
Definition: Type.h:70
bool hasSection() const
Check if this global has a custom object file section.
Definition: GlobalObject.h:73
unsigned getNumSuccessors() const
Return the number of successors that this terminator has.
Definition: InstrTypes.h:74
an instruction for type-safe pointer arithmetic to access elements of arrays and structs ...
Definition: Instructions.h:830
0: type with no size
Definition: Type.h:56
unsigned getNumSlots() const
Return the number of slots used in this attribute list.
Type * getParamType(unsigned i) const
Parameter type accessors.
Definition: DerivedTypes.h:133
Subclasses of this class are all able to terminate a basic block.
Definition: InstrTypes.h:52
bool hasSideEffects() const
Definition: InlineAsm.h:68
LLVM Basic Block Representation.
Definition: BasicBlock.h:51
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
BasicBlock * getSuccessor(unsigned idx) const
Return the specified successor.
Definition: InstrTypes.h:79
Type * getElementType(unsigned N) const
Definition: DerivedTypes.h:290
This is an important base class in LLVM.
Definition: Constant.h:42
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
Definition: SmallSet.h:36
10: Tokens
Definition: Type.h:66
#define H(x, y, z)
Definition: MD5.cpp:53
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
Definition: SmallPtrSet.h:368
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
unsigned getBitWidth() const
Return the number of bits in the APInt.
Definition: APInt.h:1255
unsigned getValueID() const
Return an ID for the concrete type of this object.
Definition: Value.h:434
6: 128-bit floating point type (two 64-bits, PowerPC)
Definition: Type.h:62
Value * getOperand(unsigned i) const
Definition: User.h:145
arg_iterator arg_begin()
Definition: Function.h:550
std::pair< NoneType, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
Definition: SmallSet.h:80
Constant Vector Declarations.
Definition: Constants.h:490
int cmpNumbers(uint64_t L, uint64_t R) const
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE int compare(StringRef RHS) const
compare - Compare two strings; the result is -1, 0, or 1 if this string is lexicographically less tha...
Definition: StringRef.h:181
int cmpMem(StringRef L, StringRef R) const
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
uint64_t FunctionHash
Hash a function.
bool ugt(const APInt &RHS) const
Unsigned greather than comparison.
Definition: APInt.h:1083
14: Arrays
Definition: Type.h:73
int compareSignature() const
Compares the signature and other general attributes of the two functions.
const MDOperand & getOperand(unsigned I) const
Definition: Metadata.h:1034
FunctionType * getFunctionType() const
getFunctionType - InlineAsm's are always pointers to functions.
Definition: InlineAsm.cpp:54
Iterator for intrusive lists based on ilist_node.
const BasicBlockListType & getBasicBlockList() const
Definition: Function.h:512
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
Definition: SmallPtrSet.h:425
This is the shared class of boolean and integer constants.
Definition: Constants.h:88
int cmpTypes(Type *TyL, Type *TyR) const
cmpType - compares two types, defines total ordering among the types set.
16: SIMD 'packed' format, or other vector type
Definition: Type.h:75
iterator end()
Definition: BasicBlock.h:230
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:843
Module.h This file contains the declarations for the Module class.
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:230
iterator end(unsigned Slot) const
LLVM_NODISCARD T pop_back_val()
Definition: SmallVector.h:382
BasicBlock * getBasicBlock() const
Definition: Constants.h:851
const BasicBlock & getEntryBlock() const
Definition: Function.h:519
bool isNullValue() const
Return true if this is the value that would be returned by getNullValue.
Definition: Constants.cpp:90
static unsigned int semanticsPrecision(const fltSemantics &)
Definition: APFloat.cpp:136
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:132
8: Metadata
Definition: Type.h:64
AttributeSet getAttributes() const
Return the attribute list for this Function.
Definition: Function.h:176
ConstantArray - Constant Array Declarations.
Definition: Constants.h:411
Class for arbitrary precision integers.
Definition: APInt.h:77
static bool isWeak(const MCSymbolELF &Sym)
int compare()
Test whether the two functions have equivalent behaviour.
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
Definition: Module.cpp:384
int cmpConstants(const Constant *L, const Constant *R) const
Constants comparison.
unsigned getRawSubclassOptionalData() const
Return the raw optional flags value contained in this value.
Definition: Value.h:441
ImmutableCallSite - establish a view to a call site for examination.
Definition: CallSite.h:665
const std::string & getGC() const
Definition: Function.cpp:412
#define I(x, y, z)
Definition: MD5.cpp:54
TerminatorInst * getTerminator()
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
Definition: BasicBlock.cpp:124
FunctionType * getFunctionType() const
Returns the FunctionType for me.
Definition: Function.cpp:230
int cmpBasicBlocks(const BasicBlock *BBL, const BasicBlock *BBR) const
Test whether two basic blocks have equivalent behaviour.
unsigned getPointerSizeInBits(unsigned AS=0) const
Layout pointer size, in bits FIXME: The defaults need to be removed once all of the backends/clients ...
Definition: DataLayout.h:349
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Definition: Casting.h:287
unsigned getPointerAddressSpace() const
Method to return the address space of the pointer operand.
Definition: Operator.h:420
AttributeSet getAttributes(LLVMContext &C, ID id)
Return the attributes for an intrinsic.
bool isVarArg() const
Definition: DerivedTypes.h:122
3: 64-bit floating point type
Definition: Type.h:59
Type * getReturnType() const
Definition: DerivedTypes.h:123
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Function * getFunction() const
Definition: Constants.h:850
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:537
LLVM Value Representation.
Definition: Value.h:71
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
Definition: Instruction.h:111
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
Definition: Compiler.h:239
Invoke instruction.
#define DEBUG(X)
Definition: Debug.h:100
int cmpAPFloats(const APFloat &L, const APFloat &R) const
std::string Hash(const Unit &U)
Definition: FuzzerSHA1.cpp:216
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:47
static bool isVolatile(Instruction *Inst)
unsigned getNumElements() const
Random access to the elements.
Definition: DerivedTypes.h:289
bool isAlignStack() const
Definition: InlineAsm.h:69
bool isVarArg() const
isVarArg - Return true if this function takes a variable number of arguments.
Definition: Function.cpp:234
const fltSemantics & getSemantics() const
Definition: APFloat.h:1043
an instruction to allocate memory on the stack
Definition: Instructions.h:60
This instruction inserts a struct field of array element value into an aggregate value.
5: 128-bit floating point type (112-bit mantissa)
Definition: Type.h:61