aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorShuxin Yang <shuxin.llvm@gmail.com>2013-10-23 17:28:19 +0000
committerShuxin Yang <shuxin.llvm@gmail.com>2013-10-23 17:28:19 +0000
commit8e3851a6eb9fe5fc30094c3a00d2b89c7cd68cbd (patch)
treeaa761eb31c1f7c14a3c9e313f4a1d29ea06e066b /lib
parentf39fe46062d2093fc3d7c092bc8c4561b744164c (diff)
downloadexternal_llvm-8e3851a6eb9fe5fc30094c3a00d2b89c7cd68cbd.zip
external_llvm-8e3851a6eb9fe5fc30094c3a00d2b89c7cd68cbd.tar.gz
external_llvm-8e3851a6eb9fe5fc30094c3a00d2b89c7cd68cbd.tar.bz2
Use address-taken to disambiguate global variable and indirect memops.
Major steps include: 1). introduces a not-addr-taken bit-field in GlobalVariable 2). GlobalOpt pass sets "not-address-taken" if it proves a global varirable dosen't have its address taken. 3). AA use this info for disambiguation. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@193251 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Analysis/BasicAliasAnalysis.cpp11
-rw-r--r--lib/AsmParser/LLLexer.cpp1
-rw-r--r--lib/AsmParser/LLParser.cpp4
-rw-r--r--lib/AsmParser/LLToken.h1
-rw-r--r--lib/Bitcode/Reader/BitcodeReader.cpp3
-rw-r--r--lib/Bitcode/Writer/BitcodeWriter.cpp4
-rw-r--r--lib/IR/AsmWriter.cpp1
-rw-r--r--lib/IR/Globals.cpp3
-rw-r--r--lib/Transforms/IPO/GlobalOpt.cpp1
9 files changed, 27 insertions, 2 deletions
diff --git a/lib/Analysis/BasicAliasAnalysis.cpp b/lib/Analysis/BasicAliasAnalysis.cpp
index bf92969..4e423a7 100644
--- a/lib/Analysis/BasicAliasAnalysis.cpp
+++ b/lib/Analysis/BasicAliasAnalysis.cpp
@@ -1238,6 +1238,17 @@ BasicAliasAnalysis::aliasCheck(const Value *V1, uint64_t V1Size,
return NoAlias;
if (isEscapeSource(O2) && isNonEscapingLocalObject(O1))
return NoAlias;
+
+ // If one object is a global variable without address taken, the other one
+ // is a different object, they will not alias because the global variable
+ // in question cannot be indirectly accessed.
+ if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(O1))
+ if (!GV->AddressMaybeTaken())
+ return NoAlias;
+
+ if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(O2))
+ if (!GV->AddressMaybeTaken())
+ return NoAlias;
}
// If the size of one access is larger than the entire object on the other
diff --git a/lib/AsmParser/LLLexer.cpp b/lib/AsmParser/LLLexer.cpp
index 99bff45..6d643b6 100644
--- a/lib/AsmParser/LLLexer.cpp
+++ b/lib/AsmParser/LLLexer.cpp
@@ -504,6 +504,7 @@ lltok::Kind LLLexer::LexIdentifier() {
KEYWORD(zeroinitializer);
KEYWORD(undef);
KEYWORD(null);
+ KEYWORD(notaddrtaken);
KEYWORD(to);
KEYWORD(tail);
KEYWORD(target);
diff --git a/lib/AsmParser/LLParser.cpp b/lib/AsmParser/LLParser.cpp
index 74c0ea4..9b5fb27 100644
--- a/lib/AsmParser/LLParser.cpp
+++ b/lib/AsmParser/LLParser.cpp
@@ -704,7 +704,7 @@ bool LLParser::ParseGlobal(const std::string &Name, LocTy NameLoc,
unsigned Linkage, bool HasLinkage,
unsigned Visibility) {
unsigned AddrSpace;
- bool IsConstant, UnnamedAddr, IsExternallyInitialized;
+ bool IsConstant, UnnamedAddr, IsExternallyInitialized, notAddrTaken;
GlobalVariable::ThreadLocalMode TLM;
LocTy UnnamedAddrLoc;
LocTy IsExternallyInitializedLoc;
@@ -719,6 +719,7 @@ bool LLParser::ParseGlobal(const std::string &Name, LocTy NameLoc,
IsExternallyInitialized,
&IsExternallyInitializedLoc) ||
ParseGlobalType(IsConstant) ||
+ ParseOptionalToken(lltok::kw_notaddrtaken, notAddrTaken) ||
ParseType(Ty, TyLoc))
return true;
@@ -776,6 +777,7 @@ bool LLParser::ParseGlobal(const std::string &Name, LocTy NameLoc,
GV->setLinkage((GlobalValue::LinkageTypes)Linkage);
GV->setVisibility((GlobalValue::VisibilityTypes)Visibility);
GV->setExternallyInitialized(IsExternallyInitialized);
+ GV->setAddressMaybeTaken(!notAddrTaken);
GV->setThreadLocalMode(TLM);
GV->setUnnamedAddr(UnnamedAddr);
diff --git a/lib/AsmParser/LLToken.h b/lib/AsmParser/LLToken.h
index e1382fd..7832e81 100644
--- a/lib/AsmParser/LLToken.h
+++ b/lib/AsmParser/LLToken.h
@@ -51,6 +51,7 @@ namespace lltok {
kw_localdynamic, kw_initialexec, kw_localexec,
kw_zeroinitializer,
kw_undef, kw_null,
+ kw_notaddrtaken,
kw_to,
kw_tail,
kw_target,
diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp
index e408cd1..3fca4ab 100644
--- a/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -1848,6 +1848,9 @@ bool BitcodeReader::ParseModule(bool Resume) {
new GlobalVariable(*TheModule, Ty, isConstant, Linkage, 0, "", 0,
TLM, AddressSpace, ExternallyInitialized);
NewGV->setAlignment(Alignment);
+ if (Record.size() > 10)
+ NewGV->setAddressMaybeTaken(Record[10]);
+
if (!Section.empty())
NewGV->setSection(Section);
NewGV->setVisibility(Visibility);
diff --git a/lib/Bitcode/Writer/BitcodeWriter.cpp b/lib/Bitcode/Writer/BitcodeWriter.cpp
index b082ba6..4f631b9 100644
--- a/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -616,11 +616,13 @@ static void WriteModuleInfo(const Module *M, const ValueEnumerator &VE,
Vals.push_back(GV->hasSection() ? SectionMap[GV->getSection()] : 0);
if (GV->isThreadLocal() ||
GV->getVisibility() != GlobalValue::DefaultVisibility ||
- GV->hasUnnamedAddr() || GV->isExternallyInitialized()) {
+ GV->hasUnnamedAddr() || GV->isExternallyInitialized() ||
+ !GV->AddressMaybeTaken()) {
Vals.push_back(getEncodedVisibility(GV));
Vals.push_back(getEncodedThreadLocalMode(GV));
Vals.push_back(GV->hasUnnamedAddr());
Vals.push_back(GV->isExternallyInitialized());
+ Vals.push_back(GV->AddressMaybeTaken());
} else {
AbbrevToUse = SimpleGVarAbbrev;
}
diff --git a/lib/IR/AsmWriter.cpp b/lib/IR/AsmWriter.cpp
index 6e3b853..dc337c1 100644
--- a/lib/IR/AsmWriter.cpp
+++ b/lib/IR/AsmWriter.cpp
@@ -1459,6 +1459,7 @@ void AssemblyWriter::printGlobal(const GlobalVariable *GV) {
if (GV->hasUnnamedAddr()) Out << "unnamed_addr ";
if (GV->isExternallyInitialized()) Out << "externally_initialized ";
Out << (GV->isConstant() ? "constant " : "global ");
+ if (!GV->AddressMaybeTaken()) Out << "notaddrtaken ";
TypePrinter.print(GV->getType()->getElementType(), Out);
if (GV->hasInitializer()) {
diff --git a/lib/IR/Globals.cpp b/lib/IR/Globals.cpp
index da3b02a..8c28ec1 100644
--- a/lib/IR/Globals.cpp
+++ b/lib/IR/Globals.cpp
@@ -99,6 +99,7 @@ GlobalVariable::GlobalVariable(Type *Ty, bool constant, LinkageTypes Link,
}
LeakDetector::addGarbageObject(this);
+ setAddressMaybeTaken(true);
}
GlobalVariable::GlobalVariable(Module &M, Type *Ty, bool constant,
@@ -125,6 +126,7 @@ GlobalVariable::GlobalVariable(Module &M, Type *Ty, bool constant,
Before->getParent()->getGlobalList().insert(Before, this);
else
M.getGlobalList().push_back(this);
+ setAddressMaybeTaken(true);
}
void GlobalVariable::setParent(Module *parent) {
@@ -185,6 +187,7 @@ void GlobalVariable::copyAttributesFrom(const GlobalValue *Src) {
GlobalValue::copyAttributesFrom(Src);
const GlobalVariable *SrcVar = cast<GlobalVariable>(Src);
setThreadLocal(SrcVar->isThreadLocal());
+ setAddressMaybeTaken(SrcVar->AddressMaybeTaken());
}
diff --git a/lib/Transforms/IPO/GlobalOpt.cpp b/lib/Transforms/IPO/GlobalOpt.cpp
index 82a59ed..a259b4d 100644
--- a/lib/Transforms/IPO/GlobalOpt.cpp
+++ b/lib/Transforms/IPO/GlobalOpt.cpp
@@ -1723,6 +1723,7 @@ bool GlobalOpt::ProcessGlobal(GlobalVariable *GV,
if (GlobalStatus::analyzeGlobal(GV, GS))
return false;
+ GV->setAddressMaybeTaken(false);
if (!GS.IsCompared && !GV->hasUnnamedAddr()) {
GV->setUnnamedAddr(true);
NumUnnamed++;