Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions llvm/include/llvm/CodeGen/MIRYamlMapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@ struct MachineFunction {

bool CallsEHReturn = false;
bool CallsUnwindInit = false;
bool HasEHCatchret = false;
bool HasEHContTarget = false;
bool HasEHScopes = false;
bool HasEHFunclets = false;
bool IsOutlined = false;
Expand Down Expand Up @@ -810,7 +810,7 @@ template <> struct MappingTraits<MachineFunction> {

YamlIO.mapOptional("callsEHReturn", MF.CallsEHReturn, false);
YamlIO.mapOptional("callsUnwindInit", MF.CallsUnwindInit, false);
YamlIO.mapOptional("hasEHCatchret", MF.HasEHCatchret, false);
YamlIO.mapOptional("hasEHContTarget", MF.HasEHContTarget, false);
YamlIO.mapOptional("hasEHScopes", MF.HasEHScopes, false);
YamlIO.mapOptional("hasEHFunclets", MF.HasEHFunclets, false);
YamlIO.mapOptional("isOutlined", MF.IsOutlined, false);
Expand Down
20 changes: 10 additions & 10 deletions llvm/include/llvm/CodeGen/MachineBasicBlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ class MachineBasicBlock
/// LLVM IR.
bool IsEHScopeEntry = false;

/// Indicates if this is a target block of a catchret.
bool IsEHCatchretTarget = false;
/// Indicates if this is a target of Windows EH Continuation Guard.
bool IsEHContTarget = false;

/// Indicate that this basic block is the entry block of an EH funclet.
bool IsEHFuncletEntry = false;
Expand Down Expand Up @@ -234,8 +234,8 @@ class MachineBasicBlock
/// is only computed once and is cached.
mutable MCSymbol *CachedMCSymbol = nullptr;

/// Cached MCSymbol for this block (used if IsEHCatchRetTarget).
mutable MCSymbol *CachedEHCatchretMCSymbol = nullptr;
/// Cached MCSymbol for this block (used if IsEHContTarget).
mutable MCSymbol *CachedEHContMCSymbol = nullptr;

/// Marks the end of the basic block. Used during basic block sections to
/// calculate the size of the basic block, or the BB section ending with it.
Expand Down Expand Up @@ -652,11 +652,11 @@ class MachineBasicBlock
/// that used to have a catchpad or cleanuppad instruction in the LLVM IR.
void setIsEHScopeEntry(bool V = true) { IsEHScopeEntry = V; }

/// Returns true if this is a target block of a catchret.
bool isEHCatchretTarget() const { return IsEHCatchretTarget; }
/// Returns true if this is a target of Windows EH Continuation Guard.
bool isEHContTarget() const { return IsEHContTarget; }

/// Indicates if this is a target block of a catchret.
void setIsEHCatchretTarget(bool V = true) { IsEHCatchretTarget = V; }
/// Indicates if this is a target of Windows EH Continuation Guard.
void setIsEHContTarget(bool V = true) { IsEHContTarget = V; }

/// Returns true if this is the entry block of an EH funclet.
bool isEHFuncletEntry() const { return IsEHFuncletEntry; }
Expand Down Expand Up @@ -1238,8 +1238,8 @@ class MachineBasicBlock
/// Return the MCSymbol for this basic block.
MCSymbol *getSymbol() const;

/// Return the EHCatchret Symbol for this basic block.
MCSymbol *getEHCatchretSymbol() const;
/// Return the Windows EH Continuation Symbol for this basic block.
MCSymbol *getEHContSymbol() const;

std::optional<uint64_t> getIrrLoopHeaderWeight() const {
return IrrLoopHeaderWeight;
Expand Down
28 changes: 13 additions & 15 deletions llvm/include/llvm/CodeGen/MachineFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,9 @@ class LLVM_ABI MachineFunction {
/// construct a table of valid longjmp targets for Windows Control Flow Guard.
std::vector<MCSymbol *> LongjmpTargets;

/// List of basic blocks that are the target of catchrets. Used to construct
/// a table of valid targets for Windows EHCont Guard.
std::vector<MCSymbol *> CatchretTargets;
/// List of basic blocks that are the targets for Windows EH Continuation
/// Guard.
std::vector<MCSymbol *> EHContTargets;

/// \name Exception Handling
/// \{
Expand All @@ -383,7 +383,7 @@ class LLVM_ABI MachineFunction {

bool CallsEHReturn = false;
bool CallsUnwindInit = false;
bool HasEHCatchret = false;
bool HasEHContTarget = false;
bool HasEHScopes = false;
bool HasEHFunclets = false;
bool HasFakeUses = false;
Expand Down Expand Up @@ -1197,17 +1197,15 @@ class LLVM_ABI MachineFunction {
/// Control Flow Guard.
void addLongjmpTarget(MCSymbol *Target) { LongjmpTargets.push_back(Target); }

/// Returns a reference to a list of symbols that we have catchrets.
/// Used to construct the catchret target table used by Windows EHCont Guard.
const std::vector<MCSymbol *> &getCatchretTargets() const {
return CatchretTargets;
/// Returns a reference to a list of symbols that are targets for Windows
/// EH Continuation Guard.
const std::vector<MCSymbol *> &getEHContTargets() const {
return EHContTargets;
}

/// Add the specified symbol to the list of valid catchret targets for Windows
/// EHCont Guard.
void addCatchretTarget(MCSymbol *Target) {
CatchretTargets.push_back(Target);
}
/// Add the specified symbol to the list of targets for Windows EH
/// Continuation Guard.
void addEHContTarget(MCSymbol *Target) { EHContTargets.push_back(Target); }

/// Tries to get the global and target flags for a call site, if the
/// instruction is a call to a global.
Expand Down Expand Up @@ -1236,8 +1234,8 @@ class LLVM_ABI MachineFunction {
bool callsUnwindInit() const { return CallsUnwindInit; }
void setCallsUnwindInit(bool b) { CallsUnwindInit = b; }

bool hasEHCatchret() const { return HasEHCatchret; }
void setHasEHCatchret(bool V) { HasEHCatchret = V; }
bool hasEHContTarget() const { return HasEHContTarget; }
void setHasEHContTarget(bool V) { HasEHContTarget = V; }

bool hasEHScopes() const { return HasEHScopes; }
void setHasEHScopes(bool V) { HasEHScopes = V; }
Expand Down
6 changes: 3 additions & 3 deletions llvm/include/llvm/CodeGen/Passes.h
Original file line number Diff line number Diff line change
Expand Up @@ -550,9 +550,9 @@ namespace llvm {
/// \see CFGuardLongjmp.cpp
FunctionPass *createCFGuardLongjmpPass();

/// Creates EHContGuard catchret target identification pass.
/// \see EHContGuardCatchret.cpp
FunctionPass *createEHContGuardCatchretPass();
/// Creates Windows EH Continuation Guard target identification pass.
/// \see EHContGuardTargets.cpp
FunctionPass *createEHContGuardTargetsPass();

/// Create Hardware Loop pass. \see HardwareLoops.cpp
FunctionPass *createHardwareLoopsLegacyPass();
Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/InitializePasses.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ void initializeEarlyIfPredicatorPass(PassRegistry &);
void initializeEarlyMachineLICMPass(PassRegistry &);
void initializeEarlyTailDuplicateLegacyPass(PassRegistry &);
void initializeEdgeBundlesWrapperLegacyPass(PassRegistry &);
void initializeEHContGuardCatchretPass(PassRegistry &);
void initializeEHContGuardTargetsPass(PassRegistry &);
void initializeExpandLargeFpConvertLegacyPassPass(PassRegistry &);
void initializeExpandLargeDivRemLegacyPassPass(PassRegistry &);
void initializeExpandMemCmpLegacyPassPass(PassRegistry &);
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4288,9 +4288,9 @@ void AsmPrinter::emitBasicBlockStart(const MachineBasicBlock &MBB) {
}
}

if (MBB.isEHCatchretTarget() &&
if (MBB.isEHContTarget() &&
MAI->getExceptionHandlingType() == ExceptionHandling::WinEH) {
OutStreamer->emitLabel(MBB.getEHCatchretSymbol());
OutStreamer->emitLabel(MBB.getEHContSymbol());
}

// With BB sections, each basic block must handle CFI information on its own
Expand Down
8 changes: 4 additions & 4 deletions llvm/lib/CodeGen/AsmPrinter/WinException.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,10 @@ void WinException::endFunction(const MachineFunction *MF) {
Asm->OutStreamer->popSection();
}

if (!MF->getCatchretTargets().empty()) {
// Copy the function's catchret targets to a module-level list.
EHContTargets.insert(EHContTargets.end(), MF->getCatchretTargets().begin(),
MF->getCatchretTargets().end());
if (!MF->getEHContTargets().empty()) {
// Copy the function's EH Continuation targets to a module-level list.
EHContTargets.insert(EHContTargets.end(), MF->getEHContTargets().begin(),
MF->getEHContTargets().end());
}
}

Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ add_llvm_component_library(LLVMCodeGen
DwarfEHPrepare.cpp
EarlyIfConversion.cpp
EdgeBundles.cpp
EHContGuardCatchret.cpp
EHContGuardTargets.cpp
ExecutionDomainFix.cpp
ExpandLargeDivRem.cpp
ExpandLargeFpConvert.cpp
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- EHContGuardCatchret.cpp - Catchret target symbols -------*- C++ -*-===//
//===-- EHContGuardTargets.cpp - EH continuation target symbols -*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand All @@ -8,9 +8,10 @@
///
/// \file
/// This file contains a machine function pass to insert a symbol before each
/// valid catchret target and store this in the MachineFunction's
/// CatchRetTargets vector. This will be used to emit the table of valid targets
/// used by EHCont Guard.
/// valid target where the unwinder in Windows may continue exectution after an
/// exception is thrown and store this in the MachineFunction's EHContTargets
/// vector. This will be used to emit the table of valid targets used by Windows
/// EH Continuation Guard.
///
//===----------------------------------------------------------------------===//

Expand All @@ -26,19 +27,18 @@ using namespace llvm;

#define DEBUG_TYPE "ehcontguard-catchret"

STATISTIC(EHContGuardCatchretTargets,
"Number of EHCont Guard catchret targets");
STATISTIC(EHContGuardTargetsFound, "Number of EHCont Guard targets");

namespace {

/// MachineFunction pass to insert a symbol before each valid catchret target
/// and store these in the MachineFunction's CatchRetTargets vector.
class EHContGuardCatchret : public MachineFunctionPass {
class EHContGuardTargets : public MachineFunctionPass {
public:
static char ID;

EHContGuardCatchret() : MachineFunctionPass(ID) {
initializeEHContGuardCatchretPass(*PassRegistry::getPassRegistry());
EHContGuardTargets() : MachineFunctionPass(ID) {
initializeEHContGuardTargetsPass(*PassRegistry::getPassRegistry());
}

StringRef getPassName() const override {
Expand All @@ -50,31 +50,31 @@ class EHContGuardCatchret : public MachineFunctionPass {

} // end anonymous namespace

char EHContGuardCatchret::ID = 0;
char EHContGuardTargets::ID = 0;

INITIALIZE_PASS(EHContGuardCatchret, "EHContGuardCatchret",
"Insert symbols at valid catchret targets for /guard:ehcont",
false, false)
FunctionPass *llvm::createEHContGuardCatchretPass() {
return new EHContGuardCatchret();
INITIALIZE_PASS(EHContGuardTargets, "EHContGuardTargets",
"Insert symbols at valid targets for /guard:ehcont", false,
false)
FunctionPass *llvm::createEHContGuardTargetsPass() {
return new EHContGuardTargets();
}

bool EHContGuardCatchret::runOnMachineFunction(MachineFunction &MF) {
bool EHContGuardTargets::runOnMachineFunction(MachineFunction &MF) {

// Skip modules for which the ehcontguard flag is not set.
if (!MF.getFunction().getParent()->getModuleFlag("ehcontguard"))
return false;

// Skip functions that do not have catchret
if (!MF.hasEHCatchret())
// Skip functions that do not have targets
if (!MF.hasEHContTarget())
return false;

bool Result = false;

for (MachineBasicBlock &MBB : MF) {
if (MBB.isEHCatchretTarget()) {
MF.addCatchretTarget(MBB.getEHCatchretSymbol());
EHContGuardCatchretTargets++;
if (MBB.isEHContTarget()) {
MF.addEHContTarget(MBB.getEHContSymbol());
EHContGuardTargetsFound++;
Result = true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/MIRParser/MIRParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ MIRParserImpl::initializeMachineFunction(const yaml::MachineFunction &YamlMF,

MF.setCallsEHReturn(YamlMF.CallsEHReturn);
MF.setCallsUnwindInit(YamlMF.CallsUnwindInit);
MF.setHasEHCatchret(YamlMF.HasEHCatchret);
MF.setHasEHContTarget(YamlMF.HasEHContTarget);
MF.setHasEHScopes(YamlMF.HasEHScopes);
MF.setHasEHFunclets(YamlMF.HasEHFunclets);
MF.setIsOutlined(YamlMF.IsOutlined);
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/MIRPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ void MIRPrinter::print(const MachineFunction &MF) {

YamlMF.CallsEHReturn = MF.callsEHReturn();
YamlMF.CallsUnwindInit = MF.callsUnwindInit();
YamlMF.HasEHCatchret = MF.hasEHCatchret();
YamlMF.HasEHContTarget = MF.hasEHContTarget();
YamlMF.HasEHScopes = MF.hasEHScopes();
YamlMF.HasEHFunclets = MF.hasEHFunclets();
YamlMF.HasFakeUses = MF.hasFakeUses();
Expand Down
8 changes: 4 additions & 4 deletions llvm/lib/CodeGen/MachineBasicBlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,15 @@ MCSymbol *MachineBasicBlock::getSymbol() const {
return CachedMCSymbol;
}

MCSymbol *MachineBasicBlock::getEHCatchretSymbol() const {
if (!CachedEHCatchretMCSymbol) {
MCSymbol *MachineBasicBlock::getEHContSymbol() const {
if (!CachedEHContMCSymbol) {
const MachineFunction *MF = getParent();
SmallString<128> SymbolName;
raw_svector_ostream(SymbolName)
<< "$ehgcr_" << MF->getFunctionNumber() << '_' << getNumber();
CachedEHCatchretMCSymbol = MF->getContext().getOrCreateSymbol(SymbolName);
CachedEHContMCSymbol = MF->getContext().getOrCreateSymbol(SymbolName);
}
return CachedEHCatchretMCSymbol;
return CachedEHContMCSymbol;
}

MCSymbol *MachineBasicBlock::getEndSymbol() const {
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1981,8 +1981,8 @@ void SelectionDAGBuilder::visitCatchRet(const CatchReturnInst &I) {
// Update machine-CFG edge.
MachineBasicBlock *TargetMBB = FuncInfo.getMBB(I.getSuccessor());
FuncInfo.MBB->addSuccessor(TargetMBB);
TargetMBB->setIsEHCatchretTarget(true);
DAG.getMachineFunction().setHasEHCatchret(true);
TargetMBB->setIsEHContTarget(true);
DAG.getMachineFunction().setHasEHContTarget(true);

auto Pers = classifyEHPersonality(FuncInfo.Fn->getPersonalityFn());
bool IsSEH = isAsynchronousEHPersonality(Pers);
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,7 @@ void AArch64PassConfig::addPreEmitPass() {
// Identify valid longjmp targets for Windows Control Flow Guard.
addPass(createCFGuardLongjmpPass());
// Identify valid eh continuation targets for Windows EHCont Guard.
addPass(createEHContGuardCatchretPass());
addPass(createEHContGuardTargetsPass());
}

if (TM->getOptLevel() != CodeGenOptLevel::None && EnableCollectLOH &&
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/ARM/ARMTargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ void ARMPassConfig::addPreEmitPass2() {
// Identify valid longjmp targets for Windows Control Flow Guard.
addPass(createCFGuardLongjmpPass());
// Identify valid eh continuation targets for Windows EHCont Guard.
addPass(createEHContGuardCatchretPass());
addPass(createEHContGuardTargetsPass());
}
}

Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/X86/X86TargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ void X86PassConfig::addPreEmitPass2() {
// Identify valid longjmp targets for Windows Control Flow Guard.
addPass(createCFGuardLongjmpPass());
// Identify valid eh continuation targets for Windows EHCont Guard.
addPass(createEHContGuardCatchretPass());
addPass(createEHContGuardTargetsPass());
}
addPass(createX86LoadValueInjectionRetHardeningPass());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ tracksRegLiveness: true
hasWinCFI: false
callsEHReturn: false
callsUnwindInit: false
hasEHCatchret: false
hasEHContTarget: false
hasEHScopes: false
hasEHFunclets: false
failsVerification: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ tracksRegLiveness: true
hasWinCFI: false
callsEHReturn: false
callsUnwindInit: false
hasEHCatchret: false
hasEHContTarget: false
hasEHScopes: false
hasEHFunclets: false
isOutlined: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ tracksRegLiveness: true
hasWinCFI: false
callsEHReturn: false
callsUnwindInit: false
hasEHCatchret: false
hasEHContTarget: false
hasEHScopes: false
hasEHFunclets: false
isOutlined: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ tracksRegLiveness: true
hasWinCFI: false
callsEHReturn: false
callsUnwindInit: false
hasEHCatchret: false
hasEHContTarget: false
hasEHScopes: false
hasEHFunclets: false
isOutlined: false
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/CodeGen/AArch64/nested-iv-regalloc.mir
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ tracksRegLiveness: true
hasWinCFI: false
callsEHReturn: false
callsUnwindInit: false
hasEHCatchret: false
hasEHContTarget: false
hasEHScopes: false
hasEHFunclets: false
isOutlined: false
Expand Down
Loading