[InstCombine] Signed saturation patterns
[llvm-complete.git] / lib / Target / Hexagon / MCTargetDesc / HexagonMCExpr.cpp
blob1e708ba1bcd3accf2608471b8f32d90b0ca73fc6
1 //===-- HexagonMCExpr.cpp - Hexagon specific MC expression classes
2 //----------===//
3 //
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //
8 //===----------------------------------------------------------------------===//
10 #include "HexagonMCExpr.h"
11 #include "llvm/BinaryFormat/ELF.h"
12 #include "llvm/MC/MCContext.h"
13 #include "llvm/MC/MCStreamer.h"
14 #include "llvm/MC/MCSymbolELF.h"
15 #include "llvm/MC/MCValue.h"
16 #include "llvm/Support/raw_ostream.h"
18 using namespace llvm;
20 #define DEBUG_TYPE "hexagon-mcexpr"
22 HexagonMCExpr *HexagonMCExpr::create(MCExpr const *Expr, MCContext &Ctx) {
23 return new (Ctx) HexagonMCExpr(Expr);
26 bool HexagonMCExpr::evaluateAsRelocatableImpl(MCValue &Res,
27 MCAsmLayout const *Layout,
28 MCFixup const *Fixup) const {
29 return Expr->evaluateAsRelocatable(Res, Layout, Fixup);
32 void HexagonMCExpr::visitUsedExpr(MCStreamer &Streamer) const {
33 Streamer.visitUsedExpr(*Expr);
36 MCFragment *llvm::HexagonMCExpr::findAssociatedFragment() const {
37 return Expr->findAssociatedFragment();
40 static void fixELFSymbolsInTLSFixupsImpl(const MCExpr *Expr, MCAssembler &Asm) {
41 switch (Expr->getKind()) {
42 case MCExpr::Target:
43 llvm_unreachable("Cannot handle nested target MCExpr");
44 break;
45 case MCExpr::Constant:
46 break;
48 case MCExpr::Binary: {
49 const MCBinaryExpr *be = cast<MCBinaryExpr>(Expr);
50 fixELFSymbolsInTLSFixupsImpl(be->getLHS(), Asm);
51 fixELFSymbolsInTLSFixupsImpl(be->getRHS(), Asm);
52 break;
54 case MCExpr::SymbolRef: {
55 const MCSymbolRefExpr &symRef = *cast<MCSymbolRefExpr>(Expr);
56 switch (symRef.getKind()) {
57 default:
58 return;
59 case MCSymbolRefExpr::VK_Hexagon_GD_GOT:
60 case MCSymbolRefExpr::VK_Hexagon_LD_GOT:
61 case MCSymbolRefExpr::VK_Hexagon_GD_PLT:
62 case MCSymbolRefExpr::VK_Hexagon_LD_PLT:
63 case MCSymbolRefExpr::VK_Hexagon_IE:
64 case MCSymbolRefExpr::VK_Hexagon_IE_GOT:
65 case MCSymbolRefExpr::VK_TPREL:
66 break;
68 cast<MCSymbolELF>(symRef.getSymbol()).setType(ELF::STT_TLS);
69 break;
71 case MCExpr::Unary:
72 fixELFSymbolsInTLSFixupsImpl(cast<MCUnaryExpr>(Expr)->getSubExpr(), Asm);
73 break;
77 void HexagonMCExpr::fixELFSymbolsInTLSFixups(MCAssembler &Asm) const {
78 auto expr = getExpr();
79 fixELFSymbolsInTLSFixupsImpl(expr, Asm);
82 MCExpr const *HexagonMCExpr::getExpr() const { return Expr; }
84 void HexagonMCExpr::setMustExtend(bool Val) {
85 assert((!Val || !MustNotExtend) && "Extension contradiction");
86 MustExtend = Val;
89 bool HexagonMCExpr::mustExtend() const { return MustExtend; }
90 void HexagonMCExpr::setMustNotExtend(bool Val) {
91 assert((!Val || !MustExtend) && "Extension contradiction");
92 MustNotExtend = Val;
94 bool HexagonMCExpr::mustNotExtend() const { return MustNotExtend; }
96 bool HexagonMCExpr::s27_2_reloc() const { return S27_2_reloc; }
97 void HexagonMCExpr::setS27_2_reloc(bool Val) {
98 S27_2_reloc = Val;
101 bool HexagonMCExpr::classof(MCExpr const *E) {
102 return E->getKind() == MCExpr::Target;
105 HexagonMCExpr::HexagonMCExpr(MCExpr const *Expr)
106 : Expr(Expr), MustNotExtend(false), MustExtend(false), S27_2_reloc(false),
107 SignMismatch(false) {}
109 void HexagonMCExpr::printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const {
110 Expr->print(OS, MAI);
113 void HexagonMCExpr::setSignMismatch(bool Val) {
114 SignMismatch = Val;
117 bool HexagonMCExpr::signMismatch() const {
118 return SignMismatch;