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"
19#include "llvm/IR/Statepoint.h"
20
21using namespace llvm;
22
24 // Nothing to do for declarations.
25 if (F.isDeclaration())
26 return false;
28 // TODO: We currently do not handle gc.relocates that are in landing pads,
29 // i.e. not bound to a single statepoint token.
30 for (Instruction &I : instructions(F)) {
31 if (auto *GCR = dyn_cast<GCRelocateInst>(&I))
32 if (isa<GCStatepointInst>(GCR->getOperand(0)))
33 GCRelocates.push_back(GCR);
34 }
35 // All gc.relocates are bound to a single statepoint token. The order of
36 // visiting gc.relocates for deletion does not matter.
37 for (GCRelocateInst *GCRel : GCRelocates) {
38 GCRel->replaceAllUsesWith(GCRel->getDerivedPtr());
39 GCRel->eraseFromParent();
40 }
41 return !GCRelocates.empty();
42}
43
46 if (!stripGCRelocates(F))
48
49 // Removing gc.relocate preserves the CFG, but most other analysis probably
50 // need to re-run.
53 return PA;
54}
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.