@@ -16,38 +16,8 @@ using namespace llvm;
1616
1717#define DEBUG_TYPE " ppcmcexpr"
1818
19- const PPCMCExpr *PPCMCExpr::create (Specifier S, const MCExpr *Expr,
20- MCContext &Ctx) {
21- return new (Ctx) PPCMCExpr (S, Expr);
22- }
23-
24- const PPCMCExpr *PPCMCExpr::create (const MCExpr *Expr, Specifier S,
25- MCContext &Ctx) {
26- return new (Ctx) PPCMCExpr (S, Expr);
27- }
28-
29- void PPCMCExpr::printImpl (raw_ostream &OS, const MCAsmInfo *MAI) const {
30- getSubExpr ()->print (OS, MAI);
31- OS << ' @' << MAI->getSpecifierName (specifier);
32- }
33-
34- bool
35- PPCMCExpr::evaluateAsConstant (int64_t &Res) const {
36- MCValue Value;
37-
38- if (!getSubExpr ()->evaluateAsRelocatable (Value, nullptr ))
39- return false ;
40-
41- if (!Value.isAbsolute ())
42- return false ;
43- auto Tmp = evaluateAsInt64 (Value.getConstant ());
44- if (!Tmp)
45- return false ;
46- Res = *Tmp;
47- return true ;
48- }
49-
50- std::optional<int64_t > PPCMCExpr::evaluateAsInt64 (int64_t Value) const {
19+ static std::optional<int64_t > evaluateAsInt64 (uint16_t specifier,
20+ int64_t Value) {
5121 switch (specifier) {
5222 case PPC::S_LO:
5323 return Value & 0xffff ;
@@ -72,21 +42,35 @@ std::optional<int64_t> PPCMCExpr::evaluateAsInt64(int64_t Value) const {
7242 }
7343}
7444
75- bool PPCMCExpr::evaluateAsRelocatableImpl (MCValue &Res,
76- const MCAssembler *Asm) const {
77- if (!Asm)
45+ bool PPC::evaluateAsConstant (const MCSpecifierExpr &Expr, int64_t &Res) {
46+ MCValue Value;
47+
48+ if (!Expr.getSubExpr ()->evaluateAsRelocatable (Value, nullptr ))
49+ return false ;
50+
51+ if (!Value.isAbsolute ())
52+ return false ;
53+ auto Tmp = evaluateAsInt64 (Expr.getSpecifier (), Value.getConstant ());
54+ if (!Tmp)
7855 return false ;
79- if (!getSubExpr ()->evaluateAsRelocatable (Res, Asm))
56+ Res = *Tmp;
57+ return true ;
58+ }
59+
60+ bool PPC::evaluateAsRelocatableImpl (const MCSpecifierExpr &Expr, MCValue &Res,
61+ const MCAssembler *Asm) {
62+ if (!Expr.getSubExpr ()->evaluateAsRelocatable (Res, Asm))
8063 return false ;
8164
8265 // The signedness of the result is dependent on the instruction operand. E.g.
8366 // in addis 3,3,65535@l, 65535@l is signed. In the absence of information at
8467 // parse time (!Asm), disable the folding.
85- std::optional<int64_t > MaybeInt = evaluateAsInt64 (Res.getConstant ());
68+ std::optional<int64_t > MaybeInt =
69+ evaluateAsInt64 (Expr.getSpecifier (), Res.getConstant ());
8670 if (Res.isAbsolute () && MaybeInt) {
8771 Res = MCValue::get (*MaybeInt);
8872 } else {
89- Res.setSpecifier (specifier );
73+ Res.setSpecifier (Expr. getSpecifier () );
9074 }
9175
9276 return true ;
0 commit comments