CmpInstAnalysis.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. //===-- CmpInstAnalysis.h - Utils to help fold compare insts ----*- C++ -*-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file holds routines to help analyse compare instructions
  11. // and fold them into constants or other compare instructions
  12. //
  13. //===----------------------------------------------------------------------===//
  14. #ifndef LLVM_TRANSFORMS_UTILS_CMPINSTANALYSIS_H
  15. #define LLVM_TRANSFORMS_UTILS_CMPINSTANALYSIS_H
  16. #include "llvm/IR/InstrTypes.h"
  17. namespace llvm {
  18. class ICmpInst;
  19. class Value;
  20. /// getICmpCode - Encode a icmp predicate into a three bit mask. These bits
  21. /// are carefully arranged to allow folding of expressions such as:
  22. ///
  23. /// (A < B) | (A > B) --> (A != B)
  24. ///
  25. /// Note that this is only valid if the first and second predicates have the
  26. /// same sign. Is illegal to do: (A u< B) | (A s> B)
  27. ///
  28. /// Three bits are used to represent the condition, as follows:
  29. /// 0 A > B
  30. /// 1 A == B
  31. /// 2 A < B
  32. ///
  33. /// <=> Value Definition
  34. /// 000 0 Always false
  35. /// 001 1 A > B
  36. /// 010 2 A == B
  37. /// 011 3 A >= B
  38. /// 100 4 A < B
  39. /// 101 5 A != B
  40. /// 110 6 A <= B
  41. /// 111 7 Always true
  42. ///
  43. unsigned getICmpCode(const ICmpInst *ICI, bool InvertPred = false);
  44. /// getICmpValue - This is the complement of getICmpCode, which turns an
  45. /// opcode and two operands into either a constant true or false, or the
  46. /// predicate for a new ICmp instruction. The sign is passed in to determine
  47. /// which kind of predicate to use in the new icmp instruction.
  48. /// Non-NULL return value will be a true or false constant.
  49. /// NULL return means a new ICmp is needed. The predicate for which is
  50. /// output in NewICmpPred.
  51. Value *getICmpValue(bool Sign, unsigned Code, Value *LHS, Value *RHS,
  52. CmpInst::Predicate &NewICmpPred);
  53. /// PredicatesFoldable - Return true if both predicates match sign or if at
  54. /// least one of them is an equality comparison (which is signless).
  55. bool PredicatesFoldable(CmpInst::Predicate p1, CmpInst::Predicate p2);
  56. } // end namespace llvm
  57. #endif