mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-25 04:02:41 +01:00
b20ef5f960
As noted in https://bugs.llvm.org/show_bug.cgi?id=36651, the specialization for isPodLike<std::pair<...>> did not match the expectation of std::is_trivially_copyable which makes the memcpy optimization invalid. This patch renames the llvm::isPodLike trait into llvm::is_trivially_copyable. Unfortunately std::is_trivially_copyable is not portable across compiler / STL versions. So a portable version is provided too. Note that the following specialization were invalid: std::pair<T0, T1> llvm::Optional<T> Tests have been added to assert that former specialization are respected by the standard usage of llvm::is_trivially_copyable, and that when a decent version of std::is_trivially_copyable is available, llvm::is_trivially_copyable is compared to std::is_trivially_copyable. As of this patch, llvm::Optional is no longer considered trivially copyable, even if T is. This is to be fixed in a later patch, as it has impact on a long-running bug (see r347004) Note that GCC warns about this UB, but this got silented by https://reviews.llvm.org/D50296. Differential Revision: https://reviews.llvm.org/D54472 llvm-svn: 351701
99 lines
3.6 KiB
C++
99 lines
3.6 KiB
C++
//===- BlockFrequencyInfoTest.cpp - BlockFrequencyInfo unit tests ---------===//
|
|
//
|
|
// 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/BlockFrequencyInfo.h"
|
|
#include "llvm/Analysis/BlockFrequencyInfoImpl.h"
|
|
#include "llvm/Analysis/BranchProbabilityInfo.h"
|
|
#include "llvm/Analysis/LoopInfo.h"
|
|
#include "llvm/AsmParser/Parser.h"
|
|
#include "llvm/IR/BasicBlock.h"
|
|
#include "llvm/IR/Dominators.h"
|
|
#include "llvm/IR/Function.h"
|
|
#include "llvm/IR/LLVMContext.h"
|
|
#include "llvm/IR/Module.h"
|
|
#include "llvm/Support/DataTypes.h"
|
|
#include "llvm/Support/SourceMgr.h"
|
|
#include "llvm/Support/raw_ostream.h"
|
|
#include "gtest/gtest.h"
|
|
|
|
namespace llvm {
|
|
namespace {
|
|
|
|
class BlockFrequencyInfoTest : public testing::Test {
|
|
protected:
|
|
std::unique_ptr<BranchProbabilityInfo> BPI;
|
|
std::unique_ptr<DominatorTree> DT;
|
|
std::unique_ptr<LoopInfo> LI;
|
|
LLVMContext C;
|
|
|
|
BlockFrequencyInfo buildBFI(Function &F) {
|
|
DT.reset(new DominatorTree(F));
|
|
LI.reset(new LoopInfo(*DT));
|
|
BPI.reset(new BranchProbabilityInfo(F, *LI));
|
|
return BlockFrequencyInfo(F, *BPI, *LI);
|
|
}
|
|
std::unique_ptr<Module> makeLLVMModule() {
|
|
const char *ModuleStrig = "define i32 @f(i32 %x) {\n"
|
|
"bb0:\n"
|
|
" %y1 = icmp eq i32 %x, 0 \n"
|
|
" br i1 %y1, label %bb1, label %bb2 \n"
|
|
"bb1:\n"
|
|
" br label %bb3\n"
|
|
"bb2:\n"
|
|
" br label %bb3\n"
|
|
"bb3:\n"
|
|
" %y2 = phi i32 [0, %bb1], [1, %bb2] \n"
|
|
" ret i32 %y2\n"
|
|
"}\n";
|
|
SMDiagnostic Err;
|
|
return parseAssemblyString(ModuleStrig, Err, C);
|
|
}
|
|
};
|
|
|
|
TEST_F(BlockFrequencyInfoTest, Basic) {
|
|
auto M = makeLLVMModule();
|
|
Function *F = M->getFunction("f");
|
|
F->setEntryCount(100);
|
|
|
|
BlockFrequencyInfo BFI = buildBFI(*F);
|
|
BasicBlock &BB0 = F->getEntryBlock();
|
|
BasicBlock *BB1 = BB0.getTerminator()->getSuccessor(0);
|
|
BasicBlock *BB2 = BB0.getTerminator()->getSuccessor(1);
|
|
BasicBlock *BB3 = BB1->getSingleSuccessor();
|
|
|
|
uint64_t BB0Freq = BFI.getBlockFreq(&BB0).getFrequency();
|
|
uint64_t BB1Freq = BFI.getBlockFreq(BB1).getFrequency();
|
|
uint64_t BB2Freq = BFI.getBlockFreq(BB2).getFrequency();
|
|
uint64_t BB3Freq = BFI.getBlockFreq(BB3).getFrequency();
|
|
|
|
EXPECT_EQ(BB0Freq, BB3Freq);
|
|
EXPECT_EQ(BB0Freq, BB1Freq + BB2Freq);
|
|
EXPECT_EQ(BB0Freq, BB3Freq);
|
|
|
|
EXPECT_EQ(BFI.getBlockProfileCount(&BB0).getValue(), UINT64_C(100));
|
|
EXPECT_EQ(BFI.getBlockProfileCount(BB3).getValue(), UINT64_C(100));
|
|
EXPECT_EQ(BFI.getBlockProfileCount(BB1).getValue(),
|
|
(100 * BB1Freq + BB0Freq / 2) / BB0Freq);
|
|
EXPECT_EQ(BFI.getBlockProfileCount(BB2).getValue(),
|
|
(100 * BB2Freq + BB0Freq / 2) / BB0Freq);
|
|
|
|
// Scale the frequencies of BB0, BB1 and BB2 by a factor of two.
|
|
SmallPtrSet<BasicBlock *, 4> BlocksToScale({BB1, BB2});
|
|
BFI.setBlockFreqAndScale(&BB0, BB0Freq * 2, BlocksToScale);
|
|
EXPECT_EQ(BFI.getBlockFreq(&BB0).getFrequency(), 2 * BB0Freq);
|
|
EXPECT_EQ(BFI.getBlockFreq(BB1).getFrequency(), 2 * BB1Freq);
|
|
EXPECT_EQ(BFI.getBlockFreq(BB2).getFrequency(), 2 * BB2Freq);
|
|
EXPECT_EQ(BFI.getBlockFreq(BB3).getFrequency(), BB3Freq);
|
|
}
|
|
|
|
static_assert(is_trivially_copyable<bfi_detail::BlockMass>::value,
|
|
"trivially copyable");
|
|
|
|
} // end anonymous namespace
|
|
} // end namespace llvm
|