mirror of
https://github.com/RPCS3/llvm.git
synced 2025-01-27 05:32:22 +00:00
52ab0bc417
preparation for de-coupling the AA implementations. In order to do this, they had to become fake-scoped using the traditional LLVM pattern of a leading initialism. These can't be actual scoped enumerations because they're bitfields and thus inherently we use them as integers. I've also renamed the behavior enums that are specific to reasoning about the mod/ref behavior of functions when called. This makes it more clear that they have a very narrow domain of applicability. I think there is a significantly cleaner API for all of this, but I don't want to try to do really substantive changes for now, I just want to refactor the things away from analysis groups so I'm preserving the exact original design and just cleaning up the names, style, and lifting out of the class. Differential Revision: http://reviews.llvm.org/D10564 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@242963 91177308-0d34-0410-b5e6-96231b3b80d8
105 lines
3.7 KiB
C++
105 lines
3.7 KiB
C++
//===--- AliasAnalysisTest.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/AliasAnalysis.h"
|
|
#include "llvm/Analysis/Passes.h"
|
|
#include "llvm/IR/Constants.h"
|
|
#include "llvm/IR/Instructions.h"
|
|
#include "llvm/IR/LLVMContext.h"
|
|
#include "llvm/IR/Module.h"
|
|
#include "llvm/IR/LegacyPassManager.h"
|
|
#include "llvm/Support/CommandLine.h"
|
|
#include "gtest/gtest.h"
|
|
|
|
namespace llvm {
|
|
namespace {
|
|
|
|
class AliasAnalysisTest : public testing::Test {
|
|
protected:
|
|
AliasAnalysisTest() : M("AliasAnalysisTBAATest", C) {}
|
|
|
|
// This is going to check that calling getModRefInfo without a location, and
|
|
// with a default location, first, doesn't crash, and second, gives the right
|
|
// answer.
|
|
void CheckModRef(Instruction *I, ModRefInfo Result) {
|
|
static char ID;
|
|
class CheckModRefTestPass : public FunctionPass {
|
|
public:
|
|
CheckModRefTestPass(Instruction *I, ModRefInfo Result)
|
|
: FunctionPass(ID), ExpectResult(Result), I(I) {}
|
|
static int initialize() {
|
|
PassInfo *PI = new PassInfo("CheckModRef testing pass", "", &ID,
|
|
nullptr, true, true);
|
|
PassRegistry::getPassRegistry()->registerPass(*PI, false);
|
|
initializeAliasAnalysisAnalysisGroup(*PassRegistry::getPassRegistry());
|
|
initializeBasicAliasAnalysisPass(*PassRegistry::getPassRegistry());
|
|
return 0;
|
|
}
|
|
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
|
AU.setPreservesAll();
|
|
AU.addRequiredTransitive<AliasAnalysis>();
|
|
}
|
|
bool runOnFunction(Function &) override {
|
|
AliasAnalysis &AA = getAnalysis<AliasAnalysis>();
|
|
EXPECT_EQ(AA.getModRefInfo(I, MemoryLocation()), ExpectResult);
|
|
EXPECT_EQ(AA.getModRefInfo(I), ExpectResult);
|
|
return false;
|
|
}
|
|
ModRefInfo ExpectResult;
|
|
Instruction *I;
|
|
};
|
|
static int initialize = CheckModRefTestPass::initialize();
|
|
(void)initialize;
|
|
CheckModRefTestPass *P = new CheckModRefTestPass(I, Result);
|
|
legacy::PassManager PM;
|
|
PM.add(createBasicAliasAnalysisPass());
|
|
PM.add(P);
|
|
PM.run(M);
|
|
}
|
|
|
|
LLVMContext C;
|
|
Module M;
|
|
};
|
|
|
|
TEST_F(AliasAnalysisTest, getModRefInfo) {
|
|
// 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 *Load1 = new LoadInst(Addr, "load", BB);
|
|
auto *Add1 = BinaryOperator::CreateAdd(Value, Value, "add", BB);
|
|
auto *VAArg1 = new VAArgInst(Addr, PtrType, "vaarg", BB);
|
|
auto *CmpXChg1 = new AtomicCmpXchgInst(Addr, ConstantInt::get(IntType, 0),
|
|
ConstantInt::get(IntType, 1),
|
|
Monotonic, Monotonic, CrossThread, BB);
|
|
auto *AtomicRMW =
|
|
new AtomicRMWInst(AtomicRMWInst::Xchg, Addr, ConstantInt::get(IntType, 1),
|
|
Monotonic, CrossThread, BB);
|
|
|
|
ReturnInst::Create(C, nullptr, BB);
|
|
|
|
// Check basic results
|
|
CheckModRef(Store1, MRI_Mod);
|
|
CheckModRef(Load1, MRI_Ref);
|
|
CheckModRef(Add1, MRI_NoModRef);
|
|
CheckModRef(VAArg1, MRI_ModRef);
|
|
CheckModRef(CmpXChg1, MRI_ModRef);
|
|
CheckModRef(AtomicRMW, MRI_ModRef);
|
|
}
|
|
|
|
} // end anonymous namspace
|
|
} // end llvm namespace
|