LLVM  4.0.0
BPFTargetMachine.cpp
Go to the documentation of this file.
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"
18 #include "llvm/CodeGen/Passes.h"
23 using namespace llvm;
24 
25 extern "C" void LLVMInitializeBPFTarget() {
26  // Register the target.
30 }
31 
32 // DataLayout: little or big endian
33 static std::string computeDataLayout(const Triple &TT) {
34  if (TT.getArch() == Triple::bpfeb)
35  return "E-m:e-p:64:64-i64:64-n32:64-S128";
36  else
37  return "e-m:e-p:64:64-i64:64-n32:64-S128";
38 }
39 
41  if (!RM.hasValue())
42  return Reloc::PIC_;
43  return *RM;
44 }
45 
47  StringRef CPU, StringRef FS,
48  const TargetOptions &Options,
51  : LLVMTargetMachine(T, computeDataLayout(TT), TT, CPU, FS, Options,
52  getEffectiveRelocModel(RM), CM, OL),
54  Subtarget(TT, CPU, FS, *this) {
55  initAsmInfo();
56 }
57 namespace {
58 // BPF Code Generator Pass Configuration Options.
59 class BPFPassConfig : public TargetPassConfig {
60 public:
61  BPFPassConfig(BPFTargetMachine *TM, PassManagerBase &PM)
62  : TargetPassConfig(TM, PM) {}
63 
64  BPFTargetMachine &getBPFTargetMachine() const {
65  return getTM<BPFTargetMachine>();
66  }
67 
68  bool addInstSelector() override;
69 };
70 }
71 
73  return new BPFPassConfig(this, PM);
74 }
75 
76 // Install an instruction selector pass using
77 // the ISelDag to gen BPF code.
78 bool BPFPassConfig::addInstSelector() {
79  addPass(createBPFISelDag(getBPFTargetMachine()));
80 
81  return false;
82 }
bool hasValue() const
Definition: Optional.h:125
BPFTargetMachine(const Target &T, const Triple &TT, StringRef CPU, StringRef FS, const TargetOptions &Options, Optional< Reloc::Model > RM, CodeModel::Model CM, CodeGenOpt::Level OL)
Target-Independent Code Generator Pass Configuration Options.
TargetPassConfig * createPassConfig(PassManagerBase &PM) override
Create a pass configuration object to be used by addPassToEmitX methods for generating a pipeline of ...
ArchType getArch() const
getArch - Get the parsed architecture type of this triple.
Definition: Triple.h:270
std::enable_if<!std::is_array< T >::value, std::unique_ptr< T > >::type make_unique(Args &&...args)
Constructs a new T() with the given args and returns a unique_ptr<T> which owns the object...
Definition: STLExtras.h:845
static Reloc::Model getEffectiveRelocModel(Optional< Reloc::Model > RM)
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang","erlang-compatible garbage collector")
This class describes a target machine that is implemented with the LLVM target-independent code gener...
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
Target - Wrapper for Target specific information.
void LLVMInitializeBPFTarget()
static std::string computeDataLayout(const Triple &TT)
Target & getTheBPFleTarget()
RegisterTargetMachine - Helper template for registering a target machine implementation, for use in the target machine initialization function.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:47
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml","ocaml 3.10-compatible collector")
Target & getTheBPFbeTarget()
FunctionPass * createBPFISelDag(BPFTargetMachine &TM)
Target & getTheBPFTarget()