diff options
author | Francis Visoiu Mistrih <francisvm@yahoo.com> | 2017-12-14 10:03:09 +0000 |
---|---|---|
committer | Francis Visoiu Mistrih <francisvm@yahoo.com> | 2017-12-14 10:03:09 +0000 |
commit | 5df3bbf3e637b8f9175e0f96e02aab0776f1d2f1 (patch) | |
tree | d7ad954694901b10048b02f17167532adbbc9fc0 /llvm/unittests/CodeGen/MachineOperandTest.cpp | |
parent | e76c5fcd70695f3b838b868ba53471f2554e0ee6 (diff) | |
download | bcm5719-llvm-5df3bbf3e637b8f9175e0f96e02aab0776f1d2f1.tar.gz bcm5719-llvm-5df3bbf3e637b8f9175e0f96e02aab0776f1d2f1.zip |
[CodeGen] Print global addresses as @foo in both MIR and debug output
Work towards the unification of MIR and debug output by printing
`@foo` instead of `<ga:@foo>`.
Also print target flags in the MIR format since most of them are used on
global address operands.
Only debug syntax is affected.
llvm-svn: 320682
Diffstat (limited to 'llvm/unittests/CodeGen/MachineOperandTest.cpp')
-rw-r--r-- | llvm/unittests/CodeGen/MachineOperandTest.cpp | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/llvm/unittests/CodeGen/MachineOperandTest.cpp b/llvm/unittests/CodeGen/MachineOperandTest.cpp index 36897d918b3..96498e681ed 100644 --- a/llvm/unittests/CodeGen/MachineOperandTest.cpp +++ b/llvm/unittests/CodeGen/MachineOperandTest.cpp @@ -7,10 +7,11 @@ // //===----------------------------------------------------------------------===// -#include "llvm/ADT/ilist_node.h" #include "llvm/CodeGen/MachineOperand.h" +#include "llvm/ADT/ilist_node.h" #include "llvm/IR/Constants.h" #include "llvm/IR/LLVMContext.h" +#include "llvm/IR/Module.h" #include "llvm/IR/ModuleSlotTracker.h" #include "llvm/Support/raw_ostream.h" #include "gtest/gtest.h" @@ -235,4 +236,40 @@ TEST(MachineOperandTest, PrintExternalSymbol) { } } +TEST(MachineOperandTest, PrintGlobalAddress) { + LLVMContext Ctx; + Module M("MachineOperandGVTest", Ctx); + M.getOrInsertGlobal("foo", Type::getInt32Ty(Ctx)); + + GlobalValue *GV = M.getNamedValue("foo"); + + // Create a MachineOperand with a global address and a positive offset and + // print it. + MachineOperand MO = MachineOperand::CreateGA(GV, 12); + + // Checking some preconditions on the newly created + // MachineOperand. + ASSERT_TRUE(MO.isGlobal()); + ASSERT_TRUE(MO.getGlobal() == GV); + ASSERT_TRUE(MO.getOffset() == 12); + + std::string str; + // Print a MachineOperand containing a global address and a positive offset. + { + raw_string_ostream OS(str); + MO.print(OS, /*TRI=*/nullptr, /*IntrinsicInfo=*/nullptr); + ASSERT_TRUE(OS.str() == "@foo + 12"); + } + + str.clear(); + MO.setOffset(-12); + + // Print a MachineOperand containing a global address and a negative offset. + { + raw_string_ostream OS(str); + MO.print(OS, /*TRI=*/nullptr, /*IntrinsicInfo=*/nullptr); + ASSERT_TRUE(OS.str() == "@foo - 12"); + } +} + } // end namespace |