LLVM: lib/CodeGen/StackColoring.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

44#include "llvm/Config/llvm-config.h"

58#include

59#include

60#include

61#include

62#include

63

64using namespace llvm;

65

66#define DEBUG_TYPE "stack-coloring"

67

71 cl::desc("Disable stack coloring"));

72

73

74

75

76

77

81 cl::desc("Do not optimize lifetime zones that "

82 "are broken"));

83

84

85

86

87

91 cl::desc("Treat stack lifetimes as starting on first use, not on START marker."));

92

93

94STATISTIC(NumMarkerSeen, "Number of lifetime markers found.");

95STATISTIC(StackSpaceSaved, "Number of bytes saved due to merging slots.");

96STATISTIC(StackSlotMerged, "Number of stack slot merged.");

97STATISTIC(EscapedAllocas, "Number of allocas that escaped the lifetime region");

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

260

261

262

263

264

265

266

267

268

269

270

271

272

273

274

275

276

277

278

279

280

281

282

283

284

285

286

287

288

289

290

291

292

293

294

295

296

297

298

299

300

301

302

303

304

305

306

307

308

309

310

311

312

313

314

315

316

317

318

319

320

321

322

323

324

325

326

327

328

329

330

331

332

333

334

335

336

337

338

339

340

341

342

343

344

345

346

347

348

349

350

351

352

353

354

355

356

357

358

359

360

361

362

363

364

365

366

367

368

369

370

371

372

373

374

375

376namespace {

377

378

379

380class StackColoring {

383

384

385

386

387 struct BlockLifetimeInfo {

388

390

391

393

394

396

397

399 };

400

401

403 LivenessMap BlockLiveness;

404

405

407

408

410

411

412

414

415

417

418

420

421

423

424

425

427

428

429

431

432

433

435

436

437 unsigned NumIterations;

438

439public:

440 StackColoring(SlotIndexes *Indexes) : Indexes(Indexes) {}

442

443private:

444

446

447

448 void dump() const;

449 void dumpIntervals() const;

451 void dumpBV(const char *tag, const BitVector &BV) const;

452

453

454

455 bool removeAllMarkers();

456

457

458

459

460 unsigned collectMarkers(unsigned NumSlot);

461

462

463

464

465

466 void calculateLocalLiveness();

467

468

469

470 bool applyFirstUse(int Slot) {

472 return false;

473 if (ConservativeSlots.test(Slot))

474 return false;

475 return true;

476 }

477

478

479

480

481

482

485 bool &isStart);

486

487

488 void calculateLiveIntervals(unsigned NumSlots);

489

490

491

493

494

495

496

497

498

499

500 void removeInvalidSlotRanges();

501

502

503

504 void expungeSlotMap(DenseMap<int, int> &SlotRemap, unsigned NumSlots);

505};

506

508public:

509 static char ID;

510

512

515};

516

517}

518

519char StackColoringLegacy::ID = 0;

520

522

524 "Merge disjoint stack slots", false, false)

528

529void StackColoringLegacy::getAnalysisUsage(AnalysisUsage &AU) const {

532}

533

534#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)

537 dbgs() << tag << " : { ";

538 for (unsigned I = 0, E = BV.size(); I != E; ++I)

540 dbgs() << "}\n";

541}

542

544 LivenessMap::const_iterator BI = BlockLiveness.find(MBB);

545 assert(BI != BlockLiveness.end() && "Block not found");

546 const BlockLifetimeInfo &BlockInfo = BI->second;

547

548 dumpBV("BEGIN", BlockInfo.Begin);

549 dumpBV("END", BlockInfo.End);

550 dumpBV("LIVE_IN", BlockInfo.LiveIn);

551 dumpBV("LIVE_OUT", BlockInfo.LiveOut);

552}

553

558 dumpBB(MBB);

559 }

560}

561

563 for (unsigned I = 0, E = Intervals.size(); I != E; ++I) {

564 dbgs() << "Interval[" << I << "]:\n";

565 Intervals[I]->dump();

566 }

567}

568#endif

569

571{

572 assert((MI.getOpcode() == TargetOpcode::LIFETIME_START ||

573 MI.getOpcode() == TargetOpcode::LIFETIME_END) &&

574 "Expected LIFETIME_START or LIFETIME_END op");

577 if (Slot >= 0)

578 return Slot;

579 return -1;

580}

581

582

583

584

585

586bool StackColoring::isLifetimeStartOrEnd(const MachineInstr &MI,

588 bool &isStart) {

589 if (MI.getOpcode() == TargetOpcode::LIFETIME_START ||

590 MI.getOpcode() == TargetOpcode::LIFETIME_END) {

592 if (Slot < 0)

593 return false;

594 if (!InterestingSlots.test(Slot))

595 return false;

596 slots.push_back(Slot);

597 if (MI.getOpcode() == TargetOpcode::LIFETIME_END) {

598 isStart = false;

599 return true;

600 }

601 if (!applyFirstUse(Slot)) {

602 isStart = true;

603 return true;

604 }

606 if (MI.isDebugInstr()) {

607 bool found = false;

609 if (!MO.isFI())

610 continue;

611 int Slot = MO.getIndex();

612 if (Slot<0)

613 continue;

614 if (InterestingSlots.test(Slot) && applyFirstUse(Slot)) {

615 slots.push_back(Slot);

616 found = true;

617 }

618 }

619 if (found) {

620 isStart = true;

621 return true;

622 }

623 }

624 }

625 return false;

626}

627

628unsigned StackColoring::collectMarkers(unsigned NumSlot) {

629 unsigned MarkersFound = 0;

630 BlockBitVecMap SeenStartMap;

631 InterestingSlots.clear();

632 InterestingSlots.resize(NumSlot);

633 ConservativeSlots.clear();

634 ConservativeSlots.resize(NumSlot);

635

636

639

640

641

643

644

645

647 BetweenStartEnd.resize(NumSlot);

649 BlockBitVecMap::const_iterator I = SeenStartMap.find(Pred);

650 if (I != SeenStartMap.end()) {

651 BetweenStartEnd |= I->second;

652 }

653 }

654

655

657 if (MI.isDebugInstr())

658 continue;

659 if (MI.getOpcode() == TargetOpcode::LIFETIME_START ||

660 MI.getOpcode() == TargetOpcode::LIFETIME_END) {

662 if (Slot < 0)

663 continue;

664 InterestingSlots.set(Slot);

665 if (MI.getOpcode() == TargetOpcode::LIFETIME_START) {

666 BetweenStartEnd.set(Slot);

667 NumStartLifetimes[Slot] += 1;

668 } else {

669 BetweenStartEnd.reset(Slot);

670 NumEndLifetimes[Slot] += 1;

671 }

673 if (Allocation) {

675 LLVM_DEBUG(dbgs() << (MI.getOpcode() == TargetOpcode::LIFETIME_START

676 ? "start"

677 : "end"));

680 << " with allocation: " << Allocation->getName() << "\n");

681 }

683 MarkersFound += 1;

684 } else {

686 if (!MO.isFI())

687 continue;

688 int Slot = MO.getIndex();

689 if (Slot < 0)

690 continue;

691 if (! BetweenStartEnd.test(Slot)) {

692 ConservativeSlots.set(Slot);

693 }

694 }

695 }

696 }

698 SeenStart |= BetweenStartEnd;

699 }

700 if (!MarkersFound) {

701 return 0;

702 }

703

704

705

706 for (unsigned slot = 0; slot < NumSlot; ++slot) {

707 if (NumStartLifetimes[slot] > 1 || NumEndLifetimes[slot] > 1)

708 ConservativeSlots.set(slot);

709 }

710

711

712

713

714

718 if (H.CatchObj.FrameIndex != std::numeric_limits::max() &&

719 H.CatchObj.FrameIndex >= 0)

720 ConservativeSlots.set(H.CatchObj.FrameIndex);

721

722 LLVM_DEBUG(dumpBV("Conservative slots", ConservativeSlots));

723

724

725

726

727

729

730 BasicBlocks[MBB] = BasicBlockNumbering.size();

732

733

734 BlockLifetimeInfo &BlockInfo = BlockLiveness[MBB];

735

736 BlockInfo.Begin.resize(NumSlot);

737 BlockInfo.End.resize(NumSlot);

738

741 bool isStart = false;

743 if (isLifetimeStartOrEnd(MI, slots, isStart)) {

744 if (!isStart) {

745 assert(slots.size() == 1 && "unexpected: MI ends multiple slots");

747 if (BlockInfo.Begin.test(Slot)) {

748 BlockInfo.Begin.reset(Slot);

749 }

750 BlockInfo.End.set(Slot);

751 } else {

752 for (auto Slot : slots) {

753 LLVM_DEBUG(dbgs() << "Found a use of slot #" << Slot);

758 if (Allocation) {

760 << " with allocation: " << Allocation->getName());

761 }

763 if (BlockInfo.End.test(Slot)) {

764 BlockInfo.End.reset(Slot);

765 }

766 BlockInfo.Begin.set(Slot);

767 }

768 }

769 }

770 }

771 }

772

773

774 NumMarkerSeen += MarkersFound;

775 return MarkersFound;

776}

777

778void StackColoring::calculateLocalLiveness() {

779 unsigned NumIters = 0;

780 bool changed = true;

781

782

785 while (changed) {

786 changed = false;

787 ++NumIters;

788

790

791 LivenessMap::iterator BI = BlockLiveness.find(BB);

792 assert(BI != BlockLiveness.end() && "Block not found");

793 BlockLifetimeInfo &BlockInfo = BI->second;

794

795

796 LocalLiveIn.clear();

798 LivenessMap::const_iterator I = BlockLiveness.find(Pred);

799

800

801

802 if (I != BlockLiveness.end())

803 LocalLiveIn |= I->second.LiveOut;

804 }

805

806

807

808

809

810

811

812

813 LocalLiveOut = LocalLiveIn;

814 LocalLiveOut.reset(BlockInfo.End);

815 LocalLiveOut |= BlockInfo.Begin;

816

817

818 if (LocalLiveIn.test(BlockInfo.LiveIn)) {

819 changed = true;

820 BlockInfo.LiveIn |= LocalLiveIn;

821 }

822

823

824 if (LocalLiveOut.test(BlockInfo.LiveOut)) {

825 changed = true;

826 BlockInfo.LiveOut |= LocalLiveOut;

827 }

828 }

829 }

830

831 NumIterations = NumIters;

832}

833

834void StackColoring::calculateLiveIntervals(unsigned NumSlots) {

837

838

839

842 Starts.resize(NumSlots);

843 DefinitelyInUse.clear();

844 DefinitelyInUse.resize(NumSlots);

845

846

847 BlockLifetimeInfo &MBBLiveness = BlockLiveness[&MBB];

848 for (int pos = MBBLiveness.LiveIn.find_first(); pos != -1;

849 pos = MBBLiveness.LiveIn.find_next(pos)) {

851 }

852

853

856 bool IsStart = false;

857 if (!isLifetimeStartOrEnd(MI, slots, IsStart))

858 continue;

860 for (auto Slot : slots) {

861 if (IsStart) {

862

863

864

865 if (!DefinitelyInUse[Slot]) {

867 DefinitelyInUse[Slot] = true;

868 }

869 if (!Starts[Slot].isValid())

870 Starts[Slot] = ThisIndex;

871 } else {

872 if (Starts[Slot].isValid()) {

873 VNInfo *VNI = Intervals[Slot]->getValNumInfo(0);

874 Intervals[Slot]->addSegment(

876 Starts[Slot] = SlotIndex();

877 DefinitelyInUse[Slot] = false;

878 }

879 }

880 }

881 }

882

883

884 for (unsigned i = 0; i < NumSlots; ++i) {

885 if (!Starts[i].isValid())

886 continue;

887

889 VNInfo *VNI = Intervals[i]->getValNumInfo(0);

891 }

892 }

893}

894

895bool StackColoring::removeAllMarkers() {

896 unsigned Count = 0;

898 MI->eraseFromParent();

899 Count++;

900 }

902

903 LLVM_DEBUG(dbgs() << "Removed " << Count << " markers.\n");

904 return Count;

905}

906

907void StackColoring::remapInstructions(DenseMap<int, int> &SlotRemap) {

908 unsigned FixedInstr = 0;

909 unsigned FixedMemOp = 0;

910 unsigned FixedDbg = 0;

911

912

913 for (auto &VI : MF->getVariableDbgInfo()) {

914 if (VI.Var || VI.inStackSlot())

915 continue;

916 int Slot = VI.getStackSlot();

917 if (SlotRemap.count(Slot)) {

919 << cast(VI.Var)->getName() << "].\n");

920 VI.updateStackSlot(SlotRemap[Slot]);

921 FixedDbg++;

922 }

923 }

924

925

927

928

930

931 for (const std::pair<int, int> &SI : SlotRemap) {

934 assert(To && From && "Invalid allocation object");

935 Allocas[From] = To;

936

937

938

939 if (From->comesBefore(To))

941

942

943

944

945

946

947

952 Inst = Cast;

953 }

954

955

957 MergedAllocas.insert(To);

958

959

960

961

970

971

972

976 for (auto &Use : FromAI->uses()) {

978 if (BCI->isUsedByMetadata())

980 }

981

982

983

984

986 }

987

988

989 std::vector<std::vector<MachineMemOperand *>> SSRefs(

993

994 if (I.getOpcode() == TargetOpcode::LIFETIME_START ||

995 I.getOpcode() == TargetOpcode::LIFETIME_END)

996 continue;

997

998

1000

1001

1002 const AllocaInst *AI = dyn_cast_or_null(MMO->getValue());

1003 if (!AI)

1004 continue;

1005

1006 if (!Allocas.count(AI))

1007 continue;

1008

1009 MMO->setValue(Allocas[AI]);

1010 FixedMemOp++;

1011 }

1012

1013

1015 if (!MO.isFI())

1016 continue;

1017 int FromSlot = MO.getIndex();

1018

1019

1020 if (FromSlot<0)

1021 continue;

1022

1023

1024 if (!SlotRemap.count(FromSlot))

1025 continue;

1026

1027

1028

1029

1030

1031

1032

1033

1034#ifndef NDEBUG

1035 bool TouchesMemory = I.mayLoadOrStore();

1036

1037

1042 "Found instruction usage outside of live range.");

1043 }

1044#endif

1045

1046

1047 int ToSlot = SlotRemap[FromSlot];

1048 MO.setIndex(ToSlot);

1049 FixedInstr++;

1050 }

1051

1052

1054 bool ReplaceMemOps = false;

1056

1057

1058 if (const auto *FSV = dyn_cast_or_null(

1059 MMO->getPseudoValue())) {

1060 int FI = FSV->getFrameIndex();

1061 auto To = SlotRemap.find(FI);

1062 if (To != SlotRemap.end())

1063 SSRefs[FI].push_back(MMO);

1064 }

1065

1066

1067

1068 bool MayHaveConflictingAAMD = false;

1069 if (MMO->getAAInfo()) {

1070 if (const Value *MMOV = MMO->getValue()) {

1073

1074 if (Objs.empty())

1075 MayHaveConflictingAAMD = true;

1076 else

1077 for (Value *V : Objs) {

1078

1079

1080

1081 const AllocaInst *AI = dyn_cast_or_null(V);

1082 if (AI && MergedAllocas.count(AI)) {

1083 MayHaveConflictingAAMD = true;

1084 break;

1085 }

1086 }

1087 }

1088 }

1089 if (MayHaveConflictingAAMD) {

1091 ReplaceMemOps = true;

1092 } else {

1094 }

1095 }

1096

1097

1098

1099 if (ReplaceMemOps)

1100 I.setMemRefs(*MF, NewMMOs);

1101 }

1102

1103

1104 for (auto E : enumerate(SSRefs))

1105 if (!E.value().empty()) {

1107 MF->getPSVManager().getFixedStack(SlotRemap.find(E.index())->second);

1109 Ref->setValue(NewSV);

1110 }

1111

1112

1113 if (WinEHFuncInfo *EHInfo = MF->getWinEHFuncInfo())

1116 if (H.CatchObj.FrameIndex != std::numeric_limits::max() &&

1117 SlotRemap.count(H.CatchObj.FrameIndex))

1118 H.CatchObj.FrameIndex = SlotRemap[H.CatchObj.FrameIndex];

1119

1120 LLVM_DEBUG(dbgs() << "Fixed " << FixedMemOp << " machine memory operands.\n");

1121 LLVM_DEBUG(dbgs() << "Fixed " << FixedDbg << " debug locations.\n");

1122 LLVM_DEBUG(dbgs() << "Fixed " << FixedInstr << " machine instructions.\n");

1123 (void) FixedMemOp;

1124 (void) FixedDbg;

1125 (void) FixedInstr;

1126}

1127

1128void StackColoring::removeInvalidSlotRanges() {

1131 if (I.getOpcode() == TargetOpcode::LIFETIME_START ||

1132 I.getOpcode() == TargetOpcode::LIFETIME_END || I.isDebugInstr())

1133 continue;

1134

1135

1136

1137

1138

1139

1140

1141 if (I.mayLoad() && I.mayStore())

1142 continue;

1143

1144

1146 if (!MO.isFI())

1147 continue;

1148

1149 int Slot = MO.getIndex();

1150

1151 if (Slot<0)

1152 continue;

1153

1154 if (Intervals[Slot]->empty())

1155 continue;

1156

1157

1158

1163 LLVM_DEBUG(dbgs() << "Invalidating range #" << Slot << "\n");

1164 EscapedAllocas++;

1165 }

1166 }

1167 }

1168}

1169

1171 unsigned NumSlots) {

1172

1173 for (unsigned i=0; i < NumSlots; ++i) {

1174

1175 if (SlotRemap.count(i)) {

1176 int Target = SlotRemap[i];

1177

1180 SlotRemap[i] = Target;

1181 }

1182 }

1183 }

1184}

1185

1186bool StackColoringLegacy::runOnMachineFunction(MachineFunction &MF) {

1188 return false;

1189

1190 StackColoring SC(&getAnalysis().getSI());

1191 return SC.run(MF);

1192}

1193

1197 if (SC.run(MF))

1200}

1201

1203 LLVM_DEBUG(dbgs() << "********** Stack Coloring **********\n"

1204 << "********** Function: " << Func.getName() << '\n');

1205 MF = &Func;

1207 BlockLiveness.clear();

1208 BasicBlocks.clear();

1209 BasicBlockNumbering.clear();

1211 Intervals.clear();

1212 LiveStarts.clear();

1213 VNInfoAllocator.Reset();

1214

1216

1217

1218 if (!NumSlots)

1219 return false;

1220

1222 SortedSlots.reserve(NumSlots);

1223 Intervals.reserve(NumSlots);

1224 LiveStarts.resize(NumSlots);

1225

1226 unsigned NumMarkers = collectMarkers(NumSlots);

1227

1228 unsigned TotalSize = 0;

1229 LLVM_DEBUG(dbgs() << "Found " << NumMarkers << " markers and " << NumSlots

1230 << " slots\n");

1232

1235 << " bytes.\n");

1237 }

1238

1239 LLVM_DEBUG(dbgs() << "Total Stack size: " << TotalSize << " bytes\n\n");

1240

1241

1242

1243 if (NumMarkers < 2 || TotalSize < 16 || DisableColoring) {

1244 LLVM_DEBUG(dbgs() << "Will not try to merge slots.\n");

1245 return removeAllMarkers();

1246 }

1247

1248 for (unsigned i=0; i < NumSlots; ++i) {

1249 std::unique_ptr LI(new LiveInterval(i, 0));

1250 LI->getNextValue(Indexes->getZeroIndex(), VNInfoAllocator);

1251 Intervals.push_back(std::move(LI));

1253 }

1254

1255

1256 calculateLocalLiveness();

1257 LLVM_DEBUG(dbgs() << "Dataflow iterations: " << NumIterations << "\n");

1259

1260

1261 calculateLiveIntervals(NumSlots);

1263

1264

1265

1267 removeInvalidSlotRanges();

1268

1269

1271 unsigned RemovedSlots = 0;

1272 unsigned ReducedSize = 0;

1273

1274

1275 for (unsigned I = 0; I < NumSlots; ++I) {

1276 if (Intervals[SortedSlots[I]]->empty())

1277 SortedSlots[I] = -1;

1278 }

1279

1280

1281

1282

1283

1284

1285

1286

1287

1289

1290 if (LHS == -1)

1291 return false;

1292 if (RHS == -1)

1293 return true;

1294

1296 });

1297

1298 for (auto &s : LiveStarts)

1300

1301 bool Changed = true;

1302 while (Changed) {

1303 Changed = false;

1304 for (unsigned I = 0; I < NumSlots; ++I) {

1305 if (SortedSlots[I] == -1)

1306 continue;

1307

1308 for (unsigned J=I+1; J < NumSlots; ++J) {

1309 if (SortedSlots[J] == -1)

1310 continue;

1311

1312 int FirstSlot = SortedSlots[I];

1313 int SecondSlot = SortedSlots[J];

1314

1315

1317 continue;

1318

1320 LiveInterval *Second = &*Intervals[SecondSlot];

1321 auto &FirstS = LiveStarts[FirstSlot];

1322 auto &SecondS = LiveStarts[SecondSlot];

1323 assert(First->empty() && !Second->empty() && "Found an empty range");

1324

1325

1326

1327 if (First->isLiveAtIndexes(SecondS) &&

1329 Changed = true;

1330 First->MergeSegmentsInAsValue(*Second, First->getValNumInfo(0));

1331

1332 int OldSize = FirstS.size();

1333 FirstS.append(SecondS.begin(), SecondS.end());

1334 auto Mid = FirstS.begin() + OldSize;

1335 std::inplace_merge(FirstS.begin(), Mid, FirstS.end());

1336

1337 SlotRemap[SecondSlot] = FirstSlot;

1338 SortedSlots[J] = -1;

1339 LLVM_DEBUG(dbgs() << "Merging #" << FirstSlot << " and slots #"

1340 << SecondSlot << " together.\n");

1343

1346 "Merging a small object into a larger one");

1347

1348 RemovedSlots+=1;

1352 }

1353 }

1354 }

1355 }

1356

1357

1358 StackSpaceSaved += ReducedSize;

1359 StackSlotMerged += RemovedSlots;

1360 LLVM_DEBUG(dbgs() << "Merge " << RemovedSlots << " slots. Saved "

1361 << ReducedSize << " bytes\n");

1362

1363

1364

1365 if (!SlotRemap.empty()) {

1366 expungeSlotMap(SlotRemap, NumSlots);

1367 remapInstructions(SlotRemap);

1368 }

1369

1370 return removeAllMarkers();

1371}

This file implements the BitVector class.

BlockVerifier::State From

#define LLVM_DUMP_METHOD

Mark debug helper function definitions like dump() that should not be stripped from debug builds.

This file contains the declarations for the subclasses of Constant, which represent the different fla...

This file defines the DenseMap class.

This file builds on the ADT/GraphTraits.h file to build generic depth first graph iterator.

This defines the Use class.

std::pair< uint64_t, uint64_t > Interval

#define INITIALIZE_PASS_DEPENDENCY(depName)

#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)

#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)

static bool isValid(const char C)

Returns true if C is a valid mangled character: <0-9a-zA-Z_>.

assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())

This file defines the SmallPtrSet class.

This file defines the SmallVector class.

static int getStartOrEndSlot(const MachineInstr &MI)

static cl::opt< bool > DisableColoring("no-stack-coloring", cl::init(false), cl::Hidden, cl::desc("Disable stack coloring"))

static cl::opt< bool > ProtectFromEscapedAllocas("protect-from-escaped-allocas", cl::init(false), cl::Hidden, cl::desc("Do not optimize lifetime zones that " "are broken"))

The user may write code that uses allocas outside of the declared lifetime zone.

static cl::opt< bool > LifetimeStartOnFirstUse("stackcoloring-lifetime-start-on-first-use", cl::init(true), cl::Hidden, cl::desc("Treat stack lifetimes as starting on first use, not on START marker."))

Enable enhanced dataflow scheme for lifetime analysis (treat first use of stack slot as start of slot...

Merge disjoint stack slots

This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...

#define STATISTIC(VARNAME, DESC)

an instruction to allocate memory on the stack

PointerType * getType() const

Overload to return most specific pointer type.

A container for analyses that lazily runs them and caches their results.

PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)

Get the result of an analysis pass for a given IR unit.

Represent the analysis usage information of a pass.

This class represents a no-op cast from one type to another.

bool test(unsigned Idx) const

void resize(unsigned N, bool t=false)

resize - Grow or shrink the bitvector.

void clear()

clear - Removes all bits from the bitvector.

size_type size() const

size - Returns the number of bits in this bitvector.

Allocate memory in an ever growing pool, as if by bump-pointer.

void Reset()

Deallocate all but the current slab and reset the current pointer to the beginning of it,...

size_type count(const_arg_type_t< KeyT > Val) const

Return 1 if the specified key is in the map, 0 otherwise.

void insertAfter(Instruction *InsertPos)

Insert an unlinked instruction into a basic block immediately after the specified instruction.

LiveInterval - This class represents the liveness of a register, or stack slot.

bool isLiveAtIndexes(ArrayRef< SlotIndex > Slots) const

int getNumber() const

MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a MachineFuncti...

iterator_range< pred_iterator > predecessors()

StringRef getName() const

Return the name of the corresponding LLVM basic block, or an empty string.

The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.

SSPLayoutKind getObjectSSPLayout(int ObjectIdx) const

const AllocaInst * getObjectAllocation(int ObjectIdx) const

Return the underlying Alloca of the specified stack object if it exists.

SSPLayoutKind

Stack Smashing Protection (SSP) rules require that vulnerable stack allocations are located close the...

@ SSPLK_LargeArray

Array or nested array >= SSP-buffer-size.

@ SSPLK_AddrOf

The address of this allocation is exposed and triggered protection.

@ SSPLK_None

Did not trigger a stack protector.

void setObjectSSPLayout(int ObjectIdx, SSPLayoutKind Kind)

Align getObjectAlign(int ObjectIdx) const

Return the alignment of the specified stack object.

int64_t getObjectSize(int ObjectIdx) const

Return the size of the specified object.

void RemoveStackObject(int ObjectIdx)

Remove or mark dead a statically sized stack object.

int getObjectIndexEnd() const

Return one past the maximum frame object index.

uint8_t getStackID(int ObjectIdx) const

void setObjectAlignment(int ObjectIdx, Align Alignment)

setObjectAlignment - Change the alignment of the specified stack object.

MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...

void getAnalysisUsage(AnalysisUsage &AU) const override

getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.

virtual bool runOnMachineFunction(MachineFunction &MF)=0

runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...

const WinEHFuncInfo * getWinEHFuncInfo() const

getWinEHFuncInfo - Return information about how the current function uses Windows exception handling.

MachineFrameInfo & getFrameInfo()

getFrameInfo - Return the frame info object for the current function.

Function & getFunction()

Return the LLVM function that this machine code represents.

Representation of each machine instruction.

A description of a memory reference used in the backend.

MachineOperand class - Representation of each machine instruction operand.

static PoisonValue * get(Type *T)

Static factory methods - Return an 'poison' object of the specified type.

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.

Special value supplied for machine level alias analysis.

SlotIndex - An opaque wrapper around machine indexes.

void print(raw_ostream &os) const

Print this index to the given raw_ostream.

SlotIndex getMBBEndIdx(unsigned Num) const

Returns the last index in the given basic block number.

SlotIndex getInstructionIndex(const MachineInstr &MI, bool IgnoreBundle=false) const

Returns the base index for the given instruction.

SlotIndex getMBBStartIdx(unsigned Num) const

Returns the first index in the given basic block number.

SlotIndex getZeroIndex()

Returns the zero index for this analysis.

size_type count(ConstPtrType Ptr) const

count - Return 1 if the specified pointer is in the set, 0 otherwise.

std::pair< iterator, bool > insert(PtrType Ptr)

Inserts Ptr if and only if there is no element in the container equal to Ptr.

SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.

void reserve(size_type N)

void push_back(const T &Elt)

This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.

PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)

Target - Wrapper for Target specific information.

A Use represents the edge between a Value definition and its users.

VNInfo - Value Number Information.

LLVM Value Representation.

void replaceAllUsesWith(Value *V)

Change all uses of this to point to a new Value.

bool isUsedByMetadata() const

Return true if there is metadata referencing this value.

iterator_range< use_iterator > uses()

StringRef getName() const

Return a constant reference to the value's name.

unsigned ID

LLVM IR allows to use arbitrary numbers as calling convention identifiers.

@ SC

CHAIN = SC CHAIN, Imm128 - System call.

initializer< Ty > init(const Ty &Val)

PointerTypeMap run(const Module &M)

Compute the PointerTypeMap for the module M.

This is an optimization pass for GlobalISel generic memory operations.

void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)

void stable_sort(R &&Range)

auto enumerate(FirstRange &&First, RestRanges &&...Rest)

Given two or more input ranges, returns a new range whose values are tuples (A, B,...

bool getUnderlyingObjectsForCodeGen(const Value *V, SmallVectorImpl< Value * > &Objects)

This is a wrapper around getUnderlyingObjects and adds support for basic ptrtoint+arithmetic+inttoptr...

void sort(IteratorTy Start, IteratorTy End)

raw_ostream & dbgs()

dbgs() - This returns a reference to a raw_ostream for debugging messages.

@ Ref

The access may reference the value stored in memory.

@ First

Helpers to iterate all locations in the MemoryEffectsBase class.

char & StackColoringLegacyID

StackSlotColoring - This pass performs stack coloring and merging.

iterator_range< df_iterator< T > > depth_first(const T &G)

Printable printMBBReference(const MachineBasicBlock &MBB)

Prints a machine basic block reference.

A collection of metadata nodes that might be associated with a memory access used by the alias-analys...

This struct is a compact representation of a valid (non-zero power of two) alignment.

This represents a simple continuous liveness interval for a value.

SmallVector< WinEHHandlerType, 1 > HandlerArray