summaryrefslogtreecommitdiff
path: root/unittests
diff options
context:
space:
mode:
authorFrancis Visoiu Mistrih <francisvm@yahoo.com>2017-12-14 10:03:09 +0000
committerFrancis Visoiu Mistrih <francisvm@yahoo.com>2017-12-14 10:03:09 +0000
commit3f63013fb4671d76230171cae8d47ed7230f1562 (patch)
tree69d51d9eec98ba1bf9cd0682b57cb8069d30f922 /unittests
parentd398775f54e28939948f5c87450b1afc129667e2 (diff)
[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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@320682 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r--unittests/CodeGen/MachineOperandTest.cpp39
1 files changed, 38 insertions, 1 deletions
diff --git a/unittests/CodeGen/MachineOperandTest.cpp b/unittests/CodeGen/MachineOperandTest.cpp
index 36897d918b3..96498e681ed 100644
--- a/unittests/CodeGen/MachineOperandTest.cpp
+++ b/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