Since getSubtarget() always provides a const Subtarget, dont' require the user
authorChris Lattner <sabre@nondot.org>
Fri, 5 Aug 2005 21:53:21 +0000 (21:53 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 5 Aug 2005 21:53:21 +0000 (21:53 +0000)
to pass it in.  Also, since it always returns a non-null pointer, make it
return a reference instead for easier use.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22686 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Target/TargetMachine.h

index 1caf0eceddb5da7d68515256700cf2fc2e5f3522..9c026cc4f6c71924c866c0dfbc1865fdffb0fe38 100644 (file)
@@ -105,11 +105,11 @@ public:
   /// getSubtarget - This method returns a pointer to the specified type of
   /// TargetSubtarget.  In debug builds, it verifies that the object being
   /// returned is of the correct type.
-  template<typename STC> STC *getSubtarget() const {
+  template<typename STC> const STC &getSubtarget() const {
     const TargetSubtarget *TST = getSubtargetImpl();
-    assert(getSubtargetImpl() && dynamic_cast<STC*>(TST) &&
+    assert(TST && dynamic_cast<const STC*>(TST) &&
            "Not the right kind of subtarget!");
-    return (STC*)TST;
+    return *static_cast<const STC*>(TST);
   }
 
   /// getRegisterInfo - If register information is available, return it.  If