1 #include "llvm/Target/TargetOptions.h"
2 #include "llvm/CodeGen/TargetPassConfig.h"
3 #include "llvm/IR/LLVMContext.h"
4 #include "llvm/IR/LegacyPassManager.h"
5 #include "llvm/Support/TargetRegistry.h"
6 #include "llvm/Support/TargetSelect.h"
7 #include "llvm/Target/TargetMachine.h"
8 #include "gtest/gtest.h"
13 void initializeTestPassPass(PassRegistry
&);
19 InitializeAllTargets();
20 InitializeAllTargetMCs();
21 InitializeAllAsmPrinters();
22 InitializeAllAsmParsers();
24 PassRegistry
*Registry
= PassRegistry::getPassRegistry();
25 initializeCore(*Registry
);
26 initializeCodeGen(*Registry
);
29 /// Create a TargetMachine. We need a target that doesn't have IPRA enabled by
30 /// default. That turns out to be all targets at the moment, so just use X86.
31 std::unique_ptr
<TargetMachine
> createTargetMachine(bool EnableIPRA
) {
32 Triple
TargetTriple("x86_64--");
34 const Target
*T
= TargetRegistry::lookupTarget("", TargetTriple
, Error
);
38 TargetOptions Options
;
39 Options
.EnableIPRA
= EnableIPRA
;
40 return std::unique_ptr
<TargetMachine
>(T
->createTargetMachine(
41 "X86", "", "", Options
, None
, None
, CodeGenOpt::Aggressive
));
44 typedef std::function
<void(bool)> TargetOptionsTest
;
46 static void targetOptionsTest(bool EnableIPRA
) {
47 std::unique_ptr
<TargetMachine
> TM
= createTargetMachine(EnableIPRA
);
48 // This test is designed for the X86 backend; stop if it is not available.
51 legacy::PassManager PM
;
52 LLVMTargetMachine
*LLVMTM
= static_cast<LLVMTargetMachine
*>(TM
.get());
54 TargetPassConfig
*TPC
= LLVMTM
->createPassConfig(PM
);
57 ASSERT_TRUE(TM
->Options
.EnableIPRA
== EnableIPRA
);
62 } // End of anonymous namespace.
64 TEST(TargetOptionsTest
, IPRASetToOff
) {
65 targetOptionsTest(false);
68 TEST(TargetOptionsTest
, IPRASetToOn
) {
69 targetOptionsTest(true);
72 int main(int argc
, char **argv
) {
73 ::testing::InitGoogleTest(&argc
, argv
);
75 return RUN_ALL_TESTS();