LLVM 17.0.0git
Macros | Functions | Variables
DwarfEHPrepare.cpp File Reference
#include "llvm/ADT/BitVector.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Analysis/CFG.h"
#include "llvm/Analysis/DomTreeUpdater.h"
#include "llvm/Analysis/TargetTransformInfo.h"
#include "llvm/CodeGen/RuntimeLibcalls.h"
#include "llvm/CodeGen/StackProtector.h"
#include "llvm/CodeGen/TargetLowering.h"
#include "llvm/CodeGen/TargetPassConfig.h"
#include "llvm/CodeGen/TargetSubtargetInfo.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DebugInfoMetadata.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/EHPersonalities.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Type.h"
#include "llvm/InitializePasses.h"
#include "llvm/Pass.h"
#include "llvm/Support/Casting.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/TargetParser/Triple.h"
#include "llvm/Transforms/Utils/Local.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include <cstddef>
Include dependency graph for DwarfEHPrepare.cpp:

Go to the source code of this file.

Macros

#define DEBUG_TYPE   "dwarfehprepare"
 

Functions

 STATISTIC (NumResumesLowered, "Number of resume calls lowered")
 
 STATISTIC (NumCleanupLandingPadsUnreachable, "Number of cleanup landing pads found unreachable")
 
 STATISTIC (NumCleanupLandingPadsRemaining, "Number of cleanup landing pads remaining")
 
 STATISTIC (NumNoUnwind, "Number of functions with nounwind")
 
 STATISTIC (NumUnwind, "Number of functions with unwind")
 
static void addCleanupResumeToLandingPad (BasicBlock &BB, DomTreeUpdater *DTU)
 If a landingpad block doesn't already have a cleanup case, add one that feeds directly into a resume instruction.
 
static BasicBlockcreateCleanupResumeBB (Function &F, Type *LandingPadTy)
 Create a basic block that has a landingpad instruction feeding directly into a resume.
 
static void changeCallToInvokeResume (CallInst &CI, BasicBlock *CleanupResumeBB, DomTreeUpdater *DTU)
 Convert a call that might throw into an invoke that unwinds to the specified simple landingpad/resume block.
 
static void addCleanupPathsForStackProtector (Function &F, DomTreeUpdater *DTU)
 Ensure that any call in this function that might throw has an associated cleanup/resume that the stack protector can instrument later.
 
static bool prepareDwarfEH (CodeGenOpt::Level OptLevel, Function &F, const TargetLowering &TLI, DominatorTree *DT, const TargetTransformInfo *TTI, const Triple &TargetTriple)
 
 INITIALIZE_PASS_BEGIN (DwarfEHPrepareLegacyPass, DEBUG_TYPE, "Prepare DWARF exceptions", false, false) INITIALIZE_PASS_END(DwarfEHPrepareLegacyPass
 

Variables

 DEBUG_TYPE
 
Prepare DWARF exceptions
 
Prepare DWARF false
 

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "dwarfehprepare"

Definition at line 47 of file DwarfEHPrepare.cpp.

Function Documentation

◆ addCleanupPathsForStackProtector()

static void addCleanupPathsForStackProtector ( Function F,
DomTreeUpdater DTU 
)
static

Ensure that any call in this function that might throw has an associated cleanup/resume that the stack protector can instrument later.

Existing invokes will get an added cleanup clause if needed, calls will be converted to an invoke with trivial unwind followup.

Definition at line 256 of file DwarfEHPrepare.cpp.

References addCleanupResumeToLandingPad(), changeCallToInvokeResume(), createCleanupResumeBB(), llvm::CallBase::doesNotThrow(), F, llvm::BasicBlock::getLandingPadInst(), I, and llvm::CallInst::isTailCall().

◆ addCleanupResumeToLandingPad()

static void addCleanupResumeToLandingPad ( BasicBlock BB,
DomTreeUpdater DTU 
)
static

◆ changeCallToInvokeResume()

static void changeCallToInvokeResume ( CallInst CI,
BasicBlock CleanupResumeBB,
DomTreeUpdater DTU 
)
static

◆ createCleanupResumeBB()

static BasicBlock * createCleanupResumeBB ( Function F,
Type LandingPadTy 
)
static

Create a basic block that has a landingpad instruction feeding directly into a resume.

Will be set to the unwind destination of a new invoke.

Definition at line 207 of file DwarfEHPrepare.cpp.

References B, llvm::BasicBlock::Create(), F, llvm::IntegerType::get(), llvm::StructType::get(), llvm::Type::getInt8PtrTy(), and llvm::LandingPadInst::setCleanup().

Referenced by addCleanupPathsForStackProtector().

◆ INITIALIZE_PASS_BEGIN()

INITIALIZE_PASS_BEGIN ( DwarfEHPrepareLegacyPass  ,
DEBUG_TYPE  ,
"Prepare DWARF exceptions"  ,
false  ,
false   
)

◆ prepareDwarfEH()

static bool prepareDwarfEH ( CodeGenOpt::Level  OptLevel,
Function F,
const TargetLowering TLI,
DominatorTree DT,
const TargetTransformInfo TTI,
const Triple TargetTriple 
)
static

Definition at line 444 of file DwarfEHPrepare.cpp.

References F.

◆ STATISTIC() [1/5]

STATISTIC ( NumCleanupLandingPadsRemaining  ,
"Number of cleanup landing pads remaining"   
)

◆ STATISTIC() [2/5]

STATISTIC ( NumCleanupLandingPadsUnreachable  ,
"Number of cleanup landing pads found unreachable"   
)

◆ STATISTIC() [3/5]

STATISTIC ( NumNoUnwind  ,
"Number of functions with nounwind"   
)

◆ STATISTIC() [4/5]

STATISTIC ( NumResumesLowered  ,
"Number of resume calls lowered"   
)

◆ STATISTIC() [5/5]

STATISTIC ( NumUnwind  ,
"Number of functions with unwind"   
)

References F.

Variable Documentation

◆ DEBUG_TYPE

DEBUG_TYPE

Definition at line 507 of file DwarfEHPrepare.cpp.

◆ exceptions

Prepare DWARF exceptions

Definition at line 508 of file DwarfEHPrepare.cpp.

◆ false

Prepare DWARF false

Definition at line 508 of file DwarfEHPrepare.cpp.