From 40e7d564a52e8e04282c5855e8af8d19cdd2b744 Mon Sep 17 00:00:00 2001 From: Whitney Tsang Date: Fri, 30 Aug 2019 16:41:35 +0000 Subject: [PATCH] [INSTRUCTIONS] Add support of const for getLoadStorePointerOperand() and getLoadStorePointerOperand(). Reviewer: hsaito, sebpop, reames, hfinkel, mkuper, bogner, haicheng, arsenm, lattner, chandlerc, grosser, rengolin Reviewed By: reames Subscribers: wdng, llvm-commits, bmahjour Tag: LLVM Differential Revision: https://reviews.llvm.org/D66595 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@370486 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/IR/Instructions.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/include/llvm/IR/Instructions.h b/include/llvm/IR/Instructions.h index cb2ec07338e..b7e1d0fa18a 100644 --- a/include/llvm/IR/Instructions.h +++ b/include/llvm/IR/Instructions.h @@ -5255,23 +5255,30 @@ public: /// A helper function that returns the pointer operand of a load or store /// instruction. Returns nullptr if not load or store. -inline Value *getLoadStorePointerOperand(Value *V) { +inline const Value *getLoadStorePointerOperand(const Value *V) { if (auto *Load = dyn_cast(V)) return Load->getPointerOperand(); if (auto *Store = dyn_cast(V)) return Store->getPointerOperand(); return nullptr; } +inline Value *getLoadStorePointerOperand(Value *V) { + return const_cast( + getLoadStorePointerOperand(static_cast(V))); +} /// A helper function that returns the pointer operand of a load, store /// or GEP instruction. Returns nullptr if not load, store, or GEP. -inline Value *getPointerOperand(Value *V) { +inline const Value *getPointerOperand(const Value *V) { if (auto *Ptr = getLoadStorePointerOperand(V)) return Ptr; if (auto *Gep = dyn_cast(V)) return Gep->getPointerOperand(); return nullptr; } +inline Value *getPointerOperand(Value *V) { + return const_cast(getPointerOperand(static_cast(V))); +} /// A helper function that returns the alignment of load or store instruction. inline unsigned getLoadStoreAlignment(Value *I) { -- 2.40.0