add_compile_options(-Wno-undefined-var-template)
endif()
+# Define PNACL_LLVM for LLVM_VERSION <= 3.7
+if((NOT LLVM_VERSION_MAJOR GREATER 3) AND (NOT LLVM_VERSION_MINOR GREATER 7))
+ add_definitions(
+ -DPNACL_LLVM
+ )
+endif()
+
target_link_libraries(pnacl-sz pthread)
-DALLOW_WASM=0 -DPNACL_BROWSER_TRANSLATOR=0
CXX.Flags += -Wno-undefined-var-template
endif
+
+CPP.Defines += -DPNACL_LLVM
BASE_CXX_DEFINES += -DSZTARGET=$(SZTARGET)
endif
+BASE_CXX_DEFINES += -DPNACL_LLVM
+
CXX_DEFINES := $(BASE_CXX_DEFINES) -DPNACL_BROWSER_TRANSLATOR=0
ifdef NOASSERT
unsigned Capacity; // Size of allocated memory in BitWord.
Allocator Alloc;
+ uint64_t alignTo(uint64_t Value, uint64_t Align) {
+#ifdef PNACL_LLVM
+ return llvm::RoundUpToAlignment(Value, Align);
+#else // !PNACL_LLVM
+ return llvm::alignTo(Value, Align);
+#endif // !PNACL_LLVM
+ }
+
public:
typedef unsigned size_type;
// Encapsulation of a single bit.
BitWord PrefixMask = ~0UL << (I % BITWORD_SIZE);
Bits[I / BITWORD_SIZE] |= PrefixMask;
- I = llvm::RoundUpToAlignment(I, BITWORD_SIZE);
+ I = alignTo(I, BITWORD_SIZE);
for (; I + BITWORD_SIZE <= E; I += BITWORD_SIZE)
Bits[I / BITWORD_SIZE] = ~0UL;
BitWord PrefixMask = ~0UL << (I % BITWORD_SIZE);
Bits[I / BITWORD_SIZE] &= ~PrefixMask;
- I = llvm::RoundUpToAlignment(I, BITWORD_SIZE);
+ I = alignTo(I, BITWORD_SIZE);
for (; I + BITWORD_SIZE <= E; I += BITWORD_SIZE)
Bits[I / BITWORD_SIZE] = 0UL;
Instr.setDeleted();
auto &LoweringContext = getTarget()->getContext();
- LoweringContext.setInsertPoint(Instr);
+ LoweringContext.setInsertPoint(instToIterator(&Instr));
LoweringContext.insert(ShuffleVector);
}
}
I->emitIAS(Func);
// Only update stats during the final pass.
if (Retrying)
- updateStats(Func, I);
+ updateStats(Func, iteratorToInst(I));
} else {
// Treat it as though there were an implicit bundle_lock and
// bundle_unlock wrapping the instruction.
Helper.rollback();
Helper.padToNextBundle();
I->emitIAS(Func);
- updateStats(Func, I);
+ updateStats(Func, iteratorToInst(I));
Helper.leaveBundleLockRegion();
}
}
using ReturnType = Ice::VerboseMask;
};
+template <> struct ToSetterParam<cl::list<std::string>> {
+ using ReturnType = std::vector<std::string>;
+};
+
template <typename T>
typename ToSetterParam<T>::ReturnType toSetterParam(const T &Param) {
return Param;
return VMask;
}
+template <>
+ToSetterParam<cl::list<std::string>>::ReturnType
+toSetterParam(const cl::list<std::string> &Param) {
+ return *&Param;
+}
+
} // end of anonymous namespace
void ClFlags::getParsedClFlags(ClFlags &OutFlags) {
#include <utility>
#include <vector>
+#ifndef PNACL_LLVM
+namespace llvm {
+// \brief Define the expected format of the file.
+enum NaClFileFormat {
+ // LLVM IR source or bitcode file (as appropriate).
+ LLVMFormat,
+ // PNaCl bitcode file.
+ PNaClFormat,
+ // Autodetect if PNaCl or LLVM format.
+ AutodetectFileFormat
+};
+} // end of namespace llvm
+#endif // !PNACL_LLVM
+
namespace Ice {
// detail defines the type cl_type_traits, which is used to define the
// getters/setters for the ClFlags class. It converts the cl_detail::*_flag
public:
TextDataStreamer() = default;
~TextDataStreamer() final = default;
- static TextDataStreamer *create(const std::string &Filename,
+#ifdef PNACL_LLVM
+ using CreateType = TextDataStreamer *;
+#else // !PNACL_LLVM
+ using CreateType = std::unique_ptr<TextDataStreamer>;
+#endif // !PNACL_LLVM
+ static CreateType create(const std::string &Filename,
std::string *Err);
size_t GetBytes(unsigned char *Buf, size_t Len) final;
size_t Cursor = 0;
};
-TextDataStreamer *TextDataStreamer::create(const std::string &Filename,
+TextDataStreamer::CreateType TextDataStreamer::create(const std::string &Filename,
std::string *Err) {
+#ifdef PNACL_LLVM
TextDataStreamer *Streamer = new TextDataStreamer();
llvm::raw_string_ostream ErrStrm(*Err);
if (std::error_code EC = llvm::readNaClRecordTextAndBuildBitcode(
}
ErrStrm.flush();
return Streamer;
+#else // !PNACL_LLVM
+ return CreateType();
+#endif // !PNACL_LLVM
}
size_t TextDataStreamer::GetBytes(unsigned char *Buf, size_t Len) {
const bool WasmBuildOnRead = Flags.getBuildOnRead() && wasmInput(IRFilename);
if (BuildOnRead) {
std::unique_ptr<PNaClTranslator> PTranslator(new PNaClTranslator(&Ctx));
- std::unique_ptr<llvm::StreamingMemoryObject> MemObj(
- new llvm::StreamingMemoryObjectImpl(InputStream.release()));
+#ifdef PNACL_LLVM
+ std::unique_ptr<llvm::StreamingMemoryObject> MemObj(new llvm::StreamingMemoryObjectImpl(InputStream.release()));
+#else // !PNACL_LLVM
+ std::unique_ptr<llvm::StreamingMemoryObject> MemObj(new llvm::StreamingMemoryObject(std::move(InputStream)));
+#endif // !PNACL_LLVM
PTranslator->translate(IRFilename, std::move(MemObj));
Translator.reset(PTranslator.release());
} else if (WasmBuildOnRead) {
// Parse the input LLVM IR file into a module.
llvm::SMDiagnostic Err;
TimerMarker T1(Ice::TimerStack::TT_parse, &Ctx);
+#ifdef PNACL_LLVM
llvm::DiagnosticHandlerFunction DiagnosticHandler =
Flags.getLLVMVerboseErrors()
? redirectNaClDiagnosticToStream(llvm::errs())
std::unique_ptr<llvm::Module> Mod =
NaClParseIRFile(IRFilename, Flags.getInputFileFormat(), Err,
llvm::getGlobalContext(), DiagnosticHandler);
+#else // !PNACL_LLVM
+ llvm::DiagnosticHandlerFunction DiagnosticHandler = nullptr;
+ llvm::LLVMContext Context;
+ std::unique_ptr<llvm::Module> Mod =
+ parseIRFile(IRFilename, Err, Context);
+#endif // !PNACL_LLVM
if (!Mod) {
Err.print(Flags.getAppName().c_str(), llvm::errs());
Ctx.getErrorStatus()->assign(EC_Bitcode);
// The initial definition/use of each arg is the entry node.
for (auto ArgI = F->arg_begin(), ArgE = F->arg_end(); ArgI != ArgE;
++ArgI) {
- Func->addArg(mapValueToIceVar(ArgI));
+ Func->addArg(mapValueToIceVar(&*ArgI));
}
// Make an initial pass through the block list just to resolve the blocks
E = Mod->global_end();
I != E; ++I) {
- const GlobalVariable *GV = I;
+ const GlobalVariable *GV = &*I;
Ice::GlobalDeclaration *Var = getConverter().getGlobalDeclaration(GV);
auto *VarDecl = cast<Ice::VariableDeclaration>(Var);
for (Module::const_global_iterator I = Mod->global_begin(),
E = Mod->global_end();
I != E; ++I) {
- const GlobalVariable *GV = I;
+ const GlobalVariable *GV = &*I;
constexpr bool NoSuppressMangling = false;
auto *Var = VariableDeclaration::create(
GlobalDeclarationsPool.get(), NoSuppressMangling, GV->getLinkage());
} // end of namespace llvm
+namespace Ice {
+
+inline InstList::iterator instToIterator(Inst *Instr) {
+#ifdef PNACL_LLVM
+ return Instr;
+#else // !PNACL_LLVM
+ return Instr->getIterator();
+#endif // !PNACL_LLVM
+}
+
+inline Inst *iteratorToInst(InstList::iterator Iter) {
+ return &*Iter;
+}
+
+inline const Inst *iteratorToInst(InstList::const_iterator Iter) {
+ return &*Iter;
+}
+
+} // end of namespace Ice
+
#endif // SUBZERO_SRC_ICEINST_H
Context.init(Node);
while (!Context.atEnd()) {
PostIncrLoweringContext _(Context);
- genTargetHelperCallFor(Context.getCur());
+ genTargetHelperCallFor(iteratorToInst(Context.getCur()));
}
}
}
}
void TargetLowering::doNopInsertion(RandomNumberGenerator &RNG) {
- Inst *I = Context.getCur();
+ Inst *I = iteratorToInst(Context.getCur());
bool ShouldSkip = llvm::isa<InstFakeUse>(I) || llvm::isa<InstFakeDef>(I) ||
llvm::isa<InstFakeKill>(I) || I->isRedundantAssign() ||
I->isDeleted();
// should delete any additional instructions it consumes.
void TargetLowering::lower() {
assert(!Context.atEnd());
- Inst *Instr = Context.getCur();
+ Inst *Instr = iteratorToInst(Context.getCur());
Instr->deleteIfDead();
if (!Instr->isDeleted() && !llvm::isa<InstFakeDef>(Instr) &&
!llvm::isa<InstFakeUse>(Instr)) {
Context.setNext(Next);
Context.insert(Instr);
--Next;
- assert(&*Next == Instr);
+ assert(iteratorToInst(Next) == Instr);
Context.setCur(Next);
lower();
}
Inst *getNextInst() const {
if (Next == End)
return nullptr;
- return Next;
+ return iteratorToInst(Next);
}
Inst *getNextInst(InstList::iterator &Iter) const {
advanceForward(Iter);
if (Iter == End)
return nullptr;
- return Iter;
+ return iteratorToInst(Iter);
}
CfgNode *getNode() const { return Node; }
bool atEnd() const { return Cur == End; }
Context.init(Node);
while (!Context.atEnd()) {
PostIncrLoweringContext PostIncrement(Context);
- Inst *CurInstr = Context.getCur();
+ Inst *CurInstr = iteratorToInst(Context.getCur());
if (auto *Call = llvm::dyn_cast<InstCall>(CurInstr)) {
SizeT OutArgsSizeBytes = getCallStackArgumentsSizeBytes(Call);
MaxOutArgsSizeBytes = std::max(MaxOutArgsSizeBytes, OutArgsSizeBytes);
// The got addr needs to be materialized at the same point where DefGotPtr
// lives.
- Context.setInsertPoint(DefGotPtr);
+ Context.setInsertPoint(instToIterator(DefGotPtr));
assert(DefGotPtr->getSrcSize() == 1);
auto *T = llvm::cast<Variable>(DefGotPtr->getSrc(0));
loadNamedConstantRelocatablePIC(Ctx->getGlobalString(GlobalOffsetTable), T,
PostLoweringLegalizer Legalizer(this);
while (!Context.atEnd()) {
PostIncrLoweringContext PostIncrement(Context);
- Inst *CurInstr = Context.getCur();
+ Inst *CurInstr = iteratorToInst(Context.getCur());
// Check if the previous TempBaseReg is clobbered, and reset if needed.
Legalizer.resetTempBaseIfClobberedBy(CurInstr);
}
void TargetARM32::doAddressOptLoad() {
- Inst *Instr = Context.getCur();
+ Inst *Instr = iteratorToInst(Context.getCur());
assert(llvm::isa<InstLoad>(Instr));
Variable *Dest = Instr->getDest();
Operand *Addr = Instr->getSrc(0);
}
void TargetARM32::doAddressOptStore() {
- Inst *Instr = Context.getCur();
+ Inst *Instr = iteratorToInst(Context.getCur());
assert(llvm::isa<InstStore>(Instr));
Operand *Src = Instr->getSrc(0);
Operand *Addr = Instr->getSrc(1);
}
bool FunctionParser::ParseBlock(unsigned BlockID) {
+#ifndef PNACL_LLVM
+ constexpr bool PNaClAllowLocalSymbolTables = true;
+#endif // !PNACL_LLVM
switch (BlockID) {
case naclbitc::CONSTANTS_BLOCK_ID: {
ConstantsParser Parser(BlockID, this);
//
//===----------------------------------------------------------------------===//
+#ifdef PNACL_LLVM
+
#ifdef SZTARGET
#ifndef SUBZERO_TARGET
#include "llvm/Config/SZTargets.def"
#endif // !SZTARGET
+
+#else // !PNACL_LLVM
+
+SUBZERO_TARGET(ARM32)
+SUBZERO_TARGET(MIPS32)
+SUBZERO_TARGET(X8632)
+SUBZERO_TARGET(X8664)
+
+#endif // !PNACL_LLVM