llvm-6502/unittests/Analysis/MixedTBAATest.cpp
Hal Finkel 2c7c54c86c AA metadata refactoring (introduce AAMDNodes)
In order to enable the preservation of noalias function parameter information
after inlining, and the representation of block-level __restrict__ pointer
information (etc.), additional kinds of aliasing metadata will be introduced.
This metadata needs to be carried around in AliasAnalysis::Location objects
(and MMOs at the SDAG level), and so we need to generalize the current scheme
(which is hard-coded to just one TBAA MDNode*).

This commit introduces only the necessary refactoring to allow for the
introduction of other aliasing metadata types, but does not actually introduce
any (that will come in a follow-up commit). What it does introduce is a new
AAMDNodes structure to hold all of the aliasing metadata nodes associated with
a particular memory-accessing instruction, and uses that structure instead of
the raw MDNode* in AliasAnalysis::Location, etc.

No functionality change intended.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@213859 91177308-0d34-0410-b5e6-96231b3b80d8
2014-07-24 12:16:19 +00:00

78 lines
2.5 KiB
C++

//===--- 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/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/PassManager.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;
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(createTypeBasedAliasAnalysisPass());
PM.add(createAAEvalPass());
PM.run(M);
}
} // end anonymous namspace
} // end llvm namespace