LLVM: lib/Target/PowerPC/MCTargetDesc/PPCMCTargetDesc.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
49
50using namespace llvm;
51
52#define GET_INSTRINFO_MC_DESC
53#define ENABLE_INSTR_PREDICATE_VERIFIER
54#include "PPCGenInstrInfo.inc"
55
56#define GET_SUBTARGETINFO_MC_DESC
57#include "PPCGenSubtargetInfo.inc"
58
59#define GET_REGINFO_MC_DESC
60#include "PPCGenRegisterInfo.inc"
61
62
63
66 case 'a':
69 break;
70 case 'f':
73 [[fallthrough]];
74 case 'r':
75 case 'v':
80 }
82 case 'c':
85 break;
86 case 'w':
87
91 else
93 }
94 break;
95 case 'd':
96
103 else if (RegName[3] == 'p')
105 else
107 }
108 break;
109 }
110
112}
113
114
115
116
117
118
119
120
121
123 unsigned OpNo) {
124 int16_t regClass = Desc.operands()[OpNo].RegClass;
125 switch (regClass) {
126
127
128 case PPC::VSSRCRegClassID:
129 case PPC::VSFRCRegClassID:
131 return PPC::VSX32 + (Reg - PPC::VF0);
132 break;
133
134
135 case PPC::VSRCRegClassID:
137 return PPC::VSX32 + (Reg - PPC::V0);
138 break;
139
140 default:
141 break;
142 }
143 return Reg;
144}
145
147
148
150
153 InitPPCMCInstrInfo(X);
154 return X;
155}
156
158 bool isPPC64 =
160 unsigned Flavour = isPPC64 ? 0 : 1;
161 unsigned RA = isPPC64 ? PPC::LR8 : PPC::LR;
162
164 InitPPCMCRegisterInfo(X, RA, Flavour, Flavour);
165 return X;
166}
167
170
171 std::string FullFS = std::string(FS);
172
173 if (TT.isOSAIX()) {
174 if (!FullFS.empty())
175 FullFS = "+aix," + FullFS;
176 else
177 FullFS = "+aix";
178 }
179
180 return createPPCMCSubtargetInfoImpl(TT, CPU, CPU, FullFS);
181}
182
184 const Triple &TheTriple,
188
192 else
194
195
196 unsigned Reg = isPPC64 ? PPC::X1 : PPC::R1;
200
201 return MAI;
202}
203
204namespace {
205
207 formatted_raw_ostream &OS;
208
209public:
210 PPCTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS)
211 : PPCTargetStreamer(S), OS(OS) {}
212
215 MCSymbolXCOFF *TCSym =
216 static_cast<const MCSectionXCOFF *>(Streamer.getCurrentSectionOnly())
217 ->getQualNameSymbol();
218
219
220
221
222
223
224
228 OS << "\t.tc " << TCSym->getName() << "," << S.getName() << "@"
229 << getContext().getAsmInfo()->getSpecifierName(Kind) << '\n';
230 else
231 OS << "\t.tc " << TCSym->getName() << "," << S.getName() << '\n';
232
234 Streamer.emitXCOFFRenameDirective(TCSym, TCSym->getSymbolTableName());
235 return;
236 }
237
238 OS << "\t.tc " << S.getName() << "[TC]," << S.getName() << '\n';
239 }
240
241 void emitMachine(StringRef CPU) override {
242 const Triple &TT = Streamer.getContext().getTargetTriple();
243 if (TT.isOSBinFormatXCOFF())
244 OS << "\t.machine\t" << '\"' << CPU << '\"' << '\n';
245 else
246 OS << "\t.machine " << CPU << '\n';
247 }
248
249 void emitAbiVersion(int AbiVersion) override {
250 OS << "\t.abiversion " << AbiVersion << '\n';
251 }
252
253 void emitLocalEntry(MCSymbolELF *S, const MCExpr *LocalOffset) override {
254 const MCAsmInfo *MAI = Streamer.getContext().getAsmInfo();
255
256 OS << "\t.localentry\t";
257 S->print(OS, MAI);
258 OS << ", ";
259 MAI->printExpr(OS, *LocalOffset);
260 OS << '\n';
261 }
262};
263
265public:
266 PPCTargetELFStreamer(MCStreamer &S) : PPCTargetStreamer(S) {}
267
268 MCELFStreamer &getStreamer() {
269 return static_cast<MCELFStreamer &>(Streamer);
270 }
271
273
274 Streamer.emitValueToAlignment(Align(8));
275 Streamer.emitSymbolValue(&S, 8);
276 }
277
278 void emitMachine(StringRef CPU) override {
279
280
281 }
282
283 void emitAbiVersion(int AbiVersion) override {
284 ELFObjectWriter &W = getStreamer().getWriter();
285 unsigned Flags = W.getELFHeaderEFlags();
286 Flags &= ~ELF::EF_PPC64_ABI;
288 W.setELFHeaderEFlags(Flags);
289 }
290
291 void emitLocalEntry(MCSymbolELF *S, const MCExpr *LocalOffset) override {
292
293
294
295 unsigned Encoded = encodePPC64LocalEntryOffset(LocalOffset);
296
298 Other &= ~ELF::STO_PPC64_LOCAL_MASK;
301
302
303
304 ELFObjectWriter &W = getStreamer().getWriter();
305 unsigned Flags = W.getELFHeaderEFlags();
307 W.setELFHeaderEFlags(Flags | 2);
308 }
309
310 void emitAssignment(MCSymbol *S, const MCExpr *Value) override {
311 auto *Symbol = static_cast<MCSymbolELF *>(S);
312
313
314
315 if (copyLocalEntry(Symbol, Value))
316 UpdateOther.insert(Symbol);
317 else
318 UpdateOther.erase(Symbol);
319 }
320
321 void finish() override {
322 for (auto *Sym : UpdateOther)
323 if (Sym->isVariable())
324 copyLocalEntry(Sym, Sym->getVariableValue());
325
326
327
328 UpdateOther.clear();
329 }
330
331private:
332 SmallPtrSet<MCSymbolELF *, 32> UpdateOther;
333
334 bool copyLocalEntry(MCSymbolELF *D, const MCExpr *S) {
336 if ()
337 return false;
338 auto &RhsSym = static_cast<const MCSymbolELF &>(Ref->getSymbol());
339 unsigned Other = D->getOther();
340 Other &= ~ELF::STO_PPC64_LOCAL_MASK;
343 return true;
344 }
345
346 unsigned encodePPC64LocalEntryOffset(const MCExpr *LocalOffset) {
347 MCAssembler &MCA = getStreamer().getAssembler();
349 if (!LocalOffset->evaluateAsAbsolute(Offset, MCA))
351 ".localentry expression must be absolute");
352
354 default:
356 LocalOffset->getLoc(), ".localentry expression must be a power of 2");
357 return 0;
358 case 0:
359 return 0;
360 case 1:
362 case 4:
363 case 8:
364 case 16:
365 case 32:
366 case 64:
368 }
369 }
370};
371
373public:
374 PPCTargetMachOStreamer(MCStreamer &S) : PPCTargetStreamer(S) {}
375
378 }
379
380 void emitMachine(StringRef CPU) override {
381
382
383 }
384
385 void emitAbiVersion(int AbiVersion) override {
387 }
388
389 void emitLocalEntry(MCSymbolELF *S, const MCExpr *LocalOffset) override {
391 }
392};
393
395public:
396 PPCTargetXCOFFStreamer(MCStreamer &S) : PPCTargetStreamer(S) {}
397
399 const MCAsmInfo *MAI = Streamer.getContext().getAsmInfo();
401 Streamer.emitValueToAlignment(Align(PointerSize));
403 PointerSize);
404 }
405
406 void emitMachine(StringRef CPU) override {
407 static_cast<XCOFFObjectWriter &>(Streamer.getAssemblerPtr()->getWriter())
408 .setCPU(CPU);
409 }
410
411 void emitAbiVersion(int AbiVersion) override {
412 llvm_unreachable("ABI-version pseudo-ops are invalid for XCOFF.");
413 }
414
415 void emitLocalEntry(MCSymbolELF *S, const MCExpr *LocalOffset) override {
416 llvm_unreachable("Local-entry pseudo-ops are invalid for XCOFF.");
417 }
418};
419
420}
421
425 return new PPCTargetAsmStreamer(S, OS);
426}
427
431
435 if (TT.isOSBinFormatELF())
436 return new PPCTargetELFStreamer(S);
437 if (TT.isOSBinFormatXCOFF())
438 return new PPCTargetXCOFFStreamer(S);
439 return new PPCTargetMachOStreamer(S);
440}
441
443 unsigned SyntaxVariant,
448}
449
450namespace {
451
453public:
454 explicit PPCMCInstrAnalysis(const MCInstrInfo *Info)
455 : MCInstrAnalysis(Info) {}
456
457 bool evaluateBranch(const MCInst &Inst, uint64_t Addr, uint64_t Size,
458 uint64_t &Target) const override {
463 return false;
465 return true;
466 }
467};
468
469}
470
472 return new PPCMCInstrAnalysis(Info);
473}
474
479
481
482
484
485
487
488
490
491
493
494
496
497
499
500
502
503
505
506
509
510
512
513
515
516
518 }
519}
unsigned const MachineRegisterInfo * MRI
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
Analysis containing CSE Info
#define LLVM_EXTERNAL_VISIBILITY
const size_t AbstractManglingParser< Derived, Alloc >::NumOps
static MCTargetStreamer * createNullTargetStreamer(MCStreamer &S)
static MCTargetStreamer * createAsmTargetStreamer(MCStreamer &S, formatted_raw_ostream &OS, MCInstPrinter *InstPrint)
Definition PPCMCTargetDesc.cpp:422
static MCInstPrinter * createPPCMCInstPrinter(const Triple &T, unsigned SyntaxVariant, const MCAsmInfo &MAI, const MCInstrInfo &MII, const MCRegisterInfo &MRI)
Definition PPCMCTargetDesc.cpp:442
static MCTargetStreamer * createObjectTargetStreamer(MCStreamer &S, const MCSubtargetInfo &STI)
Definition PPCMCTargetDesc.cpp:433
LLVM_ABI LLVM_EXTERNAL_VISIBILITY void LLVMInitializePowerPCTargetMC()
Definition PPCMCTargetDesc.cpp:476
static MCInstrAnalysis * createPPCMCInstrAnalysis(const MCInstrInfo *Info)
Definition PPCMCTargetDesc.cpp:471
static MCAsmInfo * createPPCMCAsmInfo(const MCRegisterInfo &MRI, const Triple &TheTriple, const MCTargetOptions &Options)
Definition PPCMCTargetDesc.cpp:183
static MCSubtargetInfo * createPPCMCSubtargetInfo(const Triple &TT, StringRef CPU, StringRef FS)
Definition PPCMCTargetDesc.cpp:168
static MCRegisterInfo * createPPCMCRegisterInfo(const Triple &TT)
Definition PPCMCTargetDesc.cpp:157
static MCInstrInfo * createPPCMCInstrInfo()
Definition PPCMCTargetDesc.cpp:151
SI optimize exec mask operations pre RA
This file defines the SmallPtrSet class.
static TableGen::Emitter::OptClass< SkeletonEmitter > X("gen-skeleton-class", "Generate example skeleton class")
This class is intended to be used as a base class for asm properties and features specific to the tar...
void addInitialFrameState(const MCCFIInstruction &Inst)
void printExpr(raw_ostream &, const MCExpr &) const
unsigned getCodePointerSize() const
Get the code pointer size in bytes.
MCContext & getContext() const
static MCCFIInstruction cfiDefCfa(MCSymbol *L, unsigned Register, int64_t Offset, SMLoc Loc={})
.cfi_def_cfa defines a rule for computing CFA as: take address from Register and add Offset to it.
LLVM_ABI void reportError(SMLoc L, const Twine &Msg)
This is an instance of a target assembly language printer that converts an MCInst to valid target ass...
unsigned getNumOperands() const
unsigned getOpcode() const
const MCOperand & getOperand(unsigned i) const
Describe properties that are true of each instruction in the target description file.
Interface to description of machine instruction set.
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
Wrapper class representing physical registers. Should be passed by value.
Streaming machine code generation interface.
Generic base class for all target subtargets.
const Triple & getTargetTriple() const
unsigned getOther() const
void setOther(unsigned Other)
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx, SMLoc Loc=SMLoc())
StringRef getSymbolTableName() const
LLVM_ABI void print(raw_ostream &OS, const MCAsmInfo *MAI) const
print - Print the value to the stream OS.
StringRef getName() const
getName - Get the symbol name.
Target specific streamer interface.
MCTargetStreamer(MCStreamer &S)
~PPCTargetStreamer() override
PPCTargetStreamer(MCStreamer &S)
Definition PPCMCTargetDesc.cpp:146
StringRef - Represent a constant reference to a string, i.e.
Target - Wrapper for Target specific information.
Triple - Helper class for working with autoconf configuration names.
ArchType getArch() const
Get the parsed architecture type of this triple.
bool isOSBinFormatXCOFF() const
Tests whether the OS uses the XCOFF binary format.
formatted_raw_ostream - A raw_ostream that wraps another one and keeps track of line and column posit...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
@ C
The default llvm calling convention, compatible with C.
const char * stripRegisterPrefix(const char *RegName)
stripRegisterPrefix - This method strips the character prefix from a register name so that only the n...
Definition PPCMCTargetDesc.cpp:64
MCRegister getRegNumForOperand(const MCInstrDesc &Desc, MCRegister Reg, unsigned OpNo)
getRegNumForOperand - some operands use different numbering schemes for the same registers.
Definition PPCMCTargetDesc.cpp:122
static bool isVRRegister(MCRegister Reg)
static bool isVFRegister(MCRegister Reg)
constexpr uint64_t PointerSize
aarch64 pointer size.
Context & getContext() const
This is an optimization pass for GlobalISel generic memory operations.
FunctionAddr VTableAddr Value
Target & getThePPC64LETarget()
decltype(auto) dyn_cast(const From &Val)
dyn_cast - Return the argument parameter cast to the specified type.
Target & getThePPC32Target()
MCAsmBackend * createPPCAsmBackend(const Target &T, const MCSubtargetInfo &STI, const MCRegisterInfo &MRI, const MCTargetOptions &Options)
unsigned Log2_32(uint32_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
MCStreamer * createPPCXCOFFStreamer(const Triple &, MCContext &, std::unique_ptr< MCAsmBackend > &&MAB, std::unique_ptr< MCObjectWriter > &&OW, std::unique_ptr< MCCodeEmitter > &&Emitter)
@ Ref
The access may reference the value stored in memory.
Target & getThePPC64Target()
MCCodeEmitter * createPPCMCCodeEmitter(const MCInstrInfo &MCII, MCContext &Ctx)
Target & getThePPC32LETarget()
MCStreamer * createPPCELFStreamer(const Triple &, MCContext &, std::unique_ptr< MCAsmBackend > &&MAB, std::unique_ptr< MCObjectWriter > &&OW, std::unique_ptr< MCCodeEmitter > &&Emitter)
RegisterMCAsmInfoFn - Helper template for registering a target assembly info implementation.
static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn)
RegisterMCRegInfo - Register a MCRegisterInfo implementation for the given target.
static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn)
RegisterMCAsmBackend - Register a MCAsmBackend implementation for the given target.
static void RegisterXCOFFStreamer(Target &T, Target::XCOFFStreamerCtorTy Fn)
static void RegisterMCCodeEmitter(Target &T, Target::MCCodeEmitterCtorTy Fn)
RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the given target.
static void RegisterMCSubtargetInfo(Target &T, Target::MCSubtargetInfoCtorFnTy Fn)
RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for the given target.
static void RegisterObjectTargetStreamer(Target &T, Target::ObjectTargetStreamerCtorTy Fn)
static void RegisterMCInstrAnalysis(Target &T, Target::MCInstrAnalysisCtorFnTy Fn)
RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for the given target.
static void RegisterELFStreamer(Target &T, Target::ELFStreamerCtorTy Fn)
static void RegisterNullTargetStreamer(Target &T, Target::NullTargetStreamerCtorTy Fn)
static void RegisterMCInstPrinter(Target &T, Target::MCInstPrinterCtorTy Fn)
RegisterMCInstPrinter - Register a MCInstPrinter implementation for the given target.
static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn)
RegisterMCInstrInfo - Register a MCInstrInfo implementation for the given target.
static void RegisterAsmTargetStreamer(Target &T, Target::AsmTargetStreamerCtorTy Fn)