8 #include <unordered_map>
10 #include <llvm/ADT/DenseMap.h>
11 #include <llvm/Analysis/OptimizationRemarkEmitter.h>
12 #include <llvm/CodeGen/MachineBasicBlock.h>
13 #include <llvm/IR/Module.h>
14 #include <llvm/IR/Type.h>
15 #include <llvm/Pass.h>
16 #include <llvm/Target/X86/X86InstrInfo.h>
17 #include <llvm/Target/X86/X86ISelDAGToDAG.h>
18 #include <llvm/Target/X86/X86MachineFunctionInfo.h>
19 #include <llvm/Target/X86/X86RegisterInfo.h>
20 #include <llvm/Target/X86/X86Subtarget.h>
21 #include <llvm/Target/X86/X86TargetMachine.h>
23 #include "core/insts.h"
24 #include "emitter/isel.h"
25 #include "emitter/x86/x86call.h"
41 llvm::X86TargetMachine &tm,
42 llvm::CodeGenOpt::Level ol,
43 llvm::MachineFunction &mf
49 llvm::SelectionDAG &
GetDAG()
const {
return *CurDAG; }
55 llvm::X86TargetMachine &tm_;
67 llvm::X86TargetMachine &tm,
68 llvm::TargetLibraryInfo &libInfo,
70 llvm::CodeGenOpt::Level ol,
76 void Lower(llvm::MachineFunction &mf)
override
85 void LowerArch(
const Inst *inst)
override;
88 void LowerSyscall(
const SyscallInst *inst)
override;
90 void LowerClone(
const CloneInst *inst)
override;
92 void LowerReturn(
const ReturnInst *inst)
override;
94 void LowerRaise(
const RaiseInst *inst)
override;
96 void LowerSpawn(
const SpawnInst *inst)
override;
98 void LowerLandingPad(
const LandingPadInst *inst)
override;
100 void LowerSet(
const SetInst *inst)
override;
103 void LowerFPUControl(
111 void Lower(
const BarrierInst *inst,
unsigned op);
113 void Lower(
const X86_CpuIdInst *inst);
115 void Lower(
const X86_XchgInst *inst);
117 void Lower(
const X86_CmpXchgInst *inst);
119 void Lower(
const X86_FnClExInst *inst);
121 void Lower(
const X86_RdTscInst *inst);
123 void Lower(
const X86_InInst *inst);
125 void Lower(
const X86_OutInst *inst);
127 void Lower(
const X86_WrMsrInst *inst);
129 void Lower(
const X86_RdMsrInst *inst);
131 void Lower(
const X86_PauseInst *inst);
133 void Lower(
const X86_YieldInst *inst);
135 void Lower(
const X86_StiInst *inst);
137 void Lower(
const X86_CliInst *inst);
139 void Lower(
const X86_HltInst *inst);
141 void Lower(
const X86_SpinInst *inst);
143 void Lower(
const X86_LgdtInst *inst);
145 void Lower(
const X86_LidtInst *inst);
147 void Lower(
const X86_LtrInst *inst);
149 void Lower(
const X86_XSaveOptInst *inst);
151 void Lower(
const X86_XRestoreInst *inst);
154 void LowerArguments(
bool hasVAStart)
override;
156 void LowerVASetup(
const X86Call &lowering);
159 virtual bool Finalize(llvm::MachineFunction &MF)
override;
163 SDValue GetRegArch(Register reg)
override;
165 void LowerSetSP(SDValue value);
167 void LowerSetReg(
const char *code, MVT type, SDValue value);
169 void LowerRaise(SDValue spVal, SDValue pcVal, SDValue glue);
171 void LowerContextMask(
bool store,
unsigned op, SDValue addr, SDValue mask);
173 void LowerSetCs(SDValue value);
177 llvm::SelectionDAG &GetDAG()
const override {
return m_->GetDAG(); }
179 void PreprocessISelDAG()
override { m_->PreprocessISelDAG(); }
181 void PostprocessISelDAG()
override { m_->PostprocessISelDAG(); }
183 void Select(SDNode *node)
override { m_->Select(node); }
186 llvm::Register GetStackRegister()
const override;
188 llvm::Register GetBaseRegister()
const;
192 void LowerCallSite(llvm::SDValue chain,
const CallSite *call)
override;
196 llvm::X86TargetMachine &tm_;
198 std::unique_ptr<X86Matcher> m_;
200 llvm::Function *trampoline_;