30
30
#include " llvm/TargetParser/Triple.h"
31
31
32
32
using namespace llvm ;
33
+ using namespace llvm ::COFF;
33
34
using namespace llvm ::object;
34
35
35
36
using OperandBundleDef = OperandBundleDefT<Value *>;
@@ -45,8 +46,6 @@ static cl::opt<bool> GenerateThunks("arm64ec-generate-thunks", cl::Hidden,
45
46
46
47
namespace {
47
48
48
- enum class ThunkType { GuestExit, Entry, Exit };
49
-
50
49
class AArch64Arm64ECCallLowering : public ModulePass {
51
50
public:
52
51
static char ID;
@@ -73,15 +72,15 @@ class AArch64Arm64ECCallLowering : public ModulePass {
73
72
Type *I64Ty;
74
73
Type *VoidTy;
75
74
76
- void getThunkType (FunctionType *FT, AttributeList AttrList, ThunkType TT,
77
- raw_ostream &Out, FunctionType *&Arm64Ty ,
78
- FunctionType *&X64Ty);
75
+ void getThunkType (FunctionType *FT, AttributeList AttrList,
76
+ Arm64ECThunkType TT, raw_ostream &Out ,
77
+ FunctionType *&Arm64Ty, FunctionType *& X64Ty);
79
78
void getThunkRetType (FunctionType *FT, AttributeList AttrList,
80
79
raw_ostream &Out, Type *&Arm64RetTy, Type *&X64RetTy,
81
80
SmallVectorImpl<Type *> &Arm64ArgTypes,
82
81
SmallVectorImpl<Type *> &X64ArgTypes, bool &HasSretPtr);
83
- void getThunkArgTypes (FunctionType *FT, AttributeList AttrList, ThunkType TT,
84
- raw_ostream &Out,
82
+ void getThunkArgTypes (FunctionType *FT, AttributeList AttrList,
83
+ Arm64ECThunkType TT, raw_ostream &Out,
85
84
SmallVectorImpl<Type *> &Arm64ArgTypes,
86
85
SmallVectorImpl<Type *> &X64ArgTypes, bool HasSretPtr);
87
86
void canonicalizeThunkType (Type *T, Align Alignment, bool Ret,
@@ -91,13 +90,11 @@ class AArch64Arm64ECCallLowering : public ModulePass {
91
90
92
91
} // end anonymous namespace
93
92
94
- void AArch64Arm64ECCallLowering::getThunkType (FunctionType *FT,
95
- AttributeList AttrList,
96
- ThunkType TT, raw_ostream &Out,
97
- FunctionType *&Arm64Ty,
98
- FunctionType *&X64Ty) {
99
- Out << (TT == ThunkType::Entry ? " $ientry_thunk$cdecl$"
100
- : " $iexit_thunk$cdecl$" );
93
+ void AArch64Arm64ECCallLowering::getThunkType (
94
+ FunctionType *FT, AttributeList AttrList, Arm64ECThunkType TT,
95
+ raw_ostream &Out, FunctionType *&Arm64Ty, FunctionType *&X64Ty) {
96
+ Out << (TT == Arm64ECThunkType::Entry ? " $ientry_thunk$cdecl$"
97
+ : " $iexit_thunk$cdecl$" );
101
98
102
99
Type *Arm64RetTy;
103
100
Type *X64RetTy;
@@ -108,7 +105,7 @@ void AArch64Arm64ECCallLowering::getThunkType(FunctionType *FT,
108
105
// The first argument to a thunk is the called function, stored in x9.
109
106
// For exit thunks, we pass the called function down to the emulator;
110
107
// for entry/guest exit thunks, we just call the Arm64 function directly.
111
- if (TT == ThunkType ::Exit)
108
+ if (TT == Arm64ECThunkType ::Exit)
112
109
Arm64ArgTypes.push_back (PtrTy);
113
110
X64ArgTypes.push_back (PtrTy);
114
111
@@ -125,8 +122,8 @@ void AArch64Arm64ECCallLowering::getThunkType(FunctionType *FT,
125
122
}
126
123
127
124
void AArch64Arm64ECCallLowering::getThunkArgTypes (
128
- FunctionType *FT, AttributeList AttrList, ThunkType TT, raw_ostream &Out ,
129
- SmallVectorImpl<Type *> &Arm64ArgTypes,
125
+ FunctionType *FT, AttributeList AttrList, Arm64ECThunkType TT,
126
+ raw_ostream &Out, SmallVectorImpl<Type *> &Arm64ArgTypes,
130
127
SmallVectorImpl<Type *> &X64ArgTypes, bool HasSretPtr) {
131
128
132
129
Out << " $" ;
@@ -163,7 +160,7 @@ void AArch64Arm64ECCallLowering::getThunkArgTypes(
163
160
X64ArgTypes.push_back (PtrTy);
164
161
// x5
165
162
Arm64ArgTypes.push_back (I64Ty);
166
- if (TT != ThunkType ::Entry) {
163
+ if (TT != Arm64ECThunkType ::Entry) {
167
164
// FIXME: x5 isn't actually used by the x64 side; revisit once we
168
165
// have proper isel for varargs
169
166
X64ArgTypes.push_back (I64Ty);
@@ -348,7 +345,8 @@ Function *AArch64Arm64ECCallLowering::buildExitThunk(FunctionType *FT,
348
345
SmallString<256 > ExitThunkName;
349
346
llvm::raw_svector_ostream ExitThunkStream (ExitThunkName);
350
347
FunctionType *Arm64Ty, *X64Ty;
351
- getThunkType (FT, Attrs, ThunkType::Exit, ExitThunkStream, Arm64Ty, X64Ty);
348
+ getThunkType (FT, Attrs, Arm64ECThunkType::Exit, ExitThunkStream, Arm64Ty,
349
+ X64Ty);
352
350
if (Function *F = M->getFunction (ExitThunkName))
353
351
return F;
354
352
@@ -451,8 +449,8 @@ Function *AArch64Arm64ECCallLowering::buildEntryThunk(Function *F) {
451
449
SmallString<256 > EntryThunkName;
452
450
llvm::raw_svector_ostream EntryThunkStream (EntryThunkName);
453
451
FunctionType *Arm64Ty, *X64Ty;
454
- getThunkType (F->getFunctionType (), F->getAttributes (), ThunkType::Entry,
455
- EntryThunkStream, Arm64Ty, X64Ty);
452
+ getThunkType (F->getFunctionType (), F->getAttributes (),
453
+ Arm64ECThunkType::Entry, EntryThunkStream, Arm64Ty, X64Ty);
456
454
if (Function *F = M->getFunction (EntryThunkName))
457
455
return F;
458
456
@@ -543,8 +541,8 @@ Function *AArch64Arm64ECCallLowering::buildEntryThunk(Function *F) {
543
541
Function *AArch64Arm64ECCallLowering::buildGuestExitThunk (Function *F) {
544
542
llvm::raw_null_ostream NullThunkName;
545
543
FunctionType *Arm64Ty, *X64Ty;
546
- getThunkType (F->getFunctionType (), F->getAttributes (), ThunkType::GuestExit,
547
- NullThunkName, Arm64Ty, X64Ty);
544
+ getThunkType (F->getFunctionType (), F->getAttributes (),
545
+ Arm64ECThunkType::GuestExit, NullThunkName, Arm64Ty, X64Ty);
548
546
auto MangledName = getArm64ECMangledFunctionName (F->getName ().str ());
549
547
assert (MangledName && " Can't guest exit to function that's already native" );
550
548
std::string ThunkName = *MangledName;
@@ -679,7 +677,7 @@ bool AArch64Arm64ECCallLowering::runOnModule(Module &Mod) {
679
677
struct ThunkInfo {
680
678
Constant *Src;
681
679
Constant *Dst;
682
- unsigned Kind;
680
+ Arm64ECThunkType Kind;
683
681
};
684
682
SmallVector<ThunkInfo> ThunkMapping;
685
683
for (Function &F : Mod) {
@@ -688,14 +686,17 @@ bool AArch64Arm64ECCallLowering::runOnModule(Module &Mod) {
688
686
F.getCallingConv () != CallingConv::ARM64EC_Thunk_X64) {
689
687
if (!F.hasComdat ())
690
688
F.setComdat (Mod.getOrInsertComdat (F.getName ()));
691
- ThunkMapping.push_back ({&F, buildEntryThunk (&F), 1 });
689
+ ThunkMapping.push_back (
690
+ {&F, buildEntryThunk (&F), Arm64ECThunkType::Entry});
692
691
}
693
692
}
694
693
for (Function *F : DirectCalledFns) {
695
694
ThunkMapping.push_back (
696
- {F, buildExitThunk (F->getFunctionType (), F->getAttributes ()), 4 });
695
+ {F, buildExitThunk (F->getFunctionType (), F->getAttributes ()),
696
+ Arm64ECThunkType::Exit});
697
697
if (!F->hasDLLImportStorageClass ())
698
- ThunkMapping.push_back ({buildGuestExitThunk (F), F, 0 });
698
+ ThunkMapping.push_back (
699
+ {buildGuestExitThunk (F), F, Arm64ECThunkType::GuestExit});
699
700
}
700
701
701
702
if (!ThunkMapping.empty ()) {
@@ -704,7 +705,7 @@ bool AArch64Arm64ECCallLowering::runOnModule(Module &Mod) {
704
705
ThunkMappingArrayElems.push_back (ConstantStruct::getAnon (
705
706
{ConstantExpr::getBitCast (Thunk.Src , PtrTy),
706
707
ConstantExpr::getBitCast (Thunk.Dst , PtrTy),
707
- ConstantInt::get (M->getContext (), APInt (32 , Thunk.Kind ))}));
708
+ ConstantInt::get (M->getContext (), APInt (32 , uint8_t ( Thunk.Kind ) ))}));
708
709
}
709
710
Constant *ThunkMappingArray = ConstantArray::get (
710
711
llvm::ArrayType::get (ThunkMappingArrayElems[0 ]->getType (),
0 commit comments