mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-22 10:42:39 +01:00
[NFC] Split Knowledge retention and place it more appropriatly
Summary: Splitting Knowledge retention into Queries in Analysis and Builder into Transform/Utils allows Queries and Transform/Utils to use Analysis. Reviewers: jdoerfert, sstefan1 Reviewed By: jdoerfert Subscribers: mgorny, hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D77171
This commit is contained in:
parent
e80a23909b
commit
361dc8333f
@ -1,4 +1,4 @@
|
||||
//===- KnowledgeRetention.h - utilities to preserve informations *- C++ -*-===//
|
||||
//===- AssumeBundleQueries.h - utilities to query assume bundles *- C++ -*-===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
@ -6,19 +6,16 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file contain tools to preserve informations. They should be used before
|
||||
// performing a transformation that may move and delete instructions as those
|
||||
// transformation may destroy or worsen information that can be derived from the
|
||||
// IR.
|
||||
// This file contain tools to query into assume bundles. assume bundles can be
|
||||
// built using utilities from Transform/Utils/AssumeBundleBuilder.h
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_TRANSFORMS_UTILS_ASSUMEBUILDER_H
|
||||
#define LLVM_TRANSFORMS_UTILS_ASSUMEBUILDER_H
|
||||
#ifndef LLVM_TRANSFORMS_UTILS_ASSUMEBUNDLEQUERIES_H
|
||||
#define LLVM_TRANSFORMS_UTILS_ASSUMEBUNDLEQUERIES_H
|
||||
|
||||
#include "llvm/IR/Attributes.h"
|
||||
#include "llvm/IR/Instruction.h"
|
||||
#include "llvm/IR/PassManager.h"
|
||||
#include "llvm/IR/Instructions.h"
|
||||
#include "llvm/ADT/DenseMap.h"
|
||||
|
||||
namespace llvm {
|
||||
@ -35,6 +32,14 @@ IntrinsicInst *buildAssumeFromInst(Instruction *I);
|
||||
/// contained in the instruction I.
|
||||
void salvageKnowledge(Instruction *I);
|
||||
|
||||
/// Index of elements in the operand bundle.
|
||||
/// If the element exist it is guaranteed to be what is specified in this enum
|
||||
/// but it may not exist.
|
||||
enum AssumeBundleArg {
|
||||
ABA_WasOn = 0,
|
||||
ABA_Argument = 1,
|
||||
};
|
||||
|
||||
/// It is possible to have multiple Value for the argument of an attribute in
|
||||
/// the same llvm.assume on the same llvm::Value. This is rare but need to be
|
||||
/// dealt with.
|
||||
@ -135,16 +140,6 @@ inline RetainedKnowledge getKnowledgeFromUseInAssume(const Use *U) {
|
||||
/// function returned true.
|
||||
bool isAssumeWithEmptyBundle(CallInst &Assume);
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Utilities for testing
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
/// This pass will try to build an llvm.assume for every instruction in the
|
||||
/// function. Its main purpose is testing.
|
||||
struct AssumeBuilderPass : public PassInfoMixin<AssumeBuilderPass> {
|
||||
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
|
||||
};
|
||||
|
||||
} // namespace llvm
|
||||
|
||||
#endif
|
@ -101,6 +101,7 @@
|
||||
#include "llvm/ADT/SCCIterator.h"
|
||||
#include "llvm/ADT/SetVector.h"
|
||||
#include "llvm/Analysis/AliasAnalysis.h"
|
||||
#include "llvm/Analysis/AssumeBundleQueries.h"
|
||||
#include "llvm/Analysis/CGSCCPassManager.h"
|
||||
#include "llvm/Analysis/CallGraph.h"
|
||||
#include "llvm/Analysis/InlineCost.h"
|
||||
@ -110,7 +111,6 @@
|
||||
#include "llvm/Analysis/TargetTransformInfo.h"
|
||||
#include "llvm/IR/CallSite.h"
|
||||
#include "llvm/IR/ConstantRange.h"
|
||||
#include "llvm/IR/KnowledgeRetention.h"
|
||||
#include "llvm/IR/PassManager.h"
|
||||
#include "llvm/Support/Allocator.h"
|
||||
#include "llvm/Transforms/Utils/CallGraphUpdater.h"
|
||||
|
45
include/llvm/Transforms/Utils/AssumeBundleBuilder.h
Normal file
45
include/llvm/Transforms/Utils/AssumeBundleBuilder.h
Normal file
@ -0,0 +1,45 @@
|
||||
//===- AssumeBundleBuilder.h - utils to build assume bundles ----*- C++ -*-===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file contain tools to preserve informations. They should be used before
|
||||
// performing a transformation that may move and delete instructions as those
|
||||
// transformation may destroy or worsen information that can be derived from the
|
||||
// IR.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_TRANSFORMS_UTILS_ASSUMEBUNDLEBUILDER_H
|
||||
#define LLVM_TRANSFORMS_UTILS_ASSUMEBUNDLEBUILDER_H
|
||||
|
||||
#include "llvm/IR/Attributes.h"
|
||||
#include "llvm/IR/Instruction.h"
|
||||
#include "llvm/IR/PassManager.h"
|
||||
|
||||
namespace llvm {
|
||||
class IntrinsicInst;
|
||||
|
||||
/// Build a call to llvm.assume to preserve informations that can be derived
|
||||
/// from the given instruction.
|
||||
/// If no information derived from \p I, this call returns null.
|
||||
/// The returned instruction is not inserted anywhere.
|
||||
IntrinsicInst *buildAssumeFromInst(Instruction *I);
|
||||
|
||||
/// Calls BuildAssumeFromInst and if the resulting llvm.assume is valid insert
|
||||
/// if before I. This is usually what need to be done to salvage the knowledge
|
||||
/// contained in the instruction I.
|
||||
void salvageKnowledge(Instruction *I);
|
||||
|
||||
/// This pass will try to build an llvm.assume for every instruction in the
|
||||
/// function. Its main purpose is testing.
|
||||
struct AssumeBuilderPass : public PassInfoMixin<AssumeBuilderPass> {
|
||||
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
|
||||
};
|
||||
|
||||
} // namespace llvm
|
||||
|
||||
#endif
|
@ -272,7 +272,6 @@ module LLVM_intrinsic_gen {
|
||||
module IR_PatternMatch { header "IR/PatternMatch.h" export * }
|
||||
module IR_SafepointIRVerifier { header "IR/SafepointIRVerifier.h" export * }
|
||||
module IR_Statepoint { header "IR/Statepoint.h" export * }
|
||||
module IR_KnowledgeRetention { header "IR/KnowledgeRetention.h" export * }
|
||||
|
||||
export *
|
||||
}
|
||||
|
120
lib/Analysis/AssumeBundleQueries.cpp
Normal file
120
lib/Analysis/AssumeBundleQueries.cpp
Normal file
@ -0,0 +1,120 @@
|
||||
//===- AssumeBundleQueries.cpp - tool to query assume bundles ---*- C++ -*-===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/Analysis/AssumeBundleQueries.h"
|
||||
#include "llvm/IR/Function.h"
|
||||
#include "llvm/IR/InstIterator.h"
|
||||
#include "llvm/IR/IntrinsicInst.h"
|
||||
|
||||
using namespace llvm;
|
||||
|
||||
static bool bundleHasArgument(const CallBase::BundleOpInfo &BOI, unsigned Idx) {
|
||||
return BOI.End - BOI.Begin > Idx;
|
||||
}
|
||||
|
||||
static Value *getValueFromBundleOpInfo(IntrinsicInst &Assume,
|
||||
const CallBase::BundleOpInfo &BOI,
|
||||
unsigned Idx) {
|
||||
assert(bundleHasArgument(BOI, Idx) && "index out of range");
|
||||
return (Assume.op_begin() + BOI.Begin + Idx)->get();
|
||||
}
|
||||
|
||||
bool llvm::hasAttributeInAssume(CallInst &AssumeCI, Value *IsOn,
|
||||
StringRef AttrName, uint64_t *ArgVal,
|
||||
AssumeQuery AQR) {
|
||||
assert(isa<IntrinsicInst>(AssumeCI) &&
|
||||
"this function is intended to be used on llvm.assume");
|
||||
IntrinsicInst &Assume = cast<IntrinsicInst>(AssumeCI);
|
||||
assert(Assume.getIntrinsicID() == Intrinsic::assume &&
|
||||
"this function is intended to be used on llvm.assume");
|
||||
assert(Attribute::isExistingAttribute(AttrName) &&
|
||||
"this attribute doesn't exist");
|
||||
assert((ArgVal == nullptr || Attribute::doesAttrKindHaveArgument(
|
||||
Attribute::getAttrKindFromName(AttrName))) &&
|
||||
"requested value for an attribute that has no argument");
|
||||
if (Assume.bundle_op_infos().empty())
|
||||
return false;
|
||||
|
||||
auto Loop = [&](auto &&Range) {
|
||||
for (auto &BOI : Range) {
|
||||
if (BOI.Tag->getKey() != AttrName)
|
||||
continue;
|
||||
if (IsOn && (BOI.End - BOI.Begin <= ABA_WasOn ||
|
||||
IsOn != getValueFromBundleOpInfo(Assume, BOI, ABA_WasOn)))
|
||||
continue;
|
||||
if (ArgVal) {
|
||||
assert(BOI.End - BOI.Begin > ABA_Argument);
|
||||
*ArgVal = cast<ConstantInt>(
|
||||
getValueFromBundleOpInfo(Assume, BOI, ABA_Argument))
|
||||
->getZExtValue();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
if (AQR == AssumeQuery::Lowest)
|
||||
return Loop(Assume.bundle_op_infos());
|
||||
return Loop(reverse(Assume.bundle_op_infos()));
|
||||
}
|
||||
|
||||
void llvm::fillMapFromAssume(CallInst &AssumeCI, RetainedKnowledgeMap &Result) {
|
||||
IntrinsicInst &Assume = cast<IntrinsicInst>(AssumeCI);
|
||||
assert(Assume.getIntrinsicID() == Intrinsic::assume &&
|
||||
"this function is intended to be used on llvm.assume");
|
||||
for (auto &Bundles : Assume.bundle_op_infos()) {
|
||||
std::pair<Value *, Attribute::AttrKind> Key{
|
||||
nullptr, Attribute::getAttrKindFromName(Bundles.Tag->getKey())};
|
||||
if (bundleHasArgument(Bundles, ABA_WasOn))
|
||||
Key.first = getValueFromBundleOpInfo(Assume, Bundles, ABA_WasOn);
|
||||
|
||||
if (Key.first == nullptr && Key.second == Attribute::None)
|
||||
continue;
|
||||
if (!bundleHasArgument(Bundles, ABA_Argument)) {
|
||||
Result[Key][&Assume] = {0, 0};
|
||||
continue;
|
||||
}
|
||||
unsigned Val = cast<ConstantInt>(
|
||||
getValueFromBundleOpInfo(Assume, Bundles, ABA_Argument))
|
||||
->getZExtValue();
|
||||
auto Lookup = Result.find(Key);
|
||||
if (Lookup == Result.end() || !Lookup->second.count(&Assume)) {
|
||||
Result[Key][&Assume] = {Val, Val};
|
||||
continue;
|
||||
}
|
||||
Lookup->second[&Assume].Min = std::min(Val, Lookup->second[&Assume].Min);
|
||||
Lookup->second[&Assume].Max = std::max(Val, Lookup->second[&Assume].Max);
|
||||
}
|
||||
}
|
||||
|
||||
RetainedKnowledge llvm::getKnowledgeFromOperandInAssume(CallInst &AssumeCI,
|
||||
unsigned Idx) {
|
||||
IntrinsicInst &Assume = cast<IntrinsicInst>(AssumeCI);
|
||||
assert(Assume.getIntrinsicID() == Intrinsic::assume &&
|
||||
"this function is intended to be used on llvm.assume");
|
||||
CallBase::BundleOpInfo BOI = Assume.getBundleOpInfoForOperand(Idx);
|
||||
RetainedKnowledge Result;
|
||||
Result.AttrKind = Attribute::getAttrKindFromName(BOI.Tag->getKey());
|
||||
Result.WasOn = getValueFromBundleOpInfo(Assume, BOI, ABA_WasOn);
|
||||
if (BOI.End - BOI.Begin > ABA_Argument)
|
||||
Result.ArgValue =
|
||||
cast<ConstantInt>(getValueFromBundleOpInfo(Assume, BOI, ABA_Argument))
|
||||
->getZExtValue();
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
bool llvm::isAssumeWithEmptyBundle(CallInst &CI) {
|
||||
IntrinsicInst &Assume = cast<IntrinsicInst>(CI);
|
||||
assert(Assume.getIntrinsicID() == Intrinsic::assume &&
|
||||
"this function is intended to be used on llvm.assume");
|
||||
return none_of(Assume.bundle_op_infos(),
|
||||
[](const CallBase::BundleOpInfo &BOI) {
|
||||
return BOI.Tag->getKey() != "ignore";
|
||||
});
|
||||
}
|
@ -4,6 +4,7 @@ add_llvm_component_library(LLVMAnalysis
|
||||
AliasAnalysisSummary.cpp
|
||||
AliasSetTracker.cpp
|
||||
Analysis.cpp
|
||||
AssumeBundleQueries.cpp
|
||||
AssumptionCache.cpp
|
||||
BasicAliasAnalysis.cpp
|
||||
BlockFrequencyInfo.cpp
|
||||
|
@ -28,7 +28,6 @@ add_llvm_component_library(LLVMCore
|
||||
Instruction.cpp
|
||||
Instructions.cpp
|
||||
IntrinsicInst.cpp
|
||||
KnowledgeRetention.cpp
|
||||
LLVMContext.cpp
|
||||
LLVMContextImpl.cpp
|
||||
LLVMRemarkStreamer.cpp
|
||||
|
@ -59,7 +59,6 @@
|
||||
#include "llvm/CodeGen/UnreachableBlockElim.h"
|
||||
#include "llvm/IR/Dominators.h"
|
||||
#include "llvm/IR/IRPrintingPasses.h"
|
||||
#include "llvm/IR/KnowledgeRetention.h"
|
||||
#include "llvm/IR/PassManager.h"
|
||||
#include "llvm/IR/SafepointIRVerifier.h"
|
||||
#include "llvm/IR/Verifier.h"
|
||||
@ -176,6 +175,7 @@
|
||||
#include "llvm/Transforms/Scalar/TailRecursionElimination.h"
|
||||
#include "llvm/Transforms/Scalar/WarnMissedTransforms.h"
|
||||
#include "llvm/Transforms/Utils/AddDiscriminators.h"
|
||||
#include "llvm/Transforms/Utils/AssumeBundleBuilder.h"
|
||||
#include "llvm/Transforms/Utils/BreakCriticalEdges.h"
|
||||
#include "llvm/Transforms/Utils/CanonicalizeAliases.h"
|
||||
#include "llvm/Transforms/Utils/EntryExitInstrumenter.h"
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "llvm/ADT/SmallVector.h"
|
||||
#include "llvm/ADT/Statistic.h"
|
||||
#include "llvm/ADT/Twine.h"
|
||||
#include "llvm/Analysis/AssumeBundleQueries.h"
|
||||
#include "llvm/Analysis/AssumptionCache.h"
|
||||
#include "llvm/Analysis/InstructionSimplify.h"
|
||||
#include "llvm/Analysis/Loads.h"
|
||||
@ -48,7 +49,6 @@
|
||||
#include "llvm/IR/IntrinsicsNVPTX.h"
|
||||
#include "llvm/IR/IntrinsicsAMDGPU.h"
|
||||
#include "llvm/IR/IntrinsicsPowerPC.h"
|
||||
#include "llvm/IR/KnowledgeRetention.h"
|
||||
#include "llvm/IR/LLVMContext.h"
|
||||
#include "llvm/IR/Metadata.h"
|
||||
#include "llvm/IR/PatternMatch.h"
|
||||
|
@ -38,7 +38,6 @@
|
||||
#include "llvm/IR/Instructions.h"
|
||||
#include "llvm/IR/IntrinsicInst.h"
|
||||
#include "llvm/IR/Intrinsics.h"
|
||||
#include "llvm/IR/KnowledgeRetention.h"
|
||||
#include "llvm/IR/LLVMContext.h"
|
||||
#include "llvm/IR/PassManager.h"
|
||||
#include "llvm/IR/PatternMatch.h"
|
||||
@ -55,6 +54,7 @@
|
||||
#include "llvm/Support/RecyclingAllocator.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
#include "llvm/Transforms/Scalar.h"
|
||||
#include "llvm/Transforms/Utils/AssumeBundleBuilder.h"
|
||||
#include "llvm/Transforms/Utils/GuardUtils.h"
|
||||
#include "llvm/Transforms/Utils/Local.h"
|
||||
#include <cassert>
|
||||
|
@ -1,4 +1,4 @@
|
||||
//===- KnowledgeRetention.h - utilities to preserve informations *- C++ -*-===//
|
||||
//===- AssumeBundleBuilder.cpp - tools to preserve informations -*- C++ -*-===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
@ -6,7 +6,8 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/IR/KnowledgeRetention.h"
|
||||
#include "llvm/Transforms/Utils/AssumeBundleBuilder.h"
|
||||
#include "llvm/Analysis/AssumeBundleQueries.h"
|
||||
#include "llvm/ADT/DenseSet.h"
|
||||
#include "llvm/IR/Function.h"
|
||||
#include "llvm/IR/InstIterator.h"
|
||||
@ -65,14 +66,6 @@ template <> struct DenseMapInfo<AssumedKnowledge> {
|
||||
|
||||
namespace {
|
||||
|
||||
/// Index of elements in the operand bundle.
|
||||
/// If the element exist it is guaranteed to be what is specified in this enum
|
||||
/// but it may not exist.
|
||||
enum BundleOpInfoElem {
|
||||
BOIE_WasOn = 0,
|
||||
BOIE_Argument = 1,
|
||||
};
|
||||
|
||||
/// Deterministically compare OperandBundleDef.
|
||||
/// The ordering is:
|
||||
/// - by the attribute's name aka operand bundle tag, (doesn't change)
|
||||
@ -85,13 +78,13 @@ bool isLowerOpBundle(const OperandBundleDef &LHS, const OperandBundleDef &RHS) {
|
||||
auto getTuple = [](const OperandBundleDef &Op) {
|
||||
return std::make_tuple(
|
||||
Op.getTag(),
|
||||
Op.input_size() <= BOIE_Argument
|
||||
Op.input_size() <= ABA_Argument
|
||||
? 0
|
||||
: cast<ConstantInt>(*(Op.input_begin() + BOIE_Argument))
|
||||
: cast<ConstantInt>(*(Op.input_begin() + ABA_Argument))
|
||||
->getZExtValue(),
|
||||
Op.input_size() <= BOIE_WasOn
|
||||
Op.input_size() <= ABA_WasOn
|
||||
? StringRef("")
|
||||
: (*(Op.input_begin() + BOIE_WasOn))->getName());
|
||||
: (*(Op.input_begin() + ABA_WasOn))->getName());
|
||||
};
|
||||
return getTuple(LHS) < getTuple(RHS);
|
||||
}
|
||||
@ -234,113 +227,6 @@ void llvm::salvageKnowledge(Instruction *I) {
|
||||
Intr->insertBefore(I);
|
||||
}
|
||||
|
||||
static bool bundleHasArgument(const CallBase::BundleOpInfo &BOI,
|
||||
unsigned Idx) {
|
||||
return BOI.End - BOI.Begin > Idx;
|
||||
}
|
||||
|
||||
static Value *getValueFromBundleOpInfo(IntrinsicInst &Assume,
|
||||
const CallBase::BundleOpInfo &BOI,
|
||||
unsigned Idx) {
|
||||
assert(bundleHasArgument(BOI, Idx) && "index out of range");
|
||||
return (Assume.op_begin() + BOI.Begin + Idx)->get();
|
||||
}
|
||||
|
||||
bool llvm::hasAttributeInAssume(CallInst &AssumeCI, Value *IsOn,
|
||||
StringRef AttrName, uint64_t *ArgVal,
|
||||
AssumeQuery AQR) {
|
||||
assert(isa<IntrinsicInst>(AssumeCI) &&
|
||||
"this function is intended to be used on llvm.assume");
|
||||
IntrinsicInst &Assume = cast<IntrinsicInst>(AssumeCI);
|
||||
assert(Assume.getIntrinsicID() == Intrinsic::assume &&
|
||||
"this function is intended to be used on llvm.assume");
|
||||
assert(Attribute::isExistingAttribute(AttrName) &&
|
||||
"this attribute doesn't exist");
|
||||
assert((ArgVal == nullptr || Attribute::doesAttrKindHaveArgument(
|
||||
Attribute::getAttrKindFromName(AttrName))) &&
|
||||
"requested value for an attribute that has no argument");
|
||||
if (Assume.bundle_op_infos().empty())
|
||||
return false;
|
||||
|
||||
auto Loop = [&](auto &&Range) {
|
||||
for (auto &BOI : Range) {
|
||||
if (BOI.Tag->getKey() != AttrName)
|
||||
continue;
|
||||
if (IsOn && (BOI.End - BOI.Begin <= BOIE_WasOn ||
|
||||
IsOn != getValueFromBundleOpInfo(Assume, BOI, BOIE_WasOn)))
|
||||
continue;
|
||||
if (ArgVal) {
|
||||
assert(BOI.End - BOI.Begin > BOIE_Argument);
|
||||
*ArgVal = cast<ConstantInt>(
|
||||
getValueFromBundleOpInfo(Assume, BOI, BOIE_Argument))
|
||||
->getZExtValue();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
if (AQR == AssumeQuery::Lowest)
|
||||
return Loop(Assume.bundle_op_infos());
|
||||
return Loop(reverse(Assume.bundle_op_infos()));
|
||||
}
|
||||
|
||||
void llvm::fillMapFromAssume(CallInst &AssumeCI, RetainedKnowledgeMap &Result) {
|
||||
IntrinsicInst &Assume = cast<IntrinsicInst>(AssumeCI);
|
||||
assert(Assume.getIntrinsicID() == Intrinsic::assume &&
|
||||
"this function is intended to be used on llvm.assume");
|
||||
for (auto &Bundles : Assume.bundle_op_infos()) {
|
||||
std::pair<Value *, Attribute::AttrKind> Key{
|
||||
nullptr, Attribute::getAttrKindFromName(Bundles.Tag->getKey())};
|
||||
if (bundleHasArgument(Bundles, BOIE_WasOn))
|
||||
Key.first = getValueFromBundleOpInfo(Assume, Bundles, BOIE_WasOn);
|
||||
|
||||
if (Key.first == nullptr && Key.second == Attribute::None)
|
||||
continue;
|
||||
if (!bundleHasArgument(Bundles, BOIE_Argument)) {
|
||||
Result[Key][&Assume] = {0, 0};
|
||||
continue;
|
||||
}
|
||||
unsigned Val = cast<ConstantInt>(
|
||||
getValueFromBundleOpInfo(Assume, Bundles, BOIE_Argument))
|
||||
->getZExtValue();
|
||||
auto Lookup = Result.find(Key);
|
||||
if (Lookup == Result.end() || !Lookup->second.count(&Assume)) {
|
||||
Result[Key][&Assume] = {Val, Val};
|
||||
continue;
|
||||
}
|
||||
Lookup->second[&Assume].Min = std::min(Val, Lookup->second[&Assume].Min);
|
||||
Lookup->second[&Assume].Max = std::max(Val, Lookup->second[&Assume].Max);
|
||||
}
|
||||
}
|
||||
|
||||
RetainedKnowledge llvm::getKnowledgeFromOperandInAssume(CallInst &AssumeCI,
|
||||
unsigned Idx) {
|
||||
IntrinsicInst &Assume = cast<IntrinsicInst>(AssumeCI);
|
||||
assert(Assume.getIntrinsicID() == Intrinsic::assume &&
|
||||
"this function is intended to be used on llvm.assume");
|
||||
CallBase::BundleOpInfo BOI = Assume.getBundleOpInfoForOperand(Idx);
|
||||
RetainedKnowledge Result;
|
||||
Result.AttrKind = Attribute::getAttrKindFromName(BOI.Tag->getKey());
|
||||
Result.WasOn = getValueFromBundleOpInfo(Assume, BOI, BOIE_WasOn);
|
||||
if (BOI.End - BOI.Begin > BOIE_Argument)
|
||||
Result.ArgValue =
|
||||
cast<ConstantInt>(getValueFromBundleOpInfo(Assume, BOI, BOIE_Argument))
|
||||
->getZExtValue();
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
bool llvm::isAssumeWithEmptyBundle(CallInst &CI) {
|
||||
IntrinsicInst &Assume = cast<IntrinsicInst>(CI);
|
||||
assert(Assume.getIntrinsicID() == Intrinsic::assume &&
|
||||
"this function is intended to be used on llvm.assume");
|
||||
return none_of(Assume.bundle_op_infos(),
|
||||
[](const CallBase::BundleOpInfo &BOI) {
|
||||
return BOI.Tag->getKey() != "ignore";
|
||||
});
|
||||
}
|
||||
|
||||
PreservedAnalyses AssumeBuilderPass::run(Function &F,
|
||||
FunctionAnalysisManager &AM) {
|
||||
for (Instruction &I : instructions(F))
|
@ -1,7 +1,8 @@
|
||||
add_llvm_component_library(LLVMTransformUtils
|
||||
AddDiscriminators.cpp
|
||||
AMDGPUEmitPrintf.cpp
|
||||
ASanStackFrameLayout.cpp
|
||||
AddDiscriminators.cpp
|
||||
AssumeBundleBuilder.cpp
|
||||
BasicBlockUtils.cpp
|
||||
BreakCriticalEdges.cpp
|
||||
BuildLibCalls.cpp
|
||||
|
@ -50,7 +50,6 @@
|
||||
#include "llvm/IR/Instructions.h"
|
||||
#include "llvm/IR/IntrinsicInst.h"
|
||||
#include "llvm/IR/Intrinsics.h"
|
||||
#include "llvm/IR/KnowledgeRetention.h"
|
||||
#include "llvm/IR/LLVMContext.h"
|
||||
#include "llvm/IR/MDBuilder.h"
|
||||
#include "llvm/IR/Metadata.h"
|
||||
@ -61,6 +60,7 @@
|
||||
#include "llvm/Support/Casting.h"
|
||||
#include "llvm/Support/CommandLine.h"
|
||||
#include "llvm/Support/ErrorHandling.h"
|
||||
#include "llvm/Transforms/Utils/AssumeBundleBuilder.h"
|
||||
#include "llvm/Transforms/Utils/Cloning.h"
|
||||
#include "llvm/Transforms/Utils/ValueMapper.h"
|
||||
#include <algorithm>
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "llvm/ADT/SmallVector.h"
|
||||
#include "llvm/ADT/Statistic.h"
|
||||
#include "llvm/ADT/TinyPtrVector.h"
|
||||
#include "llvm/Analysis/AssumeBundleQueries.h"
|
||||
#include "llvm/Analysis/ConstantFolding.h"
|
||||
#include "llvm/Analysis/DomTreeUpdater.h"
|
||||
#include "llvm/Analysis/EHPersonalities.h"
|
||||
@ -59,7 +60,6 @@
|
||||
#include "llvm/IR/Instructions.h"
|
||||
#include "llvm/IR/IntrinsicInst.h"
|
||||
#include "llvm/IR/Intrinsics.h"
|
||||
#include "llvm/IR/KnowledgeRetention.h"
|
||||
#include "llvm/IR/LLVMContext.h"
|
||||
#include "llvm/IR/MDBuilder.h"
|
||||
#include "llvm/IR/Metadata.h"
|
||||
|
@ -1,4 +1,4 @@
|
||||
//===- KnowledgeRetention.h - utilities to preserve informations *- C++ -*-===//
|
||||
//===- AssumeBundleQueriesTest.cpp ------------------------------*- C++ -*-===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
@ -6,7 +6,7 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/IR/KnowledgeRetention.h"
|
||||
#include "llvm/Analysis/AssumeBundleQueries.h"
|
||||
#include "llvm/AsmParser/Parser.h"
|
||||
#include "llvm/IR/CallSite.h"
|
||||
#include "llvm/IR/LLVMContext.h"
|
||||
@ -14,6 +14,7 @@
|
||||
#include "llvm/Support/Regex.h"
|
||||
#include "llvm/Support/SourceMgr.h"
|
||||
#include "llvm/Support/CommandLine.h"
|
||||
#include "llvm/Transforms/Utils/AssumeBundleBuilder.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include <random>
|
||||
|
@ -9,6 +9,7 @@ set(LLVM_LINK_COMPONENTS
|
||||
add_llvm_unittest(AnalysisTests
|
||||
AliasAnalysisTest.cpp
|
||||
AliasSetTrackerTest.cpp
|
||||
AssumeBundleQueriesTest.cpp
|
||||
BasicAliasAnalysisTest.cpp
|
||||
BlockFrequencyInfoTest.cpp
|
||||
BranchProbabilityInfoTest.cpp
|
||||
|
@ -24,7 +24,6 @@ add_llvm_unittest(IRTests
|
||||
IRBuilderTest.cpp
|
||||
InstructionsTest.cpp
|
||||
IntrinsicsTest.cpp
|
||||
KnowledgeRetentionTest.cpp
|
||||
LegacyPassManagerTest.cpp
|
||||
MDBuilderTest.cpp
|
||||
ManglerTest.cpp
|
||||
|
Loading…
Reference in New Issue
Block a user