Alexei Starovoitov | e4c8c80 | 2015-01-24 17:51:26 +0000 | [diff] [blame^] | 1 | //===-- BPFTargetMachine.cpp - Define TargetMachine for BPF ---------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // Implements the info about BPF target spec. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "BPF.h" |
| 15 | #include "BPFTargetMachine.h" |
| 16 | #include "llvm/CodeGen/TargetLoweringObjectFileImpl.h" |
| 17 | #include "llvm/PassManager.h" |
| 18 | #include "llvm/CodeGen/Passes.h" |
| 19 | #include "llvm/Support/FormattedStream.h" |
| 20 | #include "llvm/Support/TargetRegistry.h" |
| 21 | #include "llvm/Target/TargetOptions.h" |
| 22 | using namespace llvm; |
| 23 | |
| 24 | extern "C" void LLVMInitializeBPFTarget() { |
| 25 | // Register the target. |
| 26 | RegisterTargetMachine<BPFTargetMachine> X(TheBPFTarget); |
| 27 | } |
| 28 | |
| 29 | // DataLayout --> Little-endian, 64-bit pointer/ABI/alignment |
| 30 | // The stack is always 8 byte aligned |
| 31 | // On function prologue, the stack is created by decrementing |
| 32 | // its pointer. Once decremented, all references are done with positive |
| 33 | // offset from the stack/frame pointer. |
| 34 | BPFTargetMachine::BPFTargetMachine(const Target &T, StringRef TT, StringRef CPU, |
| 35 | StringRef FS, const TargetOptions &Options, |
| 36 | Reloc::Model RM, CodeModel::Model CM, |
| 37 | CodeGenOpt::Level OL) |
| 38 | : LLVMTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL), |
| 39 | TLOF(make_unique<TargetLoweringObjectFileELF>()), |
| 40 | Subtarget(TT, CPU, FS, *this) { |
| 41 | initAsmInfo(); |
| 42 | } |
| 43 | namespace { |
| 44 | // BPF Code Generator Pass Configuration Options. |
| 45 | class BPFPassConfig : public TargetPassConfig { |
| 46 | public: |
| 47 | BPFPassConfig(BPFTargetMachine *TM, PassManagerBase &PM) |
| 48 | : TargetPassConfig(TM, PM) {} |
| 49 | |
| 50 | BPFTargetMachine &getBPFTargetMachine() const { |
| 51 | return getTM<BPFTargetMachine>(); |
| 52 | } |
| 53 | |
| 54 | bool addInstSelector() override; |
| 55 | }; |
| 56 | } |
| 57 | |
| 58 | TargetPassConfig *BPFTargetMachine::createPassConfig(PassManagerBase &PM) { |
| 59 | return new BPFPassConfig(this, PM); |
| 60 | } |
| 61 | |
| 62 | // Install an instruction selector pass using |
| 63 | // the ISelDag to gen BPF code. |
| 64 | bool BPFPassConfig::addInstSelector() { |
| 65 | addPass(createBPFISelDag(getBPFTargetMachine())); |
| 66 | |
| 67 | return false; |
| 68 | } |