<commit_before>//===-- llvm/ConstantRangesSet.h - The constant set of ranges ---*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
/// @file
/// This file contains class that implements constant set of ranges:
/// [<Low0,High0>,...,<LowN,HighN>]. Mainly, this set is used by SwitchInst and
/// represents case value that may contain multiple ranges for a single
/// successor.
///
//
//===----------------------------------------------------------------------===//

#ifndef CONSTANTRANGESSET_H_
#define CONSTANTRANGESSET_H_

#include "llvm/Constants.h"
#include "llvm/DerivedTypes.h"
#include "llvm/LLVMContext.h"

namespace llvm {
  
  // The IntItem is a wrapper for APInt.
  // 1. It determines sign of integer, it allows to use
  //    comparison operators >,<,>=,<=, and as result we got shorter and cleaner
  //    constructions.
  // 2. It helps to implement PR1255 (case ranges) as a series of small patches.
  // 3. Currently we can interpret IntItem both as ConstantInt and as APInt.
  //    It allows to provide SwitchInst methods that works with ConstantInt for
  //    non-updated passes. And it allows to use APInt interface for new methods.   
  // 4. IntItem can be easily replaced with APInt.
  
  // The set of macros that allows to propagate APInt operators to the IntItem. 

#define INT_ITEM_DEFINE_COMPARISON(op,func) \
  bool operator op (const APInt& RHS) const { \
    return ConstantIntVal->getValue().func(RHS); \
  }
  
#define INT_ITEM_DEFINE_UNARY_OP(op) \
  IntItem operator op () const { \
    APInt res = op(ConstantIntVal->getValue()); \
    Constant *NewVal = ConstantInt::get(ConstantIntVal->getContext(), res); \
    return IntItem(cast<ConstantInt>(NewVal)); \
  }
  
#define INT_ITEM_DEFINE_BINARY_OP(op) \
  IntItem operator op (const APInt& RHS) const { \
    APInt res = ConstantIntVal->getValue() op RHS; \
    Constant *NewVal = ConstantInt::get(ConstantIntVal->getContext(), res); \
    return IntItem(cast<ConstantInt>(NewVal)); \
  }
  
#define INT_ITEM_DEFINE_ASSIGNMENT_BY_OP(op) \
  IntItem& operator op (const APInt& RHS) {\
    APInt res = ConstantIntVal->getValue();\
    res op RHS; \
    Constant *NewVal = ConstantInt::get(ConstantIntVal->getContext(), res); \
    ConstantIntVal = cast<ConstantInt>(NewVal); \
    return *this; \
  }  
  
#define INT_ITEM_DEFINE_PREINCDEC(op) \
    IntItem& operator op () { \
      APInt res = ConstantIntVal->getValue(); \
      op(res); \
      Constant *NewVal = ConstantInt::get(ConstantIntVal->getContext(), res); \
      ConstantIntVal = cast<ConstantInt>(NewVal); \
      return *this; \
    }    

#define INT_ITEM_DEFINE_POSTINCDEC(op) \
    IntItem& operator op (int) { \
      APInt res = ConstantIntVal->getValue();\
      op(res); \
      Constant *NewVal = ConstantInt::get(ConstantIntVal->getContext(), res); \
      OldConstantIntVal = ConstantIntVal; \
      ConstantIntVal = cast<ConstantInt>(NewVal); \
      return IntItem(OldConstantIntVal); \
    }   
  
#define INT_ITEM_DEFINE_OP_STANDARD_INT(RetTy, op, IntTy) \
  RetTy operator op (IntTy RHS) const { \
    return (*this) op APInt(ConstantIntVal->getValue().getBitWidth(), RHS); \
  }  

class IntItem {
  ConstantInt *ConstantIntVal;
  IntItem(const ConstantInt *V) : ConstantIntVal(const_cast<ConstantInt*>(V)) {}
public:
  
  IntItem() {}
  
  operator const APInt&() const {
    return (const APInt&)ConstantIntVal->getValue();
  }  
  
  // Propogate APInt operators.
  // Note, that
  // /,/=,>>,>>= are not implemented in APInt.
  // <<= is implemented for unsigned RHS, but not implemented for APInt RHS.
  
  INT_ITEM_DEFINE_COMPARISON(<, ult);
  INT_ITEM_DEFINE_COMPARISON(>, ugt);
  INT_ITEM_DEFINE_COMPARISON(<=, ule);
  INT_ITEM_DEFINE_COMPARISON(>=, uge);
  INT_ITEM_DEFINE_COMPARISON(==, eq);
  INT_ITEM_DEFINE_COMPARISON(!=, ne);
  
  INT_ITEM_DEFINE_BINARY_OP(*);
  INT_ITEM_DEFINE_BINARY_OP(+);
  INT_ITEM_DEFINE_OP_STANDARD_INT(IntItem,+,uint64_t);
  INT_ITEM_DEFINE_BINARY_OP(-);
  INT_ITEM_DEFINE_OP_STANDARD_INT(IntItem,-,uint64_t);
  INT_ITEM_DEFINE_BINARY_OP(<<);
  INT_ITEM_DEFINE_OP_STANDARD_INT(IntItem,<<,unsigned);
  INT_ITEM_DEFINE_BINARY_OP(&);
  INT_ITEM_DEFINE_BINARY_OP(^);
  INT_ITEM_DEFINE_BINARY_OP(|);
  
  INT_ITEM_DEFINE_ASSIGNMENT_BY_OP(*=);
  INT_ITEM_DEFINE_ASSIGNMENT_BY_OP(+=);
  INT_ITEM_DEFINE_ASSIGNMENT_BY_OP(-=);
  INT_ITEM_DEFINE_ASSIGNMENT_BY_OP(&=);
  INT_ITEM_DEFINE_ASSIGNMENT_BY_OP(^=);
  INT_ITEM_DEFINE_ASSIGNMENT_BY_OP(|=);
  
  // Special case for <<=
  IntItem& operator <<= (unsigned RHS) {
    APInt res = ConstantIntVal->getValue();
    res <<= RHS;
    Constant *NewVal = ConstantInt::get(ConstantIntVal->getContext(), res);
    ConstantIntVal = cast<ConstantInt>(NewVal);
    return *this;    
  }
  
  INT_ITEM_DEFINE_UNARY_OP(-);
  INT_ITEM_DEFINE_UNARY_OP(~);
  
  INT_ITEM_DEFINE_PREINCDEC(++);
  INT_ITEM_DEFINE_PREINCDEC(--);
  
  // The set of workarounds, since currently we use ConstantInt implemented
  // integer.
  
  static IntItem fromConstantInt(const ConstantInt *V) {
    return IntItem(V);<commit_msg>Remove noisy semicolons.<commit_after>//===-- llvm/ConstantRangesSet.h - The constant set of ranges ---*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
/// @file
/// This file contains class that implements constant set of ranges:
/// [<Low0,High0>,...,<LowN,HighN>]. Mainly, this set is used by SwitchInst and
/// represents case value that may contain multiple ranges for a single
/// successor.
///
//
//===----------------------------------------------------------------------===//

#ifndef CONSTANTRANGESSET_H_
#define CONSTANTRANGESSET_H_

#include "llvm/Constants.h"
#include "llvm/DerivedTypes.h"
#include "llvm/LLVMContext.h"

namespace llvm {
  
  // The IntItem is a wrapper for APInt.
  // 1. It determines sign of integer, it allows to use
  //    comparison operators >,<,>=,<=, and as result we got shorter and cleaner
  //    constructions.
  // 2. It helps to implement PR1255 (case ranges) as a series of small patches.
  // 3. Currently we can interpret IntItem both as ConstantInt and as APInt.
  //    It allows to provide SwitchInst methods that works with ConstantInt for
  //    non-updated passes. And it allows to use APInt interface for new methods.   
  // 4. IntItem can be easily replaced with APInt.
  
  // The set of macros that allows to propagate APInt operators to the IntItem. 

#define INT_ITEM_DEFINE_COMPARISON(op,func) \
  bool operator op (const APInt& RHS) const { \
    return ConstantIntVal->getValue().func(RHS); \
  }
  
#define INT_ITEM_DEFINE_UNARY_OP(op) \
  IntItem operator op () const { \
    APInt res = op(ConstantIntVal->getValue()); \
    Constant *NewVal = ConstantInt::get(ConstantIntVal->getContext(), res); \
    return IntItem(cast<ConstantInt>(NewVal)); \
  }
  
#define INT_ITEM_DEFINE_BINARY_OP(op) \
  IntItem operator op (const APInt& RHS) const { \
    APInt res = ConstantIntVal->getValue() op RHS; \
    Constant *NewVal = ConstantInt::get(ConstantIntVal->getContext(), res); \
    return IntItem(cast<ConstantInt>(NewVal)); \
  }
  
#define INT_ITEM_DEFINE_ASSIGNMENT_BY_OP(op) \
  IntItem& operator op (const APInt& RHS) {\
    APInt res = ConstantIntVal->getValue();\
    res op RHS; \
    Constant *NewVal = ConstantInt::get(ConstantIntVal->getContext(), res); \
    ConstantIntVal = cast<ConstantInt>(NewVal); \
    return *this; \
  }  
  
#define INT_ITEM_DEFINE_PREINCDEC(op) \
    IntItem& operator op () { \
      APInt res = ConstantIntVal->getValue(); \
      op(res); \
      Constant *NewVal = ConstantInt::get(ConstantIntVal->getContext(), res); \
      ConstantIntVal = cast<ConstantInt>(NewVal); \
      return *this; \
    }    

#define INT_ITEM_DEFINE_POSTINCDEC(op) \
    IntItem& operator op (int) { \
      APInt res = ConstantIntVal->getValue();\
      op(res); \
      Constant *NewVal = ConstantInt::get(ConstantIntVal->getContext(), res); \
      OldConstantIntVal = ConstantIntVal; \
      ConstantIntVal = cast<ConstantInt>(NewVal); \
      return IntItem(OldConstantIntVal); \
    }   
  
#define INT_ITEM_DEFINE_OP_STANDARD_INT(RetTy, op, IntTy) \
  RetTy operator op (IntTy RHS) const { \
    return (*this) op APInt(ConstantIntVal->getValue().getBitWidth(), RHS); \
  }  

class IntItem {
  ConstantInt *ConstantIntVal;
  IntItem(const ConstantInt *V) : ConstantIntVal(const_cast<ConstantInt*>(V)) {}
public:
  
  IntItem() {}
  
  operator const APInt&() const {
    return (const APInt&)ConstantIntVal->getValue();
  }  
  
  // Propogate APInt operators.
  // Note, that
  // /,/=,>>,>>= are not implemented in APInt.
  // <<= is implemented for unsigned RHS, but not implemented for APInt RHS.
  
  INT_ITEM_DEFINE_COMPARISON(<, ult)
  INT_ITEM_DEFINE_COMPARISON(>, ugt)
  INT_ITEM_DEFINE_COMPARISON(<=, ule)
  INT_ITEM_DEFINE_COMPARISON(>=, uge)
  INT_ITEM_DEFINE_COMPARISON(==, eq)
  INT_ITEM_DEFINE_COMPARISON(!=, ne)
  
  INT_ITEM_DEFINE_BINARY_OP(*)
  INT_ITEM_DEFINE_BINARY_OP(+)
  INT_ITEM_DEFINE_OP_STANDARD_INT(IntItem,+,uint64_t)
  INT_ITEM_DEFINE_BINARY_OP(-)
  INT_ITEM_DEFINE_OP_STANDARD_INT(IntItem,-,uint64_t)
  INT_ITEM_DEFINE_BINARY_OP(<<)
  INT_ITEM_DEFINE_OP_STANDARD_INT(IntItem,<<,unsigned)
  INT_ITEM_DEFINE_BINARY_OP(&)
  INT_ITEM_DEFINE_BINARY_OP(^)
  INT_ITEM_DEFINE_BINARY_OP(|)
  
  INT_ITEM_DEFINE_ASSIGNMENT_BY_OP(*=)
  INT_ITEM_DEFINE_ASSIGNMENT_BY_OP(+=)
  INT_ITEM_DEFINE_ASSIGNMENT_BY_OP(-=)
  INT_ITEM_DEFINE_ASSIGNMENT_BY_OP(&=)
  INT_ITEM_DEFINE_ASSIGNMENT_BY_OP(^=)
  INT_ITEM_DEFINE_ASSIGNMENT_BY_OP(|=)
  
  // Special case for <<=
  IntItem& operator <<= (unsigned RHS) {
    APInt res = ConstantIntVal->getValue();
    res <<= RHS;
    Constant *NewVal = ConstantInt::get(ConstantIntVal->getContext(), res);
    ConstantIntVal = cast<ConstantInt>(NewVal);
    return *this;    
  }
  
  INT_ITEM_DEFINE_UNARY_OP(-)
  INT_ITEM_DEFINE_UNARY_OP(~)
  
  INT_ITEM_DEFINE_PREINCDEC(++)
  INT_ITEM_DEFINE_PREINCDEC(--)
  
  // The set of workarounds, since currently we use ConstantInt implemented
  // integer.
  
  static IntItem fromConstantInt(const ConstantInt *V) {
    return IntItem(V);
{'fraction_non_alphanumeric': 0.15163584637268848, 'fraction_numerical': 0.0026552868658131818, 'mean_word_length': 3.2489927477840452, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 67, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1350768', 'n_tokens_mistral': 3600, 'n_tokens_neox': 3476, 'n_words': 797}