16
16
17
17
#ifndef NGEN_ASM_HPP
18
18
#define NGEN_ASM_HPP
19
- #ifdef NGEN_ASM
20
19
21
- #include " ngen_config.hpp"
20
+ #include " ngen_config_internal.hpp"
21
+
22
+ #ifdef NGEN_ASM
22
23
23
24
#include < array>
24
25
#include < cstdint>
25
26
#include < sstream>
26
27
#include < string>
27
28
29
+ #include " ngen_core.hpp"
30
+ #include " ngen_debuginfo.hpp"
28
31
#include " ngen_gen12.hpp"
29
32
30
33
namespace NGEN_NAMESPACE {
@@ -210,6 +213,7 @@ struct AsmInstruction {
210
213
explicit AsmInstruction (uint32_t inum_, const std::string &comment_)
211
214
: op(Opcode::illegal), ext(0 ), inum(inum_), mod{}, dst{}, src{}, labelManager{nullptr }, comment{comment_} {}
212
215
inline AsmInstruction (const autoswsb::SyncInsertion &si);
216
+ inline AsmInstruction (const autoswsb::DummyMovInsertion &mi);
213
217
214
218
bool isLabel () const { return (op == Opcode::illegal) && (dst.type == AsmOperand::Type::label); }
215
219
bool isComment () const { return (op == Opcode::illegal) && !comment.empty (); }
@@ -278,6 +282,21 @@ AsmInstruction::AsmInstruction(const autoswsb::SyncInsertion &si)
278
282
src[0 ] = NullRegister ();
279
283
}
280
284
285
+ AsmInstruction::AsmInstruction (const autoswsb::DummyMovInsertion &mi)
286
+ {
287
+ op = Opcode::mov_gen12;
288
+ ext = 0 ;
289
+ mod = 1 | InstructionModifier::createMaskCtrl (true );
290
+ mod.setSWSB (mi.swsb );
291
+ dst = NullRegister ().retype (mi.dt );
292
+ for (auto n = 1 ; n < 4 ; n++)
293
+ src[n] = NoOperand ();
294
+ if (mi.constant ) {
295
+ src[0 ] = Immediate::zero (mi.dt );
296
+ } else
297
+ src[0 ] = GRF (mi.grf ).sub (0 , mi.dt );
298
+ }
299
+
281
300
unsigned AsmInstruction::getTypecode (const AsmOperand &op)
282
301
{
283
302
DataType dt = DataType::invalid;
@@ -416,7 +435,7 @@ class AsmCodeGenerator {
416
435
streamStack.push_back (new InstructionStream ());
417
436
}
418
437
419
- explicit AsmCodeGenerator (HW hardware_, int stepping_ = 0 ) : AsmCodeGenerator({genericProductFamily (hardware_), 0 }) {}
438
+ explicit AsmCodeGenerator (HW hardware_, int stepping_ = 0 ) : AsmCodeGenerator({genericProductFamily (hardware_), 0 , PlatformType::Unknown }) {}
420
439
421
440
AsmCodeGenerator (HW hardware_, std::ostream &defaultOutput_, int stepping_ = 0 ) : AsmCodeGenerator(hardware_, stepping_) {
422
441
defaultOutput = &defaultOutput_;
@@ -488,7 +507,6 @@ class AsmCodeGenerator {
488
507
LabelManager labelManager;
489
508
std::vector<InstructionStream*> streamStack;
490
509
491
-
492
510
inline void unsupported ();
493
511
494
512
// Output functions.
@@ -555,7 +573,7 @@ class AsmCodeGenerator {
555
573
src0.fixup (hardware, 1 , 0 , defaultType, 0 , 3 );
556
574
src1.fixup (hardware, 1 , 0 , defaultType, 1 , 3 );
557
575
src2.fixup (hardware, 1 , 0 , defaultType, 2 , 3 );
558
- (void ) streamStack.back ()->append (op, static_cast < uint16_t >(( sdepth << 8 ) | rcount) , mod | defaultModifier, &labelManager, dst, src0, src1, src2);
576
+ (void ) streamStack.back ()->append (op, ( sdepth << 8 ) | rcount, mod | defaultModifier, &labelManager, dst, src0, src1, src2);
559
577
}
560
578
template <typename D, typename S0> void opCall (Opcode op, const InstructionModifier &mod, D dst, S0 src0) {
561
579
(void ) streamStack.back ()->append (op, 0 , mod | defaultModifier | NoMask, &labelManager, dst, src0);
@@ -582,7 +600,6 @@ class AsmCodeGenerator {
582
600
bool getDefaultNoMask () const { return defaultModifier.isWrEn (); }
583
601
bool getDefaultAutoSWSB () const { return defaultModifier.isAutoSWSB (); }
584
602
585
-
586
603
// Stream handling.
587
604
void pushStream () { pushStream (new InstructionStream ()); }
588
605
void pushStream (InstructionStream &s) { pushStream (&s); }
@@ -917,7 +934,7 @@ class AsmCodeGenerator {
917
934
void halt (const InstructionModifier &mod, Label &jip, SourceLocation loc = {}) {
918
935
halt (mod, jip, jip);
919
936
}
920
- void if_ (InstructionModifier mod, Label &jip, Label &uip, bool branchCtrl = false , SourceLocation loc = {}) {
937
+ void if_ (InstructionModifier mod, Label &jip, Label &uip, bool branchCtrl, SourceLocation loc = {}) {
921
938
(void ) jip.getID (labelManager);
922
939
(void ) uip.getID (labelManager);
923
940
opX (Opcode::if_, DataType::invalid, mod, NoOperand (), jip, uip, NoOperand (), branchCtrl);
@@ -1073,6 +1090,9 @@ class AsmCodeGenerator {
1073
1090
}
1074
1091
template <typename DT = void >
1075
1092
void movi (const InstructionModifier &mod, const RegData &dst, const RegData &src0, SourceLocation loc = {}) {
1093
+ #ifdef NGEN_SAFE
1094
+ if (!src0.isIndirect ()) throw invalid_address_mode_exception ();
1095
+ #endif
1076
1096
if (hardware >= HW::Gen10)
1077
1097
movi<DT>(mod, dst, src0, null);
1078
1098
else
@@ -1082,6 +1102,7 @@ class AsmCodeGenerator {
1082
1102
void movi (const InstructionModifier &mod, const RegData &dst, const RegData &src0, const Immediate &src1, SourceLocation loc = {}) {
1083
1103
#ifdef NGEN_SAFE
1084
1104
if (hardware < HW::Gen10) throw unsupported_instruction ();
1105
+ if (!src0.isIndirect ()) throw invalid_address_mode_exception ();
1085
1106
#endif
1086
1107
opX (isGen12 ? Opcode::movi_gen12 : Opcode::movi, getDataType<DT>(), mod, dst, src0, src1);
1087
1108
}
@@ -1585,17 +1606,24 @@ void AsmCodeGenerator::getCode(std::ostream &out)
1585
1606
1586
1607
autoswsb::BasicBlockList analysis = autoswsb::autoSWSB (hardware, declaredGRFs, streamStack.back ()->buffer );
1587
1608
std::multimap<int32_t , autoswsb::SyncInsertion*> syncs; // Syncs inserted by auto-SWSB.
1609
+ std::multimap<int32_t , autoswsb::DummyMovInsertion*> movs; // Dummy moves inserted by auto-SWSB.
1588
1610
1589
- for (auto &bb : analysis)
1590
- for (auto &sync : bb.syncs )
1611
+ for (auto &bb : analysis) {
1612
+ for (auto &sync : bb.syncs )
1591
1613
syncs.insert (std::make_pair (sync .inum , &sync ));
1614
+ for (auto &mov: bb.movs )
1615
+ movs.insert (std::make_pair (mov.inum , &mov));
1616
+ }
1592
1617
1593
1618
auto nextSync = syncs.begin ();
1619
+ auto nextMov = movs.begin ();
1594
1620
int lineNo = 0 ;
1595
1621
1596
1622
for (auto &i : streamStack.back ()->buffer ) {
1597
1623
while ((nextSync != syncs.end ()) && (nextSync->second ->inum == i.inum ))
1598
1624
outX (out, *(nextSync++)->second , lineNo++);
1625
+ while ((nextMov != movs.end ()) && (nextMov->second ->inum == i.inum ))
1626
+ outX (out, *(nextMov++)->second , lineNo++);
1599
1627
1600
1628
if (i.isLabel ()) {
1601
1629
i.dst .label .outputText (out, PrintDetail::full, labelManager);
0 commit comments