From e5e475e09d1e8a9ea1bda58b536867ff16600399 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Mon, 8 Sep 2003 17:45:59 +0000 Subject: [PATCH] Add support for volatile loads/stores git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@8393 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/iMemory.h | 37 +++++++++++++++++++++++++++++++------ lib/VMCore/AsmWriter.cpp | 5 +++++ lib/VMCore/iMemory.cpp | 22 +++++++++++++++++++--- 3 files changed, 55 insertions(+), 9 deletions(-) diff --git a/include/llvm/iMemory.h b/include/llvm/iMemory.h index 09c94a2c77d..4cc76e46d7a 100644 --- a/include/llvm/iMemory.h +++ b/include/llvm/iMemory.h @@ -1,7 +1,7 @@ -//===-- llvm/iMemory.h - Memory Operator node definitions --------*- C++ -*--=// +//===-- llvm/iMemory.h - Memory Operator node definitions -------*- C++ -*-===// // // This file contains the declarations of all of the memory related operators. -// This includes: malloc, free, alloca, load, store, getfield, putfield +// This includes: malloc, free, alloca, load, store, and getelementptr // //===----------------------------------------------------------------------===// @@ -139,13 +139,24 @@ struct FreeInst : public Instruction { class LoadInst : public Instruction { LoadInst(const LoadInst &LI) : Instruction(LI.getType(), Load) { + Volatile = LI.isVolatile(); Operands.reserve(1); Operands.push_back(Use(LI.Operands[0], this)); } + bool Volatile; // True if this is a volatile load public: - LoadInst(Value *Ptr, const std::string &Name = "", + LoadInst(Value *Ptr, const std::string &Name, Instruction *InsertBefore); + LoadInst(Value *Ptr, const std::string &Name = "", bool isVolatile = false, Instruction *InsertBefore = 0); + /// isVolatile - Return true if this is a load from a volatile memory + /// location. + bool isVolatile() const { return Volatile; } + + /// setVolatile - Specify whether this is a volatile load or not. + /// + void setVolatile(bool V) { Volatile = V; } + virtual Instruction *clone() const { return new LoadInst(*this); } Value *getPointerOperand() { return getOperand(0); } @@ -155,7 +166,7 @@ public: // Methods for support type inquiry through isa, cast, and dyn_cast: static inline bool classof(const LoadInst *) { return true; } static inline bool classof(const Instruction *I) { - return (I->getOpcode() == Instruction::Load); + return I->getOpcode() == Instruction::Load; } static inline bool classof(const Value *V) { return isa(V) && classof(cast(V)); @@ -169,12 +180,26 @@ public: class StoreInst : public Instruction { StoreInst(const StoreInst &SI) : Instruction(SI.getType(), Store) { + Volatile = SI.isVolatile(); Operands.reserve(2); Operands.push_back(Use(SI.Operands[0], this)); Operands.push_back(Use(SI.Operands[1], this)); } + bool Volatile; // True if this is a volatile store public: - StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore = 0); + StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore); + StoreInst(Value *Val, Value *Ptr, bool isVolatile = false, + Instruction *InsertBefore = 0); + + + /// isVolatile - Return true if this is a load from a volatile memory + /// location. + bool isVolatile() const { return Volatile; } + + /// setVolatile - Specify whether this is a volatile load or not. + /// + void setVolatile(bool V) { Volatile = V; } + virtual Instruction *clone() const { return new StoreInst(*this); } virtual bool mayWriteToMemory() const { return true; } @@ -186,7 +211,7 @@ public: // Methods for support type inquiry through isa, cast, and dyn_cast: static inline bool classof(const StoreInst *) { return true; } static inline bool classof(const Instruction *I) { - return (I->getOpcode() == Instruction::Store); + return I->getOpcode() == Instruction::Store; } static inline bool classof(const Value *V) { return isa(V) && classof(cast(V)); diff --git a/lib/VMCore/AsmWriter.cpp b/lib/VMCore/AsmWriter.cpp index b9b2e8fe9e7..f849fe1cd90 100644 --- a/lib/VMCore/AsmWriter.cpp +++ b/lib/VMCore/AsmWriter.cpp @@ -771,6 +771,11 @@ void AssemblyWriter::printInstruction(const Instruction &I) { if (I.hasName()) Out << getLLVMName(I.getName()) << " = "; + // If this is a volatile load or store, print out the volatile marker + if ((isa(I) && cast(I).isVolatile()) || + (isa(I) && cast(I).isVolatile())) + Out << "volatile "; + // Print out the opcode... Out << I.getOpcodeName(); diff --git a/lib/VMCore/iMemory.cpp b/lib/VMCore/iMemory.cpp index 559c15efe12..68a628bcb9b 100644 --- a/lib/VMCore/iMemory.cpp +++ b/lib/VMCore/iMemory.cpp @@ -1,4 +1,4 @@ -//===-- iMemory.cpp - Implement Memory instructions --------------*- C++ -*--=// +//===-- iMemory.cpp - Implement Memory instructions -----------------------===// // // This file implements the various memory related classes defined in iMemory.h // @@ -58,18 +58,34 @@ FreeInst::FreeInst(Value *Ptr, Instruction *InsertBefore) LoadInst::LoadInst(Value *Ptr, const std::string &Name, Instruction *InsertBef) : Instruction(cast(Ptr->getType())->getElementType(), - Load, Name, InsertBef) { + Load, Name, InsertBef), Volatile(false) { Operands.reserve(1); Operands.push_back(Use(Ptr, this)); } +LoadInst::LoadInst(Value *Ptr, const std::string &Name, bool isVolatile, + Instruction *InsertBef) + : Instruction(cast(Ptr->getType())->getElementType(), + Load, Name, InsertBef), Volatile(isVolatile) { + Operands.reserve(1); + Operands.push_back(Use(Ptr, this)); +} //===----------------------------------------------------------------------===// // StoreInst Implementation //===----------------------------------------------------------------------===// StoreInst::StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore) - : Instruction(Type::VoidTy, Store, "", InsertBefore) { + : Instruction(Type::VoidTy, Store, "", InsertBefore), Volatile(false) { + + Operands.reserve(2); + Operands.push_back(Use(Val, this)); + Operands.push_back(Use(Ptr, this)); +} + +StoreInst::StoreInst(Value *Val, Value *Ptr, bool isVolatile, + Instruction *InsertBefore) + : Instruction(Type::VoidTy, Store, "", InsertBefore), Volatile(isVolatile) { Operands.reserve(2); Operands.push_back(Use(Val, this));