LLVM 20.0.0git
AMDGPUDelayedMCExpr.cpp
Go to the documentation of this file.
1//===- AMDGPUDelayedMCExpr.cpp - Delayed MCExpr resolve ---------*- C++ -*-===//
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
10#include "llvm/MC/MCExpr.h"
11#include "llvm/MC/MCValue.h"
12
13using namespace llvm;
14
16 MCValue Val) {
18 switch (Type) {
19 default:
20 return Doc->getEmptyNode();
21 case msgpack::Type::Int:
22 return Doc->getNode(static_cast<int64_t>(Val.getConstant()));
23 case msgpack::Type::UInt:
24 return Doc->getNode(static_cast<uint64_t>(Val.getConstant()));
25 case msgpack::Type::Boolean:
26 return Doc->getNode(static_cast<bool>(Val.getConstant()));
27 }
28}
29
31 const MCExpr *ExprValue) {
32 MCValue Res;
33 if (ExprValue->evaluateAsRelocatable(Res, nullptr, nullptr)) {
34 if (Res.isAbsolute()) {
35 DN = getNode(DN, Type, Res);
36 return;
37 }
38 }
39
40 DelayedExprs.emplace_back(DN, Type, ExprValue);
41}
42
44 while (!DelayedExprs.empty()) {
45 Expr DE = DelayedExprs.front();
46 MCValue Res;
47
48 if (!DE.ExprValue->evaluateAsRelocatable(Res, nullptr, nullptr) ||
49 !Res.isAbsolute())
50 return false;
51
52 DelayedExprs.pop_front();
53 DE.DN = getNode(DE.DN, DE.Type, Res);
54 }
55
56 return true;
57}
58
59void DelayedMCExprs::clear() { DelayedExprs.clear(); }
60
61bool DelayedMCExprs::empty() { return DelayedExprs.empty(); }
static msgpack::DocNode getNode(msgpack::DocNode DN, msgpack::Type Type, MCValue Val)
void assignDocNode(msgpack::DocNode &DN, msgpack::Type Type, const MCExpr *ExprValue)
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:34
bool evaluateAsRelocatable(MCValue &Res, const MCAssembler *Asm, const MCFixup *Fixup) const
Try to evaluate the expression to a relocatable value, i.e.
Definition: MCExpr.cpp:819
This represents an "assembler immediate".
Definition: MCValue.h:36
int64_t getConstant() const
Definition: MCValue.h:43
bool isAbsolute() const
Is this an absolute (as opposed to relocatable) value.
Definition: MCValue.h:49
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
A node in a MsgPack Document.
Document * getDocument() const
Simple in-memory representation of a document of msgpack objects with ability to find and create arra...
DocNode getEmptyNode()
Create an empty node associated with this Document.
DocNode getNode()
Create a nil node associated with this Document.
Type
MessagePack types as defined in the standard, with the exception of Integer being divided into a sign...
Definition: MsgPackReader.h:53
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18