blob: 1d35824daedf75397e0f05d21881e41db6ff9c6e [file] [log] [blame]
Clement Courbet44b4c542018-06-19 11:28:59 +00001//===-- Target.h ------------------------------------------------*- C++ -*-===//
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/// \file
11///
12/// Classes that handle the creation of target-specific objects. This is
13/// similar to llvm::Target/TargetRegistry.
14///
15//===----------------------------------------------------------------------===//
16
17#ifndef LLVM_TOOLS_LLVM_EXEGESIS_TARGET_H
18#define LLVM_TOOLS_LLVM_EXEGESIS_TARGET_H
19
20#include "llvm/ADT/Triple.h"
Clement Courbet6fd00e32018-06-20 11:54:35 +000021#include "llvm/CodeGen/TargetPassConfig.h"
22#include "llvm/IR/LegacyPassManager.h"
Clement Courbeta51efc22018-06-25 13:12:02 +000023#include "llvm/MC/MCInst.h"
24#include "llvm/MC/MCRegisterInfo.h"
Clement Courbet44b4c542018-06-19 11:28:59 +000025
26namespace exegesis {
27
28class ExegesisTarget {
29public:
Clement Courbet6fd00e32018-06-20 11:54:35 +000030 // Targets can use this to add target-specific passes in assembleToStream();
31 virtual void addTargetSpecificPasses(llvm::PassManagerBase &PM) const {}
32
Clement Courbeta51efc22018-06-25 13:12:02 +000033 // Generates code to move a constant into a the given register.
34 virtual std::vector<llvm::MCInst> setRegToConstant(unsigned Reg) const {
35 return {};
36 }
37
Clement Courbet44b4c542018-06-19 11:28:59 +000038 // Returns the ExegesisTarget for the given triple or nullptr if the target
39 // does not exist.
Clement Courbet6fd00e32018-06-20 11:54:35 +000040 static const ExegesisTarget *lookup(llvm::Triple TT);
Clement Courbet44b4c542018-06-19 11:28:59 +000041 // Registers a target. Not thread safe.
42 static void registerTarget(ExegesisTarget *T);
43
Roman Lebedev3de96642018-06-19 11:58:10 +000044 virtual ~ExegesisTarget();
Clement Courbet44b4c542018-06-19 11:28:59 +000045
46private:
47 virtual bool matchesArch(llvm::Triple::ArchType Arch) const = 0;
Clement Courbetcff2caa2018-06-25 11:22:23 +000048 const ExegesisTarget *Next = nullptr;
Clement Courbet44b4c542018-06-19 11:28:59 +000049};
50
Clement Courbetcff2caa2018-06-25 11:22:23 +000051} // namespace exegesis
Clement Courbet44b4c542018-06-19 11:28:59 +000052
53#endif // LLVM_TOOLS_LLVM_EXEGESIS_TARGET_H