Skip to content

Commit 017d10b

Browse files
author
Vladimir Sukharev
committedMar 26, 2015
[AArch64] Move initializations of AArch64NamedImmMapper out of void AArch64Operand::print(...)
class AArch64NamedImmMapper is to become dependent of SubTargetFeatures, while class AArch64Operand don't have access to the latter. So, AArch64NamedImmMapper constructor invocations are refactored away from methods of AArch64Operand. Reviewers: jmolloy Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D8579 llvm-svn: 233297
1 parent 1459883 commit 017d10b

File tree

1 file changed

+48
-18
lines changed

1 file changed

+48
-18
lines changed
 

‎llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp

+48-18
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,8 @@ class AArch64Operand : public MCParsedAsmOperand {
204204

205205
struct BarrierOp {
206206
unsigned Val; // Not the enum since not all values have names.
207+
const char *Data;
208+
unsigned Length;
207209
};
208210

209211
struct SysRegOp {
@@ -220,6 +222,8 @@ class AArch64Operand : public MCParsedAsmOperand {
220222

221223
struct PrefetchOp {
222224
unsigned Val;
225+
const char *Data;
226+
unsigned Length;
223227
};
224228

225229
struct ShiftExtendOp {
@@ -347,6 +351,11 @@ class AArch64Operand : public MCParsedAsmOperand {
347351
return Barrier.Val;
348352
}
349353

354+
StringRef getBarrierName() const {
355+
assert(Kind == k_Barrier && "Invalid access!");
356+
return StringRef(Barrier.Data, Barrier.Length);
357+
}
358+
350359
unsigned getReg() const override {
351360
assert(Kind == k_Register && "Invalid access!");
352361
return Reg.RegNum;
@@ -382,6 +391,11 @@ class AArch64Operand : public MCParsedAsmOperand {
382391
return Prefetch.Val;
383392
}
384393

394+
StringRef getPrefetchName() const {
395+
assert(Kind == k_Prefetch && "Invalid access!");
396+
return StringRef(Prefetch.Data, Prefetch.Length);
397+
}
398+
385399
AArch64_AM::ShiftExtendType getShiftExtendType() const {
386400
assert(Kind == k_ShiftExtend && "Invalid access!");
387401
return ShiftExtend.Type;
@@ -1595,10 +1609,14 @@ class AArch64Operand : public MCParsedAsmOperand {
15951609
return Op;
15961610
}
15971611

1598-
static std::unique_ptr<AArch64Operand> CreateBarrier(unsigned Val, SMLoc S,
1612+
static std::unique_ptr<AArch64Operand> CreateBarrier(unsigned Val,
1613+
StringRef Str,
1614+
SMLoc S,
15991615
MCContext &Ctx) {
16001616
auto Op = make_unique<AArch64Operand>(k_Barrier, Ctx);
16011617
Op->Barrier.Val = Val;
1618+
Op->Barrier.Data = Str.data();
1619+
Op->Barrier.Length = Str.size();
16021620
Op->StartLoc = S;
16031621
Op->EndLoc = S;
16041622
return Op;
@@ -1629,10 +1647,14 @@ class AArch64Operand : public MCParsedAsmOperand {
16291647
return Op;
16301648
}
16311649

1632-
static std::unique_ptr<AArch64Operand> CreatePrefetch(unsigned Val, SMLoc S,
1650+
static std::unique_ptr<AArch64Operand> CreatePrefetch(unsigned Val,
1651+
StringRef Str,
1652+
SMLoc S,
16331653
MCContext &Ctx) {
16341654
auto Op = make_unique<AArch64Operand>(k_Prefetch, Ctx);
16351655
Op->Prefetch.Val = Val;
1656+
Op->Barrier.Data = Str.data();
1657+
Op->Barrier.Length = Str.size();
16361658
Op->StartLoc = S;
16371659
Op->EndLoc = S;
16381660
return Op;
@@ -1660,9 +1682,8 @@ void AArch64Operand::print(raw_ostream &OS) const {
16601682
<< AArch64_AM::getFPImmFloat(getFPImm()) << ") >";
16611683
break;
16621684
case k_Barrier: {
1663-
bool Valid;
1664-
StringRef Name = AArch64DB::DBarrierMapper().toString(getBarrier(), Valid);
1665-
if (Valid)
1685+
StringRef Name = getBarrierName();
1686+
if (!Name.empty())
16661687
OS << "<barrier " << Name << ">";
16671688
else
16681689
OS << "<barrier invalid #" << getBarrier() << ">";
@@ -1705,9 +1726,8 @@ void AArch64Operand::print(raw_ostream &OS) const {
17051726
OS << "c" << getSysCR();
17061727
break;
17071728
case k_Prefetch: {
1708-
bool Valid;
1709-
StringRef Name = AArch64PRFM::PRFMMapper().toString(getPrefetch(), Valid);
1710-
if (Valid)
1729+
StringRef Name = getPrefetchName();
1730+
if (!Name.empty())
17111731
OS << "<prfop " << Name << ">";
17121732
else
17131733
OS << "<prfop invalid #" << getPrefetch() << ">";
@@ -1950,7 +1970,11 @@ AArch64AsmParser::tryParsePrefetch(OperandVector &Operands) {
19501970
return MatchOperand_ParseFail;
19511971
}
19521972

1953-
Operands.push_back(AArch64Operand::CreatePrefetch(prfop, S, getContext()));
1973+
bool Valid;
1974+
auto Mapper = AArch64PRFM::PRFMMapper();
1975+
StringRef Name = Mapper.toString(MCE->getValue(), Valid);
1976+
Operands.push_back(AArch64Operand::CreatePrefetch(prfop, Name,
1977+
S, getContext()));
19541978
return MatchOperand_Success;
19551979
}
19561980

@@ -1960,14 +1984,16 @@ AArch64AsmParser::tryParsePrefetch(OperandVector &Operands) {
19601984
}
19611985

19621986
bool Valid;
1963-
unsigned prfop = AArch64PRFM::PRFMMapper().fromString(Tok.getString(), Valid);
1987+
auto Mapper = AArch64PRFM::PRFMMapper();
1988+
unsigned prfop = Mapper.fromString(Tok.getString(), Valid);
19641989
if (!Valid) {
19651990
TokError("pre-fetch hint expected");
19661991
return MatchOperand_ParseFail;
19671992
}
19681993

19691994
Parser.Lex(); // Eat identifier token.
1970-
Operands.push_back(AArch64Operand::CreatePrefetch(prfop, S, getContext()));
1995+
Operands.push_back(AArch64Operand::CreatePrefetch(prfop, Tok.getString(),
1996+
S, getContext()));
19711997
return MatchOperand_Success;
19721998
}
19731999

@@ -2569,8 +2595,11 @@ AArch64AsmParser::tryParseBarrierOperand(OperandVector &Operands) {
25692595
Error(ExprLoc, "barrier operand out of range");
25702596
return MatchOperand_ParseFail;
25712597
}
2572-
Operands.push_back(
2573-
AArch64Operand::CreateBarrier(MCE->getValue(), ExprLoc, getContext()));
2598+
bool Valid;
2599+
auto Mapper = AArch64DB::DBarrierMapper();
2600+
StringRef Name = Mapper.toString(MCE->getValue(), Valid);
2601+
Operands.push_back( AArch64Operand::CreateBarrier(MCE->getValue(), Name,
2602+
ExprLoc, getContext()));
25742603
return MatchOperand_Success;
25752604
}
25762605

@@ -2580,7 +2609,8 @@ AArch64AsmParser::tryParseBarrierOperand(OperandVector &Operands) {
25802609
}
25812610

25822611
bool Valid;
2583-
unsigned Opt = AArch64DB::DBarrierMapper().fromString(Tok.getString(), Valid);
2612+
auto Mapper = AArch64DB::DBarrierMapper();
2613+
unsigned Opt = Mapper.fromString(Tok.getString(), Valid);
25842614
if (!Valid) {
25852615
TokError("invalid barrier option name");
25862616
return MatchOperand_ParseFail;
@@ -2592,8 +2622,8 @@ AArch64AsmParser::tryParseBarrierOperand(OperandVector &Operands) {
25922622
return MatchOperand_ParseFail;
25932623
}
25942624

2595-
Operands.push_back(
2596-
AArch64Operand::CreateBarrier(Opt, getLoc(), getContext()));
2625+
Operands.push_back( AArch64Operand::CreateBarrier(Opt, Tok.getString(),
2626+
getLoc(), getContext()));
25972627
Parser.Lex(); // Consume the option
25982628

25992629
return MatchOperand_Success;
@@ -2618,8 +2648,8 @@ AArch64AsmParser::tryParseSysReg(OperandVector &Operands) {
26182648
assert(IsKnown == (MSRReg != -1U) &&
26192649
"register should be -1 if and only if it's unknown");
26202650

2621-
uint32_t PStateField =
2622-
AArch64PState::PStateMapper().fromString(Tok.getString(), IsKnown);
2651+
auto PStateMapper = AArch64PState::PStateMapper();
2652+
uint32_t PStateField = PStateMapper.fromString(Tok.getString(), IsKnown);
26232653
assert(IsKnown == (PStateField != -1U) &&
26242654
"register should be -1 if and only if it's unknown");
26252655

0 commit comments

Comments
 (0)
Please sign in to comment.