7
7
8
8
#include " llvm.h"
9
9
10
+ // TODO-LLVM-Upstream: figure out how to fix these warnings in LLVM headers.
11
+ #pragma warning(push)
12
+ #pragma warning(disable : 4242)
13
+ #pragma warning(disable : 4244)
14
+ #include " llvm/IR/Verifier.h"
15
+ #include " llvm/IR/IntrinsicsWebAssembly.h"
16
+ #pragma warning(pop)
17
+
10
18
#define BBNAME (prefix, index ) Twine(prefix) + ((index < 10 ) ? " 0" : " " ) + Twine(index)
11
19
20
+ using AllocaMap = JitHashTable<unsigned , JitSmallPrimitiveKeyFuncs<unsigned >, llvm::AllocaInst*>;
21
+
22
+ struct LlvmBlockRange
23
+ {
24
+ llvm::BasicBlock* FirstBlock;
25
+ llvm::BasicBlock* LastBlock;
26
+ INDEBUG (unsigned Count = 1 );
27
+
28
+ LlvmBlockRange (llvm::BasicBlock* llvmBlock) : FirstBlock(llvmBlock), LastBlock(llvmBlock)
29
+ {
30
+ }
31
+ };
32
+
33
+ struct EHRegionInfo
34
+ {
35
+ llvm::BasicBlock* UnwindBlock;
36
+ Value* CatchArgValue;
37
+ };
38
+
39
+ struct FunctionInfo
40
+ {
41
+ Function* LlvmFunction;
42
+ union {
43
+ llvm::AllocaInst** Allocas; // Dense "lclNum -> Alloca*" mapping used for the main function.
44
+ AllocaMap* AllocaMap; // Sparse "lclNum -> Alloca*" mapping used for funclets.
45
+ };
46
+ llvm::BasicBlock* ResumeLlvmBlock;
47
+ llvm::BasicBlock* ExceptionThrownReturnLlvmBlock;
48
+ };
49
+
12
50
// ------------------------------------------------------------------------
13
51
// Compile: Compile IR to LLVM, adding to the LLVM Module
14
52
//
@@ -25,12 +63,7 @@ void Llvm::Compile()
25
63
generateUnwindBlocks ();
26
64
generateBlocks ();
27
65
fillPhis ();
28
-
29
- if (m_diFunction != nullptr )
30
- {
31
- m_diBuilder->finalizeSubprogram (m_diFunction);
32
- }
33
-
66
+ finalizeDebugInfo ();
34
67
generateAuxiliaryArtifacts ();
35
68
36
69
displayGeneratedCode ();
@@ -398,7 +431,7 @@ void Llvm::generateUnwindBlocks()
398
431
llvm::Constant* nullValue = llvm::Constant::getNullValue (ptrLlvmType);
399
432
Function* personalityLlvmFunc = getOrCreatePersonalityLlvmFunction (m_ehModel);
400
433
Function* cppBeginCatchFunc = nullptr ;
401
- if (model == CorInfoLlvmEHModel::Cpp )
434
+ if (model == CORINFO_LLVM_EH_CPP )
402
435
{
403
436
cppBeginCatchFunc = getOrCreateKnownLlvmFunction (" __cxa_begin_catch" , [ptrLlvmType]() {
404
437
return FunctionType::get (ptrLlvmType, {ptrLlvmType}, /* isVarArg */ false );
@@ -465,7 +498,7 @@ void Llvm::generateUnwindBlocks()
465
498
466
499
// The code we will generate uses native unwinding to call second-pass handlers.
467
500
//
468
- // For CorInfoLlvmEHModel::Cpp :
501
+ // For CORINFO_LLVM_EH_CPP :
469
502
//
470
503
// UNWIND_INNER:
471
504
// __cxa_begin_catch(landingPadInst.ExceptionData);
@@ -482,7 +515,7 @@ void Llvm::generateUnwindBlocks()
482
515
// RESUME:
483
516
// resume(cppExcTuple); // Rethrow the exception and unwind to caller.
484
517
//
485
- // CorInfoLlvmEHModel::Wasm has the same structure but uses Windows EH instructions and rethrows:
518
+ // CORINFO_LLVM_EH_WASM has the same structure but uses Windows EH instructions and rethrows:
486
519
//
487
520
// UNWIND_INNER:
488
521
// catchswitch unwind to UNWIND_OUTER
@@ -494,7 +527,7 @@ void Llvm::generateUnwindBlocks()
494
527
// }
495
528
// <Catch handler code...>
496
529
//
497
- // CorInfoLlvmEHModel::Emulated uses fully "manual" unwinding based on early returns:
530
+ // CORINFO_LLVM_EH_EMULATED uses fully "manual" unwinding based on early returns:
498
531
//
499
532
// UNWIND_INNER:
500
533
// RhpExceptionThrown = 0; // Stop the unwinding before calling managed code.
@@ -517,7 +550,7 @@ void Llvm::generateUnwindBlocks()
517
550
// Create the C++ exception data alloca, to store the active landing pad value.
518
551
FunctionInfo& funcInfo = getLlvmFunctionInfoForIndex (funcIdx);
519
552
llvm::AllocaInst* cppExcTupleAlloca = funcData.CppExcTupleAlloca ;
520
- if ((model == CorInfoLlvmEHModel::Cpp ) && (cppExcTupleAlloca == nullptr ))
553
+ if ((model == CORINFO_LLVM_EH_CPP ) && (cppExcTupleAlloca == nullptr ))
521
554
{
522
555
llvm::BasicBlock* prologLlvmBlock = getOrCreatePrologLlvmBlockForFunction (funcIdx);
523
556
@@ -529,15 +562,15 @@ void Llvm::generateUnwindBlocks()
529
562
530
563
// Generate the resume block needed in the C++ and emulated models.
531
564
if ((funcInfo.ResumeLlvmBlock == nullptr ) &&
532
- ((model == CorInfoLlvmEHModel::Cpp ) || (model == CorInfoLlvmEHModel::Emulated )))
565
+ ((model == CORINFO_LLVM_EH_CPP ) || (model == CORINFO_LLVM_EH_EMULATED )))
533
566
{
534
567
llvm::BasicBlock* resumeLlvmBlock =
535
568
llvm::BasicBlock::Create (m_context->Context , " BBRE" , llvmFunc, funcData.InsertBeforeLlvmBlock );
536
569
LlvmBlockRange resumeLlvmBlocks (resumeLlvmBlock);
537
570
setCurrentEmitContext (
538
571
funcIdx, EHblkDsc::NO_ENCLOSING_INDEX, EHblkDsc::NO_ENCLOSING_INDEX, &resumeLlvmBlocks);
539
572
540
- if (model == CorInfoLlvmEHModel::Cpp )
573
+ if (model == CORINFO_LLVM_EH_CPP )
541
574
{
542
575
Value* resumeOperandValue = _builder.CreateLoad (cppExcTupleLlvmType, cppExcTupleAlloca);
543
576
_builder.CreateResume (resumeOperandValue);
@@ -561,9 +594,9 @@ void Llvm::generateUnwindBlocks()
561
594
_builder.SetCurrentDebugLocation (unwindBlocksDebugLoc);
562
595
563
596
// Set up entry to the native "catch".
564
- if ((model == CorInfoLlvmEHModel::Cpp ) || (model == CorInfoLlvmEHModel::Emulated ))
597
+ if ((model == CORINFO_LLVM_EH_CPP ) || (model == CORINFO_LLVM_EH_EMULATED ))
565
598
{
566
- if (model == CorInfoLlvmEHModel::Cpp )
599
+ if (model == CORINFO_LLVM_EH_CPP )
567
600
{
568
601
llvm::LandingPadInst* landingPadInst = _builder.CreateLandingPad (cppExcTupleLlvmType, 1 );
569
602
landingPadInst->addClause (nullValue); // Catch all C++ exceptions.
@@ -2275,11 +2308,11 @@ void Llvm::buildCatchRet(BasicBlock* block)
2275
2308
llvm::BasicBlock* destLlvmBlock = getFirstLlvmBlockForBlock (block->GetTarget ());
2276
2309
switch (m_ehModel)
2277
2310
{
2278
- case CorInfoLlvmEHModel::Cpp :
2279
- case CorInfoLlvmEHModel::Emulated :
2311
+ case CORINFO_LLVM_EH_CPP :
2312
+ case CORINFO_LLVM_EH_EMULATED :
2280
2313
_builder.CreateBr (destLlvmBlock);
2281
2314
break ;
2282
- case CorInfoLlvmEHModel::Wasm :
2315
+ case CORINFO_LLVM_EH_WASM :
2283
2316
_builder.CreateCatchRet (getCatchPadForHandler (block->getHndIndex ()), destLlvmBlock);
2284
2317
break ;
2285
2318
default :
@@ -2688,7 +2721,7 @@ llvm::CallBase* Llvm::emitCallOrInvoke(llvm::FunctionCallee callee, ArrayRef<Val
2688
2721
llvm::BasicBlock* catchLlvmBlock = getUnwindLlvmBlockForCurrentInvoke ();
2689
2722
2690
2723
llvm::SmallVector<llvm::OperandBundleDef, 1 > bundles{};
2691
- if (m_ehModel == CorInfoLlvmEHModel::Wasm )
2724
+ if (m_ehModel == CORINFO_LLVM_EH_WASM )
2692
2725
{
2693
2726
llvm::CatchPadInst* catchPadInst = getCatchPadForHandler (getCurrentHandlerIndex ());
2694
2727
if ((catchPadInst != nullptr ) && (catchPadInst->getFunction () == getCurrentLlvmFunction ()))
@@ -2699,7 +2732,7 @@ llvm::CallBase* Llvm::emitCallOrInvoke(llvm::FunctionCallee callee, ArrayRef<Val
2699
2732
2700
2733
llvm::CallBase* callInst;
2701
2734
bool isThrowingCall = (callSiteFacts & CSF_NO_THROW) == 0 ;
2702
- if (isThrowingCall && (catchLlvmBlock != nullptr ) && (m_ehModel != CorInfoLlvmEHModel::Emulated ))
2735
+ if (isThrowingCall && (catchLlvmBlock != nullptr ) && (m_ehModel != CORINFO_LLVM_EH_EMULATED ))
2703
2736
{
2704
2737
llvm::BasicBlock* nextLlvmBlock = createInlineLlvmBlock ();
2705
2738
callInst = _builder.CreateInvoke (callee, nextLlvmBlock, catchLlvmBlock, args, bundles);
@@ -2715,7 +2748,7 @@ llvm::CallBase* Llvm::emitCallOrInvoke(llvm::FunctionCallee callee, ArrayRef<Val
2715
2748
}
2716
2749
}
2717
2750
2718
- if (isThrowingCall && (m_ehModel == CorInfoLlvmEHModel::Emulated ))
2751
+ if (isThrowingCall && (m_ehModel == CORINFO_LLVM_EH_EMULATED ))
2719
2752
{
2720
2753
// In the emulated EH model, top-level calls also need to return early if they throw.
2721
2754
if (catchLlvmBlock == nullptr )
@@ -2932,7 +2965,7 @@ void Llvm::annotateHelperFunction(CorInfoHelpFunc helperFunc, Function* llvmFunc
2932
2965
}
2933
2966
2934
2967
HelperCallProperties& properties = Compiler::s_helperCallProperties;
2935
- const bool isEmulatedEH = m_ehModel == CorInfoLlvmEHModel::Emulated ;
2968
+ const bool isEmulatedEH = m_ehModel == CORINFO_LLVM_EH_EMULATED ;
2936
2969
const bool mayThrow = helperCallMayPhysicallyThrow (helperFunc);
2937
2970
2938
2971
if (!mayThrow)
@@ -3026,7 +3059,7 @@ llvm::BasicBlock* Llvm::getUnwindLlvmBlockForCurrentInvoke()
3026
3059
3027
3060
void Llvm::emitUnwindToOuterHandler ()
3028
3061
{
3029
- if (m_ehModel == CorInfoLlvmEHModel::Wasm )
3062
+ if (m_ehModel == CORINFO_LLVM_EH_WASM )
3030
3063
{
3031
3064
Function* wasmRethrowLlvmFunc =
3032
3065
llvm::Intrinsic::getDeclaration (&m_context->Module , llvm::Intrinsic::wasm_rethrow);
@@ -3078,19 +3111,19 @@ Function* Llvm::getOrCreatePersonalityLlvmFunction(CorInfoLlvmEHModel ehModel)
3078
3111
{
3079
3112
switch (ehModel)
3080
3113
{
3081
- case CorInfoLlvmEHModel::Cpp :
3114
+ case CORINFO_LLVM_EH_CPP :
3082
3115
return getOrCreateKnownLlvmFunction (" __gxx_personality_v0" , [this ]() {
3083
3116
Type* ptrLlvmType = getPtrLlvmType ();
3084
3117
Type* int32LlvmType = Type::getInt32Ty (m_context->Context );
3085
3118
Type* cppExcTupleLlvmType = llvm::StructType::get (ptrLlvmType, int32LlvmType);
3086
3119
return FunctionType::get (cppExcTupleLlvmType, {int32LlvmType, ptrLlvmType, ptrLlvmType}, /* isVarArg */ true );
3087
3120
});
3088
3121
break ;
3089
- case CorInfoLlvmEHModel::Wasm :
3122
+ case CORINFO_LLVM_EH_WASM :
3090
3123
return getOrCreateKnownLlvmFunction (" __gxx_wasm_personality_v0" , [this ]() {
3091
3124
return FunctionType::get (Type::getInt32Ty (m_context->Context ), /* isVarArg */ true );
3092
3125
});
3093
- case CorInfoLlvmEHModel::Emulated :
3126
+ case CORINFO_LLVM_EH_EMULATED :
3094
3127
return nullptr ;
3095
3128
default :
3096
3129
unreached ();
@@ -3099,7 +3132,7 @@ Function* Llvm::getOrCreatePersonalityLlvmFunction(CorInfoLlvmEHModel ehModel)
3099
3132
3100
3133
llvm::CatchPadInst* Llvm::getCatchPadForHandler (unsigned hndIndex)
3101
3134
{
3102
- assert (m_ehModel == CorInfoLlvmEHModel::Wasm );
3135
+ assert (m_ehModel == CORINFO_LLVM_EH_WASM );
3103
3136
if (hndIndex == EHblkDsc::NO_ENCLOSING_INDEX)
3104
3137
{
3105
3138
return nullptr ;
@@ -3120,7 +3153,7 @@ llvm::CatchPadInst* Llvm::getCatchPadForHandler(unsigned hndIndex)
3120
3153
3121
3154
llvm::BasicBlock* Llvm::getOrCreateExceptionThrownReturnBlock ()
3122
3155
{
3123
- assert (m_ehModel == CorInfoLlvmEHModel::Emulated );
3156
+ assert (m_ehModel == CORINFO_LLVM_EH_EMULATED );
3124
3157
3125
3158
FunctionInfo& funcInfo = getLlvmFunctionInfoForIndex (getCurrentLlvmFunctionIndex ());
3126
3159
if (funcInfo.ExceptionThrownReturnLlvmBlock == nullptr )
@@ -3144,7 +3177,7 @@ llvm::BasicBlock* Llvm::getOrCreateExceptionThrownReturnBlock()
3144
3177
3145
3178
Value* Llvm::getOrCreateExceptionThrownAddressValue ()
3146
3179
{
3147
- assert (m_ehModel == CorInfoLlvmEHModel::Emulated );
3180
+ assert (m_ehModel == CORINFO_LLVM_EH_EMULATED );
3148
3181
if (m_exceptionThrownAddressValue == nullptr )
3149
3182
{
3150
3183
m_exceptionThrownAddressValue = getOrCreateSymbol (GetExceptionThrownVariable (), /* isThreadLocal */ true );
0 commit comments