LLVM 24.0.0git
FatLTOCleanup.cpp
Go to the documentation of this file.
1//===- FatLtoCleanup.cpp - clean up IR for the FatLTO pipeline --*- C++ -*-===//
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 file defines operations used to clean up IR for the FatLTO pipeline.
10// Instrumentation that is beneficial for bitcode sections used in LTO may
11// need to be cleaned up to finish non-LTO compilation. llvm.checked.load is
12// an example of an instruction that we want to preserve for LTO, but is
13// incorrect to leave unchanged during the per-TU compilation in FatLTO.
14//
15//===----------------------------------------------------------------------===//
16
18#include "llvm/IR/Function.h"
19#include "llvm/IR/IRBuilder.h"
20#include "llvm/IR/Intrinsics.h"
21#include "llvm/IR/Module.h"
22#include "llvm/IR/PassManager.h"
23#include "llvm/IR/Use.h"
24#include "llvm/Support/Debug.h"
26
27using namespace llvm;
28
29#define DEBUG_TYPE "fatlto-cleanup"
30
32 // Undo the frontend checked-load instrumentation: it is not correct for
33 // the non-LTO part of a FatLTO object, where whole-program metadata is
34 // unavailable, and the backend cannot select these intrinsics anyway.
35 Function *TypeCheckedLoadFn =
36 Intrinsic::getDeclarationIfExists(&M, Intrinsic::type_checked_load);
37 Function *TypeCheckedLoadRelFn = Intrinsic::getDeclarationIfExists(
38 &M, Intrinsic::type_checked_load_relative);
39
40 bool Changed = false;
41 if (TypeCheckedLoadFn)
42 Changed |=
43 lowertypetests::cleanUpTypeCheckedLoad(M, *TypeCheckedLoadFn, false);
44 if (TypeCheckedLoadRelFn)
45 Changed |=
46 lowertypetests::cleanUpTypeCheckedLoad(M, *TypeCheckedLoadRelFn, true);
47
48 if (Changed)
51}
Module.h This file contains the declarations for the Module class.
This header defines various interfaces for pass management in LLVM.
This defines the Use class.
LLVM_ABI PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:68
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
Definition Analysis.h:115
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition Analysis.h:118
Changed
LLVM_ABI Function * getDeclarationIfExists(const Module *M, ID id)
Look up the Function declaration of the intrinsic id in the Module M and return it if it exists.
LLVM_ABI bool cleanUpTypeCheckedLoad(Module &M, Function &CheckedLoadFn, bool IsRelative)
Lower @llvm.type.checked.load[.relative] calls to the guarded load with the check assumed true,...
This is an optimization pass for GlobalISel generic memory operations.
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
Definition MIRParser.h:39