Skip to content

Commit 8a6618e

Browse files
author
git apple-llvm automerger
committed
Merge commit 'ff05c3bd6a7a' from apple/main into swift/next
2 parents 091dfad + ff05c3b commit 8a6618e

File tree

5 files changed

+74
-21
lines changed

5 files changed

+74
-21
lines changed

llvm/include/llvm/MC/MCStreamer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#ifndef LLVM_MC_MCSTREAMER_H
1414
#define LLVM_MC_MCSTREAMER_H
1515

16+
#include "llvm/ADT/APInt.h"
1617
#include "llvm/ADT/ArrayRef.h"
1718
#include "llvm/ADT/DenseMap.h"
1819
#include "llvm/ADT/Optional.h"
@@ -673,6 +674,7 @@ class MCStreamer {
673674
/// Special case of EmitValue that avoids the client having
674675
/// to pass in a MCExpr for constant integers.
675676
virtual void emitIntValue(uint64_t Value, unsigned Size);
677+
virtual void emitIntValue(APInt Value);
676678

677679
/// Special case of EmitValue that avoids the client having to pass
678680
/// in a MCExpr for constant integers & prints in Hex format for certain

llvm/lib/MC/MCParser/MasmParser.cpp

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,7 @@ class MasmParser : public MCAsmParser {
634634
DK_DW,
635635
DK_REAL4,
636636
DK_REAL8,
637+
DK_REAL10,
637638
DK_ALIGN,
638639
DK_ORG,
639640
DK_ENDR,
@@ -771,7 +772,7 @@ class MasmParser : public MCAsmParser {
771772
bool parseDirectiveNamedValue(StringRef TypeName, unsigned Size,
772773
StringRef Name, SMLoc NameLoc);
773774

774-
// "real4", "real8"
775+
// "real4", "real8", "real10"
775776
bool emitRealValues(const fltSemantics &Semantics, unsigned *Count = nullptr);
776777
bool addRealField(StringRef Name, const fltSemantics &Semantics, size_t Size);
777778
bool parseDirectiveRealValue(StringRef IDVal, const fltSemantics &Semantics,
@@ -2147,6 +2148,8 @@ bool MasmParser::parseStatement(ParseStatementInfo &Info,
21472148
return parseDirectiveRealValue(IDVal, APFloat::IEEEsingle(), 4);
21482149
case DK_REAL8:
21492150
return parseDirectiveRealValue(IDVal, APFloat::IEEEdouble(), 8);
2151+
case DK_REAL10:
2152+
return parseDirectiveRealValue(IDVal, APFloat::x87DoubleExtended(), 10);
21502153
case DK_STRUCT:
21512154
case DK_UNION:
21522155
return parseDirectiveNestedStruct(IDVal, DirKind);
@@ -2382,6 +2385,10 @@ bool MasmParser::parseStatement(ParseStatementInfo &Info,
23822385
Lex();
23832386
return parseDirectiveNamedRealValue(nextVal, APFloat::IEEEdouble(), 8,
23842387
IDVal, IDLoc);
2388+
case DK_REAL10:
2389+
Lex();
2390+
return parseDirectiveNamedRealValue(nextVal, APFloat::x87DoubleExtended(),
2391+
10, IDVal, IDLoc);
23852392
case DK_STRUCT:
23862393
case DK_UNION:
23872394
Lex();
@@ -3456,14 +3463,14 @@ bool MasmParser::parseRealValue(const fltSemantics &Semantics, APInt &Res) {
34563463
} else if (IDVal.consume_back("r") || IDVal.consume_back("R")) {
34573464
// MASM hexadecimal floating-point literal; no APFloat conversion needed.
34583465
// To match ML64.exe, ignore the initial sign.
3459-
unsigned Size = Value.getSizeInBits(Semantics);
3460-
if (Size != (IDVal.size() << 2))
3466+
unsigned SizeInBits = Value.getSizeInBits(Semantics);
3467+
if (SizeInBits != (IDVal.size() << 2))
34613468
return TokError("invalid floating point literal");
34623469

34633470
// Consume the numeric token.
34643471
Lex();
34653472

3466-
Res = APInt(Size, IDVal, 16);
3473+
Res = APInt(SizeInBits, IDVal, 16);
34673474
if (SignLoc.isValid())
34683475
return Warning(SignLoc, "MASM-style hex floats ignore explicit sign");
34693476
return false;
@@ -3540,8 +3547,7 @@ bool MasmParser::emitRealValues(const fltSemantics &Semantics,
35403547
return true;
35413548

35423549
for (const APInt &AsInt : ValuesAsInt) {
3543-
getStreamer().emitIntValue(AsInt.getLimitedValue(),
3544-
AsInt.getBitWidth() / 8);
3550+
getStreamer().emitIntValue(AsInt);
35453551
}
35463552
if (Count)
35473553
*Count = ValuesAsInt.size();
@@ -3571,7 +3577,7 @@ bool MasmParser::addRealField(StringRef Name, const fltSemantics &Semantics,
35713577
}
35723578

35733579
/// parseDirectiveRealValue
3574-
/// ::= (real4 | real8) [ expression (, expression)* ]
3580+
/// ::= (real4 | real8 | real10) [ expression (, expression)* ]
35753581
bool MasmParser::parseDirectiveRealValue(StringRef IDVal,
35763582
const fltSemantics &Semantics,
35773583
size_t Size) {
@@ -3586,7 +3592,7 @@ bool MasmParser::parseDirectiveRealValue(StringRef IDVal,
35863592
}
35873593

35883594
/// parseDirectiveNamedRealValue
3589-
/// ::= name (real4 | real8) [ expression (, expression)* ]
3595+
/// ::= name (real4 | real8 | real10) [ expression (, expression)* ]
35903596
bool MasmParser::parseDirectiveNamedRealValue(StringRef TypeName,
35913597
const fltSemantics &Semantics,
35923598
unsigned Size, StringRef Name,
@@ -3680,29 +3686,41 @@ bool MasmParser::parseFieldInitializer(const FieldInfo &Field,
36803686
bool MasmParser::parseFieldInitializer(const FieldInfo &Field,
36813687
const RealFieldInfo &Contents,
36823688
FieldInitializer &Initializer) {
3683-
const fltSemantics &Semantics =
3684-
(Field.Type == 4) ? APFloat::IEEEsingle() : APFloat::IEEEdouble();
3689+
const fltSemantics *Semantics;
3690+
switch (Field.Type) {
3691+
case 4:
3692+
Semantics = &APFloat::IEEEsingle();
3693+
break;
3694+
case 8:
3695+
Semantics = &APFloat::IEEEdouble();
3696+
break;
3697+
case 10:
3698+
Semantics = &APFloat::x87DoubleExtended();
3699+
break;
3700+
default:
3701+
llvm_unreachable("unknown real field type");
3702+
}
36853703

36863704
SMLoc Loc = getTok().getLoc();
36873705

36883706
SmallVector<APInt, 1> AsIntValues;
36893707
if (parseOptionalToken(AsmToken::LCurly)) {
36903708
if (Field.LengthOf == 1)
36913709
return Error(Loc, "Cannot initialize scalar field with array value");
3692-
if (parseRealInstList(Semantics, AsIntValues, AsmToken::RCurly) ||
3710+
if (parseRealInstList(*Semantics, AsIntValues, AsmToken::RCurly) ||
36933711
parseToken(AsmToken::RCurly))
36943712
return true;
36953713
} else if (parseOptionalAngleBracketOpen()) {
36963714
if (Field.LengthOf == 1)
36973715
return Error(Loc, "Cannot initialize scalar field with array value");
3698-
if (parseRealInstList(Semantics, AsIntValues, AsmToken::Greater) ||
3716+
if (parseRealInstList(*Semantics, AsIntValues, AsmToken::Greater) ||
36993717
parseAngleBracketClose())
37003718
return true;
37013719
} else if (Field.LengthOf > 1) {
37023720
return Error(Loc, "Cannot initialize array field with scalar value");
37033721
} else {
37043722
AsIntValues.emplace_back();
3705-
if (parseRealValue(Semantics, AsIntValues.back()))
3723+
if (parseRealValue(*Semantics, AsIntValues.back()))
37063724
return true;
37073725
}
37083726

@@ -6278,6 +6296,7 @@ void MasmParser::initializeDirectiveKindMap() {
62786296
DirectiveKindMap["sqword"] = DK_SQWORD;
62796297
DirectiveKindMap["real4"] = DK_REAL4;
62806298
DirectiveKindMap["real8"] = DK_REAL8;
6299+
DirectiveKindMap["real10"] = DK_REAL10;
62816300
DirectiveKindMap["align"] = DK_ALIGN;
62826301
// DirectiveKindMap[".org"] = DK_ORG;
62836302
DirectiveKindMap["extern"] = DK_EXTERN;
@@ -6732,6 +6751,7 @@ bool MasmParser::lookUpType(StringRef Name, AsmTypeInfo &Info) const {
67326751
.CasesLower("qword", "dq", "sqword", 8)
67336752
.CaseLower("real4", 4)
67346753
.CaseLower("real8", 8)
6754+
.CaseLower("real10", 10)
67356755
.Default(0);
67366756
if (Size) {
67376757
Info.Name = Name;

llvm/lib/MC/MCStreamer.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,21 @@ void MCStreamer::emitIntValue(uint64_t Value, unsigned Size) {
138138
unsigned Index = IsLittleEndian ? 0 : 8 - Size;
139139
emitBytes(StringRef(reinterpret_cast<char *>(&Swapped) + Index, Size));
140140
}
141+
void MCStreamer::emitIntValue(APInt Value) {
142+
if (Value.getNumWords() == 1) {
143+
emitIntValue(Value.getLimitedValue(), Value.getBitWidth() / 8);
144+
return;
145+
}
146+
147+
const bool IsLittleEndianTarget = Context.getAsmInfo()->isLittleEndian();
148+
const bool ShouldSwap = sys::IsLittleEndianHost != IsLittleEndianTarget;
149+
const APInt Swapped = ShouldSwap ? Value.byteSwap() : Value;
150+
const unsigned Size = Value.getBitWidth() / 8;
151+
SmallString<10> Tmp;
152+
Tmp.resize(Size);
153+
StoreIntToMemory(Swapped, reinterpret_cast<uint8_t *>(Tmp.data()), Size);
154+
emitBytes(Tmp.str());
155+
}
141156

142157
/// EmitULEB128IntValue - Special case of EmitULEB128Value that avoids the
143158
/// client having to pass in a MCExpr for constant integers.

llvm/test/tools/llvm-ml/builtin_types.test

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,20 +65,28 @@ t5_signed SQWORD -4611686018427387904
6565
; CHECK-NEXT: .quad -4611686018427387904
6666

6767
t6_single REAL4 1.3
68-
t6_double REAL8 1.3
68+
t6_single_hex REAL4 3fa66666r
6969

7070
; CHECK-LABEL: t6_single:
7171
; CHECK-NEXT: .long 1067869798
72-
; CHECK-LABEL: t6_double:
73-
; CHECK-NEXT: .quad 4608533498688228557
72+
; CHECK-LABEL: t6_single_hex:
73+
; CHECK-NEXT: .long 1067869798
7474

75-
t7_single_hex REAL4 3f800000r
76-
t7_double_hex REAL8 3FF0000000000000R
75+
t7_double REAL8 1.3
76+
t7_double_hex REAL8 3FF4CCCCCCCCCCCDR
7777

78-
; CHECK-LABEL: t7_single_hex:
79-
; CHECK-NEXT: .long 1065353216
78+
; CHECK-LABEL: t7_double:
79+
; CHECK-NEXT: .quad 4608533498688228557
8080
; CHECK-LABEL: t7_double_hex:
81-
; CHECK-NEXT: .quad 4607182418800017408
81+
; CHECK-NEXT: .quad 4608533498688228557
82+
83+
t8_extended REAL10 1.3
84+
t8_extended_hex REAL10 3FFFA666666666666666r
85+
86+
; CHECK-LABEL: t8_extended:
87+
; CHECK-NEXT: .ascii "fffffff\246\377?"
88+
; CHECK-LABEL: t8_extended_hex:
89+
; CHECK-NEXT: .ascii "fffffff\246\377?"
8290

8391
.code
8492

llvm/test/tools/llvm-ml/type_operators.test

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ mov eax, type(t6_signed)
196196

197197
t7_single REAL4 2 DUP (?)
198198
t7_double REAL8 ?
199+
t7_extended REAL10 3 DUP (?)
199200

200201
t7:
201202
; CHECK-LABEL: t7:
@@ -214,6 +215,13 @@ mov eax, type(t7_double)
214215
; CHECK: mov eax, 1
215216
; CHECK: mov eax, 8
216217

218+
mov eax, sizeof(t7_extended)
219+
mov eax, lengthof(t7_extended)
220+
mov eax, type(t7_extended)
221+
; CHECK: mov eax, 30
222+
; CHECK: mov eax, 3
223+
; CHECK: mov eax, 10
224+
217225

218226
t8_var FOO <>, <>
219227

0 commit comments

Comments
 (0)