3030#include " llvm/TargetParser/Triple.h"
3131
3232using namespace llvm ;
33+ using namespace llvm ::COFF;
3334using namespace llvm ::object;
3435
3536using OperandBundleDef = OperandBundleDefT<Value *>;
@@ -45,8 +46,6 @@ static cl::opt<bool> GenerateThunks("arm64ec-generate-thunks", cl::Hidden,
4546
4647namespace {
4748
48- enum class ThunkType { GuestExit, Entry, Exit };
49-
5049class AArch64Arm64ECCallLowering : public ModulePass {
5150public:
5251 static char ID;
@@ -73,15 +72,15 @@ class AArch64Arm64ECCallLowering : public ModulePass {
7372 Type *I64Ty;
7473 Type *VoidTy;
7574
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);
7978 void getThunkRetType (FunctionType *FT, AttributeList AttrList,
8079 raw_ostream &Out, Type *&Arm64RetTy, Type *&X64RetTy,
8180 SmallVectorImpl<Type *> &Arm64ArgTypes,
8281 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,
8584 SmallVectorImpl<Type *> &Arm64ArgTypes,
8685 SmallVectorImpl<Type *> &X64ArgTypes, bool HasSretPtr);
8786 void canonicalizeThunkType (Type *T, Align Alignment, bool Ret,
@@ -91,13 +90,11 @@ class AArch64Arm64ECCallLowering : public ModulePass {
9190
9291} // end anonymous namespace
9392
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$" );
10198
10299 Type *Arm64RetTy;
103100 Type *X64RetTy;
@@ -108,7 +105,7 @@ void AArch64Arm64ECCallLowering::getThunkType(FunctionType *FT,
108105 // The first argument to a thunk is the called function, stored in x9.
109106 // For exit thunks, we pass the called function down to the emulator;
110107 // for entry/guest exit thunks, we just call the Arm64 function directly.
111- if (TT == ThunkType ::Exit)
108+ if (TT == Arm64ECThunkType ::Exit)
112109 Arm64ArgTypes.push_back (PtrTy);
113110 X64ArgTypes.push_back (PtrTy);
114111
@@ -125,8 +122,8 @@ void AArch64Arm64ECCallLowering::getThunkType(FunctionType *FT,
125122}
126123
127124void 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,
130127 SmallVectorImpl<Type *> &X64ArgTypes, bool HasSretPtr) {
131128
132129 Out << " $" ;
@@ -163,7 +160,7 @@ void AArch64Arm64ECCallLowering::getThunkArgTypes(
163160 X64ArgTypes.push_back (PtrTy);
164161 // x5
165162 Arm64ArgTypes.push_back (I64Ty);
166- if (TT != ThunkType ::Entry) {
163+ if (TT != Arm64ECThunkType ::Entry) {
167164 // FIXME: x5 isn't actually used by the x64 side; revisit once we
168165 // have proper isel for varargs
169166 X64ArgTypes.push_back (I64Ty);
@@ -348,7 +345,8 @@ Function *AArch64Arm64ECCallLowering::buildExitThunk(FunctionType *FT,
348345 SmallString<256 > ExitThunkName;
349346 llvm::raw_svector_ostream ExitThunkStream (ExitThunkName);
350347 FunctionType *Arm64Ty, *X64Ty;
351- getThunkType (FT, Attrs, ThunkType::Exit, ExitThunkStream, Arm64Ty, X64Ty);
348+ getThunkType (FT, Attrs, Arm64ECThunkType::Exit, ExitThunkStream, Arm64Ty,
349+ X64Ty);
352350 if (Function *F = M->getFunction (ExitThunkName))
353351 return F;
354352
@@ -451,8 +449,8 @@ Function *AArch64Arm64ECCallLowering::buildEntryThunk(Function *F) {
451449 SmallString<256 > EntryThunkName;
452450 llvm::raw_svector_ostream EntryThunkStream (EntryThunkName);
453451 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);
456454 if (Function *F = M->getFunction (EntryThunkName))
457455 return F;
458456
@@ -543,8 +541,8 @@ Function *AArch64Arm64ECCallLowering::buildEntryThunk(Function *F) {
543541Function *AArch64Arm64ECCallLowering::buildGuestExitThunk (Function *F) {
544542 llvm::raw_null_ostream NullThunkName;
545543 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);
548546 auto MangledName = getArm64ECMangledFunctionName (F->getName ().str ());
549547 assert (MangledName && " Can't guest exit to function that's already native" );
550548 std::string ThunkName = *MangledName;
@@ -679,7 +677,7 @@ bool AArch64Arm64ECCallLowering::runOnModule(Module &Mod) {
679677 struct ThunkInfo {
680678 Constant *Src;
681679 Constant *Dst;
682- unsigned Kind;
680+ Arm64ECThunkType Kind;
683681 };
684682 SmallVector<ThunkInfo> ThunkMapping;
685683 for (Function &F : Mod) {
@@ -688,14 +686,17 @@ bool AArch64Arm64ECCallLowering::runOnModule(Module &Mod) {
688686 F.getCallingConv () != CallingConv::ARM64EC_Thunk_X64) {
689687 if (!F.hasComdat ())
690688 F.setComdat (Mod.getOrInsertComdat (F.getName ()));
691- ThunkMapping.push_back ({&F, buildEntryThunk (&F), 1 });
689+ ThunkMapping.push_back (
690+ {&F, buildEntryThunk (&F), Arm64ECThunkType::Entry});
692691 }
693692 }
694693 for (Function *F : DirectCalledFns) {
695694 ThunkMapping.push_back (
696- {F, buildExitThunk (F->getFunctionType (), F->getAttributes ()), 4 });
695+ {F, buildExitThunk (F->getFunctionType (), F->getAttributes ()),
696+ Arm64ECThunkType::Exit});
697697 if (!F->hasDLLImportStorageClass ())
698- ThunkMapping.push_back ({buildGuestExitThunk (F), F, 0 });
698+ ThunkMapping.push_back (
699+ {buildGuestExitThunk (F), F, Arm64ECThunkType::GuestExit});
699700 }
700701
701702 if (!ThunkMapping.empty ()) {
@@ -704,7 +705,7 @@ bool AArch64Arm64ECCallLowering::runOnModule(Module &Mod) {
704705 ThunkMappingArrayElems.push_back (ConstantStruct::getAnon (
705706 {ConstantExpr::getBitCast (Thunk.Src , PtrTy),
706707 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 ) ))}));
708709 }
709710 Constant *ThunkMappingArray = ConstantArray::get (
710711 llvm::ArrayType::get (ThunkMappingArrayElems[0 ]->getType (),
0 commit comments