55#include "llvm/IR/IntrinsicsX86.h"
69#define DEBUG_TYPE "x86-lower-amx-type"
85 if (
II->getType()->isX86_AMXTy())
88 if (
V->getType()->isX86_AMXTy())
98 if (
I.getType()->isX86_AMXTy())
110 switch (
II->getIntrinsicID()) {
112 case Intrinsic::x86_acev1_top2bf16ps_internal:
113 case Intrinsic::x86_acev1_top4buud_internal:
114 case Intrinsic::x86_acev1_top4busd_internal:
115 case Intrinsic::x86_acev1_top4bssd_internal:
116 case Intrinsic::x86_acev1_top4bsud_internal:
118 case Intrinsic::x86_acev1_top4mxhf8ps_internal:
119 case Intrinsic::x86_acev1_top4mxbhf8ps_internal:
120 case Intrinsic::x86_acev1_top4mxhbf8ps_internal:
121 case Intrinsic::x86_acev1_top4mxbf8ps_internal:
122 case Intrinsic::x86_acev1_top4mxbssps_internal:
124 case Intrinsic::x86_acev1_tilemovcolinsert_internal:
125 case Intrinsic::x86_acev1_tilemovrowinsert_internal:
127 case Intrinsic::x86_acev1_tilezero_internal:
128 case Intrinsic::x86_acev1_tcvtrowps2bf16h_internal:
129 case Intrinsic::x86_acev1_tcvtrowps2bf16l_internal:
130 case Intrinsic::x86_acev1_tcvtrowps2phh_internal:
131 case Intrinsic::x86_acev1_tcvtrowps2phl_internal:
132 case Intrinsic::x86_acev1_tcvtrowd2ps_internal:
133 case Intrinsic::x86_acev1_tilemovrowextract_internal:
142 for (
unsigned I = 0,
E =
PHI->getNumIncomingValues();
I !=
E; ++
I) {
159 unsigned AllocaAS =
DL.getAllocaAddrSpace();
161 new AllocaInst(Ty, AllocaAS,
"",
F.getEntryBlock().begin());
175 Value *RealRow =
nullptr;
193 RealRow = Builder.CreateUDiv(
V, Builder.getInt16(4));
207 Value *Row =
nullptr, *Col =
nullptr;
208 switch (
II->getIntrinsicID()) {
211 case Intrinsic::x86_tileloadd64_internal:
212 case Intrinsic::x86_tileloaddt164_internal:
213 case Intrinsic::x86_tilestored64_internal:
214 case Intrinsic::x86_tileloaddrs64_internal:
215 case Intrinsic::x86_tileloaddrst164_internal: {
216 Row =
II->getArgOperand(0);
217 Col =
II->getArgOperand(1);
222 case Intrinsic::x86_tcmmimfp16ps_internal:
223 case Intrinsic::x86_tcmmrlfp16ps_internal:
224 case Intrinsic::x86_tdpbssd_internal:
225 case Intrinsic::x86_tdpbsud_internal:
226 case Intrinsic::x86_tdpbusd_internal:
227 case Intrinsic::x86_tdpbuud_internal:
228 case Intrinsic::x86_tdpbf16ps_internal:
229 case Intrinsic::x86_tdpfp16ps_internal:
230 case Intrinsic::x86_tdpbf8ps_internal:
231 case Intrinsic::x86_tdpbhf8ps_internal:
232 case Intrinsic::x86_tdphbf8ps_internal:
233 case Intrinsic::x86_tdphf8ps_internal: {
236 Row =
II->getArgOperand(0);
237 Col =
II->getArgOperand(1);
240 Row =
II->getArgOperand(0);
241 Col =
II->getArgOperand(2);
245 Col =
II->getArgOperand(1);
250 case Intrinsic::x86_tcvtrowd2ps_internal:
251 case Intrinsic::x86_tcvtrowps2bf16h_internal:
252 case Intrinsic::x86_tcvtrowps2bf16l_internal:
253 case Intrinsic::x86_tcvtrowps2phh_internal:
254 case Intrinsic::x86_tcvtrowps2phl_internal:
255 case Intrinsic::x86_tilemovrow_internal:
256 case Intrinsic::x86_acev1_tcvtrowps2bf16h_internal:
257 case Intrinsic::x86_acev1_tcvtrowps2bf16l_internal:
258 case Intrinsic::x86_acev1_tcvtrowps2phh_internal:
259 case Intrinsic::x86_acev1_tcvtrowps2phl_internal:
260 case Intrinsic::x86_acev1_tcvtrowd2ps_internal:
261 case Intrinsic::x86_acev1_tilemovrowextract_internal: {
262 assert(OpNo == 2 &&
"Illegal Operand Number.");
263 Row =
II->getArgOperand(0);
264 Col =
II->getArgOperand(1);
271 case Intrinsic::x86_acev1_top2bf16ps_internal:
272 case Intrinsic::x86_acev1_top4buud_internal:
273 case Intrinsic::x86_acev1_top4busd_internal:
274 case Intrinsic::x86_acev1_top4bssd_internal:
275 case Intrinsic::x86_acev1_top4bsud_internal: {
276 assert(OpNo == 2 &&
"Illegal Operand Number.");
277 Row =
II->getArgOperand(0);
278 Col =
II->getArgOperand(1);
282 case Intrinsic::x86_acev1_top4mxhf8ps_internal:
283 case Intrinsic::x86_acev1_top4mxbhf8ps_internal:
284 case Intrinsic::x86_acev1_top4mxhbf8ps_internal:
285 case Intrinsic::x86_acev1_top4mxbf8ps_internal:
286 case Intrinsic::x86_acev1_top4mxbssps_internal: {
287 assert(OpNo == 3 &&
"Illegal Operand Number.");
288 Row =
II->getArgOperand(0);
289 Col =
II->getArgOperand(1);
294 case Intrinsic::x86_acev1_tilemovcolinsert_internal:
295 case Intrinsic::x86_acev1_tilemovrowinsert_internal: {
296 assert(OpNo == 2 &&
"Illegal Operand Number.");
297 Row =
II->getArgOperand(0);
298 Col =
II->getArgOperand(1);
303 return std::make_pair(Row, Col);
309 Use &U = *(Phi->use_begin());
310 OpNo = U.getOperandNo();
311 User *
V = U.getUser();
320 Use &U = *(
V->use_begin());
321 OpNo = U.getOperandNo();
328 Use &U = *(
V->use_begin());
343 ? Intrinsic::x86_acev1_tilezero_internal
344 : Intrinsic::x86_tilezero_internal;
356 Value *Rows = Builder.CreateBitCast(Vec, RowsTy);
358 Value *Tile = Builder.CreateIntrinsic(Intrinsic::x86_acev1_tilezero_internal,
364 Tile = Builder.CreateIntrinsic(
365 Intrinsic::x86_acev1_tilemovrowinsert_internal, {},
366 {Row, Col, Tile, Builder.CreateShuffleVector(Rows, Mask),
367 Builder.getInt32(R)});
378 Builder.CreateIntrinsic(Intrinsic::x86_acev1_tilemovrowextract_internal,
379 {}, {Row, Col, Tile, Builder.getInt32(R)}));
386 for (
unsigned E = 0;
E != 2 * NumElts; ++
E)
388 for (
unsigned I = 0;
I != Width / 2; ++
I)
389 Rows[
I] = Builder.CreateShuffleVector(Rows[2 *
I], Rows[2 *
I + 1], Mask);
391 return Builder.CreateBitCast(Rows[0], VecTy);
395class X86LowerAMXType {
401 std::map<Value *, Value *> Col2Row;
406 void combineLoadBitcast(LoadInst *LD, BitCastInst *Bitcast);
407 void combineBitcastStore(BitCastInst *Bitcast, StoreInst *ST);
408 bool transformBitcast(BitCastInst *Bitcast);
417 Value *Row =
nullptr, *Col =
nullptr;
419 unsigned OpNo =
U.getOperandNo();
424 Value *Stride = Builder.getInt64(64);
425 Value *I8Ptr =
LD->getOperand(0);
426 std::array<Value *, 4>
Args = {Row, Col, I8Ptr, Stride};
429 Builder.CreateIntrinsic(Intrinsic::x86_tileloadd64_internal, Args);
430 Bitcast->replaceAllUsesWith(NewInst);
440void X86LowerAMXType::combineBitcastStore(BitCastInst *Bitcast, StoreInst *ST) {
446 Value *Row =
II->getOperand(0);
447 Value *Col =
II->getOperand(1);
451 Value *Stride = Builder.getInt64(64);
452 Value *I8Ptr =
ST->getOperand(1);
453 std::array<Value *, 5>
Args = {Row, Col, I8Ptr, Stride, Tile};
454 Builder.CreateIntrinsic(Intrinsic::x86_tilestored64_internal, Args);
466 Value *Vec = Builder.CreateLoad(
Bitcast->getType(),
ST->getOperand(1));
467 Bitcast->replaceAllUsesWith(Vec);
471bool X86LowerAMXType::transformBitcast(BitCastInst *Bitcast) {
473 AllocaInst *AllocaAddr;
474 Value *I8Ptr, *Stride;
475 auto *Src =
Bitcast->getOperand(0);
477 auto Prepare = [&](
Type *MemTy) {
480 Stride = Builder.getInt64(64);
483 if (
Bitcast->getType()->isX86_AMXTy()) {
493 unsigned OpNo =
U.getOperandNo();
497 Prepare(
Bitcast->getOperand(0)->getType());
498 Builder.CreateStore(Src, AllocaAddr);
500 Value *Row =
nullptr, *Col =
nullptr;
502 std::array<Value *, 4>
Args = {Row, Col, I8Ptr, Stride};
504 Builder.CreateIntrinsic(Intrinsic::x86_tileloadd64_internal, Args);
505 Bitcast->replaceAllUsesWith(NewInst);
518 Value *Row =
II->getOperand(0);
519 Value *Col =
II->getOperand(1);
520 std::array<Value *, 5>
Args = {Row, Col, I8Ptr, Stride, Src};
521 Builder.CreateIntrinsic(Intrinsic::x86_tilestored64_internal, Args);
522 Value *NewInst = Builder.CreateLoad(
Bitcast->getType(), AllocaAddr);
523 Bitcast->replaceAllUsesWith(NewInst);
529bool X86LowerAMXType::visit() {
530 SmallVector<Instruction *, 8> DeadInsts;
540 if (
Bitcast->getType()->isX86_AMXTy()) {
547 if (transformBitcast(Bitcast))
567 combineLoadBitcast(LD, Bitcast);
571 }
else if (Src->getType()->isX86_AMXTy()) {
576 StoreInst *
ST =
nullptr;
577 for (Instruction *U :
Bitcast->users()) {
583 if (transformBitcast(Bitcast))
607 combineBitcastStore(Bitcast, ST);
615 bool C = !DeadInsts.
empty();
617 for (
auto *Inst : DeadInsts)
618 Inst->eraseFromParent();
628 unsigned AllocaAS =
DL.getAllocaAddrSpace();
631 new AllocaInst(V256I32Ty, AllocaAS,
"",
F->getEntryBlock().begin());
634 Builder.SetInsertPoint(&*Iter);
635 Value *I8Ptr = Builder.CreateBitCast(AllocaRes, Builder.getPtrTy());
643 assert(
II &&
"Not tile intrinsic!");
644 Value *Row =
II->getOperand(0);
645 Value *Col =
II->getOperand(1);
649 Value *Stride = Builder.getInt64(64);
650 std::array<Value *, 5> Args = {Row, Col, Ptr, Stride, TileDef};
652 Instruction *TileStore = Builder.CreateIntrinsicWithoutFolding(
653 Intrinsic::x86_tilestored64_internal, Args);
659 assert(
V->getType()->isX86_AMXTy() &&
"Not define tile!");
669 Value *Row =
II->getOperand(0);
670 Value *Col =
II->getOperand(1);
674 Value *Stride = Builder.getInt64(64);
675 std::array<Value *, 4> Args = {Row, Col, Ptr, Stride};
678 Builder.CreateIntrinsic(Intrinsic::x86_tileloadd64_internal, Args);
693class X86VolatileTileData {
698 Value *updatePhiIncomings(BasicBlock *BB,
699 SmallVector<Instruction *, 2> &Incomings);
700 void replacePhiDefWithLoad(Instruction *
PHI,
Value *StorePtr);
701 bool volatileTileData();
702 void volatileTilePHI(PHINode *
PHI);
703 void volatileTileNonPHI(Instruction *
I);
706Value *X86VolatileTileData::updatePhiIncomings(
707 BasicBlock *BB, SmallVector<Instruction *, 2> &Incomings) {
710 for (
auto *
I : Incomings) {
714 for (Use &U :
I->uses()) {
724void X86VolatileTileData::replacePhiDefWithLoad(Instruction *
PHI,
726 for (Use &U :
PHI->uses())
728 PHI->eraseFromParent();
786void X86VolatileTileData::volatileTilePHI(PHINode *
PHI) {
788 SmallVector<Instruction *, 2> Incomings;
790 for (
unsigned I = 0,
E =
PHI->getNumIncomingValues();
I !=
E; ++
I) {
793 assert(Inst &&
"We shouldn't fold AMX instruction!");
797 Value *StorePtr = updatePhiIncomings(BB, Incomings);
798 replacePhiDefWithLoad(
PHI, StorePtr);
817void X86VolatileTileData::volatileTileNonPHI(Instruction *
I) {
823 for (Use &U :
I->uses()) {
843bool X86VolatileTileData::volatileTileData() {
845 for (BasicBlock &BB :
F) {
846 SmallVector<Instruction *, 2> PHIInsts;
847 SmallVector<Instruction *, 8> AMXDefInsts;
849 for (Instruction &
I : BB) {
850 if (!
I.getType()->isX86_AMXTy())
859 for (Instruction *
I : AMXDefInsts) {
866 volatileTileNonPHI(
I);
870 for (Instruction *
I : PHIInsts) {
885class X86LowerAMXCast {
887 std::unique_ptr<DominatorTree> DT;
891 bool combineCastStore(IntrinsicInst *Cast, StoreInst *ST);
892 bool combineLoadCast(IntrinsicInst *Cast, LoadInst *LD);
893 bool combineTilezero(IntrinsicInst *Cast);
894 bool combineLdSt(SmallVectorImpl<Instruction *> &Casts);
895 bool combineAMXcast(TargetLibraryInfo *
TLI);
896 bool transformAMXCast(IntrinsicInst *AMXCast);
897 bool transformAllAMXCast();
898 bool optimizeAMXCastFromPhi(IntrinsicInst *CI, PHINode *PN,
899 SmallSetVector<Instruction *, 16> &DeadInst);
903 SmallSetVector<Instruction *, 16> &WorkList,
904 const TargetLibraryInfo *
TLI) {
911 for (
unsigned i = 0, e =
I->getNumOperands(); i != e; ++i) {
912 Value *OpV =
I->getOperand(i);
913 I->setOperand(i,
nullptr);
927 I->eraseFromParent();
941bool X86LowerAMXCast::optimizeAMXCastFromPhi(
942 IntrinsicInst *CI, PHINode *PN,
943 SmallSetVector<Instruction *, 16> &DeadInst) {
946 Type *SrcTy = Src->getType();
950 SmallSetVector<PHINode *, 4> OldPhiNodes;
958 while (!PhiWorklist.
empty()) {
960 for (
unsigned I = 0;
I < OldPN->getNumOperands(); ++
I) {
961 Value *IncValue = OldPN->getIncomingValue(
I);
968 Value *Row =
nullptr, *Col =
nullptr;
969 unsigned ConsumerOpNo = 0;
972 std::tie(Row, Col) =
getShape(Consumer, ConsumerOpNo);
978 auto *
Block = OldPN->getIncomingBlock(
I);
980 Instruction *NewInst = Builder.CreateIntrinsicWithoutFolding(
983 NewInst = Builder.CreateIntrinsicWithoutFolding(
984 Intrinsic::x86_cast_tile_to_vector, {IncValue->
getType()},
988 OldPN->setIncomingValue(
I, NewInst);
993 if (OldPhiNodes.
insert(PNode))
1002 if (TyA != DestTy || TyB != SrcTy)
1012 for (
auto *OldPN : OldPhiNodes) {
1013 for (Instruction *
V : OldPN->users()) {
1016 Type *TyB =
V->getOperand(0)->getType();
1017 Type *TyA =
V->getType();
1018 if (TyA != DestTy || TyB != SrcTy)
1039 if (OldPhiNodes.count(
PHI) == 0)
1047 SmallDenseMap<PHINode *, PHINode *> NewPNodes;
1048 for (
auto *OldPN : OldPhiNodes) {
1049 Builder.SetInsertPoint(OldPN);
1050 PHINode *NewPN = Builder.CreatePHI(DestTy, OldPN->getNumOperands());
1051 NewPNodes[OldPN] = NewPN;
1055 for (
auto *OldPN : OldPhiNodes) {
1056 PHINode *NewPN = NewPNodes[OldPN];
1057 for (
unsigned j = 0, e = OldPN->getNumOperands(); j != e; ++j) {
1058 Value *
V = OldPN->getOperand(j);
1059 Value *NewV =
nullptr;
1065 NewV = NewPNodes[PrevPN];
1067 NewPN->
addIncoming(NewV, OldPN->getIncomingBlock(j));
1079 for (
auto *OldPN : OldPhiNodes) {
1080 PHINode *NewPN = NewPNodes[OldPN];
1083 Type *TyB =
V->getOperand(0)->getType();
1084 Type *TyA =
V->getType();
1085 assert(TyA == DestTy && TyB == SrcTy);
1088 V->replaceAllUsesWith(NewPN);
1107bool X86LowerAMXCast::combineCastStore(IntrinsicInst *Cast, StoreInst *ST) {
1110 assert(Tile->getType()->isX86_AMXTy() &&
"Not Tile Operand!");
1113 if (!Tile->hasOneUse())
1123 Value *Row =
II->getOperand(0);
1124 Value *Col =
II->getOperand(1);
1129 Value *Stride = Builder.CreateSExt(Col, Builder.getInt64Ty());
1130 Value *I8Ptr = Builder.CreateBitCast(
ST->getOperand(1), Builder.getPtrTy());
1131 std::array<Value *, 5>
Args = {Row, Col, I8Ptr, Stride, Tile};
1132 Builder.CreateIntrinsic(Intrinsic::x86_tilestored64_internal, Args);
1141bool X86LowerAMXCast::combineLoadCast(IntrinsicInst *Cast, LoadInst *LD) {
1142 bool EraseLoad =
true;
1143 Value *Row =
nullptr, *Col =
nullptr;
1145 unsigned OpNo =
U.getOperandNo();
1161 DT.reset(
new DominatorTree(Func));
1162 if (!DT->dominates(Row, LD) || !DT->dominates(Col, LD)) {
1166 Builder.SetInsertPoint(&*std::next(
LD->getIterator()));
1167 Builder.CreateStore(LD, AllocaAddr);
1169 Builder.SetInsertPoint(Cast);
1170 I8Ptr = Builder.CreateBitCast(AllocaAddr, Builder.getPtrTy());
1173 I8Ptr = Builder.CreateBitCast(
LD->getOperand(0), Builder.getPtrTy());
1176 Value *Stride = Builder.CreateSExt(Col, Builder.getInt64Ty());
1177 std::array<Value *, 4>
Args = {Row, Col, I8Ptr, Stride};
1180 Builder.CreateIntrinsic(Intrinsic::x86_tileloadd64_internal, Args);
1189bool X86LowerAMXCast::combineTilezero(IntrinsicInst *Cast) {
1190 Value *Row =
nullptr, *Col =
nullptr;
1192 unsigned OpNo =
U.getOperandNo();
1206bool X86LowerAMXCast::combineLdSt(SmallVectorImpl<Instruction *> &Casts) {
1207 bool Change =
false;
1208 for (
auto *Cast : Casts) {
1215 if (
II->getIntrinsicID() == Intrinsic::x86_cast_tile_to_vector) {
1216 SmallVector<Instruction *, 2> DeadStores;
1217 for (User *U : Cast->
users()) {
1226 for (
auto *
Store : DeadStores)
1227 Store->eraseFromParent();
1248 Load->eraseFromParent();
1256bool X86LowerAMXCast::combineAMXcast(TargetLibraryInfo *
TLI) {
1257 bool Change =
false;
1259 SmallVector<Instruction *, 8> Vec2TileInsts;
1260 SmallVector<Instruction *, 8> Tile2VecInsts;
1261 SmallVector<Instruction *, 8> PhiCastWorkList;
1262 SmallSetVector<Instruction *, 16> DeadInst;
1263 for (BasicBlock &BB : Func) {
1264 for (Instruction &
I : BB) {
1275 auto Convert = [&](SmallVectorImpl<Instruction *> &Insts,
Intrinsic::ID IID) {
1276 for (
auto *Inst : Insts) {
1277 for (User *U : Inst->users()) {
1279 if (!
II ||
II->getIntrinsicID() != IID)
1288 II->replaceAllUsesWith(Inst->getOperand(0));
1294 Convert(Vec2TileInsts, Intrinsic::x86_cast_tile_to_vector);
1295 Convert(Tile2VecInsts, Intrinsic::x86_cast_vector_to_tile);
1297 SmallVector<Instruction *, 8> LiveCasts;
1298 auto EraseInst = [&](SmallVectorImpl<Instruction *> &Insts) {
1299 for (
auto *Inst : Insts) {
1300 if (Inst->use_empty()) {
1301 Inst->eraseFromParent();
1309 EraseInst(Vec2TileInsts);
1310 EraseInst(Tile2VecInsts);
1311 LLVM_DEBUG(
dbgs() <<
"[LowerAMXTYpe][combineAMXcast] IR dump after combine "
1312 "Vec2Tile and Tile2Vec:\n";
1314 Change |= combineLdSt(LiveCasts);
1315 EraseInst(LiveCasts);
1316 LLVM_DEBUG(
dbgs() <<
"[LowerAMXTYpe][combineAMXcast] IR dump after combine "
1317 "AMXCast and load/store:\n";
1321 for (BasicBlock &BB : Func) {
1322 for (Instruction &
I : BB) {
1329 for (
auto *
I : PhiCastWorkList) {
1342 while (!DeadInst.
empty()) {
1346 LLVM_DEBUG(
dbgs() <<
"[LowerAMXTYpe][combineAMXcast] IR dump after "
1347 "optimizeAMXCastFromPhi:\n";
1354bool X86LowerAMXCast::transformAMXCast(IntrinsicInst *AMXCast) {
1356 AllocaInst *AllocaAddr;
1357 Value *I8Ptr, *Stride;
1360 auto Prepare = [&](
Type *MemTy) {
1362 I8Ptr = Builder.CreateBitCast(AllocaAddr, Builder.getPtrTy());
1363 Stride = Builder.getInt64(64);
1384 unsigned OpNo =
U.getOperandNo();
1389 Value *Row =
nullptr, *Col =
nullptr;
1397 Builder.CreateStore(Src, AllocaAddr);
1399 Value *Row =
nullptr, *Col =
nullptr;
1401 std::array<Value *, 4>
Args = {
1402 Row, Col, I8Ptr, Builder.CreateSExt(Col, Builder.getInt64Ty())};
1404 Builder.CreateIntrinsic(Intrinsic::x86_tileloadd64_internal, Args);
1427 Value *Row =
II->getOperand(0);
1428 Value *Col =
II->getOperand(1);
1429 std::array<Value *, 5>
Args = {
1430 Row, Col, I8Ptr, Builder.CreateSExt(Col, Builder.getInt64Ty()), Src};
1431 Builder.CreateIntrinsic(Intrinsic::x86_tilestored64_internal, Args);
1432 Value *NewInst = Builder.CreateLoad(AMXCast->
getType(), AllocaAddr);
1440bool X86LowerAMXCast::transformAllAMXCast() {
1441 bool Change =
false;
1443 SmallVector<Instruction *, 8> WorkLists;
1444 for (BasicBlock &BB : Func) {
1445 for (Instruction &
I : BB) {
1451 for (
auto *Inst : WorkLists) {
1458bool lowerAmxType(
Function &
F,
const TargetMachine *TM,
1459 TargetLibraryInfo *
TLI) {
1469 X86LowerAMXCast LAC(
F);
1470 C |= LAC.combineAMXcast(
TLI);
1473 C |= LAC.transformAllAMXCast();
1475 X86LowerAMXType LAT(
F);
1490 if (!
F.hasFnAttribute(Attribute::OptimizeNone)) {
1491 X86VolatileTileData VTD(
F);
1492 C = VTD.volatileTileData() ||
C;
1524 &getAnalysis<TargetLibraryInfoWrapperPass>().getTLI(
F);
1525 return lowerAmxType(
F, TM,
TLI);
1528 void getAnalysisUsage(AnalysisUsage &AU)
const override {
1537static const char PassName[] =
"Lower AMX type for load/store";
1538char X86LowerAMXTypeLegacyPass::ID = 0;
1547 return new X86LowerAMXTypeLegacyPass();
const TargetLowering & TLI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static bool DCEInstruction(Instruction *I, SmallSetVector< Instruction *, 16 > &WorkList, const TargetLibraryInfo *TLI)
static bool runOnFunction(Function &F, bool PostInlining)
This header defines various interfaces for pass management in LLVM.
uint64_t IntrinsicInst * II
FunctionAnalysisManager FAM
#define INITIALIZE_PASS_DEPENDENCY(depName)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
This file builds on the ADT/GraphTraits.h file to build a generic graph post order iterator.
static void visit(BasicBlock &Start, std::function< bool(BasicBlock *)> op)
This file implements a set that has insertion order iteration characteristics.
static SymbolRef::Type getType(const Symbol *Sym)
Target-Independent Code Generator Pass Configuration Options pass.
static ShapeT getShape(MachineRegisterInfo *MRI, Register TileReg)
static const char PassName[]
static bool isAMXCast(Instruction *II)
static Value * createACETileFromVector(IRBuilder<> &Builder, Value *Vec, Value *Row, Value *Col)
static Value * getRowFromCol(Instruction *II, Value *V, unsigned Granularity)
static constexpr unsigned ACENumTileRows
static void replaceWithTileLoad(Use &U, Value *Ptr, bool IsPHI=false)
static Instruction * createTileStore(Instruction *TileDef, Value *Ptr)
static Value * getAllocaPos(BasicBlock *BB)
static Intrinsic::ID getTilezeroIntrinsic(IntrinsicInst *Consumer)
static bool containsAMXCode(Function &F)
static constexpr unsigned ACERowNumElts
std::pair< Value *, Value * > getShape(IntrinsicInst *II, unsigned OpNo)
static IntrinsicInst * getTileConsumer(PHINode *Phi, unsigned &OpNo)
static bool hasACEIncomingValue(PHINode *PHI)
static bool isIncomingOfPHI(Instruction *I)
static bool isAMXIntrinsic(Value *I)
static Instruction * getFirstNonAllocaInTheEntryBlock(Function &F)
static bool isACEOnlyIntrinsic(Instruction *I)
static AllocaInst * createAllocaInstAtEntry(IRBuilder<> &Builder, BasicBlock *BB, Type *Ty)
static Value * createVectorFromACETile(IRBuilder<> &Builder, Value *Tile, Value *Row, Value *Col, Type *VecTy)
an instruction to allocate memory on the stack
void setAlignment(Align Align)
AnalysisUsage & addRequired()
LLVM_ABI void setPreservesCFG()
This function should be called by the pass, iff they do not:
LLVM Basic Block Representation.
const Function * getParent() const
Return the enclosing method, or null if none.
InstListType::iterator iterator
Instruction iterators...
This class represents a no-op cast from one type to another.
Represents analyses that only rely on functions' control flow.
A parsed version of the target data layout string in and methods for querying it.
static LLVM_ABI FixedVectorType * get(Type *ElementType, unsigned NumElts)
FunctionPass class - This class is used to implement most global optimizations.
Value * CreateUDiv(Value *LHS, Value *RHS, const Twine &Name="", bool isExact=false)
ConstantInt * getInt16(uint16_t C)
Get a constant 16-bit value.
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
LLVM_ABI void moveBefore(InstListType::iterator InsertPos)
Unlink this instruction from its current basic block and insert it into the basic block that MovePos ...
LLVM_ABI InstListType::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
iterator_range< user_iterator > users()
A wrapper class for inspecting calls to intrinsic functions.
This is an important class for using LLVM in a threaded context.
An instruction for reading from memory.
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
PreservedAnalyses & preserveSet()
Mark an analysis set as preserved.
bool contains(const_arg_type key) const
Check if the SetVector contains the given key.
bool empty() const
Determine if the SetVector is empty or not.
bool insert(const value_type &X)
Insert a new element into the SetVector.
value_type pop_back_val()
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Analysis pass providing the TargetLibraryInfo.
Provides information about what library functions are available for the current target.
Primary interface to the complete machine description for the target machine.
CodeGenOptLevel getOptLevel() const
Returns the optimization level: None, Less, Default, or Aggressive.
Target-Independent Code Generator Pass Configuration Options.
The instances of the Type class are immutable: once they are created, they are never changed.
static LLVM_ABI Type * getX86_AMXTy(LLVMContext &C)
bool isX86_AMXTy() const
Return true if this is X86 AMX.
A Use represents the edge between a Value definition and its users.
void setOperand(unsigned i, Value *Val)
LLVM_ABI bool replaceUsesOfWith(Value *From, Value *To)
Replace uses of one Value with another.
Value * getOperand(unsigned i) const
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
LLVM_ABI void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
static LLVM_ABI VectorType * get(Type *ElementType, ElementCount EC)
This static method is the primary way to construct an VectorType.
PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM)
const ParentTy * getParent() const
self_iterator getIterator()
Pass manager infrastructure for declaring and invalidating analyses.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
@ BasicBlock
Various leaf nodes.
@ Bitcast
Perform the operation on a different, but equivalently sized type.
bool match(Val *V, const Pattern &P)
auto m_Value()
Match an arbitrary value and ignore it.
auto m_Intrinsic(const Ts &...Ops)
Match intrinsic calls like this: m_Intrinsic<Intrinsic::fabs>(m_Value(X))
@ User
could "use" a pointer
NodeAddr< UseNode * > Use
NodeAddr< FuncNode * > Func
friend class Instruction
Iterator for Instructions in a `BasicBlock.
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
LLVM_ABI void salvageDebugInfo(const MachineRegisterInfo &MRI, MachineInstr &MI)
Assuming the instruction MI is going to be deleted, attempt to salvage debug users of MI by writing t...
@ Load
The value being inserted comes from a load (InsertElement only).
@ Store
The extracted value is stored (ExtractElement only).
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
LLVM_ABI bool isInstructionTriviallyDead(Instruction *I, const TargetLibraryInfo *TLI=nullptr)
Return true if the result produced by the instruction is not used, and the instruction will return.
auto reverse(ContainerTy &&C)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
IRBuilder(LLVMContext &, FolderTy, InserterTy) -> IRBuilder< FolderTy, InserterTy >
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
auto post_order(const T &G)
Post-order traversal of a graph.
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
LLVM_ABI bool salvageKnowledge(Instruction *I, AssumptionCache *AC=nullptr, DominatorTree *DT=nullptr)
Calls BuildAssumeFromInst and if the resulting llvm.assume is valid insert if before I.
DWARFExpression::Operation Op
FunctionPass * createX86LowerAMXTypeLegacyPass()
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.