@@ -31,6 +31,26 @@ class LLVM_LIBRARY_VISIBILITY X86AsmPrinter : public AsmPrinter {
3131 bool EmitFPOData = false ;
3232 bool ShouldEmitWeakSwiftAsyncExtendedFramePointerFlags = false ;
3333 bool IndCSPrefix = false ;
34+ bool EnableImportCallOptimization = false ;
35+
36+ enum ImportCallKind : unsigned {
37+ IMAGE_RETPOLINE_AMD64_IMPORT_BR = 0x02 ,
38+ IMAGE_RETPOLINE_AMD64_IMPORT_CALL = 0x03 ,
39+ IMAGE_RETPOLINE_AMD64_INDIR_BR = 0x04 ,
40+ IMAGE_RETPOLINE_AMD64_INDIR_CALL = 0x05 ,
41+ IMAGE_RETPOLINE_AMD64_INDIR_BR_REX = 0x06 ,
42+ IMAGE_RETPOLINE_AMD64_CFG_BR = 0x08 ,
43+ IMAGE_RETPOLINE_AMD64_CFG_CALL = 0x09 ,
44+ IMAGE_RETPOLINE_AMD64_CFG_BR_REX = 0x0A ,
45+ IMAGE_RETPOLINE_AMD64_SWITCHTABLE_FIRST = 0x010 ,
46+ IMAGE_RETPOLINE_AMD64_SWITCHTABLE_LAST = 0x01F ,
47+ };
48+ struct ImportCallInfo {
49+ MCSymbol *CalleeSymbol;
50+ ImportCallKind Kind;
51+ };
52+ DenseMap<MCSection *, std::vector<ImportCallInfo>>
53+ SectionToImportedFunctionCalls;
3454
3555 // This utility class tracks the length of a stackmap instruction's 'shadow'.
3656 // It is used by the X86AsmPrinter to ensure that the stackmap shadow
@@ -45,7 +65,7 @@ class LLVM_LIBRARY_VISIBILITY X86AsmPrinter : public AsmPrinter {
4565 void startFunction (MachineFunction &MF) {
4666 this ->MF = &MF;
4767 }
48- void count (MCInst &Inst, const MCSubtargetInfo &STI,
68+ void count (const MCInst &Inst, const MCSubtargetInfo &STI,
4969 MCCodeEmitter *CodeEmitter);
5070
5171 // Called to signal the start of a shadow of RequiredSize bytes.
@@ -126,6 +146,17 @@ class LLVM_LIBRARY_VISIBILITY X86AsmPrinter : public AsmPrinter {
126146 void emitMachOIFuncStubHelperBody (Module &M, const GlobalIFunc &GI,
127147 MCSymbol *LazyPointer) override ;
128148
149+ void emitCallInstruction (const llvm::MCInst &MCI);
150+
151+ // Emits a label to mark the next instruction as being relevant to Import Call
152+ // Optimization.
153+ void emitLabelAndRecordForImportCallOptimization (ImportCallKind Kind);
154+
155+ // Ensure that rax is used as the operand for the given instruction.
156+ //
157+ // NOTE: This assumes that it is safe to clobber rax.
158+ void ensureRaxUsedForOperand (MCInst &TmpInst);
159+
129160public:
130161 X86AsmPrinter (TargetMachine &TM, std::unique_ptr<MCStreamer> Streamer);
131162
0 commit comments