Replace dbg.declare values with coroutine frame offset. · modocache/llvm-project@afbc04e (original) (raw)

`@@ -22,6 +22,7 @@

`

22

22

`#include "llvm/Transforms/Utils/Local.h"

`

23

23

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

`

24

24

`#include "llvm/IR/CFG.h"

`

``

25

`+

#include "llvm/IR/DIBuilder.h"

`

25

26

`#include "llvm/IR/Dominators.h"

`

26

27

`#include "llvm/IR/IRBuilder.h"

`

27

28

`#include "llvm/IR/InstIterator.h"

`

`@@ -583,7 +584,7 @@ static Instruction *splitBeforeCatchSwitch(CatchSwitchInst *CatchSwitch) {

`

583

584

`// whatever

`

584

585

`//

`

585

586

`//

`

586

``

`-

static Instruction *insertSpills(const SpillInfo &Spills, coro::Shape &Shape) {

`

``

587

`+

static Instruction *insertSpills(Function &F, const SpillInfo &Spills, coro::Shape &Shape) {

`

587

588

`auto *CB = Shape.CoroBegin;

`

588

589

` LLVMContext &C = CB->getContext();

`

589

590

` IRBuilder<> Builder(CB->getNextNode());

`

`@@ -637,11 +638,11 @@ static Instruction *insertSpills(const SpillInfo &Spills, coro::Shape &Shape) {

`

637

638

``

638

639

`// Create a load instruction to reload the spilled value from the coroutine

`

639

640

`// frame.

`

640

``

`-

auto CreateReload = [&](Instruction *InsertBefore) {

`

``

641

`+

auto CreateReload = [&](Instruction *InsertBefore, llvm::Value *& G) {

`

641

642

`assert(Index != InvalidFieldIndex && "accessing unassigned field number");

`

642

643

` Builder.SetInsertPoint(InsertBefore);

`

643

644

``

644

``

`-

auto *G = GetFramePointer(Index, CurrentValue);

`

``

645

`+

G = GetFramePointer(Index, CurrentValue);

`

645

646

` G->setName(CurrentValue->getName() + Twine(".reload.addr"));

`

646

647

``

647

648

`return isa(CurrentValue)

`

`@@ -720,9 +721,10 @@ static Instruction *insertSpills(const SpillInfo &Spills, coro::Shape &Shape) {

`

720

721

` }

`

721

722

``

722

723

`// If we have not seen the use block, generate a reload in it.

`

``

724

`+

llvm::Value *GEP = nullptr;

`

723

725

`if (CurrentBlock != E.userBlock()) {

`

724

726

` CurrentBlock = E.userBlock();

`

725

``

`-

CurrentReload = CreateReload(&*CurrentBlock->getFirstInsertionPt());

`

``

727

`+

CurrentReload = CreateReload(&*CurrentBlock->getFirstInsertionPt(), GEP);

`

726

728

` }

`

727

729

``

728

730

`// If we have a single edge PHINode, remove it and replace it with a reload

`

`@@ -737,6 +739,8 @@ static Instruction *insertSpills(const SpillInfo &Spills, coro::Shape &Shape) {

`

737

739

` }

`

738

740

``

739

741

`// Replace all uses of CurrentValue in the current instruction with reload.

`

``

742

`+

DIBuilder DIB(*F.getParent(), /AllowUnresolved/ false);

`

``

743

`+

replaceDbgDeclare(CurrentValue, GEP, DIB, DIExpression::ApplyOffset, 0);

`

740

744

` E.user()->replaceUsesOfWith(CurrentValue, CurrentReload);

`

741

745

` }

`

742

746

``

`@@ -1323,10 +1327,6 @@ static void eliminateSwiftError(Function &F, coro::Shape &Shape) {

`

1323

1327

`}

`

1324

1328

``

1325

1329

`void coro::buildCoroutineFrame(Function &F, Shape &Shape) {

`

1326

``

`-

// Lower coro.dbg.declare to coro.dbg.value, since we are going to rewrite

`

1327

``

`-

// access to local variables.

`

1328

``

`-

LowerDbgDeclare(F);

`

1329

``

-

1330

1330

`eliminateSwiftError(F, Shape);

`

1331

1331

``

1332

1332

`if (Shape.ABI == coro::ABI::Switch &&

`

`@@ -1432,7 +1432,7 @@ void coro::buildCoroutineFrame(Function &F, Shape &Shape) {

`

1432

1432

` }

`

1433

1433

`LLVM_DEBUG(dump("Spills", Spills));

`

1434

1434

` Shape.FrameTy = buildFrameType(F, Shape, Spills);

`

1435

``

`-

Shape.FramePtr = insertSpills(Spills, Shape);

`

``

1435

`+

Shape.FramePtr = insertSpills(F, Spills, Shape);

`

1436

1436

`lowerLocalAllocas(LocalAllocas, DeadInstructions);

`

1437

1437

``

1438

1438

`for (auto I : DeadInstructions)

`