1 //===-- BPFTargetMachine.cpp - Define TargetMachine for BPF ---------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Implements the info about BPF target spec.
12 //===----------------------------------------------------------------------===//
15 #include "BPFTargetMachine.h"
16 #include "llvm/CodeGen/TargetLoweringObjectFileImpl.h"
17 #include "llvm/IR/LegacyPassManager.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"
24 extern "C" void LLVMInitializeBPFTarget() {
25 // Register the target.
26 RegisterTargetMachine<BPFTargetMachine> X(TheBPFTarget);
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,
38 : LLVMTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL),
39 TLOF(make_unique<TargetLoweringObjectFileELF>()),
40 DL("e-m:e-p:64:64-i64:64-n32:64-S128"),
41 Subtarget(TT, CPU, FS, *this) {
45 // BPF Code Generator Pass Configuration Options.
46 class BPFPassConfig : public TargetPassConfig {
48 BPFPassConfig(BPFTargetMachine *TM, PassManagerBase &PM)
49 : TargetPassConfig(TM, PM) {}
51 BPFTargetMachine &getBPFTargetMachine() const {
52 return getTM<BPFTargetMachine>();
55 bool addInstSelector() override;
59 TargetPassConfig *BPFTargetMachine::createPassConfig(PassManagerBase &PM) {
60 return new BPFPassConfig(this, PM);
63 // Install an instruction selector pass using
64 // the ISelDag to gen BPF code.
65 bool BPFPassConfig::addInstSelector() {
66 addPass(createBPFISelDag(getBPFTargetMachine()));