diff options
author | Sanjoy Das <sanjoy@playingwithpointers.com> | 2016-11-08 20:46:01 +0000 |
---|---|---|
committer | Sanjoy Das <sanjoy@playingwithpointers.com> | 2016-11-08 20:46:01 +0000 |
commit | 2582e690b7088e938d33dd5e3d271f92d44ba16c (patch) | |
tree | 8882021c2d37be7a3073b9d34c380994c2dccc1c /llvm/unittests/Analysis | |
parent | d092107b0e07b1861e541e5f21b342a74218ccb9 (diff) | |
download | bcm5719-llvm-2582e690b7088e938d33dd5e3d271f92d44ba16c.tar.gz bcm5719-llvm-2582e690b7088e938d33dd5e3d271f92d44ba16c.zip |
[TBAA] Drop support for "old style" scalar TBAA tags
Summary:
We've had support for auto upgrading old style scalar TBAA access
metadata tags into the "new" struct path aware TBAA metadata for 3 years
now. The only way to actually generate old style TBAA was explicitly
through the IRBuilder API. I think this is a good time for dropping
support for old style scalar TBAA.
I'm not removing support for textual or bitcode upgrade -- if you have
IR with the old style scalar TBAA tags that go through the AsmParser orf
the bitcode parser before LLVM sees them, they will keep working as
usual.
Note:
%val = load i32, i32* %ptr, !tbaa !N
!N = < scalar tbaa node >
is equivalent to
%val = load i32, i32* %ptr, !tbaa !M
!N = < scalar tbaa node >
!M = !{!N, !N, 0}
Reviewers: manmanren, chandlerc, sunfish
Subscribers: mcrosier, llvm-commits, mgorny
Differential Revision: https://reviews.llvm.org/D26229
llvm-svn: 286291
Diffstat (limited to 'llvm/unittests/Analysis')
-rw-r--r-- | llvm/unittests/Analysis/CMakeLists.txt | 2 | ||||
-rw-r--r-- | llvm/unittests/Analysis/MixedTBAATest.cpp | 79 | ||||
-rw-r--r-- | llvm/unittests/Analysis/TBAATest.cpp | 63 |
3 files changed, 64 insertions, 80 deletions
diff --git a/llvm/unittests/Analysis/CMakeLists.txt b/llvm/unittests/Analysis/CMakeLists.txt index 2292a454c27..347c3be5147 100644 --- a/llvm/unittests/Analysis/CMakeLists.txt +++ b/llvm/unittests/Analysis/CMakeLists.txt @@ -14,7 +14,7 @@ add_llvm_unittest(AnalysisTests LazyCallGraphTest.cpp LoopPassManagerTest.cpp ScalarEvolutionTest.cpp - MixedTBAATest.cpp + TBAATest.cpp ValueTrackingTest.cpp UnrollAnalyzer.cpp ) diff --git a/llvm/unittests/Analysis/MixedTBAATest.cpp b/llvm/unittests/Analysis/MixedTBAATest.cpp deleted file mode 100644 index d70324f2c6a..00000000000 --- a/llvm/unittests/Analysis/MixedTBAATest.cpp +++ /dev/null @@ -1,79 +0,0 @@ -//===--- MixedTBAATest.cpp - Mixed TBAA unit tests ------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#include "llvm/Analysis/TypeBasedAliasAnalysis.h" -#include "llvm/Analysis/AliasAnalysisEvaluator.h" -#include "llvm/Analysis/Passes.h" -#include "llvm/IR/Constants.h" -#include "llvm/IR/Instructions.h" -#include "llvm/IR/LLVMContext.h" -#include "llvm/IR/MDBuilder.h" -#include "llvm/IR/Module.h" -#include "llvm/IR/LegacyPassManager.h" -#include "llvm/Support/CommandLine.h" -#include "gtest/gtest.h" - -namespace llvm { -namespace { - -class MixedTBAATest : public testing::Test { -protected: - MixedTBAATest() : M("MixedTBAATest", C), MD(C) {} - - LLVMContext C; - Module M; - MDBuilder MD; - legacy::PassManager PM; -}; - -TEST_F(MixedTBAATest, MixedTBAA) { - // Setup function. - FunctionType *FTy = FunctionType::get(Type::getVoidTy(C), - std::vector<Type *>(), false); - auto *F = cast<Function>(M.getOrInsertFunction("f", FTy)); - auto *BB = BasicBlock::Create(C, "entry", F); - auto IntType = Type::getInt32Ty(C); - auto PtrType = Type::getInt32PtrTy(C); - auto *Value = ConstantInt::get(IntType, 42); - auto *Addr = ConstantPointerNull::get(PtrType); - - auto *Store1 = new StoreInst(Value, Addr, BB); - auto *Store2 = new StoreInst(Value, Addr, BB); - ReturnInst::Create(C, nullptr, BB); - - // New TBAA metadata - { - auto RootMD = MD.createTBAARoot("Simple C/C++ TBAA"); - auto MD1 = MD.createTBAAScalarTypeNode("omnipotent char", RootMD); - auto MD2 = MD.createTBAAScalarTypeNode("int", MD1); - auto MD3 = MD.createTBAAStructTagNode(MD2, MD2, 0); - Store2->setMetadata(LLVMContext::MD_tbaa, MD3); - } - - // Old TBAA metadata - { - auto RootMD = MD.createTBAARoot("Simple C/C++ TBAA"); - auto MD1 = MD.createTBAANode("omnipotent char", RootMD); - auto MD2 = MD.createTBAANode("int", MD1); - Store1->setMetadata(LLVMContext::MD_tbaa, MD2); - } - - // Run the TBAA eval pass on a mixture of path-aware and non-path-aware TBAA. - // The order of the metadata (path-aware vs non-path-aware) is important, - // because the AA eval pass only runs one test per store-pair. - const char* args[] = { "MixedTBAATest", "-evaluate-aa-metadata" }; - cl::ParseCommandLineOptions(sizeof(args) / sizeof(const char*), args); - PM.add(createTypeBasedAAWrapperPass()); - PM.add(createAAEvalPass()); - PM.run(M); -} - -} // end anonymous namspace -} // end llvm namespace - diff --git a/llvm/unittests/Analysis/TBAATest.cpp b/llvm/unittests/Analysis/TBAATest.cpp new file mode 100644 index 00000000000..98899dd553d --- /dev/null +++ b/llvm/unittests/Analysis/TBAATest.cpp @@ -0,0 +1,63 @@ +//===--- TBAATest.cpp - Mixed TBAA unit tests -----------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/Analysis/AliasAnalysisEvaluator.h" +#include "llvm/Analysis/Passes.h" +#include "llvm/IR/Constants.h" +#include "llvm/IR/Instructions.h" +#include "llvm/IR/LLVMContext.h" +#include "llvm/IR/MDBuilder.h" +#include "llvm/IR/Module.h" +#include "llvm/IR/LegacyPassManager.h" +#include "llvm/IR/Verifier.h" +#include "llvm/Support/CommandLine.h" +#include "gtest/gtest.h" + +namespace llvm { +namespace { + +class OldTBAATest : public testing::Test { +protected: + OldTBAATest() : M("MixedTBAATest", C), MD(C) {} + + LLVMContext C; + Module M; + MDBuilder MD; +}; + +TEST_F(OldTBAATest, checkVerifierBehavior) { + // C++ unit test case to avoid going through the auto upgrade logic. + + FunctionType *FTy = FunctionType::get(Type::getVoidTy(C), {}); + auto *F = cast<Function>(M.getOrInsertFunction("f", FTy)); + auto *BB = BasicBlock::Create(C, "entry", F); + auto *IntType = Type::getInt32Ty(C); + auto *PtrType = Type::getInt32PtrTy(C); + auto *SI = new StoreInst(ConstantInt::get(IntType, 42), + ConstantPointerNull::get(PtrType), BB); + ReturnInst::Create(C, nullptr, BB); + + auto *RootMD = MD.createTBAARoot("Simple C/C++ TBAA"); + auto *MD1 = MD.createTBAANode("omnipotent char", RootMD); + auto *MD2 = MD.createTBAANode("int", MD1); + SI->setMetadata(LLVMContext::MD_tbaa, MD2); + + SmallVector<char, 0> ErrorMsg; + raw_svector_ostream Outs(ErrorMsg); + + StringRef ExpectedFailureMsg( + "Old-style TBAA is no longer allowed, use struct-path TBAA instead"); + + EXPECT_TRUE(verifyFunction(*F, &Outs)); + EXPECT_TRUE(StringRef(ErrorMsg.begin(), ErrorMsg.size()) + .startswith(ExpectedFailureMsg)); +} + +} // end anonymous namspace +} // end llvm namespace |