<commit_before>//===--- Devirtualize.h - Helper for devirtualizing apply -------*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
//
// This contains helper functions that perform the work of devirtualizing a
// given apply when possible.
//
//===----------------------------------------------------------------------===//

#ifndef SWIFT_SIL_DEVIRTUALIZE_H
#define SWIFT_SIL_DEVIRTUALIZE_H

#include "swift/AST/Decl.h"
#include "swift/AST/Types.h"
#include "swift/SIL/SILDeclRef.h"
#include "swift/SIL/SILFunction.h"
#include "swift/SIL/SILInstruction.h"
#include "swift/SIL/SILModule.h"
#include "swift/SIL/SILType.h"
#include "swift/SIL/SILValue.h"
#include "swift/SILOptimizer/Analysis/ClassHierarchyAnalysis.h"
#include "swift/SILOptimizer/Utils/Local.h"
#include "llvm/ADT/ArrayRef.h"

namespace swift {
/// A pair representing results of devirtualization.
///  - The first element is the value representing the result of the
///    devirtualized call.
///  - The second element is the new apply/try_apply instruction.
/// If no devirtualization was possible, the pair:
/// <nullptr, FullApplySite()> is returned.
///
/// Two elements are required, because a result of the new devirtualized
/// apply/try_apply instruction (second element) eventually needs to be
/// casted to produce a properly typed value (first element).
typedef std::pair<ValueBase *, ApplySite> DevirtualizationResult;

DevirtualizationResult tryDevirtualizeApply(ApplySite AI,
                                            ClassHierarchyAnalysis *CHA);
bool canDevirtualizeApply(FullApplySite AI, ClassHierarchyAnalysis *CHA);
bool isNominalTypeWithUnboundGenericParameters(SILType Ty, SILModule &M);
bool canDevirtualizeClassMethod(FullApplySite AI, SILType ClassInstanceType);
SILFunction *getTargetClassMethod(SILModule &M, SILType ClassOrMetatypeType,
                                  MethodInst *MI);
DevirtualizationResult devirtualizeClassMethod(FullApplySite AI,
                                               SILValue ClassInstance);
DevirtualizationResult tryDevirtualizeClassMethod(FullApplySite AI,
                                                  SILValue ClassInstance);
DevirtualizationResult tryDevirtualizeWitnessMethod(ApplySite AI);
}

#endif<commit_msg>[gardening] Add a note to DevirtualizationResult explaining that it can contain an Argument.<commit_after>//===--- Devirtualize.h - Helper for devirtualizing apply -------*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
//
// This contains helper functions that perform the work of devirtualizing a
// given apply when possible.
//
//===----------------------------------------------------------------------===//

#ifndef SWIFT_SIL_DEVIRTUALIZE_H
#define SWIFT_SIL_DEVIRTUALIZE_H

#include "swift/AST/Decl.h"
#include "swift/AST/Types.h"
#include "swift/SIL/SILDeclRef.h"
#include "swift/SIL/SILFunction.h"
#include "swift/SIL/SILInstruction.h"
#include "swift/SIL/SILModule.h"
#include "swift/SIL/SILType.h"
#include "swift/SIL/SILValue.h"
#include "swift/SILOptimizer/Analysis/ClassHierarchyAnalysis.h"
#include "swift/SILOptimizer/Utils/Local.h"
#include "llvm/ADT/ArrayRef.h"

namespace swift {

/// A pair representing results of devirtualization.
///  - The first element is the value representing the result of the
///    devirtualized call.
///  - The second element is the new apply/try_apply instruction.
/// If no devirtualization was possible, the pair:
/// <nullptr, FullApplySite()> is returned.
///
/// Two elements are required, because a result of the new devirtualized
/// apply/try_apply instruction (second element) eventually needs to be
/// casted to produce a properly typed value (first element).
///
/// *NOTE* The reason why we use a ValueBase here instead of a SILInstruction is
/// that a devirtualization result may be a BB arg if there was a cast in
/// between optional types.
typedef std::pair<ValueBase *, ApplySite> DevirtualizationResult;

DevirtualizationResult tryDevirtualizeApply(ApplySite AI,
                                            ClassHierarchyAnalysis *CHA);
bool canDevirtualizeApply(FullApplySite AI, ClassHierarchyAnalysis *CHA);
bool isNominalTypeWithUnboundGenericParameters(SILType Ty, SILModule &M);
bool canDevirtualizeClassMethod(FullApplySite AI, SILType ClassInstanceType);
SILFunction *getTargetClassMethod(SILModule &M, SILType ClassOrMetatypeType,
                                  MethodInst *MI);
DevirtualizationResult devirtualizeClassMethod(FullApplySite AI,
                                               SILValue ClassInstance);
DevirtualizationResult tryDevirtualizeClassMethod(FullApplySite AI,
                                                  SILValue ClassInstance);
DevirtualizationResult tryDevirtualizeWitnessMethod(ApplySite AI);
}

#endif
{'fraction_non_alphanumeric': 0.14882553344091806, 'fraction_numerical': 0.0035861574323112783, 'mean_word_length': 2.779132791327913, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3010156', 'n_tokens_mistral': 1540, 'n_tokens_neox': 1471, 'n_words': 455}