LLVM 17.0.0git
Classes | Namespaces | Macros | Enumerations | Functions | Variables
WholeProgramDevirt.cpp File Reference
#include "llvm/Transforms/IPO/WholeProgramDevirt.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/DenseMapInfo.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/MapVector.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/ADT/iterator_range.h"
#include "llvm/Analysis/AssumptionCache.h"
#include "llvm/Analysis/BasicAliasAnalysis.h"
#include "llvm/Analysis/OptimizationRemarkEmitter.h"
#include "llvm/Analysis/TypeMetadataUtils.h"
#include "llvm/Bitcode/BitcodeReader.h"
#include "llvm/Bitcode/BitcodeWriter.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/DebugLoc.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/GlobalAlias.h"
#include "llvm/IR/GlobalVariable.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/InstrTypes.h"
#include "llvm/IR/Instruction.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/Intrinsics.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/MDBuilder.h"
#include "llvm/IR/Metadata.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/ModuleSummaryIndexYAML.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Errc.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/GlobPattern.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/TargetParser/Triple.h"
#include "llvm/Transforms/IPO.h"
#include "llvm/Transforms/IPO/FunctionAttrs.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include "llvm/Transforms/Utils/CallPromotionUtils.h"
#include "llvm/Transforms/Utils/Evaluator.h"
#include <algorithm>
#include <cstddef>
#include <map>
#include <set>
#include <string>

Go to the source code of this file.

Classes

struct  llvm::DenseMapInfo< VTableSlot >
 
struct  llvm::DenseMapInfo< VTableSlotSummary >
 

Namespaces

namespace  llvm
 This is an optimization pass for GlobalISel generic memory operations.
 

Macros

#define DEBUG_TYPE   "wholeprogramdevirt"
 

Enumerations

enum  WPDCheckMode { None , Trap , Fallback }
 Mechanism to add runtime checking of devirtualization decisions, optionally trapping or falling back to indirect call on any that are not correct. More...
 

Functions

 STATISTIC (NumDevirtTargets, "Number of whole program devirtualization targets")
 
 STATISTIC (NumSingleImpl, "Number of single implementation devirtualizations")
 
 STATISTIC (NumBranchFunnel, "Number of branch funnels")
 
 STATISTIC (NumUniformRetVal, "Number of uniform return value optimizations")
 
 STATISTIC (NumUniqueRetVal, "Number of unique return value optimizations")
 
 STATISTIC (NumVirtConstProp1Bit, "Number of 1 bit virtual constant propagations")
 
 STATISTIC (NumVirtConstProp, "Number of virtual constant propagations")
 
bool llvm::hasWholeProgramVisibility (bool WholeProgramVisibilityEnabledInLTO)
 
void llvm::updateVCallVisibilityInModule (Module &M, bool WholeProgramVisibilityEnabledInLTO, const DenseSet< GlobalValue::GUID > &DynamicExportSymbols)
 If whole program visibility asserted, then upgrade all public vcall visibility metadata on vtable definitions to linkage unit visibility in Module IR (for regular or hybrid LTO).
 
void llvm::updatePublicTypeTestCalls (Module &M, bool WholeProgramVisibilityEnabledInLTO)
 
void llvm::updateVCallVisibilityInIndex (ModuleSummaryIndex &Index, bool WholeProgramVisibilityEnabledInLTO, const DenseSet< GlobalValue::GUID > &DynamicExportSymbols)
 If whole program visibility asserted, then upgrade all public vcall visibility metadata on vtable definition summaries to linkage unit visibility in Module summary index (for ThinLTO).
 
void llvm::runWholeProgramDevirtOnIndex (ModuleSummaryIndex &Summary, std::set< GlobalValue::GUID > &ExportedGUIDs, std::map< ValueInfo, std::vector< VTableSlotSummary > > &LocalWPDTargetsMap)
 Perform index-based whole program devirtualization on the Summary index.
 
void llvm::updateIndexWPDForExports (ModuleSummaryIndex &Summary, function_ref< bool(StringRef, ValueInfo)> isExported, std::map< ValueInfo, std::vector< VTableSlotSummary > > &LocalWPDTargetsMap)
 Call after cross-module importing to update the recorded single impl devirt target names for any locals that were exported.
 
static Error checkCombinedSummaryForTesting (ModuleSummaryIndex *Summary)
 
static bool AddCalls (VTableSlotInfo &SlotInfo, const ValueInfo &Callee)
 

Variables

static cl::opt< PassSummaryActionClSummaryAction ("wholeprogramdevirt-summary-action", cl::desc("What to do with the summary when running this pass"), cl::values(clEnumValN(PassSummaryAction::None, "none", "Do nothing"), clEnumValN(PassSummaryAction::Import, "import", "Import typeid resolutions from summary and globals"), clEnumValN(PassSummaryAction::Export, "export", "Export typeid resolutions to summary and globals")), cl::Hidden)
 
static cl::opt< std::string > ClReadSummary ("wholeprogramdevirt-read-summary", cl::desc("Read summary from given bitcode or YAML file before running pass"), cl::Hidden)
 
static cl::opt< std::string > ClWriteSummary ("wholeprogramdevirt-write-summary", cl::desc("Write summary to given bitcode or YAML file after running pass. " "Output file format is deduced from extension: *.bc means writing " "bitcode, otherwise YAML"), cl::Hidden)
 
static cl::opt< unsignedClThreshold ("wholeprogramdevirt-branch-funnel-threshold", cl::Hidden, cl::init(10), cl::desc("Maximum number of call targets per " "call site to enable branch funnels"))
 
static cl::opt< boolPrintSummaryDevirt ("wholeprogramdevirt-print-index-based", cl::Hidden, cl::desc("Print index-based devirtualization messages"))
 
static cl::opt< boolWholeProgramVisibility ("whole-program-visibility", cl::Hidden, cl::desc("Enable whole program visibility"))
 Provide a way to force enable whole program visibility in tests.
 
static cl::opt< boolDisableWholeProgramVisibility ("disable-whole-program-visibility", cl::Hidden, cl::desc("Disable whole program visibility (overrides enabling options)"))
 Provide a way to force disable whole program for debugging or workarounds, when enabled via the linker.
 
static cl::list< std::string > SkipFunctionNames ("wholeprogramdevirt-skip", cl::desc("Prevent function(s) from being devirtualized"), cl::Hidden, cl::CommaSeparated)
 Provide way to prevent certain function from being devirtualized.
 
static cl::opt< WPDCheckModeDevirtCheckMode ("wholeprogramdevirt-check", cl::Hidden, cl::desc("Type of checking for incorrect devirtualizations"), cl::values(clEnumValN(WPDCheckMode::None, "none", "No checking"), clEnumValN(WPDCheckMode::Trap, "trap", "Trap when incorrect"), clEnumValN(WPDCheckMode::Fallback, "fallback", "Fallback to indirect when incorrect")))
 

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "wholeprogramdevirt"

Definition at line 108 of file WholeProgramDevirt.cpp.

Enumeration Type Documentation

◆ WPDCheckMode

Mechanism to add runtime checking of devirtualization decisions, optionally trapping or falling back to indirect call on any that are not correct.

Trapping mode is useful for debugging undefined behavior leading to failures with WPD. Fallback mode is useful for ensuring safety when whole program visibility may be compromised.

Enumerator
None 
Trap 
Fallback 

Definition at line 177 of file WholeProgramDevirt.cpp.

Function Documentation

◆ AddCalls()

static bool AddCalls ( VTableSlotInfo &  SlotInfo,
const ValueInfo Callee 
)
static

Definition at line 1183 of file WholeProgramDevirt.cpp.

References AddCalls(), Callee, llvm::CalleeInfo::Hot, and P.

Referenced by AddCalls().

◆ checkCombinedSummaryForTesting()

static Error checkCombinedSummaryForTesting ( ModuleSummaryIndex Summary)
static

◆ STATISTIC() [1/7]

STATISTIC ( NumBranchFunnel  ,
"Number of branch funnels"   
)

◆ STATISTIC() [2/7]

STATISTIC ( NumDevirtTargets  ,
"Number of whole program devirtualization targets"   
)

◆ STATISTIC() [3/7]

STATISTIC ( NumSingleImpl  ,
"Number of single implementation devirtualizations"   
)

◆ STATISTIC() [4/7]

STATISTIC ( NumUniformRetVal  ,
"Number of uniform return value optimizations"   
)

◆ STATISTIC() [5/7]

STATISTIC ( NumUniqueRetVal  ,
"Number of unique return value optimizations"   
)

◆ STATISTIC() [6/7]

STATISTIC ( NumVirtConstProp  ,
"Number of virtual constant propagations"   
)

◆ STATISTIC() [7/7]

STATISTIC ( NumVirtConstProp1Bit  ,
"Number of 1 bit virtual constant propagations"   
)

Variable Documentation

◆ ClReadSummary

cl::opt< std::string > ClReadSummary("wholeprogramdevirt-read-summary", cl::desc( "Read summary from given bitcode or YAML file before running pass"), cl::Hidden) ( "wholeprogramdevirt-read-summary"  ,
cl::desc( "Read summary from given bitcode or YAML file before running pass")  ,
cl::Hidden   
)
static

◆ ClSummaryAction

cl::opt< PassSummaryAction > ClSummaryAction("wholeprogramdevirt-summary-action", cl::desc("What to do with the summary when running this pass"), cl::values(clEnumValN(PassSummaryAction::None, "none", "Do nothing"), clEnumValN(PassSummaryAction::Import, "import", "Import typeid resolutions from summary and globals"), clEnumValN(PassSummaryAction::Export, "export", "Export typeid resolutions to summary and globals")), cl::Hidden) ( "wholeprogramdevirt-summary-action"  ,
cl::desc("What to do with the summary when running this pass")  ,
cl::values(clEnumValN(PassSummaryAction::None, "none", "Do nothing"), clEnumValN(PassSummaryAction::Import, "import", "Import typeid resolutions from summary and globals"), clEnumValN(PassSummaryAction::Export, "export", "Export typeid resolutions to summary and globals"))  ,
cl::Hidden   
)
static

◆ ClThreshold

cl::opt< unsigned > ClThreshold("wholeprogramdevirt-branch-funnel-threshold", cl::Hidden, cl::init(10), cl::desc("Maximum number of call targets per " "call site to enable branch funnels")) ( "wholeprogramdevirt-branch-funnel-threshold"  ,
cl::Hidden  ,
cl::init(10)  ,
cl::desc("Maximum number of call targets per " "call site to enable branch funnels")   
)
static

◆ ClWriteSummary

cl::opt< std::string > ClWriteSummary("wholeprogramdevirt-write-summary", cl::desc("Write summary to given bitcode or YAML file after running pass. " "Output file format is deduced from extension: *.bc means writing " "bitcode, otherwise YAML"), cl::Hidden) ( "wholeprogramdevirt-write-summary"  ,
cl::desc("Write summary to given bitcode or YAML file after running pass. " "Output file format is deduced from extension: *.bc means writing " "bitcode, otherwise YAML")  ,
cl::Hidden   
)
static

◆ DevirtCheckMode

cl::opt< WPDCheckMode > DevirtCheckMode("wholeprogramdevirt-check", cl::Hidden, cl::desc("Type of checking for incorrect devirtualizations"), cl::values(clEnumValN(WPDCheckMode::None, "none", "No checking"), clEnumValN(WPDCheckMode::Trap, "trap", "Trap when incorrect"), clEnumValN(WPDCheckMode::Fallback, "fallback", "Fallback to indirect when incorrect"))) ( "wholeprogramdevirt-check"  ,
cl::Hidden  ,
cl::desc("Type of checking for incorrect devirtualizations")  ,
cl::values(clEnumValN(WPDCheckMode::None, "none", "No checking"), clEnumValN(WPDCheckMode::Trap, "trap", "Trap when incorrect"), clEnumValN(WPDCheckMode::Fallback, "fallback", "Fallback to indirect when incorrect"))   
)
static

◆ DisableWholeProgramVisibility

cl::opt< bool > DisableWholeProgramVisibility("disable-whole-program-visibility", cl::Hidden, cl::desc("Disable whole program visibility (overrides enabling options)")) ( "disable-whole-program-visibility"  ,
cl::Hidden  ,
cl::desc("Disable whole program visibility (overrides enabling options)")   
)
static

Provide a way to force disable whole program for debugging or workarounds, when enabled via the linker.

Referenced by llvm::hasWholeProgramVisibility().

◆ PrintSummaryDevirt

cl::opt< bool > PrintSummaryDevirt("wholeprogramdevirt-print-index-based", cl::Hidden, cl::desc("Print index-based devirtualization messages")) ( "wholeprogramdevirt-print-index-based"  ,
cl::Hidden  ,
cl::desc("Print index-based devirtualization messages")   
)
static

◆ SkipFunctionNames

cl::list< std::string > SkipFunctionNames("wholeprogramdevirt-skip", cl::desc("Prevent function(s) from being devirtualized"), cl::Hidden, cl::CommaSeparated) ( "wholeprogramdevirt-skip"  ,
cl::desc("Prevent function(s) from being devirtualized")  ,
cl::Hidden  ,
cl::CommaSeparated   
)
static

Provide way to prevent certain function from being devirtualized.

◆ WholeProgramVisibility

cl::opt< bool > WholeProgramVisibility("whole-program-visibility", cl::Hidden, cl::desc("Enable whole program visibility")) ( "whole-program-visibility"  ,
cl::Hidden  ,
cl::desc("Enable whole program visibility")   
)
static

Provide a way to force enable whole program visibility in tests.

This is needed to support legacy tests that don't contain !vcall_visibility metadata (the mere presense of type tests previously implied hidden visibility).

Referenced by llvm::hasWholeProgramVisibility().