[SampleProfileLoader] Fix integer overflow in generateMDProfMetadata (#90217)
[llvm-project.git] / llvm / lib / Target / XCore / MCTargetDesc / XCoreMCTargetDesc.cpp
blobbc69e1868b88f5b50585d19b4ada5aae753a52d4
1 //===-- XCoreMCTargetDesc.cpp - XCore Target Descriptions -----------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file provides XCore specific target descriptions.
11 //===----------------------------------------------------------------------===//
13 #include "MCTargetDesc/XCoreMCTargetDesc.h"
14 #include "MCTargetDesc/XCoreInstPrinter.h"
15 #include "MCTargetDesc/XCoreMCAsmInfo.h"
16 #include "TargetInfo/XCoreTargetInfo.h"
17 #include "XCoreTargetStreamer.h"
18 #include "llvm/ADT/StringRef.h"
19 #include "llvm/MC/MCDwarf.h"
20 #include "llvm/MC/MCInstrInfo.h"
21 #include "llvm/MC/MCRegisterInfo.h"
22 #include "llvm/MC/MCSubtargetInfo.h"
23 #include "llvm/MC/TargetRegistry.h"
24 #include "llvm/Support/CodeGen.h"
25 #include "llvm/Support/ErrorHandling.h"
26 #include "llvm/Support/FormattedStream.h"
27 #include "llvm/Support/raw_ostream.h"
29 using namespace llvm;
31 #define GET_INSTRINFO_MC_DESC
32 #define ENABLE_INSTR_PREDICATE_VERIFIER
33 #include "XCoreGenInstrInfo.inc"
35 #define GET_SUBTARGETINFO_MC_DESC
36 #include "XCoreGenSubtargetInfo.inc"
38 #define GET_REGINFO_MC_DESC
39 #include "XCoreGenRegisterInfo.inc"
41 static MCInstrInfo *createXCoreMCInstrInfo() {
42 MCInstrInfo *X = new MCInstrInfo();
43 InitXCoreMCInstrInfo(X);
44 return X;
47 static MCRegisterInfo *createXCoreMCRegisterInfo(const Triple &TT) {
48 MCRegisterInfo *X = new MCRegisterInfo();
49 InitXCoreMCRegisterInfo(X, XCore::LR);
50 return X;
53 static MCSubtargetInfo *
54 createXCoreMCSubtargetInfo(const Triple &TT, StringRef CPU, StringRef FS) {
55 return createXCoreMCSubtargetInfoImpl(TT, CPU, /*TuneCPU*/ CPU, FS);
58 static MCAsmInfo *createXCoreMCAsmInfo(const MCRegisterInfo &MRI,
59 const Triple &TT,
60 const MCTargetOptions &Options) {
61 MCAsmInfo *MAI = new XCoreMCAsmInfo(TT);
63 // Initial state of the frame pointer is SP.
64 MCCFIInstruction Inst = MCCFIInstruction::cfiDefCfa(nullptr, XCore::SP, 0);
65 MAI->addInitialFrameState(Inst);
67 return MAI;
70 static MCInstPrinter *createXCoreMCInstPrinter(const Triple &T,
71 unsigned SyntaxVariant,
72 const MCAsmInfo &MAI,
73 const MCInstrInfo &MII,
74 const MCRegisterInfo &MRI) {
75 return new XCoreInstPrinter(MAI, MII, MRI);
78 XCoreTargetStreamer::XCoreTargetStreamer(MCStreamer &S) : MCTargetStreamer(S) {}
80 XCoreTargetStreamer::~XCoreTargetStreamer() = default;
82 namespace {
84 class XCoreTargetAsmStreamer : public XCoreTargetStreamer {
85 formatted_raw_ostream &OS;
87 public:
88 XCoreTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS);
90 void emitCCTopData(StringRef Name) override;
91 void emitCCTopFunction(StringRef Name) override;
92 void emitCCBottomData(StringRef Name) override;
93 void emitCCBottomFunction(StringRef Name) override;
96 } // end anonymous namespace
98 XCoreTargetAsmStreamer::XCoreTargetAsmStreamer(MCStreamer &S,
99 formatted_raw_ostream &OS)
100 : XCoreTargetStreamer(S), OS(OS) {}
102 void XCoreTargetAsmStreamer::emitCCTopData(StringRef Name) {
103 OS << "\t.cc_top " << Name << ".data," << Name << '\n';
106 void XCoreTargetAsmStreamer::emitCCTopFunction(StringRef Name) {
107 OS << "\t.cc_top " << Name << ".function," << Name << '\n';
110 void XCoreTargetAsmStreamer::emitCCBottomData(StringRef Name) {
111 OS << "\t.cc_bottom " << Name << ".data\n";
114 void XCoreTargetAsmStreamer::emitCCBottomFunction(StringRef Name) {
115 OS << "\t.cc_bottom " << Name << ".function\n";
118 static MCTargetStreamer *createTargetAsmStreamer(MCStreamer &S,
119 formatted_raw_ostream &OS,
120 MCInstPrinter *InstPrint,
121 bool isVerboseAsm) {
122 return new XCoreTargetAsmStreamer(S, OS);
125 static MCTargetStreamer *createNullTargetStreamer(MCStreamer &S) {
126 return new XCoreTargetStreamer(S);
129 // Force static initialization.
130 extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeXCoreTargetMC() {
131 // Register the MC asm info.
132 RegisterMCAsmInfoFn X(getTheXCoreTarget(), createXCoreMCAsmInfo);
134 // Register the MC instruction info.
135 TargetRegistry::RegisterMCInstrInfo(getTheXCoreTarget(),
136 createXCoreMCInstrInfo);
138 // Register the MC register info.
139 TargetRegistry::RegisterMCRegInfo(getTheXCoreTarget(),
140 createXCoreMCRegisterInfo);
142 // Register the MC subtarget info.
143 TargetRegistry::RegisterMCSubtargetInfo(getTheXCoreTarget(),
144 createXCoreMCSubtargetInfo);
146 // Register the MCInstPrinter
147 TargetRegistry::RegisterMCInstPrinter(getTheXCoreTarget(),
148 createXCoreMCInstPrinter);
150 TargetRegistry::RegisterAsmTargetStreamer(getTheXCoreTarget(),
151 createTargetAsmStreamer);
153 TargetRegistry::RegisterNullTargetStreamer(getTheXCoreTarget(),
154 createNullTargetStreamer);