LLVM 24.0.0git
StripGCRelocates.cpp
Go to the documentation of this file.
1//===- StripGCRelocates.cpp - Remove gc.relocates inserted by RewriteStatePoints===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This is a little utility pass that removes the gc.relocates inserted by
10// RewriteStatepointsForGC. Note that the generated IR is incorrect,
11// but this is useful as a single pass in itself, for analysis of IR, without
12// the GC.relocates. The statepoint and gc.result intrinsics would still be
13// present.
14//===----------------------------------------------------------------------===//
15
17#include "llvm/IR/Function.h"
20#include "llvm/IR/Statepoint.h"
21
22using namespace llvm;
23
25 // Nothing to do for declarations.
26 if (F.isDeclaration())
27 return false;
29 // TODO: We currently do not handle gc.relocates that are in landing pads,
30 // i.e. not bound to a single statepoint token.
31 for (Instruction &I : instructions(F)) {
32 if (auto *GCR = dyn_cast<GCRelocateInst>(&I))
33 if (isa<GCStatepointInst>(GCR->getOperand(0)))
34 GCRelocates.push_back(GCR);
35 }
36 // All gc.relocates are bound to a single statepoint token. The order of
37 // visiting gc.relocates for deletion does not matter.
38 for (GCRelocateInst *GCRel : GCRelocates) {
39 GCRel->replaceAllUsesWith(GCRel->getDerivedPtr());
40 GCRel->eraseFromParent();
41 }
42 return !GCRelocates.empty();
43}
44
47 if (!stripGCRelocates(F))
49
50 // Removing gc.relocate preserves the CFG, but most other analysis probably
51 // need to re-run.
54 return PA;
55}
Expand Atomic instructions
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
static bool stripGCRelocates(Function &F)
Represents analyses that only rely on functions' control flow.
Definition Analysis.h:73
Represents calls to the gc.relocate intrinsic.
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition Analysis.h:118
PreservedAnalyses & preserveSet()
Mark an analysis set as preserved.
Definition Analysis.h:151
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
LLVM_ABI PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
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.
Definition Casting.h:643
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...
Definition Casting.h:547
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.