aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/CodeGen
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/unittests/CodeGen')
-rw-r--r--llvm/unittests/CodeGen/InstrRefLDVTest.cpp2
-rw-r--r--llvm/unittests/CodeGen/LexicalScopesTest.cpp43
-rw-r--r--llvm/unittests/CodeGen/MFCommon.inc7
-rw-r--r--llvm/unittests/CodeGen/TypeTraitsTest.cpp35
4 files changed, 71 insertions, 16 deletions
diff --git a/llvm/unittests/CodeGen/InstrRefLDVTest.cpp b/llvm/unittests/CodeGen/InstrRefLDVTest.cpp
index 53bc024..3a625b2 100644
--- a/llvm/unittests/CodeGen/InstrRefLDVTest.cpp
+++ b/llvm/unittests/CodeGen/InstrRefLDVTest.cpp
@@ -159,7 +159,7 @@ public:
// Setup things like the artifical block map, and BlockNo <=> RPO Order
// mappings.
LDV->initialSetup(*MF);
- LDV->LS.initialize(*MF);
+ LDV->LS.scanFunction(*MF);
addMTracker(MF);
return &*LDV;
}
diff --git a/llvm/unittests/CodeGen/LexicalScopesTest.cpp b/llvm/unittests/CodeGen/LexicalScopesTest.cpp
index 563d496..34bd37a 100644
--- a/llvm/unittests/CodeGen/LexicalScopesTest.cpp
+++ b/llvm/unittests/CodeGen/LexicalScopesTest.cpp
@@ -44,6 +44,7 @@ public:
std::unique_ptr<MachineFunction> MF;
DICompileUnit *OurCU;
DIFile *OurFile;
+ DISubroutineType *OurSubT;
DISubprogram *OurFunc;
DILexicalBlock *OurBlock, *AnotherBlock;
DISubprogram *ToInlineFunc;
@@ -103,7 +104,7 @@ public:
OurFile = DIB.createFile("xyzzy.c", "/cave");
OurCU =
DIB.createCompileUnit(dwarf::DW_LANG_C99, OurFile, "nou", false, "", 0);
- auto OurSubT = DIB.createSubroutineType(DIB.getOrCreateTypeArray({}));
+ OurSubT = DIB.createSubroutineType(DIB.getOrCreateTypeArray({}));
OurFunc =
DIB.createFunction(OurCU, "bees", "", OurFile, 1, OurSubT, 1,
DINode::FlagZero, DISubprogram::SPFlagDefinition);
@@ -136,10 +137,10 @@ TEST_F(LexicalScopesTest, FlatLayout) {
LexicalScopes LS;
EXPECT_TRUE(LS.empty());
- LS.reset();
+ LS.resetFunction();
EXPECT_EQ(LS.getCurrentFunctionScope(), nullptr);
- LS.initialize(*MF);
+ LS.scanFunction(*MF);
EXPECT_FALSE(LS.empty());
LexicalScope *FuncScope = LS.getCurrentFunctionScope();
EXPECT_EQ(FuncScope->getParent(), nullptr);
@@ -182,7 +183,7 @@ TEST_F(LexicalScopesTest, BlockScopes) {
BuildMI(*MBB4, MBB4->end(), InBlockLoc, BeanInst);
LexicalScopes LS;
- LS.initialize(*MF);
+ LS.scanFunction(*MF);
LexicalScope *FuncScope = LS.getCurrentFunctionScope();
EXPECT_EQ(FuncScope->getDesc(), OurFunc);
auto &Children = FuncScope->getChildren();
@@ -217,7 +218,7 @@ TEST_F(LexicalScopesTest, InlinedScopes) {
BuildMI(*MBB4, MBB4->end(), InlinedLoc, BeanInst);
LexicalScopes LS;
- LS.initialize(*MF);
+ LS.scanFunction(*MF);
LexicalScope *FuncScope = LS.getCurrentFunctionScope();
auto &Children = FuncScope->getChildren();
ASSERT_EQ(Children.size(), 1u);
@@ -252,7 +253,7 @@ TEST_F(LexicalScopesTest, FuncWithEmptyGap) {
BuildMI(*MBB4, MBB4->end(), OutermostLoc, BeanInst);
LexicalScopes LS;
- LS.initialize(*MF);
+ LS.scanFunction(*MF);
LexicalScope *FuncScope = LS.getCurrentFunctionScope();
// A gap in a range that contains no other location, is not actually a
@@ -273,7 +274,7 @@ TEST_F(LexicalScopesTest, FuncWithRealGap) {
MachineInstr *LastI = BuildMI(*MBB4, MBB4->end(), InBlockLoc, BeanInst);
LexicalScopes LS;
- LS.initialize(*MF);
+ LS.scanFunction(*MF);
LexicalScope *BlockScope = LS.findLexicalScope(InBlockLoc.get());
ASSERT_NE(BlockScope, nullptr);
@@ -306,7 +307,7 @@ TEST_F(LexicalScopesTest, NotNested) {
MachineInstr *FourthI = BuildMI(*MBB4, MBB4->end(), InBlockLoc, BeanInst);
LexicalScopes LS;
- LS.initialize(*MF);
+ LS.scanFunction(*MF);
LexicalScope *FuncScope = LS.getCurrentFunctionScope();
LexicalScope *BlockScope = LS.findLexicalScope(InBlockLoc.get());
LexicalScope *OtherBlockScope = LS.findLexicalScope(NotNestedBlockLoc.get());
@@ -344,7 +345,7 @@ TEST_F(LexicalScopesTest, TestDominates) {
BuildMI(*MBB4, MBB4->end(), InBlockLoc, BeanInst);
LexicalScopes LS;
- LS.initialize(*MF);
+ LS.scanFunction(*MF);
LexicalScope *FuncScope = LS.getCurrentFunctionScope();
LexicalScope *BlockScope = LS.findLexicalScope(InBlockLoc.get());
LexicalScope *OtherBlockScope = LS.findLexicalScope(NotNestedBlockLoc.get());
@@ -386,7 +387,7 @@ TEST_F(LexicalScopesTest, TestGetBlocks) {
BuildMI(*MBB4, MBB4->end(), InBlockLoc, BeanInst);
LexicalScopes LS;
- LS.initialize(*MF);
+ LS.scanFunction(*MF);
LexicalScope *FuncScope = LS.getCurrentFunctionScope();
LexicalScope *BlockScope = LS.findLexicalScope(InBlockLoc.get());
LexicalScope *OtherBlockScope = LS.findLexicalScope(NotNestedBlockLoc.get());
@@ -443,7 +444,7 @@ TEST_F(LexicalScopesTest, TestMetaInst) {
BuildMI(*MBB4, MBB4->end(), InBlockLoc, BeanInst);
LexicalScopes LS;
- LS.initialize(*MF);
+ LS.scanFunction(*MF);
LexicalScope *FuncScope = LS.getCurrentFunctionScope();
LexicalScope *BlockScope = LS.findLexicalScope(InBlockLoc.get());
ASSERT_NE(FuncScope, nullptr);
@@ -459,4 +460,24 @@ TEST_F(LexicalScopesTest, TestMetaInst) {
EXPECT_TRUE(LS.dominates(InBlockLoc.get(), MBB4));
}
+// Test function map creation.
+TEST_F(LexicalScopesTest, TestFunctionScan) {
+ auto MF2 = createMachineFunction(Ctx, Mod, "Test2");
+ DIBuilder DIB(Mod, false, OurCU);
+ DISubprogram *Func2 =
+ DIB.createFunction(OurCU, "Func2", "", OurFile, 1, OurSubT, 1,
+ DINode::FlagZero, DISubprogram::SPFlagDefinition);
+ DISubprogram *UnattachedFunc =
+ DIB.createFunction(OurCU, "UnattachedFunc", "", OurFile, 1, OurSubT, 1,
+ DINode::FlagZero, DISubprogram::SPFlagDefinition);
+ MF2->getFunction().setSubprogram(Func2);
+ DIB.finalize();
+
+ LexicalScopes LS;
+ LS.initialize(Mod);
+ ASSERT_EQ(LS.getFunction(OurFunc), &MF->getFunction());
+ ASSERT_EQ(LS.getFunction(Func2), &MF2->getFunction());
+ ASSERT_EQ(LS.getFunction(UnattachedFunc), nullptr);
+}
+
} // anonymous namespace
diff --git a/llvm/unittests/CodeGen/MFCommon.inc b/llvm/unittests/CodeGen/MFCommon.inc
index cb4a241..a86a68c 100644
--- a/llvm/unittests/CodeGen/MFCommon.inc
+++ b/llvm/unittests/CodeGen/MFCommon.inc
@@ -132,10 +132,10 @@ BogusTargetMachine *createTargetMachine() {
return &BogusTM;
}
-std::unique_ptr<MachineFunction> createMachineFunction(LLVMContext &Ctx,
- Module &M) {
+std::unique_ptr<MachineFunction>
+createMachineFunction(LLVMContext &Ctx, Module &M, const Twine &Name = "Test") {
auto Type = FunctionType::get(Type::getVoidTy(Ctx), false);
- auto F = Function::Create(Type, GlobalValue::ExternalLinkage, "Test", &M);
+ auto F = Function::Create(Type, GlobalValue::ExternalLinkage, Name, &M);
auto TM = createTargetMachine();
unsigned FunctionNum = 42;
@@ -145,4 +145,3 @@ std::unique_ptr<MachineFunction> createMachineFunction(LLVMContext &Ctx,
return std::make_unique<MachineFunction>(*F, *TM, STI, MMI.getContext(),
FunctionNum);
}
-
diff --git a/llvm/unittests/CodeGen/TypeTraitsTest.cpp b/llvm/unittests/CodeGen/TypeTraitsTest.cpp
index dde8628..f0ed0e8 100644
--- a/llvm/unittests/CodeGen/TypeTraitsTest.cpp
+++ b/llvm/unittests/CodeGen/TypeTraitsTest.cpp
@@ -6,13 +6,16 @@
//
//===----------------------------------------------------------------------===//
+#include "llvm/CodeGen/RDFRegisters.h"
#include "llvm/CodeGen/RegisterPressure.h"
#include "llvm/CodeGen/ScheduleDAG.h"
#include "llvm/CodeGen/SelectionDAGNodes.h"
#include "llvm/CodeGen/SlotIndexes.h"
#include "llvm/CodeGen/TargetPassConfig.h"
#include "gtest/gtest.h"
+#include <functional>
#include <type_traits>
+#include <utility>
using namespace llvm;
@@ -23,3 +26,35 @@ static_assert(std::is_trivially_copyable_v<SDValue>, "trivially copyable");
static_assert(std::is_trivially_copyable_v<SlotIndex>, "trivially copyable");
static_assert(std::is_trivially_copyable_v<IdentifyingPassPtr>,
"trivially copyable");
+
+// https://llvm.org/PR105169
+// Verify that we won't accidently specialize std::less and std::equal_to in a
+// wrong way.
+// C++17 [namespace.std]/2, C++20/23 [namespace.std]/5:
+// A program may explicitly instantiate a template defined in the standard
+// library only if the declaration
+// - depends on the name of a user-defined type and
+// - the instantiation meets the standard library requirements for the
+// original template.
+template <class Fn> constexpr bool CheckStdCmpRequirements() {
+ // std::less and std::equal_to are literal, default constructible, and
+ // copyable classes.
+ Fn f1{};
+ auto f2 = f1;
+ auto f3 = std::move(f2);
+ f2 = f3;
+ f2 = std::move(f3);
+
+ // Properties held on all known implementations, although not guaranteed by
+ // the standard.
+ static_assert(std::is_empty_v<Fn>);
+ static_assert(std::is_trivially_default_constructible_v<Fn>);
+ static_assert(std::is_trivially_copyable_v<Fn>);
+
+ return true;
+}
+
+static_assert(CheckStdCmpRequirements<std::less<rdf::RegisterRef>>(),
+ "same as the original template");
+static_assert(CheckStdCmpRequirements<std::equal_to<rdf::RegisterRef>>(),
+ "same as the original template");