[llvm] 764a7f4 - [TypePromotion] Format Type Promotion. NFC
David Green via llvm-commits
llvm-commits at lists.llvm.org
Wed May 11 00:19:08 PDT 2022
Author: David Green
Date: 2022-05-11T08:18:58+01:00
New Revision: 764a7f48647210f4a360f74f82432ad276d92716
URL: https://github.com/llvm/llvm-project/commit/764a7f48647210f4a360f74f82432ad276d92716
DIFF: https://github.com/llvm/llvm-project/commit/764a7f48647210f4a360f74f82432ad276d92716.diff
LOG: [TypePromotion] Format Type Promotion. NFC
This clang-formats the TypePromotion code, with the only meaningful
change being the removal of a verifyFunction call inside a LLVM_DEBUG,
and the printing of the entire function which can be better handled
via -print-after-all.
Added:
Modified:
llvm/lib/CodeGen/TypePromotion.cpp
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/TypePromotion.cpp b/llvm/lib/CodeGen/TypePromotion.cpp
index 48454a5047dd..6b991aa73de9 100644
--- a/llvm/lib/CodeGen/TypePromotion.cpp
+++ b/llvm/lib/CodeGen/TypePromotion.cpp
@@ -43,9 +43,9 @@
using namespace llvm;
-static cl::opt<bool>
-DisablePromotion("disable-type-promotion", cl::Hidden, cl::init(false),
- cl::desc("Disable type promotion pass"));
+static cl::opt<bool> DisablePromotion("disable-type-promotion", cl::Hidden,
+ cl::init(false),
+ cl::desc("Disable type promotion pass"));
// The goal of this pass is to enable more efficient code generation for
// operations on narrow types (i.e. types with < 32-bits) and this is a
@@ -104,15 +104,15 @@ class IRPromoter {
LLVMContext &Ctx;
IntegerType *OrigTy = nullptr;
unsigned PromotedWidth = 0;
- SetVector<Value*> &Visited;
- SetVector<Value*> &Sources;
- SetVector<Instruction*> &Sinks;
+ SetVector<Value *> &Visited;
+ SetVector<Value *> &Sources;
+ SetVector<Instruction *> &Sinks;
SmallPtrSetImpl<Instruction *> &SafeWrap;
IntegerType *ExtTy = nullptr;
- SmallPtrSet<Value*, 8> NewInsts;
- SmallPtrSet<Instruction*, 4> InstsToRemove;
- DenseMap<Value*, SmallVector<Type*, 4>> TruncTysMap;
- SmallPtrSet<Value*, 8> Promoted;
+ SmallPtrSet<Value *, 8> NewInsts;
+ SmallPtrSet<Instruction *, 4> InstsToRemove;
+ DenseMap<Value *, SmallVector<Type *, 4>> TruncTysMap;
+ SmallPtrSet<Value *, 8> Promoted;
void ReplaceAllUsersOfWith(Value *From, Value *To);
void ExtendSources();
@@ -141,8 +141,8 @@ class TypePromotion : public FunctionPass {
unsigned TypeSize = 0;
LLVMContext *Ctx = nullptr;
unsigned RegisterBitWidth = 0;
- SmallPtrSet<Value*, 16> AllVisited;
- SmallPtrSet<Instruction*, 8> SafeToPromote;
+ SmallPtrSet<Value *, 16> AllVisited;
+ SmallPtrSet<Instruction *, 8> SafeToPromote;
SmallPtrSet<Instruction *, 4> SafeWrap;
// Does V have the same size result type as TypeSize.
@@ -189,7 +189,7 @@ class TypePromotion : public FunctionPass {
bool runOnFunction(Function &F) override;
};
-}
+} // namespace
static bool GenerateSignBits(Instruction *I) {
unsigned Opc = I->getOpcode();
@@ -268,7 +268,7 @@ bool TypePromotion::isSink(Value *V) {
/// Return whether this instruction can safely wrap.
bool TypePromotion::isSafeWrap(Instruction *I) {
- // We can support a, potentially, wrapping instruction (I) if:
+ // We can support a potentially wrapping instruction (I) if:
// - It is only used by an unsigned icmp.
// - The icmp uses a constant.
// - The wrapping value (I) is decreasing, i.e would underflow - wrapping
@@ -355,7 +355,7 @@ bool TypePromotion::isSafeWrap(Instruction *I) {
if (!OverflowConst.isNonPositive())
return false;
- // Using C1 = OverflowConst and C2 = ICmpConst, we can use either prove that:
+ // Using C1 = OverflowConst and C2 = ICmpConst, we can either prove that:
// zext(x) + sext(C1) <u zext(C2) if C1 < 0 and C1 >s C2
// zext(x) + sext(C1) <u sext(C2) if C1 < 0 and C1 <=s C2
if (OverflowConst.sgt(ICmpConst)) {
@@ -403,7 +403,7 @@ static bool isPromotedResultSafe(Instruction *I) {
}
void IRPromoter::ReplaceAllUsersOfWith(Value *From, Value *To) {
- SmallVector<Instruction*, 4> Users;
+ SmallVector<Instruction *, 4> Users;
Instruction *InstTo = dyn_cast<Instruction>(To);
bool ReplacedAll = true;
@@ -505,7 +505,7 @@ void IRPromoter::TruncateSinks() {
IRBuilder<> Builder{Ctx};
- auto InsertTrunc = [&](Value *V, Type *TruncTy) -> Instruction* {
+ auto InsertTrunc = [&](Value *V, Type *TruncTy) -> Instruction * {
if (!isa<Instruction>(V) || !isa<IntegerType>(V->getType()))
return nullptr;
@@ -513,7 +513,7 @@ void IRPromoter::TruncateSinks() {
return nullptr;
LLVM_DEBUG(dbgs() << "IR Promotion: Creating " << *TruncTy << " Trunc for "
- << *V << "\n");
+ << *V << "\n");
Builder.SetInsertPoint(cast<Instruction>(V));
auto *Trunc = dyn_cast<Instruction>(Builder.CreateTrunc(V, TruncTy));
if (Trunc)
@@ -575,7 +575,7 @@ void IRPromoter::Cleanup() {
Value *Src = ZExt->getOperand(0);
if (ZExt->getSrcTy() == ZExt->getDestTy()) {
LLVM_DEBUG(dbgs() << "IR Promotion: Removing unnecessary cast: " << *ZExt
- << "\n");
+ << "\n");
ReplaceAllUsersOfWith(ZExt, Src);
continue;
}
@@ -614,7 +614,7 @@ void IRPromoter::ConvertTruncs() {
unsigned NumBits = DestTy->getScalarSizeInBits();
ConstantInt *Mask =
- ConstantInt::get(SrcTy, APInt::getMaxValue(NumBits).getZExtValue());
+ ConstantInt::get(SrcTy, APInt::getMaxValue(NumBits).getZExtValue());
Value *Masked = Builder.CreateAnd(Trunc->getOperand(0), Mask);
if (auto *I = dyn_cast<Instruction>(Masked))
@@ -626,7 +626,8 @@ void IRPromoter::ConvertTruncs() {
void IRPromoter::Mutate() {
LLVM_DEBUG(dbgs() << "IR Promotion: Promoting use-def chains from "
- << OrigTy->getBitWidth() << " to " << PromotedWidth << "-bits\n");
+ << OrigTy->getBitWidth() << " to " << PromotedWidth
+ << "-bits\n");
// Cache original types of the values that will likely need truncating
for (auto *I : Sinks) {
@@ -676,8 +677,7 @@ bool TypePromotion::isSupportedType(Value *V) {
if (Ty->isVoidTy() || Ty->isPointerTy())
return true;
- if (!isa<IntegerType>(Ty) ||
- cast<IntegerType>(Ty)->getBitWidth() == 1 ||
+ if (!isa<IntegerType>(Ty) || cast<IntegerType>(Ty)->getBitWidth() == 1 ||
cast<IntegerType>(Ty)->getBitWidth() > RegisterBitWidth)
return false;
@@ -737,13 +737,12 @@ bool TypePromotion::isSupportedValue(Value *V) {
/// smaller than the targeted promoted type. Check that we're not trying to
/// promote something larger than our base 'TypeSize' type.
bool TypePromotion::isLegalToPromote(Value *V) {
-
auto *I = dyn_cast<Instruction>(V);
if (!I)
return true;
if (SafeToPromote.count(I))
- return true;
+ return true;
if (isPromotedResultSafe(I) || isSafeWrap(I)) {
SafeToPromote.insert(I);
@@ -764,10 +763,10 @@ bool TypePromotion::TryToPromote(Value *V, unsigned PromotedWidth) {
LLVM_DEBUG(dbgs() << "IR Promotion: TryToPromote: " << *V << ", from "
<< TypeSize << " bits to " << PromotedWidth << "\n");
- SetVector<Value*> WorkList;
- SetVector<Value*> Sources;
- SetVector<Instruction*> Sinks;
- SetVector<Value*> CurrentVisited;
+ SetVector<Value *> WorkList;
+ SetVector<Value *> Sources;
+ SetVector<Instruction *> Sinks;
+ SetVector<Value *> CurrentVisited;
WorkList.insert(V);
// Return true if V was added to the worklist as a supported instruction,
@@ -838,14 +837,15 @@ bool TypePromotion::TryToPromote(Value *V, unsigned PromotedWidth) {
}
}
- LLVM_DEBUG(dbgs() << "IR Promotion: Visited nodes:\n";
- for (auto *I : CurrentVisited)
- I->dump();
- );
+ LLVM_DEBUG({
+ dbgs() << "IR Promotion: Visited nodes:\n";
+ for (auto *I : CurrentVisited)
+ I->dump();
+ });
unsigned ToPromote = 0;
unsigned NonFreeArgs = 0;
- SmallPtrSet<BasicBlock*, 4> Blocks;
+ SmallPtrSet<BasicBlock *, 4> Blocks;
for (auto *V : CurrentVisited) {
if (auto *I = dyn_cast<Instruction>(V))
Blocks.insert(I->getParent());
@@ -859,8 +859,8 @@ bool TypePromotion::TryToPromote(Value *V, unsigned PromotedWidth) {
if (Sinks.count(cast<Instruction>(V)))
continue;
- ++ToPromote;
- }
+ ++ToPromote;
+ }
// DAG optimizations should be able to handle these cases better, especially
// for function arguments.
@@ -892,14 +892,14 @@ bool TypePromotion::runOnFunction(Function &F) {
const TargetSubtargetInfo *SubtargetInfo = TM.getSubtargetImpl(F);
const TargetLowering *TLI = SubtargetInfo->getTargetLowering();
const TargetTransformInfo &TII =
- getAnalysis<TargetTransformInfoWrapperPass>().getTTI(F);
+ getAnalysis<TargetTransformInfoWrapperPass>().getTTI(F);
RegisterBitWidth =
TII.getRegisterBitWidth(TargetTransformInfo::RGK_Scalar).getFixedSize();
Ctx = &F.getParent()->getContext();
// Search up from icmps to try to promote their operands.
for (BasicBlock &BB : F) {
- for (auto &I : BB) {
+ for (Instruction &I : BB) {
if (AllVisited.count(&I))
continue;
@@ -908,8 +908,7 @@ bool TypePromotion::runOnFunction(Function &F) {
auto *ICmp = cast<ICmpInst>(&I);
// Skip signed or pointer compares
- if (ICmp->isSigned() ||
- !isa<IntegerType>(ICmp->getOperand(0)->getType()))
+ if (ICmp->isSigned() || !isa<IntegerType>(ICmp->getOperand(0)->getType()))
continue;
LLVM_DEBUG(dbgs() << "IR Promotion: Searching from: " << *ICmp << "\n");
@@ -920,13 +919,13 @@ bool TypePromotion::runOnFunction(Function &F) {
if (SrcVT.isSimple() && TLI->isTypeLegal(SrcVT.getSimpleVT()))
break;
- if (TLI->getTypeAction(ICmp->getContext(), SrcVT) !=
+ if (TLI->getTypeAction(*Ctx, SrcVT) !=
TargetLowering::TypePromoteInteger)
break;
- EVT PromotedVT = TLI->getTypeToTransformTo(ICmp->getContext(), SrcVT);
+ EVT PromotedVT = TLI->getTypeToTransformTo(*Ctx, SrcVT);
if (RegisterBitWidth < PromotedVT.getFixedSizeInBits()) {
LLVM_DEBUG(dbgs() << "IR Promotion: Couldn't find target register "
- << "for promoted type\n");
+ << "for promoted type\n");
break;
}
@@ -935,13 +934,7 @@ bool TypePromotion::runOnFunction(Function &F) {
}
}
}
- LLVM_DEBUG(if (verifyFunction(F, &dbgs())) {
- dbgs() << F;
- report_fatal_error("Broken function after type promotion");
- });
}
- if (MadeChange)
- LLVM_DEBUG(dbgs() << "After TypePromotion: " << F << "\n");
AllVisited.clear();
SafeToPromote.clear();
@@ -955,6 +948,4 @@ INITIALIZE_PASS_END(TypePromotion, DEBUG_TYPE, PASS_NAME, false, false)
char TypePromotion::ID = 0;
-FunctionPass *llvm::createTypePromotionPass() {
- return new TypePromotion();
-}
+FunctionPass *llvm::createTypePromotionPass() { return new TypePromotion(); }
More information about the llvm-commits
mailing list