<commit_before>//===---- CGBuiltin.cpp - Emit LLVM Code for builtins ---------------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This contains code to emit Builtin calls as LLVM code.
//
//===----------------------------------------------------------------------===//

#include "CodeGenFunction.h"
#include "CodeGenModule.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/AST/APValue.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/Decl.h"
#include "clang/AST/TargetBuiltins.h"
#include "llvm/Intrinsics.h"
using namespace clang;
using namespace CodeGen;
using namespace llvm;

/// Utility to insert an atomic instruction based Instrinsic::ID and
// the expression node
static RValue EmitBinaryAtomic(CodeGenFunction& CFG, 
                               Intrinsic::ID Id, const CallExpr *E) {
  const llvm::Type *ResType[2];
  ResType[0] = CFG.ConvertType(E->getType());
  ResType[1] = CFG.ConvertType(E->getArg(0)->getType());
  Value *AtomF = CFG.CGM.getIntrinsic(Id, ResType, 2);
  return RValue::get(CFG.Builder.CreateCall2(AtomF,
                                             CFG.EmitScalarExpr(E->getArg(0)),
                                             CFG.EmitScalarExpr(E->getArg(1))));
}

RValue CodeGenFunction::EmitBuiltinExpr(unsigned BuiltinID, const CallExpr *E) {
  switch (BuiltinID) {
  default: break;  // Handle intrinsics and libm functions below.
      
  case Builtin::BI__builtin_huge_val:
  case Builtin::BI__builtin_huge_valf:
  case Builtin::BI__builtin_huge_vall:
  case Builtin::BI__builtin_inf:
  case Builtin::BI__builtin_inff:
  case Builtin::BI__builtin_infl:
  case Builtin::BI__builtin_nan:
  case Builtin::BI__builtin_nanf:
  case Builtin::BI__builtin_nanl:
  case Builtin::BI__builtin_classify_type:
  case Builtin::BI__builtin_constant_p: {
    APValue Result;
    if (!E->tryEvaluate(Result, CGM.getContext()))
      break;  // Not a constant, expand below.
    
    if (Result.isInt())
      return RValue::get(llvm::ConstantInt::get(Result.getInt()));
    assert(Result.isFloat() && "Unsupported constant type");
    return RValue::get(llvm::ConstantFP::get(Result.getFloat()));
  }
      
  case Builtin::BI__builtin___CFStringMakeConstantString: {
    const Expr *Arg = E->getArg(0);<commit_msg>always try to fold a builtin before emitting it.  In the future it is possible that a builtin could sometimes be folded (e.g. __builtin_clz) if it's operand is a constant.<commit_after>//===---- CGBuiltin.cpp - Emit LLVM Code for builtins ---------------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This contains code to emit Builtin calls as LLVM code.
//
//===----------------------------------------------------------------------===//

#include "CodeGenFunction.h"
#include "CodeGenModule.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/AST/APValue.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/Decl.h"
#include "clang/AST/TargetBuiltins.h"
#include "llvm/Intrinsics.h"
using namespace clang;
using namespace CodeGen;
using namespace llvm;

/// Utility to insert an atomic instruction based Instrinsic::ID and
// the expression node
static RValue EmitBinaryAtomic(CodeGenFunction& CFG, 
                               Intrinsic::ID Id, const CallExpr *E) {
  const llvm::Type *ResType[2];
  ResType[0] = CFG.ConvertType(E->getType());
  ResType[1] = CFG.ConvertType(E->getArg(0)->getType());
  Value *AtomF = CFG.CGM.getIntrinsic(Id, ResType, 2);
  return RValue::get(CFG.Builder.CreateCall2(AtomF,
                                             CFG.EmitScalarExpr(E->getArg(0)),
                                             CFG.EmitScalarExpr(E->getArg(1))));
}

RValue CodeGenFunction::EmitBuiltinExpr(unsigned BuiltinID, const CallExpr *E) {
  // See if we can constant fold this builtin.  If so, don't emit it at all.
  APValue Result;
  if (E->tryEvaluate(Result, CGM.getContext())) {
    if (Result.isInt())
      return RValue::get(llvm::ConstantInt::get(Result.getInt()));
    assert(Result.isFloat() && "Unsupported constant type");
    return RValue::get(llvm::ConstantFP::get(Result.getFloat()));
  }
      
  switch (BuiltinID) {
  default: break;  // Handle intrinsics and libm functions below.
  case Builtin::BI__builtin___CFStringMakeConstantString: {
    const Expr *Arg = E->getArg(0);
{'fraction_non_alphanumeric': 0.19367088607594937, 'fraction_numerical': 0.0037974683544303796, 'mean_word_length': 2.5092524056254626, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4479709', 'n_tokens_mistral': 1421, 'n_tokens_neox': 1427, 'n_words': 343}