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/InitializePasses.h"
6 #include "llvm/MC/TargetRegistry.h"
7 #include "llvm/Support/TargetSelect.h"
8 #include "llvm/Target/TargetMachine.h"
9 #include "gtest/gtest.h"
14 void initializeTestPassPass(PassRegistry
&);
20 InitializeAllTargets();
21 InitializeAllTargetMCs();
22 InitializeAllAsmPrinters();
23 InitializeAllAsmParsers();
25 PassRegistry
*Registry
= PassRegistry::getPassRegistry();
26 initializeCore(*Registry
);
27 initializeCodeGen(*Registry
);
30 /// Create a TargetMachine. We need a target that doesn't have IPRA enabled by
31 /// default. That turns out to be all targets at the moment, so just use X86.
32 std::unique_ptr
<TargetMachine
> createTargetMachine(bool EnableIPRA
) {
33 Triple
TargetTriple("x86_64--");
35 const Target
*T
= TargetRegistry::lookupTarget("", TargetTriple
, Error
);
39 TargetOptions Options
;
40 Options
.EnableIPRA
= EnableIPRA
;
41 return std::unique_ptr
<TargetMachine
>(T
->createTargetMachine(
42 "X86", "", "", Options
, None
, None
, CodeGenOpt::Aggressive
));
45 typedef std::function
<void(bool)> TargetOptionsTest
;
47 static void targetOptionsTest(bool EnableIPRA
) {
48 std::unique_ptr
<TargetMachine
> TM
= createTargetMachine(EnableIPRA
);
49 // This test is designed for the X86 backend; stop if it is not available.
52 legacy::PassManager PM
;
53 LLVMTargetMachine
*LLVMTM
= static_cast<LLVMTargetMachine
*>(TM
.get());
55 TargetPassConfig
*TPC
= LLVMTM
->createPassConfig(PM
);
58 ASSERT_TRUE(TM
->Options
.EnableIPRA
== EnableIPRA
);
63 } // End of anonymous namespace.
65 TEST(TargetOptionsTest
, IPRASetToOff
) {
66 targetOptionsTest(false);
69 TEST(TargetOptionsTest
, IPRASetToOn
) {
70 targetOptionsTest(true);
73 int main(int argc
, char **argv
) {
74 ::testing::InitGoogleTest(&argc
, argv
);
76 return RUN_ALL_TESTS();